]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
kernel-install/60-ukify: also support the convention with 'devicetree' file 29523/head
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Tue, 10 Oct 2023 17:41:35 +0000 (19:41 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Wed, 11 Oct 2023 15:34:43 +0000 (17:34 +0200)
Requested in https://github.com/systemd/systemd/pull/28582#issuecomment-1673300596.
The is the last requested changed, so fixes #28771.

90-loaderentry.install is modified to also check $KERNEL_INSTALL_CONF_ROOT
when looking for the devicetree file. For normal use this is probably not
needed, but it's nice to be consistent and it also makes it much easier to
write the tests.

In tests, also do 'ukify inspect' now that we have it.

src/kernel-install/60-ukify.install.in
src/kernel-install/90-loaderentry.install.in
src/kernel-install/test-kernel-install.sh

index 44a7750da50fa57e6eb4f146dbc23a72a74c2730..21ef694ba1ff3d206b1718013b6157cf53ee30c2 100755 (executable)
@@ -147,6 +147,31 @@ def uki_conf_location() -> Optional[Path]:
                                '/etc/kernel')
 
 
+def devicetree_config_location() -> Optional[Path]:
+    return input_file_location('devicetree')
+
+
+def devicetree_file_location(opts) -> Optional[Path]:
+    # This mirrors the logic in 90-loaderentry.install. Keep in sync.
+    configfile = devicetree_config_location()
+    if configfile is None:
+        return None
+
+    devicetree = configfile.read_text().strip()
+    if not devicetree:
+        raise ValueError(f'{configfile!r} is empty')
+
+    path = input_file_location(
+        devicetree,
+        f'/usr/lib/firmware/{opts.kernel_version}/device-tree',
+        f'/usr/lib/linux-image-{opts.kernel_version}',
+        f'/usr/lib/modules/{opts.kernel_version}/dtb',
+    )
+    if path is None:
+        raise FileNotFoundError(f'DeviceTree file {devicetree} not found')
+    return path
+
+
 def kernel_cmdline_base() -> list[str]:
     path = input_file_location('cmdline')
     if path:
@@ -208,6 +233,9 @@ def call_ukify(opts):
     # Note that 'uki.efi' is the name required by 90-uki-copy.install.
     opts2.output = opts.staging_area / 'uki.efi'
 
+    if devicetree := devicetree_file_location(opts):
+        opts2.devicetree = devicetree
+
     opts2.cmdline = kernel_cmdline(opts)
     if BOOT_STUB:
         opts2.stub = BOOT_STUB
index 02497211b39123b093096d112b395da3f69b4960..a52dd812e434ec9e12fc7ab4e71a87275ce64f9a 100755 (executable)
@@ -126,10 +126,12 @@ elif [ -f /usr/lib/kernel/devicetree ]; then
 fi
 if [ -n "$DEVICETREE" ]; then
     for prefix in \
+        "$KERNEL_INSTALL_CONF_ROOT" \
         "/usr/lib/firmware/$KERNEL_VERSION/device-tree" \
         "/usr/lib/linux-image-$KERNEL_VERSION" \
         "/usr/lib/modules/$KERNEL_VERSION/dtb"
     do
+        [ -n "$prefix" ] || continue
         [ -f "$prefix/$DEVICETREE" ] || continue
         DEVICETREE_SRC="$prefix/$DEVICETREE"
         break
index ad9462c7fb496542984ec23ee45a369c28fb6739..30bee06b533ffb191b054d72e863a97c84e43342 100755 (executable)
@@ -39,6 +39,11 @@ BOOT_ROOT="$D/badboot"
 MACHINE_ID=badbadbadbadbadbad6abadbadbadbad
 EOF
 
+# Create a 'devicetree' config file that points to a fake dtb file
+echo 'subdir/whatever.dtb' >"$D/sources/devicetree"
+mkdir "$D/sources/subdir"
+echo 'DTBDTBDTBDTB' >"$D/sources/subdir/whatever.dtb"
+
 export KERNEL_INSTALL_CONF_ROOT="$D/sources"
 # We "install" multiple plugins, but control which ones will be active via install.conf.
 export KERNEL_INSTALL_PLUGINS="${ukify_install} ${loaderentry_install} ${uki_copy_install}"
@@ -60,9 +65,11 @@ grep -qE '^version +1.1.1' "$entry"
 grep -qE '^options +opt1 opt2' "$entry"
 grep -qE '^linux .*/the-token/1.1.1/linux' "$entry"
 grep -qE '^initrd .*/the-token/1.1.1/initrd' "$entry"
+grep -qE '^devicetree .*/the-token/1.1.1/whatever.dtb' "$entry"
 
 grep -qE 'image' "$BOOT_ROOT/the-token/1.1.1/linux"
 grep -qE 'initrd' "$BOOT_ROOT/the-token/1.1.1/initrd"
+grep -qE 'DTBDTB' "$BOOT_ROOT/the-token/1.1.1/whatever.dtb"
 
 "$kernel_install" inspect
 "$kernel_install" inspect "$D/sources/linux"
@@ -95,9 +102,11 @@ grep -qE '^version +1.1.2' "$entry"
 grep -qE '^options +opt1 opt2' "$entry"
 grep -qE '^linux .*/the-token/1.1.2/linux' "$entry"
 ( ! grep -qE '^initrd' "$entry" )
+grep -qE '^devicetree .*/the-token/1.1.2/whatever.dtb' "$entry"
 
 grep -qE 'image' "$BOOT_ROOT/the-token/1.1.2/linux"
 test ! -e "$BOOT_ROOT/the-token/1.1.2/initrd"
+grep -qE 'DTBDTB' "$BOOT_ROOT/the-token/1.1.2/whatever.dtb"
 
 # Check installation with boot counting
 echo '56' >"$D/sources/tries"
@@ -120,6 +129,7 @@ if [ -f "$ukify" ]; then
 layout=uki
 uki_generator=ukify
 EOF
+
     "$kernel_install" -v add 1.1.3 "$D/sources/linux" "$D/sources/initrd"
     uki="${BOOT_ROOT}/EFI/Linux/the-token-1.1.3+56.efi"
     test -f "$uki"
@@ -129,6 +139,13 @@ EOF
         "$bootctl" kernel-inspect "$uki" | grep -qE 'Version: +1\.1\.3$'
         "$bootctl" kernel-inspect "$uki" | grep -qE 'Cmdline: +opt1 opt2$'
     fi
+
+    "$ukify" inspect "$uki" | grep -qE '^.sbat'
+    "$ukify" inspect "$uki" | grep -qE '^.cmdline'
+    "$ukify" inspect "$uki" | grep -qE '^.uname'
+    "$ukify" inspect "$uki" | grep -qE '^.initrd'
+    "$ukify" inspect "$uki" | grep -qE '^.linux'
+    "$ukify" inspect "$uki" | grep -qE '^.dtb'
 fi
 
 # Test bootctl