From bf767d623b9dab17ce9e273dc63bc1ddbf16442f Mon Sep 17 00:00:00 2001 From: Rodrigo Arias Mallo Date: Thu, 7 Mar 2024 16:49:48 +0100 Subject: [PATCH] Generate U-Boot commands --- flake.nix | 2 ++ fpga/upload.sh | 3 ++- lagarto-hun.nix | 24 ++++++++++++++++++++++++ 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/flake.nix b/flake.nix index d461baf..baeeb65 100644 --- a/flake.nix +++ b/flake.nix @@ -61,10 +61,12 @@ build = nixosconf.config.system.build; in pkgs.mkShell { pname = "lagarto-hun-shell"; + TOPLEVEL = build.toplevel; OPENSBI = syspkgs.opensbi; KERNEL = build.kernel; INITRD = build.initialRamdisk; ROOTFS = build.sdImage; + UBOOT_ENV = syspkgs.uboot-env; }; }; } diff --git a/fpga/upload.sh b/fpga/upload.sh index adbcc4e..191e3cc 100755 --- a/fpga/upload.sh +++ b/fpga/upload.sh @@ -11,6 +11,7 @@ rsync -a fpga/env.sh "$dst" rsync "$OPENSBI/share/opensbi/lp64/fpga/openpiton/firmware/fw_payload.bin" "$dst/opensbi.bin" rsync "$KERNEL/Image" "$dst/kernel.bin" rsync "$INITRD/initrd" "$dst/initrd.bin" -rsync "$ROOTFS/rootfs.img" "$dst/rootfs.img" +rsync "$ROOTFS/sd-image/rootfs.img" "$dst/rootfs.img" +rsync "$UBOOT_ENV" "$dst/uboot.env" echo "Now go to $dst and run ./boot.sh" diff --git a/lagarto-hun.nix b/lagarto-hun.nix index f7fbc76..1fececa 100644 --- a/lagarto-hun.nix +++ b/lagarto-hun.nix @@ -81,6 +81,30 @@ ''; }; + uboot-env = let + init = "${config.system.build.toplevel}/init"; + initrd = "${config.system.build.initialRamdisk}/initrd"; + in prev.runCommand "uboot.txt" {} '' + cat > $out < + + # Reduce memory + fdt set /memory@80000000 reg <0x00000000 0x80000000 0x00000001 0x00000000> + + # Set kernel options + setenv bootargs "root=/dev/ram0 loglevel=7 debug rw earlycon=sbi boot.trace console=hvc0 init=${init}" + + EOF + + # Populate the bood commands from the initrd size + echo "# Boot system" >> $out + echo "setenv ramdisk_size $(stat --format %s $(readlink -f ${initrd}))" >> $out + echo 'booti ''${kernel_addr_r} ''${ramdisk_addr_r}:''${ramdisk_size} ''${fdtcontroladdr}' >> $out + ''; + opensbi = prev.opensbi.overrideAttrs (old: { makeFlags = old.makeFlags ++ [ "PLATFORM=fpga/openpiton"