From e24c372777476c975a17716c1dfb3c8979388240 Mon Sep 17 00:00:00 2001 From: Marco Oliverio Date: Tue, 12 Sep 2023 15:08:10 +0000 Subject: [PATCH] fsp: remove WOLFBOOT_FIXED_PARTITIONS (and hardcoded size limit) now the size of the image is limited by the available memory only. The image is loaded in RAM just after wolfboot. --- config/examples/kontron_vx3060_s2.config | 3 +- config/examples/x86_fsp_qemu.config | 3 +- .../examples/x86_fsp_qemu_stage1_auth.config | 3 +- config/examples/x86_fsp_qemu_tpm.config | 3 +- .../examples/x86_fsp_qemu_tpm_keystore.config | 3 +- include/stage1.h | 1 + src/boot_x86_fsp.c | 7 +++- src/update_disk.c | 32 +++++++++++++++---- 8 files changed, 37 insertions(+), 18 deletions(-) diff --git a/config/examples/kontron_vx3060_s2.config b/config/examples/kontron_vx3060_s2.config index 989ec0d0..053a2a8b 100644 --- a/config/examples/kontron_vx3060_s2.config +++ b/config/examples/kontron_vx3060_s2.config @@ -6,8 +6,7 @@ HASH=SHA384 DEBUG=1 SPMATH=1 ENCRYPTION=0 -WOLFBOOT_FIXED_PARTITIONS=1 -WOLFBOOT_PARTITION_SIZE=0x4000000 +WOLFBOOT_NO_PARTITIONS=1 FORCE_32BIT=1 # 4gb - 12mb (BIOS Region size) diff --git a/config/examples/x86_fsp_qemu.config b/config/examples/x86_fsp_qemu.config index 46602add..76734003 100644 --- a/config/examples/x86_fsp_qemu.config +++ b/config/examples/x86_fsp_qemu.config @@ -7,8 +7,7 @@ DEBUG=1 SPMATH=1 FORCE_32BIT=1 ENCRYPTION=0 -WOLFBOOT_FIXED_PARTITIONS=1 -WOLFBOOT_PARTITION_SIZE=0x8000000 +WOLFBOOT_NO_PARTITIONS=1 WOLFTPM=0 # TPM Keystore options diff --git a/config/examples/x86_fsp_qemu_stage1_auth.config b/config/examples/x86_fsp_qemu_stage1_auth.config index fcbcb340..ec209d2f 100644 --- a/config/examples/x86_fsp_qemu_stage1_auth.config +++ b/config/examples/x86_fsp_qemu_stage1_auth.config @@ -7,8 +7,7 @@ DEBUG=1 SPMATH=1 FORCE_32BIT=1 ENCRYPTION=0 -WOLFBOOT_FIXED_PARTITIONS=1 -WOLFBOOT_PARTITION_SIZE=0x8000000 +WOLFBOOT_NO_PARTITIONS=1 WOLFTPM=0 # TPM Keystore options diff --git a/config/examples/x86_fsp_qemu_tpm.config b/config/examples/x86_fsp_qemu_tpm.config index 2cb93f0b..ebaa63c0 100644 --- a/config/examples/x86_fsp_qemu_tpm.config +++ b/config/examples/x86_fsp_qemu_tpm.config @@ -7,8 +7,7 @@ DEBUG=1 SPMATH=1 FORCE_32BIT=1 ENCRYPTION=0 -WOLFBOOT_FIXED_PARTITIONS=1 -WOLFBOOT_PARTITION_SIZE=0x8000000 +WOLFBOOT_NO_PARTITIONS=1 WOLFTPM=1 # TPM Keystore options diff --git a/config/examples/x86_fsp_qemu_tpm_keystore.config b/config/examples/x86_fsp_qemu_tpm_keystore.config index 52100d91..9b8c1111 100644 --- a/config/examples/x86_fsp_qemu_tpm_keystore.config +++ b/config/examples/x86_fsp_qemu_tpm_keystore.config @@ -7,8 +7,7 @@ DEBUG=1 SPMATH=1 FORCE_32BIT=1 ENCRYPTION=0 -WOLFBOOT_FIXED_PARTITIONS=1 -WOLFBOOT_PARTITION_SIZE=0x800000 +WOLFBOOT_NO_PARTITIONS=1 WOLFTPM=1 # TPM Keystore options diff --git a/include/stage1.h b/include/stage1.h index 41159760..6bd5ff8f 100644 --- a/include/stage1.h +++ b/include/stage1.h @@ -27,6 +27,7 @@ struct stage2_parameter { #if WOLFBOOT_FSP uint32_t hobList; uint32_t page_table; + uint32_t tolum; #endif }; diff --git a/src/boot_x86_fsp.c b/src/boot_x86_fsp.c index 739a1c29..4b5c75b0 100644 --- a/src/boot_x86_fsp.c +++ b/src/boot_x86_fsp.c @@ -546,12 +546,17 @@ void start(uint32_t stack_base, uint32_t stack_top, uint64_t timestamp, stage2_params->hobList = (uint32_t)hobList; #ifdef WOLFBOOT_64BIT - stage2_params->page_table = ((uint32_t)(stage2_params) - + stage2_params->page_table = ((uint32_t)(top_address) - x86_paging_get_page_table_size()); stage2_params->page_table = (((uint32_t)stage2_params->page_table) & ~((1 << 12) - 1)); memset((uint8_t*)stage2_params->page_table, 0, x86_paging_get_page_table_size()); + wolfBoot_printf("page table @ 0x%x [length: %x]" ENDLINE, (uint32_t)stage2_params->page_table, x86_paging_get_page_table_size()); + top_address = stage2_params->page_table; #endif /* WOLFBOOT_64BIT */ + stage2_params->tolum = top_address; + + /* change_stack_and_invoke() never returns. * * Execution here is eventually transferred to memory_ready_entry diff --git a/src/update_disk.c b/src/update_disk.c index 86728a30..091021e3 100644 --- a/src/update_disk.c +++ b/src/update_disk.c @@ -41,7 +41,9 @@ #include "hal.h" #include "spi_flash.h" #include "printf.h" +#include "stage1.h" #include "wolfboot/wolfboot.h" +#include #include #include #include @@ -62,7 +64,9 @@ #define MAX_FAILURES 4 -#define IMAGE_PRELOAD_ADDRESS 0x5000100 +/* from the linker, where wolfBoot ends */ +extern uint8_t _end_wb[]; + /** * @brief function for starting the boot process. * @@ -72,6 +76,7 @@ */ void RAMFUNCTION wolfBoot_start(void) { + struct stage2_parameter *stage2_params; struct wolfBoot_image os_image; uint8_t p_hdr[IMAGE_HEADER_SIZE]; int pA_ver = 0, pB_ver = 0; @@ -110,14 +115,15 @@ void RAMFUNCTION wolfBoot_start(void) wolfBoot_printf("Versions, A:%u B:%u\r\n", pA_ver, pB_ver); - if (pB_ver > pA_ver) selected = 1; else selected = 0; - load_address = (uint32_t *)(IMAGE_PRELOAD_ADDRESS - IMAGE_HEADER_SIZE); - + stage2_params = stage2_get_parameters(); + /* load the image just after wolfboot */ + load_address = (uint32_t *)(_end_wb); + wolfBoot_printf("Load address %x\r\n", load_address); do { failures++; if (selected) @@ -139,7 +145,14 @@ void RAMFUNCTION wolfBoot_start(void) /* Dereference img_size from header */ img_size = *( ((uint32_t *)p_hdr) + 1); + if (img_size > + ((uint32_t)(stage2_params->tolum) - (uint32_t)(uintptr_t)load_address)) { + wolfBoot_printf("Image size %d doesn't fit in low memory\r\n", img_size); + break; + } + /* Read the image into RAM */ + wolfBoot_printf("Loading image from disk..."); load_off = 0; do { ret = disk_read(BOOT_DISK, cur_part, load_off, 512, @@ -155,25 +168,30 @@ void RAMFUNCTION wolfBoot_start(void) selected ^= 1; continue; } - + wolfBoot_printf("done.\r\n"); ret = wolfBoot_open_image_address(&os_image, (void *)load_address); if (ret < 0) { wolfBoot_printf("Error parsing loaded image\r\n"); selected ^= 1; continue; } + + wolfBoot_printf("Checking image integrity..."); if (wolfBoot_verify_integrity(&os_image) != 0) { wolfBoot_printf("Error validating integrity for partition %c\r\n", 'A' + selected); selected ^= 1; continue; } + wolfBoot_printf("done.\r\n"); + wolfBoot_printf("Verifying image signature..."); if (wolfBoot_verify_authenticity(&os_image) != 0) { wolfBoot_printf("Error validating authenticity for partition %c\r\n", 'A' + selected); selected ^= 1; continue; } else { + wolfBoot_printf("done.\r\n"); failures = 0; break; /* Success case */ } @@ -183,8 +201,8 @@ void RAMFUNCTION wolfBoot_start(void) panic(); } - wolfBoot_printf("Firmware Valid\n"); - wolfBoot_printf("Booting at %08lx\n", IMAGE_PRELOAD_ADDRESS); + wolfBoot_printf("Firmware Valid.\r\n"); + wolfBoot_printf("Booting at %08lx\r\n", os_image.fw_base); hal_prepare_boot(); do_boot((uint32_t*)os_image.fw_base);