From: Jan Kiszka <[email protected]> EDK2 does not support this yet. We can live without it if the user provides DTBs with the required carve-outs hard-coded. Therefore, issue a warning and install the embedded DTB directly.
Signed-off-by: Jan Kiszka <[email protected]> --- kernel-stub/fdt.c | 43 +++++++++++++++++++++++++++++++-------- kernel-stub/kernel-stub.h | 1 + kernel-stub/main.c | 2 +- 3 files changed, 37 insertions(+), 9 deletions(-) diff --git a/kernel-stub/fdt.c b/kernel-stub/fdt.c index b64cd7d..11e8857 100644 --- a/kernel-stub/fdt.c +++ b/kernel-stub/fdt.c @@ -152,9 +152,24 @@ BOOLEAN match_fdt(const VOID *fdt, const CHAR8 *compatible) return strcmpa(compatible, alt_compatible) == 0; } -EFI_STATUS replace_fdt(const VOID *fdt) +static VOID *clone_fdt(const VOID *fdt, UINTN size) { const FDT_HEADER *header = fdt; + VOID *clone; + + clone = AllocatePool(size); + if (!clone) { + error(L"Error allocating device tree buffer", + EFI_OUT_OF_RESOURCES); + return NULL; + } + + CopyMem(clone, fdt, BE32_TO_HOST(header->TotalSize)); + return clone; +} + +EFI_STATUS replace_fdt(const VOID *fdt) +{ EFI_DT_FIXUP_PROTOCOL *protocol; EFI_STATUS status; VOID *fdt_buffer; @@ -162,27 +177,39 @@ EFI_STATUS replace_fdt(const VOID *fdt) status = LibLocateProtocol(&EfiDtFixupProtocol, (VOID **)&protocol); if (EFI_ERROR(status)) { - error(L"Did not find device tree fixup protocol", status); + const FDT_HEADER *header = fdt; + + info(L"Firmware does not provide device tree fixup protocol"); + + fdt_buffer = clone_fdt(fdt, BE32_TO_HOST(header->TotalSize)); + if (!fdt_buffer) { + return EFI_OUT_OF_RESOURCES; + } + + status = BS->InstallConfigurationTable(&EfiDtbTableGuid, + fdt_buffer); + if (EFI_ERROR(status)) { + FreePool(fdt_buffer); + error(L"Failed to install alternative device tree", + status); + } return status; } /* Find out which size we need */ size = 0; - status = protocol->Fixup(protocol, (VOID *)fdt, &size, + status = protocol->Fixup(protocol, (VOID *) fdt, &size, EFI_DT_APPLY_FIXUPS); if (status != EFI_BUFFER_TOO_SMALL) { error(L"Device tree fixup: unexpected error", status); return status; } - fdt_buffer = AllocatePool(size); + fdt_buffer = clone_fdt(fdt, size); if (!fdt_buffer) { - status = EFI_OUT_OF_RESOURCES; - error(L"Error allocating device tree buffer", status); - return status; + return EFI_OUT_OF_RESOURCES; } - CopyMem(fdt_buffer, fdt, BE32_TO_HOST(header->TotalSize)); status = protocol->Fixup(protocol, fdt_buffer, &size, EFI_DT_APPLY_FIXUPS | EFI_DT_RESERVE_MEMORY | EFI_DT_INSTALL_TABLE); diff --git a/kernel-stub/kernel-stub.h b/kernel-stub/kernel-stub.h index c0bd542..6bf9d88 100644 --- a/kernel-stub/kernel-stub.h +++ b/kernel-stub/kernel-stub.h @@ -16,6 +16,7 @@ VOID error(CHAR16 *message, EFI_STATUS status); VOID __attribute__((noreturn)) error_exit(CHAR16 *message, EFI_STATUS status); +VOID info(CHAR16 *message); const VOID *get_fdt_compatible(VOID); BOOLEAN match_fdt(const VOID *fdt, const CHAR8 *compatible); diff --git a/kernel-stub/main.c b/kernel-stub/main.c index 5cf06ac..c0be1f6 100644 --- a/kernel-stub/main.c +++ b/kernel-stub/main.c @@ -63,7 +63,7 @@ EFI_PHYSICAL_ADDRESS align_addr(EFI_PHYSICAL_ADDRESS ptr, return (ptr + align - 1) & ~(align - 1); } -static VOID info(CHAR16 *message) +VOID info(CHAR16 *message) { Print(L"Unified kernel stub: %s\n", message); } -- 2.35.3 -- You received this message because you are subscribed to the Google Groups "EFI Boot Guard" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/efibootguard-dev/361d910c0befd157fb275ac6ad8230a1bfd7582c.1657110125.git.jan.kiszka%40siemens.com.
