@@ -445,29 +445,34 @@ void do_boot(const uint32_t *app_offset)
445445 */
446446
447447#ifdef WOLFBOOT_RISCV_MMODE
448+ #ifdef WOLFBOOT_MMODE_SMODE_BOOT
448449 /*
449450 * M-mode to S-mode transition for booting Linux:
450451 * 1. Set up PMP to allow S-mode full memory access
451452 * 2. Delegate traps/interrupts to S-mode
452453 * 3. Use MRET to switch to S-mode and jump to kernel
453454 */
454- #ifdef DEBUG_BOOT
455- wolfBoot_printf ("Setting up M-mode to S-mode transition...\n" );
456- wolfBoot_printf (" PMP: Configuring for S-mode access\n" );
457- #endif
455+ wolfBoot_printf ("M->S transition: entry=0x%lx\n" , (unsigned long )app_offset );
458456 setup_pmp_for_smode ();
459-
460- #ifdef DEBUG_BOOT
461- wolfBoot_printf (" Delegating traps to S-mode\n" );
462- #endif
463457 delegate_traps_to_smode ();
464-
465- #ifdef DEBUG_BOOT
466- wolfBoot_printf (" Entering S-mode: entry=0x%lx, hartid=%lu, dtb=0x%lx\n" ,
467- (unsigned long )app_offset , hartid , dts_addr );
468- #endif
469458 /* This never returns */
470459 enter_smode ((unsigned long )app_offset , hartid , dts_addr );
460+ #else
461+ /*
462+ * Direct M-mode jump for bare-metal payloads (no S-mode transition).
463+ * Use this for test-apps; define WOLFBOOT_MMODE_SMODE_BOOT for Linux.
464+ */
465+ wolfBoot_printf ("M-mode direct jump to 0x%lx\n" , (unsigned long )app_offset );
466+ /* Drain UART before jumping */
467+ {
468+ volatile int i ;
469+ for (i = 0 ; i < 100000 ; i ++ ) {}
470+ }
471+ (void )hartid ;
472+ (void )dts_addr ;
473+ asm volatile ("jr %0" : : "r" (app_offset ));
474+ __builtin_unreachable ();
475+ #endif /* WOLFBOOT_MMODE_SMODE_BOOT */
471476
472477#elif __riscv_xlen == 64
473478 asm volatile (
0 commit comments