scripts: add build-dtb-image.sh, self-contained FIT DTB image builder co-located with metadata#83
Open
bjordiscollaku wants to merge 2 commits intoqualcomm-linux:mainfrom
Conversation
Introduce build-dtb-image.sh, a production-ready tool for generating
FAT-formatted FIT DTB images for Qualcomm ARM64 platforms.
The script is co-located with the metadata it consumes (qcom-metadata.dts,
qcom-next-fitimage.its), eliminating the need to clone this repository
at build time. The metadata directory is resolved at runtime via
BASH_SOURCE[0], so the script works correctly regardless of the caller's
working directory or CI environment.
FIT image mode is the default and only operating mode. The --fit-image
flag is accepted for backward compatibility with existing callers but is
a no-op.
Two DTB source sub-modes are supported:
--kernel-deb Extract DTBs from a Debian kernel package (.deb).
Probes paths in order:
1. usr/lib/linux-image-*/ (Debian standard)
2. usr/lib/firmware/*/device-tree (Ubuntu, usrmerge)
3. lib/firmware/*/device-tree (Ubuntu, legacy)
This probe order ensures correct operation on both Debian
and Ubuntu regardless of usrmerge layout, and is fully
backward compatible with legacy build-kernel-deb.sh packages.
--dtb-src Read DTBs directly from a kernel build tree directory.
Build pipeline (5 steps):
1. Assemble a temporary staging tree with ITS, compiled metadata DTB,
and all per-platform DTBs laid out as the ITS /incbin/ paths expect.
2. Compile qcom-metadata.dts → qcom-metadata.dtb via dtc.
3. Copy qcom-next-fitimage.its into the staging directory.
4. Invoke mkimage from the staging directory to produce qclinux_fit.img
(-E -B 8). The output filename is hardcoded in UEFI firmware and
must not be changed.
5. Pack qclinux_fit.img into a FAT image (default: dtb.bin, 4 MB).
Hardening:
- Upfront validation that qcom-metadata.dts and the ITS file exist
before any build work begins.
- find -L replaces flat *.dtb* glob, correctly collecting DTBs nested
under vendor subdirectories (e.g. qcom/).
- Staged DTB count check with sorted listing for early diagnosis of
empty or misconfigured DTB sources.
- Cleanup trap covers all temporary resources (loop device, mount
point, .deb extraction dir, staging dir) on any exit path.
Signed-off-by: Bjordis Collaku <bcollaku@qti.qualcomm.com>
|
Please drop |
ad297fb to
34e80dc
Compare
Author
Done, addressed by 64f8ef7. |
Replace losetup/mkfs.vfat/mount with mtools (mformat + mcopy) for FAT image creation. mtools operates directly on image files without needing a loop device or mount point, eliminating the only step that required root privileges. The script now runs entirely as a normal user. 4 KiB sector size is preserved via mformat -S 5 (2^(5+7) = 4096 bytes), matching the previous mkfs.vfat -S 4096. FAT type auto-detection is preserved by omitting -F, so mformat selects the same FAT variant as mkfs.vfat for a given image size. Signed-off-by: Bjordis Collaku <bcollaku@qti.qualcomm.com>
69b61c3 to
64f8ef7
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Introduce
build-dtb-image.sh, a production-ready build tool for generating FAT-formatted FIT DTB images for Qualcomm ARM64 platforms. The script is co-located with the ITS and DTS metadata it consumes, making the repository fully self-contained: cloningqcom-dtb-metadatais sufficient to build a FIT image, no additional tooling repositories, no network access at build time, and no metadata path arguments.Background
Previously, FIT DTB image generation required a separate build tool (
build-dtb-image.shinqcom-build-utils) that clonedqcom-dtb-metadataat runtime, reset to a pinned commit, and referenced the ITS and DTS files from the cloned copy.Design
The script resolves its own location at runtime using
BASH_SOURCE[0]:SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"All metadata files (
qcom-metadata.dts,qcom-next-fitimage.its) are read directly fromSCRIPT_DIR. The version of the metadata used is always exactly the version of the repository that was cloned, no pinning, no drift, no separate clone step.Capabilities
DTB source modes (exactly one required):
--kernel-deb <path>.deb)--dtb-src <path>--kernel-debDTB discovery probes paths in order, most to least preferred:Probing the Debian standard path first ensures correct operation on both Debian and Ubuntu regardless of usrmerge layout, and is fully backward compatible with legacy packages.
--fit-imageis accepted for backward compatibility with existing CI callers but is a no-op, FIT image mode is the default and only mode.Build Pipeline
Hardening
qcom-metadata.dtsand the ITS file exist inSCRIPT_DIRbefore any build work begins, fails fast with a clear diagnostic.find -Lreplaces the previous flat*.dtb*glob, correctly collecting DTBs nested under vendor subdirectories (e.g.qcom/) and following symlinks transparently.Usage
Files Changed
build-dtb-image.sh(new): self-contained FIT DTB image builder