Skip to content

Commit

Permalink
zynq: add various fixes and cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
fsagbuya committed Jan 2, 2024
1 parent 79ff6e6 commit ada3dcb
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 49 deletions.
6 changes: 6 additions & 0 deletions stage-1.nix
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,11 @@ let
initialRamdisk = pkgs.makeInitrd {
contents = [ { object = bootStage1; symlink = "/init"; } ];
};
# Use for zynq_image
uRamdisk = pkgs.makeInitrd {
makeUInitrd = true;
contents = [ { object = bootStage1; symlink = "/init"; } ];
};
in
{
options = {
Expand All @@ -205,6 +210,7 @@ in
config = {
system.build.bootStage1 = bootStage1;
system.build.initialRamdisk = initialRamdisk;
system.build.uRamdisk = uRamdisk;
system.build.extraUtils = extraUtils;
boot.initrd.availableKernelModules = [ ];
boot.initrd.kernelModules = [ "tun" "loop" "squashfs" ] ++ (lib.optional config.not-os.nix "overlay");
Expand Down
5 changes: 5 additions & 0 deletions stage-2.nix
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ with lib;
type = types.str;
};
};
networking.hostName = mkOption {
default = "";
type = types.strMatching
"^$|^[[:alnum:]]([[:alnum:]_-]{0,61}[[:alnum:]])?$";
};
};
config = {
system.build.bootStage2 = pkgs.substituteAll {
Expand Down
93 changes: 44 additions & 49 deletions zynq_image.nix
Original file line number Diff line number Diff line change
@@ -1,66 +1,61 @@
{ config, pkgs, ... }:

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 {
crosspkgs = import pkgs.path {
system = "x86_64-linux";
crossSystem = {
system = "armv7l-linux";
linux-kernel = {
name = "zynq";
baseConfig = "multi_v7_defconfig";
target = "uImage";
installTarget = "uImage";
autoModules = false;
DTB = true;
makeFlags = [ "LOADADDR=0x8000" ];
};
};
};
customKernel = (crosspkgs.linux.override {
extraConfig = ''
OVERLAY_FS y
'';
};
customKernelPackages = pkgs.linuxPackagesFor customKernel;
}).overrideAttrs (oa: {
postInstall = ''
cp arch/arm/boot/uImage $out
${oa.postInstall}
'';
});
customKernelPackages = crosspkgs.linuxPackagesFor customKernel;
in {
imports = [ ./arm32-cross-fixes.nix ];
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" ];
networking.hostName = "zynq";
system.build.zynq_image = pkgs.runCommand "zynq_image" {
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 .
cp -s ${config.system.build.kernel}/uImage .
cp -s ${config.system.build.uRamdisk}/initrd uRamdisk.image.gz
cp -s ${config.system.build.kernel}/dtbs/zynq-zc706.dtb devicetree.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 = "";
environment = {
systemPackages = with pkgs; [ strace inetutils ];
etc = {
"service/getty/run".source = pkgs.writeShellScript "getty" ''
hostname ${config.networking.hostName}
agetty ttyPS0 115200
'';
"pam.d/other".text = ''
auth sufficient pam_permit.so
account required pam_permit.so
password required pam_permit.so
session optional pam_env.so
'';
"security/pam_env.conf".text = "";
};
};
}

0 comments on commit ada3dcb

Please sign in to comment.