From: Jan Kiszka <[email protected]> Will allow reuse by kernel stub.
Signed-off-by: Jan Kiszka <[email protected]> --- Makefile.am | 2 ++ bootguard.c | 2 -- drivers/watchdog/amdfch_wdt.c | 1 + drivers/watchdog/atom-quark.c | 1 + drivers/watchdog/eiois200_wdt.c | 1 + drivers/watchdog/hpwdt.c | 1 + drivers/watchdog/i6300esb.c | 1 + drivers/watchdog/ipc4x7e_wdt.c | 1 + drivers/watchdog/ipcbx21a.c | 1 + drivers/watchdog/ipmi_wdt.c | 1 + drivers/watchdog/itco.c | 1 + drivers/watchdog/w83627hf_wdt.c | 1 + drivers/watchdog/wdat.c | 1 + env/fatvars.c | 1 + env/syspart.c | 1 + include/bootguard.h | 2 -- include/print.h | 43 +++++++++++++++++++++++++++++++++ include/utils.h | 21 ---------------- main.c | 1 + print.c | 42 ++++++++++++++++++++++++++++++++ utils.c | 22 +---------------- 21 files changed, 102 insertions(+), 46 deletions(-) create mode 100644 include/print.h create mode 100644 print.c diff --git a/Makefile.am b/Makefile.am index 6dc1df8..9d49828 100644 --- a/Makefile.am +++ b/Makefile.am @@ -144,6 +144,7 @@ noinst_HEADERS = \ include/syspart.h \ include/test-interface.h \ include/uservars.h \ + include/print.h \ include/utils.h # @@ -236,6 +237,7 @@ efi_sources = \ drivers/watchdog/wdfuncs_end.c \ env/syspart.c \ env/fatvars.c \ + print.c \ utils.c \ loader_interface.c \ bootguard.c \ diff --git a/bootguard.c b/bootguard.c index c9c5328..124f333 100644 --- a/bootguard.c +++ b/bootguard.c @@ -15,8 +15,6 @@ #include "bootguard.h" #include "utils.h" -EFI_HANDLE this_image; - VOLUME_DESC *volumes = NULL; UINTN volume_count = 128; CHAR16 *boot_medium_path; diff --git a/drivers/watchdog/amdfch_wdt.c b/drivers/watchdog/amdfch_wdt.c index 0576892..d7082f1 100644 --- a/drivers/watchdog/amdfch_wdt.c +++ b/drivers/watchdog/amdfch_wdt.c @@ -17,6 +17,7 @@ #include <pci/header.h> #include <sys/io.h> #include <mmio.h> +#include "print.h" #include "utils.h" /* #define AMDFCH_WDT_DEBUG */ diff --git a/drivers/watchdog/atom-quark.c b/drivers/watchdog/atom-quark.c index 813eab9..ef891fa 100644 --- a/drivers/watchdog/atom-quark.c +++ b/drivers/watchdog/atom-quark.c @@ -16,6 +16,7 @@ #include <efilib.h> #include <pci/header.h> #include <sys/io.h> +#include "print.h" #include "utils.h" #define PCI_DEVICE_ID_INTEL_ITC 0x8186 diff --git a/drivers/watchdog/eiois200_wdt.c b/drivers/watchdog/eiois200_wdt.c index 61855d0..6fd61e9 100644 --- a/drivers/watchdog/eiois200_wdt.c +++ b/drivers/watchdog/eiois200_wdt.c @@ -18,6 +18,7 @@ #include <pci/header.h> #include <sys/io.h> #include <mmio.h> +#include "print.h" #include "smbios.h" #include "utils.h" diff --git a/drivers/watchdog/hpwdt.c b/drivers/watchdog/hpwdt.c index 8987558..becea61 100644 --- a/drivers/watchdog/hpwdt.c +++ b/drivers/watchdog/hpwdt.c @@ -14,6 +14,7 @@ #include <efi.h> #include <pci/header.h> +#include "print.h" #include "utils.h" #define PCI_VENDOR_ID_HP 0x103c diff --git a/drivers/watchdog/i6300esb.c b/drivers/watchdog/i6300esb.c index b19063c..626709b 100644 --- a/drivers/watchdog/i6300esb.c +++ b/drivers/watchdog/i6300esb.c @@ -15,6 +15,7 @@ #include <efi.h> #include <efilib.h> #include <pci/header.h> +#include "print.h" #include "utils.h" #define PCI_DEVICE_ID_INTEL_ESB_9 0x25ab diff --git a/drivers/watchdog/ipc4x7e_wdt.c b/drivers/watchdog/ipc4x7e_wdt.c index c09ddc8..b0bb54f 100644 --- a/drivers/watchdog/ipc4x7e_wdt.c +++ b/drivers/watchdog/ipc4x7e_wdt.c @@ -18,6 +18,7 @@ #include <pci/header.h> #include <sys/io.h> #include <mmio.h> +#include "print.h" #include "simatic.h" #include "utils.h" diff --git a/drivers/watchdog/ipcbx21a.c b/drivers/watchdog/ipcbx21a.c index a1b8a9a..c9f50ea 100644 --- a/drivers/watchdog/ipcbx21a.c +++ b/drivers/watchdog/ipcbx21a.c @@ -16,6 +16,7 @@ #include <efilib.h> #include <pci/header.h> #include <sys/io.h> +#include "print.h" #include "simatic.h" #include "utils.h" diff --git a/drivers/watchdog/ipmi_wdt.c b/drivers/watchdog/ipmi_wdt.c index 610c798..faaab01 100644 --- a/drivers/watchdog/ipmi_wdt.c +++ b/drivers/watchdog/ipmi_wdt.c @@ -15,6 +15,7 @@ #include <efi.h> #include <pci/header.h> #include <sys/io.h> +#include "print.h" #include "smbios.h" #include "utils.h" diff --git a/drivers/watchdog/itco.c b/drivers/watchdog/itco.c index ccd3dfe..d967c5b 100644 --- a/drivers/watchdog/itco.c +++ b/drivers/watchdog/itco.c @@ -18,6 +18,7 @@ #include <pci/header.h> #include <sys/io.h> #include <mmio.h> +#include "print.h" #include "utils.h" #define SMI_EN_REG 0x30 diff --git a/drivers/watchdog/w83627hf_wdt.c b/drivers/watchdog/w83627hf_wdt.c index e88182e..94f985b 100644 --- a/drivers/watchdog/w83627hf_wdt.c +++ b/drivers/watchdog/w83627hf_wdt.c @@ -41,6 +41,7 @@ #include <pci/header.h> #include <sys/io.h> #include <mmio.h> +#include "print.h" #include "simatic.h" #include "utils.h" diff --git a/drivers/watchdog/wdat.c b/drivers/watchdog/wdat.c index 15e1e18..975d5b8 100644 --- a/drivers/watchdog/wdat.c +++ b/drivers/watchdog/wdat.c @@ -19,6 +19,7 @@ #include <efilib.h> #include <mmio.h> #include <sys/io.h> +#include "print.h" #include "utils.h" #define EFI_ACPI_TABLE_GUID \ diff --git a/env/fatvars.c b/env/fatvars.c index 07c9e85..242d38b 100644 --- a/env/fatvars.c +++ b/env/fatvars.c @@ -16,6 +16,7 @@ #include <efilib.h> #include <efiapi.h> #include <bootguard.h> +#include "print.h" #include <utils.h> #include <syspart.h> #include <envdata.h> diff --git a/env/syspart.c b/env/syspart.c index 1bcde24..8d89e16 100644 --- a/env/syspart.c +++ b/env/syspart.c @@ -13,6 +13,7 @@ */ #include <syspart.h> +#include "print.h" #include <utils.h> #include <envdata.h> diff --git a/include/bootguard.h b/include/bootguard.h index af0f54a..f36740c 100644 --- a/include/bootguard.h +++ b/include/bootguard.h @@ -31,8 +31,6 @@ typedef int BG_STATUS; #define BG_CONFIG_ERROR BGERR(110) #define BG_NOT_IMPLEMENTED BGERR(200) -extern EFI_HANDLE this_image; - typedef struct _BG_LOADER_PARAMS { CHAR16 *payload_path; CHAR16 *payload_options; diff --git a/include/print.h b/include/print.h new file mode 100644 index 0000000..2478407 --- /dev/null +++ b/include/print.h @@ -0,0 +1,43 @@ +/* + * EFI Boot Guard + * + * Copyright (c) Siemens AG, 2017-2026 + * + * Authors: + * Jan Kiszka <[email protected]> + * Andreas Reichel <[email protected]> + * + * This work is licensed under the terms of the GNU GPL, version 2. See + * the COPYING file in the top-level directory. + * + * SPDX-License-Identifier: GPL-2.0-only + */ + +#pragma once + +#include <efi.h> + +extern EFI_HANDLE this_image; + +VOID __attribute__((noreturn)) error_exit(CHAR16 *message, EFI_STATUS status); + +VOID PrintC(const UINT8 color, const CHAR16 *fmt, ...); + +#define ERROR(fmt, ...) \ + do { \ + PrintC(EFI_LIGHTRED, L"ERROR: "); \ + PrintC(EFI_LIGHTGRAY, fmt, ##__VA_ARGS__); \ + } while (0) + +#define WARNING(fmt, ...) \ + do { \ + PrintC(EFI_YELLOW, L"WARNING: "); \ + PrintC(EFI_LIGHTGRAY, fmt, ##__VA_ARGS__); \ + } while (0) + +#if !defined(SILENT_BOOT) +#define INFO(fmt, ...) \ + PrintC(EFI_LIGHTGRAY, fmt, ##__VA_ARGS__) +#else +#define INFO(fmt, ...) do { } while (0) +#endif diff --git a/include/utils.h b/include/utils.h index 54b9a42..8b99553 100644 --- a/include/utils.h +++ b/include/utils.h @@ -33,7 +33,6 @@ extern UINTN volume_count; typedef enum { DOSFSLABEL, CUSTOMLABEL, NOLABEL } LABELMODE; -VOID __attribute__((noreturn)) error_exit(CHAR16 *message, EFI_STATUS status); CHAR16 *get_volume_label(EFI_FILE_HANDLE fh); EFI_STATUS get_volumes(VOLUME_DESC **volumes, UINTN *count); EFI_STATUS close_volumes(VOLUME_DESC *volumes, UINTN count); @@ -57,24 +56,4 @@ VOID register_watchdog(WATCHDOG_DRIVER *driver); register_watchdog(&this_driver); \ } -VOID PrintC(const UINT8 color, const CHAR16 *fmt, ...); -#define ERROR(fmt, ...) \ - do { \ - PrintC(EFI_LIGHTRED, L"ERROR: "); \ - PrintC(EFI_LIGHTGRAY, fmt, ##__VA_ARGS__); \ - } while (0) - -#define WARNING(fmt, ...) \ - do { \ - PrintC(EFI_YELLOW, L"WARNING: "); \ - PrintC(EFI_LIGHTGRAY, fmt, ##__VA_ARGS__); \ - } while (0) - -#if !defined(SILENT_BOOT) -#define INFO(fmt, ...) \ - PrintC(EFI_LIGHTGRAY, fmt, ##__VA_ARGS__) -#else -#define INFO(fmt, ...) do { } while (0) -#endif - #define BIT(x) (1UL << (x)) diff --git a/main.c b/main.c index 83cbcab..aa9ca9b 100644 --- a/main.c +++ b/main.c @@ -21,6 +21,7 @@ #include <bootguard.h> #include <configuration.h> #include "version.h" +#include "print.h" #include "utils.h" #include "loader_interface.h" diff --git a/print.c b/print.c new file mode 100644 index 0000000..cbc1faf --- /dev/null +++ b/print.c @@ -0,0 +1,42 @@ +/* + * EFI Boot Guard + * + * Copyright (c) Siemens AG, 2017-2026 + * + * Authors: + * Jan Kiszka <[email protected]> + * Andreas Reichel <[email protected]> + * + * This work is licensed under the terms of the GNU GPL, version 2. See + * the COPYING file in the top-level directory. + * + * SPDX-License-Identifier: GPL-2.0-only + */ + +#include <efi.h> +#include <efilib.h> + +#include "print.h" + +EFI_HANDLE this_image; + +VOID PrintC(const UINT8 color, const CHAR16 *fmt, ...) +{ + INT32 attr = ST->ConOut->Mode->Attribute; + (VOID) ST->ConOut->SetAttribute(ST->ConOut, color); + + va_list args; + va_start(args, fmt); + (VOID)VPrint(fmt, args); + va_end(args); + + (VOID) ST->ConOut->SetAttribute(ST->ConOut, attr); +} + +VOID __attribute__((noreturn)) error_exit(CHAR16 *message, EFI_STATUS status) +{ + ERROR(L"%s (%r).\n", message, status); + (VOID) BS->Stall(3 * 1000 * 1000); + (VOID) BS->Exit(this_image, status, 0, NULL); + __builtin_unreachable(); +} diff --git a/utils.c b/utils.c index 30f8513..178f4a8 100644 --- a/utils.c +++ b/utils.c @@ -16,21 +16,9 @@ #include <efi.h> #include <efilib.h> #include <bootguard.h> +#include "print.h" #include <utils.h> -VOID PrintC(const UINT8 color, const CHAR16 *fmt, ...) -{ - INT32 attr = ST->ConOut->Mode->Attribute; - (VOID) ST->ConOut->SetAttribute(ST->ConOut, color); - - va_list args; - va_start(args, fmt); - (VOID)VPrint(fmt, args); - va_end(args); - - (VOID) ST->ConOut->SetAttribute(ST->ConOut, attr); -} - static BOOLEAN IsOnBootMedium(EFI_DEVICE_PATH *dp) { extern CHAR16 *boot_medium_path; @@ -49,14 +37,6 @@ static BOOLEAN IsOnBootMedium(EFI_DEVICE_PATH *dp) return result; } -VOID __attribute__((noreturn)) error_exit(CHAR16 *message, EFI_STATUS status) -{ - ERROR(L"%s (%r).\n", message, status); - (VOID) BS->Stall(3 * 1000 * 1000); - (VOID) BS->Exit(this_image, status, 0, NULL); - __builtin_unreachable(); -} - CHAR16 *get_volume_label(EFI_FILE_HANDLE fh) { EFI_FILE_SYSTEM_INFO *fsi; -- 2.47.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 visit https://groups.google.com/d/msgid/efibootguard-dev/9a9907788a218e959fdb3f0c8ace7cec195ee541.1775543350.git.jan.kiszka%40siemens.com.
