Skip to content

Fix ubi write failing after TFTP on hi3516av200 - #6

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

Fix ubi write failing after TFTP on hi3516av200#6
widgetii merged 2 commits into
masterfrom
fix/ubi-write-after-tftp

Conversation

@widgetii

Copy link
Copy Markdown
Member

Summary

  • ubi write failed with -ENOMEM after any TFTP transfer because hi-common.h unconditionally redefined CONFIG_SYS_MALLOC_LEN to 768KB, overriding the board-specific value in hi3516av200.h
  • The 576KB effective heap was consumed by UBI structures + network allocations (~548KB), leaving insufficient room for the 124KB LEB buffer that ubi write needs
  • Guard CONFIG_SYS_MALLOC_LEN in hi-common.h with #ifndef and increase hi3516av200 malloc pool from 128KB to 2MB

Root cause

hi3516av200.h defines CONFIG_SYS_MALLOC_LEN at line 104, then #includes hi-common.h at line 358. hi-common.h unconditionally redefines CONFIG_SYS_MALLOC_LEN to CONFIG_ENV_SIZE + 512*1024, silently discarding whatever the board header set. This is why the issue reporter's attempt to increase malloc to 2MB in hi3516av200.h had no effect.

Debug instrumentation on real hardware confirmed:

heap start=0x88370000 end=0x88400000 total=576K used=548K
vmalloc(126976) failed → err=-12 (ENOMEM)

Test plan

  • Full defib restore with all 7 MTD partitions (including 4 UBI partitions via ubi write after TFTP) on real hi3516av200 hardware — all partitions written successfully, zero errors
  • Multiple TFTP transfers still work in the same session
  • Verified with 2MB malloc pool (2.3MB total heap)

Closes #5

🤖 Generated with Claude Code

John-1 and others added 2 commits April 21, 2026 21:31
`ubi write` failed with -ENOMEM after any TFTP transfer because
`vmalloc(126976)` (malloc for one LEB) could not find 124KB of free
heap. The root cause was that hi-common.h unconditionally redefined
CONFIG_SYS_MALLOC_LEN to (CONFIG_ENV_SIZE + 512KB), silently
overriding the board-specific value set in hi3516av200.h. This left
only ~576KB of heap, of which ~548KB was consumed by UBI structures
and network stack allocations after TFTP.

Guard CONFIG_SYS_MALLOC_LEN in hi-common.h with #ifndef so
board-specific values are preserved, and increase the hi3516av200
malloc pool from 128KB to 2MB.

Closes #5

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The #ifndef guard in hi-common.h now lets board-specific
CONFIG_SYS_MALLOC_LEN values through. The hi3519v101 default of
128KB was below the 512KB minimum required by UBI, causing a
build error. Increase to 2MB to match hi3516av200.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@widgetii
widgetii merged commit fb44ad2 into master Apr 21, 2026
2 checks passed
widgetii added a commit that referenced this pull request Apr 22, 2026
…ying kernel (#10)

## 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 #6)

## Test plan

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

Closes #9

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: john-1 <john-1@users.noreply.github.com>
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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.

ubi write fails after TFTP on hi3516av200 — NAND write path corrupted by network driver

2 participants