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

Anup Patel anup at brainfault.org
Sun Jul 20 08:21:11 PDT 2025


On Tue, Jun 24, 2025 at 2:13 PM 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>
> ---
>  firmware/payloads/test_main.c | 8 ++++++++
>  1 file changed, 8 insertions(+)
>
> diff --git a/firmware/payloads/test_main.c b/firmware/payloads/test_main.c
> index 194dbbe6..021bc3b8 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,6 +61,7 @@ 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");
> +       sbi_ecall_shutdown();
>
>         while (1)
>                 wfi();

Drop the while loop and also print an error message
if sbi_ecall_shutdown() fails.

Regards,
Anup



More information about the opensbi mailing list