mnt-reform: Add uboot flash script

This commit is contained in:
Jakob Leifhelm 2025-11-09 11:11:36 +01:00
parent 20baaa0d68
commit a31d53a0b2
No known key found for this signature in database
GPG key ID: 6817AA0238100822
4 changed files with 71 additions and 4 deletions

View file

@ -0,0 +1,23 @@
{
lib,
callPackage,
}:
rec {
reform-flash-uboot =
lib.mapAttrs (name: config: callPackage ./reform-flash-uboot.nix { inherit config; })
{
reform2-rk3588-dsi = {
warn = true;
mmc = "mmcblk0";
mmcBoot0 = false;
ubootOffset = 32768;
flashbinOffset = 0;
image = "${ubootImage.reform2-rk3588-dsi}/rk3588-mnt-reform2-dsi-flash.bin";
};
};
uboot.reform2-rk3588-dsi = callPackage ../rk3588/uboot.nix { };
ubootImage.reform2-rk3588-dsi = callPackage ../rk3588/uboot-image.nix {
uboot = uboot.reform2-rk3588-dsi;
};
}

View file

@ -0,0 +1,44 @@
{
lib,
writeShellApplication,
config,
}:
let
dev = "/dev/" + config.mmc + lib.optionalString config.mmcBoot0 "boot0";
in
writeShellApplication {
name = "reform-flash-uboot";
text = ''
if [ "$(id -u)" -ne 0 ]; then
echo "reform-flash-uboot has to be run as root / using sudo."
exit 1
fi
''
+ lib.optionalString config.warn ''
echo "W: Flashing u-boot to eMMC on $(cat /proc/device-tree/model) is not without risk." >&2
echo "W: If you flash the wrong u-boot or if the flashing process goes wrong, it is" >&2
echo "W: possible to soft-brick your board. Restoring it might need some extra hardware." >&2
echo "W: Please only proceed if you are sure that the benefits outweigh the risks for you." >&2
printf "Are you sure you want to proceed? [y/N] "
read -r response
if [ "$response" != "y" ]; then
echo "Exiting."
exit
fi
''
+ ''
echo "Writing ${config.image} to ${dev}" >&2
''
+ lib.optionalString config.mmcBoot0 ''
echo 0 >"/sys/class/block/${config.mmc}boot0/force_ro"
''
+ ''
dd if='${config.image}' of='${dev}' bs=512 seek='${
builtins.toString (config.ubootOffset / 512)
}' skip='${builtins.toString (config.flashbinOffset / 512)}'
''
+ lib.optionalString config.mmcBoot0 ''
echo 1 >"/sys/class/block/${config.mmc}boot0/force_ro"
'';
}