From: Jan Kiszka <[email protected]> This allows to pull in smbios_find_struct only into builds which need them (x86). And it also avoids filling the main folder with driver-only code.
Signed-off-by: Jan Kiszka <[email protected]> --- Makefile.am | 6 +++++- drivers/utils/smbios.c | 41 +++++++++++++++++++++++++++++++++++++ drivers/watchdog/ipmi_wdt.c | 1 + include/smbios.h | 21 +++++++++++++++++++ include/utils.h | 3 --- simatic.c | 1 + utils.c | 25 ---------------------- 7 files changed, 69 insertions(+), 29 deletions(-) create mode 100644 drivers/utils/smbios.c create mode 100644 include/smbios.h diff --git a/Makefile.am b/Makefile.am index b7b3936..28848e6 100644 --- a/Makefile.am +++ b/Makefile.am @@ -174,7 +174,8 @@ efi_sources_watchdogs = \ drivers/watchdog/w83627hf_wdt.c \ drivers/watchdog/ipmi_wdt.c \ drivers/watchdog/itco.c \ - drivers/watchdog/hpwdt.c + drivers/watchdog/hpwdt.c \ + drivers/utils/smbios.c else efi_sources_watchdogs = endif @@ -284,6 +285,9 @@ $(top_builddir)/drivers/watchdog/%.o: $(top_srcdir)/drivers/watchdog/%.c $(top_builddir)/drivers/watchdog/%.o: $(top_srcdir)/drivers/watchdog/%.S $(call gnuefi_compile) +$(top_builddir)/drivers/utils/%.o: $(top_srcdir)/drivers/utils/%.c + $(call gnuefi_compile) + $(top_builddir)/kernel-stub/%.o: $(top_srcdir)/kernel-stub/%.c $(call gnuefi_compile) diff --git a/drivers/utils/smbios.c b/drivers/utils/smbios.c new file mode 100644 index 0000000..a765288 --- /dev/null +++ b/drivers/utils/smbios.c @@ -0,0 +1,41 @@ +/* + * EFI Boot Guard + * + * Copyright (c) Siemens AG, 2020-2023 + * + * Authors: + * Dr. Johann Pfefferl <[email protected]> + * Jan Kiszka <[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 + */ + +#include <smbios.h> + +SMBIOS_STRUCTURE_POINTER smbios_find_struct(SMBIOS_STRUCTURE_TABLE *table, + UINT16 type) +{ + SMBIOS_STRUCTURE_POINTER strct; + UINT8 *str; + UINTN n; + + strct.Raw = (UINT8 *)(uintptr_t)table->TableAddress; + + for (n = 0; n < table->NumberOfSmbiosStructures; n++) { + if (strct.Hdr->Type == type) { + return strct; + } + /* Read over any appended strings. */ + str = strct.Raw + strct.Hdr->Length; + while (str[0] != 0 || str[1] != 0) { + str++; + } + strct.Raw = str + 2; + } + + strct.Raw = NULL; + return strct; +} diff --git a/drivers/watchdog/ipmi_wdt.c b/drivers/watchdog/ipmi_wdt.c index 55d9623..19e7813 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 "smbios.h" #include "utils.h" #define SMBIOS_TYPE_IPMI_KCS 38 diff --git a/include/smbios.h b/include/smbios.h new file mode 100644 index 0000000..edc7c39 --- /dev/null +++ b/include/smbios.h @@ -0,0 +1,21 @@ +/* + * EFI Boot Guard + * + * Copyright (c) Siemens AG, 2020-2023 + * + * Authors: + * Jan Kiszka <[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 + */ + +#pragma once + +#include <efi.h> +#include <efilib.h> + +SMBIOS_STRUCTURE_POINTER smbios_find_struct(SMBIOS_STRUCTURE_TABLE *table, + UINT16 type); diff --git a/include/utils.h b/include/utils.h index 15d60fb..084796e 100644 --- a/include/utils.h +++ b/include/utils.h @@ -56,6 +56,3 @@ VOID PrintC(const UINT8 color, const CHAR16 *fmt, ...); #define INFO(fmt, ...) \ PrintC(EFI_LIGHTGRAY, fmt, ##__VA_ARGS__) - -SMBIOS_STRUCTURE_POINTER smbios_find_struct(SMBIOS_STRUCTURE_TABLE *table, - UINT16 type); diff --git a/simatic.c b/simatic.c index 7309cdf..a1c63cb 100644 --- a/simatic.c +++ b/simatic.c @@ -17,6 +17,7 @@ #include <efi.h> #include <efilib.h> #include "simatic.h" +#include "smbios.h" #include "utils.h" static UINT32 get_station_id(SMBIOS_STRUCTURE_POINTER oem_strct) diff --git a/utils.c b/utils.c index e065b6f..0ae5a5e 100644 --- a/utils.c +++ b/utils.c @@ -295,28 +295,3 @@ CHAR16 *GetBootMediumPath(CHAR16 *input) return dst; } - -SMBIOS_STRUCTURE_POINTER smbios_find_struct(SMBIOS_STRUCTURE_TABLE *table, - UINT16 type) -{ - SMBIOS_STRUCTURE_POINTER strct; - UINT8 *str; - UINTN n; - - strct.Raw = (UINT8 *)(uintptr_t)table->TableAddress; - - for (n = 0; n < table->NumberOfSmbiosStructures; n++) { - if (strct.Hdr->Type == type) { - return strct; - } - /* Read over any appended strings. */ - str = strct.Raw + strct.Hdr->Length; - while (str[0] != 0 || str[1] != 0) { - str++; - } - strct.Raw = str + 2; - } - - strct.Raw = NULL; - return strct; -} -- 2.35.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 on the web visit https://groups.google.com/d/msgid/efibootguard-dev/d7a51655d9ff3f915a2184966c09bc522a601967.1697736989.git.jan.kiszka%40siemens.com.
