nix flake to build firware images for tolino page 2
  • Nix 69.1%
  • Shell 17.3%
  • C 13.6%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
goeranh 5b72ac8fae
koreader crash fix: initrd owns GBM symlink + self-diagnostic stderr + mask broken units
First 0.4 boot got all the way to launching KOReader, then reader.lua died
within ~1 s (coredump on every restart). The log proved why it could not have
worked, and exposed two more problems:

- systemd-tmpfiles-setup FAILED on card ('systemd-tmpfiles' not found — flash
  hole ate the ELF; udevadm was gone too while P8.7/P8.8 files were intact).
  That service is what creates /run/opengl-driver/lib/gbm/dri_gbm.so, the dir
  mesa's GBM backend loader hardcodes (root ignores $GBM_BACKENDS_PATH) —
  without it EGL init fails and reader.lua dies instantly. The initrd now
  creates that symlink itself after mounting the fresh /run tmpfs, where it
  already owns the boot contract; the tmpfiles conf stays as second source.

- All package .mount units (tmp/dev-mqueue/sys-kernel-debug/tracing/config)
  run a COMPILED-IN store-path mount (meson MOUNT_PATH -> util-linux-minimal's
  /nix/store/..., absent on card) and died one by one with status=203/EXEC.
  None is needed here: mask all five (/tmp stays an ext4 dir). Also masked
  systemd-hwdb-update (binary not in this nixpkgs build), coredump socket+
  service (no gdb; cores would eat p2 across crash loops) and the udev trio
  + load-credentials (SDL3 built with -DSDL_LIBUDEV=OFF, nothing consumes it).

Self-diagnosis for whatever kills reader.lua next: start-koreader.sh now logs
stdout/stderr to /data/koreader/{stdout,stderr}.log and prints the previous
attempt's stderr tail to ttymxc0 before each relaunch — a crash loop becomes
visible on serial without journal access. New P8.9 probe fingerprints all 67
koreader libs (count + byte total) so flash holes in that tree are caught like
the journald/networkd/luajit ones.

VERSION_ID=0.5-gbmfix; NIX-LIFEHACKS §12 extended.
2026-10-11 11:41:19 +02:00
distfiles nixos booting with display 2026-10-06 14:14:11 +02:00
image systemd PID1: fix unit path + enablement so p2 actually boots koreader 2026-10-11 01:00:15 +02:00
initrd koreader crash fix: initrd owns GBM symlink + self-diagnostic stderr + mask broken units 2026-10-11 11:41:19 +02:00
kernel nixos booting with display 2026-10-06 14:14:11 +02:00
koreader koreader working 2026-10-08 10:34:34 +02:00
lib enable touchscreen with touchscreen 2026-10-08 11:52:21 +02:00
rootfs koreader crash fix: initrd owns GBM symlink + self-diagnostic stderr + mask broken units 2026-10-11 11:41:19 +02:00
uboot image build working 2026-09-26 18:29:43 +02:00
.gitignore systemd PID1: fix unit path + enablement so p2 actually boots koreader 2026-10-11 01:00:15 +02:00
flake.lock Tolino page 2: fix image build end-to-end + docs 2026-09-24 14:29:15 +02:00
flake.nix systemd PID1: fix unit path + enablement so p2 actually boots koreader 2026-10-11 01:00:15 +02:00
NIX-LIFEHACKS.md koreader crash fix: initrd owns GBM symlink + self-diagnostic stderr + mask broken units 2026-10-11 11:41:19 +02:00
POWER-GUIDE.md nixos booting with display 2026-10-06 14:14:11 +02:00
prepare-distfiles.sh Tolino page 2: fix image build end-to-end + docs 2026-09-24 14:29:15 +02:00
prepare-koreader-deps.sh Tolino page 2: fix image build end-to-end + docs 2026-09-24 14:29:15 +02:00
README.md systemd PID1: fix unit path + enablement so p2 actually boots koreader 2026-10-11 01:00:15 +02:00

Tolino page 2 → SD card image that boots straight into KOReader (Nix flake)

Everything here is cross-built from a x86_64/aarch64 Nix host for the Tolino page 2 (ntx_6sl / E60QV0, Kobo Aura 2 family — i.MX6SL Cortex-A7, 512 MB RAM, 7" e-paper driven by the SoC EPDC controller). The build output is a single zstd-compressed card image (~200 MB in the store; decompresses to the full 15 GB card):

nix build .#sdcard-image          # → result/tolino-page2-koreader.img.zst (+.sha256)
zstd -dc result/tolino-page2-koreader.img.zst | sudo dd of=/dev/sdX bs=1M status=progress   # device OFF

systemd as PID 1 (no compositor, no X/Wayland): the kernel boots into a minimal initramfs that extracts the EPDC waveform firmware and loads the display/touch/battery modules, then hands over to a tiny rootfs where systemd runs KOReader on the e-paper panel via SDL3 KMSDRM (Restart=always) plus an interactive shell on the debug serial port.

The hardware bring-up (kernel config/DTS, u-boot defconfig, waveform location, module order, orientation) was first verified with a full postmarketOS port — see ../pmos/TOLINO-PAGE2-SETUP.md, ../pmos/PAGE2-IMPLEMENTATION.md and the working export in ../pmos/docker/out/tolino-page2-pmos-systemd.img. This flake reuses that verified setup and strips away everything else.


1. Image layout (byte-exact)

offset            what                                    where it comes from
───────────────── ─────────────────────────────────────── ──────────────────────────────
0x000000 / s0     MBR (msdos): p1 boot @s49152, p2 root  sfdisk in image/default.nix
                  to card end. msdos on purpose: a GPT header would sit at LBA1 and
                  collide with the sector-2 u-boot embed.
0x000400 / s2     u-boot.imx (SPL+u-boot, ~680 KB)       uboot derivation; byte-compared
                  U-Boot's own env lives in ext4 file      in build-time verification.
                  /uboot.env on p1 — NOT created: the
                  working pmOS export has none either, and
                  distro boot finds /extlinux/extlinux.conf
                  without it (defconfig bootcmd =
                  "run distro_bootcmd ; fastboot 0").
0x6FFFF0 …        EPDC waveform container ("Kobo hidden"  pre-extracted 2 MB window from the
0x900000          format: magic FF F5 AF FF 78 56 34 12   stock card backup (distfiles/);
                  + u32 LE length + payload. Sits in the   spliced verbatim into the image;
                  unpartitioned gap [s2 … s49152).          magic re-verified after splice.
p1 TOLINO_BOOT    /vmlinuz  /initramfs  /extlinux/extlinux.conf  /imx6sl-tolini-page2.dtb
(512 MiB ext4)    (DTB also under /dtbs/ — pmOS layout; u-boot loads the p1-root copy,
                  name MUST include the .dtb suffix to match the `fdt` line)
p2 TOLINO_ROOT    rootfs derivation: systemd (PID 1) + busybox (serial shell) +
                  /usr/lib/koreader + bundled libs + units
(ext4 → end of    + empty persistent dirs /data/koreader, /Books
card ≈ 15.9 GB)

Card geometry constants live in `lib/constants.nix` (31116288 sectors = the vendor
capacity of the internal Samsung card; a larger real card is fine to flash onto).

2. Boot flow, step by step

  1. U-Boot (card sector 2) runs its built-in default env → distro boot reads /extlinux/extlinux.conf from p1: loads /vmlinuz, /initramfs, fdt /imx6sl-tolini-page2.dtb, and the append line:

    console=ttymxc0,115200 console=tty1 fbcon=rotate:3 root=LABEL=TOLINO_ROOT rw rootfstype=ext4 rootwait
    
    • console=tty1 LAST = default/panic console → kernel printk lands in the VT that fbcon renders to the panel (upright, thanks to fbcon=rotate:3 = 270° CW — same direction as KOReader's forced-portrait rotation; verified upright on device).
    • ttymxc0 = the debug serial console — interactive shell via serial-console.service, and where every initramfs P-mark lands.
    • Note: with an initramfs present, the kernel does not honor root= itself — see §3.
  2. initramfs /init (busybox ash script, runs as PID 1; kernel exec'd it directly): 0. Mounts proc/sys + devtmpfs explicitly. This is load-bearing: when an initramfs has an executable /init, the kernel skips prepare_namespace() entirely (verified in mainline init/main.c; behaviour unchanged across these versions), so neither the real root nor devtmpfs are mounted automatically.

    1. Extracts the EPDC waveform from the card itself — extract-kobohidden /dev/mmcblk0 14336 reads the Kobo hidden container and writes /lib/firmware/imx/epdc/epdc.fw. (The image builder also splices a pristine copy of that window into every built card, so this works on freshly flashed cards without any stock content.)
    2. Loads modules in dependency order: simple-mfd-i2c → sy7636a-regulator (VCOM supply) → rtc-rc5t619 → rn5t618-power (battery gauge) → backlight-lm3630a (frontlight) → evdev (/dev/input/event* — required for SDL to see any input at all) → ektf2127 (touch), and mxc_epdc_drm LAST — it probes on load and needs both the firmware file and the VCOM regulator to already exist.
    3. Waits up to 5 s for /dev/dri/card0.
    4. Mounts TOLINO_ROOT at /rootfs (by label, /dev/mmcblk0p2 fallback), mounts fresh proc/sys/devtmpfs instances directly on the real root's directories, plus cgroup2 on /sys/fs/cgroup and tmpfs on /run (systemd requires both; this musl build cannot mount them itself), then exec switch_root -c /dev/console /rootfs /sbin/init. Before handover it exports $SYSTEMD_EXECUTOR_PATH and $SYSTEMD_UNIT_PATH=/etc/systemd:/usr/lib/systemd — the binary's compiled-in search paths are Nix store dirs absent on card (see NIX-LIFEHACKS §12).

    Why not just exit 0: PID 1 exiting panics the kernel ("Attempted to kill init") — there is no fall-through that mounts the real root. switch_root (busybox applet, verified compiled in) deletes the ramfs contents (frees RAM), overmounts / with the new root and execs its init. The fresh pseudo-fs instances are mounted on the new root's own directories because mounts that live under the old ramfs do not survive switch_root.

  3. rootfs — systemd runs as PID 1 (/sbin/init). The shipped initialized /etc/machine-id suppresses first-boot preset application, so exactly the units enabled on disk start (no distro packaging, no presets):

    • serial-console.service → interactive /bin/sh on ttymxc0 (USB-serial), respawned forever.

    • touchremap.service → touch axis-remap daemon; touchdiag.service → one-shot input diagnostics into the journal.

    • Package units from the systemd package provide journald, tmpfiles-setup (recreates the GBM backend symlink on the fresh /run), networkd/resolved (idle, no interface yet) et al. via their shipped *.target.wants dirs.

    • koreader.service → /usr/bin/start-koreader.sh, Restart=always:

      SDL_VIDEODRIVER=kmsdrm        # take DRM master on /dev/dri/card0 (mxc_epdc_drm)
      LIBGL_ALWAYS_SOFTWARE=1       # no GPU on this SoC path
      GALLIUM_DRIVER=swrast         # lightest EGL/GLES impl for 512 MB RAM
      EMULATE_READER_FORCE_PORTRAIT=1   # KOReader's built-in -90° CCW blitter rotation
      HOME=/root                    XDG_DATA_HOME=/data/koreader (settings/history)
                                    XDG_DOCUMENTS_DIR=/Books    (library root)
      

      SDL3's kmsdrm backend dlopen()s libEGL/libGLESv2/libgbm/libdrm at runtime — those stay shared and are bundled under /usr/lib/koreader/libs/. The luajit interpreter itself is dynamically linked against the musl loader (rootfs recreates its store-path PT_INTERP dir), so dlopen works. Their exit-code-85 clean-relaunch convention is kept (SuccessExitStatus=85); any other exit gets systemd's 3 s RestartSec respawn.

3. Derivations

All sources are pinned tarballs in distfiles/ with sha256 checks that abort flake evaluation if anything is missing or tampered (lib/sources.nix → checkAll). Regenerate any of them with ./prepare-distfiles.sh.

package what it builds how
kernel linux-tolini-page2-v7.3-rc6-a90ee430: Image, all modules + depmod metadata, DTBs mainline torvalds/linux @ v7.3-rc6 (replaces the stale akemnade fork "7.1.10" — mainline already has every board driver in-tree: ektf2127/sy7636a/rn5t618/rc5t619/lm3630a, plus the other Tolino/Kobo DTSes). Minimal config = the pmOS port's slimmed imx-ereader config re-synced against v7.3-rc6 with make ARCH=arm olddefconfig (no user option dropped). Patches: 0005 backports the NXP mxc-epdc DRM driver (drivers/gpu/drm/mxc-epdc/, still not upstream) + epdc node compatible/clocks in imx6sl.dtsi; 0002 adds the page-2 board DTS (page 2 is missing from mainline's Tolino set), rebased onto v7.3-rc6; 0004 ektf probe readiness poll. Built with the gnu armv7hf cross toolchain (kernel links no libc; musl only slows it down).
uboot u-boot.imx (= u-boot-dtb.imx) akemnade/u-boot-fslc @ pinned sha, mx6sltolinoshine3_defconfig + ENV_IS_IN_EXT4 on mmc 0:1 — build steps identical to the pmOS APKBUILD; MR !5542 proved this exact u-boot boots the page 2.
koreader dynamically-linked luajit + read-only app tree (Lua, frontend, resources) with all C code in libs/libkoreader-monolitic.so (+ libSDL3.so) KOReader v2026.07.2 via its own build system under musl armv7hf cross (MONOLIBTIC=1, the Android-style single-.so bundle). Local patches: 0001 adds a TARGET=linux-cross sibling of their linux target (the stock target forces the host compiler) and statically links libstdc++ into the monolitic .so; 0002 switches SDL3 to KMSDRM (+ shared libSDL3.so.0). The luajit interpreter exports its symbols (-Wl,-E, from LuaJIT's own Makefile) so the C-module .sos bind their undefined lua_* refs at dlopen time — the same mechanism as upstream kobo/desktop bundles. Not one fully-static executable: musl ≥ 1.2 ships only a dlopen() stub in static libc.a, and every loader rejects dlopen("/proc/self/exe"), so a static binary could never load its C modules or SDL3's runtime libs (patches 0003/0004 implemented that dead-end; they stay inert while static = false).
extractKobohidden static waveform extractor vendored verbatim (MIT) from pmos/kobo-firmware-extractor; compiled with -static, asserted to have no dynamic section.
initramfs gzip cpio, a few MB: static busybox + needed applet symlinks, extractor, /init, kernel modules + modules.dep assembled host-side, no target compilation.
rootfs the p2 tree (see §2.3) assembles KOReader tree + bundled shared libs (hunted by name across mesa/libgbm/libdrm — layout-proof) + swrast DRI driver + musl loader/libs (/lib) + a recreated store-path PT_INTERP dir so the dynamically-linked luajit can exec; hard-fails if any ELF's DT_NEEDED is unresolvable on the tree.
sdcard-image (default) the flashable card as tolino-page2-koreader.img.zst + sha256 (~200 MB; decompresses to 15 GB) no loop devices, no mounts: partitions are built as standalone ext4 files with mkfs.ext4 -d <dir> and spliced into a card-sized sparse file at their byte offsets; then u-boot @s2 and the waveform window are dd'd in. Hard-fails on: bad MBR signature, u-boot embed mismatch (full byte compare), wrong waveform magic, or any missing file checked via debugfs -R stat. The verified raw card is zstd-compressed straight into $out — it never enters the store as a 15 GB file, so remote builders transfer ~200 MB instead of 15 GB.

Build hosts: x86_64-linux and aarch64-linux (the image always targets armv7hf).

4. Building

nix build .#sdcard-image                 # compressed card (~200 MB; decompresses to the 15 GB card)
nix build .#kernel                       # individual pieces, e.g. for iterating on the DTS
nix build .#koreader && ls $(nix eval .#koreader --raw)/   # poke at the app tree
nix shell .#devShell                     # host tools: coreutils, e2fsprogs, file

First builds do a full cross toolchain + kernel + KOReader compile (expect a long first run; everything is cached afterwards). The flake evaluates its distfile hashes before any build.

warning: Git tree … is dirty — normal while iterating; use --no-write-lock-file / commit when done. cannot build on 'ssh://root@comp' — a stale remote-builder entry in your nix config that this host can't resolve; the build transparently falls back to local (harmless). Silence it with nix build --option additional-substituters '' … or fix remote-builders-kill-timeout/builders in /etc/nix/nix.conf.

5. Flashing

Device OFF. The Tolino boots from its single micro-SD slot (the "internal" storage IS the card — there is no second slot and no fastboot mode). Put your working card in a USB reader:

ZST=$(nix eval .#sdcard-image.out-link --raw)/tolino-page2-koreader.img.zst   # or result/…
DEV=/dev/sdX                                          # the whole disk, never a partition!

# guards (mirror ../pmos/docker/flash-sdcard.sh):
case "$DEV" in */[0-9]) echo "ABORT: that's a partition"; exit 1;; esac
grep -q " $DEV " /proc/mounts && { echo "ABORT: mounted!"; exit 1; }

zstd -dc "$ZST" | dd of="$DEV" bs=1M status=progress conv=fsync
sync

# readback sanity — BOTH regions, or a partial write passes the check:
# (a) waveform magic @ 0x6FFFF0 (expect fff5afff78563412):
dd if="$DEV" bs=1 skip=7340016 count=8 | od -A n -t x1
# (b) the whole ROM-visible region [card 0 .. boot_data.size): MBR + sector-2 u-boot.
# A failed dd here = dead device with zero serial output, while check (a) still passes.
dd if="$DEV" bs=512 count=944 status=none | cmp - <(zstd -dc "$ZST" | head -c 483328) \
    && echo "ROM region OK" || { echo "FLASH CORRUPT — re-flash"; exit 1; }

Insert the card, power on. First boot shows kernel text on the panel (upright), then KOReader's splash. rootwait + the 5 s DRM wait keep early failures visible in the console scrollback (Shift+PgUp) instead of a dead screen.

6. On-device operation & data

  • Books: drop EPUB/PDF into /Books on p2 before flashing (mount the card's second partition on any Linux box), or extend rootfs/ with a books/ input directory — the Tolino has no usable USB host port for storage and this image ships no wifi driver (see §8).
  • State: KOReader settings/history live in /data/koreader on p2; both dirs are created at build time and by rcS, so a re-flash converges.
  • Frontlight / battery: exposed through the standard sysfs nodes (backlight-lm3630a, rn5t618-power) that KOReader's SysfsLight/power code reads — modules are already loaded at first boot.
  • Orientation: if content ever shows rotated/flipped, the two knobs are fbcon=rotate:3 (kernel text console) and EMULATE_READER_FORCE_PORTRAIT=1 + SDL's KMSDRM rotation (KOReader). Both values were verified upright on device in the pmOS port; change one at a time.

7. What was verified against the working pmOS port

item evidence
kernel config flake kernel/config.armv7 = the pmOS port's slimmed imx-ereader minimal config, re-synced against v7.3-rc6 with make ARCH=arm olddefconfig; verified no user option dropped (only auto-symbols churn + one invalid NETFILTER_NETLINK=m fixed to =y)
kernel/u-boot sources distfile tarballs produced with git archive from pinned refs: torvalds tag v7.3-rc6 (local clone) and the akemnade u-boot commit; hashes recorded in lib/sources.nix, u-boot's cross-checked against the pmOS APKBUILD sha512 entry
u-boot build config flake uboot/default.nix runs the exact 6 commands of pmos/device/testing/u-boot-tolino-page2/APKBUILD
extlinux/DTB layout inspected the working export (../pmos/docker/out/tolino-page2-pmos-systemd.img) via loop mount: p1 root holds imx6sl-tolini-page2.dtb, conf says fdt /imx6sl-tolini-page2.dtb, no /uboot.env present
u-boot boot path defconfig BOOTCOMMAND="run distro_bootcmd ; fastboot 0" + the working image above (boots with no env file)
waveform format/offsets magic ff f5 af ff 78 56 34 12 at byte 0x6FFFF0 in both the stock card dump and our pre-extracted distfile; sector-14336 convention from pmos/kobo-firmware-extractor
module order superset of device-tolino-page2/modules-initfs, ordered per pmOS r2/r3 changelog (SY7636A VCOM before EPDC)
cmdline/orientation mirrors kernel-cmdline.conf + extlinux append, minus plymouth/UUIDs; rotate:3 verified upright in the r5 device test
busybox applets built nixpkgs' busybox (same musl-static recipe): CONFIG_SWITCH_ROOT=y, PIVOT_ROOT=y, MOUNT=y+FEATURE_MOUNT_LABEL=y, FANCY_SLEEP=y, MKNOD/INSMOD/MODPROBE/INIT all present
kernel init semantics read from the pinned tree itself: with executable /init, prepare_namespace() is skipped (real root + devtmpfs not auto-mounted) → explicit mount + switch_root required; exit 0 would panic

8. Known limitations & risks

  • No network. The slim kernel config keeps mac80211 symbols for the out-of-tree rtl8189fs wifi driver, but this flake does not build that driver (the tarball sits in distfiles/ as a leftover from the pmOS work). KOReader's sync/wifi features are unavailable; add books via p2.
  • Touch calibration (handled by touchremap). The eKTF2232 reports axes rotated vs its registered ABS ranges (X 0..1919 / Y 0..1435 registered, actual events use the swapped extents — long axis on raw Y). SDL3 KMSDRM reads /dev/input/event* directly and this image has no udev/libinput to host a calibration matrix, so usr/bin/touchremap (busybox-init respawned) fills that gap: it EVIOCGRABs the ektf2232 node, clones it through uinput as tolino-touch, and applies an affine matrix from /data/touch-matrix.txt to normalized coordinates. The default is the on-device-verified pmOS geometry (x'=V, y'=H); all eight rotation candidates are pre-seeded as comment lines in that file. Tuning without re-flashing (serial shell): edit /data/touch-matrix.txt so exactly one candidate row is active, then kill -USR1 $(pidof touchremap) and restart KOReader (kill $(pidof reader.lua) — init respawns it). Inspect raw geometry with touchremap -w (stop the daemon first; prints one decoded line per frame). When there is no touch at all, don't guess: every boot prints a touch diag: block on the serial console and /usr/bin/touchdiag dumps modules + input devices + i2c map + dmesg with verdict hints (§9). Note that "no ektf2232 device" means the kernel-side probe failed (the daemon only remaps an existing node) — see ../pmos/PAGE2-IMPLEMENTATION.md journal #16–17. Even a healthy clone is invisible to SDL unless listed: our SDL3 is built with -DSDL_LIBUDEV=OFF, and without udev its evdev backend does NOT scan /dev/input — it only opens nodes named in the SDL_EVDEV_DEVICES env var (deviceclass:path, class 16 = touchscreen), which start-koreader.sh sets from the tolino-touch clone's node (resolved by name on every KOReader launch, waiting ~30 s for it). A missing clone or a "no tolino-touch clone" WARNING on serial means touchremap never came up. Details: docker/touch-calib/README.md.
  • Headless failure mode. No serial connector, no reset button behavior beyond power cycle; a bad kernel/cmdline change = dark panel until you re-flash from the reader. Iterate on a spare card if possible.
  • 512 MB RAM / Cortex-A7. swrast EGL is deliberately chosen over any GPU path; heavy KOReader features (epub reflow of huge files, web) will be slow.
  • Not NixOS yet. The rootfs is busybox by design for size and simplicity. Roadmap to a minimal NixOS root: keep kernel/u-boot/initramfs-handoff/image assembly as-is; replace the rootfs derivation with nixosSystem { modules = [ ./tolino.nix ]; } built from the glibc cross instance (pkgsCross.armv7l-hf-multiplatform); KOReader becomes a root systemd service (Restart=always replaces the inittab respawn loop); disable gettys/login/networking; source the dlopen'd libs (libEGL/GLESv2/gbm/drm + swrast_dri.so) from glibc mesa/libdrm instead of musl. The kernel derivation would additionally need wrapping into a standard linuxPackages- shaped attrset for boot.kernelPackages.

9. Troubleshooting

symptom likely cause / fix
build aborts at evaluation with "distfile check failed" a tarball in distfiles/ is missing or changed — re-run ./prepare-distfiles.sh (do not hand-edit hashes)
panel stays dark, console text visible on ttymxc0 log (if you wire UART) waveform extraction failed (check "ERROR: waveform extraction" line) → bad card splice; verify magic at 0x6FFFF0 on the flashed card
kernel panics right after "switching to rootfs" TOLINO_ROOT label missing (mkfs -L not applied?) or ext4 fs corruption — check p2 with debugfs -s <rootStart> "$IMG"
KOReader respawns in a loop ("koreader exited") dlopen failure of bundled libs (wrong arch/ABI) → rebuild rootfs; orientation/env mismatch is not fatal, it just draws wrong
no touch at all every boot now prints a touch diag: block on the serial console (modules, input names, i2c map with driver binding). Run touchdiag in the serial shell and read its verdict hints: module missing → ERROR: insmod … line in the boot log; i2c client 1-0015 unbound or ektf errors in dmesg (EIO flood = chip never answered) → kernel/probe problem, not a userspace one
rotated/flipped content §6 orientation knobs; change one at a time and note which layer (console vs KOReader) is off

10. Repository layout

flake.nix                  outputs: packages.<host>.{default,sdcard-image,kernel,uboot,
                           koreader,initramfs,rootfs,extractKobohidden} + devShell
lib/constants.nix          every hardware/image constant (offsets, labels, module order, cmdline)
lib/sources.nix            pinned distfiles + eval-time sha256 gate (+ build-time verify snippet)
prepare-distfiles.sh       regenerate distfiles from the src-clones/ git checkouts
kernel/                    default.nix + config.armv7 (= pmOS port's config) + patches 0002, 0004
uboot/default.nix          defconfig + env-in-ext4, identical steps to the pmOS APKBUILD
koreader/                  default.nix (linux-cross target, MONOLIBTIC dynamic bundle; static=experimental) + patches 0001-0007
initrd/                    init (bootstrap script), extract-kobohidden.{c,nix}, default.nix (cpio)
rootfs/                    units/, start-koreader.sh.in, touchremap.c/touchdiag.sh, default.nix (p2 tree)
image/default.nix          card assembly + hard-failing verification
distfiles/                 pinned source tarballs + pre-extracted waveform window (git-tracked:
                           nix requires paths inside the flake; they are hash-gated at eval time)
NIX-LIFEHACKS.md           every non-obvious Nix trick/gotcha that made this build work, with
                           problem → fix → where-in-repo (read before "simplifying" a comment)