From 29506a30ecf0083321810574e23052439cb33790 Mon Sep 17 00:00:00 2001 From: Cole Mickens Date: Tue, 9 Jul 2024 13:22:54 -0700 Subject: [PATCH 1/2] system/kernel.nix: toplevel: add dtb link --- nixos/modules/system/boot/kernel.nix | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/nixos/modules/system/boot/kernel.nix b/nixos/modules/system/boot/kernel.nix index 4854119b25382..363f237880cc6 100644 --- a/nixos/modules/system/boot/kernel.nix +++ b/nixos/modules/system/boot/kernel.nix @@ -353,6 +353,14 @@ in ln -s ${config.system.build.initialRamdiskSecretAppender}/bin/append-initrd-secrets $out ln -s ${config.hardware.firmware}/lib/firmware $out/firmware + + ${lib.optionalString ( + config.hardware.deviceTree.enable + && config.hardware.deviceTree.package != null + && config.hardware.deviceTree.name != null) + # "ln -s ${config.boot.kernelPackages.package}/dtbs/${config.hardware.deviceTree.name} $out/dtb" + "ln -s ${config.hardware.deviceTree.package}/${config.hardware.deviceTree.name} $out/dtb" + } ''; # Implement consoleLogLevel both in early boot and using sysctl From 4f07523f641203388bb26fd7ea87ba7ffbfe9fb5 Mon Sep 17 00:00:00 2001 From: Cole Mickens Date: Mon, 15 Jul 2024 23:23:11 -0700 Subject: [PATCH 2/2] systemd-boot-builder.py: add devicetree if dtb exists --- .../systemd-boot/systemd-boot-builder.py | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/nixos/modules/system/boot/loader/systemd-boot/systemd-boot-builder.py b/nixos/modules/system/boot/loader/systemd-boot/systemd-boot-builder.py index 87ea569bdb74e..7dd151f613228 100644 --- a/nixos/modules/system/boot/loader/systemd-boot/systemd-boot-builder.py +++ b/nixos/modules/system/boot/loader/systemd-boot/systemd-boot-builder.py @@ -305,6 +305,29 @@ def write_entry(profile: str | None, sort_key=bootspec.sortKey, default=current ).write(sorted_first) + + devicetree = None + dtb_link = f"{system_dir(profile, generation, specialisation)}/dtb" + if os.path.exists(dtb_link): + dtb_path = os.path.realpath(dtb_link) + if os.path.exists(dtb_path): + devicetree = copy_from_file(dtb_path) + + with open(tmp_path, 'w') as f: + f.write(BOOT_ENTRY.format(title=title, + sort_key=bootspec.sortKey, + generation=generation, + kernel=kernel, + initrd=initrd, + kernel_params=kernel_params, + description=f"{bootspec.label}, built on {build_date}")) + if machine_id is not None: + f.write("machine-id %s\n" % machine_id) + if devicetree is not None: + f.write("devicetree %s\n" % devicetree) + f.flush() + os.fsync(f.fileno()) + os.rename(tmp_path, entry_file) def get_generations(profile: str | None = None) -> list[SystemIdentifier]: gen_list = run(