Skip to content

Commit 6af52ad

Browse files
authored
Merge pull request #37 from danielinux/aarch64
wolfBoot Aarch64 support (Xilinx Zynq and Raspberry Pi)
2 parents 50c1cb7 + cd209e9 commit 6af52ad

59 files changed

Lines changed: 4696 additions & 437 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,7 @@ src/rsa2048_pub_key.c
5656
src/rsa4096_pub_key.c
5757

5858
# keygen binaries
59-
tools/ed25519/ed25519_sign
60-
tools/ed25519/ed25519_keygen
61-
tools/ecc256/ecc256_sign
62-
tools/ecc256/ecc256_keygen
59+
tools/keytools/sign
6360

6461
# Vim swap files
6562
.*.swp
@@ -84,3 +81,6 @@ config/*.ld
8481

8582
# Generated confiuguration file
8683
.config
84+
.vs
85+
*.filters
86+
*.user

IDE/XilinxSDK/.cproject

Lines changed: 232 additions & 0 deletions
Large diffs are not rendered by default.

IDE/XilinxSDK/.project

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>efuse_wolfboot</name>
4+
<comment>Created by SDK v2018.2. standalone_bsp_0 - psu_cortexa53_0</comment>
5+
<projects>
6+
<project>standalone_bsp_0</project>
7+
</projects>
8+
<buildSpec>
9+
<buildCommand>
10+
<name>org.eclipse.cdt.managedbuilder.core.genmakebuilder</name>
11+
<arguments>
12+
</arguments>
13+
</buildCommand>
14+
<buildCommand>
15+
<name>org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder</name>
16+
<triggers>full,incremental,</triggers>
17+
<arguments>
18+
</arguments>
19+
</buildCommand>
20+
</buildSpec>
21+
<natures>
22+
<nature>org.eclipse.cdt.core.cnature</nature>
23+
<nature>org.eclipse.cdt.managedbuilder.core.managedBuildNature</nature>
24+
<nature>org.eclipse.cdt.managedbuilder.core.ScannerConfigNature</nature>
25+
</natures>
26+
</projectDescription>

IDE/XilinxSDK/README.md

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
# Xilinx SDK wolfBoot Project
2+
3+
To use this example project:
4+
1. Copy `.cproject` and `.project` into the wolfBoot root.
5+
2. From the Xilinx SDK Import wolfBoot using "Import" -> "Existing Projects into Workspace".
6+
7+
## wolfBoot Configuration
8+
9+
A build settings template for Zynq UltraScale+ can be found here `./config/examples/zynqmp.config`. This file can be copied to wolfBoot root as `.config` for building from the command line. These template settings are also in this `.cproject` as preprocessor macros. These settings are loaded into the `target.h.in` template by the wolfBoot `make`. If not using the built-in make then the following defines will need to be manually created in `target.h`:
10+
11+
```
12+
#define WOLFBOOT_SECTOR_SIZE 0x20000
13+
#define WOLFBOOT_PARTITION_BOOT_ADDRESS 0x800000
14+
#define WOLFBOOT_LOAD_ADDRESS 0x10000000
15+
#define WOLFBOOT_PARTITION_SIZE 0x2A00000
16+
#define WOLFBOOT_PARTITION_UPDATE_ADDRESS 0x3A00000
17+
#define WOLFBOOT_PARTITION_SWAP_ADDRESS 0x63E0000
18+
19+
#define WOLFBOOT_DTS_BOOT_ADDRESS 0x7E0000
20+
#define WOLFBOOT_DTS_UPDATE_ADDRESS 0x39E0000
21+
#define WOLFBOOT_LOAD_DTS_ADDRESS 0x11800000
22+
```
23+
24+
Note: If not using Position Independent Code (PIC) the linker script `ldscript.ld` must have the start address offset to match the `WOLFBOOT_LOAD_ADDRESS`.
25+
26+
## Signing Example
27+
28+
```sh
29+
python3 ./tools/keytools/sign.py --rsa4096 --sha3 ../helloworld/Debug/helloworld.elf ./rsa4096.der 1
30+
```
31+
32+
## Bootgen
33+
34+
Xilinx uses a `bootgen` tool for generating a boot binary image that has Xilinx headers, which the FSBL (First Stage Boot Loader) understands. See the `boot.bif` and `boot_auth.bif` as examples.
35+
36+
* Use "partition_owner=uboot" to prevent a partition from being loaded into RAM.
37+
* Use "offset=" option to place the application into a specific location in flash.
38+
* Use "load=" option to have FSBL load into specific location in RAM.
39+
40+
### Adding RSA Authentication
41+
42+
1. Generate keys:
43+
* `bootgen.exe -generate_keys auth pem -arch zynqmp -image boot.bif`
44+
2. Create hash for primary key:
45+
* `bootgen.exe -image boot.bif -arch zynqmp -w -o i BOOT.BIN -efuseppkbits ppkf_hash.txt`
46+
3. Import example project for programming eFuses:
47+
* New BSP project (program efuses , ZCU102_hw_platform, standalone, CPU: PSU_cortexa53_0)
48+
* Goto Xilinx Board Support Packet Settings.
49+
* Scroll down to Supported Libraries and Check the xiskey libray
50+
* In the system.mss pane, scroll down to Libraries and click Import Examples.
51+
* Check the xilskey_esfuseps_zynqmp_example
52+
4. Edit `xilskey_efuseps_zynqmp_input.h`
53+
* 433 `#define XSK_EFUSEPS_WRITE_PPK0_HASH TRUE`
54+
* 453 `#define XSK_EFUSEPS_PPK0_IS_SHA3 TRUE`
55+
* 454 `#define XSK_EFUSEPS_PPK0_HASH "0000000000000000000000000000000000000000000000000000000000000000" /* from ppkf_hash.txt */``
56+
5. Update boot.bif (see boot_auth.bif)
57+
58+
```
59+
[auth_params] ppk_select=0; spk_id=0x00000000
60+
[pskfile] pskf.pem
61+
[sskfile] sskf.pem
62+
authentication=rsa
63+
```
64+
65+
6. Build “boot.bin” image:
66+
* `bootgen.exe -image boot.bif -arch zynqmp -o i BOOT.BIN -w`
67+
68+
Note: To generate a report of a boot.bin use the `bootgen_utility`:
69+
`bootgen_utility -arch zynqmp -bin boot.bin -out boot.bin.txt`
70+
71+
### References:
72+
* [ZAPP1319](https://www.xilinx.com/support/documentation/application_notes/xapp1319-zynq-usp-prog-nvm.pdf): Programming BBRAM and eFUSEs
73+
* [UG1283](https://www.xilinx.com/support/documentation/sw_manuals/xilinx2018_2/ug1283-bootgen-user-guide.pdf): Bootgen User Guide

IDE/XilinxSDK/boot.bif

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Boot BIF example for wolfBoot with signed Hello World
2+
// Note: "partition_owner=uboot" prevents partition from being loaded to RAM
3+
the_ROM_image:
4+
{
5+
[bootloader, destination_cpu=a53-0] zynqmp_fsbl.elf
6+
[destination_cpu=pmu] pmufw.elf
7+
[destination_device=pl] system.bit
8+
[destination_cpu=a53-0, exception_level=el-3, trustzone] bl31.elf
9+
[destination_cpu=a53-0, exception_level=el-2] wolfboot.elf
10+
[destination_cpu=a53-0, offset=0x800000, partition_owner=uboot] helloworld_v1_signed.bin
11+
}

IDE/XilinxSDK/boot_auth.bif

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Boot BIF example with Xilinx Secure Boot authentication and wolfBoot
2+
the_ROM_image:
3+
{
4+
// Boot Header Authentication Enable
5+
[fsbl_config] bh_auth_enable
6+
7+
// Use the primary public key 0 and secondary public key id 0
8+
[auth_params] ppk_select=0; spk_id=0x00000000
9+
10+
// primary and secondary secret (private) keys
11+
[pskfile] pskf.pem
12+
[sskfile] sskf.pem
13+
14+
[bootloader, destination_cpu=a53-0, authentication=rsa] zynqmp_fsbl.elf
15+
[destination_cpu=pmu, authentication=rsa] pmufw.elf
16+
[destination_device=pl, authentication=rsa] system.bit
17+
[destination_cpu=a53-0, exception_level=el-3, trustzone, authentication=rsa] bl31.elf
18+
[destination_cpu=a53-0, authentication=rsa, load=0x11800000] system.dtb
19+
20+
// ARM Device Tree (loaded to RAM at 0x11800000 by wolfBoot)
21+
[ destination_cpu=a53-0, authentication=rsa, offset=0x007E0000, partition_owner=uboot] system.dtb
22+
23+
// Second Stage wolfBoot Bootloader (in RAM at 0x0)
24+
[destination_cpu=a53-0, exception_level=el-2, authentication=rsa] wolfboot.elf
25+
26+
// Kernel / Application (load to RAM at 0x10000000 by wolfBoot)
27+
// Using partition_owner=uboot prevents FSBL from loading to RAM
28+
[destination_cpu=a53-0, offset=0x800000, partition_owner=uboot] kernel.ui
29+
}

Makefile

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ OBJS:= \
1919
./src/libwolfboot.o
2020
WOLFCRYPT_OBJS:=
2121
PUBLIC_KEY_OBJS:=
22+
UPDATE_OBJS:=
2223

2324
ifeq ($(SIGN),RSA4096)
2425
SPMATH=0
@@ -56,7 +57,7 @@ ifeq ($(SIGN),ED25519)
5657
./lib/wolfssl/wolfcrypt/src/wolfmath.o \
5758
./lib/wolfssl/wolfcrypt/src/fe_low_mem.o
5859
PUBLIC_KEY_OBJS=./src/ed25519_pub_key.o
59-
CFLAGS+=-DWOLFBOOT_SIGN_ED25519 -nostdlib -DWOLFSSL_STATIC_MEMORY \
60+
CFLAGS+=-DWOLFBOOT_SIGN_ED25519 -nostdlib \
6061
-Wstack-usage=1024
6162
LDFLAGS+=-nostdlib
6263
endif
@@ -119,6 +120,9 @@ endif
119120

120121
ifeq ($(EXT_FLASH),1)
121122
CFLAGS+= -DEXT_FLASH=1 -DPART_UPDATE_EXT=1 -DPART_SWAP_EXT=1
123+
ifeq ($(NO_XIP),1)
124+
CFLAGS+=-DPART_BOOT_EXT=1
125+
endif
122126
endif
123127

124128
ifeq ($(ALLOW_DOWNGRADE),1)
@@ -151,6 +155,7 @@ ifeq ($(PKA),1)
151155
endif
152156

153157
OBJS+=$(PUBLIC_KEY_OBJS)
158+
OBJS+=$(UPDATE_OBJS)
154159

155160
ifeq ($(WOLFTPM),1)
156161
OBJS += lib/wolfTPM/src/tpm2.o \
@@ -181,7 +186,7 @@ wolfboot.hex: wolfboot.elf
181186

182187
align: wolfboot-align.bin
183188

184-
.bootloader-partition-size: FORCE
189+
.bootloader-partition-size:
185190
@printf "%d" $(WOLFBOOT_PARTITION_BOOT_ADDRESS) > .wolfboot-offset
186191
@printf "%d" $(ARCH_FLASH_OFFSET) > .wolfboot-arch-offset
187192
@expr `cat .wolfboot-offset` - `cat .wolfboot-arch-offset` > .bootloader-partition-size
@@ -202,7 +207,7 @@ test-app/image.bin: wolfboot-align.bin
202207

203208
standalone:
204209
@make -C test-app TARGET=$(TARGET) EXT_FLASH=$(EXT_FLASH) SPI_FLASH=$(SPI_FLASH) ARCH=$(ARCH) \
205-
V=$(V) RAM_CODE=$(RAM_CODE) WOLFBOOT_VERSION=$(WOLFBOOT_VERSION)\
210+
NO_XIP=$(NO_XIP) V=$(V) RAM_CODE=$(RAM_CODE) WOLFBOOT_VERSION=$(WOLFBOOT_VERSION)\
206211
MCUXPRESSO=$(MCUXPRESSO) MCUXPRESSO_CPU=$(MCUXPRESSO_CPU) MCUXPRESSO_DRIVERS=$(MCUXPRESSO_DRIVERS) \
207212
MCUXPRESSO_CMSIS=$(MCUXPRESSO_CMSIS) NVM_FLASH_WRITEONCE=$(NVM_FLASH_WRITEONCE) \
208213
FREEDOM_E_SDK=$(FREEDOM_E_SDK) standalone
@@ -223,9 +228,18 @@ rsa2048.der:
223228
rsa4096.der:
224229
@python3 tools/keytools/keygen.py $(KEYGEN_OPTIONS) src/rsa4096_pub_key.c
225230

231+
keytools:
232+
@make -C tools/keytools
233+
226234
factory.bin: $(BOOT_IMG) wolfboot-align.bin $(PRIVATE_KEY)
227235
@echo "\t[SIGN] $(BOOT_IMG)"
236+
ifneq ("$(wildcard ./tools/keytools/sign)","")
237+
@echo "\n./tools/keytools/sign $(SIGN_OPTIONS) $(BOOT_IMG) $(PRIVATE_KEY) 1"
238+
$(Q)./tools/keytools/sign $(SIGN_OPTIONS) $(BOOT_IMG) $(PRIVATE_KEY) 1
239+
else
240+
@echo "\npython3 tools/keytools/sign.py $(SIGN_OPTIONS) $(BOOT_IMG) $(PRIVATE_KEY) 1"
228241
$(Q)python3 tools/keytools/sign.py $(SIGN_OPTIONS) $(BOOT_IMG) $(PRIVATE_KEY) 1
242+
endif
229243
@echo "\t[MERGE] $@"
230244
@cat wolfboot-align.bin test-app/image_v1_signed.bin > $@
231245

@@ -255,14 +269,19 @@ clean:
255269

256270
distclean: clean
257271
@rm -f *.pem *.der tags ./src/ed25519_pub_key.c ./src/ecc256_pub_key.c ./src/rsa2048_pub_key.c include/target.h
272+
@make -C tools/keytools clean
258273

259274
include/target.h: include/target.h.in FORCE
260275
@cat include/target.h.in | \
261276
sed -e "s/##WOLFBOOT_PARTITION_SIZE##/$(WOLFBOOT_PARTITION_SIZE)/g" | \
262277
sed -e "s/##WOLFBOOT_SECTOR_SIZE##/$(WOLFBOOT_SECTOR_SIZE)/g" | \
263278
sed -e "s/##WOLFBOOT_PARTITION_BOOT_ADDRESS##/$(WOLFBOOT_PARTITION_BOOT_ADDRESS)/g" | \
264279
sed -e "s/##WOLFBOOT_PARTITION_UPDATE_ADDRESS##/$(WOLFBOOT_PARTITION_UPDATE_ADDRESS)/g" | \
265-
sed -e "s/##WOLFBOOT_PARTITION_SWAP_ADDRESS##/$(WOLFBOOT_PARTITION_SWAP_ADDRESS)/g" \
280+
sed -e "s/##WOLFBOOT_PARTITION_SWAP_ADDRESS##/$(WOLFBOOT_PARTITION_SWAP_ADDRESS)/g" | \
281+
sed -e "s/##WOLFBOOT_DTS_BOOT_ADDRESS##/$(WOLFBOOT_DTS_BOOT_ADDRESS)/g" | \
282+
sed -e "s/##WOLFBOOT_DTS_UPDATE_ADDRESS##/$(WOLFBOOT_DTS_UPDATE_ADDRESS)/g" | \
283+
sed -e "s/##WOLFBOOT_LOAD_ADDRESS##/$(WOLFBOOT_LOAD_ADDRESS)/g" | \
284+
sed -e "s/##WOLFBOOT_LOAD_DTS_ADDRESS##/$(WOLFBOOT_LOAD_DTS_ADDRESS)/g" \
266285
> $@
267286

268287
config: FORCE

README.md

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ microcontrollers will be added later. Relocating the interrupt vector can be dis
4848
- Change the entry point of the firmware image to account for bootloader presence
4949
- Equip the application with the [wolfBoot library](docs/API.md) to interact with the bootloader
5050
- [Configure and compile](docs/compile.md) a bootable image with a single "make" command
51+
- For help signing firmware see [wolfBoot Signing](docs/Signing.md)
5152

5253
### Examples provided
5354

@@ -101,23 +102,19 @@ Traceback (most recent call last):
101102
AttributeError: 'EccPrivate' object has no attribute 'sign_raw'
102103
```
103104

104-
You need to install the latest wolfcrypt-pi here: https://github.com/wolfSSL/wolfcrypt-py
105+
You need to install the latest wolfcrypt-py here: https://github.com/wolfSSL/wolfcrypt-py
105106

106107
Use `pip3 install wolfcrypt`.
107-
Make sure the wolfSSL library has been built with:
108-
```sh
109-
110-
```
111108

112-
To install based on a local wolfSSL installation use:
109+
Or to install based on a local wolfSSL installation use:
113110

114111
```sh
115-
cd youwolfssldir
116-
./configure --enable-keygen --enable-rsa --enable-ecc --enable-ed25519 CFLAGS="-DWOLFSSL_PUBLIC_MP"
112+
cd wolfssl
113+
./configure --enable-keygen --enable-rsa --enable-ecc --enable-ed25519 --enable-des3 CFLAGS="-DFP_MAX_BITS=8192 -DWOLFSSL_PUBLIC_MP"
117114
make
118115
sudo make install
119116

120-
cd yourwolfcryptpydir
117+
cd wolfcrypt-py
121118
USE_LOCAL_WOLFSSL=/usr/local pip3 install .
122119
```
123120

arch.mk

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
## CPU Architecture selection via $ARCH
22

3+
UPDATE_OBJS:=./src/update_flash.o
4+
35
# check for FASTMATH or SP_MATH
46
ifeq ($(SPMATH),1)
57
MATH_OBJS:=./lib/wolfssl/wolfcrypt/src/sp_int.o
@@ -29,6 +31,13 @@ endif
2931
WOLFCRYPT_OBJS+=./lib/wolfssl/wolfcrypt/src/sha256.o
3032

3133
## ARM
34+
ifeq ($(ARCH),AARCH64)
35+
CROSS_COMPILE:=aarch64-none-elf-
36+
CFLAGS+=-DARCH_AARCH64 -march=armv8-a
37+
OBJS+=src/boot_aarch64.o src/boot_aarch64_start.o
38+
CFLAGS+=-DNO_QNX
39+
endif
40+
3241
ifeq ($(ARCH),ARM)
3342
CROSS_COMPILE:=arm-none-eabi-
3443
CFLAGS+=-mthumb -mlittle-endian -mthumb-interwork -DARCH_ARM
@@ -149,3 +158,13 @@ ifeq ($(TARGET),stm32wb)
149158
-DSTM32WB55xx
150159
endif
151160
endif
161+
162+
163+
## Update mechanism
164+
ifeq ($(ARCH),AARCH64)
165+
CFLAGS+=-DMMU
166+
UPDATE_OBJS:=src/update_ram.o
167+
endif
168+
ifeq ($(DUALBANK_SWAP),1)
169+
UPDATE_OBJS:=src/update_flash_hwswap.o
170+
endif

config/examples/hifive1.config

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
ARCH?=RISCV
22
TARGET?=hifive1
33
SIGN?=ECC256
4+
HASH?=SHA256
45
FREEDOM_E_SDK?=~/src/freedom-e-sdk
56
DEBUG?=0
67
VTOR?=1

0 commit comments

Comments
 (0)