From 35b1c5ee8bcb09176cd93f093c3dfaa91746ff2b Mon Sep 17 00:00:00 2001 From: Nick Spinale Date: Mon, 24 Jun 2024 14:58:43 +0000 Subject: [PATCH] nix: Support custom u-boot bootcmd for rpi4 Signed-off-by: Nick Spinale --- hacking/nix/scope/plat-utils/rpi4/default.nix | 31 +++++++++++-------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/hacking/nix/scope/plat-utils/rpi4/default.nix b/hacking/nix/scope/plat-utils/rpi4/default.nix index 0bd318bce..f92ecf129 100644 --- a/hacking/nix/scope/plat-utils/rpi4/default.nix +++ b/hacking/nix/scope/plat-utils/rpi4/default.nix @@ -39,28 +39,32 @@ let uBootBin = "${uBoot}/u-boot.bin"; imageAddr = "0x30000000"; + defaultBootCmd = "load mmc 0:1 ${imageAddr} /image.elf; bootelf -p ${imageAddr}"; - uBootEnvTxt = writeText "uboot.env.txt" '' + uBootEnvTxt = { bootCmd }: writeText "uboot.env.txt" '' bootdelay=0 - bootcmd=load mmc 0:1 ${imageAddr} /image.elf; bootelf -p ${imageAddr}" + bootcmd=${bootCmd}" autostart=1 ''; - uBootEnv = runCommand "uboot.env" { - nativeBuildInputs = [ - ubootTools - ]; - } '' - mkenvimage \ - -s 0x4000 \ - -o $out \ - ${uBootEnvTxt} - ''; + uBootEnv = { bootCmd }: + assert lib.stringLength bootCmd < 3 * 4096; # conservative + runCommand "uboot.env" { + nativeBuildInputs = [ + ubootTools + ]; + } '' + mkenvimage \ + -s 0x4000 \ + -o $out \ + ${uBootEnvTxt { inherit bootCmd; }} + ''; kernelFileName = "kernel${if hostPlatform.is32bit then "7l" else "8"}.img"; mkBootLinks = { image ? null + , bootCmd ? defaultBootCmd , extraCommands ? "" }: runCommand "boot" {} '' @@ -74,7 +78,7 @@ let rm $out/kernel*.img ln -s ${uBootBin} $out/${kernelFileName} - ln -s ${uBootEnv} $out/uboot.env + ln -s ${uBootEnv { inherit bootCmd; }} $out/uboot.env ${lib.optionalString (image != null) '' ln -s ${image} $out/image.elf @@ -132,6 +136,7 @@ in { firmware uBoot defaultBootLinks + mkBootLinks mkPlatformSystemExtension ; }