From 528be7230f96059a31a57b1af69d31d2119e1eae Mon Sep 17 00:00:00 2001 From: Andy-Python-Programmer Date: Mon, 12 Sep 2022 16:51:00 +1000 Subject: [PATCH] DTB: ensure the `dtb_ptr` is an HHDM address * Ensure that the `dtb_ptr` is an HHDM address * If DTB is not found, do not generate the response Signed-off-by: Andy-Python-Programmer --- PROTOCOL.md | 2 ++ common/protos/limine.c | 13 +++++++------ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/PROTOCOL.md b/PROTOCOL.md index 4e01d222..5b656cf2 100644 --- a/PROTOCOL.md +++ b/PROTOCOL.md @@ -1079,5 +1079,7 @@ struct limine_dtb_response { * `dtb_ptr` - Virtual pointer to the device tree blob. +Note: If the DTB cannot be found, the response will *not* be generated. + Note: Information contained in the `/chosen` node may not reflect the information given by bootloader tags, and as such the `/chosen` node properties should be ignored. diff --git a/common/protos/limine.c b/common/protos/limine.c index b36fc5a8..09ad76ea 100644 --- a/common/protos/limine.c +++ b/common/protos/limine.c @@ -540,9 +540,6 @@ FEAT_START } #if defined (UEFI) - struct limine_dtb_response *dtb_response = - ext_mem_alloc(sizeof(struct limine_dtb_response)); - // TODO: Looking for the DTB should be moved out of here and into lib/, because: // 1. We will need it for core bring-up for the SMP request. // 2. We will need to patch it for the Linux boot protocol to set the initramfs @@ -555,11 +552,15 @@ FEAT_START for (size_t i = 0; i < gST->NumberOfTableEntries; i++) { EFI_CONFIGURATION_TABLE *cur_table = &gST->ConfigurationTable[i]; - if (memcmp(&cur_table->VendorGuid, &dtb_guid, sizeof(EFI_GUID)) == 0) - dtb_response->dtb_ptr = (uint64_t)(uintptr_t)cur_table->VendorTable; + if (memcmp(&cur_table->VendorGuid, &dtb_guid, sizeof(EFI_GUID)) == 0) { + struct limine_dtb_response *dtb_response = + ext_mem_alloc(sizeof(struct limine_dtb_response)); + dtb_response->dtb_ptr = reported_addr((void *)cur_table->VendorTable); + dtb_request->response = reported_addr(dtb_response); + break; + } } - dtb_request->response = reported_addr(dtb_response); #endif FEAT_END