Skip to content

Commit 834a712

Browse files
rizlikdanielinux
authored andcommitted
fsp: move TempRamInitExit and later APIs in stage2
To avoid using Flash memory after TempRamInitExit. This protects against malicious modification/injection of the flash after Cache-As-RAM is disabled.
1 parent 151de7f commit 834a712

File tree

15 files changed

+144
-236
lines changed

15 files changed

+144
-236
lines changed

Makefile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,8 @@ $(LSCRIPT): $(LSCRIPT_IN) FORCE
315315
sed -e "s/@WOLFBOOT_STAGE1_BASE_ADDR@/$(WOLFBOOT_STAGE1_BASE_ADDR)/g" | \
316316
sed -e "s/@WOLFBOOT_LOAD_BASE@/$(WOLFBOOT_LOAD_BASE)/g" | \
317317
sed -e "s/@BOOTLOADER_START@/$(BOOTLOADER_START)/g" | \
318-
sed -e "s/@IMAGE_HEADER_SIZE@/$(IMAGE_HEADER_SIZE)/g" \
318+
sed -e "s/@IMAGE_HEADER_SIZE@/$(IMAGE_HEADER_SIZE)/g" | \
319+
sed -e "s/@FSP_S_LOAD_BASE@/$(FSP_S_LOAD_BASE)/g" \
319320
> $@
320321

321322
hex: wolfboot.hex
@@ -447,6 +448,9 @@ secondary: $(SECONDARY_PRIVATE_KEY)
447448
@echo "\t[AS-$(ARCH)] $@"
448449
$(Q)$(CC) $(CFLAGS) -c $(OUTPUT_FLAG) $@ $^
449450

451+
src/x86/fsp_s.o: $(FSP_S_BIN)
452+
$(OBJCOPY) -I binary -O elf64-x86-64 -B i386 --rename-section .data=.fsp_s $^ $@
453+
450454
FORCE:
451455

452456
.PHONY: FORCE clean keytool_check

arch.mk

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -930,9 +930,7 @@ ifeq ($(filter $(TARGET),x86_fsp_qemu kontron_vx3060_s2),$(TARGET))
930930
endif
931931

932932
ifeq ($(TARGET),x86_fsp_qemu)
933-
ifeq ($(filter-out $(STAGE1),1),)
934933
OBJS+=src/x86/qemu_fsp.o
935-
endif
936934
endif
937935

938936
# x86-64 FSP targets
@@ -958,7 +956,6 @@ ifeq ("${FSP}", "1")
958956
OBJS += src/boot_x86_fsp.o
959957
OBJS += src/boot_x86_fsp_start.o
960958
OBJS += src/fsp_m.o
961-
OBJS += src/fsp_s.o
962959
OBJS += src/fsp_t.o
963960
OBJS += src/wolfboot_raw.o
964961
OBJS += src/x86/common.o
@@ -974,7 +971,6 @@ ifeq ("${FSP}", "1")
974971
OBJS += src/image.o
975972
OBJS += src/keystore.o
976973
OBJS += src/sig_wolfboot_raw.o
977-
OBJS += src/sig_fsp_s.o
978974
ifeq ($(TARGET), kontron_vx3060_s2)
979975
OBJS += hal/kontron_vx3060_s2_loader.o
980976
endif
@@ -983,6 +979,7 @@ ifeq ("${FSP}", "1")
983979
endif
984980

985981
CFLAGS += -fno-stack-protector -m32 -fno-PIC -fno-pie -mno-mmx -mno-sse -DDEBUG_UART
982+
CFLAGS += -DFSP_M_BASE=$(FSP_M_BASE)
986983
ifeq ($(FSP_TGL), 1)
987984
OBJS+=src/x86/tgl_fsp.o
988985
OBJS+=src/ucode0.o
@@ -1000,6 +997,7 @@ ifeq ("${FSP}", "1")
1000997
endif
1001998
LDFLAGS = --gc-sections --entry=main -T $(LSCRIPT) -Map=wolfboot.map
1002999
CFLAGS += -fno-stack-protector -fno-PIC -fno-pie -mno-mmx -mno-sse -Os -DDEBUG_UART
1000+
CFLAGS += -DFSP_M_BASE=$(FSP_M_BASE)
10031001
OBJS += hal/x86_fsp_tgl.o
10041002
OBJS += hal/x86_uart.o
10051003
OBJS += src/boot_x86_fsp_payload.o
@@ -1015,6 +1013,7 @@ ifeq ("${FSP}", "1")
10151013
OBJS += src/x86/exceptions.o
10161014
OBJS += src/x86/gdt.o
10171015
OBJS += src/x86/fsp.o
1016+
OBJS += src/x86/fsp_s.o
10181017
UPDATE_OBJS := src/update_disk.o
10191018
CFLAGS+=-DWOLFBOOT_UPDATE_DISK
10201019
ifeq ($(64BIT),1)
@@ -1023,7 +1022,10 @@ ifeq ("${FSP}", "1")
10231022
else
10241023
CFLAGS += -m32
10251024
LDFLAGS += -m elf_i386 --oformat elf32-i386
1026-
endif
1025+
endif
1026+
ifeq ($(FSP_TGL), 1)
1027+
OBJS+=src/x86/tgl_fsp.o
1028+
endif
10271029
endif
10281030
ifeq ($(64BIT),1)
10291031
OBJS += src/x86/paging.o

config/examples/x86_fsp_qemu_seal.config

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ WOLFBOOT_SECTOR_SIZE?=0x1000
2424
WOLFBOOT_DATA_ADDRESS=0x1000000
2525

2626
FSP_M_BASE=0xffe30000
27-
FSP_S_BASE=0xffed6000
2827
FSP_T_BASE=0xfffe0000
2928
FSP_S_LOAD_BASE=0x0FED5F00
3029
WOLFBOOT_ORIGIN=0xfff80000

hal/kontron_vx3060_s2.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include <printf.h>
2626
#include <pci.h>
2727
#include <x86/gdt.h>
28+
#include <x86/fsp.h>
2829
#include <x86/common.h>
2930

3031
#ifdef __WOLFBOOT
@@ -88,6 +89,7 @@ void hal_init(void)
8889
{
8990
gdt_setup_table();
9091
gdt_update_segments();
92+
fsp_init_silicon();
9193
}
9294

9395
void hal_prepare_boot(void)

hal/x86_fsp_qemu.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,14 @@
2929
#include <x86/ata.h>
3030
#include <x86/gdt.h>
3131
#include <x86/common.h>
32+
#include <x86/fsp.h>
3233
#include <pci.h>
3334

3435
void hal_init(void)
3536
{
3637
gdt_setup_table();
3738
gdt_update_segments();
39+
fsp_init_silicon();
3840
}
3941

4042
void hal_prepare_boot(void)

hal/x86_fsp_qemu.ld.in

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
MEM_SIZE = 536870912;
22
WOLFBOOT_LOAD_BASE = @WOLFBOOT_LOAD_BASE@;
3+
FSP_S_LOAD_BASE = @FSP_S_LOAD_BASE@;
34

45
MEMORY
56
{
@@ -16,11 +17,15 @@ SECTIONS
1617
*(.rodata*)
1718
*(.keystore*)
1819
*(.data*)
20+
_start_fsp_s = .;
21+
KEEP(*(.fsp_s))
22+
_end_fsp_s = .;
1923
. = ALIGN(4);
2024
_end_text = .;
2125
_end_wolfboot = .;
22-
}
26+
} > RAM
2327

28+
_fsp_size = _end_fsp_s - _start_fsp_s;
2429
.bss WOLFBOOT_LOAD_BASE + SIZEOF(.text) (NOLOAD):
2530
{
2631
_start_bss = .;
@@ -31,5 +36,11 @@ SECTIONS
3136
_end_bss = .;
3237
__bss_end__ = .;
3338
_end_wb = .;
39+
} > RAM
40+
41+
.fsp_s_base FSP_S_LOAD_BASE (NOLOAD) :
42+
{
43+
_fsp_s_base_start = .;
44+
. += _fsp_size;
3445
}
3546
}

hal/x86_fsp_qemu_stage1.ld.in

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ RESETVECTOR_START = 0xffffffec;
55
KEYSTORE_START = 0xffffe000;
66
FSP_T_ORIGIN = @FSP_T_BASE@; /* default base:size 0xFFFFF000:0x3000 [0xfffff000:0x100002000] */
77
FSP_M_ORIGIN = @FSP_M_BASE@; /* default base:size 0xfffdd000:0x22000 [0xfffdd000:0xfffff000] */
8-
FSP_S_ORIGIN = @FSP_S_BASE@; /* default base:size 0xfffc8000:0x15000 [0xfffdd000:0xfffdd000] */
98
WOLFBOOT_ORIGIN = @WOLFBOOT_ORIGIN@;
109
DATA_MEM_START = 0x800000; /* 8 MB */
1110
MAX_POLICY_SIZE = 512;
@@ -92,15 +91,6 @@ SECTIONS
9291
KEEP(*(.fsp_t))
9392
}
9493

95-
.fsp_s FSP_S_ORIGIN :
96-
{
97-
_fsp_s_hdr = .;
98-
KEEP(*(.sig_fsp_s*))
99-
_start_fsp_s = .;
100-
KEEP(*(.fsp_s))
101-
_end_fsp_s = .;
102-
}
103-
10494
.fsp_m FSP_M_ORIGIN :
10595
{
10696
_start_fsp_m = .;

hal/x86_fsp_tgl.ld.in

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
MEM_SIZE = 536870912;
22
WOLFBOOT_LOAD_BASE = @WOLFBOOT_LOAD_BASE@;
3+
FSP_S_LOAD_BASE = @FSP_S_LOAD_BASE@;
34

45
MEMORY
56
{
@@ -16,11 +17,15 @@ SECTIONS
1617
*(.rodata*)
1718
*(.keystore*)
1819
*(.data*)
20+
_start_fsp_s = .;
21+
KEEP(*(.fsp_s))
22+
_end_fsp_s = .;
1923
. = ALIGN(4);
2024
_end_text = .;
2125
_end_wolfboot = .;
2226
}
2327

28+
_fsp_size = _end_fsp_s - _start_fsp_s;
2429
.bss WOLFBOOT_LOAD_BASE + SIZEOF(.text) (NOLOAD):
2530
{
2631
_start_bss = .;
@@ -32,4 +37,10 @@ SECTIONS
3237
__bss_end__ = .;
3338
_end_wb = .;
3439
}
40+
41+
.fsp_s_base FSP_S_LOAD_BASE (NOLOAD) :
42+
{
43+
_fsp_s_base_start = .;
44+
. = . + _fsp_size;
45+
}
3546
}

hal/x86_fsp_tgl_stage1.ld.in

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ FLASH_SIZE = @BOOTLOADER_PARTITION_SIZE@;
22
FLASH_START = 0x100000000 - @BOOTLOADER_PARTITION_SIZE@;
33
UCODE0_BASE = @UCODE0_BASE@;
44
FIT_TABLE = 0xffe00000;
5-
FSP_S_ORIGIN = @FSP_S_BASE@;
65
WOLFBOOT_ORIGIN = @WOLFBOOT_ORIGIN@;
76
FSP_T_ORIGIN = @FSP_T_BASE@;
87
FSP_M_ORIGIN = @FSP_M_BASE@;
@@ -52,15 +51,6 @@ SECTIONS
5251
. = ALIGN(256*1024);
5352
}
5453

55-
.fsp_s FSP_S_ORIGIN :
56-
{
57-
_fsp_s_hdr = .;
58-
KEEP(*(.sig_fsp_s*))
59-
_start_fsp_s = .;
60-
KEEP(*(.fsp_s))
61-
_end_fsp_s = .;
62-
} > FLASH
63-
6454
.bootloader WOLFBOOT_ORIGIN :
6555
{
6656
KEEP(./tgl_fsp.o(.boot))

include/x86/fsp.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,6 @@ int fsp_info_header_is_ok(struct fsp_info_header *hdr);
2727
int fsp_get_image_revision(struct fsp_info_header *h, int *build,
2828
int *rev, int *maj, int *min);
2929
void print_fsp_image_revision(struct fsp_info_header *h);
30+
void fsp_init_silicon(void);
3031

3132
#endif /* FSP_H */

0 commit comments

Comments
 (0)