[PATCH v1 13/54] efi: loader: add table utility functions

Ahmad Fatoum a.fatoum at pengutronix.de
Thu Dec 18 02:37:33 PST 2025


Add some common helpers for use in the upcoming EFI boot and runtime
services implementation.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 efi/Kconfig          |  1 +
 efi/loader/Makefile  |  1 +
 efi/loader/table.c   | 31 +++++++++++++++++++++++++++++++
 include/efi/loader.h |  8 ++++++++
 4 files changed, 41 insertions(+)
 create mode 100644 efi/loader/table.c

diff --git a/efi/Kconfig b/efi/Kconfig
index 766d6b0e3094..590dd7918440 100644
--- a/efi/Kconfig
+++ b/efi/Kconfig
@@ -32,6 +32,7 @@ config EFI_LOADER
 	select EFI_GUID
 	select EFI_DEVICEPATH
 	select MEMORY_ATTRIBUTES
+	select CRC32
 	help
 	  Select this option if you want to run UEFI applications (like GNU
 	  GRUB or an EFI-stubbed kernel) on top of barebox.
diff --git a/efi/loader/Makefile b/efi/loader/Makefile
index 1f07cf6005b9..b4294d746b8b 100644
--- a/efi/loader/Makefile
+++ b/efi/loader/Makefile
@@ -2,3 +2,4 @@
 
 obj-y += memory.o pool_alloc.o
 obj-y += trace.o
+obj-y += table.o
diff --git a/efi/loader/table.c b/efi/loader/table.c
new file mode 100644
index 000000000000..0c200365b835
--- /dev/null
+++ b/efi/loader/table.c
@@ -0,0 +1,31 @@
+// SPDX-License-Identifier: GPL-2.0
+
+#include <efi/services.h>
+#include <efi/loader.h>
+#include <efi/error.h>
+#include <efi/attributes.h>
+#include <crc.h>
+
+/**
+ * efi_update_table_header_crc32() - Update crc32 in table header
+ *
+ * @table:	EFI table
+ */
+void __efi_runtime efi_update_table_header_crc32(struct efi_table_hdr *table)
+{
+	table->crc32 = __pi_crc32(0, table, table->headersize);
+}
+
+/**
+ * efi_unimplemented() - replacement function, returns EFI_UNSUPPORTED
+ *
+ * This function is used after SetVirtualAddressMap() is called as replacement
+ * for services that are not available anymore due to constraints of our
+ * implementation.
+ *
+ * Return:	EFI_UNSUPPORTED
+ */
+efi_status_t __efi_runtime EFIAPI efi_unimplemented(void)
+{
+	return EFI_UNSUPPORTED;
+}
diff --git a/include/efi/loader.h b/include/efi/loader.h
index 4a5670bcf672..fcca8676479d 100644
--- a/include/efi/loader.h
+++ b/include/efi/loader.h
@@ -8,6 +8,8 @@
 #include <efi/services.h>
 #include <efi/memory.h>
 
+struct efi_table_hdr;
+
 #define EFI_SPECIFICATION_VERSION (2 << 16 | 80)
 
 /* Key identifying current memory map */
@@ -40,4 +42,10 @@ efi_status_t efi_get_memory_map(efi_uintn_t *memory_map_size,
 				efi_uintn_t *descriptor_size,
 				uint32_t *descriptor_version);
 
+/* Update CRC32 in table header */
+void efi_update_table_header_crc32(struct efi_table_hdr *table);
+
+/* replacement function, returns EFI_UNSUPPORTED */
+efi_status_t __efi_runtime EFIAPI efi_unimplemented(void);
+
 #endif /* _EFI_LOADER_H */
-- 
2.47.3




More information about the barebox mailing list