From 6489a394242a4daa0b44c1b778716b07eedf0e08 Mon Sep 17 00:00:00 2001 From: Daniel Barlow Date: Sun, 5 Nov 2023 20:56:25 +0000 Subject: [PATCH] qemu armv7 --- ci.nix | 2 +- devices/qemu-armv7l/default.nix | 78 +++++++++++++++++++++++++++ modules/arch/arm.nix | 9 ++++ pkgs/run-liminix-vm/run-liminix-vm.sh | 8 +++ 4 files changed, 96 insertions(+), 1 deletion(-) create mode 100644 devices/qemu-armv7l/default.nix create mode 100644 modules/arch/arm.nix diff --git a/ci.nix b/ci.nix index 0f125df..085c7fe 100644 --- a/ci.nix +++ b/ci.nix @@ -9,7 +9,7 @@ let borderVmConf = ./bordervm.conf-example.nix; inherit (pkgs.lib.attrsets) genAttrs; devices = { - virt = [ "qemu" "qemu-aarch64" ]; + virt = [ "qemu" "qemu-aarch64" "qemu-armv7l" ]; hw = [ "gl-ar750" "gl-mt300n-v2" "gl-mt300a" ]; }; vanilla = ./vanilla-configuration.nix; diff --git a/devices/qemu-armv7l/default.nix b/devices/qemu-armv7l/default.nix new file mode 100644 index 0000000..149f793 --- /dev/null +++ b/devices/qemu-armv7l/default.nix @@ -0,0 +1,78 @@ +# This "device" generates images that can be used with the QEMU +# emulator. The default output is a directory containing separate +# kernel ("Image" format) and root filesystem (squashfs or jffs2) +# images +{ + system = { + crossSystem = { + config = "armv7l-unknown-linux-musleabihf"; + }; + }; + + # this device is described by the "qemu" device + description = ""; + + module = {pkgs, config, ... }: { + imports = [ ../../modules/arch/arm.nix ]; + kernel = { + src = pkgs.pkgsBuildBuild.fetchurl { + name = "linux.tar.gz"; + url = "https://cdn.kernel.org/pub/linux/kernel/v5.x/linux-5.15.71.tar.gz"; + hash = "sha256-yhO2cXIeIgUxkSZf/4aAsF11uxyh+UUZu6D1h92vCD8="; + }; + config = { + PCI_HOST_GENERIC = "y"; + PCI = "y"; + ARCH_VIRT = "y"; + + VFP = "y"; + NEON = "y"; + AEABI = "y"; + + MTD = "y"; + MTD_BLOCK = "y"; + MTD_CMDLINE_PARTS = "y"; + MTD_PHRAM = "y"; + + VIRTIO_MENU = "y"; + VIRTIO_PCI = "y"; + BLOCK = "y"; + VIRTIO_BLK = "y"; + VIRTIO_NET = "y"; + + SERIAL_EARLYCON_ARM_SEMIHOST = "y"; # earlycon=smh + SERIAL_AMBA_PL011 = "y"; + SERIAL_AMBA_PL011_CONSOLE = "y"; + }; + }; + boot.commandLine = [ + "console=ttyAMA0" + ]; + hardware = + let + mac80211 = pkgs.mac80211.override { + drivers = ["mac80211_hwsim"]; + klibBuild = config.system.outputs.kernel.modulesupport; + }; + in { + defaultOutput = "vmroot"; + loadAddress = "0x00010000"; + entryPoint = "0x00010000"; + rootDevice = "/dev/mtdblock0"; + + flash.eraseBlockSize = "65536"; # c.f. pkgs/mips-vm/mips-vm.sh + networkInterfaces = + let inherit (config.system.service.network) link; + in { + wan = link.build { ifname = "eth0"; }; + lan = link.build { ifname = "eth1"; }; + + wlan_24 = link.build { + ifname = "wlan0"; + dependencies = [ mac80211 ]; + }; + }; + }; + + }; +} diff --git a/modules/arch/arm.nix b/modules/arch/arm.nix new file mode 100644 index 0000000..474f780 --- /dev/null +++ b/modules/arch/arm.nix @@ -0,0 +1,9 @@ +{ lib, lim, pkgs, config, ...}: +{ + config = { + kernel.config = { + OF = "y"; + }; + hardware.ram.startAddress = lim.parseInt "0x40000000"; + }; +} diff --git a/pkgs/run-liminix-vm/run-liminix-vm.sh b/pkgs/run-liminix-vm/run-liminix-vm.sh index 637977a..b7afeef 100755 --- a/pkgs/run-liminix-vm/run-liminix-vm.sh +++ b/pkgs/run-liminix-vm/run-liminix-vm.sh @@ -52,6 +52,14 @@ case "$arch" in aarch64) QEMU="qemu-system-aarch64 -M virt -semihosting -cpu cortex-a72" ;; + arm) + # https://bugs.launchpad.net/qemu/+bug/1790975 + QEMU="qemu-system-arm -M virt,highmem=off -cpu cortex-a15" + ;; + *) + echo "unrecognised arch $arch" + exit 1; + ;; esac phram="mtdparts=phram0:16M(rootfs) phram.phram=phram0,${PHRAM_ADDRESS},16Mi,65536 root=/dev/mtdblock0";