From 9bb6f1171ca4366b83c7bc71a765480c2c640d48 Mon Sep 17 00:00:00 2001 From: Florian Agbuya Date: Wed, 8 Nov 2023 14:47:50 +0800 Subject: [PATCH] initial commit --- .gitignore | 1 + flake.lock | 60 +++++++++++++++++++++++++++++++++ flake.nix | 22 ++++++++++++ zynq_image.nix | 90 ++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 173 insertions(+) create mode 100644 .gitignore create mode 100644 flake.lock create mode 100644 flake.nix create mode 100644 zynq_image.nix diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e2f5dd2 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +result \ No newline at end of file diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..b4c1de7 --- /dev/null +++ b/flake.lock @@ -0,0 +1,60 @@ +{ + "nodes": { + "firmware": { + "flake": false, + "locked": { + "lastModified": 1697732010, + "narHash": "sha256-kGXbqkqHCPU2Xz6az3LtdAccVzGtlq+vnTLiR3Xl9+8=", + "owner": "raspberrypi", + "repo": "firmware", + "rev": "ce3a0b4197eaf311ba0734efdb9f5bdedefe5e27", + "type": "github" + }, + "original": { + "owner": "raspberrypi", + "repo": "firmware", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1697730408, + "narHash": "sha256-Ww//zzukdTrwTrCUkaJA/NsaLEfUfQpWZXBdXBYfhak=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "ff0a5a776b56e0ca32d47a4a47695452ec7f7d80", + "type": "github" + }, + "original": { + "id": "nixpkgs", + "type": "indirect" + } + }, + "not-os": { + "inputs": { + "firmware": "firmware", + "nixpkgs": "nixpkgs" + }, + "locked": { + "lastModified": 1699416673, + "narHash": "sha256-uJ6QnU7hFUYZsz6J/HIBEpLW0bS7GLQOo6ccKtoZ68k=", + "owner": "cleverca22", + "repo": "not-os", + "rev": "79ff6e6fe0b64bf8b8d38363b2bb0dea0cd5a686", + "type": "github" + }, + "original": { + "owner": "cleverca22", + "repo": "not-os", + "type": "github" + } + }, + "root": { + "inputs": { + "not-os": "not-os" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..8b343d6 --- /dev/null +++ b/flake.nix @@ -0,0 +1,22 @@ +{ + description = "Not-OS port to the Zynq-7000 platform"; + + inputs.not-os.url = github:cleverca22/not-os; + + outputs = { self, not-os }: { + packages.armv7l-linux = let + platforms = (import not-os.inputs.nixpkgs { config = {}; }).platforms; + eval = (import "${not-os}" { + extraModules = [ + ./zynq_image.nix + ]; + platform = system: platforms.armv7l-hf-multiplatform; + system = "x86_64-linux"; + crossSystem.system = "armv7l-linux"; + inherit (not-os.inputs) nixpkgs; + }); + in { + zynq_image = eval.config.system.build.zynq_image; + }; + }; +} \ No newline at end of file diff --git a/zynq_image.nix b/zynq_image.nix new file mode 100644 index 0000000..354b4a9 --- /dev/null +++ b/zynq_image.nix @@ -0,0 +1,90 @@ +{ config, pkgs, ... }: + +# Copy of zynq_image.nix from https://github.com/cleverca22/not-os with added patch + +let + # dont use overlays for the qemu, it causes a lot of wasted time on recompiles + x86pkgs = import pkgs.path { system = "x86_64-linux"; }; + customKernel = pkgs.linux.override { + extraConfig = '' + OVERLAY_FS y + ''; + }; + customKernelPackages = pkgs.linuxPackagesFor customKernel; +in { + boot.kernelPackages = customKernelPackages; + nixpkgs.system = "armv7l-linux"; + system.build.zynq_image = let + cmdline = "root=/dev/mmcblk0 console=ttyPS0,115200n8 systemConfig=${builtins.unsafeDiscardStringContext config.system.build.toplevel}"; + qemuScript = '' + #!/bin/bash -v + export PATH=${x86pkgs.qemu}/bin:$PATH + set -x + base=$(dirname $0) + + cp $base/root.squashfs /tmp/ + chmod +w /tmp/root.squashfs + truncate -s 64m /tmp/root.squashfs + + qemu-system-arm \ + -M xilinx-zynq-a9 \ + -serial /dev/null \ + -serial stdio \ + -display none \ + -dtb $base/zynq-zc702.dtb \ + -kernel $base/zImage \ + -initrd $base/initrd \ + -drive file=/tmp/root.squashfs,if=sd,format=raw \ + -append "${cmdline}" + ''; + in pkgs.runCommand "zynq_image" { + inherit qemuScript; + passAsFile = [ "qemuScript" ]; + preferLocalBuild = true; + } '' + mkdir $out + cd $out + cp -s ${config.system.build.squashfs} root.squashfs + cp -s ${config.system.build.kernel}/*zImage . + cp -s ${config.system.build.initialRamdisk}/initrd initrd + cp -s ${config.system.build.kernel}/dtbs/zynq-zc702.dtb . + ln -sv ${config.system.build.toplevel} toplevel + cp $qemuScriptPath qemu-script + chmod +x qemu-script + patchShebangs qemu-script + ls -ltrh + ''; + system.build.rpi_image_tar = pkgs.runCommand "dist.tar" {} '' + mkdir -p $out/nix-support + tar -cvf $out/dist.tar ${config.system.build.rpi_image} + echo "file binary-dist $out/dist.tar" >> $out/nix-support/hydra-build-products + ''; + environment.systemPackages = [ pkgs.strace ]; + environment.etc."service/getty/run".source = pkgs.writeShellScript "getty" '' + agetty ttyPS0 115200 + ''; + environment.etc."pam.d/other".text = ""; + + nixpkgs.overlays = [ + (self: super: { + + # armv7l cross-compile fixes + libuv = super.libuv.overrideAttrs (old: { + doCheck = false; + }); + elfutils = super.elfutils.overrideAttrs (old: { + doCheck = false; + doInstallCheck = false; + }); + systemd = super.systemd.override { withEfi = false; }; + procps = super.procps.override { withSystemd = false; }; + nix = super.nix.override { enableDocumentation = false; }; + + # closure size fixes + openssh = super.openssh.override { withFIDO = false; withKerberos = false; }; + util-linux = super.util-linux.override { pamSupport=false; capabilitiesSupport=false; ncursesSupport=false; systemdSupport=false; nlsSupport=false; translateManpages=false; }; + utillinuxCurses = self.util-linux; + utillinuxMinimal = self.util-linux; + }) + ]; +} \ No newline at end of file