iTranslated by AI
Running Linux on TinyEMU (RISC-V Emulator)
I learned about the TinyEMU RISC-V emulator from an article titled "Running Linux on ESP32 by running a RISC-V emulator – inajob's various reviews" and I'm going to give it a try.
Verification Environment
- iMac (24-inch, M1, 2021)
- macOS Monterey 12.4
Preparing the Linux VM
To create a Linux environment on an M1 Mac, I'll use Multipass this time.
$ brew install --cask multipass
$ multipass version
multipass 1.10.1+mac
multipassd 1.10.1+mac
Let's create a VM right away (it seems like fewer resources would be sufficient).
$ multipass launch --cpus 2 --disk 8G --mem 4G --name tinyemu
Launched: tinyemu
$ multipass list
Name State IPv4 Image
tinyemu Running 192.168.64.2 Ubuntu 20.04 LTS
Now that the VM is up, let's run a command (uname -a) inside the VM.
$ multipass exec tinyemu -- uname -a
Linux tinyemu 5.4.0-122-generic #138-Ubuntu SMP Wed Jun 22 15:05:39 UTC 2022 aarch64 aarch64 aarch64 GNU/Linux
It seems to be working correctly.
Preparing TinyEMU
Let's make TinyEMU available on the Linux VM. First, log in to the VM.
$ multipass shell tinyemu
From here on, we will proceed on the VM created with Multipass.
Following the TinyEMU documentation, we will install the dependent libraries.
$ sudo apt-get install build-essential libssl-dev libcurl4-openssl-dev
As for SDL, we will build and install it from source by referring to the Installation - SDL Wiki. Note the following points:
- Use SDL1 (Reference: SourceCode - SDL Wiki) (since TinyEMU depends on SDL1)
- Specify
--prefix /usrwhen runningconfigureso that it is installed in/usr/include/SDL
$ git clone https://github.com/libsdl-org/SDL-1.2.git
$ cd SDL-1.2
$ mkdir build
$ cd build
$ ../configure --prefix /usr
$ make
$ sudo make install
Once the dependent libraries are installed, let's build TinyEMU.
$ wget https://bellard.org/tinyemu/tinyemu-2019-12-21.tar.gz
$ tar zxvf tinyemu-2019-12-21.tar.gz
$ cd tinyemu-2019-12-21
$ make
If temu is built in the current directory and can be executed, then it's all good.
$ ./temu --help
temu version 2019-12-21, Copyright (c) 2016-2018 Fabrice Bellard
Running Linux on a RISC-V emulator
Run temu as described in the TinyEMU documentation. Since Buildroot for JSLinux has been prepared by the author, we will use that.
$ ./temu https://bellard.org/jslinux/buildroot-riscv64.cfg
Welcome to JS/Linux (riscv64)
Use 'vflogin username' to connect to your account.
You can create a new account at https://vfsync.org/signup .
Use 'export_file filename' to export a file to your computer.
Imported files are written to the home directory.
[root@localhost ~]#
It's up and running! That was easy.
Let's run uname -a.
[root@localhost ~]# uname -a
Linux localhost 4.15.0-00049-ga3b1e7a-dirty #11 Thu Nov 8 20:30:26 CET 2018 riscv64 GNU/Linux
We can see that it is correctly running on the riscv64 architecture.
Conclusion
It feels like you could run other things on the RISC-V emulator if you prepare a Buildroot. Combining this with the ESP32 story mentioned at the beginning opens up a world of possibilities.
Discussion