Skip to content

Commit 1e35087

Browse files
dgarskedanielinux
authored andcommitted
NXP S32K14X improvements from customer testing
1 parent e7728d4 commit 1e35087

4 files changed

Lines changed: 69 additions & 18 deletions

File tree

hal/s32k1xx.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,12 @@ void hal_prepare_boot(void)
487487
#ifdef DEBUG_UART
488488
/* Wait for any pending UART transmission to complete */
489489
while (!(LPUART_STAT & LPUART_STAT_TC)) {}
490+
491+
/* Disable UART before jumping to application.
492+
* This gives the application a clean UART state to initialize from.
493+
* Without this, the application may have issues reinitializing the UART.
494+
*/
495+
LPUART_CTRL = 0;
490496
#endif
491497

492498
#ifdef WOLFBOOT_RESTORE_CLOCK

test-app/Makefile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,9 @@ endif
361361

362362
ifeq ($(TARGET),s32k1xx)
363363
LSCRIPT_TEMPLATE=ARM-s32k1xx.ld
364-
APP_OBJS+=../src/keystore.o
364+
ifneq ($(SIGN),NONE)
365+
APP_OBJS+=../src/keystore.o
366+
endif
365367
CFLAGS+=-DAPP_HAS_SYSTICK
366368
CFLAGS+=-DRAM_CODE -DDEBUG_UART
367369
endif

test-app/app_s32k1xx.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,12 +369,12 @@ static void print_partition_info(void)
369369

370370
static void print_keystore_info(void)
371371
{
372+
#ifndef WOLFBOOT_NO_SIGN
372373
uint32_t n_keys;
373374
int i;
374375

375376
printf("\r\n=== Keystore Information ===\r\n");
376377

377-
378378
n_keys = keystore_num_pubkeys();
379379
printf("Number of public keys: %lu\r\n", (unsigned long)n_keys);
380380
printf("Hash: %s\r\n", hash_type_name());
@@ -390,6 +390,10 @@ static void print_keystore_info(void)
390390
printf(" Data:\r\n");
391391
print_hex(keybuf, size, 0);
392392
}
393+
#else
394+
printf("\r\n=== Keystore Information ===\r\n");
395+
printf("Signing disabled (SIGN=NONE)\r\n");
396+
#endif /* !WOLFBOOT_NO_SIGN */
393397
}
394398

395399
/* ============== XMODEM Transfer ============== */

tools/scripts/nxp-s32k142-flash.sh

Lines changed: 55 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,15 @@ SKIP_BUILD=0
5555
SKIP_FLASH=0
5656
TEST_UPDATE=0
5757
TEST_SELFUPDATE=0
58+
TRIGGER_MAGIC=0
5859

5960
usage() {
6061
echo "Usage: $0 [OPTIONS]"
6162
echo ""
6263
echo "Options:"
6364
echo " --test-update Build test-update.srec with v2 image in update partition (use 'trigger' command to start update)"
6465
echo " --test-selfupdate Build test-selfupdate.srec with bootloader v1 + v2 bootloader update (use 'trigger' command to start update)"
66+
echo " --trigger-magic Include trigger magic bytes to auto-start update on boot (use with --test-update)"
6567
echo " --skip-build Skip the build step (use existing .srec)"
6668
echo " --skip-flash Skip flashing (just build)"
6769
echo " -h, --help Show this help message"
@@ -70,10 +72,11 @@ usage() {
7072
echo " MOUNT_PATH Override mount path (default: auto-detect)"
7173
echo ""
7274
echo "Examples:"
73-
echo " $0 # Build and flash factory.srec (v1 only)"
74-
echo " $0 --test-update # Build with v2 in update partition, use 'trigger' cmd"
75-
echo " $0 --test-selfupdate # Build with bootloader v2 update, tests self-update"
76-
echo " $0 --skip-flash # Build without flashing"
75+
echo " $0 # Build and flash factory.srec (v1 only)"
76+
echo " $0 --test-update # Build with v2 in update partition, use 'trigger' cmd"
77+
echo " $0 --test-update --trigger-magic # Build with v2 and auto-trigger update on boot"
78+
echo " $0 --test-selfupdate # Build with bootloader v2 update, tests self-update"
79+
echo " $0 --skip-flash # Build without flashing"
7780
exit 0
7881
}
7982

@@ -89,6 +92,10 @@ while [[ $# -gt 0 ]]; do
8992
SREC_FILE="test-selfupdate.srec"
9093
shift
9194
;;
95+
--trigger-magic)
96+
TRIGGER_MAGIC=1
97+
shift
98+
;;
9299
--skip-build)
93100
SKIP_BUILD=1
94101
shift
@@ -293,7 +300,11 @@ if [ $SKIP_BUILD -eq 0 ]; then
293300
echo -e "${GREEN}Build successful: test-selfupdate.srec${NC}"
294301

295302
elif [ $TEST_UPDATE -eq 1 ]; then
296-
echo -e "${GREEN}[2/3] Building test-update.srec (v1 boot + v2 update, no trigger)...${NC}"
303+
if [ $TRIGGER_MAGIC -eq 1 ]; then
304+
echo -e "${GREEN}[2/3] Building test-update.srec (v1 boot + v2 update + trigger magic)...${NC}"
305+
else
306+
echo -e "${GREEN}[2/3] Building test-update.srec (v1 boot + v2 update, no trigger)...${NC}"
307+
fi
297308
make clean
298309
make factory.srec
299310

@@ -307,14 +318,38 @@ if [ $SKIP_BUILD -eq 0 ]; then
307318
echo " wolfboot.bin @ 0x0"
308319
echo " image_v1_signed.bin @ ${WOLFBOOT_PARTITION_BOOT_ADDRESS} (boot partition)"
309320
echo " image_v2_signed.bin @ ${WOLFBOOT_PARTITION_UPDATE_ADDRESS} (update partition)"
310-
echo ""
311-
echo -e "${YELLOW}NOTE: No trigger magic - use test-app 'trigger' command to start update${NC}"
312321

313-
./tools/bin-assemble/bin-assemble \
314-
test-update.bin \
315-
0x0 wolfboot.bin \
316-
${WOLFBOOT_PARTITION_BOOT_ADDRESS} test-app/image_v1_signed_backup.bin \
317-
${WOLFBOOT_PARTITION_UPDATE_ADDRESS} test-app/image_v2_signed.bin
322+
if [ $TRIGGER_MAGIC -eq 1 ]; then
323+
# Calculate trigger magic address: end of update partition - 5 bytes
324+
# Update partition end = UPDATE_ADDRESS + PARTITION_SIZE
325+
# Trigger magic "pBOOT" (5 bytes) goes at end - 5
326+
TRIGGER_ADDRESS=$(printf "0x%X" $(( ${WOLFBOOT_PARTITION_UPDATE_ADDRESS} + ${WOLFBOOT_PARTITION_SIZE} - 5 )))
327+
echo " trigger_magic.bin @ ${TRIGGER_ADDRESS} (auto-trigger update)"
328+
echo ""
329+
echo -e "${CYAN}NOTE: Update will start automatically on first boot${NC}"
330+
331+
# Create trigger magic file
332+
echo -n "pBOOT" > trigger_magic.bin
333+
334+
./tools/bin-assemble/bin-assemble \
335+
test-update.bin \
336+
0x0 wolfboot.bin \
337+
${WOLFBOOT_PARTITION_BOOT_ADDRESS} test-app/image_v1_signed_backup.bin \
338+
${WOLFBOOT_PARTITION_UPDATE_ADDRESS} test-app/image_v2_signed.bin \
339+
${TRIGGER_ADDRESS} trigger_magic.bin
340+
341+
# Cleanup trigger magic file
342+
rm -f trigger_magic.bin
343+
else
344+
echo ""
345+
echo -e "${YELLOW}NOTE: No trigger magic - use test-app 'trigger' command to start update${NC}"
346+
347+
./tools/bin-assemble/bin-assemble \
348+
test-update.bin \
349+
0x0 wolfboot.bin \
350+
${WOLFBOOT_PARTITION_BOOT_ADDRESS} test-app/image_v1_signed_backup.bin \
351+
${WOLFBOOT_PARTITION_UPDATE_ADDRESS} test-app/image_v2_signed.bin
352+
fi
318353

319354
# Convert to srec
320355
echo -e "${CYAN}Converting to test-update.srec...${NC}"
@@ -325,10 +360,14 @@ if [ $SKIP_BUILD -eq 0 ]; then
325360

326361
echo -e "${GREEN}Build successful: test-update.srec${NC}"
327362
echo ""
328-
echo -e "${CYAN}After boot, use these test-app commands:${NC}"
329-
echo " status - Show partition info (should show v1 boot, v2 update)"
330-
echo " trigger - Set update flag and reboot"
331-
echo " reboot - Reboot to start update"
363+
if [ $TRIGGER_MAGIC -eq 1 ]; then
364+
echo -e "${CYAN}Update will start automatically on boot.${NC}"
365+
else
366+
echo -e "${CYAN}After boot, use these test-app commands:${NC}"
367+
echo " status - Show partition info (should show v1 boot, v2 update)"
368+
echo " trigger - Set update flag and reboot"
369+
echo " reboot - Reboot to start update"
370+
fi
332371
else
333372
echo -e "${GREEN}[2/3] Building factory.srec...${NC}"
334373
make clean

0 commit comments

Comments
 (0)