Skip to content

Commit

Permalink
fsp: move TempRamInitExit and later APIs in stage2
Browse files Browse the repository at this point in the history
To avoid using Flash memory after TempRamInitExit. This protects against
malicious modification/injection of the flash after Cache-As-RAM is
disabled.
  • Loading branch information
rizlik authored and danielinux committed Dec 19, 2024
1 parent 151de7f commit 834a712
Show file tree
Hide file tree
Showing 15 changed files with 144 additions and 236 deletions.
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,8 @@ $(LSCRIPT): $(LSCRIPT_IN) FORCE
sed -e "s/@WOLFBOOT_STAGE1_BASE_ADDR@/$(WOLFBOOT_STAGE1_BASE_ADDR)/g" | \
sed -e "s/@WOLFBOOT_LOAD_BASE@/$(WOLFBOOT_LOAD_BASE)/g" | \
sed -e "s/@BOOTLOADER_START@/$(BOOTLOADER_START)/g" | \
sed -e "s/@IMAGE_HEADER_SIZE@/$(IMAGE_HEADER_SIZE)/g" \
sed -e "s/@IMAGE_HEADER_SIZE@/$(IMAGE_HEADER_SIZE)/g" | \
sed -e "s/@FSP_S_LOAD_BASE@/$(FSP_S_LOAD_BASE)/g" \
> $@

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

src/x86/fsp_s.o: $(FSP_S_BIN)
$(OBJCOPY) -I binary -O elf64-x86-64 -B i386 --rename-section .data=.fsp_s $^ $@

FORCE:

.PHONY: FORCE clean keytool_check
12 changes: 7 additions & 5 deletions arch.mk
Original file line number Diff line number Diff line change
Expand Up @@ -930,9 +930,7 @@ ifeq ($(filter $(TARGET),x86_fsp_qemu kontron_vx3060_s2),$(TARGET))
endif

ifeq ($(TARGET),x86_fsp_qemu)
ifeq ($(filter-out $(STAGE1),1),)
OBJS+=src/x86/qemu_fsp.o
endif
endif

# x86-64 FSP targets
Expand All @@ -958,7 +956,6 @@ ifeq ("${FSP}", "1")
OBJS += src/boot_x86_fsp.o
OBJS += src/boot_x86_fsp_start.o
OBJS += src/fsp_m.o
OBJS += src/fsp_s.o
OBJS += src/fsp_t.o
OBJS += src/wolfboot_raw.o
OBJS += src/x86/common.o
Expand All @@ -974,7 +971,6 @@ ifeq ("${FSP}", "1")
OBJS += src/image.o
OBJS += src/keystore.o
OBJS += src/sig_wolfboot_raw.o
OBJS += src/sig_fsp_s.o
ifeq ($(TARGET), kontron_vx3060_s2)
OBJS += hal/kontron_vx3060_s2_loader.o
endif
Expand All @@ -983,6 +979,7 @@ ifeq ("${FSP}", "1")
endif

CFLAGS += -fno-stack-protector -m32 -fno-PIC -fno-pie -mno-mmx -mno-sse -DDEBUG_UART
CFLAGS += -DFSP_M_BASE=$(FSP_M_BASE)
ifeq ($(FSP_TGL), 1)
OBJS+=src/x86/tgl_fsp.o
OBJS+=src/ucode0.o
Expand All @@ -1000,6 +997,7 @@ ifeq ("${FSP}", "1")
endif
LDFLAGS = --gc-sections --entry=main -T $(LSCRIPT) -Map=wolfboot.map
CFLAGS += -fno-stack-protector -fno-PIC -fno-pie -mno-mmx -mno-sse -Os -DDEBUG_UART
CFLAGS += -DFSP_M_BASE=$(FSP_M_BASE)
OBJS += hal/x86_fsp_tgl.o
OBJS += hal/x86_uart.o
OBJS += src/boot_x86_fsp_payload.o
Expand All @@ -1015,6 +1013,7 @@ ifeq ("${FSP}", "1")
OBJS += src/x86/exceptions.o
OBJS += src/x86/gdt.o
OBJS += src/x86/fsp.o
OBJS += src/x86/fsp_s.o
UPDATE_OBJS := src/update_disk.o
CFLAGS+=-DWOLFBOOT_UPDATE_DISK
ifeq ($(64BIT),1)
Expand All @@ -1023,7 +1022,10 @@ ifeq ("${FSP}", "1")
else
CFLAGS += -m32
LDFLAGS += -m elf_i386 --oformat elf32-i386
endif
endif
ifeq ($(FSP_TGL), 1)
OBJS+=src/x86/tgl_fsp.o
endif
endif
ifeq ($(64BIT),1)
OBJS += src/x86/paging.o
Expand Down
1 change: 0 additions & 1 deletion config/examples/x86_fsp_qemu_seal.config
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ WOLFBOOT_SECTOR_SIZE?=0x1000
WOLFBOOT_DATA_ADDRESS=0x1000000

FSP_M_BASE=0xffe30000
FSP_S_BASE=0xffed6000
FSP_T_BASE=0xfffe0000
FSP_S_LOAD_BASE=0x0FED5F00
WOLFBOOT_ORIGIN=0xfff80000
Expand Down
2 changes: 2 additions & 0 deletions hal/kontron_vx3060_s2.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <printf.h>
#include <pci.h>
#include <x86/gdt.h>
#include <x86/fsp.h>
#include <x86/common.h>

#ifdef __WOLFBOOT
Expand Down Expand Up @@ -88,6 +89,7 @@ void hal_init(void)
{
gdt_setup_table();
gdt_update_segments();
fsp_init_silicon();
}

void hal_prepare_boot(void)
Expand Down
2 changes: 2 additions & 0 deletions hal/x86_fsp_qemu.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,14 @@
#include <x86/ata.h>
#include <x86/gdt.h>
#include <x86/common.h>
#include <x86/fsp.h>
#include <pci.h>

void hal_init(void)
{
gdt_setup_table();
gdt_update_segments();
fsp_init_silicon();
}

void hal_prepare_boot(void)
Expand Down
13 changes: 12 additions & 1 deletion hal/x86_fsp_qemu.ld.in
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
MEM_SIZE = 536870912;
WOLFBOOT_LOAD_BASE = @WOLFBOOT_LOAD_BASE@;
FSP_S_LOAD_BASE = @FSP_S_LOAD_BASE@;

MEMORY
{
Expand All @@ -16,11 +17,15 @@ SECTIONS
*(.rodata*)
*(.keystore*)
*(.data*)
_start_fsp_s = .;
KEEP(*(.fsp_s))
_end_fsp_s = .;
. = ALIGN(4);
_end_text = .;
_end_wolfboot = .;
}
} > RAM

_fsp_size = _end_fsp_s - _start_fsp_s;
.bss WOLFBOOT_LOAD_BASE + SIZEOF(.text) (NOLOAD):
{
_start_bss = .;
Expand All @@ -31,5 +36,11 @@ SECTIONS
_end_bss = .;
__bss_end__ = .;
_end_wb = .;
} > RAM

.fsp_s_base FSP_S_LOAD_BASE (NOLOAD) :
{
_fsp_s_base_start = .;
. += _fsp_size;
}
}
10 changes: 0 additions & 10 deletions hal/x86_fsp_qemu_stage1.ld.in
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ RESETVECTOR_START = 0xffffffec;
KEYSTORE_START = 0xffffe000;
FSP_T_ORIGIN = @FSP_T_BASE@; /* default base:size 0xFFFFF000:0x3000 [0xfffff000:0x100002000] */
FSP_M_ORIGIN = @FSP_M_BASE@; /* default base:size 0xfffdd000:0x22000 [0xfffdd000:0xfffff000] */
FSP_S_ORIGIN = @FSP_S_BASE@; /* default base:size 0xfffc8000:0x15000 [0xfffdd000:0xfffdd000] */
WOLFBOOT_ORIGIN = @WOLFBOOT_ORIGIN@;
DATA_MEM_START = 0x800000; /* 8 MB */
MAX_POLICY_SIZE = 512;
Expand Down Expand Up @@ -92,15 +91,6 @@ SECTIONS
KEEP(*(.fsp_t))
}

.fsp_s FSP_S_ORIGIN :
{
_fsp_s_hdr = .;
KEEP(*(.sig_fsp_s*))
_start_fsp_s = .;
KEEP(*(.fsp_s))
_end_fsp_s = .;
}

.fsp_m FSP_M_ORIGIN :
{
_start_fsp_m = .;
Expand Down
11 changes: 11 additions & 0 deletions hal/x86_fsp_tgl.ld.in
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
MEM_SIZE = 536870912;
WOLFBOOT_LOAD_BASE = @WOLFBOOT_LOAD_BASE@;
FSP_S_LOAD_BASE = @FSP_S_LOAD_BASE@;

MEMORY
{
Expand All @@ -16,11 +17,15 @@ SECTIONS
*(.rodata*)
*(.keystore*)
*(.data*)
_start_fsp_s = .;
KEEP(*(.fsp_s))
_end_fsp_s = .;
. = ALIGN(4);
_end_text = .;
_end_wolfboot = .;
}

_fsp_size = _end_fsp_s - _start_fsp_s;
.bss WOLFBOOT_LOAD_BASE + SIZEOF(.text) (NOLOAD):
{
_start_bss = .;
Expand All @@ -32,4 +37,10 @@ SECTIONS
__bss_end__ = .;
_end_wb = .;
}

.fsp_s_base FSP_S_LOAD_BASE (NOLOAD) :
{
_fsp_s_base_start = .;
. = . + _fsp_size;
}
}
10 changes: 0 additions & 10 deletions hal/x86_fsp_tgl_stage1.ld.in
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ FLASH_SIZE = @BOOTLOADER_PARTITION_SIZE@;
FLASH_START = 0x100000000 - @BOOTLOADER_PARTITION_SIZE@;
UCODE0_BASE = @UCODE0_BASE@;
FIT_TABLE = 0xffe00000;
FSP_S_ORIGIN = @FSP_S_BASE@;
WOLFBOOT_ORIGIN = @WOLFBOOT_ORIGIN@;
FSP_T_ORIGIN = @FSP_T_BASE@;
FSP_M_ORIGIN = @FSP_M_BASE@;
Expand Down Expand Up @@ -52,15 +51,6 @@ SECTIONS
. = ALIGN(256*1024);
}

.fsp_s FSP_S_ORIGIN :
{
_fsp_s_hdr = .;
KEEP(*(.sig_fsp_s*))
_start_fsp_s = .;
KEEP(*(.fsp_s))
_end_fsp_s = .;
} > FLASH

.bootloader WOLFBOOT_ORIGIN :
{
KEEP(./tgl_fsp.o(.boot))
Expand Down
1 change: 1 addition & 0 deletions include/x86/fsp.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,6 @@ 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);
void fsp_init_silicon(void);

#endif /* FSP_H */
Loading

0 comments on commit 834a712

Please sign in to comment.