|
| 1 | +# Buildroot for TinyEMU |
| 2 | + |
| 3 | +This repo is a quick getting started guide on how to build kernel and rootfs using Buildroot for TinyEMU |
| 4 | + |
| 5 | +The current configuration is a minimal kernel with no networking, though it should be easy to change. |
| 6 | + |
| 7 | +If you're not ready to build your own, you can start get a ready made kernel, rootfs and bbl from [TinyEMU](https://bellard.org/tinyemu/), at the bottom there's [diskimage-linux-riscv-2018-09-23.tar.gz](https://bellard.org/tinyemu/diskimage-linux-riscv-2018-09-23.tar.gz). |
| 8 | + |
| 9 | +# BBL - Berkely boot loader |
| 10 | +To build BBL, you'll find the patches needed for [RISC-V Proxy Kernel](https://github.com/riscv-software-src/riscv-pk) in [diskimage-linux-riscv-2018-09-23.tar.gz](https://bellard.org/tinyemu/diskimage-linux-riscv-2018-09-23.tar.gz). |
| 11 | + |
| 12 | +# Getting Started |
| 13 | + |
| 14 | +## Building the docker image |
| 15 | +``` |
| 16 | +docker build -t buildroot . |
| 17 | +``` |
| 18 | + |
| 19 | +## Running the docker image |
| 20 | +``` |
| 21 | +docker run -it buildroot |
| 22 | +``` |
| 23 | + |
| 24 | +At this point you have a ready made machine to start building your rootfs and kernel: |
| 25 | +``` |
| 26 | +make -j 5 |
| 27 | +``` |
| 28 | + |
| 29 | +Once its done, you'll find 2 files in output/images: |
| 30 | +``` |
| 31 | +~/buildroot-2022.05# ls -l output/images |
| 32 | +total 10252 |
| 33 | +-rw-r--r-- 1 root root 2172016 Jul 12 11:36 Image |
| 34 | +-rw-r--r-- 1 root root 20971520 Jul 12 11:36 rootfs.ext2 |
| 35 | +``` |
| 36 | + |
| 37 | +Now we want to copy them into our virtual riscv machine: |
| 38 | +``` |
| 39 | +docker cp <container id>:/root/buildroot-2022.05/output/images/Image kernel32.bin |
| 40 | +docker cp <container id>:/root/buildroot-2022.05/output/images/rootfs.ext2 rootfs32.bin |
| 41 | +``` |
| 42 | + |
| 43 | +Make sure you have bbl32.bin and TinyEMU configuration file: |
| 44 | +``` |
| 45 | +/* VM configuration file */ |
| 46 | +{ |
| 47 | + version: 1, |
| 48 | + machine: "riscv32", |
| 49 | + memory_size: 12, |
| 50 | + bios: "bbl32.bin", |
| 51 | + kernel: "kernel32.bin", |
| 52 | + cmdline: "console=hvc0 debug ignore_loglevel earlycon=sbi root=/dev/vda rw", |
| 53 | + drive0: { file: "rootfs32.bin" } |
| 54 | +} |
| 55 | +``` |
| 56 | + |
| 57 | +And you're ready to go, either copy it to your SD card under /emu or run tinyemu from the command line |
| 58 | +``` |
| 59 | +<tinyemu executable> riscv32.cfg |
| 60 | +``` |
| 61 | + |
| 62 | +If you choose to run it on ESP32 through my [esp32-tinyemu](https://github.com/drorgl/esp32-tinyemu), you'll see something very similar to this: |
| 63 | +[](https://www.youtube.com/watch?v=f3a3xeTRj_A) |
| 64 | + |
| 65 | +# Quick Cheat Sheet for Buildroot |
| 66 | +configure buildroot: |
| 67 | +``` |
| 68 | +make menuconfig |
| 69 | +``` |
| 70 | + |
| 71 | +configure busybox: |
| 72 | +``` |
| 73 | +make busybox-menuconfig |
| 74 | +``` |
| 75 | + |
| 76 | +configure kernel: |
| 77 | +``` |
| 78 | +make linux-menuconfig |
| 79 | +``` |
| 80 | + |
| 81 | +rebuild whole system: |
| 82 | +``` |
| 83 | +make clean all -j 5 |
| 84 | +``` |
| 85 | + |
| 86 | +persist your buildroot configuration: |
| 87 | +``` |
| 88 | +make savedefconfig |
| 89 | +docker cp <container id>:/root/buildroot-2022.05/buildroot_rv32_config buildroot_config/buildroot_rv32_config |
| 90 | +``` |
| 91 | + |
| 92 | +persist your kernel configuration: |
| 93 | +``` |
| 94 | +make linux-update-defconfig |
| 95 | +docker cp <container id>:/root/buildroot-2022.05/linux_rv32_config buildroot_config/linux_rv32_config |
| 96 | +``` |
| 97 | + |
| 98 | +persist your busybox configuration: |
| 99 | +``` |
| 100 | +make busybox-update-config |
| 101 | +docker cp <container id>:/root/buildroot-2022.05/busybox_config buildroot_config/busybox_config |
| 102 | +``` |
| 103 | + |
| 104 | +# Notes |
| 105 | +* This docker image was customized to use axel to download each dependency with multiple connections, you might not need it on your network. |
| 106 | +* The configured overlay skips init and goes straight to bash, you'll need to remove it to work with getty (BR2_ROOTFS_OVERLAY and BR2_TARGET_GENERIC_GETTY_OPTIONS) |
0 commit comments