Skip to content

Commit

Permalink
risc-v/virt: enable gradeful shutdown in kernel build
Browse files Browse the repository at this point in the history
This enables graceful shutdown via `poweroff` command in `knsh64`
and `knsh32` configs.

Signed-off-by: Yanfeng Liu <yfliu2008@qq.com>
  • Loading branch information
yf13 authored and anchao committed May 7, 2024
1 parent c352b04 commit c9a2e4a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
1 change: 1 addition & 0 deletions boards/risc-v/qemu-rv/rv-virt/configs/knsh32/defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ CONFIG_ARCH_USE_MMU=y
CONFIG_ARCH_USE_MPU=y
CONFIG_ARCH_USE_S_MODE=y
CONFIG_BINFMT_ELF_EXECUTABLE=y
CONFIG_BOARDCTL_POWEROFF=y
CONFIG_BOARD_LOOPSPERMSEC=6366
CONFIG_BUILD_KERNEL=y
CONFIG_DEBUG_ASSERTIONS=y
Expand Down
2 changes: 1 addition & 1 deletion boards/risc-v/qemu-rv/rv-virt/configs/knsh64/defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ CONFIG_ARCH_USE_MMU=y
CONFIG_ARCH_USE_MPU=y
CONFIG_ARCH_USE_S_MODE=y
CONFIG_BINFMT_ELF_EXECUTABLE=y
CONFIG_BOARDCTL_POWEROFF=y
CONFIG_BOARD_LOOPSPERMSEC=6366
CONFIG_BUILD_KERNEL=y
CONFIG_DEBUG_ASSERTIONS=y
Expand All @@ -62,7 +63,6 @@ CONFIG_INIT_MOUNT_FSTYPE="hostfs"
CONFIG_INIT_MOUNT_SOURCE=""
CONFIG_INIT_MOUNT_TARGET="/system"
CONFIG_INIT_STACKSIZE=3072
CONFIG_INTELHEX_BINARY=y
CONFIG_LIBC_ENVPATH=y
CONFIG_LIBC_EXECFUNCS=y
CONFIG_LIBC_PERROR_STDOUT=y
Expand Down
15 changes: 15 additions & 0 deletions boards/risc-v/qemu-rv/rv-virt/src/qemu_rv_appinit.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@

#include <sys/mount.h>

#include "riscv_internal.h"
#include "romfs.h"

/****************************************************************************
Expand Down Expand Up @@ -177,3 +178,17 @@ void board_late_initialize(void)

#endif
}

#ifdef CONFIG_BOARDCTL_POWEROFF
int board_power_off(int status)
{
#ifdef CONFIG_BUILD_KERNEL
riscv_sbi_system_reset(SBI_SRST_TYPE_SHUTDOWN, SBI_SRST_REASON_NONE);
#else
#warning "to be done"
#endif

UNUSED(status);
return 0;
}
#endif

0 comments on commit c9a2e4a

Please sign in to comment.