Skip to content

Commit e7446c5

Browse files
committed
Fixes for Device Tree (DTS) handling. Updated documentation.
1 parent 2867025 commit e7446c5

7 files changed

Lines changed: 82 additions & 24 deletions

File tree

IDE/XilinxSDK/README.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,20 @@ To use this example project:
66

77
## wolfBoot Configuration
88

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.
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+
```
1023

1124
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`.
1225

@@ -52,6 +65,9 @@ Xilinx uses a `bootgen` tool for generating a boot binary image that has Xilinx
5265
6. Build “boot.bin” image:
5366
* `bootgen.exe -image boot.bif -arch zynqmp -o i BOOT.BIN -w`
5467
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+
5571
### References:
5672
* [ZAPP1319](https://www.xilinx.com/support/documentation/application_notes/xapp1319-zynq-usp-prog-nvm.pdf): Programming BBRAM and eFUSEs
5773
* [UG1283](https://www.xilinx.com/support/documentation/sw_manuals/xilinx2018_2/ug1283-bootgen-user-guide.pdf): Bootgen User Guide

IDE/XilinxSDK/boot_auth.bif

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,13 @@ the_ROM_image:
1717
[destination_cpu=a53-0, exception_level=el-3, trustzone, authentication=rsa] bl31.elf
1818
[destination_cpu=a53-0, authentication=rsa, load=0x11800000] system.dtb
1919

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+
2023
// Second Stage wolfBoot Bootloader (in RAM at 0x0)
2124
[destination_cpu=a53-0, exception_level=el-2, authentication=rsa] wolfboot.elf
2225

23-
// Using partition_owner=uboot prevents partition from being loaded to RAM
24-
[destination_cpu=a53-0, offset=0x800000, partition_owner=uboot] helloworld_v1_signed.bin
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
2529
}

config/examples/zynqmp.config

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,5 @@ WOLFBOOT_PARTITION_SWAP_ADDRESS?=0x63E0000
3535

3636
# DTS (Device Tree)
3737
WOLFBOOT_LOAD_DTS_ADDRESS?=0x11800000
38-
WOLFBOOT_DTS_BOOT_ADDRESS?=0x0
39-
WOLFBOOT_DTS_UPDATE_ADDRESS?=0x0
38+
WOLFBOOT_DTS_BOOT_ADDRESS?=0x7B0000
39+
WOLFBOOT_DTS_UPDATE_ADDRESS?=0x39B0000

docs/Signing.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# wolfBoot Signing
22

3-
Instructions for setting up Python, wolfCrypt-py module and wolfBoot for firmware signing.
3+
Instructions for setting up Python, wolfCrypt-py module and wolfBoot for firmware signing.
4+
5+
Note: There is a pure C signing tool available as well. See [C Signing Tool](#c-signing-tool) below.
46

57
## Install Python3
68

@@ -61,3 +63,11 @@ openssl rsautl -sign -keyform der -inkey rsa4096.der -in test-app/image_v1_diges
6163
# Generate final signed binary
6264
python3 ./tools/keytools/sign.py --rsa4096 --sha3 --manual-sign test-app/image.bin rsa4096_pub.der 1 test-app/image_v1.sig
6365
```
66+
67+
## C Signing Tool
68+
69+
A standalone C version of the signing tool is available here: `./tools/keytools/sign.c`. Build using `make keytools`
70+
71+
```sh
72+
./tools/keytools/sign --rsa4096 --sha3 test-app/image.bin rsa4096.der 1
73+
```

include/image.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,8 @@ uint16_t wolfBoot_find_header(uint8_t *haystack, uint16_t type, uint8_t **ptr);
9292
# define SWAP_EXT 0
9393
# endif
9494
# define PARTN_IS_EXT(pn) \
95-
((pn == PART_BOOT)?BOOT_EXT: \
96-
((pn == PART_UPDATE)?UPDATE_EXT: \
95+
((pn == PART_BOOT || pn == PART_DTS_BOOT)?BOOT_EXT: \
96+
((pn == PART_UPDATE || pn == PART_DTS_UPDATE)?UPDATE_EXT: \
9797
((pn == PART_SWAP)?SWAP_EXT:0)))
9898
# define PART_IS_EXT(x) PARTN_IS_EXT(((x)->part))
9999
#include "hal.h"
@@ -152,7 +152,7 @@ static inline int wb_flash_write_verify_word(struct wolfBoot_image *img, uint32_
152152
#define UBOOT_IMG_HDR_SZ 64
153153

154154
/* --- Flattened Device Tree Blob */
155-
#define UBOOT_FDT_MAGIC 0xD00DFEEDUL
155+
#define UBOOT_FDT_MAGIC 0xEDFE0DD0UL
156156

157157

158158
#endif /* !IMAGE_H */

src/image.c

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -453,25 +453,45 @@ int wolfBoot_open_image(struct wolfBoot_image *img, uint8_t part)
453453
uint8_t *image;
454454
if (!img)
455455
return -1;
456+
457+
#ifdef EXT_FLASH
458+
hdr_cpy_done = 0; /* reset hdr "open" flag */
459+
#endif
460+
456461
memset(img, 0, sizeof(struct wolfBoot_image));
457462
img->part = part;
458463
if (part == PART_SWAP) {
459-
img->part = PART_SWAP;
460-
img->hdr = (void *)WOLFBOOT_PARTITION_SWAP_ADDRESS;
464+
img->hdr_ok = 1;
465+
img->hdr = (void*)WOLFBOOT_PARTITION_SWAP_ADDRESS;
461466
img->fw_base = img->hdr;
462467
img->fw_size = WOLFBOOT_SECTOR_SIZE;
463468
return 0;
464469
}
465-
if (part == PART_BOOT) {
466-
img->hdr = (void *)WOLFBOOT_PARTITION_BOOT_ADDRESS;
467-
} else if (part == PART_UPDATE) {
468-
img->hdr = (void *)WOLFBOOT_PARTITION_UPDATE_ADDRESS;
469470
#ifdef MMU
470-
} else if (part == PART_DTS_BOOT) {
471-
img->hdr = (void *)WOLFBOOT_DTS_BOOT_ADDRESS;
472-
} else if (part == PART_DTS_UPDATE) {
473-
img->hdr = (void *)WOLFBOOT_DTS_UPDATE_ADDRESS;
471+
if (part == PART_DTS_BOOT || part == PART_DTS_UPDATE) {
472+
img->hdr = (part == PART_DTS_BOOT) ? (void*)WOLFBOOT_DTS_BOOT_ADDRESS
473+
: (void*)WOLFBOOT_DTS_UPDATE_ADDRESS;
474+
if (PART_IS_EXT(img))
475+
image = fetch_hdr_cpy(img);
476+
else
477+
image = (uint8_t*)img->hdr;
478+
if (*((uint32_t*)image) != UBOOT_FDT_MAGIC)
479+
return -1;
480+
img->hdr_ok = 1;
481+
img->fw_base = img->hdr;
482+
/* DTS data is big endian */
483+
size = (uint32_t*)(image + sizeof(uint32_t));
484+
img->fw_size = (((*size & 0x000000FF) << 24) |
485+
((*size & 0x0000FF00) << 8) |
486+
((*size & 0x00FF0000) >> 8) |
487+
((*size & 0xFF000000) >> 24));
488+
return 0;
489+
}
474490
#endif
491+
if (part == PART_BOOT) {
492+
img->hdr = (void*)WOLFBOOT_PARTITION_BOOT_ADDRESS;
493+
} else if (part == PART_UPDATE) {
494+
img->hdr = (void*)WOLFBOOT_PARTITION_UPDATE_ADDRESS;
475495
} else
476496
return -1;
477497

src/update_ram.c

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ void RAMFUNCTION wolfBoot_start(void)
4545
uint8_t* image_ptr;
4646
uint8_t p_state;
4747
#ifdef MMU
48-
uint32_t* dts_address;
48+
uint32_t* dts_address = NULL;
4949
#endif
5050

5151
active = wolfBoot_dualboot_candidate();
@@ -116,10 +116,18 @@ void RAMFUNCTION wolfBoot_start(void)
116116
#endif
117117

118118
#ifdef MMU
119-
/* Device Tree - Check */
120-
dts_address = (uint32_t*)WOLFBOOT_LOAD_DTS_ADDRESS;
121-
if (*dts_address != UBOOT_FDT_MAGIC) {
122-
dts_address = NULL;
119+
/* Device Tree Blob (DTB) Handling */
120+
if (wolfBoot_open_image(&os_image, PART_DTS_BOOT) >= 0) {
121+
dts_address = (uint32_t*)WOLFBOOT_LOAD_DTS_ADDRESS;
122+
123+
#ifdef EXT_FLASH
124+
/* Load DTS to RAM */
125+
if (PART_IS_EXT(&os_image)) {
126+
ext_flash_read((uintptr_t)os_image.fw_base,
127+
(uint8_t*)dts_address,
128+
os_image.fw_size);
129+
}
130+
#endif
123131
}
124132
#endif
125133

0 commit comments

Comments
 (0)