Skip to content

Commit ccc0425

Browse files
committed
Add support for PowerPC 32-bit SHA256 assembly speedups. Minor fix for ELF loading to set entry point before copying sections (resolves issue with loading on top of current location). Rename elf_load_image_mmu argument entry to pentry to avoid confusion with GET_H64 macro's use of header member "entry".
1 parent 374d605 commit ccc0425

File tree

8 files changed

+75
-29
lines changed

8 files changed

+75
-29
lines changed

arch.mk

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -561,6 +561,19 @@ ifeq ($(ARCH),PPC)
561561
LDFLAGS+=-Wl,--gc-sections
562562

563563
OBJS+=src/boot_ppc_start.o src/boot_ppc.o
564+
565+
ifeq ($(SPMATH),1)
566+
MATH_OBJS += ./lib/wolfssl/wolfcrypt/src/sp_c32.o
567+
endif
568+
569+
ifneq ($(NO_ASM),1)
570+
# Use the SHA256 and SP math all assembly accelerations
571+
CFLAGS+=-DWOLFSSL_SP_PPC
572+
CFLAGS+=-DWOLFSSL_PPC32_ASM -DWOLFSSL_PPC32_ASM_INLINE
573+
#CFLAGS+=-DWOLFSSL_PPC32_ASM_SMALL
574+
#CFLAGS+=-DUSE_SLOW_SHA256
575+
OBJS+=./lib/wolfssl/wolfcrypt/src/port/ppc32/ppc32-sha256-asm_c.o
576+
endif
564577
endif
565578

566579
ifeq ($(TARGET),kinetis)
@@ -788,12 +801,7 @@ ifeq ($(TARGET),nxp_t1024)
788801
OBJS+=src/pci.o
789802
CFLAGS+=-DWOLFBOOT_USE_PCI
790803
UPDATE_OBJS:=src/update_ram.o
791-
ifeq ($(SPMATH),1)
792-
MATH_OBJS += ./lib/wolfssl/wolfcrypt/src/sp_c32.o
793-
else
794-
# Use the SP math all assembly accelerations
795-
CFLAGS+=-DWOLFSSL_SP_PPC
796-
endif
804+
797805
SPI_TARGET=nxp
798806
OPTIMIZATION_LEVEL=0 # using default -Os causes issues with alignment
799807
endif
@@ -811,12 +819,6 @@ ifeq ($(TARGET),nxp_t2080)
811819
LDFLAGS+=-Wl,--as-needed # remove weak functions not used
812820
UPDATE_OBJS:=src/update_ram.o
813821
OBJS+=src/fdt.o
814-
ifeq ($(SPMATH),1)
815-
MATH_OBJS += ./lib/wolfssl/wolfcrypt/src/sp_c32.o
816-
else
817-
# Use the SP math all assembly accelerations
818-
CFLAGS+=-DWOLFSSL_SP_PPC
819-
endif
820822
endif
821823

822824
ifeq ($(TARGET),nxp_p1021)
@@ -835,12 +837,6 @@ ifeq ($(TARGET),nxp_p1021)
835837
# Use PPC stdlib for memcpy, etc.
836838
#CFLAGS+=-DWOLFBOOT_USE_STDLIBC
837839

838-
ifeq ($(SPMATH),1)
839-
MATH_OBJS += ./lib/wolfssl/wolfcrypt/src/sp_c32.o
840-
else
841-
# Use the SP math all assembly accelerations
842-
CFLAGS+=-DWOLFSSL_SP_PPC
843-
endif
844840
SPI_TARGET=nxp
845841
endif
846842

config/examples/nxp-p1021.config

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ SIGN?=ECC384
44
HASH?=SHA384
55
IMAGE_HEADER_SIZE?=512
66
DEBUG?=0
7+
DEBUG_SYMBOLS?=1
78
DEBUG_UART?=1
89
VTOR?=1
910
CORTEX_M0?=0
@@ -16,12 +17,13 @@ ALLOW_DOWNGRADE?=0
1617
NVM_FLASH_WRITEONCE?=0
1718
WOLFBOOT_VERSION?=0
1819
NO_MPU?=0
19-
SPMATH?=0
20-
SPMATHALL?=1
20+
SPMATH?=1
21+
SPMATHALL?=0
2122
RAM_CODE?=0
2223
DUALBANK_SWAP?=0
2324
WOLFTPM?=0
2425
ELF?=1
26+
DEBUG_ELF?=0
2527

2628
# Flash Sector (Block) Size (16KB)
2729
WOLFBOOT_SECTOR_SIZE=0x4000

docs/Targets.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1990,20 +1990,23 @@ make DEBUG=1 wolfboot.bin
19901990
# OR
19911991
make wolfboot.bin
19921992
1993-
# Sign application
1993+
# Build test app
1994+
make test-app/image.bin
1995+
1996+
# Sign the ELF32 application
19941997
# 1=version (can be any 32-bit value)
1995-
./tools/keytools/sign \
1998+
IMAGE_HEADER_SIZE=512 ./tools/keytools/sign \
19961999
--ecc384 \
19972000
--sha384 \
1998-
test-app/image.bin \
2001+
test-app/image.elf \
19992002
wolfboot_signing_private_key.der \
20002003
1
20012004
20022005
./tools/bin-assemble/bin-assemble \
20032006
factory.bin \
20042007
0x0 hal/nxp_p1021_stage1.bin \
20052008
0x8000 wolfboot.bin \
2006-
0x200000 test-app/image.bin \
2009+
0x200000 test-app/image_v1_signed.bin \
20072010
0x01F00000 fsl_qe_ucode_1021_10_A.bin
20082011
```
20092012

hal/nxp_p1021.c

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,48 @@ static void udelay(uint32_t delay_us)
514514
wait_ticks(delay_us * DELAY_US);
515515
}
516516

517+
#if 0 /* useful timer code */
518+
519+
uint64_t hal_timer_ms(void)
520+
{
521+
uint64_t val;
522+
/* time base is updated every 8 CCB clocks */
523+
uint64_t cntfrq = hal_get_bus_clk() / 8;
524+
uint64_t cntpct = get_ticks();
525+
val = (cntpct * 1000ULL) / cntfrq;
526+
return val;
527+
}
528+
529+
/* example usage */
530+
//uint64_t start = hal_get_tick_count();
531+
// do some work
532+
//wolfBoot_printf("done (%lu ms)\n", (uint32_t)hal_elapsed_time_ms(start));
533+
534+
/* Calculate elapsed time in milliseconds, handling timer overflow properly */
535+
uint64_t hal_elapsed_time_ms(uint64_t start_ticks)
536+
{
537+
uint64_t current_ticks, elapsed_ticks;
538+
uint64_t cntfrq = hal_get_bus_clk() / 8;
539+
540+
current_ticks = get_ticks();
541+
542+
/* Handle timer overflow using unsigned arithmetic
543+
* This works correctly even if the timer has rolled over,
544+
* as long as the elapsed time is less than the full timer range
545+
*/
546+
elapsed_ticks = current_ticks - start_ticks;
547+
548+
/* Convert elapsed ticks to milliseconds */
549+
return (elapsed_ticks * 1000ULL) / cntfrq;
550+
}
551+
552+
/* Get current tick count for use with hal_elapsed_time_ms() */
553+
uint64_t hal_get_tick_count(void)
554+
{
555+
return get_ticks();
556+
}
557+
#endif
558+
517559
/* ---- eSPI Driver ---- */
518560
#ifdef ENABLE_ESPI
519561
void hal_espi_init(uint32_t cs, uint32_t clock_hz, uint32_t mode)

hal/nxp_ppc.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,7 @@
498498
/* Hardware Implementation-Dependent Registers */
499499
#define SPRN_HID0 0x3F0
500500
#define HID0_TBEN (1 << 14) /* Time base enable */
501+
#define HID0_TBCLK (1 << 13) /* select clock: 0=every 8 ccb clocks, 1=rising edge of RTC */
501502
#define HID0_ENMAS7 (1 << 7) /* Enable hot-wire update of MAS7 register */
502503
#define HID0_EMCP (1 << 31) /* Enable machine check pin */
503504

include/elf.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ typedef struct elf64_program_header {
166166
#define GET_E32(name) (is_elf32 ? GET32(e32->name) : GET32(e64->name))
167167

168168
typedef int (*elf_mmu_map_cb)(uint64_t, uint64_t, uint32_t);
169-
int elf_load_image_mmu(uint8_t *image, uintptr_t *entry, elf_mmu_map_cb mmu_cb);
169+
int elf_load_image_mmu(uint8_t *image, uintptr_t *pentry, elf_mmu_map_cb mmu_cb);
170170
int elf_load_image(uint8_t *image, uintptr_t *entry, int is_ext);
171171
int64_t elf_hdr_pht_combined_size(const unsigned char* ehdr);
172172
int elf_open(const unsigned char *ehdr, int *is_elf32);

lib/wolfssl

Submodule wolfssl updated 199 files

src/elf.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ static int check_scatter_format(const unsigned char* ehdr, int is_elf32);
5454
/* Loader for elf32 or elf64 format program headers
5555
* Returns the entry point function
5656
*/
57-
int elf_load_image_mmu(uint8_t *image, uintptr_t *entry, elf_mmu_map_cb mmu_cb)
57+
int elf_load_image_mmu(uint8_t *image, uintptr_t *pentry, elf_mmu_map_cb mmu_cb)
5858
{
5959
elf32_header* h32 = (elf32_header*)image;
6060
elf64_header* h64 = (elf64_header*)image;
@@ -86,6 +86,9 @@ int elf_load_image_mmu(uint8_t *image, uintptr_t *entry, elf_mmu_map_cb mmu_cb)
8686
is_elf32 ? 32 : 64, is_le ? "little" : "big");
8787
#endif
8888

89+
/* set entry point */
90+
*pentry = GET_H64(entry);
91+
8992
/* programs */
9093
entry_off = image + GET_H32(ph_offset);
9194
entry_size = GET_H16(ph_entry_size);
@@ -144,9 +147,8 @@ int elf_load_image_mmu(uint8_t *image, uintptr_t *entry, elf_mmu_map_cb mmu_cb)
144147
#endif
145148
}
146149

147-
*entry = GET_H64(entry);
148150
#ifdef DEBUG_ELF
149-
wolfBoot_printf("Entry point %p\r\n", (void*)*entry);
151+
wolfBoot_printf("Entry point %p\r\n", (void*)*pentry);
150152
#endif
151153

152154
return 0;

0 commit comments

Comments
 (0)