:: commit 55c751df6785152dcd77cef841b053cb776b1b8a

Mintsuki <mintsuki@protonmail.com> — 2026-04-30 23:44

parents: e99fdaa76e

protos: Measure device tree blob after modules

diff --git a/common/protos/limine.c b/common/protos/limine.c
index aa89a3b6..16807a7c 100644
--- a/common/protos/limine.c
+++ b/common/protos/limine.c
@@ -1149,42 +1149,6 @@ FEAT_START
 FEAT_END
 #endif
 
-    // Device tree blob feature
-FEAT_START
-    struct limine_dtb_request *dtb_request = get_request(LIMINE_DTB_REQUEST_ID);
-    if (dtb_request == NULL) {
-        break; // next feature
-    }
-
-    void *dtb = get_device_tree_blob(config, 0, true);
-
-    if (dtb) {
-        // Delete all /memory@... nodes.
-        // The executable must use the given UEFI memory map instead.
-        while (true) {
-            int offset = fdt_subnode_offset_namelen(dtb, 0, "memory@", 7);
-
-            if (offset == -FDT_ERR_NOTFOUND) {
-                break;
-            }
-
-            if (offset < 0) {
-                panic(true, "limine: failed to find node: '%s'", fdt_strerror(offset));
-            }
-
-            int ret = fdt_del_node(dtb, offset);
-            if (ret < 0) {
-                panic(true, "limine: failed to delete memory node: '%s'", fdt_strerror(ret));
-            }
-        }
-
-        struct limine_dtb_response *dtb_response =
-            ext_mem_alloc(sizeof(struct limine_dtb_response));
-        dtb_response->dtb_ptr = reported_addr(dtb);
-        dtb_request->response = reported_addr(dtb_response);
-    }
-FEAT_END
-
     // Stack size
     uint64_t stack_size = 65536;
 FEAT_START
@@ -1364,6 +1328,42 @@ FEAT_START
     module_request->response = reported_addr(module_response);
 FEAT_END
 
+    // Device tree blob feature
+FEAT_START
+    struct limine_dtb_request *dtb_request = get_request(LIMINE_DTB_REQUEST_ID);
+    if (dtb_request == NULL) {
+        break; // next feature
+    }
+
+    void *dtb = get_device_tree_blob(config, 0, true);
+
+    if (dtb) {
+        // Delete all /memory@... nodes.
+        // The executable must use the given UEFI memory map instead.
+        while (true) {
+            int offset = fdt_subnode_offset_namelen(dtb, 0, "memory@", 7);
+
+            if (offset == -FDT_ERR_NOTFOUND) {
+                break;
+            }
+
+            if (offset < 0) {
+                panic(true, "limine: failed to find node: '%s'", fdt_strerror(offset));
+            }
+
+            int ret = fdt_del_node(dtb, offset);
+            if (ret < 0) {
+                panic(true, "limine: failed to delete memory node: '%s'", fdt_strerror(ret));
+            }
+        }
+
+        struct limine_dtb_response *dtb_response =
+            ext_mem_alloc(sizeof(struct limine_dtb_response));
+        dtb_response->dtb_ptr = reported_addr(dtb);
+        dtb_request->response = reported_addr(dtb_response);
+    }
+FEAT_END
+
     size_t req_width = 0, req_height = 0, req_bpp = 0;
 
     char *resolution = config_get_value(config, 0, "RESOLUTION");
diff --git a/common/protos/linux_risc.c b/common/protos/linux_risc.c
index d49e27e3..892fab45 100644
--- a/common/protos/linux_risc.c
+++ b/common/protos/linux_risc.c
@@ -471,7 +471,6 @@ noreturn void linux_load(char *config, char *cmdline) {
     struct boot_param p;
     memset(&p, 0, sizeof(p));
     p.cmdline = cmdline;
-    p.dtb = get_device_tree_blob(config, 0x1000, true);
 
     if (cmdline != NULL) {
         tpm_measure(TPM_PCR_BOOT_AUTH, TPM_EV_IPL,
@@ -533,6 +532,8 @@ noreturn void linux_load(char *config, char *cmdline) {
 
     load_module(&p, config);
 
+    p.dtb = get_device_tree_blob(config, 0x1000, true);
+
     prepare_device_tree_blob(&p);
 
     prepare_efi_tables(&p, config);
tab: 248 wrap: offon