configure qemu with u-boot and cleanup

This commit is contained in:
Florian Agbuya 2024-02-12 10:27:36 +08:00
parent 22129bc04e
commit 388e7e7082

121
flake.nix
View File

@ -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"; gnu-platform = "arm-none-eabi";
binutils-pkg = { zlib, extraConfigureFlags ? [] }: pkgs.stdenv.mkDerivation rec { 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 sd-image = { board ? "zc706" }: let
rootfsImage = pkgs.callPackage (pkgs.path + "/nixos/lib/make-ext4-fs.nix") { rootfsImage = pkgs.callPackage (pkgs.path + "/nixos/lib/make-ext4-fs.nix") {
storePaths = [ not-os-cfg.build.toplevel ]; storePaths = [ not-os-cfg.build.toplevel ];
@ -367,7 +316,7 @@
mkdir firmware mkdir firmware
cp ${bootimage { inherit board; }}/boot.bin 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.kernel}/uImage firmware/
cp ${not-os-cfg.build.uRamdisk}/initrd firmware/uRamdisk.image.gz 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 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 { in rec {
packages.x86_64-linux = { packages.x86_64-linux = {
inherit mkbootimage; inherit mkbootimage;
}; };
packages.armv7l-linux = { packages.armv7l-linux = {
not-os = not-os-cfg.build.zynq_image;
zc706-fsbl = fsbl { board = "zc706"; }; zc706-fsbl = fsbl { board = "zc706"; };
zc706-bootimage = bootimage { board = "zc706"; }; zc706-bootimage = bootimage { board = "zc706"; };
zc706-dtb = dtb { board = "zc706"; }; zc706-dtb = dtb { board = "zc706"; };
zc706-u-boot = u-boot { board = "zc706"; }; zc706-u-boot = u-boot { board = "zc706"; };
zc706-qemu = not-os-qemu { board = "zc706"; };
zc706-sd-image = sd-image { 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-fsbl = fsbl { board = "fast-servo"; };
fast-servo-bootimage = bootimage { board = "fast-servo"; }; fast-servo-bootimage = bootimage { board = "fast-servo"; };
fast-servo-dtb = dtb { board = "fast-servo"; }; fast-servo-dtb = dtb { board = "fast-servo"; };
fast-servo-u-boot = u-boot { board = "fast-servo"; }; fast-servo-u-boot = u-boot { board = "fast-servo"; };
fast-servo-sd-image = sd-image { 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; hydraJobs = packages.x86_64-linux // packages.armv7l-linux;
}; };