Skip to content

Commit 46058f0

Browse files
authored
Merge pull request #39 from dgarske/aarch64_more
Fixes for Zynqmp with BL31 and C signing tool padding
2 parents 6af52ad + 85b7c4d commit 46058f0

11 files changed

Lines changed: 59 additions & 49 deletions

File tree

IDE/XilinxSDK/README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,17 @@ To use this example project:
44
1. Copy `.cproject` and `.project` into the wolfBoot root.
55
2. From the Xilinx SDK Import wolfBoot using "Import" -> "Existing Projects into Workspace".
66

7+
## Xilinx SDK BSP
8+
9+
This project uses a BSP named `standalone_bsp_0`, which must be configured to use "hypervisor guest" in the BSP configuration settings. This will enable the EL-1 support required with Bl31 (ARM Trusted Firmware). The BSP generates a include/bspconfig.h, which should have these defines set:
10+
11+
```
12+
#define EL1_NONSECURE 1
13+
#define HYP_GUEST 1
14+
```
15+
16+
Note: This is a generated file from the BSP configurator tool, which is edited by opening the `system.mss` file.
17+
718
## wolfBoot Configuration
819

920
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`:

IDE/XilinxSDK/boot.bif

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ the_ROM_image:
66
[destination_cpu=pmu] pmufw.elf
77
[destination_device=pl] system.bit
88
[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
9+
[destination_cpu=a53-0, exception_level=el-1] wolfboot.elf
10+
[destination_cpu=a53-0, partition_owner=uboot, offset=0x800000] helloworld_v1_signed.bin
1111
}

IDE/XilinxSDK/boot_auth.bif

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// Boot BIF example with Xilinx Secure Boot authentication and wolfBoot
2+
// Note: Using partition_owner=uboot prevents FSBL from loading to RAM
23
the_ROM_image:
34
{
45
// Boot Header Authentication Enable
@@ -11,19 +12,17 @@ the_ROM_image:
1112
[pskfile] pskf.pem
1213
[sskfile] sskf.pem
1314

14-
[bootloader, destination_cpu=a53-0, authentication=rsa] zynqmp_fsbl.elf
15-
[destination_cpu=pmu, authentication=rsa] pmufw.elf
15+
[destination_cpu=a53-0, authentication=rsa, bootloader] zynqmp_fsbl.elf
16+
[destination_cpu=pmu, authentication=rsa] pmufw.elf
1617
[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
18+
[destination_cpu=a53-0, authentication=rsa, exception_level=el-3, trustzone] bl31.elf
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
20+
// Second Stage wolfBoot Bootloader
21+
[destination_cpu=a53-0, authentication=rsa, exception_level=el-1] wolfboot.elf
2222

23-
// Second Stage wolfBoot Bootloader (in RAM at 0x0)
24-
[destination_cpu=a53-0, exception_level=el-2, authentication=rsa] wolfboot.elf
23+
// ARM Device Tree (loaded to RAM at 0x11800000 by wolfBoot)
24+
[destination_cpu=a53-0, authentication=rsa, partition_owner=uboot, offset=0x7B0000] system.dtb
2525

2626
// 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
27+
[destination_cpu=a53-0, partition_owner=uboot, offset=0x800000] kernel_v1_signed.bin
2928
}

docs/HAL.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,23 +83,23 @@ To associate the update or the swap partition to an external memory, define `PAR
8383
The following functions are used to access the external memory, and must be defined when `EXT\_FLASH`
8484
is on:
8585

86-
`int ext_flash_write(uint32_t address, const uint8_t *data, int len)`
86+
`int ext_flash_write(uintptr_t address, const uint8_t *data, int len)`
8787

8888
This function provides an implementation of the flash write function, using the
8989
external memory's specific interface. `address` is the offset from the beginning of the
9090
addressable space in the device, `data` is the payload to be stored,
9191
and `len` is the size of the payload. `ext_flash_write` should return 0 upon success,
9292
or a negative value in case of failure.
9393

94-
`int ext_flash_read(uint32_t address, uint8_t *data, int len)`
94+
`int ext_flash_read(uintptr_t address, uint8_t *data, int len)`
9595

9696
This function provides an indirect read of the external memory, using the
9797
driver's specific interface. `address` is the offset from the beginning of the
9898
addressable space in the device, `data` is a pointer where payload is stored upon a successful
9999
call, and `len` is the maximum size allowed for the payload. `ext_flash_read` should return 0
100100
upon success, or a negative value in case of failure.
101101

102-
`int ext_flash_erase(uint32_t address, int len)`
102+
`int ext_flash_erase(uintptr_t address, int len)`
103103

104104
Called by the bootloader to erase part of the external memory.
105105
Erase operations must be performed via the specific interface of the target driver (e.g. SPI flash).

hal/zynq.c

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
#include "xzynq_gqspi.h"
4545
#endif
4646

47-
#define CORTEXA53_0_CPU_CLK_FREQ_HZ 1099989014
47+
#define CORTEXA53_0_CPU_CLK_FREQ_HZ 1099989014
4848
#define CORTEXA53_0_TIMESTAMP_CLK_FREQ 99998999
4949

5050
/* Generic Quad-SPI */
@@ -149,14 +149,14 @@
149149
#define QSPIDMA_DST_CTRL2_DEF 0x081BFFF8UL
150150

151151
/* QSPIDMA_DST_STS */
152-
#define QSPIDMA_DST_STS_WTC 0xE000U
152+
#define QSPIDMA_DST_STS_WTC 0xE000U
153153

154154
/* QSPIDMA_DST_I_STS */
155155
#define QSPIDMA_DST_I_STS_ALL_MASK 0xFEU
156156

157157
/* IOP System-level Control */
158158
#define IOU_SLCR_BASSE 0xFF180000
159-
#define IOU_TAPDLY_BYPASS (*((volatile uint32_t*)(IOU_SLCR_BASSE + 390)))
159+
#define IOU_TAPDLY_BYPASS (*((volatile uint32_t*)(IOU_SLCR_BASSE + 0x390)))
160160
#define IOU_TAPDLY_BYPASS_LQSPI_RX (1UL << 2) /* LQSPI Tap Delay Enable on Rx Clock signal. 0: enable. 1: disable (bypass tap delay). */
161161

162162

@@ -185,25 +185,21 @@
185185

186186

187187
/* Flash Commands */
188-
#define WRITE_ENABLE_CMD 0x06U
189-
#define WRITE_DISABLE_CMD 0x04U
188+
#define WRITE_ENABLE_CMD 0x06U
189+
#define WRITE_DISABLE_CMD 0x04U
190190
#define READ_ID_CMD 0x9FU
191191
#define MULTI_IO_READ_ID_CMD 0xAFU
192192
#define READ_FSR_CMD 0x70U
193193
#define ENTER_QSPI_MODE_CMD 0x35U
194194
#define EXIT_QSPI_MODE_CMD 0xF5U
195195
#define ENTER_4B_ADDR_MODE_CMD 0xB7U
196196
#define EXIT_4B_ADDR_MODE_CMD 0xE9U
197-
198197
#define FAST_READ_CMD 0x0BU
199198
#define QUAD_READ_4B_CMD 0x6CU
200-
201199
#define PAGE_PROG_CMD 0x02U
202200
#define QUAD_PAGE_PROG_4B_CMD 0x34U
203-
204201
#define SEC_ERASE_CMD 0xD8U
205202
#define SEC_4K_ERASE_CMD 0x20U
206-
207203
#define RESET_ENABLE_CMD 0x66U
208204
#define RESET_MEMORY_CMD 0x99U
209205

@@ -282,6 +278,7 @@ static int qspi_transfer(QspiDev_t* pDev,
282278
return GQSPI_CODE_SUCCESS;
283279
}
284280
#else
281+
285282
static inline int qspi_isr_wait(uint32_t wait_mask, uint32_t wait_val)
286283
{
287284
uint32_t timeout = 0;
@@ -759,6 +756,7 @@ void qspi_init(uint32_t cpu_clock, uint32_t flash_freq)
759756
GQSPI_CFG = reg_cfg;
760757

761758
/* use tap delay bypass < 40MHz SPI clock */
759+
IOU_TAPDLY_BYPASS |= IOU_TAPDLY_BYPASS_LQSPI_RX;
762760
GQSPI_LPBK_DLY_ADJ = 0;
763761
QSPI_DATA_DLY_ADJ = 0;
764762

@@ -888,7 +886,8 @@ void hal_init(void)
888886
printf("\nwolfBoot Secure Boot\n");
889887
#endif
890888

891-
asm volatile("msr cntfrq_el0, %0" : : "r" (cpu_freq) : "memory");
889+
/* This is only allowed for EL-3 */
890+
//asm volatile("msr cntfrq_el0, %0" : : "r" (cpu_freq) : "memory");
892891

893892
zynq_init(cpu_freq);
894893
}

hal/zynq.ld

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,8 @@ _EL2_STACK_SIZE = DEFINED(_EL2_STACK_SIZE) ? _EL2_STACK_SIZE : 1024;
1111
/* Define Memories in the system */
1212
MEMORY
1313
{
14-
ddr4_ctrl_C0_DDR4_ADDRESS_BLOCK : ORIGIN = 0x500000000, LENGTH = 0x20000000
15-
psu_ddr_0_MEM_0 : ORIGIN = 0x0, LENGTH = 0x7FF00000
16-
psu_ddr_1_MEM_0 : ORIGIN = 0x800000000, LENGTH = 0x80000000
17-
psu_ocm_ram_0_MEM_0 : ORIGIN = 0xFFFC0000, LENGTH = 0x40000
18-
psu_qspi_linear_0_MEM_0 : ORIGIN = 0xC0000000, LENGTH = 0x20000000
14+
psu_ddr_0_MEM_0 : ORIGIN = 0x40000000, LENGTH = 0x100000
15+
1916
}
2017

2118
/* Specify the default entry point to the program */
@@ -230,16 +227,6 @@ SECTIONS
230227
__sdata_end = .;
231228
} > psu_ddr_0_MEM_0
232229

233-
.sbss (NOLOAD) : {
234-
. = ALIGN(64);
235-
__sbss_start = .;
236-
*(.sbss)
237-
*(.sbss.*)
238-
*(.gnu.linkonce.sb.*)
239-
. = ALIGN(64);
240-
__sbss_end = .;
241-
} > psu_ddr_0_MEM_0
242-
243230
.tdata : {
244231
. = ALIGN(64);
245232
__tdata_start = .;
@@ -258,6 +245,17 @@ SECTIONS
258245
__tbss_end = .;
259246
} > psu_ddr_0_MEM_0
260247

248+
249+
.sbss (NOLOAD) : {
250+
. = ALIGN(64);
251+
__sbss_start = .;
252+
*(.sbss)
253+
*(.sbss.*)
254+
*(.gnu.linkonce.sb.*)
255+
. = ALIGN(64);
256+
__sbss_end = .;
257+
} > psu_ddr_0_MEM_0
258+
261259
.bss (NOLOAD) : {
262260
. = ALIGN(64);
263261
__bss_start__ = .;

src/image.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ static uint8_t *get_sha_block(struct wolfBoot_image *img, uint32_t offset)
154154
if (offset > img->fw_size)
155155
return NULL;
156156
if (PART_IS_EXT(img)) {
157-
ext_flash_read((unsigned long)(img->fw_base) + offset, ext_hash_block, WOLFBOOT_SHA_BLOCK_SIZE);
157+
ext_flash_read((uintptr_t)(img->fw_base) + offset, ext_hash_block, WOLFBOOT_SHA_BLOCK_SIZE);
158158
return ext_hash_block;
159159
} else
160160
return (uint8_t *)(img->fw_base + offset);

src/libwolfboot.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ uint32_t wolfBoot_get_image_version(uint8_t part)
345345
if (PARTN_IS_EXT(PART_UPDATE))
346346
{
347347
#ifdef EXT_FLASH
348-
ext_flash_read((uint32_t)WOLFBOOT_PARTITION_UPDATE_ADDRESS, hdr_cpy, IMAGE_HEADER_SIZE);
348+
ext_flash_read((uintptr_t)WOLFBOOT_PARTITION_UPDATE_ADDRESS, hdr_cpy, IMAGE_HEADER_SIZE);
349349
hdr_cpy_done = 1;
350350
image = hdr_cpy;
351351
#endif
@@ -355,7 +355,7 @@ uint32_t wolfBoot_get_image_version(uint8_t part)
355355
} else if (part == PART_BOOT) {
356356
if (PARTN_IS_EXT(PART_BOOT)) {
357357
#ifdef EXT_FLASH
358-
ext_flash_read((uint32_t)WOLFBOOT_PARTITION_BOOT_ADDRESS, hdr_cpy, IMAGE_HEADER_SIZE);
358+
ext_flash_read((uintptr_t)WOLFBOOT_PARTITION_BOOT_ADDRESS, hdr_cpy, IMAGE_HEADER_SIZE);
359359
hdr_cpy_done = 1;
360360
image = hdr_cpy;
361361
#endif
@@ -376,7 +376,7 @@ uint16_t wolfBoot_get_image_type(uint8_t part)
376376
if (PARTN_IS_EXT(PART_UPDATE))
377377
{
378378
#ifdef EXT_FLASH
379-
ext_flash_read((uint32_t)WOLFBOOT_PARTITION_UPDATE_ADDRESS, hdr_cpy, IMAGE_HEADER_SIZE);
379+
ext_flash_read((uintptr_t)WOLFBOOT_PARTITION_UPDATE_ADDRESS, hdr_cpy, IMAGE_HEADER_SIZE);
380380
hdr_cpy_done = 1;
381381
image = hdr_cpy;
382382
#endif
@@ -386,7 +386,7 @@ uint16_t wolfBoot_get_image_type(uint8_t part)
386386
} else if (part == PART_BOOT) {
387387
if (PARTN_IS_EXT(PART_BOOT)) {
388388
#ifdef EXT_FLASH
389-
ext_flash_read((uint32_t)WOLFBOOT_PARTITION_BOOT_ADDRESS, hdr_cpy, IMAGE_HEADER_SIZE);
389+
ext_flash_read((uintptr_t)WOLFBOOT_PARTITION_BOOT_ADDRESS, hdr_cpy, IMAGE_HEADER_SIZE);
390390
hdr_cpy_done = 1;
391391
image = hdr_cpy;
392392
#endif

src/loader.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ static int wolfBoot_copy_sector(struct wolfBoot_image *src, struct wolfBoot_imag
5252
wb_flash_erase(dst, dst_sector_offset, WOLFBOOT_SECTOR_SIZE);
5353
while (pos < WOLFBOOT_SECTOR_SIZE) {
5454
if (src_sector_offset + pos < (src->fw_size + IMAGE_HEADER_SIZE + FLASHBUFFER_SIZE)) {
55-
ext_flash_read((uint32_t)(src->hdr) + src_sector_offset + pos, (void *)buffer, FLASHBUFFER_SIZE);
55+
ext_flash_read((uintptr_t)(src->hdr) + src_sector_offset + pos, (void *)buffer, FLASHBUFFER_SIZE);
5656
wb_flash_write(dst, dst_sector_offset + pos, buffer, FLASHBUFFER_SIZE);
5757
}
5858
pos += FLASHBUFFER_SIZE;

src/update_flash.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ static void RAMFUNCTION wolfBoot_self_update(struct wolfBoot_image *src)
5656
if (PART_IS_EXT(src)) {
5757
uint8_t buffer[FLASHBUFFER_SIZE];
5858
if (src_offset + pos < (src->fw_size + IMAGE_HEADER_SIZE + FLASHBUFFER_SIZE)) {
59-
ext_flash_read((uint32_t)(src->hdr) + src_offset + pos, (void *)buffer, FLASHBUFFER_SIZE);
59+
ext_flash_read((uintptr_t)(src->hdr) + src_offset + pos, (void *)buffer, FLASHBUFFER_SIZE);
6060
hal_flash_write(pos + (uint32_t)&_start_text, buffer, FLASHBUFFER_SIZE);
6161
}
6262
pos += FLASHBUFFER_SIZE;
@@ -122,7 +122,7 @@ static int wolfBoot_copy_sector(struct wolfBoot_image *src, struct wolfBoot_imag
122122
wb_flash_erase(dst, dst_sector_offset, WOLFBOOT_SECTOR_SIZE);
123123
while (pos < WOLFBOOT_SECTOR_SIZE) {
124124
if (src_sector_offset + pos < (src->fw_size + IMAGE_HEADER_SIZE + FLASHBUFFER_SIZE)) {
125-
ext_flash_read((uint32_t)(src->hdr) + src_sector_offset + pos, (void *)buffer, FLASHBUFFER_SIZE);
125+
ext_flash_read((uintptr_t)(src->hdr) + src_sector_offset + pos, (void *)buffer, FLASHBUFFER_SIZE);
126126
wb_flash_write(dst, dst_sector_offset + pos, buffer, FLASHBUFFER_SIZE);
127127
}
128128
pos += FLASHBUFFER_SIZE;

0 commit comments

Comments
 (0)