[PATCH 2/3] kernel-stub: Drop incorrect new-line in error output

8 views
Skip to first unread message

Jan Kiszka

unread,
Jun 27, 2022, 5:02:16 AM6/27/22
to efibootg...@googlegroups.com, Christian Storm
From: Jan Kiszka <jan.k...@siemens.com>

error_exit takes care of that.

Signed-off-by: Jan Kiszka <jan.k...@siemens.com>
---
kernel-stub/fdt.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel-stub/fdt.c b/kernel-stub/fdt.c
index 513aa76..ab5c1e6 100644
--- a/kernel-stub/fdt.c
+++ b/kernel-stub/fdt.c
@@ -140,7 +140,7 @@ BOOLEAN match_fdt(const VOID *fdt, const CHAR8 *compatible)
const CHAR8 *alt_compatible;

if (!compatible) {
- error_exit(L"Found .dtb section but no firmware DTB\n",
+ error_exit(L"Found .dtb section but no firmware DTB",
EFI_NOT_FOUND);
}

--
2.35.3

Jan Kiszka

unread,
Jun 27, 2022, 5:02:16 AM6/27/22
to efibootg...@googlegroups.com, Christian Storm
From: Jan Kiszka <jan.k...@siemens.com>

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 <jan.k...@siemens.com>
---
kernel-stub/fdt.c | 12 ++++++++++--
kernel-stub/kernel-stub.h | 1 +
kernel-stub/main.c | 2 +-
3 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/kernel-stub/fdt.c b/kernel-stub/fdt.c
index ab5c1e6..8858773 100644
--- a/kernel-stub/fdt.c
+++ b/kernel-stub/fdt.c
@@ -162,12 +162,20 @@ VOID replace_fdt(const VOID *fdt)

status = LibLocateProtocol(&EfiDtFixupProtocol, (VOID **)&protocol);
if (EFI_ERROR(status)) {
- error_exit(L"Did not find device tree fixup protocol", status);
+ info(L"Firmware does not provide device tree fixup protocol");
+
+ status = BS->InstallConfigurationTable(&EfiDtbTableGuid,
+ (VOID *) fdt);
+ if (EFI_ERROR(status)) {
+ error_exit(L"Failed to install alternative device tree",
+ status);
+ }
+ return;
}

/* 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_exit(L"Device tree fixup: unexpected error", status);
diff --git a/kernel-stub/kernel-stub.h b/kernel-stub/kernel-stub.h
index 4944355..2b31464 100644
--- a/kernel-stub/kernel-stub.h
+++ b/kernel-stub/kernel-stub.h
@@ -15,6 +15,7 @@
#include <efi.h>

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 c9517a5..9dc14ed 100644
--- a/kernel-stub/main.c
+++ b/kernel-stub/main.c
@@ -71,7 +71,7 @@ VOID __attribute__((noreturn)) error_exit(CHAR16 *message, EFI_STATUS status)
__builtin_unreachable();
}

-static VOID info(CHAR16 *message)
+VOID info(CHAR16 *message)
{
Print(L"Unified kernel stub: %s\n", message);
}
--
2.35.3

Jan Kiszka

unread,
Jun 27, 2022, 5:02:16 AM6/27/22
to efibootg...@googlegroups.com, Christian Storm
On the one side, EDK2 is stricter than U-Boot and pointed out that our
trick to use the kernel section directly cannot work reliably, see patch
1.

On the other side, it lacks support the for device tree fixup protocol.
But if the DTB contains what the fixup would apply (and if that is
static), we can live without it, see patch 3.

Patch 2 is just an output cleanup.

Jan

Jan Kiszka (3):
kernel-stub: Copy the kernel out of its section into a buffer
kernel-stub: Drop incorrect new-line in error output
kernel-stub: Allow booting without device tree fixup protocol

kernel-stub/fdt.c | 14 +++++++--
kernel-stub/kernel-stub.h | 1 +
kernel-stub/main.c | 57 +++++++++++++++++++++++++++++++------
tools/bg_gen_unified_kernel | 4 +--
4 files changed, 62 insertions(+), 14 deletions(-)

--
2.35.3

Christian Storm

unread,
Jul 1, 2022, 10:31:05 AM7/1/22
to efibootg...@googlegroups.com
Hi,
replace_fdt() is called from efi_main(). In this execution path,
BS->FreePages(kernel_buffer, kernel_pages);
uninstall_initrd_loader();
is not called, leaking it.

This is also true for some other calls to error_exit().
Kind regards,
Christian

--
Dr. Christian Storm
Siemens AG, Technology, T CED SES-DE
Otto-Hahn-Ring 6, 81739 München, Germany
Reply all
Reply to author
Forward
0 new messages