みつきんのメモ

組み込みエンジニアです。Interface誌で「Yocto Projectではじめる 組み込みLinux開発入門」連載中

RISC-V QEMU

はじめに

RISC-VのQEMUを動かしてみる。

依存パッケージのインストール

$ sudo apt-get install gcc libc6-dev pkg-config bridge-utils uml-utilities zlib1g-dev libglib2.0-dev autoconf automake libtool libsdl1.2-dev

ビルド

ここを参考にビルド

$ git clone --recursive https://github.com/riscv/riscv-qemu.git
$ cd riscv-qemu
$ ./configure --target-list=riscv64-softmmu,riscv32-softmmu
$ make -j$(nproc)
$ sudo make install

HiFive1のバイナリを実行してみる

platformio

platformioでHiFive1向けのバイナリを作成する。

$ platformio init --board freedom-e300-hifive1

src/hello.cを次の内容で作成する。

#include <stdio.h>

int main(int argc, char *argv[])
{
    printf("hello world\n");
    return 0;
}

次のコマンドでビルド

$ platformio run

.pioenvs/freedom-e300-hifive1/firmware.elfがビルドされたバイナリ。

これを実行してみる。

$ qemu-system-riscv32 -nographic -machine sifive_e -kernel .pioenvs/freedom-e300-hifive1/firmware.elf
core freq at 11644342 Hz
hello world
Progam has exited with code:0x00000000

Ctrl+a xqemuを終了。