Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 13 additions & 18 deletions arch.mk
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,18 @@ ifeq ($(ARCH),PPC)
LDFLAGS+=-Wl,--gc-sections

OBJS+=src/boot_ppc_start.o src/boot_ppc.o

ifeq ($(SPMATH),1)
MATH_OBJS += ./lib/wolfssl/wolfcrypt/src/sp_c32.o
endif

ifneq ($(NO_ASM),1)
# Use the SHA256 and SP math all assembly accelerations
CFLAGS+=-DWOLFSSL_SP_PPC
CFLAGS+=-DWOLFSSL_PPC32_ASM -DWOLFSSL_PPC32_ASM_INLINE
#CFLAGS+=-DWOLFSSL_PPC32_ASM_SMALL
MATH_OBJS+=./lib/wolfssl/wolfcrypt/src/port/ppc32/ppc32-sha256-asm_c.o
endif
endif

ifeq ($(TARGET),kinetis)
Expand Down Expand Up @@ -788,12 +800,7 @@ ifeq ($(TARGET),nxp_t1024)
OBJS+=src/pci.o
CFLAGS+=-DWOLFBOOT_USE_PCI
UPDATE_OBJS:=src/update_ram.o
ifeq ($(SPMATH),1)
MATH_OBJS += ./lib/wolfssl/wolfcrypt/src/sp_c32.o
else
# Use the SP math all assembly accelerations
CFLAGS+=-DWOLFSSL_SP_PPC
endif

SPI_TARGET=nxp
OPTIMIZATION_LEVEL=0 # using default -Os causes issues with alignment
endif
Expand All @@ -811,12 +818,6 @@ ifeq ($(TARGET),nxp_t2080)
LDFLAGS+=-Wl,--as-needed # remove weak functions not used
UPDATE_OBJS:=src/update_ram.o
OBJS+=src/fdt.o
ifeq ($(SPMATH),1)
MATH_OBJS += ./lib/wolfssl/wolfcrypt/src/sp_c32.o
else
# Use the SP math all assembly accelerations
CFLAGS+=-DWOLFSSL_SP_PPC
endif
endif

ifeq ($(TARGET),nxp_p1021)
Expand All @@ -835,12 +836,6 @@ ifeq ($(TARGET),nxp_p1021)
# Use PPC stdlib for memcpy, etc.
#CFLAGS+=-DWOLFBOOT_USE_STDLIBC

ifeq ($(SPMATH),1)
MATH_OBJS += ./lib/wolfssl/wolfcrypt/src/sp_c32.o
else
# Use the SP math all assembly accelerations
CFLAGS+=-DWOLFSSL_SP_PPC
endif
SPI_TARGET=nxp
endif

Expand Down
6 changes: 4 additions & 2 deletions config/examples/nxp-p1021.config
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ SIGN?=ECC384
HASH?=SHA384
IMAGE_HEADER_SIZE?=512
DEBUG?=0
DEBUG_SYMBOLS?=1
DEBUG_UART?=1
VTOR?=1
CORTEX_M0?=0
Expand All @@ -16,12 +17,13 @@ ALLOW_DOWNGRADE?=0
NVM_FLASH_WRITEONCE?=0
WOLFBOOT_VERSION?=0
NO_MPU?=0
SPMATH?=0
SPMATHALL?=1
SPMATH?=1
SPMATHALL?=0
RAM_CODE?=0
DUALBANK_SWAP?=0
WOLFTPM?=0
ELF?=1
DEBUG_ELF?=0

# Flash Sector (Block) Size (16KB)
WOLFBOOT_SECTOR_SIZE=0x4000
Expand Down
11 changes: 7 additions & 4 deletions docs/Targets.md
Original file line number Diff line number Diff line change
Expand Up @@ -1990,20 +1990,23 @@ make DEBUG=1 wolfboot.bin
# OR
make wolfboot.bin

# Sign application
# Build test app
make test-app/image.bin

# Sign the ELF32 application
# 1=version (can be any 32-bit value)
./tools/keytools/sign \
IMAGE_HEADER_SIZE=512 ./tools/keytools/sign \
--ecc384 \
--sha384 \
test-app/image.bin \
test-app/image.elf \
wolfboot_signing_private_key.der \
1

./tools/bin-assemble/bin-assemble \
factory.bin \
0x0 hal/nxp_p1021_stage1.bin \
0x8000 wolfboot.bin \
0x200000 test-app/image.bin \
0x200000 test-app/image_v1_signed.bin \
0x01F00000 fsl_qe_ucode_1021_10_A.bin
```

Expand Down
42 changes: 42 additions & 0 deletions hal/nxp_p1021.c
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,48 @@ static void udelay(uint32_t delay_us)
wait_ticks(delay_us * DELAY_US);
}

#if 0 /* useful timer code */

uint64_t hal_timer_ms(void)
{
uint64_t val;
/* time base is updated every 8 CCB clocks */
uint64_t cntfrq = hal_get_bus_clk() / 8;
uint64_t cntpct = get_ticks();
val = (cntpct * 1000ULL) / cntfrq;
return val;
}

/* example usage */
//uint64_t start = hal_get_tick_count();
// do some work
//wolfBoot_printf("done (%lu ms)\n", (uint32_t)hal_elapsed_time_ms(start));

/* Calculate elapsed time in milliseconds, handling timer overflow properly */
uint64_t hal_elapsed_time_ms(uint64_t start_ticks)
{
uint64_t current_ticks, elapsed_ticks;
uint64_t cntfrq = hal_get_bus_clk() / 8;

current_ticks = get_ticks();

/* Handle timer overflow using unsigned arithmetic
* This works correctly even if the timer has rolled over,
* as long as the elapsed time is less than the full timer range
*/
elapsed_ticks = current_ticks - start_ticks;

/* Convert elapsed ticks to milliseconds */
return (elapsed_ticks * 1000ULL) / cntfrq;
}

/* Get current tick count for use with hal_elapsed_time_ms() */
uint64_t hal_get_tick_count(void)
{
return get_ticks();
}
#endif

/* ---- eSPI Driver ---- */
#ifdef ENABLE_ESPI
void hal_espi_init(uint32_t cs, uint32_t clock_hz, uint32_t mode)
Expand Down
1 change: 1 addition & 0 deletions hal/nxp_ppc.h
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,7 @@
/* Hardware Implementation-Dependent Registers */
#define SPRN_HID0 0x3F0
#define HID0_TBEN (1 << 14) /* Time base enable */
#define HID0_TBCLK (1 << 13) /* select clock: 0=every 8 ccb clocks, 1=rising edge of RTC */
#define HID0_ENMAS7 (1 << 7) /* Enable hot-wire update of MAS7 register */
#define HID0_EMCP (1 << 31) /* Enable machine check pin */

Expand Down
2 changes: 1 addition & 1 deletion include/elf.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ typedef struct elf64_program_header {
#define GET_E32(name) (is_elf32 ? GET32(e32->name) : GET32(e64->name))

typedef int (*elf_mmu_map_cb)(uint64_t, uint64_t, uint32_t);
int elf_load_image_mmu(uint8_t *image, uintptr_t *entry, elf_mmu_map_cb mmu_cb);
int elf_load_image_mmu(uint8_t *image, uintptr_t *pentry, elf_mmu_map_cb mmu_cb);
int elf_load_image(uint8_t *image, uintptr_t *entry, int is_ext);
int64_t elf_hdr_pht_combined_size(const unsigned char* ehdr);
int elf_open(const unsigned char *ehdr, int *is_elf32);
Expand Down
2 changes: 1 addition & 1 deletion lib/wolfssl
Submodule wolfssl updated 209 files
32 changes: 22 additions & 10 deletions src/elf.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ static int check_scatter_format(const unsigned char* ehdr, int is_elf32);
/* Loader for elf32 or elf64 format program headers
* Returns the entry point function
*/
int elf_load_image_mmu(uint8_t *image, uintptr_t *entry, elf_mmu_map_cb mmu_cb)
int elf_load_image_mmu(uint8_t *image, uintptr_t *pentry, elf_mmu_map_cb mmu_cb)
{
elf32_header* h32 = (elf32_header*)image;
elf64_header* h64 = (elf64_header*)image;
Expand Down Expand Up @@ -86,6 +86,9 @@ int elf_load_image_mmu(uint8_t *image, uintptr_t *entry, elf_mmu_map_cb mmu_cb)
is_elf32 ? 32 : 64, is_le ? "little" : "big");
#endif

/* set entry point */
*pentry = GET_H64(entry);

/* programs */
entry_off = image + GET_H32(ph_offset);
entry_size = GET_H16(ph_entry_size);
Expand Down Expand Up @@ -133,20 +136,29 @@ int elf_load_image_mmu(uint8_t *image, uintptr_t *entry, elf_mmu_map_cb mmu_cb)
}
}

memcpy((void*)(uintptr_t)vaddr, image + offset, file_size);
if (mem_size > file_size) {
memset((void*)(uintptr_t)(vaddr + file_size), 0,
mem_size - file_size);
/* confirm the entry won't clobber any of the headers */
if ((uint8_t*)vaddr + file_size < image ||
(uint8_t*)vaddr > (entry_off + entry_count * entry_size))
{
memcpy((void*)vaddr, image + offset, file_size);
if (mem_size > file_size) {
memset((void*)(uintptr_t)(vaddr + file_size), 0,
mem_size - file_size);
}
#ifdef ARCH_PPC
flush_cache(paddr, mem_size);
#endif
}
#ifdef DEBUG_ELF
else {
wolfBoot_printf("Section would collide with headers! Skipping\n");
}
#ifdef ARCH_PPC
flush_cache(paddr, mem_size);
#endif
#endif
#endif /* !ELF_PARSER */
}

*entry = GET_H64(entry);
#ifdef DEBUG_ELF
wolfBoot_printf("Entry point %p\r\n", (void*)*entry);
wolfBoot_printf("Entry point %p\r\n", (void*)*pentry);
#endif

return 0;
Expand Down
1 change: 0 additions & 1 deletion tools/keytools/user_settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,6 @@
#define NO_DES3
#define NO_PWDBASED
#define NO_WRITEV
#define NO_FILESYSTEM
#define NO_OLD_RNGNAME
#define NO_WOLFSSL_DIR
#define WOLFSSL_NO_SOCK
Expand Down
28 changes: 14 additions & 14 deletions tools/test.mk
Original file line number Diff line number Diff line change
Expand Up @@ -961,40 +961,40 @@ test-all: clean


test-size-all:
make test-size SIGN=NONE LIMIT=4860 NO_ARM_ASM=1
make test-size SIGN=NONE LIMIT=4824 NO_ARM_ASM=1
make keysclean
make test-size SIGN=ED25519 LIMIT=11448 NO_ARM_ASM=1
make test-size SIGN=ED25519 LIMIT=11428 NO_ARM_ASM=1
make keysclean
make test-size SIGN=ECC256 LIMIT=17988 NO_ARM_ASM=1
make test-size SIGN=ECC256 LIMIT=17968 NO_ARM_ASM=1
make clean
make test-size SIGN=ECC256 NO_ASM=1 LIMIT=13536 NO_ARM_ASM=1
make keysclean
make test-size SIGN=RSA2048 LIMIT=11272 NO_ARM_ASM=1
make test-size SIGN=RSA2048 LIMIT=11264 NO_ARM_ASM=1
make clean
make test-size SIGN=RSA2048 NO_ASM=1 LIMIT=11840 NO_ARM_ASM=1
make test-size SIGN=RSA2048 NO_ASM=1 LIMIT=11844 NO_ARM_ASM=1
make keysclean
make test-size SIGN=RSA4096 LIMIT=11556 NO_ARM_ASM=1
make test-size SIGN=RSA4096 LIMIT=11552 NO_ARM_ASM=1
make clean
make test-size SIGN=RSA4096 NO_ASM=1 LIMIT=12128 NO_ARM_ASM=1
make test-size SIGN=RSA4096 NO_ASM=1 LIMIT=12132 NO_ARM_ASM=1
make keysclean
make test-size SIGN=ECC384 LIMIT=17556 NO_ARM_ASM=1
make test-size SIGN=ECC384 LIMIT=17464 NO_ARM_ASM=1
make clean
make test-size SIGN=ECC384 NO_ASM=1 LIMIT=14924 NO_ARM_ASM=1
make test-size SIGN=ECC384 NO_ASM=1 LIMIT=14912 NO_ARM_ASM=1
make keysclean
make test-size SIGN=ED448 LIMIT=13464 NO_ARM_ASM=1
make test-size SIGN=ED448 LIMIT=13416 NO_ARM_ASM=1
make keysclean
make test-size SIGN=RSA3072 LIMIT=11408 NO_ARM_ASM=1
make test-size SIGN=RSA3072 LIMIT=11404 NO_ARM_ASM=1
make clean
make test-size SIGN=RSA3072 NO_ASM=1 LIMIT=11944 NO_ARM_ASM=1
make test-size SIGN=RSA3072 NO_ASM=1 LIMIT=11948 NO_ARM_ASM=1
make keysclean
make test-size SIGN=LMS LMS_LEVELS=2 LMS_HEIGHT=5 LMS_WINTERNITZ=8 \
WOLFBOOT_SMALL_STACK=0 IMAGE_SIGNATURE_SIZE=2644 \
IMAGE_HEADER_SIZE?=5288 LIMIT=7536 NO_ARM_ASM=1
IMAGE_HEADER_SIZE?=5288 LIMIT=7516 NO_ARM_ASM=1
make keysclean
make test-size SIGN=XMSS XMSS_PARAMS='XMSS-SHA2_10_256' \
IMAGE_SIGNATURE_SIZE=2500 IMAGE_HEADER_SIZE?=4096 \
LIMIT=8292 NO_ARM_ASM=1
make keysclean
make clean
make test-size SIGN=ML_DSA ML_DSA_LEVEL=2 LIMIT=20168 \
make test-size SIGN=ML_DSA ML_DSA_LEVEL=2 LIMIT=18866 \
IMAGE_SIGNATURE_SIZE=2420 IMAGE_HEADER_SIZE?=8192
Loading