Skip to content

grub: embed per-SoC cmdline in efi.bin, keep rootfs generic - #231

Open
Phanendra Yarra (phanendra-qc) wants to merge 1 commit into
qualcomm-linux:mainfrom
phanendra-qc:rootfs/grub-soc-cmdline-via-efi
Open

grub: embed per-SoC cmdline in efi.bin, keep rootfs generic#231
Phanendra Yarra (phanendra-qc) wants to merge 1 commit into
qualcomm-linux:mainfrom
phanendra-qc:rootfs/grub-soc-cmdline-via-efi

Conversation

@phanendra-qc

Copy link
Copy Markdown

Board-specific kernel parameters (e.g. arm64.nopauth for RB4) are now carried by each board's BOOTAA64.EFI rather than baked into the rootfs grub.cfg or resolved at runtime by a userspace service.

Design: soc_extra_cmdline GRUB variable

The ESP (efi.bin) is already per-board in gen-flash-dirs.sh (sector size, VolatileVars.bin). BOOTAA64.EFI already embeds a bootstrap grub.cfg via grub-mkstandalone. That bootstrap config is the natural place to carry board identity — it is evaluated at GRUB stage, before the kernel loads, and GRUB variables set there survive the configfile jump into the rootfs grub.cfg.

build-efi-esp.sh --extra-cmdline "arm64.nopauth" → rb4/efi.bin
build-efi-esp.sh → generic/efi.bin
build-rootfs.sh → rootfs.img (shared)

Bootstrap config (baked into BOOTAA64.EFI):
set soc_extra_cmdline="arm64.nopauth" # RB4
set soc_extra_cmdline="" # generic
configfile ($root)/boot/grub/grub.cfg

rootfs grub.cfg linux line (single generic entry):
linux /boot/vmlinuz-... <base_cmdline> ${soc_extra_cmdline}

GRUB expands ${soc_extra_cmdline} at runtime from the bootstrap value. The rootfs image is identical for all boards.

Changes

bootloader/build-efi-esp.sh

  • Add --extra-cmdline argument (default empty).
  • Embed 'set soc_extra_cmdline=""' in the bootstrap config written into BOOTAA64.EFI by grub-mkstandalone.

rootfs/scripts/build-rootfs.sh

  • GRUB_DEFAULT reverted to 0 (single entry, no grubenv needed).
  • Remove Step 7.6 (grub-soc-map.conf generation).
  • Replace Step 9.4 (RB4 entry injection) with a sed pass that appends '${soc_extra_cmdline}' to every linux line in grub.cfg.

flash/gen-flash-dirs.sh

  • Read extra_cmdline from each board's JSON entry.
  • When non-empty, rebuild efi.bin for that board via build-efi-esp.sh --extra-cmdline before placing it in the flash directory.

boards.json example

{ "name": "rb4", "ptool_platform": "qrb4210-rb2",
"extra_cmdline": "arm64.nopauth" } { "name": "rb5", "ptool_platform": "qrb5165-rb5" }

Board-specific kernel parameters (e.g. arm64.nopauth for RB4) are now
carried by each board's BOOTAA64.EFI rather than baked into the rootfs
grub.cfg or resolved at runtime by a userspace service.

Problem with the previous approach
-----------------------------------
The earlier design used two grub.cfg menu entries (Generic / RB4) and a
grub-soc-select.service that ran at sysinit, read the Device Tree serial
number, and called grub-set-default to pick the right entry for the next
boot.  This worked but had two drawbacks:

  - The rootfs was not fully board-agnostic: it contained the RB4 menu
    entry, grub-soc-map.conf, and the runtime selection service.
  - The correct cmdline only took effect from the second boot (the service
    runs after the kernel is already up).

New design: soc_extra_cmdline GRUB variable
-------------------------------------------
The ESP (efi.bin) is already per-board in gen-flash-dirs.sh (sector size,
VolatileVars.bin).  BOOTAA64.EFI already embeds a bootstrap grub.cfg via
grub-mkstandalone.  That bootstrap config is the natural place to carry
board identity — it is evaluated at GRUB stage, before the kernel loads,
and GRUB variables set there survive the configfile jump into the rootfs
grub.cfg.

  build-efi-esp.sh --extra-cmdline "arm64.nopauth"   →  rb4/efi.bin
  build-efi-esp.sh                                    →  generic/efi.bin
  build-rootfs.sh                                     →  rootfs.img (shared)

Bootstrap config (baked into BOOTAA64.EFI):
  set soc_extra_cmdline="arm64.nopauth"   # RB4
  set soc_extra_cmdline=""               # generic
  configfile ($root)/boot/grub/grub.cfg

rootfs grub.cfg linux line (single generic entry):
  linux /boot/vmlinuz-... <base_cmdline> ${soc_extra_cmdline}

GRUB expands ${soc_extra_cmdline} at runtime from the bootstrap value.
The rootfs image is identical for all boards.

Changes
-------
bootloader/build-efi-esp.sh
  - Add --extra-cmdline <params> argument (default empty).
  - Embed 'set soc_extra_cmdline="<value>"' in the bootstrap config
    written into BOOTAA64.EFI by grub-mkstandalone.

rootfs/scripts/build-rootfs.sh
  - GRUB_DEFAULT reverted to 0 (single entry, no grubenv needed).
  - Remove Step 7.6 (grub-soc-map.conf generation).
  - Replace Step 9.4 (RB4 entry injection) with a sed pass that appends
    '${soc_extra_cmdline}' to every linux line in grub.cfg.

flash/gen-flash-dirs.sh
  - Read extra_cmdline from each board's JSON entry.
  - When non-empty, rebuild efi.bin for that board via build-efi-esp.sh
    --extra-cmdline before placing it in the flash directory.

boards.json example
-------------------
  { "name": "rb4", "ptool_platform": "qrb4210-rb2",
    "extra_cmdline": "arm64.nopauth" }
  { "name": "rb5", "ptool_platform": "qrb5165-rb5" }
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.

1 participant