Repository navigation
load_novatek: refuse to load HDAL over the kernel's own memory - #2657
Conversation
The vendor U-Boot lays memory out from osmem (DT memory node up to it, HDAL pool from it), while the kernel takes its RAM from mem= alone. The bootcmd the wiki gives these boards re-runs the saved bootargs, so the two drift apart as soon as one is changed without the other. Booted with mem= past the node, the kernel owns the start of the HDAL pool and nvtmpp_heap_init in kflow_common oopses (mmioset, NULL dereference) and panics the camera, every boot. Compare mem= with the DT memory node first. When it runs past it, say so, skip the HDAL modules, and write the size U-Boot used back into bootargs so the next boot is consistent. Proven on an NT98566 + SC501AI: saved mem=54M with osmem=32M boots without the panic and heals on the next reboot.
PR Summary by QodoGuard Novatek HDAL loading against overlapping kernel memory
AI Description
Diagram
High-Level Assessment
Files changed (1)
|
Code Review by Qodo
1.
|
A space-separated awk record kept /proc/cmdline's trailing newline on the final argument, so a mem= placed last never matched and the guard let HDAL load over the kernel. Split the command line in the shell instead.
Problem
On NT9856x boards the vendor U-Boot lays memory out from the
osmemenvironment variable: the DT memory node it passes ends atosmemand the HDAL video pool starts there. The kernel takes its RAM frommem=inbootargsalone, and the bootcmd these boards were given re-runs the savedbootargs, so the two values drift apart once one is changed without the other (#2107).When
mem=is larger thanosmem, the kernel owns the start of the HDAL pool. The first HDAL module to initialise its heap writes over kernel memory, oopses innvtmpp_heap_init, and the camera panics, then reboots and panics again on every boot.load_novateknow comparesmem=with the DT memory node before loading anything. On a mismatch it logs why, skips the HDAL modules, and writes the size U-Boot actually used back intobootargs, so the next boot is consistent.The opposite drift,
osmemlarger thanmem=, hangs the kernel before the console, so nothing in userspace can catch it. That case is documented in the wiki instead (follow-up PR there).This isn't a toolchain problem. The 2022 gcc-7.5 kernel, a local gcc-13.3 build, and the 2026-10-21 nightly all boot at
mem=54Mwhenosmemmatches.Hardware tested on
NT98566 + SC501AI, 128 MB, XM vendor U-Boot 2019.04, 2026-10-21 nightly. I tested the new
load_novatekplaced in the overlay; it was removed afterwards. Serial console, observed directly.Evidence
Before: stock
load_novatek, savedmem=54Mwithosmem=32M:After: this
load_novatek, same environment:The next reboot comes up with
mem=32M, all 27 HDAL modules loaded, and the encoder at 25 fps (VIDEOENC USER WORK: PULL 25 REL 25). In the normal state (mem=32M,osmem=32M) the check readsdt_mem=32 booted_mem=32and returns without doing anything.Local
make BOARD=nt98566_lite:STRICT=1 test_shell_parse.sh,STRICT=1 test_strip_shell_comments.shandci-matrix.py --self-testpass. The selector buildsnt98562_liteandnt98566_lite.Scope
general/package/all-patches/linux/(those go to OpenIPC/linux)general/overlay/or in a sharedload_<vendor>script hardcodes a value specific to my boardLD_PRELOAD, and no binaries that cannot be rebuilt from source