[Concept,09/17] efi: app: Detect running under QEMU
Commit Message
From: Simon Glass <sjg@chromium.org>
When the app is running under QEMU we may wish to do some things
differently. Add a flag for this and use the SMBIOS tables to detect it.
Co-developed-by: Claude <noreply@anthropic.com>
Signed-off-by: Simon Glass <sjg@chromium.org>
---
include/asm-generic/global_data.h | 6 ++++++
lib/efi_client/efi_app.c | 25 ++++++++++++++++++++++++-
2 files changed, 30 insertions(+), 1 deletion(-)
@@ -764,6 +764,12 @@ enum gd_flags {
* For now, this just avoids console output on startup
*/
GD_FLG_ULIB = 0x10000000,
+ /**
+ * @GD_FLG_EMUL: Running in an emulator (e.g. QEMU)
+ *
+ * Detected from SMBIOS or other platform information
+ */
+ GD_FLG_EMUL = 0x20000000,
};
#if CONFIG_IS_ENABLED(ULIB)
@@ -22,6 +22,7 @@
#include <image.h>
#include <init.h>
#include <malloc.h>
+#include <smbios.h>
#include <sysreset.h>
#include <u-boot/uuid.h>
#include <asm/global_data.h>
@@ -179,6 +180,27 @@ static void scan_tables(struct efi_system_table *sys_table)
}
}
+static bool detect_emulator(void)
+{
+ struct smbios_info info;
+ struct smbios_type1 *t1;
+ const char *manufacturer;
+
+ /* Check if running in QEMU by looking at SMBIOS manufacturer */
+ if (!smbios_locate(gd_smbios_start(), &info)) {
+ t1 = (void *)smbios_get_header(&info,
+ SMBIOS_SYSTEM_INFORMATION);
+ if (t1) {
+ manufacturer = smbios_get_string(&t1->hdr,
+ t1->manufacturer);
+ if (manufacturer && !strcmp(manufacturer, "QEMU"))
+ return true;
+ }
+ }
+
+ return false;
+}
+
static void find_protocols(struct efi_priv *priv)
{
efi_guid_t guid = EFI_DEVICE_PATH_TO_TEXT_PROTOCOL_GUID;
@@ -415,7 +437,8 @@ efi_status_t EFIAPI efi_main(efi_handle_t image,
printf("starting\n");
- board_init_f(GD_FLG_SKIP_RELOC);
+ board_init_f(GD_FLG_SKIP_RELOC |
+ (detect_emulator() ? GD_FLG_EMUL : 0));
gd = gd->new_gd;
board_init_r(NULL, 0);
free_memory(priv);