summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAhmad Fatoum <a.fatoum@pengutronix.de>2024-03-04 19:59:47 +0100
committerSascha Hauer <s.hauer@pengutronix.de>2024-03-05 16:28:06 +0100
commitb2059a82e3959301dd4f791f9d6ee465cf6b2b74 (patch)
treedb58a931a7a28a318d48c29feee6b81078d2eac4
parent626d4126b0e9084ed0902f8653c97d2cbafedb89 (diff)
downloadbarebox-b2059a82e395.tar.gz
barebox-b2059a82e395.tar.xz
efi: payload: suppress EFI payload initcalls when not EFI-loaded
For development, it has proven very useful to be able to load the same barebox binary both as EFI loader and EFI payload and debug the interaction. For this to work, we need to mark all current EFI payload initcalls as such to avoid running them when barebox is not running as EFI payload. Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de> Link: https://lore.barebox.org/20240304190038.3486881-63-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
-rw-r--r--arch/x86/mach-efi/clocksource.c4
-rw-r--r--common/startup.c3
-rw-r--r--drivers/bus/acpi.c2
-rw-r--r--drivers/efi/efi-device.c2
-rw-r--r--efi/payload/fdt.c2
-rw-r--r--efi/payload/image.c2
-rw-r--r--efi/payload/init.c17
-rw-r--r--efi/payload/iomem.c3
-rw-r--r--fs/efivarfs.c2
-rw-r--r--include/acpi.h3
-rw-r--r--include/efi/efi-device.h6
-rw-r--r--include/efi/efi-init.h51
12 files changed, 75 insertions, 22 deletions
diff --git a/arch/x86/mach-efi/clocksource.c b/arch/x86/mach-efi/clocksource.c
index c7e557d7a2..daf3b39658 100644
--- a/arch/x86/mach-efi/clocksource.c
+++ b/arch/x86/mach-efi/clocksource.c
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: GPL-2.0-only
#include <common.h>
-#include <init.h>
+#include <efi/efi-init.h>
#include <driver.h>
static int efi_x86_pure_init(void)
@@ -10,4 +10,4 @@ static int efi_x86_pure_init(void)
return platform_device_register(dev);
}
-core_initcall(efi_x86_pure_init);
+core_efi_initcall(efi_x86_pure_init);
diff --git a/common/startup.c b/common/startup.c
index bbba72f892..522e2de755 100644
--- a/common/startup.c
+++ b/common/startup.c
@@ -38,6 +38,7 @@
#include <watchdog.h>
#include <glob.h>
#include <net.h>
+#include <efi/efi-mode.h>
#include <bselftest.h>
extern initcall_t __barebox_initcalls_start[], __barebox_early_initcalls_end[],
@@ -54,7 +55,7 @@ static int mount_root(void)
mkdir("/tmp", 0);
mount("none", "devfs", "/dev", NULL);
- if (IS_ENABLED(CONFIG_FS_EFIVARFS)) {
+ if (IS_ENABLED(CONFIG_FS_EFIVARFS) && efi_is_payload()) {
mkdir("/efivars", 0);
mount("none", "efivarfs", "/efivars", NULL);
}
diff --git a/drivers/bus/acpi.c b/drivers/bus/acpi.c
index 2d76ceb72f..938e205624 100644
--- a/drivers/bus/acpi.c
+++ b/drivers/bus/acpi.c
@@ -239,4 +239,4 @@ static int efi_acpi_probe(void)
acpi_bus.dev->priv = table;
return acpi_register_devices(&acpi_bus);
}
-postcore_initcall(efi_acpi_probe);
+postcore_efi_initcall(efi_acpi_probe);
diff --git a/drivers/efi/efi-device.c b/drivers/efi/efi-device.c
index f93bbc6a4e..a533bc43eb 100644
--- a/drivers/efi/efi-device.c
+++ b/drivers/efi/efi-device.c
@@ -462,7 +462,7 @@ static int efi_init_devices(void)
return 0;
}
-core_initcall(efi_init_devices);
+core_efi_initcall(efi_init_devices);
void efi_pause_devices(void)
{
diff --git a/efi/payload/fdt.c b/efi/payload/fdt.c
index 8dacaa8b52..b50c096919 100644
--- a/efi/payload/fdt.c
+++ b/efi/payload/fdt.c
@@ -41,4 +41,4 @@ static int efi_fdt_probe(void)
return 0;
}
-late_initcall(efi_fdt_probe);
+late_efi_initcall(efi_fdt_probe);
diff --git a/efi/payload/image.c b/efi/payload/image.c
index 8e5ad87de2..b9cdb0e056 100644
--- a/efi/payload/image.c
+++ b/efi/payload/image.c
@@ -332,4 +332,4 @@ static int efi_register_image_handler(void)
return 0;
}
-late_initcall(efi_register_image_handler);
+late_efi_initcall(efi_register_image_handler);
diff --git a/efi/payload/init.c b/efi/payload/init.c
index dedecbf92c..9bc0741e04 100644
--- a/efi/payload/init.c
+++ b/efi/payload/init.c
@@ -205,7 +205,7 @@ static int misc_init(void)
return 0;
}
-late_initcall(misc_init);
+late_efi_initcall(misc_init);
static struct NS16550_plat ns16550_plat = {
.clock = 115200 * 16,
@@ -223,7 +223,7 @@ static int efi_console_init(void)
return 0;
}
-console_initcall(efi_console_init);
+console_efi_initcall(efi_console_init);
static void __noreturn efi_restart_system(struct restart_handler *rst)
{
@@ -247,7 +247,7 @@ static int restart_register_feature(void)
return 0;
}
-coredevice_initcall(restart_register_feature);
+coredevice_efi_initcall(restart_register_feature);
extern char image_base[];
extern initcall_t __barebox_initcalls_start[], __barebox_early_initcalls_end[],
@@ -265,7 +265,7 @@ static int efi_init(void)
return 0;
}
-device_initcall(efi_init);
+device_efi_initcall(efi_init);
/**
* efi-main - Entry point for EFI images
@@ -325,7 +325,7 @@ static int efi_core_init(void)
dev = device_alloc("efi-wdt", DEVICE_ID_SINGLE);
return platform_device_register(dev);
}
-core_initcall(efi_core_init);
+core_efi_initcall(efi_core_init);
/* Features of the loader, i.e. systemd-boot, barebox (imported from systemd) */
#define EFI_LOADER_FEATURE_CONFIG_TIMEOUT (1LL << 0)
@@ -385,7 +385,7 @@ static int efi_postcore_init(void)
return 0;
}
-postcore_initcall(efi_postcore_init);
+postcore_efi_initcall(efi_postcore_init);
static int efi_late_init(void)
{
@@ -434,10 +434,13 @@ static int efi_late_init(void)
return 0;
}
-late_initcall(efi_late_init);
+late_efi_initcall(efi_late_init);
static int do_efiexit(int argc, char *argv[])
{
+ if (!BS)
+ return -ENOSYS;
+
console_flush();
if (!streq_ptr(argv[1], "-f"))
diff --git a/efi/payload/iomem.c b/efi/payload/iomem.c
index 316dacd6b3..d4390c8567 100644
--- a/efi/payload/iomem.c
+++ b/efi/payload/iomem.c
@@ -7,6 +7,7 @@
#include <init.h>
#include <efi.h>
#include <efi/efi-payload.h>
+#include <efi/efi-init.h>
#include <memory.h>
#include <linux/sizes.h>
@@ -175,4 +176,4 @@ out:
free(mmap_buf);
return ret;
}
-mem_initcall(efi_barebox_populate_mmap);
+mem_efi_initcall(efi_barebox_populate_mmap);
diff --git a/fs/efivarfs.c b/fs/efivarfs.c
index 5d805aefbf..b199318061 100644
--- a/fs/efivarfs.c
+++ b/fs/efivarfs.c
@@ -371,4 +371,4 @@ static int efivarfs_init(void)
return register_fs_driver(&efivarfs_driver);
}
-coredevice_initcall(efivarfs_init);
+coredevice_efi_initcall(efivarfs_init);
diff --git a/include/acpi.h b/include/acpi.h
index 2761fe6050..0756f94501 100644
--- a/include/acpi.h
+++ b/include/acpi.h
@@ -9,6 +9,7 @@
#include <linux/string.h>
#include <linux/types.h>
#include <driver.h>
+#include <efi/efi-init.h>
/* Names within the namespace are 4 bytes long */
@@ -130,7 +131,7 @@ static inline struct acpi_driver *to_acpi_driver(struct driver *drv)
}
#define device_acpi_driver(drv) \
- register_driver_macro(device, acpi, drv)
+ register_efi_driver_macro(device, acpi, drv)
static inline int acpi_driver_register(struct acpi_driver *acpidrv)
{
diff --git a/include/efi/efi-device.h b/include/efi/efi-device.h
index eaf89beb8e..5f7490028b 100644
--- a/include/efi/efi-device.h
+++ b/include/efi/efi-device.h
@@ -5,6 +5,7 @@
#include <efi/types.h>
#include <efi/efi-util.h>
#include <driver.h>
+#include <efi/efi-init.h>
struct efi_device {
struct device dev;
@@ -37,11 +38,6 @@ static inline struct efi_driver *to_efi_driver(struct driver *drv)
return container_of(drv, struct efi_driver, driver);
}
-#define device_efi_driver(drv) \
- register_driver_macro(device, efi, drv)
-
-#define fs_efi_driver(drv) \
- register_driver_macro(fs, efi, drv)
static inline int efi_driver_register(struct efi_driver *efidrv)
{
efidrv->driver.bus = &efi_bus;
diff --git a/include/efi/efi-init.h b/include/efi/efi-init.h
new file mode 100644
index 0000000000..f524f3973e
--- /dev/null
+++ b/include/efi/efi-init.h
@@ -0,0 +1,51 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+
+#ifndef EFI_INIT_H_
+#define EFI_INIT_H_
+
+#include <init.h>
+#include <linux/compiler.h>
+
+struct efi_boot_services;
+extern struct efi_boot_services *BS;
+
+#ifdef CONFIG_EFI_PAYLOAD
+#define efi_payload_initcall(level, fn) level##_initcall(fn)
+#else
+#define efi_payload_initcall(level, fn)
+#endif
+
+/* For use by EFI payload */
+#define __define_efi_initcall(level, fn) \
+ static int __maybe_unused __efi_initcall_##fn(void) \
+ { \
+ return BS ? fn() : 0; \
+ } \
+ efi_payload_initcall(level, __efi_initcall_##fn);
+
+#define core_efi_initcall(fn) __define_efi_initcall(core, fn)
+#define postcore_efi_initcall(fn) __define_efi_initcall(postcore, fn)
+#define console_efi_initcall(fn) __define_efi_initcall(console, fn)
+#define coredevice_efi_initcall(fn) __define_efi_initcall(coredevice, fn)
+#define mem_efi_initcall(fn) __define_efi_initcall(mem, fn)
+#define device_efi_initcall(fn) __define_efi_initcall(device, fn)
+#define fs_efi_initcall(fn) __define_efi_initcall(fs, fn)
+#define late_efi_initcall(fn) __define_efi_initcall(late, fn)
+
+#define register_efi_driver_macro(level,bus,drv) \
+ static int __init drv##_register(void) \
+ { \
+ return bus##_driver_register(&drv); \
+ } \
+ level##_efi_initcall(drv##_register)
+
+#define core_efi_driver(drv) \
+ register_efi_driver_macro(core, efi, drv)
+
+#define device_efi_driver(drv) \
+ register_efi_driver_macro(device, efi, drv)
+
+#define fs_efi_driver(drv) \
+ register_efi_driver_macro(fs, efi, drv)
+
+#endif