From 9a475bc1e37b8543e3ee958e747f0b41c0d506e8 Mon Sep 17 00:00:00 2001 From: Rodrigo Arias Mallo Date: Fri, 19 Jan 2024 12:32:06 +0100 Subject: [PATCH] Booting Linux and userspace OK --- boot.sh | 8 ++++---- configuration.nix | 25 ++++++++----------------- flake.nix | 9 ++++++--- overlay.nix | 33 +++++++++++++++++++++++++++++++++ vm.nix | 29 +++++++++++++++++++++++++++++ 5 files changed, 80 insertions(+), 24 deletions(-) create mode 100644 vm.nix diff --git a/boot.sh b/boot.sh index 5337377..07a7c93 100755 --- a/boot.sh +++ b/boot.sh @@ -67,7 +67,7 @@ exec qemu-system-riscv64 \ -device loader,addr=0x84000000,file=$system/kernel \ -kernel $system/kernel \ -initrd $system/initrd \ - -append "$(cat $system/kernel-params) init=$system/init regInfo=/nix/store/x3zpwfbk2wkiisxhgi7zwsfwbdfxk0w1-closure-info-riscv64-unknown-linux-gnu/registration 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 \ "$@" @@ -78,9 +78,9 @@ exec qemu-system-riscv64 \ - -kernel ${NIXPKGS_QEMU_KERNEL_visionfive_nix:-/nix/store/8n5fakqq44nsmbcn0vdm3mzsvcq9ihbi-nixos-system-visionfive-nix-24.05.20240115.c3e128f/kernel} \ - -initrd /nix/store/96058frp51dn0xxfci4kyvzz0rvd5ngy-initrd-linux-riscv64-unknown-linux-gnu-6.1.72/initrd \ - -append "$(cat /nix/store/8n5fakqq44nsmbcn0vdm3mzsvcq9ihbi-nixos-system-visionfive-nix-24.05.20240115.c3e128f/kernel-params) init=/nix/store/8n5fakqq44nsmbcn0vdm3mzsvcq9ihbi-nixos-system-visionfive-nix-24.05.20240115.c3e128f/init regInfo=/nix/store/bgqa92gznhcr9aryx6ac4ycx4s2385cr-closure-info-riscv64-unknown-linux-gnu/registration console=ttyS0,115200n8 console=tty0 $QEMU_KERNEL_PARAMS" \ +# -kernel ${NIXPKGS_QEMU_KERNEL_visionfive_nix:-/nix/store/8n5fakqq44nsmbcn0vdm3mzsvcq9ihbi-nixos-system-visionfive-nix-24.05.20240115.c3e128f/kernel} \ +# -initrd /nix/store/96058frp51dn0xxfci4kyvzz0rvd5ngy-initrd-linux-riscv64-unknown-linux-gnu-6.1.72/initrd \ +# -append "$(cat /nix/store/8n5fakqq44nsmbcn0vdm3mzsvcq9ihbi-nixos-system-visionfive-nix-24.05.20240115.c3e128f/kernel-params) init=/nix/store/8n5fakqq44nsmbcn0vdm3mzsvcq9ihbi-nixos-system-visionfive-nix-24.05.20240115.c3e128f/init regInfo=/nix/store/bgqa92gznhcr9aryx6ac4ycx4s2385cr-closure-info-riscv64-unknown-linux-gnu/registration console=ttyS0,115200n8 console=tty0 $QEMU_KERNEL_PARAMS" \ # -drive "file=$NIX_DISK_IMAGE,if=virtio,id=hd0" \ diff --git a/configuration.nix b/configuration.nix index c66e04b..e4599e7 100644 --- a/configuration.nix +++ b/configuration.nix @@ -3,27 +3,16 @@ { imports = [ "${modulesPath}/profiles/base.nix" - #"${modulesPath}/virtualisation/qemu-vm.nix" ]; networking.hostName = "visionfive-nix"; - boot = { - kernelParams = [ "boot.shell_on_fail" ]; - consoleLogLevel = lib.mkDefault 7; - initrd.kernelModules = [ - "virtio_pci" - "virtio_blk" - "virtio_input" - "9pnet" - "9pnet_virtio" - ]; - - loader = { - grub.enable = false; - generic-extlinux-compatible.enable = true; - }; - }; +# boot = { +# loader = { +# grub.enable = false; +# generic-extlinux-compatible.enable = true; +# }; +# }; nixpkgs.overlays = [ (import ./overlay.nix) ]; @@ -31,4 +20,6 @@ services.openssh.enable = true; system.stateVersion = "24.05"; + + boot.kernelPackages = lib.mkForce pkgs.linuxPackagesCustom; } diff --git a/flake.nix b/flake.nix index a8ca26f..eac2033 100644 --- a/flake.nix +++ b/flake.nix @@ -13,8 +13,11 @@ overlay = import ./overlay.nix; pkgs = import nixpkgs { inherit system; }; modules = [ + # For now we only define a config for VM, later we will want to split + # this into different configs. + ./vm.nix + ./configuration.nix - #"${nixos-hardware}/starfive/visionfive/v2/sd-image-installer.nix" ]; in { overlay = import ./overlay.nix; @@ -47,8 +50,8 @@ let nixosconf = self.nixosConfigurations.cross; syspkgs = nixosconf.pkgs; - #toplevel = nixosconf.config.system.build.toplevel; - toplevel = "${nixosconf.config.system.build.vm}/system"; + toplevel = nixosconf.config.system.build.toplevel; + #toplevel = "${nixosconf.config.system.build.vm}/system"; in pkgs.mkShell { pname = "qemu-shell"; diff --git a/overlay.nix b/overlay.nix index 54b05ab..c1fb5f0 100644 --- a/overlay.nix +++ b/overlay.nix @@ -35,4 +35,37 @@ final: prev: "FW_PAYLOAD_PATH=${final.uboot-custom}/u-boot.bin" ]; }); + + linuxPackagesCustom = prev.linuxPackagesFor (prev.linux.override { + structuredExtraConfig = with prev.lib.kernel; { + KEXEC = yes; + SERIAL_8250_DW = yes; + PINCTRL_STARFIVE = yes; + + # Doesn't build as a module + DW_AXI_DMAC_STARFIVE = yes; + + # stmmac hangs when built as a module + #PTP_1588_CLOCK = yes; + #STMMAC_ETH = yes; + #STMMAC_PCI = yes; + + # For qemu + BLOCK = yes; + BLK_DEV = yes; + DEVTMPFS = yes; + VIRTIO_MENU = yes; + VIRTIO_BLK = yes; + + # For 9P: https://wiki.qemu.org/Documentation/9psetup + NET_9P = yes; + NET_9P_VIRTIO = yes; + NET_9P_DEBUG = yes; + "9P_FS" = yes; + "9P_FS_POSIX_ACL" = yes; + PCI = yes; + VIRTIO_PCI = yes; + PCI_HOST_GENERIC = yes; + }; + }); } diff --git a/vm.nix b/vm.nix new file mode 100644 index 0000000..ccc022f --- /dev/null +++ b/vm.nix @@ -0,0 +1,29 @@ +{ config, lib, pkgs, modulesPath, ... }: + +# Contains the configuration to make a VM bootable with qemu. + +{ + imports = [ + "${modulesPath}/virtualisation/qemu-vm.nix" + ]; + + boot = { + kernelParams = [ "boot.shell_on_fail" ]; + consoleLogLevel = lib.mkDefault 7; + initrd.kernelModules = [ + "virtio_pci" + "virtio_blk" + "virtio_input" + "9pnet" + "9pnet_virtio" + ]; + + loader = { + grub.enable = false; + generic-extlinux-compatible.enable = true; + }; + }; + + virtualisation.diskImage = null; + +}