Skip to content

Conversation

@bjordiscollaku
Copy link
Contributor

Summary

This PR adds end-to-end support for booting via a single combined DTB
image loaded by UEFI, and updates the Ubuntu rootfs builder to be
DTB-agnostic at the GRUB layer.

Concretely, it introduces a new build-dtb-image.sh helper for building
a FAT image containing a combined DTB, and simplifies the GRUB
configuration generated by build-ubuntu-rootfs.sh to no longer select
per-platform DTBs.

Changes

1. New DTB image tooling: build-dtb-image.sh

Adds a standalone script that generates a FAT-formatted image containing
a single combined DTB for Qualcomm-based ARM64 platforms.

Key behavior:

  • Consumes a manifest listing DTB filenames (one per line), supporting:
    • Absolute paths, or
    • Paths relative to a DTB source directory (-dtb-src).
  • Normalizes the manifest into a sanitized temporary list:
    • Skips blank lines and comments (#).
    • Resolves relative paths against the DTB source directory.
  • Validates that:
    • The manifest file exists and yields at least one DTB entry.
    • Every referenced DTB file exists on disk.
    • The -size argument is a positive integer (MB).
  • Concatenates all DTBs in manifest order into:
    • <DTB_SRC>/combined-dtb.dtb.
  • Builds a FAT filesystem image:
    • Size is configurable via -size (default: 4 MB).
    • Uses dd to create the image.
    • Attaches to a loop device with losetup.
    • Formats with mkfs.vfat.
    • Mounts on a mktemp-generated directory.
    • Copies combined-dtb.dtb into the root of the FAT filesystem.

Robustness and cleanup:

  • Uses set -euo pipefail.
  • Installs an EXIT trap at startup.
  • cleanup():
    • Preserves the original exit status.
    • Unmounts the temporary mountpoint only if it exists and is mounted.
    • Detaches the loop device only if it was created.
    • Removes the temporary manifest file and mount directory.

This provides a reproducible, automation-friendly way to package a
curated DTB set into a single combined DTB binary and corresponding FAT
image (dtb.bin) suitable for UEFI-driven boot flows and CI pipelines.

2. DTB-agnostic GRUB config in build-ubuntu-rootfs.sh

Updates the Ubuntu rootfs builder script to align with the new UEFI DTB
loading model:

  • Previously:
    • GRUB generated three menu entries:
      • EVK DTB
      • CRD DTB
      • QLI/Linux-only entry
    • Each platform-specific entry referenced a DTB via a devicetree
      line, pointing into /lib/firmware/<kernel>/device-tree/....
  • Now:
    • UEFI is responsible for loading dtb.bin (the combined DTB FAT
      image) before transferring control to GRUB.
    • GRUB no longer selects a DTB and does not emit any devicetree
      directives.

New behavior:

  • Generates a single DTB-agnostic GRUB entry:

    set timeout=5
    
    menuentry "Ubuntu ${CODENAME}" {
        search --no-floppy --label system --set=root
        linux /boot/vmlinuz-$kernel_ver earlycon console=ttyMSM0,115200n8 \
            root=LABEL=system cma=128M rw clk_ignore_unused pd_ignore_unused \
            efi=noruntime rootwait ignore_loglevel
        initrd /boot/initrd.img-$kernel_ver
    }

…ation

Introduce build-dtb-image.sh, a standalone tool to generate a FAT-formatted image containing a single combined DTB for Qualcomm-based ARM64 platforms.

The script:
- Consumes a manifest listing DTB filenames (one per line), supporting both absolute and DTB source–relative paths.
- Normalizes and sanitizes the manifest into a temporary list, skipping blank and comment lines.
- Validates that:
  - The manifest file exists and yields at least one DTB entry.
  - All referenced DTB files exist under the specified DTB source tree.
  - The requested FAT image size (-size) is a positive integer (MB).
- Concatenates DTBs in manifest order into <DTB_SRC>/combined-dtb.dtb
- Creates a FAT image of configurable size (default 7 MB), attaches it to a loop device, formats it, mounts it on a temporary directory, and copies the combined DTB into the root of the filesystem.
- Installs an EXIT trap with a robust cleanup path that:
  - Preserves the original exit status.
  - Unmounts the temporary mountpoint only if mounted.
  - Detaches the loop device only if it was successfully created.
  - Removes all temporary files and directories.

This provides a reproducible, automation-friendly way to package a curated DTB set into a single combined DTB and corresponding FAT image suitable for boot flows and CI pipelines.

Signed-off-by: Bjordis Collaku <[email protected]>
Update build-ubuntu-rootfs.sh to align the generated GRUB configuration with the new UEFI-based combined DTB flow.

Changes:
- Replace the previous GRUB setup (three menu entries for EVK, CRD and QLI, each with an explicit devicetree directive) with a single, DTB-agnostic menu entry: "Ubuntu ${CODENAME}".
- Drop the CRD/EVK-specific DTB path variables:
    /lib/firmware/$kernel_ver/device-tree/x1e80100-crd.dtb
    /lib/firmware/$kernel_ver/device-tree/hamoa-iot-evk.dtb 
since GRUB no longer selects or loads DTBs directly.
- Keep the existing kernel command line (root=LABEL=system, cma, clock and power domain flags, efi=noruntime, etc.) and initrd handling unchanged.

Rationale:
With the introduction of a UEFI-loaded combined DTB image (dtb.bin), DTB selection now happens entirely at the firmware layer. GRUB only needs to locate the "system" filesystem label, load the appropriate vmlinuz/initrd pair and pass the standard kernel parameters. Removing per-board DTB handling in GRUB  reduces duplication and prevents drift between what UEFI loads and what the bootloader assumes.

Signed-off-by: Bjordis Collaku <[email protected]>
@lool
Copy link

lool commented Nov 26, 2025

I'd suggest generating the fat as non-root; you can use mtools for that:
https://github.com/qualcomm-linux/qcom-deb-images/blob/main/debos-recipes/qualcomm-linux-debian-flash.yaml#L342

…dency

Refine build-dtb-image.sh to operate as a root-only tool and eliminate its runtime dependency on sudo, improving compatibility with minimal and containerized CI environments.

Changes:
- Add an explicit EUID check at startup and fail fast if the script is not executed as root, clarifying the requirement for losetup/mkfs/mount operations.
- Remove all internal sudo invocations around:
  - losetup --show -fP
  - mkfs.vfat
  - mount / umount
  - loop-device detach
  - DTB copy into the mounted FAT filesystem
- Keep the existing EXIT trap semantics intact, still guaranteeing:
  - sync() best-effort flush,
  - unmount of the temporary mountpoint (if present and mounted),
  - loop device detachment,
  - removal of the temporary sanitized manifest file.

Behavior of the tool is otherwise unchanged:
it still normalizes and validates DTB paths from the manifest, produces <DTB_SRC>/combined-dtb.dtb by concatenation in manifest order, and creates a FAT-formatted dtb.bin image containing only the combined DTB. 

The script is now better aligned with containerized CI usage patterns, where the entrypoint already runs as root and sudo is typically absent.

Signed-off-by: Bjordis Collaku <[email protected]>
@bjordiscollaku
Copy link
Contributor Author

I'd suggest generating the fat as non-root; you can use mtools for that: https://github.com/qualcomm-linux/qcom-deb-images/blob/main/debos-recipes/qualcomm-linux-debian-flash.yaml#L342

This commit 388f7a9 already addresses this. It was mandatory to be able to invoke the tool through a --privileged docker in workflow : )

Update build-dtb-image.sh to format the DTB FAT image with a 4096-byte logical sector size by passing `-S 4096` to mkfs.vfat.

This aligns the dtb.bin filesystem layout with 4K sector expectations on target boot flows while keeping the overall image size and DTB payload unchanged.

Signed-off-by: Bjordis Collaku <[email protected]>
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