From 8da3468ee2578f544ef33517e80feb2e48951076 Mon Sep 17 00:00:00 2001 From: Dylan Bautista Date: Mon, 14 Oct 2024 14:26:59 +0200 Subject: [PATCH] Add qemu support for Lagarto Ox The network is still not working automatically, but the eth0 device is present in the host. Reviewed-by: Rodrigo Arias Mallo --- README.md | 14 ++++++++++++++ boot.sh | 15 ++++++--------- flake.nix | 46 ++++++++++++++++++++++++++++++++++++++++++++++ vm.nix | 18 +++++------------- 4 files changed, 71 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index 0728bf0..ab04f57 100644 --- a/README.md +++ b/README.md @@ -45,6 +45,20 @@ $ picocom -q -b 115200 $FPGACTL_UART It should boot without any user interaction. +## Lagarto Ox on QEMU + +To build the system and boot it on QEMU, you can run the following: + +``` +$ nix develop -L '.#qemu-lagarto-ox' +``` + +Then, simply run boot.sh to start the QEMU system. + +``` +$ ./boot.sh +``` + ## Lagarto Hun WIP diff --git a/boot.sh b/boot.sh index adc71ee..f52dc33 100755 --- a/boot.sh +++ b/boot.sh @@ -27,7 +27,7 @@ fi # Create a directory for exchanging data with the VM. mkdir -p "$TMPDIR/xchg" -system="$NIXOS_SYSTEM_TOPLEVEL" +system="$TOPLEVEL" echo "Booting $system" cd "$TMPDIR" @@ -37,7 +37,7 @@ cd "$TMPDIR" #QEMU_KERNEL_PARAMS="boot.trace boot.debug1" # Trap the CPU on compressed instructions? -TRAP_COMPRESSED="-cpu rv64,c=false" +#TRAP_COMPRESSED="-cpu rv64,c=false" CUSTOM_BIOS="-bios $OPENSBI/share/opensbi/lp64/generic/firmware/fw_payload.bin" #CUSTOM_BIOS="-bios $OPENSBI/share/opensbi/lp64/generic/firmware/fw_jump.elf" @@ -45,11 +45,10 @@ CUSTOM_BIOS="-bios $OPENSBI/share/opensbi/lp64/generic/firmware/fw_payload.bin" #CUSTOM_BIOS="-bios $CDIR/bios.bin" #CUSTOM_BIOS="-bios opensbi-1.4-rv-bin/share/opensbi/lp64/generic/firmware/fw_payload.bin" #DEBUG_GDB="-s -S" -DEBUG_CPU="-d cpu_reset" +#DEBUG_CPU="-d cpu_reset" #DEBUG_CPU="-d in_asm,cpu,cpu_reset" -# Start QEMU. exec qemu-system-riscv64 \ $DEBUG_GDB \ $DEBUG_CPU \ @@ -60,18 +59,16 @@ exec qemu-system-riscv64 \ -machine virt \ -device virtio-rng-pci \ $TRAP_COMPRESSED \ - $CUSTOM_BIOS \ - -netdev user,id=net0,hostfwd=tcp::60022-:22 -device virtio-net-device,netdev=net0 \ + -netdev user,id=net0,hostfwd=tcp::60022-:22 \ + -device virtio-net-device,netdev=net0 \ -virtfs local,path=/nix/store,security_model=none,mount_tag=nix-store \ -virtfs local,path="${SHARED_DIR:-$TMPDIR/xchg}",security_model=none,mount_tag=shared \ -virtfs local,path="$TMPDIR"/xchg,security_model=none,mount_tag=xchg \ - -device virtio-keyboard \ -drive "file=$NIX_DISK_IMAGE,if=none,id=hd0" \ -device virtio-blk-device,drive=hd0 \ - -device loader,addr=0x84000000,file=$system/kernel \ -kernel $system/kernel \ -initrd $system/initrd \ - -append "$(cat $system/kernel-params) init=$system/init console=ttyS0,115200n8 loglevel=7 $QEMU_KERNEL_PARAMS" + -append "$(cat $system/kernel-params) init=$system/init console=ttyS0,115200n8 loglevel=7 $QEMU_KERNEL_PARAMS" \ $QEMU_OPTS \ "$@" diff --git a/flake.nix b/flake.nix index f4ac664..82e007d 100644 --- a/flake.nix +++ b/flake.nix @@ -18,6 +18,7 @@ system = "${system}"; modules = [ ./configuration.nix + ./lagarto-ox.nix ./vm.nix ]; }; @@ -54,6 +55,18 @@ ./no-compressed.nix ]; }; + + # QEMU configuration (x86 host) for a FPGA Lagarto Ox CPU virtual machine + qemu-lagarto-ox = nixosSystem { + specialArgs = { inherit self; }; + system = "${system}"; + modules = [ + ./configuration.nix + ./lagarto-ox.nix + ./no-compressed.nix + ./vm.nix + ]; + }; }; # A development shell with QEMU ready to boot the RISC-V system in an x86 @@ -131,6 +144,39 @@ ''; }; + devShells.x86_64-linux.qemu-lagarto-ox = + let + nixosconf = self.nixosConfigurations.qemu-lagarto-ox; + syspkgs = nixosconf.pkgs; + build = nixosconf.config.system.build; + in syspkgs.mkShell rec { + pname = "lagarto-ox-shell"; + nativeBuildInputs = with syspkgs; [ qemu_full ]; + COMMIT = if self ? rev then self.rev else "dirty"; + TOPLEVEL = build.toplevel; + OPENSBI = syspkgs.opensbi; + KERNEL = build.kernel; + INITRD = build.initialRamdisk; + UBOOT_ENV = syspkgs.uboot-env; + BITSTREAM = syspkgs.bitstream; + BOOTROM = syspkgs.bootrom; + GCROOT = mkRoots syspkgs [ + syspkgs.stdenv KERNEL OPENSBI syspkgs.riscv-tools + ]; + shellHook = '' + echo "Here are the current system pieces:" + echo " COMMIT = $COMMIT" + echo " TOPLEVEL = $TOPLEVEL" + echo " KERNEL = $KERNEL" + echo " OPENSBI = $OPENSBI" + echo " INITRD = $INITRD" + echo " UBOOT_ENV = $UBOOT_ENV" + echo " BITSTREAM = $BITSTREAM" + echo " BOOTROM = $BOOTROM" + echo " GCROOT = $GCROOT" + ''; + }; + devShells.x86_64-linux.lagarto-ox-rd = let nixosconf = self.nixosConfigurations.lagarto-ox; diff --git a/vm.nix b/vm.nix index b6a356f..81cf44f 100644 --- a/vm.nix +++ b/vm.nix @@ -8,7 +8,9 @@ ]; # Enable ssh on boot - services.openssh.enable = true; + services.openssh.enable = lib.mkForce true; + networking.dhcpcd.enable = lib.mkForce true; + services.timesyncd.enable = lib.mkForce true; boot = { kernelParams = [ @@ -47,8 +49,8 @@ INET y NETWORK_FILESYSTEMS y OVERLAY_FS y - #"9P_FS" y - #"9P_FS_POSIX_ACL" y + 9P_FS y + 9P_FS_POSIX_ACL y PCI y VIRTIO_PCI y PCI_HOST_GENERIC y @@ -63,16 +65,6 @@ nixpkgs.overlays = [ (final: prev: { - qemu = prev.qemu.override { - pulseSupport = false; - pipewireSupport = false; - sdlSupport = false; - jackSupport = false; - gtkSupport = false; - vncSupport = false; - smartcardSupport = false; - }; - uboot-custom = prev.ubootQemuRiscv64Smode.override { # Override preboot to set 'bootcmd' directly to the kernel address in RAM extraConfig = '' -- GitLab