From 9c894bdabfc039174ea55546e6d65fb8174b2ce7 Mon Sep 17 00:00:00 2001 From: Daniel Barlow Date: Thu, 21 Dec 2023 19:17:14 +0000 Subject: [PATCH] add tftpboot test for mips --- devices/families/qemu.nix | 2 +- devices/qemu/default.nix | 21 +++++++++++++- overlay.nix | 28 +++++++++++++++++++ pkgs/kernel/default.nix | 1 + .../mips-malta-fdt-from-bootloader.patch | 18 ++++++++++++ pkgs/u-boot/0002-virtio-init-for-malta.patch | 15 ++++++++++ tests/tftpboot/configuration.nix | 12 ++++++-- tests/tftpboot/test.nix | 3 +- 8 files changed, 95 insertions(+), 5 deletions(-) create mode 100644 pkgs/kernel/mips-malta-fdt-from-bootloader.patch create mode 100644 pkgs/u-boot/0002-virtio-init-for-malta.patch diff --git a/devices/families/qemu.nix b/devices/families/qemu.nix index 7f38360..6882bd2 100644 --- a/devices/families/qemu.nix +++ b/devices/families/qemu.nix @@ -33,7 +33,7 @@ in { defaultOutput = "vmroot"; rootDevice = "/dev/mtdblock0"; - dts.src = null; + dts.src = pkgs.lib.mkDefault null; flash.eraseBlockSize = 65536; networkInterfaces = let inherit (config.system.service.network) link; diff --git a/devices/qemu/default.nix b/devices/qemu/default.nix index 3c4ce2d..7c323d5 100644 --- a/devices/qemu/default.nix +++ b/devices/qemu/default.nix @@ -36,7 +36,7 @@ in the Development manual. ''; - module = {pkgs, config, lim, ... }: { + module = {pkgs, config, lib, lim, ... }: { imports = [ ../../modules/arch/mipseb.nix ../families/qemu.nix @@ -50,5 +50,24 @@ SERIAL_8250_CONSOLE= "y"; }; }; + hardware = + # from arch/mips/mti-malta/Platform:load-$(CONFIG_MIPS_MALTA) += 0xffffffff80100000 + let addr = lim.parseInt "0x80100000"; + in { + loadAddress = addr; + entryPoint = addr; + + # Unlike the arm qemu targets, we need a static dts when + # running u-boot-using tests, qemu dumpdtb command doesn't + # work for this board. I am not at all sure this dts is + # *correct* but it does at least boot + dts = lib.mkForce { + src = "${config.system.outputs.kernel.modulesupport}/arch/mips/boot/dts/mti/malta.dts"; + includes = [ + "${config.system.outputs.kernel.modulesupport}/arch/mips/boot/dts/" + ]; + }; + + }; }; } diff --git a/overlay.nix b/overlay.nix index 70018ea..f4884c7 100644 --- a/overlay.nix +++ b/overlay.nix @@ -224,6 +224,34 @@ extraPkgs // { ''; }; + ubootQemuMips = final.buildUBoot { + defconfig = "malta_defconfig"; + extraMeta.platforms = ["mips-linux"]; + filesToInstall = ["u-boot.bin"]; + # define the prompt to be the same as arm{32,64} so + # we can use the same expect script for both + extraPatches = [ ./pkgs/u-boot/0002-virtio-init-for-malta.patch ]; + extraConfig = '' + CONFIG_SYS_PROMPT="=> " + CONFIG_VIRTIO=y + CONFIG_AUTOBOOT=y + CONFIG_DM_PCI=y + CONFIG_VIRTIO_PCI=y + CONFIG_VIRTIO_NET=y + CONFIG_VIRTIO_BLK=y + CONFIG_VIRTIO_MMIO=y + CONFIG_QFW_MMIO=y + CONFIG_FIT=y + CONFIG_LZMA=y + CONFIG_CMD_LZMADEC=y + CONFIG_SYS_BOOTM_LEN=0x1000000 + CONFIG_SYS_MALLOC_LEN=0x400000 + CONFIG_MIPS_BOOT_FDT=y + CONFIG_OF_LIBFDT=y + CONFIG_OF_STDOUT_VIA_ALIAS=y + ''; + }; + # gnufdisk = prev.gnufdisk.override { # guile = null; # }; diff --git a/pkgs/kernel/default.nix b/pkgs/kernel/default.nix index 743f5ed..b6197fd 100644 --- a/pkgs/kernel/default.nix +++ b/pkgs/kernel/default.nix @@ -51,6 +51,7 @@ stdenv.mkDerivation rec { patches = [ ./cmdline-cookie.patch ./phram-allow-cached-mappings.patch + ./mips-malta-fdt-from-bootloader.patch ]; # this is here to work around what I think is a bug in nixpkgs diff --git a/pkgs/kernel/mips-malta-fdt-from-bootloader.patch b/pkgs/kernel/mips-malta-fdt-from-bootloader.patch new file mode 100644 index 0000000..e864508 --- /dev/null +++ b/pkgs/kernel/mips-malta-fdt-from-bootloader.patch @@ -0,0 +1,18 @@ +diff --git a/arch/mips/mti-malta/malta-setup.c b/arch/mips/mti-malta/malta-setup.c +index 21cb3ac1237b..f11409ae9583 100644 +--- a/arch/mips/mti-malta/malta-setup.c ++++ b/arch/mips/mti-malta/malta-setup.c +@@ -192,7 +192,12 @@ static void __init bonito_quirks_setup(void) + + void __init *plat_get_fdt(void) + { +- return (void *)__dtb_start; ++ void *r=0; ++ if(fw_arg0 == -2) ++ r = (void *) KSEG1ADDR(fw_arg1); ++ else ++ r = (void *) __dtb_start; ++ return r; + } + + void __init plat_mem_setup(void) diff --git a/pkgs/u-boot/0002-virtio-init-for-malta.patch b/pkgs/u-boot/0002-virtio-init-for-malta.patch new file mode 100644 index 0000000..b7c1172 --- /dev/null +++ b/pkgs/u-boot/0002-virtio-init-for-malta.patch @@ -0,0 +1,15 @@ +diff --git a/board/imgtec/malta/malta.c b/board/imgtec/malta/malta.c +index 9853a0ba82..d95e332d6d 100644 +--- a/board/imgtec/malta/malta.c ++++ b/board/imgtec/malta/malta.c +@@ -169,7 +169,9 @@ int board_early_init_f(void) + int misc_init_r(void) + { + rtc_reset(); +- ++#if IS_ENABLED(CONFIG_VIRTIO) ++ virtio_init(); ++#endif + return 0; + } + diff --git a/tests/tftpboot/configuration.nix b/tests/tftpboot/configuration.nix index ef89e52..f57577d 100644 --- a/tests/tftpboot/configuration.nix +++ b/tests/tftpboot/configuration.nix @@ -18,9 +18,17 @@ in { ../../modules/outputs/tftpboot.nix ]; config = { - hardware.dts.src = lib.mkForce dts; + # use extracted dts if it was null in the device + # definition, use actual dts if provided + hardware.dts.src = lib.mkOverride 500 dts; boot.tftp = { - loadAddress = lim.parseInt "0x44000000"; + loadAddress = + let offsets = { + mips = "0x88000000"; + arm = "0x44000000"; + aarch64 = "0x44000000"; + }; + in lim.parseInt offsets.${pkgs.stdenv.hostPlatform.qemuArch} ; serverip = "10.0.2.2"; ipaddr = "10.0.2.15"; }; diff --git a/tests/tftpboot/test.nix b/tests/tftpboot/test.nix index 2c702bc..bb9c3af 100644 --- a/tests/tftpboot/test.nix +++ b/tests/tftpboot/test.nix @@ -30,6 +30,7 @@ run-liminix-vm \ expect ${./script.expect} 2>&1 |tee $out ''; in { - arm = check "qemu-armv7l" "ubootQemuArm"; aarch64 = check "qemu-aarch64" "ubootQemuAarch64"; + arm = check "qemu-armv7l" "ubootQemuArm"; + mips = check "qemu" "ubootQemuMips"; }