Skip to content

Guard CONFIG_ENV_OFFSET/SIZE in hi-common.h to prevent saveenv destroying kernel - #10

Merged
widgetii merged 2 commits into
masterfrom
fix/ubi-write-after-tftp
Apr 22, 2026
Merged

Guard CONFIG_ENV_OFFSET/SIZE in hi-common.h to prevent saveenv destroying kernel#10
widgetii merged 2 commits into
masterfrom
fix/ubi-write-after-tftp

Conversation

@widgetii

Copy link
Copy Markdown
Member

Summary

  • hi-common.h unconditionally overrides CONFIG_ENV_OFFSET from 0x80000 to 0x40000, placing the environment at 256KB — inside the kernel area on NAND
  • saveenv erases the 128KB block at 0x40000-0x5FFFF, destroying kernel data at 0x50000
  • Wrap CONFIG_ENV_OFFSET, CONFIG_ENV_SIZE, and CONFIG_ENV_SECT_SIZE with #ifndef guards (same pattern as the CONFIG_SYS_MALLOC_LEN fix in Fix ubi write failing after TFTP on hi3516av200 #6)

Test plan

  • Cold NAND boot — passes
  • Full 7-partition UBI restore — all partitions written, zero errors

Closes #9

🤖 Generated with Claude Code

John-1 and others added 2 commits April 22, 2026 17:47
The previous fix used CONFIG_ENV_SIZE in the malloc definition, but
hi-common.h redefines CONFIG_ENV_SIZE from 0x40000 to 0x10000 after
hi3516av200.h, silently shrinking the heap from 768KB to 576KB.

Use a literal 0x40000 + 768KB = 1MB total heap. This value:
- Fits UBI's 124KB vmalloc after TFTP (issue #5)
- Stays within SPL MMU page table limits for cold NAND boot (issue #7)

Tested on hardware: cold NAND boot OK, full 7-partition UBI restore OK.

Closes #7

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
hi-common.h unconditionally overrides CONFIG_ENV_OFFSET from 0x80000
to 0x40000, placing the U-Boot environment at 256KB — inside the
kernel area on NAND cameras. saveenv then erases the 128KB block at
0x40000-0x5FFFF, destroying kernel data starting at 0x50000.

Wrap CONFIG_ENV_OFFSET, CONFIG_ENV_SIZE, and CONFIG_ENV_SECT_SIZE
with #ifndef guards so board-specific values are preserved.

Also pad mini-boot.bin to 1MB in build.sh — SPI NAND cold boot
requires the full boot partition to be written (the FMC memory-mapped
interface needs contiguous page data across erase block boundaries).

Tested on hardware: cold NAND boot + full UBI restore both pass.

Closes #9

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@widgetii
widgetii force-pushed the fix/ubi-write-after-tftp branch from 5cb24f8 to 2fc0df9 Compare April 22, 2026 17:57
@widgetii
widgetii merged commit 4c16d7b into master Apr 22, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

hi3516av200: saveenv destroys kernel on NAND — CONFIG_ENV_OFFSET set to NOR offset

2 participants