diff --git a/README.md b/README.md index 0728bf0c182d4a5fd55a202be241e5324a8e1b7c..ab04f578b2b65004e1f7cb408ce005a620f4fcb6 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 adc71eefc74d9efefb8ea649110e4f5fb8e02d74..f52dc33d51aa98a96609e3c0a58c6bee6620d58d 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 f4ac6649907840d4a4d1bf3863625990cafcda5b..82e007dd0b046b9fdc0c574376a7302323ec4e55 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 b6a356f19c4632e234d5e71828b57c99923807e9..81cf44fd5eca1c22007daa0690bea2a2de0bbc74 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 = ''