mirror of
https://github.com/NixOS/nixos-hardware.git
synced 2025-11-11 13:06:09 +01:00
mnt-reform: Add uboot flash script
This commit is contained in:
parent
20baaa0d68
commit
a31d53a0b2
4 changed files with 71 additions and 4 deletions
23
mnt/reform/pkgs/default.nix
Normal file
23
mnt/reform/pkgs/default.nix
Normal 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;
|
||||
};
|
||||
}
|
||||
44
mnt/reform/pkgs/reform-flash-uboot.nix
Normal file
44
mnt/reform/pkgs/reform-flash-uboot.nix
Normal 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"
|
||||
'';
|
||||
}
|
||||
|
|
@ -44,8 +44,8 @@
|
|||
storeContents = config.installerImage.storeContents;
|
||||
comp = config.installerImage.squashfsCompression;
|
||||
};
|
||||
uboot = pkgs.callPackage ./uboot.nix { };
|
||||
firmware = pkgs.callPackage ./firmware.nix { inherit uboot; };
|
||||
packages = pkgs.callPackage ../pkgs { };
|
||||
ubootImage = packages.ubootImage.reform2-rk3588-dsi;
|
||||
content = pkgs.callPackage (
|
||||
{
|
||||
stdenv,
|
||||
|
|
@ -215,7 +215,7 @@
|
|||
eval $(partx $img -o START,SECTORS --nr 1 --pairs)
|
||||
dd conv=notrunc if=${content} of=$img seek=$START count=$SECTORS
|
||||
|
||||
dd conv=notrunc if=${firmware}/rk3588-mnt-reform2-dsi-flash.bin of=$img seek=64
|
||||
dd conv=notrunc if=${ubootImage}/rk3588-mnt-reform2-dsi-flash.bin of=$img seek=64
|
||||
|
||||
if test -n "$compressImage"; then
|
||||
zstd -T$NIX_BUILD_CORES --rm $img
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
fetchFromGitHub,
|
||||
}:
|
||||
# script from https://source.mnt.re/reform/reform-rk3588-uboot/-/blob/28289e36cd1cb90b302780e83b014250c880c4ec/build.sh
|
||||
runCommand "mnt-reform-firmware-rk3855${uboot.variant}" { } ''
|
||||
runCommand "mnt-reform-uboot-image-rk3855${uboot.variant}" { } ''
|
||||
mkdir $out
|
||||
cp ${uboot}/idbloader.img $out/rk3588-mnt-reform2${uboot.variant}-flash.bin
|
||||
dd if=${uboot}/u-boot.itb of=$out/rk3588-mnt-reform${uboot.variant}-flash.bin seek=16320
|
||||
Loading…
Add table
Add a link
Reference in a new issue