Skip to content

fix: import first variable from auxiliary environment#1483

Merged
wkz merged 1 commit intokernelkit:mainfrom
saba8814:fix/uboot-aux-env-first-var-import
Apr 30, 2026
Merged

fix: import first variable from auxiliary environment#1483
wkz merged 1 commit intokernelkit:mainfrom
saba8814:fix/uboot-aux-env-first-var-import

Conversation

@saba8814
Copy link
Copy Markdown
Contributor

Description

Checklist

Tick relevant boxes, this PR is-a or has-a:

  • Bugfix
    • Regression tests
    • ChangeLog updates (for next release)
  • Feature
    • YANG model change => revision updated?
    • Regression tests added?
    • ChangeLog updates (for next release)
    • Documentation added?
  • Test changes
    • Checked in changed Readme.adoc (make test-spec)
    • Added new test to group Readme.adoc and yaml file
  • Code style update (formatting, renaming)
  • Refactoring (please detail in commit messages)
  • Build related changes
  • Documentation content changes
    • ChangeLog updated (for major changes)
  • Other (please describe):

@troglobit
Copy link
Copy Markdown
Contributor

@wkz could you have a look at this, please?

@wkz
Copy link
Copy Markdown
Contributor

wkz commented Apr 29, 2026

This looks like the right fix 👍

I would prefer a bit more thorough commit message though:

  • Infix is big, please prefix the subject with uboot: (look through the log to see the pattern)
  • Describe what going from -b to -c means
  • Most importanly: On what systems has this been tested? For changes like this, it is critical information to assess the risk of pulling this in.

@saba8814 saba8814 changed the title fix: import first variable from auxiliary environment uboot: import first variable from auxiliary environment Apr 29, 2026
@saba8814
Copy link
Copy Markdown
Contributor Author

saba8814 commented Apr 29, 2026

Thank you for the review @wkz , as discussed below are runs with -b and -c to compare:

No Fix(-b)

(ixboot) load ${devtype} ${devnum}:${auxpart} ${loadaddr} /uboot.env
16384 bytes read in 0 ms
(ixboot) md.b ${loadaddr} 100
40200000: b0 f2 30 3b 42 4f 4f 54 5f 4f 52 44 45 52 3d 70 ..0;BOOT_ORDER=p
40200010: 72 69 6d 61 72 79 20 73 65 63 6f 6e 64 61 72 79 rimary secondary
40200020: 20 6e 65 74 00 42 4f 4f 54 5f 70 72 69 6d 61 72  net.BOOT_primar
40200030: 79 5f 4c 45 46 54 3d 31 00 42 4f 4f 54 5f 73 65 y_LEFT=1.BOOT_se
40200040: 63 6f 6e 64 61 72 79 5f 4c 45 46 54 3d 31 00 42 condary_LEFT=1.B
40200050: 4f 4f 54 5f 6e 65 74 5f 4c 45 46 54 3d 31 00 00 OOT_net_LEFT=1..
40200060: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ................
40200070: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ................
40200080: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ................
40200090: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ................
402000a0: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ................
402000b0: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ................
402000c0: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ................
402000d0: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ................
402000e0: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ................
402000f0: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ................
(ixboot) setenv BOOT_ORDER FOOBARNOTSET
(ixboot) env import -b ${loadaddr} ${filesize} BOOT_ORDER
(ixboot) printenv BOOT_ORDER
BOOT_ORDER=FOOBARNOTSET
(ixboot) setenv BOOT_primary_LEFT FOOBARNOTSET
(ixboot) env import -b ${loadaddr} ${filesize} BOOT_primary_LEFT
(ixboot) printenv BOOT_primary_LEFT
BOOT_primary_LEFT=1
(ixboot)

With Fix(-c)

(ixboot) load ${devtype} ${devnum}:${auxpart} ${loadaddr} /uboot.env
16384 bytes read in 0 ms
(ixboot) md.b ${loadaddr} 100
40200000: b0 f2 30 3b 42 4f 4f 54 5f 4f 52 44 45 52 3d 70 ..0;BOOT_ORDER=p
40200010: 72 69 6d 61 72 79 20 73 65 63 6f 6e 64 61 72 79 rimary secondary
40200020: 20 6e 65 74 00 42 4f 4f 54 5f 70 72 69 6d 61 72  net.BOOT_primar
40200030: 79 5f 4c 45 46 54 3d 31 00 42 4f 4f 54 5f 73 65 y_LEFT=1.BOOT_se
40200040: 63 6f 6e 64 61 72 79 5f 4c 45 46 54 3d 31 00 42 condary_LEFT=1.B
40200050: 4f 4f 54 5f 6e 65 74 5f 4c 45 46 54 3d 31 00 00 OOT_net_LEFT=1..
40200060: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ................
40200070: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ................
40200080: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ................
40200090: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ................
402000a0: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ................
402000b0: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ................
402000c0: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ................
402000d0: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ................
402000e0: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ................
402000f0: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ................
(ixboot) printenv BOOT_ORDER
BOOT_ORDER=primary secondary net
(ixboot) setenv BOOT_ORDER FOOBARNOTSET
(ixboot) env import -c ${loadaddr} ${filesize} BOOT_ORDER
(ixboot) printenv BOOT_ORDER
BOOT_ORDER=primary secondary net
(ixboot)

The U-Boot env file is generated by
mkenvimage, which prefixes the variable data with a 4-byte CRC32 by default.
ixpreboot.sh previously imported it with `env import -b` as per uboot docs(-b assume binary format (’0’ separated, “00” terminated).),
which treats the buffer as raw binary and does not strip the CRC.
As a result the first variable's name is parsed a part of CRC.
Later variables import correctly because by then the parser is past the CRC.
Switching to `env import -c` as per uboot docs (-c assume checksum protected environment format.)
makes U-Boot validate and strip the CRC before parsing, so the first variable imports under its real name.

Tested on:
- QEMU

Signed-off-by: Ejub Sabic <ejub1946@outlook.com>
@saba8814 saba8814 force-pushed the fix/uboot-aux-env-first-var-import branch from 72021cc to 29222e1 Compare April 29, 2026 21:28
@saba8814 saba8814 changed the title uboot: import first variable from auxiliary environment fix: import first variable from auxiliary environment Apr 29, 2026
Copy link
Copy Markdown
Contributor

@wkz wkz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice to get to the bottom of this - great job! 🥇

@wkz wkz merged commit 4c0996b into kernelkit:main Apr 30, 2026
7 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.

3 participants