Skip to content

Commit 2867025

Browse files
committed
Fixes for handling U-Boot image and DTS. Moved the Xilinx SDK project target settings into target.h.
1 parent c0b534e commit 2867025

9 files changed

Lines changed: 77 additions & 29 deletions

File tree

IDE/XilinxSDK/.cproject

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
<option defaultValue="gnu.c.optimization.level.none" id="xilinx.gnu.compiler.option.optimization.level.787097006" name="Optimization Level" superClass="xilinx.gnu.compiler.option.optimization.level" valueType="enumerated"/>
2727
<option id="xilinx.gnu.compiler.option.debugging.level.377817671" name="Debug Level" superClass="xilinx.gnu.compiler.option.debugging.level" value="gnu.c.debugging.level.max" valueType="enumerated"/>
2828
<option id="xilinx.gnu.compiler.inferred.swplatform.includes.700669541" name="Software Platform Include Path" superClass="xilinx.gnu.compiler.inferred.swplatform.includes" valueType="includePath">
29-
<listOptionValue builtIn="false" value="../../fsbl_bsp/psu_cortexa53_0/include"/>
29+
<listOptionValue builtIn="false" value="../../standalone_bsp_0/psu_cortexa53_0/include"/>
3030
</option>
3131
<option id="xilinx.gnu.compiler.inferred.swplatform.flags.1933981667" name="Software Platform Inferred Flags" superClass="xilinx.gnu.compiler.inferred.swplatform.flags" value=" " valueType="string"/>
3232
<option id="xilinx.gnu.compiler.dircategory.includes.921420610" name="Include Paths" superClass="xilinx.gnu.compiler.dircategory.includes" valueType="includePath">
@@ -52,15 +52,6 @@
5252
<listOptionValue builtIn="false" value="WOLFSSL_USER_SETTINGS"/>
5353
<listOptionValue builtIn="false" value="PLATFORM_zynq"/>
5454
<listOptionValue builtIn="false" value="IMAGE_HEADER_SIZE=1024"/>
55-
<listOptionValue builtIn="false" value="WOLFBOOT_SECTOR_SIZE=0x20000"/>
56-
<listOptionValue builtIn="false" value="WOLFBOOT_PARTITION_SIZE=0x2A00000"/>
57-
<listOptionValue builtIn="false" value="WOLFBOOT_PARTITION_BOOT_ADDRESS=0x800000"/>
58-
<listOptionValue builtIn="false" value="WOLFBOOT_LOAD_ADDRESS=0x10000000"/>
59-
<listOptionValue builtIn="false" value="WOLFBOOT_PARTITION_UPDATE_ADDRESS=0x03A00000"/>
60-
<listOptionValue builtIn="false" value="WOLFBOOT_PARTITION_SWAP_ADDRESS=0x63E0000"/>
61-
<listOptionValue builtIn="false" value="WOLFBOOT_DTS_BOOT_ADDRESS=0x2800000"/>
62-
<listOptionValue builtIn="false" value="WOLFBOOT_DTS_UPDATE_ADDRESS=0x0"/>
63-
<listOptionValue builtIn="false" value="WOLFBOOT_LOAD_DTS_ADDRESS=0x0"/>
6455
</option>
6556
<inputType id="xilinx.gnu.arm.a53.c.compiler.input.431141625" name="C source files" superClass="xilinx.gnu.arm.a53.c.compiler.input"/>
6657
</tool>
@@ -75,7 +66,7 @@
7566
<tool id="xilinx.gnu.arm.a53.toolchain.archiver.1127163903" name="ARM v8 archiver" superClass="xilinx.gnu.arm.a53.toolchain.archiver"/>
7667
<tool id="xilinx.gnu.arm.a53.c.toolchain.linker.debug.237195607" name="ARM v8 gcc linker" superClass="xilinx.gnu.arm.a53.c.toolchain.linker.debug">
7768
<option id="xilinx.gnu.linker.inferred.swplatform.lpath.85815925" name="Software Platform Library Path" superClass="xilinx.gnu.linker.inferred.swplatform.lpath" valueType="libPaths">
78-
<listOptionValue builtIn="false" value="../../fsbl_bsp/psu_cortexa53_0/lib"/>
69+
<listOptionValue builtIn="false" value="../../standalone_bsp_0/psu_cortexa53_0/lib"/>
7970
</option>
8071
<option id="xilinx.gnu.linker.inferred.swplatform.flags.27496298" name="Software Platform Inferred Flags" superClass="xilinx.gnu.linker.inferred.swplatform.flags" valueType="libs">
8172
<listOptionValue builtIn="false" value="-Wl,--start-group,-lxil,-lgcc,-lc,--end-group"/>
@@ -154,15 +145,6 @@
154145
<listOptionValue builtIn="false" value="WOLFSSL_USER_SETTINGS"/>
155146
<listOptionValue builtIn="false" value="PLATFORM_zynq"/>
156147
<listOptionValue builtIn="false" value="IMAGE_HEADER_SIZE=1024"/>
157-
<listOptionValue builtIn="false" value="WOLFBOOT_SECTOR_SIZE=0x20000"/>
158-
<listOptionValue builtIn="false" value="WOLFBOOT_PARTITION_SIZE=0x2A00000"/>
159-
<listOptionValue builtIn="false" value="WOLFBOOT_PARTITION_BOOT_ADDRESS=0x800000"/>
160-
<listOptionValue builtIn="false" value="WOLFBOOT_LOAD_ADDRESS=0x10000000"/>
161-
<listOptionValue builtIn="false" value="WOLFBOOT_PARTITION_UPDATE_ADDRESS=0x03A00000"/>
162-
<listOptionValue builtIn="false" value="WOLFBOOT_PARTITION_SWAP_ADDRESS=0x63E0000"/>
163-
<listOptionValue builtIn="false" value="WOLFBOOT_DTS_BOOT_ADDRESS=0x2800000"/>
164-
<listOptionValue builtIn="false" value="WOLFBOOT_DTS_UPDATE_ADDRESS=0x0"/>
165-
<listOptionValue builtIn="false" value="WOLFBOOT_LOAD_DTS_ADDRESS=0x0"/>
166148
</option>
167149
<option id="xilinx.gnu.compiler.dircategory.includes.1946921747" name="Include Paths" superClass="xilinx.gnu.compiler.dircategory.includes" valueType="includePath">
168150
<listOptionValue builtIn="false" value="../../standalone_bsp_0/psu_cortexa53_0/include"/>

config/examples/zynqmp.config

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@ WOLFBOOT_PARTITION_BOOT_ADDRESS?=0x800000
2929
# Load Partition to RAM Address
3030
WOLFBOOT_LOAD_ADDRESS?=0x10000000
3131
# Location in Flash for Secondary Partition
32-
WOLFBOOT_PARTITION_UPDATE_ADDRESS?=0x03A00000
32+
WOLFBOOT_PARTITION_UPDATE_ADDRESS?=0x3A00000
3333
# Location to store wolfBoot state
3434
WOLFBOOT_PARTITION_SWAP_ADDRESS?=0x63E0000
3535

3636
# DTS (Device Tree)
37-
WOLFBOOT_DTS_BOOT_ADDRESS?=0x2800000
38-
WOLFBOOT_LOAD_DTS_ADDRESS?=0x0
39-
WOLFBOOT_DTS_UPDATE_ADDRESS?=0x0
37+
WOLFBOOT_LOAD_DTS_ADDRESS?=0x11800000
38+
WOLFBOOT_DTS_BOOT_ADDRESS?=0x0
39+
WOLFBOOT_DTS_UPDATE_ADDRESS?=0x0

docs/Targets.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ Upon reboot, wolfboot will elect the best candidate (version 2 in this case) and
412412
If the accepted candidate image resides on BANK B (like in this case), wolfBoot will perform one bank swap before
413413
booting.
414414

415-
### Debuggging
415+
### Debugging
416416

417417
Debugging with OpenOCD:
418418

hal/zynq.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,7 @@ static int qspi_wait_ready(QspiDev_t* dev)
536536
return GQSPI_CODE_TIMEOUT;
537537
}
538538

539+
#if 0
539540
static int qspi_flash_reset(QspiDev_t* dev)
540541
{
541542
uint8_t cmd[1];
@@ -545,6 +546,7 @@ static int qspi_flash_reset(QspiDev_t* dev)
545546
qspi_transfer(&mDev, cmd, 1, NULL, 0, NULL, 0, 0);
546547
return GQSPI_CODE_SUCCESS;
547548
}
549+
#endif
548550

549551
#if GQSPI_QSPI_MODE == GQSPI_GEN_FIFO_MODE_QSPI
550552
static int qspi_enter_qspi_mode(QspiDev_t* dev)

include/hal.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,11 @@
2929
#include "target.h"
3030

3131
/* Architecture specific calls */
32+
#ifdef MMU
33+
extern void do_boot(const uint32_t *app_offset, const uint32_t* dts_offset);
34+
#else
3235
extern void do_boot(const uint32_t *app_offset);
36+
#endif
3337
extern void arch_reboot(void);
3438

3539

include/image.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ int wolfBoot_set_sector_flag(uint8_t part, uint8_t sector, uint8_t newflag);
7070
int wolfBoot_get_partition_state(uint8_t part, uint8_t *st);
7171
int wolfBoot_get_sector_flag(uint8_t part, uint8_t sector, uint8_t *flag);
7272

73+
uint8_t* wolfBoot_peek_image(struct wolfBoot_image *img, uint32_t offset, uint32_t* sz);
74+
7375
/* Defined in libwolfboot */
7476
uint16_t wolfBoot_find_header(uint8_t *haystack, uint16_t type, uint8_t **ptr);
7577

@@ -144,4 +146,13 @@ static inline int wb_flash_write_verify_word(struct wolfBoot_image *img, uint32_
144146

145147
#endif /* EXT_FLASH */
146148

149+
/* -- Image Formats -- */
150+
/* Legacy U-Boot Image */
151+
#define UBOOT_IMG_HDR_MAGIC 0x56190527UL
152+
#define UBOOT_IMG_HDR_SZ 64
153+
154+
/* --- Flattened Device Tree Blob */
155+
#define UBOOT_FDT_MAGIC 0xD00DFEEDUL
156+
157+
147158
#endif /* !IMAGE_H */

src/boot_aarch64.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,21 @@ void boot_entry_C(void)
5353
*
5454
*/
5555

56+
#ifdef MMU
57+
void RAMFUNCTION do_boot(const uint32_t *app_offset, const uint32_t* dts_offset)
58+
#else
5659
void RAMFUNCTION do_boot(const uint32_t *app_offset)
60+
#endif
5761
{
5862
/* Set application address via x4 */
5963
asm volatile("mov x4, %0" : : "r"(app_offset));
6064

61-
/* move the dts pointer (stored in x21) to x0 (as first argument) */
62-
asm volatile("mov x0, x21");
65+
#ifdef MMU
66+
/* move the dts pointer to x0 (as first argument) */
67+
asm volatile("mov x0, %0" : : "r"(dts_offset));
68+
#else
69+
asm volatile("mov x0, xzr");
70+
#endif
6371

6472
/* zero registers x1, x2, x3 */
6573
asm volatile("mov x3, xzr");

src/image.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -548,3 +548,14 @@ int wolfBoot_verify_authenticity(struct wolfBoot_image *img)
548548
img->signature_ok = 1;
549549
return 0;
550550
}
551+
552+
/* Peek at image offset and return static pointer */
553+
/* sz: optional and returns length of peek */
554+
uint8_t* wolfBoot_peek_image(struct wolfBoot_image *img, uint32_t offset,
555+
uint32_t* sz)
556+
{
557+
uint8_t* p = get_sha_block(img, offset);
558+
if (sz)
559+
*sz = WOLFBOOT_SHA_BLOCK_SIZE;
560+
return p;
561+
}

src/update_ram.c

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,13 @@ void RAMFUNCTION wolfBoot_start(void)
4141
{
4242
int active;
4343
struct wolfBoot_image os_image;
44+
uint32_t* load_address = (uint32_t*)WOLFBOOT_LOAD_ADDRESS;
45+
uint8_t* image_ptr;
4446
uint8_t p_state;
47+
#ifdef MMU
48+
uint32_t* dts_address;
49+
#endif
50+
4551
active = wolfBoot_dualboot_candidate();
4652

4753
if (active < 0) /* panic if no images available */
@@ -88,15 +94,39 @@ void RAMFUNCTION wolfBoot_start(void)
8894
hal_flash_lock();
8995
}
9096

97+
/* Check for U-Boot Legacy format image header */
98+
image_ptr = wolfBoot_peek_image(&os_image, 0, NULL);
99+
if (image_ptr) {
100+
if (*((uint32_t*)image_ptr) == UBOOT_IMG_HDR_MAGIC) {
101+
/* Note: Could parse header and get load_address at 0x10 */
102+
103+
/* Skip 64 bytes (size of Legacy format image header) */
104+
os_image.fw_base += UBOOT_IMG_HDR_SZ;
105+
os_image.fw_size -= UBOOT_IMG_HDR_SZ;
106+
}
107+
}
108+
91109
#ifdef EXT_FLASH
92110
/* Load image to RAM */
93111
if (PART_IS_EXT(&os_image)) {
94112
ext_flash_read((uintptr_t)os_image.fw_base,
95-
(uint8_t*)WOLFBOOT_LOAD_ADDRESS,
113+
(uint8_t*)load_address,
96114
os_image.fw_size);
97115
}
98116
#endif
99117

118+
#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;
123+
}
124+
#endif
125+
100126
hal_prepare_boot();
101-
do_boot((void *)WOLFBOOT_LOAD_ADDRESS);
127+
#ifdef MMU
128+
do_boot((uint32_t*)load_address, (uint32_t*)dts_address);
129+
#else
130+
do_boot((uint32_t*)load_address);
131+
#endif
102132
}

0 commit comments

Comments
 (0)