[PATCH v2] firmware: payload: test: Add SBI shutdown call after test message

Anup Patel anup at brainfault.org
Mon Jul 21 04:06:16 PDT 2025


On Mon, Jul 21, 2025 at 6:39 AM Xiang W <wxjstz at 126.com> wrote:
>
> Previously, 'make run' would hang in WFI after printing the test message.
> This commit adds an SBI ecall to ensure QEMU exits cleanly after the test
> payload runs.
>
> Signed-off-by: Xiang W <wxjstz at 126.com>

LGTM.

Reviewed-by: Anup Patel <anup at brainfault.org>

Applied this patch to the riscv/opensbi repo.

Thanks,
Anup

> ---
> v2 changes:
> - Remove the while loop and print the error message as suggested
>   by Anup.
>
>  firmware/payloads/test_main.c | 12 +++++++++---
>  1 file changed, 9 insertions(+), 3 deletions(-)
>
> diff --git a/firmware/payloads/test_main.c b/firmware/payloads/test_main.c
> index 194dbbe6..03f6ba39 100644
> --- a/firmware/payloads/test_main.c
> +++ b/firmware/payloads/test_main.c
> @@ -46,6 +46,13 @@ static inline void sbi_ecall_console_puts(const char *str)
>                   sbi_strlen(str), (unsigned long)str, 0, 0, 0, 0);
>  }
>
> +static inline void sbi_ecall_shutdown(void)
> +{
> +       sbi_ecall(SBI_EXT_SRST, SBI_EXT_SRST_RESET,
> +                 SBI_SRST_RESET_TYPE_SHUTDOWN, SBI_SRST_RESET_REASON_NONE,
> +                 0, 0, 0, 0);
> +}
> +
>  #define wfi()                                             \
>         do {                                              \
>                 __asm__ __volatile__("wfi" ::: "memory"); \
> @@ -54,7 +61,6 @@ static inline void sbi_ecall_console_puts(const char *str)
>  void test_main(unsigned long a0, unsigned long a1)
>  {
>         sbi_ecall_console_puts("\nTest payload running\n");
> -
> -       while (1)
> -               wfi();
> +       sbi_ecall_shutdown();
> +       sbi_ecall_console_puts("sbi_ecall_shutdown failed to execute.\n");
>  }
> --
> 2.47.2
>



More information about the opensbi mailing list