From 388e7e7082c7e1b555c0396a5ba762e687422d77 Mon Sep 17 00:00:00 2001 From: Florian Agbuya Date: Mon, 12 Feb 2024 10:27:36 +0800 Subject: [PATCH] configure qemu with u-boot and cleanup --- flake.nix | 121 ++++++++++++++++++++++++++---------------------------- 1 file changed, 58 insertions(+), 63 deletions(-) diff --git a/flake.nix b/flake.nix index 6cd5f4c..2e62851 100644 --- a/flake.nix +++ b/flake.nix @@ -23,6 +23,15 @@ ]; }; + not-os-configured = (import patched-not-os { + inherit nixpkgs; + extraModules = [ + "${patched-not-os}/zynq_image.nix" + ]; + system = "x86_64-linux"; + crossSystem.system = "armv7l-linux"; + }); + gnu-platform = "arm-none-eabi"; binutils-pkg = { zlib, extraConfigureFlags ? [] }: pkgs.stdenv.mkDerivation rec { @@ -265,66 +274,6 @@ ''; }); - # Pinned qemu version due to networking errors in recent version 8.2.0 - qemu = pkgs.qemu.overrideAttrs (oldAttrs: rec { - version = "8.1.3"; - src = pkgs.fetchurl { - url = "https://download.qemu.org/qemu-${version}.tar.xz"; - hash = "sha256-Q8wXaAQQVYb3T5A5jzTp+FeH3/QA07ZA2B93efviZbs="; - }; - }); - - not-os-configured = (import patched-not-os { - inherit nixpkgs; - extraModules = [ - "${patched-not-os}/zynq_image.nix" - ]; - system = "x86_64-linux"; - crossSystem.system = "armv7l-linux"; - }); - - not-os-qemu = { board ? "zc706" }: let - qemuScript = '' - #!/bin/bash - export PATH=${qemu}/bin:$PATH - IMGDIR=$(mktemp -d /tmp/not-os-qemu-XXXXXX) - BASE=$(realpath $(dirname $0)) - qemu-img create -F raw -f qcow2 -b $BASE/sd-image.img $IMGDIR/sd-overlay.qcow2 512M - - # Some command arguments are based from samples in Xilinx QEMU User Documentation - # See: https://xilinx-wiki.atlassian.net/wiki/spaces/A/pages/821854273/Running+Bare+Metal+Applications+on+QEMU - - qemu-system-arm \ - -M xilinx-zynq-a9 \ - -serial /dev/null \ - -serial stdio \ - -display none \ - -dtb $BASE/devicetree.dtb \ - -kernel $BASE/uImage \ - -initrd $BASE/uRamdisk.image.gz \ - -drive file=$IMGDIR/sd-overlay.qcow2,if=sd,format=qcow2 \ - -append "root=/dev/mmcblk0p2 console=ttyPS0,115200n8 systemConfig=${builtins.unsafeDiscardStringContext not-os-cfg.build.toplevel}"; - - rm -rf $IMGDIR - ''; - in pkgs.runCommand "not-os-qemu" { - inherit qemuScript; - passAsFile = [ "qemuScript" ]; - preferLocalBuild = true; - } - '' - mkdir $out - cd $out - cp -s ${not-os-cfg.build.kernel}/uImage . - cp -s ${not-os-cfg.build.uRamdisk}/initrd uRamdisk.image.gz - cp -s ${dtb { inherit board; }}/${board}.dtb devicetree.dtb - cp -s ${sd-image { inherit board; }}/sd-image/sd-image.img . - ln -sv ${not-os-cfg.build.toplevel} toplevel - cp $qemuScriptPath qemu-script - chmod +x qemu-script - patchShebangs qemu-script - ''; - sd-image = { board ? "zc706" }: let rootfsImage = pkgs.callPackage (pkgs.path + "/nixos/lib/make-ext4-fs.nix") { storePaths = [ not-os-cfg.build.toplevel ]; @@ -367,7 +316,7 @@ mkdir firmware cp ${bootimage { inherit board; }}/boot.bin firmware/ - cp ${dtb { inherit board; }}/${board}.dtb firmware/devicetree.dtb + cp ${dtb { inherit board; }}/${board}.dtb firmware/ cp ${not-os-cfg.build.kernel}/uImage firmware/ cp ${not-os-cfg.build.uRamdisk}/initrd firmware/uRamdisk.image.gz @@ -375,23 +324,69 @@ dd conv=notrunc if=firmware_part.img of=$img seek=$START count=$SECTORS ''; }; + + # Pinned qemu version due to networking errors in recent version 8.2.0 + qemu = pkgs.qemu.overrideAttrs (oldAttrs: rec { + version = "8.1.3"; + src = pkgs.fetchurl { + url = "https://download.qemu.org/qemu-${version}.tar.xz"; + hash = "sha256-Q8wXaAQQVYb3T5A5jzTp+FeH3/QA07ZA2B93efviZbs="; + }; + }); + + not-os-qemu = { board ? "zc706" }: let + qemuScript = '' + #!/bin/bash + export PATH=${qemu}/bin:$PATH + IMGDIR=$(mktemp -d /tmp/not-os-qemu-XXXXXX) + BASE=$(realpath $(dirname $0)) + qemu-img create -F raw -f qcow2 -b $BASE/sd-image.img $IMGDIR/sd-overlay.qcow2 512M + + # Some command arguments are based from samples in Xilinx QEMU User Documentation + # See: https://xilinx-wiki.atlassian.net/wiki/spaces/A/pages/821854273/Running+Bare+Metal+Applications+on+QEMU + + qemu-system-arm \ + -M xilinx-zynq-a9 \ + -m 1024 \ + $([ ${board} = "zc706" ] && echo "-serial /dev/null") -serial stdio \ + -display none \ + -kernel $BASE/u-boot.elf \ + -sd $IMGDIR/sd-overlay.qcow2 + + rm -rf $IMGDIR + ''; + in pkgs.runCommand "not-os-qemu" { + inherit qemuScript; + passAsFile = [ "qemuScript" ]; + preferLocalBuild = true; + } + '' + mkdir $out + cd $out + cp -s ${u-boot { inherit board; }}/u-boot.elf . + cp -s ${sd-image { inherit board; }}/sd-image/sd-image.img . + cp $qemuScriptPath qemu-script + chmod +x qemu-script + patchShebangs qemu-script + ''; in rec { packages.x86_64-linux = { inherit mkbootimage; }; packages.armv7l-linux = { + not-os = not-os-cfg.build.zynq_image; zc706-fsbl = fsbl { board = "zc706"; }; zc706-bootimage = bootimage { board = "zc706"; }; zc706-dtb = dtb { board = "zc706"; }; zc706-u-boot = u-boot { board = "zc706"; }; - zc706-qemu = not-os-qemu { board = "zc706"; }; zc706-sd-image = sd-image { board = "zc706"; }; - zc706-not-os = not-os-cfg.build.zynq_image; + zc706-qemu = not-os-qemu { board = "zc706"; }; fast-servo-fsbl = fsbl { board = "fast-servo"; }; fast-servo-bootimage = bootimage { board = "fast-servo"; }; fast-servo-dtb = dtb { board = "fast-servo"; }; fast-servo-u-boot = u-boot { board = "fast-servo"; }; fast-servo-sd-image = sd-image { board = "fast-servo"; }; + fast-servo-qemu = not-os-qemu { board = "fast-servo"; }; }; hydraJobs = packages.x86_64-linux // packages.armv7l-linux; };