A unique product identifier for SIMATIC IPCs may be found in the DMI data and is known as the station ID. This was up to now used to identify IPC4x7e variants but will also be necessary to support e.g. BX-59A. Move relevant code from ipc4x7e_wdt.c to simatic.c and export simatic_station_id()
Signed-off-by: Cedric Hombourger <cedric.hombour...@siemens.com> --- Makefile.am | 1 + drivers/watchdog/ipc4x7e_wdt.c | 54 ++--------------------------- include/simatic.h | 36 +++++++++++++++++++ simatic.c | 63 ++++++++++++++++++++++++++++++++++ 4 files changed, 102 insertions(+), 52 deletions(-) create mode 100644 include/simatic.h create mode 100644 simatic.c diff --git a/Makefile.am b/Makefile.am index 64d94ef..6d4c160 100644 --- a/Makefile.am +++ b/Makefile.am @@ -186,6 +186,7 @@ efi_sources = \ env/fatvars.c \ utils.c \ loader_interface.c \ + simatic.c \ bootguard.c \ main.c diff --git a/drivers/watchdog/ipc4x7e_wdt.c b/drivers/watchdog/ipc4x7e_wdt.c index f7e5e6a..046e3fe 100644 --- a/drivers/watchdog/ipc4x7e_wdt.c +++ b/drivers/watchdog/ipc4x7e_wdt.c @@ -18,24 +18,11 @@ #include <pci/header.h> #include <sys/io.h> #include <mmio.h> +#include "simatic.h" #include "utils.h" #define PCI_DEVICE_ID_INTEL_SUNRISEPOINT_H_LPC 0xa150 -#define SMBIOS_TYPE_OEM_129 129 - -#define SIMATIC_OEM_ENTRY_TYPE_BINARY 0xff - -#define SIMATIC_IPC427E 0xa01 -#define SIMATIC_IPC477E 0xa02 - -typedef struct { - UINT8 type; - UINT8 length; - UINT8 reserved[3]; - UINT32 station_id; -} __attribute__((packed)) SIMATIC_OEM_ENTRY; - #define SIMATIC_WD_ENABLE_REG 0x62 #define SIMATIC_WD_ENABLE (1 << 0) #define SIMATIC_WD_MACRO_MOD (1 << 1) @@ -57,29 +44,6 @@ typedef struct { #define PAD_CFG_DW0_GPP_A_23 0x4b8 #define PAD_CFG_GPIOTXSTATE (1 << 0) -static UINT32 get_station_id(SMBIOS_STRUCTURE_POINTER oem_strct) -{ - SIMATIC_OEM_ENTRY *entry; - UINTN n; - - entry = (SIMATIC_OEM_ENTRY *)(oem_strct.Raw + sizeof(*oem_strct.Hdr)); - - /* Find 4th entry in OEM data. */ - for (n = 0; n < 3; n++) { - if (entry->type != SIMATIC_OEM_ENTRY_TYPE_BINARY) { - return 0; - } - entry = (SIMATIC_OEM_ENTRY *)((UINT8 *)entry + entry->length); - } - - if (entry->type == SIMATIC_OEM_ENTRY_TYPE_BINARY && - entry->length == sizeof(SIMATIC_OEM_ENTRY)) { - return entry->station_id; - } - - return 0; -} - static UINTN mmcfg_address(UINTN bus, UINTN device, UINTN function, UINTN offset) { @@ -114,9 +78,6 @@ static EFI_STATUS __attribute__((constructor)) init(EFI_PCI_IO *pci_io, UINT16 pci_vendor_id, UINT16 pci_device_id, UINTN timeout) { - SMBIOS_STRUCTURE_TABLE *smbios_table; - SMBIOS_STRUCTURE_POINTER smbios_struct; - EFI_STATUS status; UINTN pad_cfg; UINT8 val; @@ -125,18 +86,7 @@ init(EFI_PCI_IO *pci_io, UINT16 pci_vendor_id, UINT16 pci_device_id, return EFI_UNSUPPORTED; } - status = LibGetSystemConfigurationTable(&SMBIOSTableGuid, - (VOID **)&smbios_table); - if (status != EFI_SUCCESS) { - return EFI_UNSUPPORTED; - } - - smbios_struct = smbios_find_struct(smbios_table, SMBIOS_TYPE_OEM_129); - if (smbios_struct.Raw == NULL) { - return EFI_UNSUPPORTED; - } - - switch (get_station_id(smbios_struct)) { + switch (simatic_station_id()) { case SIMATIC_IPC427E: case SIMATIC_IPC477E: INFO(L"Detected SIMATIC IPC4x7E watchdog\n"); diff --git a/include/simatic.h b/include/simatic.h new file mode 100644 index 0000000..33429c5 --- /dev/null +++ b/include/simatic.h @@ -0,0 +1,36 @@ +/* + * EFI Boot Guard + * + * Copyright (c) Siemens AG, 2023 + * + * Authors: + * Dr. Johann Pfefferl <johann.pfeff...@siemens.com> + * Jan Kiszka <jan.kis...@siemens.com> + * Cedric Hombourger <cedric.hombour...@siemens.com> + * + * 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> + +#define SMBIOS_TYPE_OEM_129 129 + +#define SIMATIC_OEM_ENTRY_TYPE_BINARY 0xff + +#define SIMATIC_IPC427E 0xa01 +#define SIMATIC_IPC477E 0xa02 + +typedef struct { + UINT8 type; + UINT8 length; + UINT8 reserved[3]; + UINT32 station_id; +} __attribute__((packed)) SIMATIC_OEM_ENTRY; + +UINT32 simatic_station_id(void); diff --git a/simatic.c b/simatic.c new file mode 100644 index 0000000..7309cdf --- /dev/null +++ b/simatic.c @@ -0,0 +1,63 @@ +/* + * EFI Boot Guard + * + * Copyright (c) Siemens AG, 2020 + * + * Authors: + * Dr. Johann Pfefferl <johann.pfeff...@siemens.com> + * Jan Kiszka <jan.kis...@siemens.com> + * Cedric Hombourger <cedric.hombour...@siemens.com> + * + * 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 <efi.h> +#include <efilib.h> +#include "simatic.h" +#include "utils.h" + +static UINT32 get_station_id(SMBIOS_STRUCTURE_POINTER oem_strct) +{ + SIMATIC_OEM_ENTRY *entry; + UINTN n; + + entry = (SIMATIC_OEM_ENTRY *)(oem_strct.Raw + sizeof(*oem_strct.Hdr)); + + /* Find 4th entry in OEM data. */ + for (n = 0; n < 3; n++) { + if (entry->type != SIMATIC_OEM_ENTRY_TYPE_BINARY) { + return 0; + } + entry = (SIMATIC_OEM_ENTRY *)((UINT8 *)entry + entry->length); + } + + if (entry->type == SIMATIC_OEM_ENTRY_TYPE_BINARY && + entry->length == sizeof(SIMATIC_OEM_ENTRY)) { + return entry->station_id; + } + + return 0; +} + +UINT32 simatic_station_id(VOID) +{ + SMBIOS_STRUCTURE_TABLE *smbios_table; + SMBIOS_STRUCTURE_POINTER smbios_struct; + EFI_STATUS status; + + status = LibGetSystemConfigurationTable(&SMBIOSTableGuid, + (VOID **)&smbios_table); + if (status != EFI_SUCCESS) { + return 0; + } + + smbios_struct = smbios_find_struct(smbios_table, SMBIOS_TYPE_OEM_129); + if (smbios_struct.Raw == NULL) { + return 0; + } + + return get_station_id(smbios_struct); +} -- 2.39.2 -- 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 efibootguard-dev+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/efibootguard-dev/20231019153004.209654-2-cedric.hombourger%40siemens.com.