Skip to content

refactor(grub): increased environment size to 2kB#650

Merged
HarryWaschkeit merged 8 commits into
omnect:mainfrom
HarryWaschkeit:hwt-2026-04-29-refactor-grub-enlarged-environment
May 4, 2026
Merged

refactor(grub): increased environment size to 2kB#650
HarryWaschkeit merged 8 commits into
omnect:mainfrom
HarryWaschkeit:hwt-2026-04-29-refactor-grub-enlarged-environment

Conversation

@HarryWaschkeit
Copy link
Copy Markdown
Contributor

@HarryWaschkeit HarryWaschkeit commented Apr 29, 2026

Why: feature flash-mode-3 allows to flash a device with an externally available (retrievable via HTTP[S]) image file.
Two environment variables - beside the flash-mode variable which chooses among the available flash modes - control what is to be flashed:

  • one contains the URL to a wic.xz file containing the image to be flashed to the boot device
  • the other one holding the SHA256sum for the retrieved image file for verification

NOTE: have a look at chapter "Flash Mode 3" in README.md file for full details.

Mainly the URL can be rather lengthy, possibly exceeding the standard environmrent size, together with all other variables normally set.

For this an possibly other future use cases the grubenv got extended.

NOTE: grub documentation actually states to only use grub-editenv <file> create to create an ampty einvironment file, and also for any modification the grub-editenv program shall be used. However, the grub source code currently does not make any assumptions about the file size.
The only check implemented to validate en environment file is whether it starts with the right signature (# GRUB Environment Block). Otherwise, free space to set new variables is the complete end region that is filled exclusively with # characters: the first newline that is detected marks the end of the stored variable settings where any line starting with a # character is treated as comment, hence ignored during variable/value pair parsing.

Why: feature `flash-mode-3` allows to flash a device with an externally
available (retrievable via HTTP[S]) image files.
Two environment variables - beside the `flash-mode` variable which
chooses among the available flash modes - control what is to be flashed:

- one contains the URL to a `wic.xz` file containing the image to be
  flashed to the boot device
- the other one holding the SHA256sum for the retrieved image file for
  verification

**NOTE:** have a look at chapter "Flash Mode 3" in README.md file for
full details.

Mainly the URL can be rather lengthy, possibly exceeding the standard
environmrent size, together with all other variables normally set.

For this an possibly other future use cases the `grubenv` got extended.

**NOTE:** grub documentation actually states to only use `grub-editenv
<file> create` to create an ampty einvironment file, and also for any
modification the `grub-editenv` program shall be used.
However, the `grub` source code currently does not make any assumptions
about the file size.
The only check implemented to validate en environment file is whether
it starts with the right signature (`# GRUB Environment Block`).
Otherwise, free space to set new variables is the complete end region
that is filled exclusively with `#` characters: the first newline that
is detected marks the end of the stored variable settings where any line
starting with a `#` character is treated as comment, hence ignored
during variable/value pair parsing.

Signed-off-by: Harry Waschkeit <44188360+HarryWaschkeit@users.noreply.github.com>
If for whatever reason not all variables required for flash mode 3 got
set correctly, the flash-mode-3 init script could fail leaving a system
behind with a shell in the initramfs.

Even worse, it was possible that not even a power-cycle could revive the
system, because the script left the flash mode operation panding by not
cleaning up the environment.

Admittedly, flash modes are generally devlopment-only feature, but
possibly having to manually attend a device to sort things out could be
rather inconvenient.

This change improves the situation so that at least after having failed
a flash mode (3) operation a power cycle brings up the system again as
it was before.

Signed-off-by: Harry Waschkeit <44188360+HarryWaschkeit@users.noreply.github.com>
@HarryWaschkeit HarryWaschkeit marked this pull request as draft April 29, 2026 16:08
… thereby hiding errors

Signed-off-by: Harry Waschkeit <44188360+HarryWaschkeit@users.noreply.github.com>
…ader_env_grub.sh)

Signed-off-by: Harry Waschkeit <44188360+HarryWaschkeit@users.noreply.github.com>
@HarryWaschkeit HarryWaschkeit marked this pull request as ready for review April 30, 2026 20:59
@HarryWaschkeit HarryWaschkeit requested a review from mlilien May 4, 2026 08:30
Comment thread recipes-bsp/grub/grub-efi_%.bbappend
Signed-off-by: Harry Waschkeit <44188360+HarryWaschkeit@users.noreply.github.com>
@HarryWaschkeit HarryWaschkeit requested a review from mlilien May 4, 2026 15:24
@HarryWaschkeit HarryWaschkeit merged commit e24e363 into omnect:main May 4, 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.

2 participants