Skip to content

Commit eb9d808

Browse files
build-dtb-image: probe Debian standard DTB path first in --kernel-deb mode
When extracting DTBs from a kernel .deb, probe paths in order: 1. usr/lib/linux-image-*/ (Debian standard — direct, no symlink) 2. usr/lib/firmware/*/device-tree (Ubuntu compat, usrmerge layout) 3. lib/firmware/*/device-tree (Ubuntu compat, legacy layout) Probing the Debian standard path first avoids any dependency on the Ubuntu compat symlink and works correctly on pure Debian systems that never install it, as well as on Ubuntu regardless of usrmerge layout. The fallback chain is fully backward compatible: legacy packages (built by build-kernel-deb.sh) only populate lib/firmware/, so the script falls through steps 1 and 2 and resolves via step 3 as before. Signed-off-by: Bjordis Collaku <bcollaku@qti.qualcomm.com>
1 parent 5979c20 commit eb9d808

1 file changed

Lines changed: 26 additions & 16 deletions

File tree

kernel/scripts/build-dtb-image.sh

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,13 @@
1818
# (A) Kernel .deb mode (recommended / upstream-friendly)
1919
# - Provide a Debian kernel package (.deb) as input.
2020
# - The script extracts the .deb via `dpkg-deb -R` into a temp directory.
21-
# - DTBs are expected to be present under:
22-
# $DEB_DIR/usr/lib/firmware/$BASE_KERNEL_VERSION/device-tree (usrmerge layout)
23-
# $DEB_DIR/lib/firmware/$BASE_KERNEL_VERSION/device-tree (legacy layout)
24-
# where $BASE_KERNEL_VERSION can be anything.
25-
# - The script assumes there is exactly ONE device-tree directory across
26-
# both search paths.
21+
# - DTBs are located by probing the following paths in order:
22+
# 1. $DEB_DIR/usr/lib/linux-image-*/ (Debian standard — direct, no symlink)
23+
# 2. $DEB_DIR/usr/lib/firmware/*/device-tree (Ubuntu compat, usrmerge layout)
24+
# 3. $DEB_DIR/lib/firmware/*/device-tree (Ubuntu compat, legacy layout)
25+
# Probing the Debian standard path first ensures correct operation on
26+
# both Debian and Ubuntu regardless of whether the compat symlink exists.
27+
# - The script assumes there is exactly ONE matching directory.
2728
#
2829
# (B) DTB source directory mode (dev/kernel-tree mode)
2930
# - Provide the DTB source directory directly (e.g. a kernel build tree):
@@ -171,10 +172,11 @@ usage() {
171172
cat <<EOF
172173
Usage: $0 (--kernel-deb <kernel.deb> | --dtb-src <path>) --manifest <file> [--size <MB>] [--out <file>]
173174
174-
--kernel-deb, -kernel-deb Path to Debian kernel package (.deb). DTBs read from:
175-
<extract>/usr/lib/firmware/*/device-tree (usrmerge layout)
176-
<extract>/lib/firmware/*/device-tree (legacy layout)
177-
Exactly one device-tree directory must be found.
175+
--kernel-deb, -kernel-deb Path to Debian kernel package (.deb). DTBs located by probing:
176+
1. <extract>/usr/lib/linux-image-*/ (Debian standard)
177+
2. <extract>/usr/lib/firmware/*/device-tree (Ubuntu, usrmerge)
178+
3. <extract>/lib/firmware/*/device-tree (Ubuntu, legacy)
179+
Exactly one directory must be found across all search paths.
178180
179181
--dtb-src, -dtb-src Path to DTB source directory
180182
(e.g. arch/arm64/boot/dts/qcom)
@@ -364,19 +366,27 @@ if [[ -n "${KERNEL_DEB}" ]]; then
364366
echo "[INFO] Extracting kernel .deb to: ${DEB_DIR}"
365367
dpkg-deb -R "${KERNEL_DEB}" "${DEB_DIR}"
366368

367-
# Locate exactly one device-tree directory.
368-
# Modern packages (usrmerge / pkg-linux-qcom) install the compat symlink under
369-
# usr/lib/firmware/<KVER>/device-tree; legacy packages used lib/firmware/.
370-
# Check usr/lib/firmware/ first; fall back to lib/firmware/.
369+
# Locate the DTB directory from the extracted .deb.
370+
# Probe in order (most to least preferred):
371+
# 1. usr/lib/linux-image-*/ — Debian standard install location (direct, no symlink).
372+
# Works on both Debian and Ubuntu regardless of usrmerge.
373+
# 2. usr/lib/firmware/*/device-tree — Ubuntu compat symlink (usrmerge layout).
374+
# 3. lib/firmware/*/device-tree — Ubuntu compat symlink (legacy layout).
375+
# Searching the Debian standard path first avoids any dependency on the Ubuntu
376+
# compat symlink and is correct on pure Debian systems that never install it.
371377
shopt -s nullglob
372-
dt_dirs=( "${DEB_DIR}/usr/lib/firmware"/*/device-tree )
378+
dt_dirs=( "${DEB_DIR}/usr/lib/linux-image-"*/ )
379+
if (( ${#dt_dirs[@]} == 0 )); then
380+
dt_dirs=( "${DEB_DIR}/usr/lib/firmware"/*/device-tree )
381+
fi
373382
if (( ${#dt_dirs[@]} == 0 )); then
374383
dt_dirs=( "${DEB_DIR}/lib/firmware"/*/device-tree )
375384
fi
376385
shopt -u nullglob
377386

378387
if (( ${#dt_dirs[@]} == 0 )); then
379388
echo "[ERROR] No DTB directory found under:" >&2
389+
echo " '${DEB_DIR}/usr/lib/linux-image-*/'" >&2
380390
echo " '${DEB_DIR}/usr/lib/firmware/*/device-tree'" >&2
381391
echo " '${DEB_DIR}/lib/firmware/*/device-tree'" >&2
382392
exit 1
@@ -530,7 +540,7 @@ else
530540
if (( dtb_count == 0 )); then
531541
echo "[ERROR] No DTB files found under ${DTB_SRC}" >&2
532542
echo " Verify the kernel package was built with DTB support" >&2
533-
echo " and that usr/lib/firmware/*/device-tree resolves correctly." >&2
543+
echo " and that usr/lib/linux-image-*/ is present in the package." >&2
534544
exit 1
535545
fi
536546
echo "[INFO] Staged ${dtb_count} DTB file(s) to ${DTB_STAGE}"

0 commit comments

Comments
 (0)