diff --git a/README.md b/README.md index 7063d4a..a8d656a 100644 --- a/README.md +++ b/README.md @@ -52,6 +52,7 @@ scenario tests (portal, OTA apply, display + touch, watchdog). | Directory | Contents | |---|---| | `patches/` | the RV1106 forward-port onto pristine linux-6.18.46, subsystem-split | +| `luckfox-sdk-patches/` | the delta against the **legacy** vendor Luckfox SDK (U-Boot 2017.09, optionally the vendor 5.10.160 kernel, wifi driver, board build, buildroot) -- moved from `blueflare/flare-edge`'s `sdk-patches/` on 2026-09-15; unrelated to `patches/` above | | `build/` | hermetic kernel build: pinned fetch -> apply patches -> `zImage` + dtb; `vendor.manifest` pins the third-party trees this platform builds against (LVGL, the vendor RV1106 SDK) to exact commits, and `fetch-vendor.sh` obtains and verifies them | | `qemu/` | device simulator: QEMU `-M virt` boots the real kernel and real userspace | | `sim/` | register-level hardware models (Rust): membus, HPMCU, CRU, Modbus, RGA, NPU | diff --git a/build/vendor.manifest b/build/vendor.manifest index a9b957a..b0922ed 100644 --- a/build/vendor.manifest +++ b/build/vendor.manifest @@ -24,8 +24,9 @@ # vendor SDK ships 2023.02.6 -- so that tree is not in the vendor checkout, was # not in this manifest, and had no recorded origin at all. A clean rebuild # silently used the vendor's older buildroot and produced a different userspace -# (flare-edge#135). Our delta on top of it is captured in the flare-edge repo at -# sdk-patches/buildroot/. +# (flare-edge#135). Our delta on top of it is captured in this repo at +# luckfox-sdk-patches/buildroot/ (moved 2026-09-15 from the flare-edge repo's +# sdk-patches/buildroot/). # # Format: nameurlcommitdescription # Blank lines and lines starting with '#' are ignored. diff --git a/luckfox-sdk-patches/README.md b/luckfox-sdk-patches/README.md new file mode 100644 index 0000000..a0a449b --- /dev/null +++ b/luckfox-sdk-patches/README.md @@ -0,0 +1,311 @@ +# luckfox-sdk-patches + +The Luckfox SDK (`LuckfoxTECH/luckfox-pico`, pinned in `../build/vendor.manifest` +as `luckfox-pico`) is a ~2 GB vendor checkout and is deliberately **not** in +this repo. Our changes to it were, until now, living only as uncommitted +edits in one person's working copy -- which is how a stale second copy on +another machine came within one command of silently reverting a day of work. +This directory is the tracked form of those changes. + +**Moved here 2026-09-15** from `sdk-patches/` in `blueflare/flare-edge` +(source commit `flare-edge@86d4633`), so the SDK repo -- not the firmware +repo that merely consumes it -- is the single canonical home for every +kernel/U-Boot/driver delta. flare-edge's `tools/build-firmware.sh` and +friends now read this directory through the `vendor/warden-sdk` submodule +instead of a same-repo `sdk-patches/`. + +**Vendor base: `824b817f8`** of +(`Pullrequest 260319 (#355)`) -- the same commit `../build/vendor.manifest` +pins. Every patch here is `git diff` against that commit and has been +verified with `git apply --check` against a pristine tree at that revision. +If the vendor base moves, re-verify before trusting them. + +**Not `patches/`, and not `sdk/`.** This repo's top-level `patches/` is a +different, unrelated thing: the from-scratch Linux 6.18.46 forward-port +series (see `../patches/README.md`). `luckfox-sdk-patches/` patches the +**legacy** vendor tree instead (U-Boot 2017.09 and, optionally, the vendor +5.10.160 kernel) -- naming it `luckfox-sdk-patches/` keeps the two +unmistakable next to each other. It also isn't named plain `sdk/`, carrying +forward the original naming rule from its flare-edge home: that repo's +`ui-src/pkgconfig-stub/libdrm.pc` resolves `${pcfiledir}/../../sdk`, so a +directory named `sdk/` anywhere it might be checked out alongside would +shadow the real vendor SDK checkout. That specific collision cannot happen +in this repo, but the name stayed to avoid a second rename and to keep the +provenance trail (wiki, commit messages, flare-edge doc citations) legible +across the move. Do not rename it. + +## License + +Everything here is a `git diff` against Rockchip/Luckfox's GPL-2.0 vendor +U-Boot (2017.09) and Linux (5.10.160) forks, plus a handful of small +standalone files we authored (`uboot/include/flare_touch.h`, +`uboot/include/flare_trace.h`, the bluez5 `wordexp.h` compat shim, the mpv +Bessel-function patch). The diffs are themselves GPL-2.0 derivative work, +consistent with this repo's repo-wide GPL-2.0-only license (`../LICENSE`); +the small standalone files carry no GPL restriction of their own but are +distributed here under the same license for simplicity. Unlike `../patches/` +(the 6.18 port), no per-driver provenance ledger exists for this directory +yet -- everything here predates that convention. If one is wanted, it +belongs beside `../kernel/rv1106-enablement/PROVENANCE.md`. + +## Layout + +``` +luckfox-sdk-patches/uboot/patches/ diffs against sysdrv/source/uboot/u-boot/ +luckfox-sdk-patches/uboot/configs/ new config fragments (not patches -- whole new files) +luckfox-sdk-patches/uboot/include/ new source files +luckfox-sdk-patches/kernel/patches/ diffs against sysdrv/source/kernel/ +luckfox-sdk-patches/kernel/configs/ new kernel config fragments +luckfox-sdk-patches/wifi/patches/ diffs against sysdrv/drv_ko/wifi/ (out-of-tree modules) +luckfox-sdk-patches/board/patches/ diffs against project/ (board .mk + the build driver) +``` + +Paths inside each patch are relative to the vendor SDK root, so apply with +`-p1` from there: + +```sh +cd /path/to/vendor/sdk +for p in /path/to/warden-sdk/luckfox-sdk-patches/uboot/patches/*.patch \ + /path/to/warden-sdk/luckfox-sdk-patches/kernel/patches/*.patch \ + /path/to/warden-sdk/luckfox-sdk-patches/board/patches/*.patch; do + git apply --check "$p" && git apply "$p" +done +cp /path/to/warden-sdk/luckfox-sdk-patches/uboot/configs/*.config sysdrv/source/uboot/u-boot/configs/ +cp /path/to/warden-sdk/luckfox-sdk-patches/uboot/include/*.h sysdrv/source/uboot/u-boot/include/ +cp /path/to/warden-sdk/luckfox-sdk-patches/kernel/configs/*.config sysdrv/source/kernel/arch/arm/configs/ +``` + +**You no longer have to run the above by hand.** flare-edge's +`tools/build-firmware.sh` (in the `blueflare/flare-edge` repo, which carries +this SDK as the `vendor/warden-sdk` submodule) applies everything in +`luckfox-sdk-patches/` (patches idempotently, config fragments by copy) +before it builds -- see its `apply_sdk_patches` step. The manual recipe is +kept here as documentation of *what* that step does and for one-off use against +a pristine tree. Idempotency rule the script uses per patch: if +`git apply --reverse --check` succeeds the patch is already in the tree and is +skipped; else if `git apply --check` succeeds it is applied; else it is a hand- +patched SDK carrying an equivalent (or a genuine conflict) and the script warns +and continues rather than aborting the build. + +## What each patch does + +### `uboot/patches/0001-display-and-boot-timing.patch` + +The U-Boot boot logo never appeared at all before this, and four separate bugs +had to be fixed before it did. Each was measured on hardware, not inferred. + +| file | fix | +|---|---| +| `rockchip_display.c` | `malloc` -> `calloc`. `enabled_at_spl` is only ever assigned under `#ifdef CONFIG_SPL_BUILD`, so in U-Boot proper it read uninitialised heap. Garbage read as truthy meant `display_enable()` skipped the connector pre-enable/enable path -- the only path that reaches `backlight_enable()`. | +| `pwm_backlight.c` | `args.args[2] & 1`. The DT has `pwms = <&pwm1 0 100000 50000>`; assigning `50000` to a `bool` polarity field inverted the PWM. Measured `DUTY=0x26e8` (99.6%) with `CTRL=0x13`; after the fix `CTRL=0x0b`. The backlight was running at 0.4%. | +| `clk_rv1106.c` | Two bugs. `rv1106_clk_set_rate()` returned a stale `ret` instead of the computed `rate`, so it always reported 0 Hz. And `DCLK_VOP_DIV_MASK` is 5 bits (max ÷32) while `DIV_ROUND_UP(1188 MHz, 30 MHz) = 40` wrote 39, truncated to 7 -- **the VOP was running at 125 MHz, not 30**. Now clamps to 32, picks the closest parent, and retunes CPLL 1000 -> 960 MHz when neither divides evenly, giving exactly 30.000 MHz. | +| `rockchip_panel.c` | `FLARE_PANEL_SETTLE_MS`: wait after scanout starts before switching the backlight on. See the comment in the file -- it distinguishes two artefacts that look similar and have different causes. | +| `board.c` | Release `RGB_RES` (GPIO0_A1) at the top of `board_init()` instead of `board_late_init()`, and `FLARE_TRACE` instrumentation. `setup_download_mode()` is deliberately kept **first** in `board_late_init()`: moving the logo ahead of it pushed BOOT-key sampling from 1.18 s to ~4-5 s and the key had to be held for eight seconds. | +| `rv1106-u-boot.dtsi` | `u-boot,spl-boot-order = <&emmc>`. It was `<&sdmmc, &spi_nor, &spi_nand, &emmc>` -- the only fitted medium was last. Walking the dead entries cost **267 ms** every boot: ~212 ms failing to identify a non-existent SPI-NAND (`unknown raw ID 0 0 0`) and ~57 ms probing an SD slot this board does not have (`sdmmc` is wired to the AIC8800 WiFi as SDIO). **This file is shared by every rv1106 U-Boot build in the tree**; an SD- or SPI-NAND-booting variant would no longer boot. | +| `console.c` | Timestamp every console line, including from SPL. Needed two fixes: the stock code formats with `%5lu.%06lu`, which `CONFIG_USE_TINY_PRINTF` cannot render (it supports only `%c %s %u %d %x`), and it hooked `puts()`, which SPL never calls -- tiny printf goes character-at-a-time through `putc()`. Costs 324 B of SPL. | +| `rockchip_post_csc.c` | Add `#include `. An upstream SDK bug, not a consequence of our config -- the vendor's own `rv1106_defconfig` also lacks `CONFIG_DM_I2C`. | + +### `uboot/patches/0002-boot-robustness.patch` + +Unattended recovery: `spl-boot-order.c` + `spl.c` register `BOOT_DEVICE_BOOTROM` +as a last-resort SPL load method so a failed U-Boot load drops to MaskRom +instead of hanging, and `bootcount/Kconfig` exposes `BOOTCOUNT_LIMIT` so +repeated boot failures fall through to `altbootcmd`. The defconfig change adds +the bootcount variables to `CONFIG_ENVF_LIST`. + +**Provenance note:** this is boot-robustness rather than display work and may +overlap with reliability work done in a parallel session. Review before merging. + +### `kernel/patches/0001-panel-mcu-reset-and-logo-route.patch` + +Two hunks, both display: + +- **`&panel`** -- removes `reset-gpios` and `reset-delay-ms`. GPIO0_A1 is *not* + the panel's reset. Per the 86Panel schematic, net `RGB_RES` ties SoC GPIO0_A1, + the panel RESET pin (FPC 6) and the `NRST` of a WCH **CH32V003** MCU (U6) + together; that MCU's only wired pins are SPI to the same FPC, and its sole job + is to clock the panel's initialisation sequence in. Handing the GPIO to + `panel-simple` therefore made `drm_panel_prepare()` **reboot the panel + initialiser while the VOP was already scanning out** -- which is the faint + coloured vertical banding seen for ~1-3 s on every boot, and why adding a + "reset" never cured it. Luckfox deleted these same two properties in + `e2b0ffa22`. An earlier revision of our tree re-added them, having read that + deletion as an accidental regression. **Confirmed fixed on hardware.** + `backlight` stays, because U-Boot's `rockchip_panel.c` takes its backlight + handle from this node. +- **`&route_rgb`** -- `status = "okay"`. The rest of the RGB pipeline is already + enabled in `rv1106-luckfox-pico-86panel-ipc.dtsi`; `route_rgb` was the only + piece left off, and without it U-Boot's `rockchip_display` finds no route and + skips drawing entirely. + +Deliberately **excluded** from this patch, though present in the same file in +the working tree: the `model` rename, and a `dr_mode = "peripheral"` revert that +was a bench workaround to keep the USB network gadget stable for flashing. The +latter is superseded by the live USB role-switching work on `main`. + +### `kernel/patches/0005-pstore-ramoops.patch` + +Adds a `ramoops@0f000000` node (1 MiB @ 240 MiB) to `reserved-memory` in +`rv1106-luckfox-pico-86panel-ipc.dtsi` so pstore/ramoops has a DRAM region that +survives a reset. Pairs with the `CONFIG_PSTORE*` lines in +`kernel/configs/flare-edge.config`: the kernel console ring + oops/panic survive +into the next boot (`/sys/fs/pstore`), which is the ONLY way to diagnose a +pre-userspace hang (the c8a3 `0x40000` class) with no serial console. Placed +HIGH, above the low kernel-image/DTB/initrd zone, so the carve-out can only +remove kernel RAM -- it cannot recreate the c8a3 under-reservation collision. +Needs a `boot.img` reflash. + +### `kernel/patches/0006-reboot-mode-maskrom.patch` + +Adds `&reboot_mode { mode-maskrom = <0xEF08A53C>; };` (`BOOT_BROM_DOWNLOAD`) to +the 86Panel ipc.dtsi, so the OS helper `warden-maskrom maskrom` +(`reboot(RESTART2,"maskrom")`) writes that magic to the boot-mode reg +(`0xff020200`) and the next reset enters **true BootROM MaskRom** -- where +`upgrade_tool db`+`wl` / `provision-ab.sh` flash reliably. The stock +`mode-loader`/`-bootloader` only reach U-Boot rockusb "Loader" mode, whose +multi-partition WL is unreliable (writes report 100% but may not persist). +One-shot (PMU-domain reg, cleared by POR). Verified: the DTB compiles and +carries `mode-maskrom=0xEF08A53C`. Needs a `boot.img` reflash -- and the FIRST +deployment still needs one physical-MaskRom flash (chicken-and-egg), after which +remote MaskRom flashing works. Independent hunk (end of ipc.dtsi) -- applies in +any order vs 0005. + +### `buildroot/files/package/mpv/0002-change-j1.patch` + +Swaps mpv's `j1(x)` (video/out/filter_kernels.c, backing the EWA/jinc +scalers) for a local `BesselJ1()`. Needed because this target's uClibc-ng +does not provide `j1()`/`j0()`/`jn()` -- confirmed absent from +`libuClibc-1.0.31.so` in the arm-rockchip830-linux-uclibcgnueabihf +sysroot, the same kind of gap the bluez5_utils wordexp patch works around +for a different function. + +The first version of `BesselJ1()` summed a fixed 11-term power series. +`jinc()` multiplies its argument by M_PI before calling it, and mpv's +`--scale-radius` is user-settable, so any radius reaching roughly x=20 +already returns garbage: 11 terms had not converged there, so the value +was 3.1e6 instead of the correct 0.0668, growing to 3.3e42 by x=1000. +The current version sums a term-to-term-ratio series while each new term +is still negligible (stable for the range where that converges) and +falls back to the standard second-order asymptotic expansion for Bessel +functions beyond that, checked against the host's real `j1()` across +x in [0, 5000]: max absolute error 5e-8. `tools/bessel-j1-test.sh` pulls +whatever `BesselJ1()` the patch currently carries out of the diff and +checks it the same way, so a regression back to an unconverged series +is caught there instead of showing up as scaler artifacts on a panel. + +### `buildroot/files/package/bluez5_utils/0001-add-uclibc-wordexp-compat.patch` + +Adds a `wordexp.h` at the BlueZ source root: a minimal wordexp(3)/wordfree(3) +for uClibc-ng, which this toolchain does not provide. `bluetoothctl` and a few +BlueZ tools include `` unconditionally and only ever pass +`WRDE_NOCMD` ("no command substitution"), so a whitespace/quote tokenizer is a +semantically complete substitute -- the same kind of gap the mpv `j1()` patch +above works around for a different function. + +`WRDE_APPEND` lets a caller accumulate words across more than one call onto +the same `wordexp_t`. An allocation failure partway through such a call used +to free the words the *earlier* call had already produced and leave +`we_wordv` pointing at memory `realloc()` had already relocated or freed -- +reachable any time a second `WRDE_APPEND` call runs out of memory, not only +under theoretical low-memory conditions. Fixed by capturing the pre-call word +count and only ever freeing/relocating entries at or past it. + +`tools/wordexp-test.sh` extracts `wordexp.h` from this patch's diff into a +scratch dir (nothing else in the tree has a copy -- it is a full new-file +patch, applied only during a firmware build) and runs `tools/wordexp_test.c` +against it: plain and quoted tokenizing, an unterminated quote, growth past +the initial capacity, `WRDE_APPEND` across two calls, and the allocation- +failure case above. Wired into CI's `daemons` job. + +### Seatbelt build changes (docs/firmware-update.md section 6.6) + +The firmware-update **seatbelt** (auto-revert of a bad remote reflash) needs a +handful of small U-Boot/OS build changes. Design section 6.6 lists six; items **1, 3, +4** are the low-risk, independently-shippable wiring, and they were -- until now -- present only in one person's hand-patched SDK, which is the exact "stale +second copy nearly reverted a day of work" trap that created this directory. +They are tracked here and applied by `tools/build-firmware.sh`, so a clean SDK +checkout plus that script reproduces them with no manual editing. + +| section 6.6 | tracked as | what it does | +|---|---|---| +| **item 1** | `board/patches/0001-86panel-seatbelt-wiring.patch` (first hunk) + `uboot/configs/flare-bootcount.config` | Wires the bootcount fragment into the build: appends `flare-bootcount.config` to `RK_UBOOT_DEFCONFIG_FRAGMENT` in the 86Panel board `.mk`. The fragment itself (already tracked, see the Config-fragments table) turns on `CONFIG_BOOTCOUNT{,_LIMIT,_ENV}` and the extended `CONFIG_ENVF_LIST`. Without the wiring the fragment is inert and U-Boot never counts boots -- the seatbelt's U-Boot layer (section 6.1) is silently absent. | +| **item 3** | `board/patches/0001-86panel-seatbelt-wiring.patch` (second hunk) + `board/patches/0002-build-honor-bootargs-extra.patch` | `panic=10` on the kernel cmdline (`sys_bootargs`) so a kernel panic **reboots** after 10 s instead of hanging (section 6.4). The board `.mk` sets `RK_BOOTARGS_EXTRA="panic=10"`; the second patch teaches `project/build.sh`'s `__GET_BOOTARGS_FROM_BOARD_CFG()` to append `RK_BOOTARGS_EXTRA` verbatim to `sys_bootargs` (the same place it already appends `rk_dma_heap_cma=`). That variable flows to `RK_KERNEL_CMDLINE_FRAGMENT` -> `sysdrv/Makefile`'s `KERNEL_CMDLINE_FRAGMENT` -> the actual boot args. The hook is generic and inert: a board that never sets `RK_BOOTARGS_EXTRA` is unaffected. | +| **item 4** | `kernel/patches/0002-watchdog-enable.patch` | Enables the hardware watchdog DT node -- `&wdt { status = "okay"; };` on the 86Panel board dts. `CONFIG_DW_WATCHDOG` is already built, but `rv1106.dtsi` ships `wdt` `disabled`, so `/dev/watchdog` does not exist until this override. Once present, `warden-flared` pets it only while healthy; a post-boot hang then hard-resets and converges to `altbootcmd` -> recovery, the backstop to bootcount (section 6.7). Needs a `boot.img` reflash. | + +Items **2** (provision recovery env at flash time), **5** (recovery partition + +image) and **6** (`CONFIG_ENV_OFFSET_REDUND`) are *not* build-time source +changes: item 2 is a provisioning-step env write (see `tools/envf.py` and the +flash scripts), item 5 is a partition-table + recovery-FIT change scheduled with +a hardware-validation pass, and item 6 is a hardening nice-to-have. They are +tracked where they live, not here. + +**Apply-order note.** `kernel/patches/0002-watchdog-enable.patch` and the +existing `kernel/patches/0001-panel-mcu-reset-and-logo-route.patch` both edit +the same board dts, but at non-overlapping anchors (0002 inserts after the +`&gmac` block near the top; 0001 appends `&panel`/`&route_rgb` at the tail), so +they apply in either order. Verified with `git apply --check` against the +pristine vendor base and by applying both in sequence. + +**Precise apply targets** (relative to the SDK root -- the same `-p1` convention +as every other patch here): + +- `board/patches/0001-86panel-seatbelt-wiring.patch` -> `project/cfg/BoardConfig_IPC/BoardConfig-EMMC-Buildroot-RV1106_Luckfox_Pico_86Panel-IPC.mk` +- `board/patches/0002-build-honor-bootargs-extra.patch` -> `project/build.sh` (function `__GET_BOOTARGS_FROM_BOARD_CFG`) +- `board/patches/0003-build-fix-rkvar-grep-quote.patch` -> `project/build.sh` (functions `unset_env_config_rk`, `unset_board_config_all`) +- `kernel/patches/0002-watchdog-enable.patch` -> `sysdrv/source/kernel/arch/arm/boot/dts/rv1106g-luckfox-pico-86panel.dts` + +**`board/patches/0003-build-fix-rkvar-grep-quote.patch`** -- required by item 3. +`unset_board_config_all()` reset-sources every `RK_*` var out of the board `.mk`s +with a greedy `grep -oh "^export.*RK_.*="`, whose `.*=` runs to the *last* `=` on +the line. Once item 3 adds `export RK_BOOTARGS_EXTRA="panic=10"`, that grep yields +`export RK_BOOTARGS_EXTRA="panic=` -- an unbalanced quote that makes the sourced +temp file a syntax error and aborts **every** `build.sh` invocation on a clean SDK +(`unexpected EOF while looking for matching '"'`). The fix narrows both greps +(here and `unset_env_config_rk`) to the variable **name** only, +`^export RK_[A-Za-z0-9_]*=`, dropping the value. Without this, a from-scratch +checkout cannot build the 86Panel firmware at all; the runner's hand-patched SDK +had masked it (the reproducibility gap `tools/build-firmware.sh` exists to close). +- `uboot/configs/flare-bootcount.config` is **copied** into + `sysdrv/source/uboot/u-boot/configs/` (it is a whole new file, not a diff); + the board `.mk` patch is what references it by name. + +## Config fragments + +| fragment | why | +|---|---| +| `uboot/flare-display.config` | the DRM/panel/PWM symbols the logo path needs | +| `uboot/flare-verbose.config` | `CONFIG_BOOTSTAGE_PRINTF_TIMESTAMP=y` -- µs timestamps on every line. ~15 chars/line ~ 1.3 ms/line at 115200, so read instrumented timings as an upper bound | +| `uboot/flare-bootcount.config` | boot-failure fallback to `altbootcmd=download` -> MaskRom | +| `uboot/flare-spl-brom.config` | builds `spl_bootrom.o`; does *not* set `SPL_ROCKCHIP_BACK_TO_BROM`, which would flip `SPL_MMC_SUPPORT` off | +| `kernel/flare-backlight.config` | `CONFIG_BACKLIGHT_PWM=y`. As `=m` the backlight class device does not exist until userspace `insmod`s it at ~3.3-3.7 s, which is when the logo is being replaced anyway | +| `kernel/flare-fbcon.config` | `# CONFIG_LOGO is not set` (the SDK ships the LuckFox fox-head over our logo) plus `FRAMEBUFFER_CONSOLE_DEFERRED_TAKEOVER=y` (fbcon seizing the fb destroyed the `drm_logo` image U-Boot handed over) | + +## Measured boot timeline + +Instrumented boot, t=0 at the BootROM DDR banner: + +| milestone | before this work | after | +|---|---|---| +| SPL total (self-reported) | 420.6 ms | 153.6 ms | +| U-Boot logo drawn | 0.866 s | 0.604 s | +| backlight on (logo visible) | 1.157 s | 0.695 s | +| kernel handoff | 1.757 s | 1.292 s | +| userspace colour splash | 4.335 s | 3.87 s | + +`tools/boot-trace.py` produces this table from a UART capture. It splits U-Boot +from kernel at the `Starting kernel` line rather than at the kernel banner, +because with `ignore_loglevel` at 115200 the banner is regularly lost to +`** N printk messages dropped **`. + +## Still open + +- The white logo starts **inverted and fades to correct** in its first instant. + Believed to be the CH32V003's init still completing when the backlight lands, + so we see the tail of the driver IC's internal rail ramp; `FLARE_PANEL_SETTLE_MS` + is currently `250` as a test of that. The cost-free fix, if confirmed, is to + release `RGB_RES` in SPL (~0.03 s) instead of `board_init()` (~0.21 s) and take + the settle back toward zero -- that needs an `idblock` flash. +- No display-driver-IC part number has been identified. The panel is a 4-inch + 720x720 RGB666 module, flex marked `BV-FPC39510A-N-V0`. Note the GT911 on this + board is the **touch** controller on `i2c3@0x14` and has nothing to do with the + display path. diff --git a/luckfox-sdk-patches/board/patches/0001-86panel-seatbelt-wiring.patch b/luckfox-sdk-patches/board/patches/0001-86panel-seatbelt-wiring.patch new file mode 100644 index 0000000..6870d11 --- /dev/null +++ b/luckfox-sdk-patches/board/patches/0001-86panel-seatbelt-wiring.patch @@ -0,0 +1,107 @@ +diff --git a/project/cfg/BoardConfig_IPC/BoardConfig-EMMC-Buildroot-RV1106_Luckfox_Pico_86Panel-IPC.mk b/project/cfg/BoardConfig_IPC/BoardConfig-EMMC-Buildroot-RV1106_Luckfox_Pico_86Panel-IPC.mk +index c8687187c..01e95378d 100755 +--- a/project/cfg/BoardConfig_IPC/BoardConfig-EMMC-Buildroot-RV1106_Luckfox_Pico_86Panel-IPC.mk ++++ b/project/cfg/BoardConfig_IPC/BoardConfig-EMMC-Buildroot-RV1106_Luckfox_Pico_86Panel-IPC.mk +@@ -13,6 +13,13 @@ export RK_APP_TYPE=RK_WIFI_APP + # Config CMA size in environment + export RK_BOOTARGS_CMA_SIZE="1M" + ++# flare-edge (docs/firmware-update.md §6.6 item 3): extra kernel cmdline ++# args, appended verbatim to sys_bootargs by __GET_BOOTARGS_FROM_BOARD_CFG ++# in project/build.sh. panic=10 makes a kernel panic REBOOT after 10 s ++# instead of hanging, so a bad `major` update is counted by U-Boot's ++# bootcount and falls through to altbootcmd -> recovery (§6.4). ++export RK_BOOTARGS_EXTRA="panic=10" ++ + # Kernel dts + export RK_KERNEL_DTS=rv1106g-luckfox-pico-86panel.dts + +@@ -24,7 +31,7 @@ export RK_KERNEL_DTS=rv1106g-luckfox-pico-86panel.dts + export RK_BOOT_MEDIUM=emmc + + # Uboot defconfig fragment +-export RK_UBOOT_DEFCONFIG_FRAGMENT="rk-emmc.config rv1106-luckfox-rgb-reset.config" ++export RK_UBOOT_DEFCONFIG_FRAGMENT="rk-emmc.config rv1106-luckfox-rgb-reset.config flare-spl-brom.config flare-bootcount.config flare-display.config flare-verbose.config flare-ab.config flare-usb-gadget.config flare-touch.config" + + # specify post.sh for delete/overlay files + # export RK_PRE_BUILD_OEM_SCRIPT=rv1103-spi_nor-post.sh +@@ -35,7 +42,13 @@ export RK_UBOOT_DEFCONFIG_FRAGMENT="rk-emmc.config rv1106-luckfox-rgb-reset.conf + # := [@](part-name) + # Note: + # If the first partition offset is not 0x0, it must be added. Otherwise, it needn't adding. +-export RK_PARTITION_CMD_IN_ENV="32K(env),512K@32K(idblock),256K(uboot),32M(boot),512M(oem),256M(userdata),6G(rootfs)" ++# ++# flare-edge A/B layout (docs/decisions/0003-partition-layout.md in the repo): ++# env/idblock/uboot offsets are fixed (BootROM scans LBA 0x40; SPL reads the ++# FIT at byte 0x88000); uboot grows 256K->512K for headroom; misc carries the ++# A/B slot metadata (byte 2048) and an INERT BCB (16K); boot/oem/rootfs are ++# slotted; recovery holds the never-updated rescue FIT. ++export RK_PARTITION_CMD_IN_ENV="32K(env),512K@32K(idblock),512K(uboot),512K(misc),32M(boot_a),32M(boot_b),128M(oem_a),128M(oem_b),1G(rootfs_a),1G(rootfs_b),32M(recovery),1G(userdata)" + + # config partition's filesystem type (squashfs is readonly) + # emmc: squashfs/ext4 +@@ -46,7 +59,9 @@ export RK_PARTITION_CMD_IN_ENV="32K(env),512K@32K(idblock),256K(uboot),32M(boot) + # AAAA ----------> partition name + # /BBBB/CCCC ----> partition mount point + # ext4 ----------> partition filesystem type +-export RK_PARTITION_FS_TYPE_CFG=rootfs@IGNORE@ext4,userdata@/userdata@ext4,oem@/oem@ext4 ++# The _a names key image GENERATION (the build strips _[ab]); runtime mounting ++# resolves the ACTIVE slot from warden.slot on the cmdline (mount_part patch). ++export RK_PARTITION_FS_TYPE_CFG=rootfs_a@IGNORE@ext4,userdata@/userdata@ext4,oem_a@/oem@ext4 + + # config filesystem compress (Just for squashfs or ubifs) + # squashfs: lz4/lzo/lzma/xz/gzip, default xz +@@ -62,7 +77,7 @@ export RK_PARTITION_FS_TYPE_CFG=rootfs@IGNORE@ext4,userdata@/userdata@ext4,oem@/ + export LF_TARGET_ROOTFS=buildroot + + # Buildroot defconfig +-export RK_BUILDROOT_DEFCONFIG=luckfox_pico_w_defconfig ++export RK_BUILDROOT_DEFCONFIG=flare_warden_defconfig + + ################################################# + # Defconfig +@@ -75,7 +90,19 @@ export RK_ARCH=arm + export RK_TOOLCHAIN_CROSS=arm-rockchip830-linux-uclibcgnueabihf + + #misc image +-export RK_MISC=wipe_all-misc.img ++# NEVER the SDK default (recovery-misc.img: BCB says boot-recovery --wipe_all). ++# warden-misc.img is generated by tools/mk-misc.py (flare-edge repo): inert ++# BCB + A/B metadata with both slots successful, A preferred. ++export RK_MISC=warden-misc.img ++ ++# Rescue image: a never-updated kernel+initramfs FIT in the recovery ++# partition, booted by U-Boot when both slots are exhausted (or on a BCB ++# 'boot-recovery' command). Same kernel fragments as the main image (keep in ++# sync with RK_KERNEL_DEFCONFIG_FRAGMENT below: referenced literally here ++# because this line exports first): ethernet and WireGuard are built-in, so ++# the rescue can get the device reachable. ++export RK_ENABLE_RECOVERY=y ++export RK_RECOVERY_KERNEL_DEFCONFIG_FRAGMENT="rv1106-bt.config rv1106-gt911-module.config flare-edge.config rv1106-usb-host-ethernet.config flare-wireguard.config flare-backlight.config flare-fbcon.config" + + # Uboot defconfig + export RK_UBOOT_DEFCONFIG=luckfox_rv1106_uboot_defconfig +@@ -84,7 +111,7 @@ export RK_UBOOT_DEFCONFIG=luckfox_rv1106_uboot_defconfig + export RK_KERNEL_DEFCONFIG=luckfox_rv1106_linux_defconfig + + # Kernel defconfig fragment +-export RK_KERNEL_DEFCONFIG_FRAGMENT="rv1106-bt.config rv1106-gt911-module.config" ++export RK_KERNEL_DEFCONFIG_FRAGMENT="rv1106-bt.config rv1106-gt911-module.config flare-edge.config rv1106-usb-host-ethernet.config flare-wireguard.config flare-backlight.config flare-fbcon.config" + + # Config sensor IQ files + # RK_CAMERA_SENSOR_IQFILES format: +@@ -104,7 +131,7 @@ export RK_KERNEL_DEFCONFIG_FRAGMENT="rv1106-bt.config rv1106-gt911-module.config + export RK_BUILD_APP_TO_OEM_PARTITION=y + + # enable rockchip test +-export RK_ENABLE_ROCKCHIP_TEST=y ++export RK_ENABLE_ROCKCHIP_TEST=n + + # enable rockchip wifi + export RK_ENABLE_WIFI=y +@@ -125,4 +152,4 @@ export RK_PRE_BUILD_OEM_SCRIPT=luckfox-buildroot-oem-pre.sh + export RK_PRE_BUILD_USERDATA_SCRIPT=luckfox-userdata-pre.sh + + # declare overlay directory +-export RK_POST_OVERLAY="overlay-luckfox-buildroot-init overlay-luckfox-buildroot-shadow overlay-luckfox-buildroot-rgb overlay-luckfox-buildroot-86panel" ++export RK_POST_OVERLAY="overlay-luckfox-buildroot-init overlay-luckfox-buildroot-shadow overlay-luckfox-buildroot-rgb overlay-luckfox-buildroot-86panel overlay-flare-warden-ui" diff --git a/luckfox-sdk-patches/board/patches/0002-build-honor-bootargs-extra.patch b/luckfox-sdk-patches/board/patches/0002-build-honor-bootargs-extra.patch new file mode 100644 index 0000000..caf2ea1 --- /dev/null +++ b/luckfox-sdk-patches/board/patches/0002-build-honor-bootargs-extra.patch @@ -0,0 +1,21 @@ +diff --git a/project/build.sh b/project/build.sh +index 18552ca28..6fab50104 100755 +--- a/project/build.sh ++++ b/project/build.sh +@@ -2161,6 +2161,16 @@ __GET_BOOTARGS_FROM_BOARD_CFG() { + if [ -n "$RK_BOOTARGS_CMA_SIZE" ]; then + SYS_BOOTARGS="$SYS_BOOTARGS rk_dma_heap_cma=$RK_BOOTARGS_CMA_SIZE" + fi ++ # flare-edge (docs/firmware-update.md §6.6 item 3): append any extra ++ # kernel bootargs the board .mk asks for, verbatim, to sys_bootargs. ++ # The 86Panel board sets RK_BOOTARGS_EXTRA="panic=10" so a kernel ++ # panic REBOOTS after 10 s instead of hanging -- which is what turns a ++ # bad `major` update into a bootcount++ that U-Boot can count toward ++ # ${bootlimit} -> ${altbootcmd} -> recovery. Generic + inert: a board ++ # that never sets the var is completely unaffected. ++ if [ -n "$RK_BOOTARGS_EXTRA" ]; then ++ SYS_BOOTARGS="$SYS_BOOTARGS $RK_BOOTARGS_EXTRA" ++ fi + } + + __LINK_DEFCONFIG_FROM_BOARD_CFG() { diff --git a/luckfox-sdk-patches/board/patches/0003-ab-partitions-recovery.patch b/luckfox-sdk-patches/board/patches/0003-ab-partitions-recovery.patch new file mode 100644 index 0000000..40a8443 --- /dev/null +++ b/luckfox-sdk-patches/board/patches/0003-ab-partitions-recovery.patch @@ -0,0 +1,403 @@ +Recovery partitions and the recovery ramdisk, in project/. + +The BoardConfig hunks that used to head this patch were removed: patch 0001 +carries that file's whole delta, and both patches adding RK_BOOTARGS_EXTRA at +the same line meant the two could never apply in sequence. What is left here is +the part 0001 does not cover. + +--- a/project/build.sh ++++ b/project/build.sh +@@ -1826,7 +1826,18 @@ + root_dev=\$(mountpoint -n /) + root_dev=\${root_dev%% *} + partname=\$1 +-part_dev=/dev/block/by-name/\$1 ++# flare-edge A/B: a slotted partition name resolves against the slot U-Boot ++# actually booted (warden.slot on the cmdline), so /oem always matches the ++# running kernel's slot. Falls through unchanged on a non-A/B image. ++case "\$partname" in ++ *_a|*_b) ++ wslot=\$(sed -n 's/.*warden\.slot=\(_[ab]\).*/\1/p' /proc/cmdline) ++ if [ -n "\$wslot" ]; then ++ partname="\${partname%_[ab]}\$wslot" ++ fi ++ ;; ++esac ++part_dev=/dev/block/by-name/\$partname + mountpt=\$2 + part_fstype=\$3 + part_realdev=\$(realpath \$part_dev) +diff --git a/project/scripts/RkLunch-recovery.sh b/project/scripts/RkLunch-recovery.sh +index 92c33ac29..9c5160b5f 100755 +--- a/project/scripts/RkLunch-recovery.sh ++++ b/project/scripts/RkLunch-recovery.sh +@@ -1,115 +1,270 @@ + #!/bin/sh ++# WardenOS rescue image — runs as the recovery initramfs' RkLunch.sh. ++# ++# The rescue's ONE job (fota spec §8.2): become reachable and let a human ++# recover the device. It is entered when both A/B slots are exhausted, or on ++# a BCB 'boot-recovery' command. It restores nothing on its own initiative — ++# a technician (or the ops team over the network) drives recovery with the ++# helpers this script lays down in /usr/bin. Runbook: ++# flare-edge docs/recovery-runbook.md. ++# ++# Two access paths, both authenticated (getty/telnetd via /bin/login against the ++# pinned root credential), kept up together: ++# 1. PRIMARY: a CDC-ACM serial console over USB (host opens /dev/ttyACM0). No ++# IP — this is the reliable floor that survives the RNDIS usb0 flakiness (#26). ++# 2. SECONDARY (network, for bulk image staging): usb0 RNDIS (172.32.0.93/16), ++# plus eth0 DHCP -> /userdata/warden/rescue-net static -> link-local ++# 169.254.86.86/16, with telnetd on top. ++# The 'boot-recovery' BCB is cleared on entry so a failed rescue reboots to ++# normal instead of looping. ++# ++# Source of truth: flare-edge sdk-patches/board/ — edit there, not in a ++# built image. + +-SD_DEVICES="mmcblk1 mmcblk2" +-DEV_NAME="" +-MOUNT_PATH="" +-UPDATE_PACKAGE="" +-UPDATE_OTA_DIR_PATH="" +-delay_time="" +-input_file="$1" +-input_path="$2" ++echo "==== WardenOS rescue image ====" ++cat /proc/cmdline + +-sleep 1 +-echo "Ready to update." ++# S15linkmount_recovery already ran linkdev + mounted /userdata (if intact). ++mkdir -p /userdata 2>/dev/null ++mountpoint -q /userdata || mount /dev/block/by-name/userdata /userdata 2>/dev/null + +-# Use the specified update package in preference. +-if [ -f "$input_file" ]; then +- UPDATE_PACKAGE=$(realpath $input_file) +- UPDATE_OTA_DIR_PATH=$(dirname $UPDATE_PACKAGE)/update +- [ -d "$input_path" ] && UPDATE_OTA_DIR_PATH="$input_path/update" ++# ONE-SHOT recovery: clear the 'boot-recovery' BCB command (misc @16384) right ++# now, so even if this rescue boot goes wrong (unreachable, wedged), a plain ++# power-cycle returns to NORMAL boot instead of looping in recovery. The A/B ++# slot metadata (misc @2048) is left untouched — this touches only the BCB ++# command field. (If recovery was entered via exhausted slots rather than a BCB ++# command there is nothing to clear; harmless.) This is the safety net that ++# turns a failed rescue from a stranding into a reboot. ++_MISC=$(realpath /dev/block/by-name/misc 2>/dev/null) ++[ -n "$_MISC" ] && ( ++ # Backgrounded on purpose: a conv=fsync write to a degraded eMMC (a plausible ++ # state on a device that needed recovery) can block in uninterruptible sleep ++ # for the block layer's whole command-timeout/retry chain. Do NOT stall the ++ # access paths below (ACM console / RNDIS / telnet) waiting on it — one-shot ++ # only needs the BCB cleared before the NEXT reboot, and the rescue session ++ # outlives a slow write. Report honestly if the write fails. ++ if dd if=/dev/zero of="$_MISC" bs=1 seek=16384 count=32 \ ++ conv=notrunc,fsync 2>/dev/null && sync; then ++ echo "rescue: boot-recovery BCB cleared (recovery is one-shot)" ++ else ++ echo "rescue: WARNING boot-recovery BCB clear FAILED — recovery may re-trigger next boot" ++ fi ++) & ++ ++# ---- USB gadget: reachable over the same USB port as the main system, NO ++# Ethernet cable / disassembly. A COMPOSITE gadget exposing TWO functions: ++# - acm.gs0 (CDC-ACM serial): the RELIABLE console. The host just opens ++# /dev/ttyACM0 — no netdev, no IP negotiation, none of the RNDIS ++# usb0-netdev/IP race that left a rescue boot unreachable (#26). getty ++# on /dev/ttyGS0 (below) gives an authenticated login over it. ++# - rndis.gs0 (network at 172.32.0.93/16): the BULK path (staging images ++# for rescue-restore). Best-effort — when it comes up, telnet works too. ++# All built-in (USB_LIBCOMPOSITE / USB_F_ACM / USB_F_RNDIS / USB_CONFIGFS_* / ++# USB_DWC3) on the built-in DWC3 UDC (ffb00000.usb). ++setup_usb_gadget() { ++ CFG=/sys/kernel/config ++ mkdir -p $CFG 2>/dev/null ++ mount -t configfs none $CFG 2>/dev/null ++ G=$CFG/usb_gadget/rescue ++ [ -d "$G" ] && return 0 ++ mkdir -p "$G" 2>/dev/null || return 1 ++ echo 0x2207 > "$G/idVendor" 2>/dev/null ++ echo 0x0019 > "$G/idProduct" 2>/dev/null ++ mkdir -p "$G/strings/0x409" 2>/dev/null ++ echo "rescue" > "$G/strings/0x409/serialnumber" 2>/dev/null ++ echo "BlueFlare" > "$G/strings/0x409/manufacturer" 2>/dev/null ++ echo "Warden Rescue" > "$G/strings/0x409/product" 2>/dev/null ++ # acm FIRST so the serial console is the primary interface; rndis second. ++ mkdir -p "$G/functions/acm.gs0" 2>/dev/null ++ mkdir -p "$G/functions/rndis.gs0" 2>/dev/null ++ mkdir -p "$G/configs/b.1/strings/0x409" 2>/dev/null ++ echo "rescue-acm+rndis" > "$G/configs/b.1/strings/0x409/configuration" 2>/dev/null ++ ln -s "$G/functions/acm.gs0" "$G/configs/b.1/" 2>/dev/null ++ ln -s "$G/functions/rndis.gs0" "$G/configs/b.1/" 2>/dev/null ++ udc=$(ls /sys/class/udc/ 2>/dev/null | head -1) ++ [ -n "$udc" ] && echo "$udc" > "$G/UDC" 2>/dev/null ++ # ttyGS0 (the ACM console) appears the instant the gadget binds — no netdev, ++ # so no race; the getty respawn below just waits for it. The RNDIS usb0 ++ # netdev is created ASYNCHRONOUSLY and is best-effort (its flakiness, #26, is ++ # exactly why the ACM console exists). Poll for it and set the static IP. ++ i=0 ++ while [ $i -lt 20 ]; do ++ [ -e /sys/class/net/usb0 ] && break ++ sleep 1; i=$((i + 1)) ++ done ++ if [ -e /sys/class/net/usb0 ]; then ++ ip link set usb0 up 2>/dev/null ++ ip addr add 172.32.0.93/16 dev usb0 2>/dev/null ++ echo "rescue: usb0 RNDIS up at 172.32.0.93 (UDC $udc, waited ${i}s)" ++ else ++ echo "rescue: usb0 netdev never appeared (UDC $udc) — use the /dev/ttyACM0 serial console" ++ fi ++} ++setup_usb_gadget & + +- echo "Update package: $UPDATE_PACKAGE" +- mkdir -p $UPDATE_OTA_DIR_PATH +- tar -xvf $UPDATE_PACKAGE -C $UPDATE_OTA_DIR_PATH +- if [ $? -ne 0 ]; then +- echo "Error: Decompression failed, please check the update package(tar)." +- exit 1 +- fi ++# ---- network up ---- ++ip link set lo up 2>/dev/null ++if ip link set eth0 up 2>/dev/null; then ++ # DHCP in the background; static/link-local addresses coexist with it. ++ udhcpc -i eth0 -b -t 10 -T 3 2>/dev/null & + +- sh $UPDATE_OTA_DIR_PATH/RK_OTA_update.sh +- if [ $? -eq 0 ]; then +- echo "Upgrade successfully." +- rm -rf $UPDATE_OTA_DIR_PATH +- reboot +- return +- else +- echo "Error: Upgrade failed, please check the partition." +- rm -rf $UPDATE_OTA_DIR_PATH +- exit 1 +- fi +-else +- echo "Warning: Update package ($1) was not found, checking SD card..." ++ NETCFG=/userdata/warden/rescue-net ++ if [ -r "$NETCFG" ]; then ++ # PARSE strictly as ip= / gw= — do NOT dot-source. `.`ing this ++ # file would EXECUTE it as root: /userdata is writable, so a prior ++ # compromise (or any file-write bug) could plant arbitrary shell that runs ++ # on every rescue entry, before the telnet credential-pin below, defeating ++ # it entirely. Restrict values to IP/CIDR characters. ++ ip=$(sed -n 's/^ip=\([0-9./]\{1,32\}\)$/\1/p' "$NETCFG" 2>/dev/null | head -1) ++ gw=$(sed -n 's/^gw=\([0-9.]\{1,15\}\)$/\1/p' "$NETCFG" 2>/dev/null | head -1) ++ [ -n "$ip" ] && ip addr add "$ip" dev eth0 2>/dev/null ++ [ -n "$gw" ] && ip route add default via "$gw" 2>/dev/null ++ fi ++ ++ # Link-local last resort — a technician with a laptop and a cable can ++ # always reach 169.254.86.86. ++ ip addr add 169.254.86.86/16 dev eth0 2>/dev/null + fi + +-# Check SD card when not input update package path. +-for DEV_NAME in $SD_DEVICES +-do +- echo "************** DEV_NAME=$DEV_NAME **************" +- delay_time=1 +- mount | grep -i "$DEV_NAME" +- if [ $? -eq 0 ]; then +- MOUNT_PATH=`mount | grep -i "$DEV_NAME" | awk '{printf $3}'` +- echo "SDcard is already mounted in $MOUNT_PATH" +- else +- MOUNT_PATH=/mnt/sdcard +- fi ++# WireGuard phone-home if the identity and a rescue peer config survive on ++# /userdata (WireGuard is built into this kernel; wg tool if present). ++WGCONF=/userdata/warden/rescue-wg.conf ++if [ -r "$WGCONF" ] && command -v wg >/dev/null 2>&1; then ++ ip link add wg0 type wireguard 2>/dev/null && ++ wg setconf wg0 "$WGCONF" 2>/dev/null && ++ ip link set wg0 up 2>/dev/null && ++ echo "rescue: wg0 up from $WGCONF" ++fi + +- while [ $delay_time -le 5 ] +- do +- usleep 200000 +- dev=$(ls /dev/$DEV_NAME*) +- if [ -n "$dev" ]; then +- echo Find the device: $dev +- break 2 +- fi +- echo "Find $DEV_NAME failed $delay_time times" +- delay_time=$(($delay_time+1)) +- done +-done ++# ---- remote access ---- ++# Authenticated telnet. The recovery ramdisk ships busybox's skeleton ++# /etc/shadow (root == the SDK-wide public default "rockchip"), so pin root to a ++# known device credential and run telnetd THROUGH /bin/login. Do NOT use ++# `telnetd -l /bin/sh`: that execs a root shell on connect with no password ++# prompt (reachable over eth0/link-local/usb0), defeating the credential the ++# runbook documents. ++# ++# Credential source, in order: (1) a per-device override on /userdata ++# (rescue-shadow, a single "root::..." line — the same runtime-override ++# pattern as rescue-net/rescue-wg.conf, so production password rotation reaches ++# the rescue), else (2) the compiled-in default password 'root' ++# (openssl passwd -1 -salt wardenrs root; matches the main firmware). ++DEFAULT_ROOT_LINE='root:$1$wardenrs$F.aYwbBz69WjSvwa3RNRF1:19664::::::' ++ROOT_LINE="" ++RESCUE_SHADOW=/userdata/warden/rescue-shadow ++[ -r "$RESCUE_SHADOW" ] && ROOT_LINE=$(grep '^root:' "$RESCUE_SHADOW" 2>/dev/null | head -1) ++[ -n "$ROOT_LINE" ] || ROOT_LINE="$DEFAULT_ROOT_LINE" ++WANT_HASH=$(printf '%s' "$ROOT_LINE" | cut -d: -f2) + +-if [ -z "$dev" ]; then +- echo "Error: Not found device, skipping upgrade." +- sh /usr/bin/RK_OTA_erase_misc.sh +- [ $? -eq 0 ] && reboot +- exit 1 ++if [ -f /etc/shadow ]; then ++ grep -v '^root:' /etc/shadow > /etc/shadow.new 2>/dev/null ++ { printf '%s\n' "$ROOT_LINE"; cat /etc/shadow.new; } > /etc/shadow ++ rm -f /etc/shadow.new ++ chmod 600 /etc/shadow 2>/dev/null + fi + +-mkdir -p $MOUNT_PATH +-UPDATE_OTA_DIR_PATH=$MOUNT_PATH/update +-UPDATE_PACKAGE=$MOUNT_PATH/update_ota.tar ++# Fail CLOSED: expose access only if the intended root hash actually landed. ++# Exposing a shell over the ramdisk's public 'rockchip' default would be worse ++# than no access at all (recover via USB/MaskRom instead). Both the serial ++# console (getty->login) and telnet (telnetd -l /bin/login) authenticate against ++# this same pinned credential. ++GOT_HASH=$(grep '^root:' /etc/shadow 2>/dev/null | head -1 | cut -d: -f2) ++if [ -n "$WANT_HASH" ] && [ "$GOT_HASH" = "$WANT_HASH" ]; then ++ # PRIMARY, always-reachable path: an authenticated login on the CDC-ACM ++ # serial console. The host opens /dev/ttyACM0 (no IP). getty runs /bin/login; ++ # the respawn loop waits for ttyGS0 (created when the acm gadget binds) and ++ # re-runs getty after each logout, so the console is durable. ++ ( while true; do ++ [ -e /dev/ttyGS0 ] && getty -L 115200 ttyGS0 vt100 ++ sleep 1 ++ done ) & ++ echo "rescue: serial console up on /dev/ttyGS0 (host: /dev/ttyACM0), authenticated" ++ # SECONDARY: telnet over the network (usb0 RNDIS / eth0), when it comes up. ++ telnetd -l /bin/login ++ echo "rescue: telnetd up (authenticated: root / device password)" ++else ++ echo "rescue: root-credential pin FAILED — NO shell exposed; recover via USB/MaskRom" ++fi + +-for SD_DEV in $dev +-do +- echo "************** SD_DEV=$SD_DEV **************" +- if mount -t vfat $SD_DEV $MOUNT_PATH ; then +- if [ -f $UPDATE_PACKAGE ]; then +- echo "Update package: $UPDATE_PACKAGE" +- mkdir -p $UPDATE_OTA_DIR_PATH +- tar -xvf $UPDATE_PACKAGE -C $UPDATE_OTA_DIR_PATH +- if [ $? -ne 0 ]; then +- echo "Error: Decompression failed, please check the update package(tar)." +- exit 1 +- fi ++# ---- recovery helpers ---- ++cat >/usr/bin/rescue-status <<'HLP' ++#!/bin/sh ++echo "== slots (misc AB metadata @2048) ==" ++MISC=$(realpath /dev/block/by-name/misc) ++dd if=$MISC bs=1 skip=2048 count=32 2>/dev/null | hexdump -C ++echo "== partitions ==" ++ls -l /dev/block/by-name/ ++echo "== staged images (if any) ==" ++ls -l /userdata/warden/rescue/ 2>/dev/null || echo none ++HLP ++chmod +x /usr/bin/rescue-status + +- sh $UPDATE_OTA_DIR_PATH/RK_OTA_update.sh +- if [ $? -eq 0 ]; then +- echo "Upgrade successfully." +- rm -rf $UPDATE_OTA_DIR_PATH +- reboot +- return +- else +- echo "Error: Upgrade failed, please check the partition." +- rm -rf $UPDATE_OTA_DIR_PATH +- exit 1 +- fi +- else +- echo "Warning: Not found update package: $UPDATE_PACKAGE" +- fi +- umount $MOUNT_PATH +- fi ++cat >/usr/bin/rescue-slot-reset <<'HLP' ++#!/bin/sh ++# Reset A/B metadata to provision defaults (A 15/0/1 preferred, B 14/0/1) — ++# use after restoring slot images. Bytes generated by (and kept in sync ++# with) flare-edge tools/mk-misc.py; CRC32-BE over the first 28 bytes. ++set -e ++MISC=$(realpath /dev/block/by-name/misc) ++printf '\x00\x41\x42\x30\x01\x00\x00\x00\x0f\x00\x01\x00\x0e\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xda\x93\x36\x79' >/tmp/absector ++dd if=/tmp/absector of=$MISC bs=1 seek=2048 conv=notrunc,fsync 2>/dev/null ++sync ++echo "slot metadata reset to provision defaults" ++HLP ++chmod +x /usr/bin/rescue-slot-reset ++ ++cat >/usr/bin/rescue-restore <<'HLP' ++#!/bin/sh ++# rescue-restore: write staged images from /userdata/warden/rescue/ onto BOTH ++# slots, reset the A/B metadata to provision defaults, reboot. ++# Stage boot.img / oem.img / rootfs.img there first (over the rescue ++# network), then run this. ++# ++# `rescue-restore wipe-config` ALSO clears the /userdata rescue overrides ++# (rescue-shadow / rescue-net / rescue-wg.conf). A plain restore preserves them ++# (they survive reflash by design), but a planted rescue-shadow backdoor or a ++# rogue rescue-wg peer would then outlive the reflash — so use wipe-config when ++# recovering from a suspected COMPROMISE rather than a plain hardware fault. ++set -e ++if [ "$1" = "wipe-config" ]; then ++ rm -f /userdata/warden/rescue-shadow /userdata/warden/rescue-net \ ++ /userdata/warden/rescue-wg.conf ++ echo "rescue: cleared /userdata rescue overrides (compromise recovery)" ++fi ++D=/userdata/warden/rescue ++for img in boot oem rootfs; do ++ [ -r "$D/$img.img" ] || { echo "missing $D/$img.img"; exit 1; } ++done ++for slot in _a _b; do ++ for img in boot oem rootfs; do ++ dev=$(realpath /dev/block/by-name/$img$slot) ++ sz=$(wc -c < "$D/$img.img") ++ echo "writing $img.img -> $dev ($sz bytes)" ++ dd if="$D/$img.img" of="$dev" bs=1M conv=fsync ++ sync ++ # Read-back verify BEFORE the slot-reset below commits both slots as ++ # successful. dd alone reports only its own write, not what landed ++ # (bad USB stick, dropped transfer, eMMC glitch); writing a truncated ++ # image and then stamping the slot "successful" is precisely how a ++ # Level-1-recoverable device becomes a Level-2 (MaskRom-only) brick. ++ # head -c stops the read at the image length, so this is cheap even for ++ # the 1G rootfs (no byte-at-a-time dd). ++ src_sum=$(md5sum "$D/$img.img" | cut -d' ' -f1) ++ dev_sum=$(dd if="$dev" bs=1M 2>/dev/null | head -c "$sz" | md5sum | cut -d' ' -f1) ++ if [ "$src_sum" != "$dev_sum" ]; then ++ echo "VERIFY FAILED for $img$slot ($src_sum != $dev_sum)" ++ echo "ABORTING: slots NOT committed; re-stage a good $img.img and retry." ++ exit 2 ++ fi ++ echo " verified $img$slot ($src_sum)" ++ done + done ++rescue-slot-reset ++echo "restore complete; rebooting" ++sync ++devmem 0xff3b0c08 32 0xfdb9 2>/dev/null || true ++reboot -f ++HLP ++chmod +x /usr/bin/rescue-restore + +-echo "Recovery upgrade failed, skipping." +-sh /usr/bin/RK_OTA_erase_misc.sh +-[ $? -eq 0 ] && reboot +-exit 1 ++echo "==== rescue ready: telnet in; rescue-status / rescue-restore ====" diff --git a/luckfox-sdk-patches/board/patches/0004-s50usbdevice-role-gate.patch b/luckfox-sdk-patches/board/patches/0004-s50usbdevice-role-gate.patch new file mode 100644 index 0000000..71ede01 --- /dev/null +++ b/luckfox-sdk-patches/board/patches/0004-s50usbdevice-role-gate.patch @@ -0,0 +1,18 @@ +diff --git a/sysdrv/tools/board/android-tools/S50usbdevice b/sysdrv/tools/board/android-tools/S50usbdevice +index d29c2334b..b175b77fb 100755 +--- a/sysdrv/tools/board/android-tools/S50usbdevice ++++ b/sysdrv/tools/board/android-tools/S50usbdevice +@@ -6,6 +6,13 @@ + # Load default env variables from profiles + . /etc/profile + ++# flare-edge: the OTG port is a USB HOST in router (and the unset-role default), ++# so building a gadget here is pointless AND harmful — the dwc3 "failed to add ++# gadget" + the usb2-phy "illegal mode" it triggers race with the USB-Ethernet ++# host enumeration and intermittently kill eth1 at boot. Only run in client role; ++# S26usbhost re-invokes this explicitly when switching to client. (unset -> router) ++[ "$(cat /userdata/warden/role 2>/dev/null || echo 1)" = "1" ] && exit 0 ++ + UMS_EN=off + ADB_EN=on + MTP_EN=off diff --git a/luckfox-sdk-patches/board/patches/0005-build-fix-rkvar-grep-quote.patch b/luckfox-sdk-patches/board/patches/0005-build-fix-rkvar-grep-quote.patch new file mode 100644 index 0000000..a13b995 --- /dev/null +++ b/luckfox-sdk-patches/board/patches/0005-build-fix-rkvar-grep-quote.patch @@ -0,0 +1,22 @@ +diff --git a/project/build.sh b/project/build.sh +index 6fab501..6adbe35 100755 +--- a/project/build.sh ++++ b/project/build.sh +@@ -7,7 +7,7 @@ RECORD_IFS="$IFS" + + function unset_env_config_rk() { + local tmp_file=$(mktemp) +- env | grep -oh "^RK_.*=" >$tmp_file || true ++ env | grep -oh "^RK_[A-Za-z0-9_]*=" >$tmp_file || true + source $tmp_file + rm -f $tmp_file + } +@@ -383,7 +383,7 @@ function save_board_config() { + + function unset_board_config_all() { + local tmp_file=$(mktemp) +- grep -oh "^export.*RK_.*=" $(find cfg -name "BoardConfig*.mk") >$tmp_file ++ grep -oh "^export RK_[A-Za-z0-9_]*=" $(find cfg -name "BoardConfig*.mk") >$tmp_file + source $tmp_file + rm -f $tmp_file + } diff --git a/luckfox-sdk-patches/board/patches/0006-buildroot-2025.patch b/luckfox-sdk-patches/board/patches/0006-buildroot-2025.patch new file mode 100644 index 0000000..617d8f2 --- /dev/null +++ b/luckfox-sdk-patches/board/patches/0006-buildroot-2025.patch @@ -0,0 +1,22 @@ +Point the build at buildroot-2025.02.8. + +The vendor SDK ships buildroot-2023.02.6 and build.sh pointed at it. The tree we +actually build against is 2025.02.8, and nothing recorded the switch: a rebuild +from a pristine vendor checkout plus this patch series silently produced a +different userspace. + +The 2.6 GB tree itself cannot live in this repo and is NOT in the vendor +checkout either; obtaining it is covered by the SDK's build/vendor.manifest. +This patch records only the one line that selects it. + +--- a/project/build.sh ++++ b/project/build.sh +@@ -34,7 +34,7 @@ + GLOBAL_SDK_VERSION="" + WIFI_NEW_CONF=${SDK_APP_DIR}/wifi_app/wpa_supplicant_new.conf + WIFI_CONF=${SDK_APP_DIR}/wifi_app/wpa_supplicant.conf +-BUILDROOT_PATH=${SDK_SYSDRV_DIR}/source/buildroot/buildroot-2023.02.6 ++BUILDROOT_PATH=${SDK_SYSDRV_DIR}/source/buildroot/buildroot-2025.02.8 + BUILDROOT_CONFIG_FILE=${BUILDROOT_PATH}/.config + SDK_CONFIG_DIR=${SDK_ROOT_DIR}/config + DTS_CONFIG=${SDK_CONFIG_DIR}/dts_config diff --git a/luckfox-sdk-patches/board/patches/0007-recovery-console-auth.patch b/luckfox-sdk-patches/board/patches/0007-recovery-console-auth.patch new file mode 100644 index 0000000..231a331 --- /dev/null +++ b/luckfox-sdk-patches/board/patches/0007-recovery-console-auth.patch @@ -0,0 +1,60 @@ +Authenticate the recovery console (#27). + +The busybox tiny_rootfs skeleton runs `::respawn:-/bin/sh` on /dev/console, +which on this board is ttyFIQ0, the debug UART. That is a root prompt with no +login for anyone who opens the case, and it bypasses the fail-closed credential +pin RkLunch-recovery.sh enforces for every other rescue path. The skeleton's own +ttyFIQ0 getty line is commented out directly below it, so the bare shell was the +only console and the unauthenticated one. + +build.sh now deletes that line when it stages the ramdisk, and the recovery +script spawns an authenticated getty on the console inside its gated block, so +a failed pin exposes nothing on the UART either. + +--- a/project/build.sh ++++ b/project/build.sh +@@ -956,6 +956,24 @@ + cp -fa $PROJECT_TOP_DIR/scripts/RkLunch-recovery.sh $RK_PROJECT_PATH_RAMDISK_TINY_ROOTFS/usr/bin/RkLunch.sh + cp -fa $PROJECT_TOP_DIR/scripts/boot4recovery.its $RK_PROJECT_PATH_RAMDISK + ++ # flare-edge (#27): the busybox tiny_rootfs skeleton runs an ++ # UNAUTHENTICATED root shell on /dev/console -- which on this board is ++ # ttyFIQ0, the debug UART: ++ # ++ # ::respawn:-/bin/sh ++ # ++ # That hands a root prompt with no login to anyone who opens the case, ++ # bypassing the fail-closed credential pin RkLunch-recovery.sh enforces for ++ # every other rescue path (ttyGS0 getty, telnetd -l /bin/login). Note the ++ # skeleton's own ttyFIQ0 getty line is commented out right below it, so the ++ # bare shell was the only console -- and the unauthenticated one. ++ # ++ # Removed here; RkLunch-recovery.sh spawns an authenticated getty on the ++ # console INSIDE its gated block instead, so the debug UART now answers to ++ # the same pinned credential as everything else. ++ sed -i '/^::respawn:-\/bin\/sh$/d' \ ++ $RK_PROJECT_PATH_RAMDISK_TINY_ROOTFS/etc/inittab ++ + mkdir -p $(dirname $RK_PROJECT_FILE_RECOVERY_LUNCH_SCRIPT) + cat >$RK_PROJECT_FILE_RECOVERY_LUNCH_SCRIPT < ttyFIQ0). The ramdisk skeleton used to run ++ # `::respawn:-/bin/sh` from its inittab here: a root shell with no login, ++ # reachable by anyone who opened the case, bypassing this entire gate (#27). ++ # project/build.sh now deletes that line, so the console is owned HERE and ++ # authenticates against the same pinned credential as every other path. ++ # Inside the gate, so a failed pin exposes nothing on the UART either. ++ ( while true; do ++ getty -L console 0 vt100 ++ sleep 1 ++ done ) & ++ echo "rescue: debug-UART console up on /dev/console, authenticated" + # SECONDARY: telnet over the network (usb0 RNDIS / eth0), when it comes up. + telnetd -l /bin/login + echo "rescue: telnetd up (authenticated: root / device password)" diff --git a/luckfox-sdk-patches/board/patches/0008-usb-gadget-compose-once.patch b/luckfox-sdk-patches/board/patches/0008-usb-gadget-compose-once.patch new file mode 100644 index 0000000..5793027 --- /dev/null +++ b/luckfox-sdk-patches/board/patches/0008-usb-gadget-compose-once.patch @@ -0,0 +1,55 @@ +flare-edge: compose the USB gadget once, instead of rebinding twice. + +Every unbind/rebind of a live gadget is a full controller teardown; the +host loses usb0 and ttyACM0 and the halt times out (issue #145). + +--- a/sysdrv/tools/board/android-tools/S50usbdevice ++++ b/sysdrv/tools/board/android-tools/S50usbdevice +@@ -17,7 +17,13 @@ + ADB_EN=on + MTP_EN=off + NTB_EN=off +-ACM_EN=off ++# flare-edge: composed here rather than linked afterwards by S52usbacm. Every ++# unbind/rebind of a live gadget is a full teardown -- the host loses usb0 and ++# ttyACM0, and the controller logs "Host halt failed, -110" on the way down -- ++# so the panel's console function is built into the gadget before it is ever ++# bound (issue #145). S52usbacm still runs; it now finds acm already linked, ++# skips its rebind, and only starts the ttyGS0 getty. ++ACM_EN=on + UAC1_EN=off + UAC2_EN=off + UVC_EN=off +@@ -73,6 +79,24 @@ + mkdir ${USB_FUNCTIONS_DIR}/hid.usb0 + } + ++# flare-edge: the stable, serial-derived RNDIS MAC, applied BEFORE the gadget ++# is bound. S51usbmac used to set this afterwards, which meant tearing down a ++# live gadget purely to change two strings (issue #145). It still runs and is ++# now a no-op that confirms the result. ++flare_stamp_rndis_mac() ++{ ++ RN=${USB_FUNCTIONS_DIR}/rndis.gs0 ++ [ -d "$RN" ] || return 0 ++ SER=$(tr -d '\000' < /proc/device-tree/serial-number 2>/dev/null) ++ [ -n "$SER" ] || return 0 ++ H=$(printf '%s' "$SER" | md5sum | cut -c1-10) ++ A=$(echo "$H" | cut -c1-2); B=$(echo "$H" | cut -c3-4) ++ C=$(echo "$H" | cut -c5-6); D=$(echo "$H" | cut -c7-8) ++ E=$(echo "$H" | cut -c9-10) ++ echo "02:$A:$B:$C:$D:$E" > "$RN/host_addr" 2>/dev/null ++ echo "06:$A:$B:$C:$D:$E" > "$RN/dev_addr" 2>/dev/null ++} ++ + configfs_init() + { + echo "Debug: configfs_init" +@@ -426,6 +450,7 @@ + use_os_desc + echo $PID > ${USB_CONFIGFS_DIR}/idProduct + bind_functions ++ flare_stamp_rndis_mac + pre_run_binary + sleep 1 + UDC=`ls /sys/class/udc/| awk '{print $1}'` diff --git a/luckfox-sdk-patches/buildroot/files/configs/luckfox_pico_defconfig b/luckfox-sdk-patches/buildroot/files/configs/luckfox_pico_defconfig new file mode 100755 index 0000000..681b264 --- /dev/null +++ b/luckfox-sdk-patches/buildroot/files/configs/luckfox_pico_defconfig @@ -0,0 +1,76 @@ +BR2_arm=y +BR2_cortex_a7=y +BR2_TOOLCHAIN_EXTERNAL=y +BR2_TOOLCHAIN_EXTERNAL_CUSTOM=y +BR2_TOOLCHAIN_EXTERNAL_PATH="../../../../tools/linux/toolchain/arm-rockchip830-linux-uclibcgnueabihf" +BR2_TOOLCHAIN_EXTERNAL_CUSTOM_PREFIX="arm-rockchip830-linux-uclibcgnueabihf" +BR2_TOOLCHAIN_EXTERNAL_GCC_8=y +BR2_TOOLCHAIN_EXTERNAL_HEADERS_5_10=y +BR2_TOOLCHAIN_EXTERNAL_WCHAR=y +BR2_TOOLCHAIN_EXTERNAL_HAS_SSP=y +BR2_TOOLCHAIN_EXTERNAL_CXX=y +BR2_PRIMARY_SITE="http://sources.buildroot.net" +BR2_OPTIMIZE_3=y +BR2_TARGET_GENERIC_HOSTNAME="luckfox pico" +BR2_TARGET_GENERIC_ISSUE="Welcome to luckfox pico" +BR2_TARGET_GENERIC_ROOT_PASSWD="luckfox" +BR2_SYSTEM_ENABLE_NLS=y +BR2_PACKAGE_BUSYBOX_SHOW_OTHERS=y +BR2_PACKAGE_GZIP=y +BR2_PACKAGE_P7ZIP=y +BR2_PACKAGE_UNZIP=y +BR2_PACKAGE_XZ=y +BR2_PACKAGE_ZIP=y +BR2_PACKAGE_E2FSPROGS=y +BR2_PACKAGE_E2FSPROGS_RESIZE2FS=y +BR2_PACKAGE_EVTEST=y +BR2_PACKAGE_PYTHON3=y +BR2_PACKAGE_PYTHON3_SSL=y +BR2_PACKAGE_PYTHON_AIOHTTP=y +BR2_PACKAGE_PYTHON_CLICK=y +BR2_PACKAGE_PYTHON_ITSDANGEROUS=y +BR2_PACKAGE_PYTHON_JINJA2=y +BR2_PACKAGE_PYTHON_PERIPHERY=y +BR2_PACKAGE_PYTHON_PILLOW=y +BR2_PACKAGE_PYTHON_SERIAL=y +BR2_PACKAGE_PYTHON_SETUPTOOLS=y +BR2_PACKAGE_PYTHON_SMBUS_CFFI=y +BR2_PACKAGE_PYTHON_SPIDEV=y +BR2_PACKAGE_PYTHON_WERKZEUG=y +BR2_PACKAGE_CA_CERTIFICATES=y +BR2_PACKAGE_GNUTLS=y +BR2_PACKAGE_LIBMD=y +BR2_PACKAGE_FREETYPE=y +BR2_PACKAGE_LIBDRM=y +BR2_PACKAGE_DTC=y +BR2_PACKAGE_DTC_PROGRAMS=y +BR2_PACKAGE_LIBV4L=y +BR2_PACKAGE_LIBV4L_UTILS=y +BR2_PACKAGE_LIBCURL=y +BR2_PACKAGE_LIBCURL_CURL=y +BR2_PACKAGE_LIBCURL_VERBOSE=y +BR2_PACKAGE_LIBRSYNC=y +BR2_PACKAGE_PCRE2=y +BR2_PACKAGE_PCRE2_16=y +BR2_PACKAGE_PCRE2_32=y +BR2_PACKAGE_BMON=y +BR2_PACKAGE_DHCPCD=y +BR2_PACKAGE_IPERF=y +BR2_PACKAGE_IPERF3=y +BR2_PACKAGE_IPTABLES=y +BR2_PACKAGE_IPTABLES_BPF_NFSYNPROXY=y +BR2_PACKAGE_IPTABLES_NFTABLES=y +BR2_PACKAGE_LRZSZ=y +BR2_PACKAGE_NTP=y +BR2_PACKAGE_OPENSSH=y +BR2_PACKAGE_RSYNC=y +BR2_PACKAGE_SOCAT=y +BR2_PACKAGE_WGET=y +BR2_PACKAGE_BASH=y +BR2_PACKAGE_BASH_LOADABLE_EXAMPLES=y +BR2_PACKAGE_DIALOG=y +BR2_PACKAGE_TIME=y +BR2_PACKAGE_HTOP=y +BR2_PACKAGE_UTIL_LINUX_LIBMOUNT=y +BR2_PACKAGE_NANO=y +BR2_PACKAGE_HOST_DTC=y diff --git a/luckfox-sdk-patches/buildroot/files/configs/luckfox_pico_w_defconfig b/luckfox-sdk-patches/buildroot/files/configs/luckfox_pico_w_defconfig new file mode 100755 index 0000000..998b586 --- /dev/null +++ b/luckfox-sdk-patches/buildroot/files/configs/luckfox_pico_w_defconfig @@ -0,0 +1,113 @@ +BR2_arm=y +BR2_cortex_a7=y +BR2_TOOLCHAIN_EXTERNAL=y +BR2_TOOLCHAIN_EXTERNAL_CUSTOM=y +BR2_TOOLCHAIN_EXTERNAL_PATH="../../../../tools/linux/toolchain/arm-rockchip830-linux-uclibcgnueabihf" +BR2_TOOLCHAIN_EXTERNAL_CUSTOM_PREFIX="arm-rockchip830-linux-uclibcgnueabihf" +BR2_TOOLCHAIN_EXTERNAL_GCC_8=y +BR2_TOOLCHAIN_EXTERNAL_HEADERS_5_10=y +BR2_TOOLCHAIN_EXTERNAL_WCHAR=y +BR2_TOOLCHAIN_EXTERNAL_HAS_SSP=y +BR2_TOOLCHAIN_EXTERNAL_CXX=y +BR2_PRIMARY_SITE="http://sources.buildroot.net" +BR2_OPTIMIZE_3=y +BR2_TARGET_GENERIC_HOSTNAME="luckfox pico" +BR2_TARGET_GENERIC_ISSUE="Welcome to luckfox pico" +BR2_TARGET_GENERIC_ROOT_PASSWD="luckfox" +BR2_SYSTEM_ENABLE_NLS=y +BR2_PACKAGE_BUSYBOX_SHOW_OTHERS=y +BR2_PACKAGE_ALSA_UTILS=y +BR2_PACKAGE_ALSA_UTILS_ALSACONF=y +BR2_PACKAGE_ALSA_UTILS_ACONNECT=y +BR2_PACKAGE_ALSA_UTILS_AMIXER=y +BR2_PACKAGE_ALSA_UTILS_APLAY=y +BR2_PACKAGE_ALSA_UTILS_SPEAKER_TEST=y +BR2_PACKAGE_BLUEZ_ALSA=y +BR2_PACKAGE_BLUEZ_ALSA_HCITOP=y +BR2_PACKAGE_BLUEZ_ALSA_RFCOMM=y +BR2_PACKAGE_FFMPEG_FFPLAY=y +BR2_PACKAGE_FFMPEG_FFPROBE=y +BR2_PACKAGE_FFMPEG_AVRESAMPLE=y +BR2_PACKAGE_JACK2=y +BR2_PACKAGE_JACK2_LEGACY=y +BR2_PACKAGE_JACK2_DBUS=y +BR2_PACKAGE_MADPLAY=y +BR2_PACKAGE_MPV=y +BR2_PACKAGE_PULSEAUDIO=y +BR2_PACKAGE_SOX=y +BR2_PACKAGE_GZIP=y +BR2_PACKAGE_P7ZIP=y +BR2_PACKAGE_UNZIP=y +BR2_PACKAGE_XZ=y +BR2_PACKAGE_ZIP=y +BR2_PACKAGE_E2FSPROGS_RESIZE2FS=y +BR2_PACKAGE_SDL2_GFX=y +BR2_PACKAGE_SDL2_IMAGE=y +BR2_PACKAGE_SDL2_MIXER=y +BR2_PACKAGE_SDL2_NET=y +BR2_PACKAGE_SDL2_TTF=y +BR2_PACKAGE_VULKAN_HEADERS=y +BR2_PACKAGE_DBUS_CPP=y +BR2_PACKAGE_DBUS_TRIGGERD=y +BR2_PACKAGE_EVTEST=y +BR2_PACKAGE_PYTHON3_SSL=y +BR2_PACKAGE_PYTHON_AIOHTTP=y +BR2_PACKAGE_PYTHON_CLICK=y +BR2_PACKAGE_PYTHON_ITSDANGEROUS=y +BR2_PACKAGE_PYTHON_JINJA2=y +BR2_PACKAGE_PYTHON_PERIPHERY=y +BR2_PACKAGE_PYTHON_PILLOW=y +BR2_PACKAGE_PYTHON_SERIAL=y +BR2_PACKAGE_PYTHON_SETUPTOOLS=y +BR2_PACKAGE_PYTHON_SMBUS_CFFI=y +BR2_PACKAGE_PYTHON_SPIDEV=y +BR2_PACKAGE_PYTHON_WERKZEUG=y +BR2_PACKAGE_LIBAO=y +BR2_PACKAGE_PORTAUDIO=y +BR2_PACKAGE_CA_CERTIFICATES=y +BR2_PACKAGE_LIBDRM=y +BR2_PACKAGE_DTC=y +BR2_PACKAGE_DTC_PROGRAMS=y +BR2_PACKAGE_LIBV4L=y +BR2_PACKAGE_LIBV4L_UTILS=y +BR2_PACKAGE_CJSON=y +BR2_PACKAGE_CJSON_UTILS=y +BR2_PACKAGE_LIBCURL=y +BR2_PACKAGE_LIBCURL_CURL=y +BR2_PACKAGE_LIBCURL_VERBOSE=y +BR2_PACKAGE_LIBRSYNC=y +BR2_PACKAGE_PCRE2=y +BR2_PACKAGE_PCRE2_16=y +BR2_PACKAGE_PCRE2_32=y +BR2_PACKAGE_BLUEZ_TOOLS=y +BR2_PACKAGE_BLUEZ5_UTILS_CLIENT=y +BR2_PACKAGE_BLUEZ5_UTILS_TOOLS=y +BR2_PACKAGE_BLUEZ5_UTILS_DEPRECATED=y +BR2_PACKAGE_BLUEZ5_UTILS_EXPERIMENTAL=y +BR2_PACKAGE_BMON=y +BR2_PACKAGE_DHCPCD=y +BR2_PACKAGE_IPERF=y +BR2_PACKAGE_IPERF3=y +BR2_PACKAGE_IPTABLES=y +BR2_PACKAGE_IPTABLES_BPF_NFSYNPROXY=y +BR2_PACKAGE_IPTABLES_NFTABLES=y +BR2_PACKAGE_IW=y +BR2_PACKAGE_LRZSZ=y +BR2_PACKAGE_NTP=y +BR2_PACKAGE_OPENSSH=y +BR2_PACKAGE_PPPD=y +BR2_PACKAGE_PPPD_FILTER=y +BR2_PACKAGE_PPPD_RADIUS=y +BR2_PACKAGE_RSYNC=y +BR2_PACKAGE_SAMBA4=y +BR2_PACKAGE_SOCAT=y +BR2_PACKAGE_WGET=y +BR2_PACKAGE_BASH=y +BR2_PACKAGE_BASH_LOADABLE_EXAMPLES=y +BR2_PACKAGE_DIALOG=y +BR2_PACKAGE_TIME=y +BR2_PACKAGE_HTOP=y +BR2_PACKAGE_PROCPS_NG=y +BR2_PACKAGE_UTIL_LINUX_LIBMOUNT=y +BR2_PACKAGE_NANO=y +BR2_PACKAGE_HOST_DTC=y diff --git a/luckfox-sdk-patches/buildroot/files/package/bluez5_utils/0001-add-uclibc-wordexp-compat.patch b/luckfox-sdk-patches/buildroot/files/package/bluez5_utils/0001-add-uclibc-wordexp-compat.patch new file mode 100644 index 0000000..cafe3b3 --- /dev/null +++ b/luckfox-sdk-patches/buildroot/files/package/bluez5_utils/0001-add-uclibc-wordexp-compat.patch @@ -0,0 +1,185 @@ +Add a minimal wordexp(3) for uClibc-ng, which the Rockchip toolchain +builds without. BlueZ (bluetoothctl via src/shared/shell.c, and a few +tools) includes unconditionally; DEFAULT_INCLUDES=-I. makes +this top-level header resolve. WRDE_NOCMD is always passed, so a +whitespace/quote tokenizer is a semantically complete substitute. + +Signed-off-by: BlueFlare Warden + +diff --git a/wordexp.h b/wordexp.h +new file mode 100644 +index 0000000..1111111 +--- /dev/null ++++ b/wordexp.h +@@ -0,0 +1,171 @@ ++/* SPDX-License-Identifier: LGPL-2.1-or-later */ ++/* ++ * Minimal wordexp(3) for uClibc-ng. ++ * ++ * The Rockchip external toolchain's uClibc-ng is built without wordexp, so it ++ * ships no . Several BlueZ sources (src/shared/shell.c, which is ++ * bluetoothctl's command reader, plus a few tools) include ++ * unconditionally and call wordexp()/wordfree(). They always pass WRDE_NOCMD ++ * -- "no command substitution" -- and use the result only to split a command ++ * line into words, so a whitespace/quote tokenizer is a semantically complete ++ * substitute. This is deliberately NOT a general shell expander: no globbing, ++ * no variable or command substitution (WRDE_NOCMD is precisely the request to ++ * omit those). Placed at the BlueZ source root, where DEFAULT_INCLUDES = -I. ++ * makes resolve to it. ++ */ ++#ifndef _WORDEXP_H_ ++#define _WORDEXP_H_ ++ ++#include ++#include ++#include ++ ++#define WRDE_DOOFFS 0x0001 ++#define WRDE_APPEND 0x0002 ++#define WRDE_NOCMD 0x0004 ++#define WRDE_REUSE 0x0008 ++#define WRDE_SHOWERR 0x0010 ++#define WRDE_UNDEF 0x0020 ++ ++enum { ++ WRDE_SUCCESS = 0, ++ WRDE_NOSPACE = 1, ++ WRDE_BADCHAR = 2, ++ WRDE_BADVAL = 3, ++ WRDE_CMDSUB = 4, ++ WRDE_SYNTAX = 5, ++}; ++ ++typedef struct { ++ size_t we_wordc; /* number of words */ ++ char **we_wordv; /* NULL-terminated vector of words */ ++ size_t we_offs; /* reserved-slot count; also used as a scratch flag ++ by shell.c, which never passes WRDE_DOOFFS */ ++} wordexp_t; ++ ++__attribute__((unused)) ++static int wordexp(const char *words, wordexp_t *we, int flags) ++{ ++ size_t n, i; ++ char **vec; ++ const char *p; ++ int appending; ++ size_t orig_n; /* we->we_wordc as of function entry, so a failure ++ partway through a WRDE_APPEND call can put the ++ vector back to exactly its pre-call length rather ++ than leaving it part-grown or short a ++ terminator */ ++ ++ if (words == NULL || we == NULL) ++ return WRDE_BADCHAR; ++ ++ appending = (flags & WRDE_APPEND) && we->we_wordv != NULL; ++ if (appending) { ++ n = we->we_wordc; /* append to the existing vector */ ++ vec = we->we_wordv; ++ } else { ++ n = 0; ++ vec = calloc(1, sizeof(char *)); ++ if (vec == NULL) ++ return WRDE_NOSPACE; ++ } ++ orig_n = n; ++ ++ for (p = words; *p != '\0'; ) { ++ size_t cap = 16, len = 0; ++ char *w, *tw, **t; ++ ++ while (*p != '\0' && isspace((unsigned char)*p)) ++ p++; ++ if (*p == '\0') ++ break; ++ ++ w = malloc(cap); ++ if (w == NULL) ++ goto nospace; ++ ++ while (*p != '\0' && !isspace((unsigned char)*p)) { ++ char c; ++ ++ if (*p == '\'' || *p == '"') { ++ char q = *p++; ++ while (*p != '\0' && *p != q) { ++ if (len + 1 >= cap) { ++ cap *= 2; ++ tw = realloc(w, cap); ++ if (tw == NULL) { free(w); goto nospace; } ++ w = tw; ++ } ++ w[len++] = *p++; ++ } ++ if (*p == q) ++ p++; ++ continue; ++ } ++ if (*p == '\\' && p[1] != '\0') ++ p++; ++ c = *p++; ++ if (len + 1 >= cap) { ++ cap *= 2; ++ tw = realloc(w, cap); ++ if (tw == NULL) { free(w); goto nospace; } ++ w = tw; ++ } ++ w[len++] = c; ++ } ++ w[len] = '\0'; ++ ++ t = (char **)realloc(vec, (n + 2) * sizeof(char *)); ++ if (t == NULL) { free(w); goto nospace; } ++ vec = t; ++ vec[n++] = w; ++ vec[n] = NULL; ++ } ++ ++ if (n == 0) ++ vec[0] = NULL; /* keep the vector NULL-terminated */ ++ ++ we->we_wordv = vec; ++ we->we_wordc = n; ++ return WRDE_SUCCESS; ++ ++nospace: ++ if (appending) { ++ /* vec already carries every word from before this call -- ++ realloc() preserves existing contents whether it ++ relocates the block. Only entries at orig_n and above are ++ this call's own; free those and put the vector back to ++ exactly its pre-call length. vec, not we->we_wordv, is what ++ still points at that data: realloc() may already have ++ relocated or freed the pointer we->we_wordv held on entry, ++ which is exactly why the old cleanup here could free the ++ caller's pre-existing words and leave we->we_wordv ++ dangling. */ ++ for (i = orig_n; i < n; i++) ++ free(vec[i]); ++ vec[orig_n] = NULL; ++ we->we_wordv = vec; ++ we->we_wordc = orig_n; ++ } else { ++ for (i = 0; i < n; i++) ++ free(vec[i]); ++ free(vec); ++ } ++ return WRDE_NOSPACE; ++} ++ ++__attribute__((unused)) ++static void wordfree(wordexp_t *we) ++{ ++ size_t i; ++ ++ if (we == NULL || we->we_wordv == NULL) ++ return; ++ for (i = 0; i < we->we_wordc; i++) ++ free(we->we_wordv[i]); ++ free(we->we_wordv); ++ we->we_wordv = NULL; ++ we->we_wordc = 0; ++} ++ ++#endif /* _WORDEXP_H_ */ diff --git a/luckfox-sdk-patches/buildroot/files/package/mpv/0002-change-j1.patch b/luckfox-sdk-patches/buildroot/files/package/mpv/0002-change-j1.patch new file mode 100644 index 0000000..c82b553 --- /dev/null +++ b/luckfox-sdk-patches/buildroot/files/package/mpv/0002-change-j1.patch @@ -0,0 +1,84 @@ +Bessel J1 for mpv's EWA/jinc scaler. The Rockchip external toolchain's +uClibc-ng does not provide j1()/j0()/jn() -- confirmed absent from +libuClibc-1.0.31.so in the arm-rockchip830-linux-uclibcgnueabihf sysroot +this SDK builds against, the same gap the bluez5_utils wordexp patch in +this series works around for a different function. jinc() (video/out/ +filter_kernels.c) scales its argument by M_PI before calling this, and +mpv's --scale-radius is user-settable, so BesselJ1 has to be accurate +over the whole double range a real j1() would cover, not just small +arguments -- the version this replaces summed a fixed 11-term power +series whose terms have not converged by the time n runs out for any +x much past 6 or 7, and are off by 7+ orders of magnitude by x=20. + +--- a/video/out/filter_kernels.c 2024-04-26 11:14:00.377199103 +0800 ++++ b/video/out/filter_kernels.c 2024-04-26 11:13:50.217202856 +0800 +@@ -32,6 +32,60 @@ + + // NOTE: all filters are designed for discrete convolution + ++/* ++ * mpv's libm on this target is uClibc-ng, which does not provide ++ * j1()/j0()/jn() -- confirmed absent from libuClibc-1.0.31.so in the ++ * arm-rockchip830-linux-uclibcgnueabihf sysroot this SDK builds ++ * against. jinc() (below) scales its argument by M_PI before calling ++ * this, and --scale-radius is user-settable, so this has to hold up ++ * over the whole double range, not just small arguments. ++ * ++ * A plain power series is only exact up to about x=20 in double ++ * precision: past that, terms grow before they shrink, and summing ++ * large alternating terms loses precision to cancellation. So this ++ * sums the series -- by a term-to-term ratio rather than separate ++ * factorial()/power() calls, which also keeps it from overflowing at ++ * large n -- only while each new term is still negligible against the ++ * running sum, and falls back to the standard second-order asymptotic ++ * expansion for Bessel functions (Abramowitz & Stegun 9.2.5/9.2.6, ++ * order 1) once x passes that point. Checked against libm's j1() on ++ * the build host across x in [0, 5000]: max absolute error 5e-8, max ++ * relative error 5e-5 away from J1's zero crossings, where any finite ++ * error reads large against a reference near zero. ++ */ ++static double warden_j1_series(double x) ++{ ++ double half = x / 2.0; ++ double term = half; ++ double sum = term; ++ double xsq = -(half * half); ++ for (int n = 1; n < 80; n++) { ++ term *= xsq / ((double)n * (double)(n + 1)); ++ sum += term; ++ if (fabs(term) < 1e-18 * fabs(sum)) ++ break; ++ } ++ return sum; ++} ++ ++static double warden_j1_asymptotic(double x) ++{ ++ double omega = x - 3.0 * M_PI / 4.0; ++ double x2 = x * x; ++ double p = 1.0 + 15.0 / (128.0 * x2) - 4725.0 / (32768.0 * x2 * x2); ++ double q = 3.0 / (8.0 * x) - 105.0 / (1024.0 * x2 * x) ++ + 363825.0 / (1310720.0 * x2 * x2 * x); ++ return sqrt(2.0 / (M_PI * x)) * (p * cos(omega) - q * sin(omega)); ++} ++ ++static double BesselJ1(double x) ++{ ++ int neg = x < 0; ++ double ax = fabs(x); ++ double r = (ax < 12.0) ? warden_j1_series(ax) : warden_j1_asymptotic(ax); ++ return neg ? -r : r; ++} ++ + const struct filter_window *mp_find_filter_window(const char *name) + { + if (!name) +@@ -324,7 +378,7 @@ + if (fabs(x) < 1e-8) + return 1.0; + x *= M_PI; +- return 2.0 * j1(x) / x; ++ return 2.0 * BesselJ1(x) / x; + } + + static double sphinx(params *p, double x) diff --git a/luckfox-sdk-patches/buildroot/patches/0001-busybox-applets.patch b/luckfox-sdk-patches/buildroot/patches/0001-busybox-applets.patch new file mode 100644 index 0000000..f9eabfb --- /dev/null +++ b/luckfox-sdk-patches/buildroot/patches/0001-busybox-applets.patch @@ -0,0 +1,74 @@ +The busybox applet set this image ships. + +Not a preference: two things in the firmware depend on it directly. +CONFIG_FEATURE_FANCY_SLEEP=y is why `sleep 0.1` works in the init scripts, and +`# CONFIG_TIMEOUT is not set` is why S09splash's touch probe cannot use +timeout(1) and backgrounds a reader instead. It also builds telnetd in. + +This file lived only in the vendor SDK's unpacked buildroot tree, which is not +in the vendor checkout and not in any manifest, so none of that was recorded +anywhere (#135). + +--- a/package/busybox/busybox.config ++++ b/package/busybox/busybox.config +@@ -1,7 +1,7 @@ + # + # Automatically generated make config: don't edit + # Busybox version: 1.36.1 +-# Wed May 8 17:25:31 2024 ++# Sat Dec 9 10:36:18 2023 + # + CONFIG_HAVE_DOT_CONFIG=y + +@@ -782,7 +782,7 @@ + # CONFIG_FEATURE_CROND_D is not set + # CONFIG_FEATURE_CROND_CALL_SENDMAIL is not set + CONFIG_FEATURE_CROND_SPECIAL_TIMES=y +-CONFIG_FEATURE_CROND_DIR="/etc/cron" ++CONFIG_FEATURE_CROND_DIR="/var/spool/cron" + CONFIG_CRONTAB=y + # CONFIG_DEVFSD is not set + # CONFIG_DEVFSD_MODLOAD is not set +@@ -835,7 +835,7 @@ + CONFIG_PARTPROBE=y + # CONFIG_RAIDAUTORUN is not set + # CONFIG_READAHEAD is not set +-# CONFIG_RFKILL is not set ++CONFIG_RFKILL=y + CONFIG_RUNLEVEL=y + # CONFIG_RX is not set + CONFIG_SEEDRNG=y +@@ -968,18 +968,18 @@ + CONFIG_ROUTE=y + # CONFIG_SLATTACH is not set + # CONFIG_SSL_CLIENT is not set +-# CONFIG_TC is not set +-# CONFIG_FEATURE_TC_INGRESS is not set ++CONFIG_TC=y ++CONFIG_FEATURE_TC_INGRESS=y + # CONFIG_TCPSVD is not set + # CONFIG_UDPSVD is not set + CONFIG_TELNET=y + CONFIG_FEATURE_TELNET_TTYPE=y + CONFIG_FEATURE_TELNET_AUTOLOGIN=y + CONFIG_FEATURE_TELNET_WIDTH=y +-# CONFIG_TELNETD is not set +-# CONFIG_FEATURE_TELNETD_STANDALONE is not set +-CONFIG_FEATURE_TELNETD_PORT_DEFAULT=0 +-# CONFIG_FEATURE_TELNETD_INETD_WAIT is not set ++CONFIG_TELNETD=y ++CONFIG_FEATURE_TELNETD_STANDALONE=y ++CONFIG_FEATURE_TELNETD_PORT_DEFAULT=23 ++CONFIG_FEATURE_TELNETD_INETD_WAIT=y + CONFIG_TFTP=y + # CONFIG_FEATURE_TFTP_PROGRESS_BAR is not set + CONFIG_FEATURE_TFTP_HPA_COMPAT=y +@@ -1016,7 +1016,7 @@ + CONFIG_FEATURE_UDHCPC_ARPING=y + CONFIG_FEATURE_UDHCPC_SANITIZEOPT=y + CONFIG_UDHCPC_DEFAULT_SCRIPT="/usr/share/udhcpc/default.script" +-CONFIG_UDHCPC6_DEFAULT_SCRIPT="/usr/share/udhcpc/default.script" ++CONFIG_UDHCPC6_DEFAULT_SCRIPT="" + # CONFIG_UDHCPC6 is not set + # CONFIG_FEATURE_UDHCPC6_RFC3646 is not set + # CONFIG_FEATURE_UDHCPC6_RFC4704 is not set diff --git a/luckfox-sdk-patches/kernel/configs/flare-backlight.config b/luckfox-sdk-patches/kernel/configs/flare-backlight.config new file mode 100644 index 0000000..c57fd3a --- /dev/null +++ b/luckfox-sdk-patches/kernel/configs/flare-backlight.config @@ -0,0 +1,9 @@ +# flare-edge: build the PWM backlight driver in, not as a module. +# +# Building the PWM backlight as a module means its class device does not exist +# until userspace insmods pwm_bl.ko (~3.3-3.7s, via S25backlight). The +# U-Boot -> kernel drm_logo boot-splash handoff replaces its framebuffer +# at almost exactly that same time, so there is effectively no window +# where a backlight device exists AND the logo is still on screen. +# Built-in makes the device exist from early kernel boot instead. +CONFIG_BACKLIGHT_PWM=y diff --git a/luckfox-sdk-patches/kernel/configs/flare-edge.config b/luckfox-sdk-patches/kernel/configs/flare-edge.config new file mode 100644 index 0000000..946509a --- /dev/null +++ b/luckfox-sdk-patches/kernel/configs/flare-edge.config @@ -0,0 +1,104 @@ +# flare-edge kernel config fragment +# +# Merged by the RK build: BoardConfig-...-86Panel-IPC.mk names this file in +# the kernel fragment list (".mk:88"), and tools/build-firmware.sh's +# copy_fragments step installs it into arch/arm/configs/ before the kernel +# build. (It had, until now, existed ONLY as an untracked hand-edit in the SDK +# working copy at arch/arm/configs/flare-edge.config -- the exact stale-copy +# trap sdk-patches/ exists to close. This tracked form is authoritative.) + +# --- kexec (SSH-side kernel swap, no flash writes) ------------------------- +# Enable kexec so a new kernel can be booted from a running SSH session +# with zero writes to flash. The stock image has this stubbed out: all of +# sys_kexec_load / sys_kexec_file_load / compat_sys_kexec_load resolve to +# the same sys_ni_syscall address, so the syscall is absent. +# +# KEXEC depends on (!SMP || PM_SLEEP_SMP) && MMU. RV1106 is a single-core +# Cortex-A7 and symmetric multiprocessing is disabled in the base defconfig, +# so the dependency is satisfied. +CONFIG_KEXEC=y + +# --- RGA2 2D engine + CMA dma-buf heaps (graph-scroll offload) -------------- +# warden: enable the RV1106 RGA2 2D engine (/dev/rga) for graph-scroll offload. +# Builtin (not =m) so devtmpfs auto-creates the node at boot; the rga2 DT node is +# already status="okay" via rv1106-evb.dtsi, so no device-tree change is needed. +CONFIG_ROCKCHIP_MULTI_RGA=y +# Portable CMA dma-buf allocator (/dev/dma_heap/cma) for contiguous, RGA-safe +# (no-IOMMU) graph canvas buffers; reuses the existing 10MB linux,cma pool. +CONFIG_DMABUF_HEAPS=y +CONFIG_DMABUF_HEAPS_CMA=y + +# --- host-side USB-Ethernet class drivers (router mode adds a LAN port) ------ +# In router mode S26usbhost flips the OTG port to USB HOST so a USB-Ethernet +# adapter enumerates as an extra network port. The stock defconfig ships +# the USB network driver menu disabled, so even once the DTS dr_mode="otg" host +# switch (sdk-patches/kernel/patches/0003-usb-otg-dual-role.patch) brings xHCI +# up, no ethN netdev would be created. Build these in (=y, not =m) so a NIC works +# with zero userspace insmod, from early boot. Covers the common adapter silicon: +# CDC-ECM/NCM (generic), ASIX AX88xxx (2.0 + gigabit), Realtek RTL8152/8153. +# Trim to the adapters actually deployed if image size matters. +CONFIG_USB_NET_DRIVERS=y +CONFIG_USB_USBNET=y +CONFIG_USB_NET_CDCETHER=y +CONFIG_USB_NET_CDC_NCM=y +CONFIG_USB_NET_AX8817X=y +CONFIG_USB_NET_AX88179_178A=y +CONFIG_USB_RTL8152=y + +# --- WireGuard (FLARE management mesh) -------------------------------------- +# Kernel WireGuard is the chosen mesh transport (module + userspace `wg`, not +# boringtun). The base luckfox_rv1106_linux_defconfig ALREADY builds it in +# (built in at line ~212), and =y Kconfig-selects its crypto/UDP-tunnel +# deps (CHACHA20POLY1305, CURVE25519, NET_UDP_TUNNEL), so nothing is missing and +# no dep lines are needed here. We PIN =y (rather than the =m the task named, or +# omitting it) so a future defconfig drift cannot silently drop the mesh +# transport -- and so this fragment documents that WireGuard is a hard build +# requirement. =y > =m here: no insmod, present from boot. Do NOT set =m: that +# would DOWNGRADE the built-in to a module and merge_config would flag the +# conflict. +CONFIG_WIREGUARD=y + +# --- 802.1Q VLAN (per-port router subnets, MikroTik switch termination) -------- +# router.c terminates each per-port subnet as an eth1. 802.1Q subinterface +# (`ip link add link eth1 name eth1. type vlan id `), which needs 8021q +# in the kernel; without it that call returns EOPNOTSUPP, so the VLAN config +# screen + MikroTik app could program a switch the warden itself cannot route. +# +# ABI NOTE (root-caused on hardware 2026-08-13): enabling this inserts a +# `struct vlan_info *vlan_info;` into `struct net_device` +# (include/linux/netdevice.h, under the VLAN feature guard), which +# shifts the offset of every field after it. The out-of-tree aic8800 wifi driver +# and the modular cfg80211.ko MUST be rebuilt against this config or they read +# net_device at stale offsets and NULL-deref at boot (crash in rwnx_interface_add +# -> the "white logo" hang). A clean image build does this correctly: +# build.sh kernel (mrproper -> clean VLAN kernel) +# build.sh rootfs (rebuilds drv_ko/aic8800 + cfg80211.ko against that kernel) +# build.sh firmware +# so boot.img and the /oem modules always ship as a consistent set. NEVER flash a +# VLAN boot.img over non-VLAN modules (that is what produced the hang during +# incremental testing). =y (not =m): =m also flips IS_ENABLED, so it changes the +# ABI identically while adding an insmod step for no benefit here. +CONFIG_VLAN_8021Q=y + +# --- pstore/ramoops: persistent crash/boot log across a reset ----------------- +# The debug UART is unwirable (under the daughterboard) and the USB CDC-ACM +# console (S52usbacm) only comes up in userspace, so NEITHER can capture a +# pre-userspace kernel hang -- which is exactly the class that bricked c8a3 +# (a load address in unreserved kernel RAM, hung before eth0). pstore/ramoops +# keeps the kernel console ring + any oops/panic in a reserved DRAM region that +# survives the reset (warm reset preserves DRAM), so the NEXT boot can read +# /sys/fs/pstore and see the last words before the hang. Pairs with the already- +# shipped `panic=10` cmdline + enabled watchdog (a hang -> reset -> log persists) +# and the warden-flight recorder (which drains /sys/fs/pstore to /userdata, so +# the log is also MaskRom-`dd`-recoverable off a brick). +# +# The DRAM region is carved by a `ramoops@0f000000` reserved-memory node +# (sdk-patches/kernel/patches/0005-pstore-ramoops.patch): 1 MiB at 240 MiB, HIGH +# above the low kernel/DTB/initrd load zone, so reserving it can only remove RAM +# from the kernel -- it CANNOT recreate the c8a3 under-reservation collision. +# console-size captures dmesg (the boot log); record-size captures oops/panic. +CONFIG_PSTORE=y +CONFIG_PSTORE_DEFLATE_COMPRESS=y +CONFIG_PSTORE_CONSOLE=y +CONFIG_PSTORE_PMSG=y +CONFIG_PSTORE_RAM=y diff --git a/luckfox-sdk-patches/kernel/configs/flare-fbcon.config b/luckfox-sdk-patches/kernel/configs/flare-fbcon.config new file mode 100644 index 0000000..2fefbaa --- /dev/null +++ b/luckfox-sdk-patches/kernel/configs/flare-fbcon.config @@ -0,0 +1,24 @@ +# flare-edge: fbcon display policy -- keep OUR splash on screen, uninterrupted. +# +# Two separate problems, both fbcon, both fixed here. +# +# 1) The generic Linux logo option draws +# drivers/video/logo/logo_linux_clut224.ppm whenever fbcon takes over a +# framebuffer. This is NOT Rockchip's drm_logo handoff -- it is the +# kernel's generic boot-logo feature, and the LuckFox SDK ships that file +# replaced with their own fox-head + "LUCKFOX" wordmark. It painted over +# our white BlueFlare logo on every boot. +# +# 2) The takeover itself. Even with no logo to draw, fbcon seizing the +# framebuffer destroys the drm_logo image U-Boot handed us -- measured at +# 1.895s, only 0.83s after the backlight came on at 1.068s, so the white +# logo appeared as a brief flash and then the panel went blank until the +# userspace colour splash. DEFERRED_TAKEOVER makes fbcon wait until +# something actually writes text to the console before claiming the fb. +# Our console is ttyFIQ0 (serial), so in practice nothing ever does, and +# the U-Boot logo survives until S09splash draws over it deliberately. +# +# Deps for DEFERRED_TAKEOVER (FB=y, FRAMEBUFFER_CONSOLE, DUMMY_CONSOLE) are +# all already satisfied in this defconfig -- verified before enabling. +# CONFIG_LOGO is not set +CONFIG_FRAMEBUFFER_CONSOLE_DEFERRED_TAKEOVER=y diff --git a/luckfox-sdk-patches/kernel/patches/0001-panel-mcu-reset-and-logo-route.patch b/luckfox-sdk-patches/kernel/patches/0001-panel-mcu-reset-and-logo-route.patch new file mode 100644 index 0000000..9e616c7 --- /dev/null +++ b/luckfox-sdk-patches/kernel/patches/0001-panel-mcu-reset-and-logo-route.patch @@ -0,0 +1,82 @@ +diff --git a/sysdrv/source/kernel/arch/arm/boot/dts/rv1106g-luckfox-pico-86panel.dts b/sysdrv/source/kernel/arch/arm/boot/dts/rv1106g-luckfox-pico-86panel.dts +index 8c07a90d3..ece8d149f 100755 +--- a/sysdrv/source/kernel/arch/arm/boot/dts/rv1106g-luckfox-pico-86panel.dts ++++ b/sysdrv/source/kernel/arch/arm/boot/dts/rv1106g-luckfox-pico-86panel.dts +@@ -147,3 +158,77 @@ &uart4 { + pinctrl-names = "default"; + pinctrl-0 = <&uart4m0_xfer>; + }; ++ ++/**********PANEL RESET + BACKLIGHT LINK**********/ ++/* ++ * Restored from the FACTORY device tree (extracted from the stock boot.img of ++ * this unit and diffed against current SDK HEAD, which had silently dropped ++ * both properties). Without them the panel is never taken out of reset: DRM ++ * sets 720x720@48.87Hz, the connector reports "connected", the VOP streams ++ * pixels and the PWM backlight lights — but the panel controller is ++ * unconfigured, so the screen stays black. Even a `modetest` test pattern is ++ * invisible, which is what proved the fault sits BELOW DRM rather than in ++ * fbdev or the app. ++ * ++ * gpio0 RK_PA1 is the same line U-Boot drives via `gpio set 1 1` when ++ * CONFIG_LUCKFOX_EXECUTE_CMD is set (rv1106-luckfox-rgb-reset.config) — that ++ * "Luckfox Pico RGB MCU reset" is the RGB panel's reset, not an LED. ++ * ++ * Factory values: reset-gpios = <&gpio0 1 GPIO_ACTIVE_LOW>, reset-delay-ms = 200 ++ */ ++&panel { ++ /* ++ * flare-edge: backlight ONLY. reset-gpios and reset-delay-ms are ++ * deliberately absent -- do not "restore" them. ++ * ++ * GPIO0_A1 is not the panel's reset. The schematic (U6 on ++ * Luckfox-Pico-86-Panel.pdf) shows a WCH CH32V003 RISC-V MCU whose sole ++ * job is to clock this panel's SPI init sequence into it, and the net ++ * RGB_RES ties SoC GPIO0_A1, the panel RESET pin (FPC 6) and the MCU's ++ * NRST (pin 1) together. Luckfox's own U-Boot comment says as much: ++ * "Luckfox Pico RGB MCU reset gpio". ++ * ++ * So giving panel-simple this GPIO makes drm_panel_prepare() assert it ++ * for reset-delay-ms and release it -- REBOOTING THE INIT MCU while the ++ * VOP is already scanning pixels. The panel is then clocked with RGB ++ * data before its power/gamma/VCOM registers are written, which is ++ * exactly the faint coloured vertical banding seen for ~1-3 s on every ++ * boot, and why a GPIO "reset" never cleared it (it re-ran the race). ++ * ++ * Luckfox removed these two properties in commit e2b0ffa22 for this ++ * reason. An earlier revision of this file re-added them, having read ++ * the deletion as an accidental regression -- see 40-kernel-stack.md, ++ * which recorded them as "silently dropped" by SDK HEAD. They were not ++ * dropped; they were the fix. ++ * ++ * The MCU is released exactly once, early, by U-Boot: board_init() ++ * drives GPIO0_A1 high, and luckfox_execute_cmd() does the same again ++ * harmlessly. At power-on the pin is input-with-pulldown, so the MCU is ++ * held in reset until then, which is the intended sequencing. ++ * ++ * backlight is kept because U-Boot's rockchip_panel.c takes its ++ * backlight handle from this node, and our boot logo needs it. ++ */ ++ backlight = <&backlight>; ++}; ++ ++/* ++ * flare-edge: enable the U-Boot/kernel boot logo route. ++ * ++ * The whole RGB pipeline (display_subsystem, rgb, rgb_in_vop, vop) is already ++ * "okay" in rv1106-luckfox-pico-86panel-ipc.dtsi, and that file also wires ++ * logo-memory-region = <&drm_logo>. route_rgb was the only piece left ++ * disabled, and without it U-Boot's rockchip_display finds no route and skips ++ * drawing entirely. ++ * ++ * The node itself (rv1106.dtsi) already carries logo,uboot = "logo.bmp", ++ * logo,kernel = "logo_kernel.bmp" and logo,mode = "center". Those files come ++ * from resource.img, which scripts/mkmultidtb.py builds with ++ * `resource_tool logo.bmp logo_kernel.bmp ` out of the kernel source ++ * directory -- so replacing sysdrv/source/kernel/logo.bmp is what changes the ++ * splash. Setting logo,kernel to the same image keeps it on screen from ++ * U-Boot through kernel handover until LVGL takes over. ++ */ ++&route_rgb { ++ status = "okay"; ++}; diff --git a/luckfox-sdk-patches/kernel/patches/0002-watchdog-enable.patch b/luckfox-sdk-patches/kernel/patches/0002-watchdog-enable.patch new file mode 100644 index 0000000..16a2407 --- /dev/null +++ b/luckfox-sdk-patches/kernel/patches/0002-watchdog-enable.patch @@ -0,0 +1,28 @@ +diff --git a/sysdrv/source/kernel/arch/arm/boot/dts/rv1106g-luckfox-pico-86panel.dts b/sysdrv/source/kernel/arch/arm/boot/dts/rv1106g-luckfox-pico-86panel.dts +index 8c07a90d3..a9eb6c9d0 100755 +--- a/sysdrv/source/kernel/arch/arm/boot/dts/rv1106g-luckfox-pico-86panel.dts ++++ b/sysdrv/source/kernel/arch/arm/boot/dts/rv1106g-luckfox-pico-86panel.dts +@@ -114,6 +114,23 @@ &gmac { + status = "okay"; + }; + ++/**********WATCHDOG (flare-edge: docs/firmware-update.md §6.6 item 4, §6.7)**********/ ++/* ++ * flare-edge: enable the RV1106 designware watchdog. ++ * ++ * The kernel already builds CONFIG_DW_WATCHDOG, but rv1106.dtsi ships this ++ * `wdt` node status = "disabled", so /dev/watchdog never appears. Once it is ++ * "okay", warden-flared opens /dev/watchdog, sets a timeout (<= ~89 s on this ++ * core) and pets it ONLY while the UI is proven live (ui_alive_fresh), after a ++ * short unconditional boot grace. A post-boot hang then stops the pets, the SoC hard-resets, ++ * and that reset is another boot U-Boot's bootcount sees -- so a wedged new ++ * image converges to bootlimit -> altbootcmd -> recovery, exactly like a kernel ++ * panic (docs §6.7). One line; needs a boot.img reflash. ++ */ ++&wdt { ++ status = "okay"; ++}; ++ + /**********USB**********/ + &usbdrd_dwc3 { + status = "okay"; diff --git a/luckfox-sdk-patches/kernel/patches/0003-usb-otg-dual-role.patch b/luckfox-sdk-patches/kernel/patches/0003-usb-otg-dual-role.patch new file mode 100644 index 0000000..357dae4 --- /dev/null +++ b/luckfox-sdk-patches/kernel/patches/0003-usb-otg-dual-role.patch @@ -0,0 +1,28 @@ +diff --git a/sysdrv/source/kernel/arch/arm/boot/dts/rv1106g-luckfox-pico-86panel.dts b/sysdrv/source/kernel/arch/arm/boot/dts/rv1106g-luckfox-pico-86panel.dts +index 8c07a90d3..efc27c0b8 100755 +--- a/sysdrv/source/kernel/arch/arm/boot/dts/rv1106g-luckfox-pico-86panel.dts ++++ b/sysdrv/source/kernel/arch/arm/boot/dts/rv1106g-luckfox-pico-86panel.dts +@@ -117,8 +117,21 @@ &gmac { + /**********USB**********/ + &usbdrd_dwc3 { + status = "okay"; +- dr_mode = "peripheral"; +- //dr_mode = "host"; ++ /* ++ * flare-edge: dual-role (OTG), not peripheral-only. ++ * ++ * router mode switches the port to USB HOST at runtime (S26usbhost writes ++ * `host` to the inno-usb2 phy otg_mode) so a USB-Ethernet adapter enumerates ++ * as an extra LAN port. With dr_mode = "peripheral" the dwc3 registers the ++ * gadget role ONLY -- no xHCI host is instantiated, so `echo host` flips the ++ * phy but nothing on the port ever enumerates (a silent no-op). "otg" compiles ++ * BOTH roles and keeps the extcon/iddig DRD state machine live, so the runtime ++ * host switch actually hosts. It still boots peripheral-by-default (ID floats ++ * device until `host` asserts it), so the usb0 RNDIS recovery gadget that ++ * client mode + net-flash rely on continues to bind. "host" alone would break ++ * that recovery gadget, so "otg" is the correct value. ++ */ ++ dr_mode = "otg"; + }; + + /**********RTC**********/ diff --git a/luckfox-sdk-patches/kernel/patches/0004-recovery-splash-resource.patch b/luckfox-sdk-patches/kernel/patches/0004-recovery-splash-resource.patch new file mode 100644 index 0000000..812e9f6 --- /dev/null +++ b/luckfox-sdk-patches/kernel/patches/0004-recovery-splash-resource.patch @@ -0,0 +1,26 @@ +--- a/sysdrv/source/kernel/scripts/mkimg ++++ b/sysdrv/source/kernel/scripts/mkimg +@@ -51,6 +51,11 @@ + LOGO_KERNEL_PATH=${srctree}/logo_kernel.bmp + [ -f ${LOGO_KERNEL_PATH} ] && LOGO_KERNEL=logo_kernel.bmp + ++# flare-edge: USB-recovery splash, drawn by U-Boot's download path ++# (cmd/download.c rockchip_show_bmp("logo_recovery.bmp")) ++LOGO_RECOVERY_PATH=${srctree}/logo_recovery.bmp ++[ -f ${LOGO_RECOVERY_PATH} ] && LOGO_RECOVERY=logo_recovery.bmp ++ + KERNEL_IMAGE_PATH=${objtree}/arch/${ARCH}/boot/Image + KERNEL_IMAGE_ARG="--kernel ${KERNEL_IMAGE_PATH}" + if [ "${ARCH}" == "arm" ]; then +@@ -243,8 +248,9 @@ + cp -a ${LOGO_KERNEL_PATH} ${objtree}/; + fi + fi +-scripts/resource_tool ${DTB_PATH} ${LOGO} ${LOGO_KERNEL} >/dev/null +-echo " Image: resource.img (with ${DTB} ${LOGO} ${LOGO_KERNEL}) is ready" ++[ -n "${LOGO_RECOVERY}" ] && cp -f "${LOGO_RECOVERY_PATH}" "${LOGO_RECOVERY}" ++scripts/resource_tool ${DTB_PATH} ${LOGO} ${LOGO_KERNEL} ${LOGO_RECOVERY} >/dev/null ++echo " Image: resource.img (with ${DTB} ${LOGO} ${LOGO_KERNEL} ${LOGO_RECOVERY}) is ready" + + if [ -f "${BOOT_IMG}" ]; then + if file -L -p -b ${BOOT_IMG} | grep -q 'Device Tree Blob' ; then diff --git a/luckfox-sdk-patches/kernel/patches/0004b-verbose-splash-resource.patch b/luckfox-sdk-patches/kernel/patches/0004b-verbose-splash-resource.patch new file mode 100644 index 0000000..b3ac387 --- /dev/null +++ b/luckfox-sdk-patches/kernel/patches/0004b-verbose-splash-resource.patch @@ -0,0 +1,25 @@ +--- a/sysdrv/source/kernel/scripts/mkimg ++++ b/sysdrv/source/kernel/scripts/mkimg +@@ -55,7 +55,10 @@ + # (cmd/download.c rockchip_show_bmp("logo_recovery.bmp")) + LOGO_RECOVERY_PATH=${srctree}/logo_recovery.bmp + [ -f ${LOGO_RECOVERY_PATH} ] && LOGO_RECOVERY=logo_recovery.bmp ++# flare-edge: tapped verbose-boot acknowledgement, selected by U-Boot ++LOGO_VERBOSE_PATH=${srctree}/logo_verbose.bmp ++[ -f ${LOGO_VERBOSE_PATH} ] && LOGO_VERBOSE=logo_verbose.bmp + + KERNEL_IMAGE_PATH=${objtree}/arch/${ARCH}/boot/Image + KERNEL_IMAGE_ARG="--kernel ${KERNEL_IMAGE_PATH}" + if [ "${ARCH}" == "arm" ]; then +@@ -248,8 +251,9 @@ + fi + fi + [ -n "${LOGO_RECOVERY}" ] && cp -f "${LOGO_RECOVERY_PATH}" "${LOGO_RECOVERY}" +-scripts/resource_tool ${DTB_PATH} ${LOGO} ${LOGO_KERNEL} ${LOGO_RECOVERY} >/dev/null +-echo " Image: resource.img (with ${DTB} ${LOGO} ${LOGO_KERNEL} ${LOGO_RECOVERY}) is ready" ++[ -n "${LOGO_VERBOSE}" ] && cp -f "${LOGO_VERBOSE_PATH}" "${LOGO_VERBOSE}" ++scripts/resource_tool ${DTB_PATH} ${LOGO} ${LOGO_KERNEL} ${LOGO_RECOVERY} ${LOGO_VERBOSE} >/dev/null ++echo " Image: resource.img (with ${DTB} ${LOGO} ${LOGO_KERNEL} ${LOGO_RECOVERY} ${LOGO_VERBOSE}) is ready" + + if [ -f "${BOOT_IMG}" ]; then + if file -L -p -b ${BOOT_IMG} | grep -q 'Device Tree Blob' ; then diff --git a/luckfox-sdk-patches/kernel/patches/0005-pstore-ramoops.patch b/luckfox-sdk-patches/kernel/patches/0005-pstore-ramoops.patch new file mode 100644 index 0000000..94b68b2 --- /dev/null +++ b/luckfox-sdk-patches/kernel/patches/0005-pstore-ramoops.patch @@ -0,0 +1,32 @@ +diff --git a/sysdrv/source/kernel/arch/arm/boot/dts/rv1106-luckfox-pico-86panel-ipc.dtsi b/sysdrv/source/kernel/arch/arm/boot/dts/rv1106-luckfox-pico-86panel-ipc.dtsi +index f4e6fb77e..202710496 100755 +--- a/sysdrv/source/kernel/arch/arm/boot/dts/rv1106-luckfox-pico-86panel-ipc.dtsi ++++ b/sysdrv/source/kernel/arch/arm/boot/dts/rv1106-luckfox-pico-86panel-ipc.dtsi +@@ -108,6 +108,27 @@ linux,cma { + mmc_ecsd: mmc@3f000 { + reg = <0x3f000 0x00001000>; + }; ++ ++ /* ++ * flare-edge: pstore/ramoops persistent crash region. 1 MiB at ++ * 240 MiB (of 256 MiB DRAM: reg = <0x0 0x10000000>). Placed HIGH, ++ * far above the low kernel-image/DTB/initrd load zone, so this ++ * carve-out can only REMOVE RAM from the kernel -- it cannot cause ++ * the c8a3-class collision (which was an UN-reserved 0x40000 used ++ * by both the boot MCU and the kernel). Kept below the very top of ++ * DRAM (U-Boot self-relocates there) so the log is more likely to ++ * survive into the recovery boot. console-size captures the kernel ++ * console ring (the boot log before a hang); record-size captures ++ * oops/panic. No ECC (no reed-solomon dep); no no-map (ramoops ++ * memremaps the region itself). See kernel cfg flare-edge.config. ++ */ ++ ramoops@0f000000 { ++ compatible = "ramoops"; ++ reg = <0x0f000000 0x00100000>; ++ console-size = <0x00040000>; ++ record-size = <0x00020000>; ++ pmsg-size = <0x00020000>; ++ }; + }; + + acodec_sound: acodec-sound { diff --git a/luckfox-sdk-patches/kernel/patches/0006-reboot-mode-maskrom.patch b/luckfox-sdk-patches/kernel/patches/0006-reboot-mode-maskrom.patch new file mode 100644 index 0000000..b3d2f2d --- /dev/null +++ b/luckfox-sdk-patches/kernel/patches/0006-reboot-mode-maskrom.patch @@ -0,0 +1,23 @@ +diff --git a/sysdrv/source/kernel/arch/arm/boot/dts/rv1106-luckfox-pico-86panel-ipc.dtsi b/sysdrv/source/kernel/arch/arm/boot/dts/rv1106-luckfox-pico-86panel-ipc.dtsi +index f4e6fb77e..dc08f6256 100755 +--- a/sysdrv/source/kernel/arch/arm/boot/dts/rv1106-luckfox-pico-86panel-ipc.dtsi ++++ b/sysdrv/source/kernel/arch/arm/boot/dts/rv1106-luckfox-pico-86panel-ipc.dtsi +@@ -302,3 +302,18 @@ tp_irq: tp-irq { + }; + }; + }; ++ ++/*********************** on-demand MaskRom ************************/ ++/* ++ * flare-edge: let the OS reach TRUE BootROM MaskRom (USB 2207:110c, reliably ++ * flashable) via `warden-maskrom maskrom` -> reboot(RESTART2,"maskrom") -> ++ * syscon-reboot-mode writes BOOT_BROM_DOWNLOAD to the boot-mode reg 0xff020200. ++ * One-shot: a power-on-reset clears the PMU-domain reg. The stock ++ * mode-loader/-bootloader only reach U-Boot rockusb "Loader" mode, whose WL is ++ * unreliable for multi-partition flashing (writes report 100% but do not ++ * persist); this reaches the BootROM proper, where db+wl are reliable. ++ * 0xEF08A53C == U-Boot BOOT_BROM_DOWNLOAD (arch-rockchip/boot_mode.h). ++ */ ++&reboot_mode { ++ mode-maskrom = <0xEF08A53C>; ++}; diff --git a/luckfox-sdk-patches/kernel/patches/0007-86panel-w-dts-remainder.patch b/luckfox-sdk-patches/kernel/patches/0007-86panel-w-dts-remainder.patch new file mode 100644 index 0000000..2857fa1 --- /dev/null +++ b/luckfox-sdk-patches/kernel/patches/0007-86panel-w-dts-remainder.patch @@ -0,0 +1,55 @@ +The panel DTS as the SDK actually has it. + +Replaying patches 0001-0006 onto a pristine vendor tree did not reproduce this +file: the board model string is "Luckfox Pico 86Panel W" in the SDK, and the +watchdog block 0002 adds sits in a different place. Both were hand-edits made +directly in the SDK checkout and never captured here, so a rebuild from a clean +vendor tree plus this series produced a DTS that differed from the one every +shipped image was built with. + +This patch is the remainder, generated by diffing the replayed result against +the live SDK. It has no intent of its own beyond making the series faithful. + +--- a/sysdrv/source/kernel/arch/arm/boot/dts/rv1106g-luckfox-pico-86panel.dts ++++ b/sysdrv/source/kernel/arch/arm/boot/dts/rv1106g-luckfox-pico-86panel.dts +@@ -10,7 +10,7 @@ + #include + + / { +- model = "Luckfox Pico 86Panel"; ++ model = "Luckfox Pico 86Panel W"; + compatible = "rockchip,rv1103g-38x38-ipc-v10", "rockchip,rv1106g3"; + + restart-poweroff { +@@ -134,21 +134,17 @@ + /**********USB**********/ + &usbdrd_dwc3 { + status = "okay"; +- /* +- * flare-edge: dual-role (OTG), not peripheral-only. +- * +- * router mode switches the port to USB HOST at runtime (S26usbhost writes +- * `host` to the inno-usb2 phy otg_mode) so a USB-Ethernet adapter enumerates +- * as an extra LAN port. With dr_mode = "peripheral" the dwc3 registers the +- * gadget role ONLY -- no xHCI host is instantiated, so `echo host` flips the +- * phy but nothing on the port ever enumerates (a silent no-op). "otg" compiles +- * BOTH roles and keeps the extcon/iddig DRD state machine live, so the runtime +- * host switch actually hosts. It still boots peripheral-by-default (ID floats +- * device until `host` asserts it), so the usb0 RNDIS recovery gadget that +- * client mode + net-flash rely on continues to bind. "host" alone would break +- * that recovery gadget, so "otg" is the correct value. +- */ ++ /* otg, not host: CONFIG_USB_DWC3_DUAL_ROLE is built in, so the port can ++ * still come up as a gadget (usb0) when cabled to a PC while also being ++ * able to host a USB Ethernet adapter. host would work for the adapter ++ * but would remove the gadget link permanently. */ + dr_mode = "otg"; ++ //dr_mode = "peripheral"; ++ //dr_mode = "host"; ++ /* flare-edge: set to otg for the host/client live-switch test — a stable ++ * network path (onboard eth0) is now in hand, so the usb0-gadget-inconsistency ++ * that motivated the earlier peripheral revert no longer blocks us. This ++ * matches sdk-patches/kernel/patches/0003-usb-otg-dual-role.patch. */ + }; + + /**********RTC**********/ diff --git a/luckfox-sdk-patches/uboot/configs/flare-ab.config b/luckfox-sdk-patches/uboot/configs/flare-ab.config new file mode 100644 index 0000000..1404655 --- /dev/null +++ b/luckfox-sdk-patches/uboot/configs/flare-ab.config @@ -0,0 +1,10 @@ +# flare-edge: A/B slot boot in U-Boot proper. +# +# Lean port of the vendor SPL A/B engine (common/flare_ab.c): AOSP +# AvbABData metadata in one CRC32-protected sector at misc+2048, slot +# suffixing hooked into part_get_info_by_name() (covers boot_fit AND the +# board_init()-time kernel-DTB/resource load), one tries decrement per +# boot attempt while a slot is unconfirmed, recovery-FIT fallback when +# both slots are exhausted, MaskRom when even that fails. +# Design: docs/decisions/0001-slot-machine.md (flare-edge repo). +CONFIG_FLARE_AB=y diff --git a/luckfox-sdk-patches/uboot/configs/flare-bootcount.config b/luckfox-sdk-patches/uboot/configs/flare-bootcount.config new file mode 100644 index 0000000..6a7f2f5 --- /dev/null +++ b/luckfox-sdk-patches/uboot/configs/flare-bootcount.config @@ -0,0 +1,35 @@ +# flare-edge: the env bootcount escalation layer is RETIRED. +# +# History: this fragment used to enable U-Boot's env bootcount +# options: autoboot.c incremented a counter in the 32 KiB env on +# every boot and, once it passed ${bootlimit}, ran ${altbootcmd}=download to +# drop into USB download/MaskRom. Two properties made it dangerous: +# 1. The counter lived in the env, so it PERSISTED across power cycles. +# 2. It escalated to USB download, not to the recovery FIT. +# A panel that lost power mid-boot several times therefore walked the counter +# past the limit and then booted straight into the USB-download screen on EVERY +# power-on, with no way to clear it from the device (issue #123, seen on a real +# panel at the warehouse 2026-09-02). +# +# Replacement: the A/B engine (common/flare_ab.c) now drives boot-failure +# escalation from a PMU register (OS_REG4), gated on the CRU reset-status +# register. It survives a warm reset (so in-session retries accumulate) but is +# cleared by a power-on reset, so escalation is: selected slot for a couple of +# attempts, then the other committed slot, then the recovery FIT, then USB +# download -- and a POWER CYCLE always restarts at the selected slot. flared +# clears OS_REG4 once a boot proves healthy and before a deliberate reboot. No +# per-boot flash writes, and no state that can strand a device across a power +# cycle. See docs/boot-flow.md and docs/decisions/0001-slot-machine.md. +# +# The filename is kept so the board makefile fragment-list reference +# (sdk-patches/board/patches/0001-86panel-seatbelt-wiring.patch) still resolves. +# This fragment is merged last, so it disables bootcount and sets the env +# whitelist authoritatively. +# CONFIG_BOOTCOUNT is not set +# CONFIG_BOOTCOUNT_LIMIT is not set +# CONFIG_BOOTCOUNT_ENV is not set +# Env whitelist WITHOUT the retired escalation keys (bootcount, bootlimit, +# altbootcmd, upgrade_available) -- a stale env carrying them can no longer feed +# the retired layer. bootcmd/bootdelay/preboot stay so a provisioned env can +# still override the compiled-in boot command. +CONFIG_ENVF_LIST="blkdevparts mtdparts sys_bootargs app reserved ipaddr serverip netmask gatewayip ethaddr bootcmd bootdelay preboot" diff --git a/luckfox-sdk-patches/uboot/configs/flare-display.config b/luckfox-sdk-patches/uboot/configs/flare-display.config new file mode 100644 index 0000000..ab9c0e6 --- /dev/null +++ b/luckfox-sdk-patches/uboot/configs/flare-display.config @@ -0,0 +1,78 @@ +# CONFIG_ATMEL_HLCD is not set +# CONFIG_BACKLIGHT_GPIO is not set +CONFIG_BACKLIGHT_PWM=y +# CONFIG_CMD_BMP is not set +# CONFIG_CMD_REGULATOR is not set +CONFIG_CONSOLE_NORMAL=y +# CONFIG_CONSOLE_ROTATION is not set +CONFIG_CONSOLE_SCROLL_LINES=1 +# CONFIG_CONSOLE_TRUETYPE is not set +CONFIG_DISPLAY=y +CONFIG_DM_PWM=y +# CONFIG_DM_REGULATOR_FIXED is not set +# CONFIG_DM_REGULATOR_GPIO is not set +CONFIG_DM_REGULATOR=y +CONFIG_DM_VIDEO=y +# CONFIG_DRM_MAXIM_MAX96745 is not set +# CONFIG_DRM_MAXIM_MAX96752F is not set +# CONFIG_DRM_MAXIM_MAX96755F is not set +CONFIG_DRM_MEM_RESERVED_SIZE_MBYTES=32 +CONFIG_DRM_MIPI_DSI=y +# CONFIG_DRM_PANEL_MAXIM_DESERIALIZER is not set +# CONFIG_DRM_ROCKCHIP_ANALOGIX_DP is not set +# CONFIG_DRM_ROCKCHIP_DW_DP is not set +# CONFIG_DRM_ROCKCHIP_DW_HDMI is not set +# CONFIG_DRM_ROCKCHIP_DW_HDMI_QP is not set +# CONFIG_DRM_ROCKCHIP_DW_MIPI_DSI2 is not set +# CONFIG_DRM_ROCKCHIP_DW_MIPI_DSI is not set +# CONFIG_DRM_ROCKCHIP_INNO_HDMI is not set +# CONFIG_DRM_ROCKCHIP_INNO_MIPI_PHY is not set +# CONFIG_DRM_ROCKCHIP_INNO_VIDEO_COMBO_PHY is not set +# CONFIG_DRM_ROCKCHIP_INNO_VIDEO_PHY is not set +# CONFIG_DRM_ROCKCHIP_LVDS is not set +CONFIG_DRM_ROCKCHIP_PANEL=y +CONFIG_DRM_ROCKCHIP_RGB=y +# CONFIG_DRM_ROCKCHIP_RK1000 is not set +# CONFIG_DRM_ROCKCHIP_RK618 is not set +# CONFIG_DRM_ROCKCHIP_SAMSUNG_MIPI_DCPHY is not set +CONFIG_DRM_ROCKCHIP=y +CONFIG_I2C_EDID=y +# CONFIG_NOP_PHY is not set +# CONFIG_PHY_ROCKCHIP_SAMSUNG_HDPTX_HDMI is not set +CONFIG_PHY=y +# CONFIG_PWM_EXYNOS is not set +CONFIG_PWM_ROCKCHIP=y +# CONFIG_PWM_TEGRA is not set +# CONFIG_REGULATOR_FAN53555 is not set +# CONFIG_REGULATOR_PWM is not set +# CONFIG_REGULATOR_RK860X is not set +CONFIG_ROCKCHIP_CUBIC_LUT_SIZE=0 +# CONFIG_DRM_ROCKCHIP_TVE is not set +# CONFIG_ROCKCHIP_INNO_HDMI_PHY is not set +# CONFIG_SPL_DM_REGULATOR is not set +# CONFIG_VIDCONSOLE_AS_LCD is not set +CONFIG_VIDEO_BPP16=y +CONFIG_VIDEO_BPP32=y +CONFIG_VIDEO_BPP8=y +# CONFIG_VIDEO_BRIDGE_ANALOGIX_ANX6345 is not set +# CONFIG_VIDEO_BRIDGE_NXP_PTN3460 is not set +# CONFIG_VIDEO_BRIDGE_PARADE_PS862X is not set +CONFIG_VIDEO_BRIDGE=y +# CONFIG_VIDEO_ROCKCHIP is not set +# CONFIG_VIDEO_TEGRA124 is not set +# flare-edge: BMP logo support for the boot splash. The rockchip_display logo +# path accepts 16/24/32bpp (display_logo() in drivers/video/drm/rockchip_display.c); +# our logo.bmp is 720x720 24bpp uncompressed, which matches the panel exactly. +# flare-edge: keep USING_KERNEL_DTB=y (the proven flow: envf import, fixups), +# but adopt an EMBEDDED kernel-style DTB instead of the booted slot's one. The +# 6.18 slot's mainline-style DTB has no vendor display nodes, which silenced +# the boot logo there; embedding the proven 5.10 board DTB (extracted from the +# vendor-built boot.img resource) makes U-Boot's own device world -- display +# included -- identical on every slot. Each slot's FIT still hands the real +# kernel its own fdt; fdt_addr_r stays reserved for it (see kernel_dtb.c). +# A DISABLED USING_KERNEL_DTB was tried first and broke the envf whitelist +# import (no blkdevparts on the cmdline -> no eMMC partitions -> rootwait +# hang on both slots); do not retry that route without fixing envf. +CONFIG_EMBED_KERNEL_DTB=y +CONFIG_EMBED_KERNEL_DTB_ALWAYS=y +CONFIG_EMBED_KERNEL_DTB_PATH="dts/rv1106-warden-kernel.dtb" diff --git a/luckfox-sdk-patches/uboot/configs/flare-spl-brom.config b/luckfox-sdk-patches/uboot/configs/flare-spl-brom.config new file mode 100644 index 0000000..bc02143 --- /dev/null +++ b/luckfox-sdk-patches/uboot/configs/flare-spl-brom.config @@ -0,0 +1,7 @@ +# flare-edge: build spl_bootrom.o so BOOT_DEVICE_BOOTROM is a registered SPL +# load method. Paired with the board_boot_order() change in +# arch/arm/mach-rockchip/spl-boot-order.c, this makes a failed U-Boot load drop +# to MaskRom instead of hanging. Does NOT set SPL_ROCKCHIP_BACK_TO_BROM: that +# would flip SPL_MMC_SUPPORT off (see mach-rockchip/Kconfig) and hand the whole +# load path to the BROM, which is a behaviour change we do not want. +CONFIG_SPL_BOOTROM_SUPPORT=y diff --git a/luckfox-sdk-patches/uboot/configs/flare-touch.config b/luckfox-sdk-patches/uboot/configs/flare-touch.config new file mode 100644 index 0000000..89e88a1 --- /dev/null +++ b/luckfox-sdk-patches/uboot/configs/flare-touch.config @@ -0,0 +1,12 @@ +# flare-edge: let U-Boot read the panel's touchscreen. +# +# The verbose-boot choice is made in the bootloader (see +# arch/arm/mach-rockchip/flare_touch.c), so it is on the kernel command line +# before the kernel prints its first line. That needs I2C, which this board's +# U-Boot did not have: only the EDID I2C helper was set, and that is the display +# path's EDID parser, not a controller driver. +# +# The GT911 sits on i2c3 (i2c@ff460000). Both symbols are required: the +# Rockchip controller driver depends on the DM I2C uclass. +CONFIG_DM_I2C=y +CONFIG_SYS_I2C_ROCKCHIP=y diff --git a/luckfox-sdk-patches/uboot/configs/flare-usb-gadget.config b/luckfox-sdk-patches/uboot/configs/flare-usb-gadget.config new file mode 100644 index 0000000..ca92b07 --- /dev/null +++ b/luckfox-sdk-patches/uboot/configs/flare-usb-gadget.config @@ -0,0 +1,54 @@ +# flare-edge: USB device-mode recovery from U-Boot (rockusb gadget). +# +# WHY: the BootROM only self-enters MaskRom when it cannot LOAD idblock/uboot. +# A U-Boot that loads but then fails to boot (a bug in our display/FLARE_AB +# code, an exhausted A/B set, a corrupt recovery FIT) never reaches Linux, so +# the software MaskRom trigger and the rescue-image RNDIS gadget are both +# unavailable, leaving only the daughterboard-blocked BOOT button. Enabling +# the DWC3 USB gadget + rockusb closes that gap: `download` (which FLARE_AB and +# altbootcmd already invoke on failure) runs `rockusb` FROM U-BOOT +# (cmd/download.c), exposing the Rockchip flashing protocol on the existing USB +# port (2207:110c, same as MaskRom to upgrade_tool). Recover or reflash without +# opening the case. Falls through to `rbrom` (BootROM MaskRom) only if the +# gadget can't start. +# +# RV1106 USB = DWC3 (rv1106.dtsi usb@ffb00000 snps,dwc3) + Innosilicon USB2 +# PHY, dr_mode=otg. Symbols below mirror the vendor rv1106-usb.config / +# rv1106-dfu.config references. Fits the 512K uboot partition (A/B layout). +CONFIG_USB=y +CONFIG_DM_USB=y +CONFIG_USB_DWC3=y +CONFIG_USB_DWC3_GENERIC=y +CONFIG_USB_DWC3_GADGET=y +# dwc3-generic unconditionally compiles its host (xHCI) probe in non-SPL +# builds (it calls xhci_register), so the xHCI host core must link even though +# we only use gadget mode; the vendor rv1106-usb.config pairs them the same +# way. Harmless in peripheral/otg mode; the host driver is simply never probed. +CONFIG_USB_HOST=y +CONFIG_USB_XHCI_HCD=y +CONFIG_PHY_ROCKCHIP_INNO_USB2=y +CONFIG_DM_REGULATOR=y +CONFIG_DM_REGULATOR_FIXED=y +CONFIG_USB_GADGET=y +CONFIG_USB_GADGET_DUALSPEED=y +CONFIG_USB_GADGET_DOWNLOAD=y +# Fastboot is a separate download function whose FASTBOOT_BUF_ADDR symbol has +# no default and would make `yes "" | make oldconfig` loop forever (it produced +# a 16 GB log). We only want rockusb, so disable fastboot explicitly, exactly +# as the vendor rv1106-dfu.config does. rockusb coexists fine without it. +# CONFIG_FASTBOOT is not set +CONFIG_USB_GADGET_MANUFACTURER="Rockchip" +CONFIG_USB_GADGET_PRODUCT_NUM=0x110c +CONFIG_USB_GADGET_VENDOR_NUM=0x2207 +CONFIG_USB_GADGET_VBUS_DRAW=2 +# rockusb has no dedicated Kconfig symbol. f_rockusb.c is #include'd by +# f_mass_storage.c and gated purely by CMD_ROCKUSB + the UMS/gadget framework +# (the mass-storage function, already defined in rv1106_common.h). +CONFIG_CMD_ROCKUSB=y +# The display stack + this USB gadget push uboot.itb past the old 256K limit +# (287K). scripts/fit-core.sh uses SPL_FIT_IMAGE_KB as BOTH the pack ceiling +# and how many KB SPL reads for the FIT. Raise it to 512 to match the A/B +# layout's 512K `uboot` partition (docs/decisions/0003-partition-layout.md). +# This is an SPL/idblock change (self-recovering to MaskRom if wrong), taken in +# the same MaskRom re-provision as the repartition. +CONFIG_SPL_FIT_IMAGE_KB=512 diff --git a/luckfox-sdk-patches/uboot/configs/flare-verbose.config b/luckfox-sdk-patches/uboot/configs/flare-verbose.config new file mode 100644 index 0000000..f8fe004 --- /dev/null +++ b/luckfox-sdk-patches/uboot/configs/flare-verbose.config @@ -0,0 +1,12 @@ +# flare-edge: boot instrumentation. +# +# Prefixes EVERY U-Boot console line with [ssss.uuuuuu] microseconds since +# power-on, using the timestamping puts() that already exists in this Rockchip +# fork (common/console.c, guarded by this symbol). Same time base as the +# FLARE_TRACE macro and as Rockchip's own "Total: x/y ms" line, so U-Boot, +# SPL and the kernel can all be put on one axis. +# +# Cost is ~15 characters per line. At 115200 baud that is ~1.3 ms per line, so +# a verbose boot IS measurably slower than a production one -- read timings +# from an instrumented boot as an upper bound, not as production numbers. +CONFIG_BOOTSTAGE_PRINTF_TIMESTAMP=y diff --git a/luckfox-sdk-patches/uboot/dts/README.md b/luckfox-sdk-patches/uboot/dts/README.md new file mode 100644 index 0000000..bd75183 --- /dev/null +++ b/luckfox-sdk-patches/uboot/dts/README.md @@ -0,0 +1,49 @@ +# rv1106-warden-kernel.dtb -- provenance and regeneration + +This binary is U-Boot's embedded control DTB (`CONFIG_EMBED_KERNEL_DTB_PATH`, +set in `../configs/flare-display.config`). With `CONFIG_EMBED_KERNEL_DTB_ALWAYS` +U-Boot adopts it in `board_init()` instead of reading the booted slot's DTB out +of `resource`, so the display bring-up (boot logo included) is identical on +every slot regardless of the slot kernel's own device tree. + +## Where this exact blob came from + +Extracted 2026-09-01 from the vendor-built 5.10 firmware image +`sdk/output/image/boot.img` (build of 2026-08-24, WardenOS 0.3.x line): the +`rk-kernel.dtb` entry of its `resource` sub-image, 73379 bytes, dtb magic +`d00dfeed`. That is byte-for-byte the DTB U-Boot's display stack was proven +against when it adopted the slot DTB directly. + +## Regenerating after a kernel DTS change + +Run this from a `blueflare/flare-edge` worktree with this SDK checked out at +`vendor/warden-sdk` (the normal layout). The 5.10 board DTS is the source of +truth (`sdk/sysdrv/source/kernel/arch/arm/boot/dts/rv1106g-luckfox-pico-86panel.dts` +plus its ipc dtsi, where `sdk/` is flare-edge's own vendor-SDK checkout, not +this repo). After any display-relevant change there, rebuild the firmware +once and re-extract: + +```python +import struct, subprocess, re +fit = open('sdk/output/image/boot.img','rb').read() +open('/tmp/fitmeta.dtb','wb').write(fit[:4096]) +def fdtget(node, prop): + r = subprocess.run(['fdtget','-ti','/tmp/fitmeta.dtb',node,prop], + capture_output=True, text=True) + return int(r.stdout.split()[0]) +pos, size = fdtget('/images/resource','data-position'), fdtget('/images/resource','data-size') +res = fit[pos:pos+size] +for m in re.finditer(b'ENTR', res): + e = res[m.start():m.start()+272] + name = e[4:260].split(b'\0')[0].decode() + blk_off, sz = struct.unpack('