1
0
Fork 0

hacky wip aarch64 boots in qemu

This commit is contained in:
Daniel Barlow 2023-09-19 18:44:09 +01:00
parent 12b9feb8ee
commit 2841952245
11 changed files with 164 additions and 22 deletions

View File

@ -2436,3 +2436,17 @@ Sun Sep 17 16:44:31 BST 2023
Can we figure out which bits of the old doc are missing from the new Can we figure out which bits of the old doc are missing from the new
one and just transplant those? Then we can merge it sooner one and just transplant those? Then we can merge it sooner
instead of blocking on writig all the new stuff instead of blocking on writig all the new stuff
We need to find a nice place for an introduction to choosing
rootfsType
Mon Sep 18 17:07:56 BST 2023
Let's see if we can hack up an aarch64 qemu port
From https://gist.github.com/oznu/ac9efae7c24fd1f37f1d933254587aa4 :
curl -L https://releases.linaro.org/components/kernel/uefi-linaro/latest/release/qemu64/QEMU_EFI.fd -O
dd if=/dev/zero of=flash1.img bs=1M count=64
dd if=/dev/zero of=flash0.img bs=1M count=64
dd if=QEMU_EFI.fd of=flash0.img conv=notrunc

View File

@ -16,6 +16,7 @@ let
]; ];
}; };
}); });
pkgsNative = pkgs.pkgsBuildBuild;
config = (pkgs.lib.evalModules { config = (pkgs.lib.evalModules {
modules = [ modules = [
@ -49,16 +50,19 @@ in {
# cross-compiling nix-shell for any package we're customizing # cross-compiling nix-shell for any package we're customizing
inherit pkgs; inherit pkgs;
buildEnv = pkgs.mkShell { buildEnv =
packages = with pkgs.pkgsBuildBuild; [ pkgs.mkShell {
tufted packages =
routeros.routeros with pkgsNative; [
routeros.ros-exec-script tufted
mips-vm routeros.routeros
borderVm.build.vm routeros.ros-exec-script
go-l2tp borderVm.build.vm
min-copy-closure go-l2tp
fennelrepl min-copy-closure
]; fennelrepl
}; (mips-vm.override { inherit (pkgs) ubootQemuAarch64; })
];
};
} }

View File

@ -0,0 +1,92 @@
# This "device" generates images that can be used with the QEMU
# emulator. The default output is a directory containing separate
# kernel (uncompressed vmlinux) and initrd (squashfs) images
{
system = {
crossSystem = {
config = "aarch64-unknown-linux-musl";
};
};
module = {pkgs, config, ... }: {
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 = {
CPU_LITTLE_ENDIAN= "y";
CPU_BIG_ENDIAN= "n";
VIRTUALIZATION = "y";
ACPI="y";
ARM64_VA_BITS_48="y";
# ARM_MHU="y";
# PLATFORM_MHU="y";
ARM_SMMU="y";
ARM_SMMU_V3="y";
ARCH_VEXPRESS = "y";
PCI_HOST_GENERIC="y";
MTD = "y";
MTD_BLOCK2MTD = "y";
MTD_BLKDEVS = "y";
MTD_BLOCK = "y";
VIRTIO_MENU = "y";
PCI = "y";
VIRTIO_PCI = "y";
BLOCK = "y";
VIRTIO_BLK = "y";
NETDEVICES = "y";
VIRTIO_NET = "y";
# https://stackoverflow.com/a/68340492
CMDLINE="\"earlycon=ttyS0 console=ttyS0\"";
CMDLINE_FROM_BOOTLOADER = "y";
ARM64 = "y";
PINCTRL = "y";
EFI_EARLYCON = "y";
SERIAL_EARLYCON_ARM_SEMIHOST = "y"; # earlycon=smh
SERIAL_AMBA_PL011 = "y";
SERIAL_AMBA_PL011_CONSOLE = "y";
SERIAL_8250= "y";
SERIAL_8250_CONSOLE= "y";
SERIAL_EARLYCON = "y";
};
};
hardware =
let
mac80211 = pkgs.mac80211.override {
drivers = ["mac80211_hwsim"];
klibBuild = config.system.outputs.kernel.modulesupport;
};
in {
defaultOutput = "vmroot";
loadAddress = "0x0";
entryPoint = "0x0";
dts.src = ./empty.dts;
rootDevice = "/dev/mtd1";
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 ];
};
};
};
};
}

View File

@ -0,0 +1,3 @@
/dts-v1/;
/ { };

View File

@ -6,6 +6,7 @@
} : } :
let let
objcopy = "${stdenv.cc.bintools.targetPrefix}objcopy"; objcopy = "${stdenv.cc.bintools.targetPrefix}objcopy";
arch = "arm64";
in { in {
kernel kernel
, commandLine , commandLine
@ -40,7 +41,7 @@ stdenv.mkDerivation {
buildPhase = '' buildPhase = ''
${objcopy} -O binary -R .reginfo -R .notes -R .note -R .comment -R .mdebug -R .note.gnu.build-id -S vmlinux.elf vmlinux.bin ${objcopy} -O binary -R .reginfo -R .notes -R .note -R .comment -R .mdebug -R .note.gnu.build-id -S vmlinux.elf vmlinux.bin
rm -f vmlinux.bin.lzma ; lzma -k -z vmlinux.bin rm -f vmlinux.bin.lzma ; lzma -k -z vmlinux.bin
mkimage -A mips -O linux -T kernel -C lzma -a ${loadAddress} -e ${entryPoint} -n 'MIPS Liminix Linux ${extraName}' -d vmlinux.bin.lzma kernel.uimage mkimage -A ${arch} -O linux -T kernel -C lzma -a ${loadAddress} -e ${entryPoint} -n '${arch} Liminix Linux ${extraName}' -d vmlinux.bin.lzma kernel.uimage
''; '';
installPhase = '' installPhase = ''
cp kernel.uimage $out cp kernel.uimage $out

View File

@ -56,9 +56,9 @@ in {
MODULE_SIG = if modular then "y" else "n"; MODULE_SIG = if modular then "y" else "n";
DEBUG_FS = "y"; DEBUG_FS = "y";
MIPS_BOOTLOADER_CMDLINE_REQUIRE_COOKIE = "y"; # MIPS_BOOTLOADER_CMDLINE_REQUIRE_COOKIE = "y";
MIPS_BOOTLOADER_CMDLINE_COOKIE = "\"liminix\""; # MIPS_BOOTLOADER_CMDLINE_COOKIE = "\"liminix\"";
MIPS_CMDLINE_DTB_EXTEND = "y"; # MIPS_CMDLINE_DTB_EXTEND = "y";
# basic networking protocols # basic networking protocols
NET = "y"; NET = "y";

View File

@ -76,11 +76,12 @@ in
inherit dtb; inherit dtb;
}; };
# could use trivial-builders.linkFarmFromDrvs here? # could use trivial-builders.linkFarmFromDrvs here?
vmroot = pkgs.runCommand "qemu" {} '' vmroot = pkgs.runCommandCC "vmroot" {} ''
mkdir $out mkdir $out
cd $out cd $out
ln -s ${config.system.outputs.rootfs} rootfs ln -s ${config.system.outputs.rootfs} rootfs
ln -s ${kernel} vmlinux ln -s ${kernel} vmlinux
${pkgs.stdenv.cc.targetPrefix}objcopy -O binary -S ${kernel} Image
ln -s ${manifest} manifest ln -s ${manifest} manifest
ln -s ${kernel.headers} build ln -s ${kernel.headers} build
''; '';

View File

@ -28,7 +28,7 @@ stdenv.mkDerivation rec {
"-I${openssl.dev}/include -L${openssl.out}/lib -L${ncurses.out}/lib"; "-I${openssl.dev}/include -L${openssl.out}/lib -L${ncurses.out}/lib";
PKG_CONFIG_PATH = "./pkgconfig"; PKG_CONFIG_PATH = "./pkgconfig";
CROSS_COMPILE = stdenv.cc.bintools.targetPrefix; CROSS_COMPILE = stdenv.cc.bintools.targetPrefix;
ARCH = "mips"; # kernel uses "mips" here for both mips and mipsel ARCH = "arm64";
KBUILD_BUILD_HOST = "liminix.builder"; KBUILD_BUILD_HOST = "liminix.builder";
dontStrip = true; dontStrip = true;
@ -47,7 +47,7 @@ stdenv.mkDerivation rec {
]; ];
patches = [ patches = [
./cmdline-cookie.patch # ./cmdline-cookie.patch
]; ];
# this is here to work around what I think is a bug in nixpkgs # this is here to work around what I think is a bug in nixpkgs

View File

@ -1,12 +1,14 @@
{ {
qemu qemu
, socat , socat
, ubootQemuAarch64
, writeShellScriptBin , writeShellScriptBin
, symlinkJoin , symlinkJoin
, lib , lib
}: let }: let
mips-vm = writeShellScriptBin "mips-vm" '' mips-vm = writeShellScriptBin "mips-vm" ''
export PATH="${lib.makeBinPath [qemu]}:$PATH" export PATH="${lib.makeBinPath [qemu]}:$PATH"
export UBOOT=${ubootQemuAarch64}/u-boot.bin
${builtins.readFile ./mips-vm.sh} ${builtins.readFile ./mips-vm.sh}
''; '';
connect = writeShellScriptBin "connect-vm" '' connect = writeShellScriptBin "connect-vm" ''

View File

@ -39,11 +39,36 @@ if test -n "$3"; then
initramfs="-initrd $3" initramfs="-initrd $3"
fi fi
cat <<_IGNORE
fdt addr 5edbbdb0
fdt set /chosen bootargs 'earlycon=smh console=ttyAMA0 rw root=/dev/vda'
run bootcmd_qfw
_IGNORE
INIT=${INIT-/bin/init} INIT=${INIT-/bin/init}
echo $QEMU_OPTIONS echo $QEMU_OPTIONS
qemu-system-mips \ set -x
-M malta -m 256 \ qemu-system-aarch64 \
-echr 16 \
-M virt -m 512 \
-semihosting \
-cpu cortex-a72 -bios $UBOOT \
-drive file=$rootfs,format=raw,readonly=off,if=virtio,index=0 \
-kernel $1 \
-display none $flags
exit
-device nand,chip_id=0x59,id=cheeky \
-drive file=$rootfs,format=raw,readonly=off,if=mtd,index=0,id=cheeky \
-drive file=flash0.img,format=raw,if=pflash \
-drive file=flash1.img,format=raw,if=pflash \
# -D log.txt
qemu-system-aarch64 \
-M virt,gic-version=max -cpu max -m 512 -D log.txt \
-echr 16 \ -echr 16 \
-append "liminix default console=ttyS0,38400n8 panic=10 oops=panic init=$INIT loglevel=8 root=/dev/mtdblock0 block2mtd.block2mtd=/dev/vda,65536" \ -append "liminix default console=ttyS0,38400n8 panic=10 oops=panic init=$INIT loglevel=8 root=/dev/mtdblock0 block2mtd.block2mtd=/dev/vda,65536" \
-drive file=$rootfs,format=raw,readonly=off,if=virtio,index=0 \ -drive file=$rootfs,format=raw,readonly=off,if=virtio,index=0 \

View File

@ -1,7 +1,7 @@
let let
nixpkgs = <nixpkgs>; nixpkgs = <nixpkgs>;
liminix = (import ./default.nix { liminix = (import ./default.nix {
device = (import ./devices/qemu); device = (import ./devices/qemu-aarch64);
liminix-config = ./vanilla-configuration.nix; liminix-config = ./vanilla-configuration.nix;
inherit nixpkgs; inherit nixpkgs;
}); });