Skip to content

Commit db15f9b

Browse files
dgarskedanielinux
authored andcommitted
Further NXP P1021 fixes and improvements:
* Added ELF32 and ELF64 loader support (config `ELF=1` or build option `WOLFBOOT_ELF`). * Add ELF support to `update_ram.c` loader. * Add support for loading entire flash image to RAM when `EXT_FLASH=1` and `NO_XIP=1` (or `WOLFBOOT_USE_RAMBOOT`). * Added QUICC Engine support to load microcode and enable. * Add multiple core support for NXP P1021. * Fixes to resolve first stage boot ROM relocation. - Implemented temporary workaround to resolve stack traps. * Added PPC GOT relocation support. * Fix for the PPC `isr_empty` handler address. * Fix to allow stack to use DDR by having assembly setup DDR TLB. After relocating wolfBoot use stack on DDR. * Cleanup wolfBoot output. - Only remove extra .bin/.elf created unless `make distclean` is used. - Don't output the key grep test (only check result). - Adjust build order (first stage, wolfboot, test app, key, sign test app and factory). - Fix to make sure linker script is rebuilt before objects. Sample NXP P1021 Output: ``` Relocating BOOT ROM to DDR Loading wolfBoot to DDR Jumping to full wolfBoot wolfBoot HAL Init Flash Init: Ret 0, ID 0x76207620 QE: Length 63732, Count 1 QE: uploading 'Microcode for P1021 r1.0' version 0.0.1 QE: Traps 0 MP: Starting core 2 (spin table 0xFFFFF240) Versions: Boot 1, Update 0 Trying Boot partition at 0x200000 Loading header 512 bytes to 0x1DFFFE00 Loading image 3170724 bytes to 0x1E000000 Image size 3170724 Firmware Valid Loading elf at 0x1E000000 Found valid elf32 (big endian) Booting at 0x6000 ```
1 parent a56e225 commit db15f9b

31 files changed

Lines changed: 2227 additions & 548 deletions

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ tools/test-update-server/server
9898
tools/uart-flash-server/ufserver
9999
tools/unit-tests/unit-parser
100100
tools/bin-assemble/bin-assemble
101+
tools/elf-parser/elf-parser
101102
config/*.ld
102103

103104
# Generated confiuguration file

Makefile

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ $(PRIVATE_KEY):
163163
$(Q)(test $(SIGN) = NONE) && (echo "// SIGN=NONE" > src/keystore.c) || true
164164

165165
keytools:
166-
@$(MAKE) -C tools/keytools clean
166+
@$(MAKE) -C tools/keytools -s clean
167167
@$(MAKE) -C tools/keytools
168168

169169
test-app/image_v1_signed.bin: $(BOOT_IMG)
@@ -175,28 +175,28 @@ test-app/image.elf: wolfboot.elf
175175
$(Q)$(MAKE) -C test-app WOLFBOOT_ROOT="$(WOLFBOOT_ROOT)" image.elf
176176
$(Q)$(SIZE) test-app/image.elf
177177

178-
internal_flash.dd: test-app/image_v1_signed.bin wolfboot.elf $(BINASSEMBLE)
178+
internal_flash.dd: $(BINASSEMBLE) wolfboot.elf test-app/image_v1_signed.bin
179179
@echo "\t[MERGE] internal_flash.dd"
180180
$(Q)dd if=/dev/zero bs=1 count=$$(($(WOLFBOOT_SECTOR_SIZE))) > /tmp/swap
181181
$(Q)$(BINASSEMBLE) $@ 0 test-app/image_v1_signed.bin \
182182
$(WOLFBOOT_PARTITION_SIZE) /tmp/swap \
183183
$$(($(WOLFBOOT_PARTITION_SIZE)*2)) /tmp/swap
184184

185-
factory.bin: $(BOOT_IMG) wolfboot.bin $(PRIVATE_KEY) test-app/image_v1_signed.bin $(BINASSEMBLE)
185+
factory.bin: $(BINASSEMBLE) wolfboot.bin $(BOOT_IMG) $(PRIVATE_KEY) test-app/image_v1_signed.bin
186186
@echo "\t[MERGE] $@"
187187
$(Q)$(BINASSEMBLE) $@ \
188188
$(WOLFBOOT_ORIGIN) wolfboot.bin \
189189
$(WOLFBOOT_PARTITION_BOOT_ADDRESS) test-app/image_v1_signed.bin
190190

191-
factory_wstage1.bin: $(BOOT_IMG) wolfboot.bin $(PRIVATE_KEY) test-app/image_v1_signed.bin $(BINASSEMBLE) stage1/loader_stage1.bin
191+
factory_wstage1.bin: $(BINASSEMBLE) stage1/loader_stage1.bin wolfboot.bin $(BOOT_IMG) $(PRIVATE_KEY) test-app/image_v1_signed.bin
192192
@echo "\t[MERGE] $@"
193193
$(Q)$(BINASSEMBLE) $@ \
194194
$(WOLFBOOT_STAGE1_FLASH_ADDR) stage1/loader_stage1.bin \
195195
$(WOLFBOOT_ORIGIN) wolfboot.bin \
196196
$(WOLFBOOT_PARTITION_BOOT_ADDRESS) test-app/image_v1_signed.bin
197197

198-
wolfboot.elf: include/target.h $(OBJS) $(LSCRIPT) FORCE
199-
$(Q)(test $(SIGN) = NONE) || (grep $(SIGN) src/keystore.c) || (echo "Key mismatch: please run 'make distclean' to remove all keys if you want to change algorithm" && false)
198+
wolfboot.elf: include/target.h $(LSCRIPT) $(OBJS) $(BINASSEMBLE) FORCE
199+
$(Q)(test $(SIGN) = NONE) || (grep -q $(SIGN) src/keystore.c) || (echo "Key mismatch: please run 'make distclean' to remove all keys if you want to change algorithm" && false)
200200
@echo "\t[LD] $@"
201201
@echo $(OBJS)
202202
$(Q)$(LD) $(LDFLAGS) $(LSCRIPT_FLAGS) $(LD_START_GROUP) $(OBJS) $(LD_END_GROUP) -o $@
@@ -236,28 +236,28 @@ keys: $(PRIVATE_KEY)
236236

237237
clean:
238238
$(Q)rm -f src/*.o hal/*.o hal/spi/*.o lib/wolfssl/wolfcrypt/src/*.o test-app/*.o
239-
$(Q)rm -f *.bin *.elf wolfboot.map test-update.rom *.hex $(LSCRIPT)
240-
$(Q)$(MAKE) -C test-app clean
241-
$(Q)$(MAKE) -C tools/check_config clean
242-
$(Q)$(MAKE) -C stage1 clean
239+
$(Q)rm -f wolfboot.bin wolfboot.elf wolfboot.map test-update.rom *.hex $(LSCRIPT)
240+
$(Q)rm -f $(MAIN_TARGET)
241+
$(Q)$(MAKE) -C test-app -s clean
242+
$(Q)$(MAKE) -C tools/check_config -s clean
243+
$(Q)$(MAKE) -C stage1 -s clean
243244

244245
utilsclean: clean
245-
$(Q)$(MAKE) -C tools/keytools clean
246-
$(Q)$(MAKE) -C tools/delta clean
247-
$(Q)$(MAKE) -C tools/bin-assemble clean
248-
$(Q)$(MAKE) -C tools/check_config clean
249-
$(Q)$(MAKE) -C tools/test-expect-version clean
250-
$(Q)$(MAKE) -C tools/test-update-server clean
251-
$(Q)$(MAKE) -C tools/uart-flash-server clean
252-
$(Q)$(MAKE) -C tools/unit-tests clean
246+
$(Q)$(MAKE) -C tools/keytools -s clean
247+
$(Q)$(MAKE) -C tools/delta -s clean
248+
$(Q)$(MAKE) -C tools/bin-assemble -s clean
249+
$(Q)$(MAKE) -C tools/elf-parser -s clean
250+
$(Q)$(MAKE) -C tools/check_config -s clean
251+
$(Q)$(MAKE) -C tools/test-expect-version -s clean
252+
$(Q)$(MAKE) -C tools/test-update-server -s clean
253+
$(Q)$(MAKE) -C tools/uart-flash-server -s clean
254+
$(Q)$(MAKE) -C tools/unit-tests -s clean
253255

254256
keysclean: clean
255-
@rm -f *.pem *.der tags ./src/*_pub_key.c ./src/keystore.c include/target.h
256-
257-
257+
$(Q)rm -f *.pem *.der tags ./src/*_pub_key.c ./src/keystore.c include/target.h
258258

259259
distclean: clean keysclean utilsclean
260-
260+
$(Q)rm -f *.bin *.elf
261261

262262
include/target.h: $(TARGET_H_TEMPLATE) FORCE
263263
@cat $(TARGET_H_TEMPLATE) | \
@@ -280,6 +280,9 @@ tools/delta/bmdiff: FORCE
280280
delta-test: FORCE
281281
$(Q)$(MAKE) -C tools/delta $@
282282

283+
elf-parser:
284+
@$(MAKE) -C tools/elf-parser -s clean
285+
@$(MAKE) -C tools/elf-parser
283286

284287
config: FORCE
285288
$(MAKE) -C config

arch.mk

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ endif
216216
ifeq ($(ARCH),PPC)
217217
CROSS_COMPILE?=powerpc-linux-gnu-
218218
LDFLAGS+=-Wl,--build-id=none
219+
CFLAGS+=-DARCH_PPC
219220

220221
ifeq ($(DEBUG_UART),0)
221222
CFLAGS+=-fno-builtin-printf
@@ -324,6 +325,10 @@ ifeq ($(TARGET),nxp_p1021)
324325
LDFLAGS+=$(ARCH_FLAGS)
325326
LDFLAGS+=-Wl,--as-needed # remove weak functions not used
326327
UPDATE_OBJS:=src/update_ram.o
328+
UPDATE_OBJS+=src/boot_ppc_mp.o
329+
330+
# Use PPC stdlib for memcpy, etc.
331+
#CFLAGS+=-DWOLFBOOT_USE_STDLIBC
327332

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

config/examples/nxp-p1021.config

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ SPMATH?=0
2020
SPMATHALL?=1
2121
RAM_CODE?=0
2222
DUALBANK_SWAP?=0
23-
WOLFTPM?=1
23+
WOLFTPM?=0
24+
ELF?=1
2425

2526
# Flash Sector (Block) Size (16KB)
2627
WOLFBOOT_SECTOR_SIZE=0x4000
@@ -33,7 +34,7 @@ WOLFBOOT_STAGE1_SIZE=0x1000
3334
BOOTLOADER_PARTITION_SIZE=0x20000
3435

3536
# Application Partition Size (16MB)
36-
WOLFBOOT_PARTITION_SIZE?=0x1000000
37+
WOLFBOOT_PARTITION_SIZE=0x1000000
3738

3839

3940
## NAND Flash Offsets ##
@@ -42,22 +43,22 @@ WOLFBOOT_STAGE1_FLASH_ADDR=0x0
4243
# Location in Flash for wolfBoot
4344
WOLFBOOT_ORIGIN=0x8000
4445
# Location in Flash for Application Partition
45-
WOLFBOOT_PARTITION_BOOT_ADDRESS?= 0x200000
46+
WOLFBOOT_PARTITION_BOOT_ADDRESS= 0x200000
4647
# Location in Flash for Update Partition
47-
WOLFBOOT_PARTITION_UPDATE_ADDRESS?=0x1200000
48+
WOLFBOOT_PARTITION_UPDATE_ADDRESS=0x1200000
4849
# Location in Flash for temporary sector used during updates
49-
WOLFBOOT_PARTITION_SWAP_ADDRESS?= 0x2200000
50+
WOLFBOOT_PARTITION_SWAP_ADDRESS= 0x2200000
5051

5152
## Loader Destinations (DDR) ##
5253

5354
# Address in RAM to load stage 1 loader (can't be 0x0)
54-
WOLFBOOT_STAGE1_BASE_ADDR=0x4000
55+
WOLFBOOT_STAGE1_BASE_ADDR=0x8000
5556

56-
# Address in RAM to load wolfBoot
57-
WOLFBOOT_STAGE1_LOAD_ADDR=0x8000
57+
# Address in RAM to load wolfBoot (end of DDR at 512MB-1MB)
58+
WOLFBOOT_STAGE1_LOAD_ADDR=0x1FF00000
5859

5960
# Address in RAM to load application partition (at 480MB)
60-
WOLFBOOT_LOAD_ADDRESS?=0x1E000000
61+
WOLFBOOT_LOAD_ADDRESS=0x1E000000
6162

62-
# Read from flash in blocks of 512 (align with NAND page size)
63-
CFLAGS_EXTRA+=-DWOLFBOOT_SHA_BLOCK_SIZE=512
63+
# Read from flash (must be multiple of NAND page size 512 bytes)
64+
CFLAGS_EXTRA+=-DWOLFBOOT_SHA_BLOCK_SIZE=4096

docs/Targets.md

Lines changed: 42 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ This README describes configuration of supported targets.
1010
* [NXP LPC54xxx](#nxp-lpc54xxx)
1111
* [NXP iMX-RT](#nxp-imx-rt)
1212
* [NXP Kinetis](#nxp-kinetis)
13-
* [NXP P1021 PPC](#nxp-p1021-ppc)
14-
* [NXP T2080 PPC](#nxp-t2080-ppc)
13+
* [NXP P1021 PPC](#nxp-qoriq-p1021-ppc)
14+
* [NXP T2080 PPC](#nxp-qoriq-t2080-ppc)
1515
* [Qemu x86-64 UEFI](#qemu-x86-64-uefi)
1616
* [SiFive HiFive1 RISC-V](#sifive-hifive1-risc-v)
1717
* [STM32F4](#stm32f4)
@@ -1113,28 +1113,55 @@ A loader must reside in the 4KB page to handle early startup including DDR and t
11131113

11141114
A first stage loader is required to load the wolfBoot image into DDR for execution. This is because only 4KB of code space is available on boot. The stage 1 loader must also copy iteslf from the FCM buffer to DDR (or L2SRAM) to allow using of the eLBC to read NAND blocks.
11151115

1116-
### Building wolfBoot for NXP P1021 PPC
1117-
1118-
By default wolfBoot will use `powerpc-linux-gnu-` cross-compiler prefix. These tools can be installed with the Debian package `gcc-powerpc-linux-gnu` (`sudo apt install gcc-powerpc-linux-gnu`).
1119-
1120-
The `make` creates a `factory_wstage1.bin` image that can be programmed at `0x00000000`
1121-
1122-
```
1123-
cp ./config/examples/nxp-p1021.config .config
1124-
make keytools
1125-
make clean && make
1126-
```
1127-
11281116
#### Flash Layout for NXP P1021 PPC (default)
11291117

11301118
| File | NAND offset |
11311119
| ---------------------------- | ----------- |
11321120
| stage1/loader_stage1.bin | 0x00000000 |
1133-
| wolfboot.bin | 0x00004000 |
1121+
| wolfboot.bin | 0x00008000 |
11341122
| test-app/image_v1_signed.bin | 0x00200000 |
11351123
| update | 0x01200000 |
1124+
| fsl_qe_ucode_1021_10_A.bin | 0x01F00000 |
11361125
| swap block | 0x02200000 |
11371126

1127+
### Building wolfBoot for NXP P1021 PPC
1128+
1129+
By default wolfBoot will use `powerpc-linux-gnu-` cross-compiler prefix. These tools can be installed with the Debian package `gcc-powerpc-linux-gnu` (`sudo apt install gcc-powerpc-linux-gnu`).
1130+
1131+
The `make` creates a `factory_wstage1.bin` image that can be programmed at `0x00000000`, that include the first stage loader, wolfBoot and a signed test application.
1132+
1133+
To build the first stage load, wolfBoot, sign a custom application and assembly a single factory image use:
1134+
1135+
```
1136+
cp config/examples/nxp-p1021.config .config
1137+
1138+
# build the C version of the key tools (instead of using the python ones)
1139+
make keytools
1140+
1141+
make clean
1142+
make stage1
1143+
1144+
# Build wolfBoot (with or without DEBUG)
1145+
make DEBUG=1 wolfboot.bin
1146+
# OR
1147+
make wolfboot.bin
1148+
1149+
# Sign application
1150+
# 1=version (can be any 32-bit value)
1151+
./tools/keytools/sign \
1152+
--ecc384 \
1153+
--sha384 \
1154+
test-app/image.bin \
1155+
wolfboot_signing_private_key.der \
1156+
1
1157+
1158+
./tools/bin-assemble/bin-assemble \
1159+
factory.bin \
1160+
0x0 hal/nxp_p1021_stage1.bin \
1161+
0x8000 wolfboot.bin \
1162+
0x200000 test-app/image.bin \
1163+
0x01F00000 fsl_qe_ucode_1021_10_A.bin
1164+
```
11381165

11391166
### Debugging NXP P1021 PPC
11401167

0 commit comments

Comments
 (0)