|
14 | 14 | # Use uart-monitor PTY proxy paths for serial access (allows concurrent monitoring) |
15 | 15 | HSS_TTY="${HSS_TTY:-/tmp/uart-monitor/pty/POLARFIRE_SOC_UART0}" |
16 | 16 | WOLFBOOT_TTY="${WOLFBOOT_TTY:-/tmp/uart-monitor/pty/POLARFIRE_SOC_UART1}" |
17 | | -BLOCK_DEV="${BLOCK_DEV:-/dev/sde}" |
| 17 | +BLOCK_DEV="${BLOCK_DEV:-/dev/sdf}" |
18 | 18 | PI_HOST="${PI_HOST:-pi@Pi4}" |
19 | 19 | GPIO_PIN="${GPIO_PIN:-20}" |
20 | 20 | BAUD_RATE="${BAUD_RATE:-115200}" |
@@ -1007,19 +1007,52 @@ build_wolfboot_l2lim() { |
1007 | 1007 | } |
1008 | 1008 |
|
1009 | 1009 | # Build and sign test-app for current config |
| 1010 | +# Signs using the same SIGN_ENV variables that the Makefile uses. |
| 1011 | +# We call the sign tool directly (not via make) to avoid triggering a |
| 1012 | +# wolfboot.elf rebuild that would lose the UART_QSPI_PROGRAM=1 override. |
1010 | 1013 | build_sign_testapp() { |
1011 | 1014 | local strip_debug="${1:-0}" |
1012 | 1015 |
|
1013 | | - log_info "Building test-app..." |
1014 | | - make test-app/image.elf |
| 1016 | + # Determine image format from .config: ELF or raw binary |
| 1017 | + local use_elf |
| 1018 | + use_elf=$(grep -m1 '^ELF' .config | sed 's/.*[?]*=//') |
| 1019 | + use_elf="${use_elf:-0}" |
| 1020 | + |
| 1021 | + # Build test-app directly via its own Makefile to avoid the top-level |
| 1022 | + # Makefile's wolfboot.elf dependency chain (which has a FORCE target |
| 1023 | + # that could trigger a wolfboot rebuild and lose UART_QSPI_PROGRAM=1). |
| 1024 | + # wolfboot.elf and include/target.h are already built by build_wolfboot_*. |
| 1025 | + local boot_img |
| 1026 | + if [[ "$use_elf" -eq 1 ]]; then |
| 1027 | + boot_img="test-app/image.elf" |
| 1028 | + log_info "Building test-app (ELF)..." |
| 1029 | + make -C test-app WOLFBOOT_ROOT="$PWD" image.elf |
| 1030 | + else |
| 1031 | + boot_img="test-app/image.bin" |
| 1032 | + log_info "Building test-app (BIN)..." |
| 1033 | + make -C test-app WOLFBOOT_ROOT="$PWD" image.bin |
| 1034 | + fi |
1015 | 1035 |
|
1016 | | - if [[ "$strip_debug" -eq 1 ]]; then |
| 1036 | + if [[ "$strip_debug" -eq 1 ]] && [[ "$use_elf" -eq 1 ]]; then |
1017 | 1037 | log_info "Stripping debug symbols (M-Mode L2 Scratch fit)..." |
1018 | 1038 | riscv64-unknown-elf-strip --strip-debug test-app/image.elf |
1019 | 1039 | fi |
1020 | 1040 |
|
1021 | | - log_info "Signing test-app with ECC384 + SHA384..." |
1022 | | - ./tools/keytools/sign --ecc384 --sha384 test-app/image.elf \ |
| 1041 | + # Read signing parameters from .config (same values the Makefile uses) |
| 1042 | + # Config lines may use = or ?= assignment |
| 1043 | + local hdr_size partition_size sector_size |
| 1044 | + hdr_size=$(grep -m1 '^IMAGE_HEADER_SIZE' .config | sed 's/.*[?]*=//') |
| 1045 | + hdr_size="${hdr_size:-512}" |
| 1046 | + partition_size=$(grep -m1 '^WOLFBOOT_PARTITION_SIZE' .config | sed 's/.*[?]*=//') |
| 1047 | + sector_size=$(grep -m1 '^WOLFBOOT_SECTOR_SIZE' .config | sed 's/.*[?]*=//') |
| 1048 | + |
| 1049 | + local img_size |
| 1050 | + img_size=$(stat -c%s "$boot_img") |
| 1051 | + log_info "Signing $boot_img (${img_size} bytes, IMAGE_HEADER_SIZE=${hdr_size})..." |
| 1052 | + IMAGE_HEADER_SIZE="$hdr_size" \ |
| 1053 | + WOLFBOOT_PARTITION_SIZE="$partition_size" \ |
| 1054 | + WOLFBOOT_SECTOR_SIZE="$sector_size" \ |
| 1055 | + ./tools/keytools/sign --ecc384 --sha384 "$boot_img" \ |
1023 | 1056 | wolfboot_signing_private_key.der 1 |
1024 | 1057 |
|
1025 | 1058 | log_success "Test-app built and signed: test-app/image_v1_signed.bin" |
@@ -1144,11 +1177,19 @@ run_qspi() { |
1144 | 1177 | unmount_block_device |
1145 | 1178 | echo "" |
1146 | 1179 |
|
1147 | | - # Step 4: Power cycle and flash test-app via UART QSPI programmer |
1148 | | - log_info "=== Step 4: Power cycling and flashing test-app via UART QSPI ===" |
| 1180 | + # Step 4: Flash test-app via UART QSPI programmer |
| 1181 | + # Start QSPI programmer FIRST (it waits for the prompt), then power cycle. |
| 1182 | + # wolfBoot has a 3-second window for 'P' after boot. |
| 1183 | + log_info "=== Step 4: Flashing test-app via UART QSPI ===" |
| 1184 | + flash_qspi_testapp "test-app/image_v1_signed.bin" "$QSPI_BOOT_OFFSET" "$WOLFBOOT_TTY" & |
| 1185 | + local qspi_pid=$! |
| 1186 | + sleep 1 # Let python script open serial port |
1149 | 1187 | power_cycle |
1150 | | - sleep 2 |
1151 | | - flash_qspi_testapp "test-app/image_v1_signed.bin" "$QSPI_BOOT_OFFSET" "$WOLFBOOT_TTY" |
| 1188 | + log_info "Waiting for QSPI programmer to complete..." |
| 1189 | + wait $qspi_pid || { |
| 1190 | + log_error "QSPI flash failed" |
| 1191 | + exit 1 |
| 1192 | + } |
1152 | 1193 | echo "" |
1153 | 1194 |
|
1154 | 1195 | # Step 5: Power cycle and capture boot output |
@@ -1191,11 +1232,19 @@ run_l2lim() { |
1191 | 1232 | unmount_block_device |
1192 | 1233 | echo "" |
1193 | 1234 |
|
1194 | | - # Step 4: Power cycle and flash test-app via UART QSPI programmer |
1195 | | - log_info "=== Step 4: Power cycling and flashing test-app via UART QSPI ===" |
| 1235 | + # Step 4: Flash test-app via UART QSPI programmer |
| 1236 | + # Start QSPI programmer FIRST (it waits for the prompt), then power cycle. |
| 1237 | + # wolfBoot has a 3-second window for 'P' after boot. |
| 1238 | + log_info "=== Step 4: Flashing test-app via UART QSPI ===" |
| 1239 | + flash_qspi_testapp "test-app/image_v1_signed.bin" "$QSPI_BOOT_OFFSET" "$WOLFBOOT_TTY" & |
| 1240 | + local qspi_pid=$! |
| 1241 | + sleep 1 # Let python script open serial port |
1196 | 1242 | power_cycle |
1197 | | - sleep 2 |
1198 | | - flash_qspi_testapp "test-app/image_v1_signed.bin" "$QSPI_BOOT_OFFSET" "$WOLFBOOT_TTY" |
| 1243 | + log_info "Waiting for QSPI programmer to complete..." |
| 1244 | + wait $qspi_pid || { |
| 1245 | + log_error "QSPI flash failed" |
| 1246 | + exit 1 |
| 1247 | + } |
1199 | 1248 | echo "" |
1200 | 1249 |
|
1201 | 1250 | # Step 5: Power cycle and capture boot output |
@@ -1419,55 +1468,65 @@ run_mmode() { |
1419 | 1468 | local output_file="${2:-mmode_output_$(date +%Y%m%d_%H%M%S).log}" |
1420 | 1469 |
|
1421 | 1470 | log_info "Starting M-Mode wolfBoot programming workflow..." |
1422 | | - log_info "Mode: JTAG programming to eNVM (bootmode 1)" |
| 1471 | + log_info "Mode: JTAG programming to eNVM + UART QSPI for test-app" |
1423 | 1472 | echo "" |
1424 | 1473 |
|
1425 | | - # Step 1: Build (if not skipped) |
| 1474 | + # Step 1: Build wolfBoot and test-app |
1426 | 1475 | if [[ "$skip_build" -eq 0 ]]; then |
1427 | 1476 | log_info "=== Step 1: Building wolfBoot (M-Mode) ===" |
1428 | 1477 | build_wolfboot_mmode |
1429 | 1478 | echo "" |
| 1479 | + |
| 1480 | + log_info "=== Step 2: Building and signing test-app ===" |
| 1481 | + build_sign_testapp 1 # strip_debug=1 for L2 Scratch fit |
| 1482 | + echo "" |
1430 | 1483 | else |
1431 | | - log_info "=== Step 1: Skipping build ===" |
| 1484 | + log_info "=== Steps 1-2: Skipping build ===" |
1432 | 1485 | if [[ ! -f "wolfboot.elf" ]]; then |
1433 | 1486 | log_error "wolfboot.elf not found. Cannot skip build." |
1434 | 1487 | exit 1 |
1435 | 1488 | fi |
1436 | 1489 | echo "" |
1437 | 1490 | fi |
1438 | 1491 |
|
1439 | | - # Step 2: Power on target (JTAG requires power) |
1440 | | - log_info "=== Step 2: Powering on target ===" |
| 1492 | + # Step 3: Power on target (JTAG requires power) |
| 1493 | + log_info "=== Step 3: Powering on target ===" |
1441 | 1494 | power_on |
1442 | 1495 | sleep 2 # Give device time to power up |
1443 | 1496 | echo "" |
1444 | 1497 |
|
1445 | | - # Step 3: Flash via JTAG |
1446 | | - log_info "=== Step 3: Flashing via JTAG ===" |
| 1498 | + # Step 4: Flash wolfBoot via JTAG |
| 1499 | + log_info "=== Step 4: Flashing wolfBoot via JTAG ===" |
1447 | 1500 | flash_jtag |
1448 | 1501 | echo "" |
1449 | 1502 |
|
1450 | | - # Step 4: Power cycle to boot with new firmware |
1451 | | - log_info "=== Step 4: Power cycling to boot new firmware ===" |
| 1503 | + # Step 5: Flash test-app via UART QSPI programmer |
| 1504 | + # Start the QSPI programmer FIRST (it waits for the prompt), then power cycle. |
| 1505 | + # wolfBoot has a 3-second window for 'P' after boot. |
| 1506 | + log_info "=== Step 5: Flashing test-app via UART QSPI ===" |
| 1507 | + flash_qspi_testapp "test-app/image_v1_signed.bin" "$QSPI_BOOT_OFFSET" "$MMODE_TTY" & |
| 1508 | + local qspi_pid=$! |
| 1509 | + sleep 1 # Let python script open serial port |
1452 | 1510 | power_off |
1453 | 1511 | sleep 1 |
1454 | 1512 | power_on |
| 1513 | + log_info "Waiting for QSPI programmer to complete..." |
| 1514 | + wait $qspi_pid || { |
| 1515 | + log_error "QSPI flash failed" |
| 1516 | + exit 1 |
| 1517 | + } |
1455 | 1518 | echo "" |
1456 | 1519 |
|
1457 | | - # Step 5: Capture M-Mode output (should show "wolfBoot Version: " if successful) |
1458 | | - log_info "=== Step 5: Capturing M-Mode output ===" |
1459 | | - log_info "Looking for 'wolfBoot Version:' in output..." |
| 1520 | + # Step 6: Power cycle and capture boot output (wolfBoot loads test-app from QSPI) |
| 1521 | + log_info "=== Step 6: Power cycling and capturing boot output ===" |
| 1522 | + power_off |
| 1523 | + sleep 1 |
| 1524 | + power_on |
| 1525 | + sleep 1 |
1460 | 1526 | capture_mmode_output "$output_file" |
1461 | 1527 | echo "" |
1462 | 1528 |
|
1463 | | - # Check if wolfBoot started successfully |
1464 | | - if grep -q "wolfBoot" "$output_file" 2>/dev/null; then |
1465 | | - log_success "=== M-Mode workflow completed successfully! ===" |
1466 | | - log_success "wolfBoot output detected in $output_file" |
1467 | | - else |
1468 | | - log_warn "=== M-Mode workflow completed ===" |
1469 | | - log_warn "No wolfBoot output detected - check $output_file for details" |
1470 | | - fi |
| 1529 | + check_test_result "$output_file" "M-Mode" |
1471 | 1530 | } |
1472 | 1531 |
|
1473 | 1532 | # Parse command line arguments |
|
0 commit comments