目次: Zephyr
Zephyrにはリブートを行う関数sys_reboot() が既に実装されており、アーキテクチャごとのリブート用関数sys_arch_reboot() を呼ぶ仕組みです。
// zephyr/subsys/power/reboot.c
void sys_reboot(int type)
{
(void)irq_lock();
#ifdef CONFIG_SYS_CLOCK_EXISTS
sys_clock_disable();
#endif
sys_arch_reboot(type); //★★アーキテクチャごとのリブート関数を呼ぶ
/* should never get here */
printk("Failed to reboot: spinning endlessly...\n");
for (;;) {
k_cpu_idle();
}
}
// zephyr/soc/riscv/riscv-privilege/virt/soc.c
/* Reboot machine */
#define FINISHER_REBOOT 0x7777
void sys_arch_reboot(int type)
{
volatile uint32_t *reg = (uint32_t *)SIFIVE_SYSCON_TEST;
*reg = FINISHER_REBOOT; //★★0x100000に0x00007777をWrite
ARG_UNUSED(type);
}
// zephyr/soc/riscv/riscv-privilege/virt/soc.h
#include <soc_common.h>
#include <devicetree.h>
#define SIFIVE_SYSCON_TEST 0x00100000 //★追加
#define RISCV_MTIME_BASE 0x0200BFF8
#define RISCV_MTIMECMP_BASE 0x02004000
実装は素直にsys_arch_reboot() を追加しただけです。そんなに難しくないですよね。
前回説明した通り、サンプルアプリのshellを使って動作確認します。
$ cmake -G Ninja -DBOARD=qemu_riscv32 ../samples/subsys/shell/shell_module/ $ ninja menuconfig ★★CONFIG_REBOOTとCONFIG_BOOT_BANNERを有効にする $ ninja run [0/1] To exit from QEMU enter: 'CTRL+a, x'[QEMU] CPU: riscv32 *** Booting Zephyr OS build v2.5.0-rc1-276-ge7d3bb714bc2 *** uart:~$ kernel reboot cold ★★↑ここでリブートされる *** Booting Zephyr OS build v2.5.0-rc1-276-ge7d3bb714bc2 *** uart:~$
無事リブートしました。本当にリブートしてるのか不安になるくらい速いです。Zephyrは起動時に何も言わないので、Linuxと比べるとリブートは簡素に見えますね。速いのは良いんだけど、感動がちょっと薄いのが難点かも?
< | 2021 | > | ||||
<< | < | 02 | > | >> | ||
日 | 月 | 火 | 水 | 木 | 金 | 土 |
- | 1 | 2 | 3 | 4 | 5 | 6 |
7 | 8 | 9 | 10 | 11 | 12 | 13 |
14 | 15 | 16 | 17 | 18 | 19 | 20 |
21 | 22 | 23 | 24 | 25 | 26 | 27 |
28 | - | - | - | - | - | - |
合計:
本日:
管理者: Katsuhiro Suzuki(katsuhiro( a t )katsuster.net)
This is Simple Diary 1.0
Copyright(C) Katsuhiro Suzuki 2006-2023.
Powered by PHP 8.2.15.
using GD bundled (2.1.0 compatible)(png support.)