Skip to content

QEMU and Linux

Cupertino Miranda edited this page Nov 18, 2020 · 1 revision

Introduction

As of today there're 2 platforms in Qemu usable with Linux kernel on ARC: virt & nsim. The idea is to be able to use pristine vmlinux binaries built for corresponding real platforms: "stand-alone" nSIM (even if executed from MDB's GUI) and HSDK development board.

Though SIM-HS image (built from vanilla Linux sources with haps_hs_defconfig) as it is won't work in Qemu as we're missing SMP, ARConnect part etc. Single-core nSIM works (as of 07 March 2019 ARC UART implementation is not entirely correct (no ideas why) and so in IRQ mode symbols are not printed w/o sending key presses by user) as it only needs ARC UART as a peripheral.

Preparing target binaries

Building root FS

  1. Get the most recent Buildroot (preferably master tree from their git, i.e. git clone git://git.busybox.net/buildroot)

  2. Config it with the following defconfig:

BR2_arcle=y
BR2_archs38=y
BR2_ENABLE_DEBUG=y
BR2_STATIC_LIBS=y
BR2_TARGET_ROOTFS_CPIO=y

You may do it in a scripted way:

echo "BR2_arcle=y" > .config
echo "BR2_archs38=y" >> .config
echo "BR2_ENABLE_DEBUG=y" >> .config
echo "BR2_STATIC_LIBS=y" >> .config
echo "BR2_TARGET_ROOTFS_CPIO=y" >> .config
make olddefconfig
make

As a result you'll get your root FS image output/images/rootfs.cpio.

Preparing Linux kernel image

As discussed above currently we have a coupe of changes required for Linux to work in Qemu. That's due to missing features in Qemu:

  1. Cache AUX regs
  2. ARConnect including IDU and cross-core IRQs etc

Which means vanilla Linux kernel won't work and we need source tree with some mods. Mine is available here: https://github.com/abrodkin/linux/tree/qemu-5.1 Either clone my repo or add it as a remote and checkout Qemu-"something" branch. Today it is qemu-5.1, but given we're in active development stage some other [newer?] branch might work even better.

Now select desired configuration:

  • nSIM: make nsim_hs_defconfig
  • HSDK: make haps_hs_defconfig

Specify path to root fs. For that set CONFIG_INITRAMFS_SOURCE in menuconfig to full path to output/images/rootfs.cpio.

Now just build: make.

Run Qemu

nSIM

./arc-softmmu/qemu-system-arc -M nsim -nographic -no-reboot -monitor none -serial stdio -kernel vmlinux -cpu archs

SIM-HS

./arc-softmmu/qemu-system-arc -M virt -nographic -no-reboot -monitor none -serial stdio -kernel vmlinux -cpu archs

With external filesystem in .ext2 image

./arc-softmmu/qemu-system-arc -M virt -nographic -kernel vmlinux -cpu archs \
-append "root=/dev/vda ro" \
-drive file=rootfs.ext2,format=raw,id=hd0 \
-device virtio-blk-device,drive=hd0
Clone this wiki locally