diff --git a/CMakeLists.txt b/CMakeLists.txt index 13272bd7..4190bb99 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -45,6 +45,9 @@ project(wolfBoot) include(cmake/utils.cmake) include(cmake/functions.cmake) +include_directories(include) +include_directories(lib/wolfssl) + if(NOT DEFINED WOLFBOOT_TARGET) message(FATAL_ERROR "WOLFBOOT_TARGET must be defined") else() @@ -620,6 +623,8 @@ if(NOT SPMATH AND NOT SPMATHALL) list(APPEND USER_SETTINGS USE_FAST_MATH) endif() +list(APPEND WOLFBOOT_DEFS WOLFSSL_USER_SETTINGS) + add_library(user_settings INTERFACE) target_compile_definitions(user_settings INTERFACE ${USER_SETTINGS} ${SIGN_OPTIONS}) @@ -699,7 +704,7 @@ configure_file(include/target.h.in ${CMAKE_CURRENT_BINARY_DIR}/target.h @ONLY) add_library(target INTERFACE) target_compile_definitions(target INTERFACE ${WOLFBOOT_DEFS}) -target_include_directories(target BEFORE INTERFACE ${CMAKE_CURRENT_BINARY_DIR}) +target_include_directories(target BEFORE INTERFACE ${CMAKE_CURRENT_BINARY_DIR} lib/wolfssl) set(KEYSTORE ${CMAKE_CURRENT_BINARY_DIR}/keystore.c) diff --git a/arch.mk b/arch.mk index 666276e8..54d0d513 100644 --- a/arch.mk +++ b/arch.mk @@ -253,7 +253,7 @@ ifeq ($(ARCH),ARM) CORTEX_A5=1 UPDATE_OBJS:=src/update_ram.o CFLAGS+=-DWOLFBOOT_DUALBOOT -DEXT_FLASH -DNAND_FLASH -fno-builtin -ffreestanding - #CFLAGS+=-DWOLFBOOT_USE_STDLIBC + CFLAGS+=-DWOLFBOOT_USE_STDLIBC endif ## Cortex CPU diff --git a/hal/sama5d3.c b/hal/sama5d3.c index 8c79916a..104c363d 100644 --- a/hal/sama5d3.c +++ b/hal/sama5d3.c @@ -78,7 +78,7 @@ static int division(uint32_t dividend, return 0; } -static uint32_t div(uint32_t dividend, uint32_t divisor) +static uint32_t div_u(uint32_t dividend, uint32_t divisor) { uint32_t quotient = 0; uint32_t remainder = 0; @@ -504,7 +504,7 @@ static void nand_read_info(void) nand_flash.bad_block_pos = (*(uint16_t *)(onfi_data + PARAMS_POS_FEATURES)) & 1; nand_flash.ext_page_len = *(uint16_t *)(onfi_data + PARAMS_POS_EXT_PARAM_PAGE_LEN); nand_flash.parameter_page = *(uint16_t *)(onfi_data + PARAMS_POS_PARAMETER_PAGE); - nand_flash.pages_per_block = div(nand_flash.block_size, nand_flash.page_size); + nand_flash.pages_per_block = div_u(nand_flash.block_size, nand_flash.page_size); nand_flash.pages_per_device = nand_flash.pages_per_block * nand_flash.block_count; nand_flash.oob_size = *(uint16_t *)(onfi_data + PARAMS_POS_OOBSIZE); nand_flash.revision = *(uint16_t *)(onfi_data + PARAMS_POS_REVISION); @@ -605,8 +605,8 @@ static int nand_check_bad_block(uint32_t block) int ext_flash_read(uintptr_t address, uint8_t *data, int len) { uint8_t buffer_page[NAND_FLASH_PAGE_SIZE]; - uint32_t block = div(address, nand_flash.block_size); /* The block where the address falls in */ - uint32_t page = div(address, nand_flash.page_size); /* The page where the address falls in */ + uint32_t block = div_u(address, nand_flash.block_size); /* The block where the address falls in */ + uint32_t page = div_u(address, nand_flash.page_size); /* The page where the address falls in */ uint32_t start_page_in_block = mod(page, nand_flash.pages_per_block); /* The start page within this block */ uint32_t in_block_offset = mod(address, nand_flash.block_size); /* The offset of the address within the block */ uint32_t remaining = nand_flash.block_size - in_block_offset; /* How many bytes remaining to read in the first block */ @@ -637,7 +637,7 @@ int ext_flash_read(uintptr_t address, uint8_t *data, int len) } while (ret < 0); /* Amount of pages to be read from this block */ - pages_to_read = div((sz + nand_flash.page_size - 1), nand_flash.page_size); + pages_to_read = div_u((sz + nand_flash.page_size - 1), nand_flash.page_size); if (pages_to_read * nand_flash.page_size > remaining) pages_to_read--; diff --git a/hal/sim.c b/hal/sim.c index b576b7a8..1adba014 100644 --- a/hal/sim.c +++ b/hal/sim.c @@ -378,7 +378,7 @@ void do_boot(const uint32_t *app_offset) wret = write(fd, app_offset, app_size); if (wret != app_size) { - wolfBoot_printf( "can't write test-app to memfd, address %p: fd %d rval %d errno %d\n", app_offset, fd, wret, errno); + wolfBoot_printf( "can't write test-app to memfd, address %p\n", app_offset); exit(-1); } wolfBoot_printf("Stored test-app to memfd, address %p (%zu bytes)\n", app_offset, wret); diff --git a/include/wolfboot/wolfboot.h b/include/wolfboot/wolfboot.h index 3870ed91..a44ad057 100644 --- a/include/wolfboot/wolfboot.h +++ b/include/wolfboot/wolfboot.h @@ -205,7 +205,7 @@ extern "C" { # define update_hash wc_Sha3Update # define final_hash wc_Sha3Final # define key_hash key_sha3_384 - typedef wc_sha3_384 wolfBoot_hash_t; + typedef wc_Sha3 wolfBoot_hash_t; # define HDR_HASH HDR_SHA3_384 #else # error "No valid hash algorithm defined!" diff --git a/src/elf.c b/src/elf.c index 26594ce3..2bbd90eb 100644 --- a/src/elf.c +++ b/src/elf.c @@ -48,7 +48,7 @@ #endif -#ifdef MMU +#if defined(MMU) || defined (WOLFBOOT_FSP) || defined (ARCH_PPC) /* Loader for elf32 or elf64 format program headers * Returns the entry point function */ @@ -181,7 +181,7 @@ int elf_hdr_size(const unsigned char *ehdr) } return sz; } - +#if !defined(MMU) && !defined(WOLFBOOT_FSP) && !defined(ARCH_PPC) int elf_store_image_scattered(const unsigned char *hdr, unsigned long *entry_out, int ext_flash) { const unsigned char *image; int is_elf32; @@ -274,6 +274,7 @@ int elf_store_image_scattered(const unsigned char *hdr, unsigned long *entry_out } return 0; } +#endif int elf_load_image(uint8_t *image, uintptr_t *entry, int ext_flash) diff --git a/src/image.c b/src/image.c index eb01bb8c..0814de8f 100644 --- a/src/image.c +++ b/src/image.c @@ -833,7 +833,7 @@ static int header_sha256(wc_Sha256 *sha256_ctx, struct wolfBoot_image *img) if (stored_sha_len != WOLFBOOT_SHA_DIGEST_SIZE) return -1; #ifdef WOLFBOOT_ENABLE_WOLFHSM_CLIENT - (void)wc_InitSha256_ex(&sha256_ctx, NULL, hsmClientDevIdHash); + (void)wc_InitSha256_ex(sha256_ctx, NULL, hsmClientDevIdHash); #else wc_InitSha256(sha256_ctx); #endif @@ -924,7 +924,7 @@ static int header_sha384(wc_Sha384 *sha384_ctx, struct wolfBoot_image *img) if (stored_sha_len != WOLFBOOT_SHA_DIGEST_SIZE) return -1; #ifdef WOLFBOOT_ENABLE_WOLFHSM_CLIENT - (void)wc_InitSha384_ex(&sha384_ctx, NULL, hsmClientDevIdHash); + (void)wc_InitSha384_ex(sha384_ctx, NULL, hsmClientDevIdHash); #else wc_InitSha384(sha384_ctx); #endif diff --git a/src/update_ram.c b/src/update_ram.c index d7a6a4d9..b5cef82c 100644 --- a/src/update_ram.c +++ b/src/update_ram.c @@ -271,7 +271,7 @@ backup_on_failure: #ifdef WOLFBOOT_ELF /* Load elf */ - if (elf_load_image((uint8_t*)load_address, (uintptr_t*)&load_address) != 0){ + if (elf_load_image_mmu((uint8_t*)load_address, (uintptr_t*)&load_address, NULL) != 0){ wolfBoot_printf("Invalid elf, falling back to raw binary\n"); } #endif diff --git a/tools/elf-parser/Makefile b/tools/elf-parser/Makefile index fd89e343..dc67c389 100644 --- a/tools/elf-parser/Makefile +++ b/tools/elf-parser/Makefile @@ -4,7 +4,7 @@ CC=gcc CFLAGS=-Wall -g -ggdb -CFLAGS+=-I../../include -DWOLFBOOT_ELF -DELF_PARSER -DPRINTF_ENABLED +CFLAGS+=-I../../include -DWOLFBOOT_ELF -DELF_PARSER -DPRINTF_ENABLED -DMMU -DARCH_FLASH_OFFSET=0 EXE=elf-parser LIBS= diff --git a/tools/elf-parser/elf-parser.c b/tools/elf-parser/elf-parser.c index a618b72e..cfa6f6bd 100644 --- a/tools/elf-parser/elf-parser.c +++ b/tools/elf-parser/elf-parser.c @@ -70,7 +70,7 @@ int main(int argc, char *argv[]) fclose(f); if (ret == 0) { - ret = elf_load_image(image, &entry); + ret = elf_load_image_mmu(image, &entry, NULL); } printf("Return %d, Load %p\n", ret, (void*)entry);