Skip to content

Commit dab5605

Browse files
rizlikdanielinux
authored andcommitted
fsp: refactor out common fsp routines
1 parent b8a81de commit dab5605

File tree

4 files changed

+130
-59
lines changed

4 files changed

+130
-59
lines changed

arch.mk

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -968,6 +968,7 @@ ifeq ("${FSP}", "1")
968968
OBJS += hal/x86_uart.o
969969
OBJS += src/string.o
970970
OBJS += src/stage2_params.o
971+
OBJS += src/x86/fsp.o
971972
ifeq ($(filter-out $(STAGE1_AUTH),1),)
972973
OBJS += src/libwolfboot.o
973974
OBJS += src/image.o
@@ -1013,6 +1014,7 @@ ifeq ("${FSP}", "1")
10131014
OBJS += src/stage2_params.o
10141015
OBJS += src/x86/exceptions.o
10151016
OBJS += src/x86/gdt.o
1017+
OBJS += src/x86/fsp.o
10161018
UPDATE_OBJS := src/update_disk.o
10171019
CFLAGS+=-DWOLFBOOT_UPDATE_DISK
10181020
ifeq ($(64BIT),1)

include/x86/fsp.h

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/* fsp.h
2+
*
3+
* Copyright (C) 2023 wolfSSL Inc.
4+
*
5+
* This file is part of wolfBoot.
6+
*
7+
* wolfBoot is free software; you can redistribute it and/or modify
8+
* it under the terms of the GNU General Public License as published by
9+
* the Free Software Foundation; either version 2 of the License, or
10+
* (at your option) any later version.
11+
*
12+
* wolfBoot is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU General Public License
18+
* along with this program; if not, write to the Free Software
19+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
20+
*/
21+
#ifndef FSP_H
22+
#define FSP_H
23+
24+
#include <x86/fsp/FspCommon.h>
25+
26+
int fsp_info_header_is_ok(struct fsp_info_header *hdr);
27+
int fsp_get_image_revision(struct fsp_info_header *h, int *build,
28+
int *rev, int *maj, int *min);
29+
void print_fsp_image_revision(struct fsp_info_header *h);
30+
31+
#endif /* FSP_H */

src/boot_x86_fsp.c

Lines changed: 1 addition & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929
#include <x86/fsp/FspCommon.h>
3030
#include <x86/common.h>
31+
#include <x86/fsp.h>
3132
#include <uart_drv.h>
3233
#include <x86/hob.h>
3334
#include <x86/paging.h>
@@ -351,65 +352,6 @@ static inline void memory_init_data_bss(void)
351352
memset(_start_bss, 0, (_end_bss - _start_bss));
352353
}
353354

354-
/*!
355-
* \brief Check if the FSP info header is valid.
356-
*
357-
* This static function checks if the given FSP info header is valid by verifying
358-
* its signature.
359-
*
360-
* \param hdr Pointer to the FSP info header structure.
361-
* \return 1 if the FSP info header is valid, 0 otherwise.
362-
*/
363-
static int fsp_info_header_is_ok(struct fsp_info_header *hdr)
364-
{
365-
uint8_t *raw_signature;
366-
367-
raw_signature = (uint8_t *)&hdr->Signature;
368-
if (raw_signature[0] != 'F' || raw_signature[1] != 'S' ||
369-
raw_signature[2] != 'P' || raw_signature[3] != 'H') {
370-
return 0;
371-
}
372-
return 1;
373-
}
374-
375-
static int fsp_get_image_revision(struct fsp_info_header *h, int *build,
376-
int *rev, int *maj, int *min)
377-
{
378-
uint16_t ext_revision;
379-
uint32_t revision;
380-
381-
if (!fsp_info_header_is_ok(h)) {
382-
wolfBoot_printf("Wrong FSP Header\r\n");
383-
return -1;
384-
}
385-
386-
revision = h->ImageRevision;
387-
388-
*build = revision & 0xff;
389-
*rev = (revision >> 8) & 0xff;
390-
*min = (revision >> 16) & 0xff;
391-
*maj = (revision >> 24) & 0xff;
392-
393-
if (h->HeaderRevision >= 6) {
394-
*build = *build | ((h->ExtendedImageRevision & 0xff) << 8);
395-
*rev = *rev | (h->ExtendedImageRevision & 0xff00);
396-
}
397-
398-
return 0;
399-
}
400-
401-
static void print_fsp_image_revision(struct fsp_info_header *h)
402-
{
403-
int build, rev, maj, min;
404-
int r;
405-
r = fsp_get_image_revision(h, &build, &rev, &maj, &min);
406-
if (r != 0) {
407-
wolfBoot_printf("failed to get fsp image revision\r\n");
408-
return;
409-
}
410-
wolfBoot_printf("%x.%x.%x build %x\r\n", maj, min, rev, build);
411-
}
412-
413355
static int pci_get_capability(uint8_t bus, uint8_t dev, uint8_t fun,
414356
uint8_t cap_id, uint8_t *cap_off)
415357
{

src/x86/fsp.c

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
/* fsp_tgl.c
2+
*
3+
* Copyright (C) 2023 wolfSSL Inc.
4+
*
5+
* This file is part of wolfBoot.
6+
*
7+
* wolfBoot is free software; you can redistribute it and/or modify
8+
* it under the terms of the GNU General Public License as published by
9+
* the Free Software Foundation; either version 2 of the License, or
10+
* (at your option) any later version.
11+
*
12+
* wolfBoot is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU General Public License
18+
* along with this program; if not, write to the Free Software
19+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
20+
*/
21+
#include <x86/fsp/FspCommon.h>
22+
#include <stage2_params.h>
23+
#include <x86/common.h>
24+
#include <pci.h>
25+
#include <printf.h>
26+
27+
#define FSP_INFO_HEADER_OFFSET 0x94
28+
#define EFI_SUCCESS 0x0
29+
30+
#ifndef FSP_S_PARAM_SIZE
31+
#define FSP_S_PARAM_SIZE 0xee0
32+
#endif
33+
34+
#define PCI_DEVICE_CONTROLLER_TO_PEX 0x6
35+
36+
37+
int fsp_machine_update_s_parameters(uint8_t *default_s_params);
38+
int fsp_pre_silicon_init_cb(void);
39+
/*!
40+
* \brief Check if the FSP info header is valid.
41+
*
42+
* This static function checks if the given FSP info header is valid by verifying
43+
* its signature.
44+
*
45+
* \param hdr Pointer to the FSP info header structure.
46+
* \return 1j if the FSP info header is valid, 0 otherwise.
47+
*/
48+
int fsp_info_header_is_ok(struct fsp_info_header *hdr)
49+
{
50+
uint8_t *raw_signature;
51+
52+
raw_signature = (uint8_t *)&hdr->Signature;
53+
if (raw_signature[0] != 'F' || raw_signature[1] != 'S' ||
54+
raw_signature[2] != 'P' || raw_signature[3] != 'H') {
55+
return 0;
56+
}
57+
return 1;
58+
}
59+
60+
int fsp_get_image_revision(struct fsp_info_header *h, int *build,
61+
int *rev, int *maj, int *min)
62+
{
63+
uint16_t ext_revision;
64+
uint32_t revision;
65+
66+
if (!fsp_info_header_is_ok(h)) {
67+
wolfBoot_printf("Wrong FSP Header\r\n");
68+
return -1;
69+
}
70+
71+
revision = h->ImageRevision;
72+
73+
*build = revision & 0xff;
74+
*rev = (revision >> 8) & 0xff;
75+
*min = (revision >> 16) & 0xff;
76+
*maj = (revision >> 24) & 0xff;
77+
78+
if (h->HeaderRevision >= 6) {
79+
*build = *build | ((h->ExtendedImageRevision & 0xff) << 8);
80+
*rev = *rev | (h->ExtendedImageRevision & 0xff00);
81+
}
82+
83+
return 0;
84+
}
85+
86+
void print_fsp_image_revision(struct fsp_info_header *h)
87+
{
88+
int build, rev, maj, min;
89+
int r;
90+
r = fsp_get_image_revision(h, &build, &rev, &maj, &min);
91+
if (r != 0) {
92+
wolfBoot_printf("failed to get fsp image revision\r\n");
93+
return;
94+
}
95+
wolfBoot_printf("%x.%x.%x build %x\r\n", maj, min, rev, build);
96+
}

0 commit comments

Comments
 (0)