From 4d284ae3157323cd46fd0a7064c8811e8b2088cb Mon Sep 17 00:00:00 2001 From: Rodrigo Arias Mallo Date: Thu, 7 Mar 2024 12:03:02 +0100 Subject: [PATCH] Move qemu specific config to vm.nix --- configuration.nix | 22 ++------------- overlay.nix | 71 ----------------------------------------------- vm.nix | 32 +++++++++++++++++++-- 3 files changed, 33 insertions(+), 92 deletions(-) diff --git a/configuration.nix b/configuration.nix index 52b277b..de6d5d9 100644 --- a/configuration.nix +++ b/configuration.nix @@ -2,7 +2,8 @@ { imports = [ - "${modulesPath}/profiles/base.nix" + #"${modulesPath}/profiles/base.nix" + #"${modulesPath}/profiles/minimal.nix" ]; nixpkgs.crossSystem = { @@ -11,28 +12,11 @@ networking.hostName = "nixos-riscv"; - nixpkgs.overlays = [ (import ./overlay.nix) ]; - # Enable ssh on boot services.openssh.enable = true; system.stateVersion = "24.05"; - #boot.kernelPackages = lib.mkForce pkgs.linuxPackagesCustom; - - boot.kernelPatches = [ { - name = "riscv-common"; - patch = null; - extraConfig = '' - KEXEC y - ''; - } ]; - - boot.kernelParams = [ - "console=tty1" - "console=ttyS0,115200" - ]; - services.getty.autologinUser = "test"; users = { @@ -45,5 +29,5 @@ }; }; - environment.systemPackages = with pkgs; [ vim gdb neofetch gcc bintools ]; + #environment.systemPackages = with pkgs; [ vim gdb neofetch gcc bintools ]; } diff --git a/overlay.nix b/overlay.nix index 33896b1..b3686b6 100644 --- a/overlay.nix +++ b/overlay.nix @@ -3,76 +3,5 @@ final: prev: # Changes to packages from nixpkgs { - # Fix GCC 13 format-overflow warning/error: - # ../src/shared/install.c:444:64: error: ā€˜%s’ directive argument is null [-Werror=format-overflow=] - # 444 | err = log_error_errno(changes[i].type, "Failed to %s unit, unit %s does not exist.", - # | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - systemd = prev.systemd.overrideAttrs (old: { - CFLAGS = "-Wno-error=format-overflow"; - }); - qemu = prev.qemu.override { rutabagaSupport = false; }; - - uboot-custom = prev.ubootQemuRiscv64Smode.override { - # Override preboot to set 'bootcmd' directly to the kernel address in RAM - extraConfig = '' - CONFIG_PREBOOT="setenv fdt_addr ''${fdtcontroladdr}; fdt addr ''${fdtcontroladdr}; setenv bootcmd booti ''${kernel_addr_r} - ''${fdtcontroladdr};" - CONFIG_RISCV_ISA_C=n - ''; - # Also include debug u-boot - filesToInstall = ["u-boot.bin" "u-boot"]; - }; - - opensbi-uboot = prev.opensbi.overrideAttrs (old: { - makeFlags = old.makeFlags ++ [ - # Build OpenSBI without compressed instructions - "PLATFORM_RISCV_ISA=rv64g" - # Check with: riscv64-unknown-elf-objdump -d -M no-aliases rotate - "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; - VIRTIO_NET = yes; - EXT4_FS = yes; - - # For 9P: https://wiki.qemu.org/Documentation/9psetup - NET_9P = yes; - NET_9P_VIRTIO = yes; - NET_9P_DEBUG = yes; - NET_DEVICES = yes; - NET_CORE = yes; - INET = yes; - NETWORK_FILESYSTEMS = yes; - OVERLAY_FS = yes; - "9P_FS" = yes; - "9P_FS_POSIX_ACL" = yes; - PCI = yes; - VIRTIO_PCI = yes; - PCI_HOST_GENERIC = yes; - - RISCV_ISA_C = no; - NONPORTABLE = yes; - EFI = no; - }; - }); } diff --git a/vm.nix b/vm.nix index 31fefff..e6d344f 100644 --- a/vm.nix +++ b/vm.nix @@ -8,8 +8,11 @@ ]; boot = { - kernelParams = [ "boot.shell_on_fail" ]; - #kernelPackages = lib.mkForce pkgs.linuxPackagesCustom; + kernelParams = [ + "console=tty1" + "console=ttyS0,115200" + "boot.shell_on_fail" + ]; consoleLogLevel = lib.mkDefault 7; initrd.kernelModules = [ "virtio_pci" @@ -54,4 +57,29 @@ generic-extlinux-compatible.enable = true; }; }; + + nixpkgs.overlays = [ + (final: prev: { + qemu = prev.qemu.override { rutabagaSupport = false; }; + + uboot-custom = prev.ubootQemuRiscv64Smode.override { + # Override preboot to set 'bootcmd' directly to the kernel address in RAM + extraConfig = '' + CONFIG_PREBOOT="setenv fdt_addr ''${fdtcontroladdr}; fdt addr ''${fdtcontroladdr}; setenv bootcmd booti ''${kernel_addr_r} - ''${fdtcontroladdr};" + CONFIG_RISCV_ISA_C=n + ''; + # Also include debug u-boot + filesToInstall = ["u-boot.bin" "u-boot"]; + }; + + opensbi-uboot = prev.opensbi.overrideAttrs (old: { + makeFlags = old.makeFlags ++ [ + # Build OpenSBI without compressed instructions + "PLATFORM_RISCV_ISA=rv64g" + # Check with: riscv64-unknown-elf-objdump -d -M no-aliases rotate + "FW_PAYLOAD_PATH=${final.uboot-custom}/u-boot.bin" + ]; + }); + }) + ]; }