Kendryte K210(RISC-V NOMMU Processor)でnommu-Linuxを動かしてみる

Kendryte K210(RISC-V NOMMU Processor)でnommu-Linuxを動かしてみる。

はじめに

以前はuClinuxと呼ばれていましたが、現在(Linux Kernel2.6以降)はLinuxのメイン・ツリーに取り込まれており、buildrootを使えば簡単に動かすことができます。
今回は、K210を搭載した SipeedMaixduinoM5StickVでnommu-Linuxを動かす手順を説明します。

構築手順

$ git clone http://github.com/buildroot/buildroot
$ cd buildroot/

Maixduinoの場合

$ make sipeed_maixduino_defconfig

M5StickVの場合

$ make sipeed_maix_go_defconfig

Build

$ make -j$(nproc)

kflash

$ kflash -B maixduino -t -p /dev/ttyUSB0 output/images/loader.bin
[INFO] COM Port Selected Manually:  /dev/ttyUSB0
[INFO] Default baudrate is 115200 , later it may be changed to the value you set.
[INFO] Trying to Enter the ISP Mode...
[INFO] Greeting Message Detected, Start Downloading ISP
Downloading ISP: |=============================================| 100.0% 10kiB/s
[INFO] Booting From 0x80000000
[INFO] Wait For 0.1 second for ISP to Boot
[INFO] Boot to Flashmode Successfully
[INFO] Selected Flash:  On-Board
[INFO] Initialization flash Successfully
[INFO] Flash mode: DIO, Dual SPI serial throughput rates reach around 20 Mbps
Programming BIN: |=============================================| 100.0% 10kiB/s
[INFO] Rebooting...
[INFO] The ISP stub tells us the k210 is rebooting ...

M5StickVの場合

$ kflash -B goE -t -p /dev/ttyUSB0 output/images/loader.bin

起動時のコンソール出力

[    0.000000] Linux version 5.19.0 (developer@developer-Diginnos-PC) (riscv64-buildroot-linux-uclibc-gcc.br_real (Buildroot 2023.05-442-g157089d34d) 11.4.0, GNU ld (GNU Binutils) 2.39) #2 SMP Wed Jul 19 16:36:59 JST 2023
[    0.000000] Machine model: SiPeed MAIXDUINO
[    0.000000] earlycon: sifive0 at MMIO 0x0000000038000000 (options '115200n8')
[    0.000000] printk: bootconsole [sifive0] enabled
[    0.000000] Zone ranges:
[    0.000000]   DMA32    [mem 0x0000000080000000-0x00000000807fffff]
[    0.000000]   Normal   empty
[    0.000000] Movable zone start for each node
[    0.000000] Early memory node ranges
[    0.000000]   node   0: [mem 0x0000000080000000-0x00000000807fffff]
[    0.000000] Initmem setup node 0 [mem 0x0000000080000000-0x00000000807fffff]
[    0.000000] riscv: base ISA extensions acdfim
[    0.000000] riscv: ELF capabilities acdfim
[    0.000000] percpu: max_distance=0x16000 too large for vmalloc space 0x0
[    0.000000] percpu: Embedded 11 pages/cpu s15520 r0 d29536 u45056
[    0.000000] percpu: wasting 10 pages per chunk
[    0.000000] Built 1 zonelists, mobility grouping off.  Total pages: 2020
[    0.000000] Kernel command line: earlycon console=ttySIF0
[    0.000000] Dentry cache hash table entries: 1024 (order: 1, 8192 bytes, linear)
[    0.000000] Inode-cache hash table entries: 512 (order: 0, 4096 bytes, linear)
[    0.000000] mem auto-init: stack:off, heap alloc:off, heap free:off
[    0.000000] Memory: 6032K/8192K available (933K kernel code, 134K rwdata, 208K rodata, 529K init, 66K bss, 2160K reserved, 0K cma-reserved)
[    0.000000] rcu: Hierarchical RCU implementation.
[    0.000000] rcu: RCU calculated value of scheduler-enlistment delay is 25 jiffies.
[    0.000000] NR_IRQS: 64, nr_irqs: 64, preallocated irqs: 0
[    0.000000] riscv-intc: 64 local interrupts mapped
[    0.000000] plic: interrupt-controller@c000000: mapped 65 interrupts with 2 handlers for 4 contexts.
[    0.000000] rcu: srcu_init: Setting srcu_struct sizes based on contention.
[    0.000000] k210-clk: clock-controller: CPU running at 390 MHz
[    0.000000] clint: timer@2000000: timer running at 7800000 Hz
[    0.000000] clocksource: clint_clocksource: mask: 0xffffffffffffffff max_cycles: 0x3990be68b, max_idle_ns: 881590404272 ns
[    0.000001] sched_clock: 64 bits at 8MHz, resolution 128ns, wraps every 4398046511054ns
[    0.008263] Calibrating delay loop (skipped), value calculated using timer frequency.. 15.60 BogoMIPS (lpj=31200)
[    0.018252] pid_max: default: 4096 minimum: 301
[    0.022867] Mount-cache hash table entries: 512 (order: 0, 4096 bytes, linear)
[    0.029972] Mountpoint-cache hash table entries: 512 (order: 0, 4096 bytes, linear)
[    0.040213] rcu: Hierarchical SRCU implementation.
[    0.044271] rcu:     Max phase no-delay instances is 1000.
[    0.050273] smp: Bringing up secondary CPUs ...
[    0.055373] smp: Brought up 1 node, 2 CPUs
[    0.059526] devtmpfs: initialized
[    0.076656] clocksource: jiffies: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 7645041785100000 ns
[    0.085683] pinctrl core: initialized pinctrl subsystem
[    0.119637] clocksource: Switched to clocksource clint_clocksource
[    0.131861] workingset: timestamp_bits=62 max_order=11 bucket_order=0
[    0.172099] k210-sysctl 50440000.syscon: K210 system controller
[    0.188900] k210-rst 50440000.syscon:reset-controller: K210 reset controller
[    0.197086] cacheinfo: Unable to detect cache hierarchy for CPU 0
[    0.206417] spi spi1.0: setup: ignoring unsupported mode bits a00
[    0.212938] i2c_dev: i2c /dev entries driver
[    0.223147] k210-fpioa 502b0000.pinmux: K210 FPIOA pin controller
[    0.243120] 38000000.serial: ttySIF0 at MMIO 0x38000000 (irq = 40, base_baud = 24375000) is a SiFive UART v0
[    0.252281] printk: console [ttySIF0] enabled
[    0.252281] printk: console [ttySIF0] enabled
[    0.260894] printk: bootconsole [sifive0] disabled
[    0.260894] printk: bootconsole [sifive0] disabled
[    0.273356] panel@0 enforce active low on chipselect handle
[    0.290689] Freeing unused kernel image (initmem) memory: 524K
[    0.295821] This architecture does not have kernel memory protection.
[    0.302226] Run /init as init process
[    0.330460] init (1): drop_caches: 3
          __  _
         / / (_) ____   _   _ __  __
        / /  | ||  _ \ | | | |\ \/ /
       / /___| || | | || |_| | >  <
      /_____/|_||_| |_| \____|/_/\_\
    64-bits RISC-V Kendryte K210 NOMMU

~ #

おわり

K210はdual-core RISC-V 64bit, on-chip 8MB high-speed SRAMで
CPUスペック的には十分ですが、Linuxを動かすとFreeRAMサイスが
3M強程度となります
ネットで1万以下(7~9千円ぐらい)で購入できるのでnommu-Linuxの
勉強にはちょうどよい教材です。
今回はLinuxの起動(shellが動く)まででしたが、時間があれば(次は?)
SDカードやLCDパネル、カメラなんかも動かしてみたいと考えています