Skip to content

Commit 9a23340

Browse files
committed
Cleanups
1 parent aaba142 commit 9a23340

6 files changed

Lines changed: 36 additions & 114 deletions

File tree

arch.mk

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ ifeq ($(ARCH),AARCH64)
8787
CFLAGS+=-DWOLFBOOT_DUALBOOT
8888
# Support detection and skip of U-Boot legacy header
8989
CFLAGS+=-DWOLFBOOT_UBOOT_LEGACY
90+
# PLM owns RVBAR on Versal in JTAG boot; skip RVBAR writes
91+
CFLAGS+=-DSKIP_RVBAR=1
9092
endif
9193

9294
ifeq ($(TARGET),nxp_ls1028a)

docs/Targets.md

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2308,7 +2308,7 @@ Typical boot timing with ECC384/SHA384 signing:
23082308

23092309
### SD Card Boot
23102310

2311-
wolfBoot supports booting from SD card on the VMK180 using the Cadence SDHCI controller. This enables A/B partition-based firmware updates from GPT partitions on the SD card.
2311+
wolfBoot supports booting from SD card on the VMK180 using the Arasan SDHCI controller. This enables A/B partition-based firmware updates from MBR partitions on the SD card.
23122312

23132313
#### SD Card Partition Layout
23142314

@@ -2334,8 +2334,8 @@ make
23342334
Key differences from QSPI configuration:
23352335
- `DISK_SDCARD=1` - Enable SD card support via SDHCI driver
23362336
- `EXT_FLASH=0` - Disable QSPI flash
2337-
- `BOOT_PART_A=2` - Primary firmware on partition 2
2338-
- `BOOT_PART_B=3` - Update firmware on partition 3
2337+
- `BOOT_PART_A=1` - Primary firmware on partition 2 (OFP_A, 0-based index 1)
2338+
- `BOOT_PART_B=2` - Update firmware on partition 3 (OFP_B, 0-based index 2)
23392339

23402340
#### Building and Provisioning
23412341

@@ -2348,7 +2348,7 @@ Key differences from QSPI configuration:
23482348
This creates:
23492349
- `wolfboot.elf` - wolfBoot bootloader
23502350
- `BOOT.BIN` - Complete boot image for partition 1
2351-
- `sdcard.img` - GPT-partitioned SD card image with signed test apps
2351+
- `sdcard.img` - MBR-partitioned SD card image with signed test apps
23522352
- `test-app/image_v1_signed.bin` - Signed primary firmware
23532353
- `test-app/image_v2_signed.bin` - Signed update firmware
23542354

@@ -2375,7 +2375,7 @@ sudo umount /mnt
23752375
3. **Verify partitions:**
23762376

23772377
```sh
2378-
sudo sgdisk -p /dev/sdX
2378+
sudo fdisk -l /dev/sdX
23792379
```
23802380

23812381
#### Boot Mode Selection
@@ -2392,7 +2392,6 @@ wolfBoot Secure Boot - AMD Versal
23922392
Current EL: 2
23932393
SDHCI: SDCard mode
23942394
...
2395-
Boot partition: A (2)
23962395
Firmware Valid
23972396
Booting at 0x10000000
23982397
```

hal/versal.c

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1151,36 +1151,17 @@ static void qspi_init(void)
11511151
* ============================================================================
11521152
*/
11531153

1154-
/* Very early debug: write single char directly to UART (no init needed)
1155-
* Use this to confirm wolfBoot is running before any initialization */
1156-
static void uart_write_char_direct(char c)
1157-
{
1158-
volatile uint32_t *uart_fr = (volatile uint32_t*)(DEBUG_UART_BASE + 0x18);
1159-
volatile uint32_t *uart_dr = (volatile uint32_t*)(DEBUG_UART_BASE + 0x00);
1160-
/* Wait for TX FIFO not full */
1161-
while ((*uart_fr) & (1 << 5))
1162-
;
1163-
*uart_dr = c;
1164-
}
1165-
1166-
static void uart_write_str_direct(const char *s)
1167-
{
1168-
while (*s) {
1169-
if (*s == '\n')
1170-
uart_write_char_direct('\r');
1171-
uart_write_char_direct(*s++);
1172-
}
1173-
}
1174-
11751154
void hal_init(void)
11761155
{
11771156
uart_init();
11781157

11791158
#if defined(DEBUG_UART) && defined(__WOLFBOOT)
1180-
uart_write_str_direct(
1159+
wolfBoot_printf(
11811160
"\n========================================\n"
11821161
"wolfBoot Secure Boot - AMD Versal\n"
1162+
#ifndef WOLFBOOT_REPRODUCIBLE_BUILD
11831163
"Build: " __DATE__ " " __TIME__ "\n"
1164+
#endif
11841165
"========================================\n");
11851166
wolfBoot_printf("Current EL: %d\n", current_el());
11861167
#endif
@@ -1697,4 +1678,3 @@ void sdhci_platform_set_bus_mode(int is_emmc)
16971678

16981679

16991680
#endif /* TARGET_versal */
1700-

src/boot_aarch64.c

Lines changed: 24 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -200,104 +200,44 @@ void RAMFUNCTION arch_reboot(void)
200200
#endif
201201

202202
/* ============================================================================
203-
* Exception Handlers for EL2 (DEBUG_HARDFAULT support)
203+
* Exception Handlers for EL2 (optional DEBUG_HARDFAULT)
204204
* ============================================================================
205-
* These handlers print diagnostic information when exceptions occur.
206-
* ESR_EL2 - Exception Syndrome Register (cause of exception)
207-
* ELR_EL2 - Exception Link Register (address that caused exception)
208-
* FAR_EL2 - Fault Address Register (for data/instruction aborts)
209205
*/
210206

211-
#if defined(DEBUG_UART) && defined(EL2_HYPERVISOR)
207+
#if defined(DEBUG_HARDFAULT) && defined(DEBUG_UART) && defined(EL2_HYPERVISOR)
212208

213-
/* Read EL2 exception registers */
214-
static inline uint64_t read_esr_el2(void) {
215-
uint64_t val;
216-
__asm__ volatile("mrs %0, ESR_EL2" : "=r"(val));
217-
return val;
218-
}
219-
220-
static inline uint64_t read_elr_el2(void) {
221-
uint64_t val;
222-
__asm__ volatile("mrs %0, ELR_EL2" : "=r"(val));
223-
return val;
224-
}
209+
#define READ_SYSREG(_out, _reg) __asm__ volatile("mrs %0, " #_reg : "=r"(_out))
225210

226-
static inline uint64_t read_far_el2(void) {
227-
uint64_t val;
228-
__asm__ volatile("mrs %0, FAR_EL2" : "=r"(val));
229-
return val;
230-
}
231-
232-
/* Decode ESR exception class */
233-
static const char* decode_ec(uint32_t ec) {
234-
switch (ec) {
235-
case 0x00: return "Unknown";
236-
case 0x01: return "WFI/WFE trapped";
237-
case 0x07: return "SVE/SIMD/FP trapped";
238-
case 0x0E: return "Illegal execution state";
239-
case 0x15: return "SVC in AArch64";
240-
case 0x16: return "HVC in AArch64";
241-
case 0x17: return "SMC in AArch64";
242-
case 0x20: return "Inst abort (lower EL)";
243-
case 0x21: return "Inst abort (same EL)";
244-
case 0x22: return "PC alignment fault";
245-
case 0x24: return "Data abort (lower EL)";
246-
case 0x25: return "Data abort (same EL)";
247-
case 0x26: return "SP alignment fault";
248-
case 0x2C: return "FP exception";
249-
case 0x2F: return "SError";
250-
case 0x30: return "Breakpoint (lower EL)";
251-
case 0x31: return "Breakpoint (same EL)";
252-
case 0x32: return "Software step (lower EL)";
253-
case 0x33: return "Software step (same EL)";
254-
case 0x34: return "Watchpoint (lower EL)";
255-
case 0x35: return "Watchpoint (same EL)";
256-
case 0x3C: return "BRK instruction";
257-
default: return "Other";
258-
}
259-
}
211+
static void print_exception_info(const char *type)
212+
{
213+
uint64_t esr, elr, far;
260214

261-
static void print_exception_info(const char *type) {
262-
uint64_t esr = read_esr_el2();
263-
uint64_t elr = read_elr_el2();
264-
uint64_t far = read_far_el2();
265-
uint32_t ec = (esr >> 26) & 0x3F;
266-
uint32_t iss = esr & 0x1FFFFFF;
215+
READ_SYSREG(esr, ESR_EL2);
216+
READ_SYSREG(elr, ELR_EL2);
217+
READ_SYSREG(far, FAR_EL2);
267218

268219
wolfBoot_printf("\n\n*** %s EXCEPTION ***\n", type);
269220
wolfBoot_printf("ESR_EL2: 0x%08x%08x\n", (uint32_t)(esr >> 32), (uint32_t)esr);
270-
wolfBoot_printf(" EC (Exception Class): 0x%x - %s\n", ec, decode_ec(ec));
271-
wolfBoot_printf(" ISS (Syndrome): 0x%x\n", iss);
272-
wolfBoot_printf("ELR_EL2 (fault addr): 0x%08x%08x\n", (uint32_t)(elr >> 32), (uint32_t)elr);
273-
wolfBoot_printf("FAR_EL2 (access addr): 0x%08x%08x\n", (uint32_t)(far >> 32), (uint32_t)far);
221+
wolfBoot_printf("ELR_EL2: 0x%08x%08x\n", (uint32_t)(elr >> 32), (uint32_t)elr);
222+
wolfBoot_printf("FAR_EL2: 0x%08x%08x\n", (uint32_t)(far >> 32), (uint32_t)far);
274223
wolfBoot_printf("*** SYSTEM HALTED ***\n");
275224
}
276225

277-
void SynchronousInterrupt(void) {
278-
print_exception_info("SYNCHRONOUS");
279-
while(1) { __asm__ volatile("wfi"); }
280-
}
281-
282-
void IRQInterrupt(void) {
283-
print_exception_info("IRQ");
284-
while(1) { __asm__ volatile("wfi"); }
285-
}
286-
287-
void FIQInterrupt(void) {
288-
print_exception_info("FIQ");
289-
while(1) { __asm__ volatile("wfi"); }
226+
static void hardfault_halt(const char *type)
227+
{
228+
print_exception_info(type);
229+
while (1) { __asm__ volatile("wfi"); }
290230
}
291231

292-
void SErrorInterrupt(void) {
293-
print_exception_info("SERROR");
294-
while(1) { __asm__ volatile("wfi"); }
295-
}
232+
void SynchronousInterrupt(void) { hardfault_halt("SYNCHRONOUS"); }
233+
void IRQInterrupt(void) { hardfault_halt("IRQ"); }
234+
void FIQInterrupt(void) { hardfault_halt("FIQ"); }
235+
void SErrorInterrupt(void) { hardfault_halt("SERROR"); }
296236

297237
#else
298238
/* Simple stubs when debug not enabled */
299-
void SynchronousInterrupt(void) { while(1); }
300-
void IRQInterrupt(void) { while(1); }
301-
void FIQInterrupt(void) { while(1); }
302-
void SErrorInterrupt(void) { while(1); }
303-
#endif /* DEBUG_UART && EL2_HYPERVISOR */
239+
void SynchronousInterrupt(void) { while (1) { __asm__ volatile("wfi"); } }
240+
void IRQInterrupt(void) { while (1) { __asm__ volatile("wfi"); } }
241+
void FIQInterrupt(void) { while (1) { __asm__ volatile("wfi"); } }
242+
void SErrorInterrupt(void) { while (1) { __asm__ volatile("wfi"); } }
243+
#endif /* DEBUG_HARDFAULT && DEBUG_UART && EL2_HYPERVISOR */

src/boot_aarch64_start.S

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,7 @@ InitEL1:
467467

468468
/* Assembly startup error handler */
469469
error:
470+
wfi
470471
b error
471472

472473

test-app/app_versal.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ void main(void)
5252
wolfBoot_printf("BOOT: Version: %d (0x%08x)\n", boot_version, boot_version);
5353
wolfBoot_printf("UPDATE: Version: %d (0x%08x)\n", update_version, update_version);
5454
#else
55-
wolfBoot_printf("Boot mode: Disk-based (GPT partitions)\n");
55+
wolfBoot_printf("Boot mode: Disk-based (GPT/MBR partitions)\n");
5656
#endif
5757

5858
wolfBoot_printf("Application running successfully!\n");

0 commit comments

Comments
 (0)