Bug#1087817: systemd-boot-efi: please increase minimum sections in stub PE header on riscv64

Aurelien Jarno aurel32 at debian.org
Tue Nov 19 05:32:18 GMT 2024


Package: systemd-boot-efi
Version: 257~rc2-3
Severity: wishlist
Tags: patch
X-Debbugs-Cc: debian-riscv at lists.debian.org
User: debian-riscv at lists.debian.org
Usertags: riscv64

Dear maintainers,

systemd 257 comes with a great new feature, the possibility to include
multiple DTBs in a single UKI file, with systemd-stub automatically
loading the correct one for the current hardware. This finally solves
the DTB problem in the EFI world for distribution, as a single image can
work on multiple boards.

That said trying to embedded all the kernel DTBs on riscv64 fails with
the following error:

  Traceback (most recent call last):
    File "/usr/bin/ukify", line 2246, in <module>
      main()
    File "/usr/bin/ukify", line 2235, in main
      make_uki(opts)
    File "/usr/bin/ukify", line 1307, in make_uki
      pe_add_sections(uki, unsigned_output)
    File "/usr/bin/ukify", line 902, in pe_add_sections
      raise PEError(f'Not enough header space to add section {section.name}.')
  PEError: Not enough header space to add section .dtbauto.

Indeed by default only 30 sections are free in the stub PE header, while
riscv64 currently has 35 DTBs. Note that armhf and arm64 currently have
almost 1000 DTBs. 

Fortunately there is a meson configure option to change the minimum
number of sections to keep free in stub PE header. The commit message
advise everyone to overshoot, except maybe on the tiniest of embedded
boards [1]. Following that advice, I made some tests and indeed the size
increase is relatively small (compared to the dozens of MB of the
resulting UKI file when including both kernel and initrd):

 # sections     size (bytes)     increase (bytes)
   30 (def)      72192
  100            75264            3072
  200            79360            7168
  500            91136           18944
 1000           111104           38912
 2000           151040           78848

Therefore I would like to propose to increase the minimum number of
sections to keep free in stub PE header using the
efi-stub-extra-sections meson option, at least on riscv64. We can go
with 500 for a start that should give a lot of margin. I have tested the
following patch, but feel free to use a better way:

--- systemd-257~rc2/debian/rules
+++ systemd-257~rc2/debian/rules
@@ -218,6 +218,13 @@
 CONFFLAGS += -Ddns-servers=''
 endif
 
+# Increase the minimum number of sections to keep free in stub PE header in
+# order to be able to create an UKI file with many DTBs (each of them is stored
+# in a different .dtbauto section)
+ifneq (,$(filter $(DEB_TARGET_ARCH), riscv64))
+CONFFLAGS += -Defi-stub-extra-sections=500
+endif
+
 override_dh_auto_configure:
 	dh_auto_configure \
 		-- $(CONFFLAGS) $(CONFFLAGS_DISTRO) $(CONFFLAGS_UPSTREAM)

It something that might want to be done for other architectures using
UEFI and DTBs like arm64 or armhf, but let's start with riscv64.

Regards
Aurelien

PS, some additional context: While the Debian riscv64 port is not yet
ready to use systemd-boot by default, the plan is to use systemd-ukify
to build a netboot version of debian-installer as a single netboot.efi
file, in addition to the standard ISO installer. That makes things
simpler for users than using a separate kernel, initrd and dtb, and also
ensures that the system is booted in UEFI mode.

[1] https://github.com/systemd/systemd/commit/41a9a502a1607f5b68f4f87f08807884e824fc1a



More information about the Pkg-systemd-maintainers mailing list