git.iko.soy/typeable/nixpkgs
on master help sign in
Merge pull request #125451 from zhaofengli/qemu-riscv64-sd-image
commit801d832872a11a867b297d54cafd5ba34c5e41ae authorMaciej Krüger <mkg20001@gmail.com> dateFri 7 Jan 2022, 22:14 (5 years ago) parent5034c5c048cb04
9 files changed+150−11
nixos/modules/installer/sd-card/sd-image-riscv64-qemu.nix+32 nixos/modules/installer/sd-card/sd-image-x86_64.nix+27 nixos/modules/installer/sd-card/sd-image.nix+1−1 nixos/modules/profiles/all-hardware.nix+2−2 nixos/modules/system/boot/loader/generic-extlinux-compatible/default.nix+18−1 nixos/modules/system/boot/loader/generic-extlinux-compatible/extlinux-conf-builder.sh+9−3 nixos/tests/boot.nix+40−4 pkgs/misc/uboot/default.nix+20 pkgs/top-level/all-packages.nix+1
nixos/modules/installer/sd-card/sd-image-riscv64-qemu.nixnew file+32
@@ -0,0 +1,32 @@
1+# To build, use:
2+# nix-build nixos -I nixos-config=nixos/modules/installer/sd-card/sd-image-riscv64-qemu.nix -A config.system.build.sdImage
3+{ config, lib, pkgs, ... }:
4+
5+{
6+ imports = [
7+ ../../profiles/base.nix
8+ ./sd-image.nix
9+ ];
10+
11+ boot.loader = {
12+ grub.enable = false;
13+ generic-extlinux-compatible = {
14+ enable = true;
15+
16+ # Don't even specify FDTDIR - We do not have the correct DT
17+ # The DTB is generated by QEMU at runtime
18+ useGenerationDeviceTree = false;
19+ };
20+ };
21+
22+ boot.consoleLogLevel = lib.mkDefault 7;
23+ boot.kernelParams = [ "console=tty0" "console=ttyS0,115200n8" ];
24+
25+ sdImage = {
26+ populateFirmwareCommands = "";
27+ populateRootCommands = ''
28+ mkdir -p ./files/boot
29+ ${config.boot.loader.generic-extlinux-compatible.populateCmd} -c ${config.system.build.toplevel} -d ./files/boot
30+ '';
31+ };
32+}
nixos/modules/installer/sd-card/sd-image-x86_64.nixnew file+27
@@ -0,0 +1,27 @@
1+# To build, use:
2+# nix-build nixos -I nixos-config=nixos/modules/installer/sd-card/sd-image-x86_64.nix -A config.system.build.sdImage
3+
4+# This image is primarily used in NixOS tests (boot.nix) to test `boot.loader.generic-extlinux-compatible`.
5+{ config, lib, pkgs, ... }:
6+
7+{
8+ imports = [
9+ ../../profiles/base.nix
10+ ./sd-image.nix
11+ ];
12+
13+ boot.loader = {
14+ grub.enable = false;
15+ generic-extlinux-compatible.enable = true;
16+ };
17+
18+ boot.consoleLogLevel = lib.mkDefault 7;
19+
20+ sdImage = {
21+ populateFirmwareCommands = "";
22+ populateRootCommands = ''
23+ mkdir -p ./files/boot
24+ ${config.boot.loader.generic-extlinux-compatible.populateCmd} -c ${config.system.build.toplevel} -d ./files/boot
25+ '';
26+ };
27+}
nixos/modules/installer/sd-card/sd-image.nix+1−1
@@ -176,7 +176,7 @@ in
176176
177177 nativeBuildInputs = [ dosfstools e2fsprogs mtools libfaketime util-linux zstd ];
178178
179− inherit (config.sdImage) compressImage;
179+ inherit (config.sdImage) imageName compressImage;
180180
181181 buildCommand = ''
182182 mkdir -p $out/nix-support $out/sd-image
nixos/modules/profiles/all-hardware.nix+2−2
@@ -44,12 +44,12 @@ in
4444 "ohci1394" "sbp2"
4545
4646 # Virtio (QEMU, KVM etc.) support.
47− "virtio_net" "virtio_pci" "virtio_blk" "virtio_scsi" "virtio_balloon" "virtio_console"
47+ "virtio_net" "virtio_pci" "virtio_mmio" "virtio_blk" "virtio_scsi" "virtio_balloon" "virtio_console"
4848
4949 # VMware support.
5050 "mptspi" "vmxnet3" "vsock"
5151 ] ++ lib.optional platform.isx86 "vmw_balloon"
52− ++ lib.optionals (!platform.isAarch64 && !platform.isAarch32) [ # not sure where else they're missing
52+ ++ lib.optionals (pkgs.stdenv.isi686 || pkgs.stdenv.isx86_64) [
5353 "vmw_vmci" "vmwgfx" "vmw_vsock_vmci_transport"
5454
5555 # Hyper-V support.
nixos/modules/system/boot/loader/generic-extlinux-compatible/default.nix+18−1
@@ -30,6 +30,21 @@ in
3030 '';
3131 };
3232
33+ useGenerationDeviceTree = mkOption {
34+ default = true;
35+ type = types.bool;
36+ description = ''
37+ Whether to generate Device Tree-related directives in the
38+ extlinux configuration.
39+
40+ When enabled, the bootloader will attempt to load the device
41+ tree binaries from the generation's kernel.
42+
43+ Note that this affects all generations, regardless of the
44+ setting value used in their configurations.
45+ '';
46+ };
47+
3348 configurationLimit = mkOption {
3449 default = 20;
3550 example = 10;
@@ -54,7 +69,9 @@ in
5469 };
5570
5671 config = let
57− builderArgs = "-g ${toString cfg.configurationLimit} -t ${timeoutStr}" + lib.optionalString (dtCfg.name != null) " -n ${dtCfg.name}";
72+ builderArgs = "-g ${toString cfg.configurationLimit} -t ${timeoutStr}"
73+ + lib.optionalString (dtCfg.name != null) " -n ${dtCfg.name}"
74+ + lib.optionalString (!cfg.useGenerationDeviceTree) " -r";
5875 in
5976 mkIf cfg.enable {
6077 system.build.installBootLoader = "${builder} ${builderArgs} -c";
nixos/modules/system/boot/loader/generic-extlinux-compatible/extlinux-conf-builder.sh+9−3
@@ -6,7 +6,7 @@ export PATH=/empty
66for i in @path@; do PATH=$PATH:$i/bin; done
77
88usage() {
9− echo "usage: $0 -t <timeout> -c <path-to-default-configuration> [-d <boot-dir>] [-g <num-generations>] [-n <dtbName>]" >&2
9+ echo "usage: $0 -t <timeout> -c <path-to-default-configuration> [-d <boot-dir>] [-g <num-generations>] [-n <dtbName>] [-r]" >&2
1010 exit 1
1111}
1212
@@ -15,7 +15,7 @@ default= # Default configuration
1515target=/boot # Target directory
1616numGenerations=0 # Number of other generations to include in the menu
1717
18−while getopts "t:c:d:g:n:" opt; do
18+while getopts "t:c:d:g:n:r" opt; do
1919 case "$opt" in
2020 t) # U-Boot interprets '0' as infinite and negative as instant boot
2121 if [ "$OPTARG" -lt 0 ]; then
@@ -30,6 +30,7 @@ while getopts "t:c:d:g:n:" opt; do
3030 d) target="$OPTARG" ;;
3131 g) numGenerations="$OPTARG" ;;
3232 n) dtbName="$OPTARG" ;;
33+ r) noDeviceTree=1 ;;
3334 \?) usage ;;
3435 esac
3536done
@@ -96,6 +97,12 @@ addEntry() {
9697 fi
9798 echo " LINUX ../nixos/$(basename $kernel)"
9899 echo " INITRD ../nixos/$(basename $initrd)"
100+ echo " APPEND init=$path/init $extraParams"
101+
102+ if [ -n "$noDeviceTree" ]; then
103+ return
104+ fi
105+
99106 if [ -d "$dtbDir" ]; then
100107 # if a dtbName was specified explicitly, use that, else use FDTDIR
101108 if [ -n "$dtbName" ]; then
@@ -109,7 +116,6 @@ addEntry() {
109116 exit 1
110117 fi
111118 fi
112− echo " APPEND init=$path/init $extraParams"
113119}
114120
115121tmpFile="$target/extlinux/extlinux.conf.tmp.$$"
nixos/tests/boot.nix+40−4
@@ -12,12 +12,22 @@ let
1212 iso =
1313 (import ../lib/eval-config.nix {
1414 inherit system;
15− modules =
16− [ ../modules/installer/cd-dvd/installation-cd-minimal.nix
17− ../modules/testing/test-instrumentation.nix
18− ];
15+ modules = [
16+ ../modules/installer/cd-dvd/installation-cd-minimal.nix
17+ ../modules/testing/test-instrumentation.nix
18+ ];
1919 }).config.system.build.isoImage;
2020
21+ sd =
22+ (import ../lib/eval-config.nix {
23+ inherit system;
24+ modules = [
25+ ../modules/installer/sd-card/sd-image-x86_64.nix
26+ ../modules/testing/test-instrumentation.nix
27+ { sdImage.compressImage = false; }
28+ ];
29+ }).config.system.build.sdImage;
30+
2131 pythonDict = params: "\n {\n ${concatStringsSep ",\n " (mapAttrsToList (name: param: "\"${name}\": \"${param}\"") params)},\n }\n";
2232
2333 makeBootTest = name: extraConfig:
@@ -110,4 +120,30 @@ in {
110120 };
111121
112122 biosNetboot = makeNetbootTest "bios" {};
123+
124+ ubootExtlinux = let
125+ sdImage = "${sd}/sd-image/${sd.imageName}";
126+ mutableImage = "/tmp/linked-image.qcow2";
127+
128+ machineConfig = pythonDict {
129+ bios = "${pkgs.ubootQemuX86}/u-boot.rom";
130+ qemuFlags = "-m 768 -machine type=pc,accel=tcg -drive file=${mutableImage},if=ide,format=qcow2";
131+ };
132+ in makeTest {
133+ name = "boot-uboot-extlinux";
134+ nodes = { };
135+ testScript = ''
136+ import os
137+
138+ # Create a mutable linked image backed by the read-only SD image
139+ if os.system("qemu-img create -f qcow2 -F raw -b ${sdImage} ${mutableImage}") != 0:
140+ raise RuntimeError("Could not create mutable linked image")
141+
142+ machine = create_machine(${machineConfig})
143+ machine.start()
144+ machine.wait_for_unit("multi-user.target")
145+ machine.succeed("nix store verify -r --no-trust --option experimental-features nix-command /run/current-system")
146+ machine.shutdown()
147+ '';
148+ };
113149}
pkgs/misc/uboot/default.nix+20
@@ -352,6 +352,26 @@ in {
352352 filesToInstall = ["u-boot.bin"];
353353 };
354354
355+ ubootQemuX86 = buildUBoot {
356+ defconfig = "qemu-x86_defconfig";
357+ extraConfig = ''
358+ CONFIG_USB_UHCI_HCD=y
359+ CONFIG_USB_EHCI_HCD=y
360+ CONFIG_USB_EHCI_GENERIC=y
361+ CONFIG_USB_XHCI_HCD=y
362+ '';
363+ extraPatches = [
364+ # https://patchwork.ozlabs.org/project/uboot/list/?series=268007&state=%2A&archive=both
365+ # Remove when upgrading to 2022.01
366+ (fetchpatch {
367+ url = "https://patchwork.ozlabs.org/series/268007/mbox/";
368+ sha256 = "sha256-xn4Q959dgoB63zlmJepI41AXAf1kCycIGcmu4IIVjmE=";
369+ })
370+ ];
371+ extraMeta.platforms = [ "i686-linux" "x86_64-linux" ];
372+ filesToInstall = [ "u-boot.rom" ];
373+ };
374+
355375 ubootRaspberryPi = buildUBoot {
356376 defconfig = "rpi_defconfig";
357377 extraMeta.platforms = ["armv6l-linux"];
pkgs/top-level/all-packages.nix+1
@@ -23044,6 +23044,7 @@ with pkgs;
2304423044 ubootQemuAarch64
2304523045 ubootQemuArm
2304623046 ubootQemuRiscv64Smode
23047+ ubootQemuX86
2304723048 ubootRaspberryPi
2304823049 ubootRaspberryPi2
2304923050 ubootRaspberryPi3_32bit