From dab560549a327641d335b55e210fdc0b939d7e12 Mon Sep 17 00:00:00 2001 From: Marco Oliverio Date: Wed, 11 Sep 2024 16:11:23 +0200 Subject: [PATCH] fsp: refactor out common fsp routines --- arch.mk | 2 + include/x86/fsp.h | 31 +++++++++++++++ src/boot_x86_fsp.c | 60 +---------------------------- src/x86/fsp.c | 96 ++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 130 insertions(+), 59 deletions(-) create mode 100644 include/x86/fsp.h create mode 100644 src/x86/fsp.c diff --git a/arch.mk b/arch.mk index 4ba2bab7..42a3f002 100644 --- a/arch.mk +++ b/arch.mk @@ -968,6 +968,7 @@ ifeq ("${FSP}", "1") OBJS += hal/x86_uart.o OBJS += src/string.o OBJS += src/stage2_params.o + OBJS += src/x86/fsp.o ifeq ($(filter-out $(STAGE1_AUTH),1),) OBJS += src/libwolfboot.o OBJS += src/image.o @@ -1013,6 +1014,7 @@ ifeq ("${FSP}", "1") OBJS += src/stage2_params.o OBJS += src/x86/exceptions.o OBJS += src/x86/gdt.o + OBJS += src/x86/fsp.o UPDATE_OBJS := src/update_disk.o CFLAGS+=-DWOLFBOOT_UPDATE_DISK ifeq ($(64BIT),1) diff --git a/include/x86/fsp.h b/include/x86/fsp.h new file mode 100644 index 00000000..b825d427 --- /dev/null +++ b/include/x86/fsp.h @@ -0,0 +1,31 @@ +/* fsp.h + * + * Copyright (C) 2023 wolfSSL Inc. + * + * This file is part of wolfBoot. + * + * wolfBoot is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * wolfBoot is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA + */ +#ifndef FSP_H +#define FSP_H + +#include + +int fsp_info_header_is_ok(struct fsp_info_header *hdr); +int fsp_get_image_revision(struct fsp_info_header *h, int *build, + int *rev, int *maj, int *min); +void print_fsp_image_revision(struct fsp_info_header *h); + +#endif /* FSP_H */ diff --git a/src/boot_x86_fsp.c b/src/boot_x86_fsp.c index 4718f28d..b19ca3e5 100644 --- a/src/boot_x86_fsp.c +++ b/src/boot_x86_fsp.c @@ -28,6 +28,7 @@ #include #include +#include #include #include #include @@ -351,65 +352,6 @@ static inline void memory_init_data_bss(void) memset(_start_bss, 0, (_end_bss - _start_bss)); } -/*! - * \brief Check if the FSP info header is valid. - * - * This static function checks if the given FSP info header is valid by verifying - * its signature. - * - * \param hdr Pointer to the FSP info header structure. - * \return 1 if the FSP info header is valid, 0 otherwise. - */ -static int fsp_info_header_is_ok(struct fsp_info_header *hdr) -{ - uint8_t *raw_signature; - - raw_signature = (uint8_t *)&hdr->Signature; - if (raw_signature[0] != 'F' || raw_signature[1] != 'S' || - raw_signature[2] != 'P' || raw_signature[3] != 'H') { - return 0; - } - return 1; -} - -static int fsp_get_image_revision(struct fsp_info_header *h, int *build, - int *rev, int *maj, int *min) -{ - uint16_t ext_revision; - uint32_t revision; - - if (!fsp_info_header_is_ok(h)) { - wolfBoot_printf("Wrong FSP Header\r\n"); - return -1; - } - - revision = h->ImageRevision; - - *build = revision & 0xff; - *rev = (revision >> 8) & 0xff; - *min = (revision >> 16) & 0xff; - *maj = (revision >> 24) & 0xff; - - if (h->HeaderRevision >= 6) { - *build = *build | ((h->ExtendedImageRevision & 0xff) << 8); - *rev = *rev | (h->ExtendedImageRevision & 0xff00); - } - - return 0; -} - -static void print_fsp_image_revision(struct fsp_info_header *h) -{ - int build, rev, maj, min; - int r; - r = fsp_get_image_revision(h, &build, &rev, &maj, &min); - if (r != 0) { - wolfBoot_printf("failed to get fsp image revision\r\n"); - return; - } - wolfBoot_printf("%x.%x.%x build %x\r\n", maj, min, rev, build); -} - static int pci_get_capability(uint8_t bus, uint8_t dev, uint8_t fun, uint8_t cap_id, uint8_t *cap_off) { diff --git a/src/x86/fsp.c b/src/x86/fsp.c new file mode 100644 index 00000000..f5e5e1b0 --- /dev/null +++ b/src/x86/fsp.c @@ -0,0 +1,96 @@ +/* fsp_tgl.c + * + * Copyright (C) 2023 wolfSSL Inc. + * + * This file is part of wolfBoot. + * + * wolfBoot is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * wolfBoot is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA + */ +#include +#include +#include +#include +#include + +#define FSP_INFO_HEADER_OFFSET 0x94 +#define EFI_SUCCESS 0x0 + +#ifndef FSP_S_PARAM_SIZE +#define FSP_S_PARAM_SIZE 0xee0 +#endif + +#define PCI_DEVICE_CONTROLLER_TO_PEX 0x6 + + +int fsp_machine_update_s_parameters(uint8_t *default_s_params); +int fsp_pre_silicon_init_cb(void); +/*! + * \brief Check if the FSP info header is valid. + * + * This static function checks if the given FSP info header is valid by verifying + * its signature. + * + * \param hdr Pointer to the FSP info header structure. + * \return 1j if the FSP info header is valid, 0 otherwise. + */ +int fsp_info_header_is_ok(struct fsp_info_header *hdr) +{ + uint8_t *raw_signature; + + raw_signature = (uint8_t *)&hdr->Signature; + if (raw_signature[0] != 'F' || raw_signature[1] != 'S' || + raw_signature[2] != 'P' || raw_signature[3] != 'H') { + return 0; + } + return 1; +} + +int fsp_get_image_revision(struct fsp_info_header *h, int *build, + int *rev, int *maj, int *min) +{ + uint16_t ext_revision; + uint32_t revision; + + if (!fsp_info_header_is_ok(h)) { + wolfBoot_printf("Wrong FSP Header\r\n"); + return -1; + } + + revision = h->ImageRevision; + + *build = revision & 0xff; + *rev = (revision >> 8) & 0xff; + *min = (revision >> 16) & 0xff; + *maj = (revision >> 24) & 0xff; + + if (h->HeaderRevision >= 6) { + *build = *build | ((h->ExtendedImageRevision & 0xff) << 8); + *rev = *rev | (h->ExtendedImageRevision & 0xff00); + } + + return 0; +} + +void print_fsp_image_revision(struct fsp_info_header *h) +{ + int build, rev, maj, min; + int r; + r = fsp_get_image_revision(h, &build, &rev, &maj, &min); + if (r != 0) { + wolfBoot_printf("failed to get fsp image revision\r\n"); + return; + } + wolfBoot_printf("%x.%x.%x build %x\r\n", maj, min, rev, build); +}