Skip to content

Commit a31d53a

Browse files
committed
mnt-reform: Add uboot flash script
1 parent 20baaa0 commit a31d53a

File tree

4 files changed

+71
-4
lines changed

4 files changed

+71
-4
lines changed

mnt/reform/pkgs/default.nix

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
lib,
3+
callPackage,
4+
}:
5+
rec {
6+
reform-flash-uboot =
7+
lib.mapAttrs (name: config: callPackage ./reform-flash-uboot.nix { inherit config; })
8+
{
9+
reform2-rk3588-dsi = {
10+
warn = true;
11+
mmc = "mmcblk0";
12+
mmcBoot0 = false;
13+
ubootOffset = 32768;
14+
flashbinOffset = 0;
15+
image = "${ubootImage.reform2-rk3588-dsi}/rk3588-mnt-reform2-dsi-flash.bin";
16+
};
17+
};
18+
19+
uboot.reform2-rk3588-dsi = callPackage ../rk3588/uboot.nix { };
20+
ubootImage.reform2-rk3588-dsi = callPackage ../rk3588/uboot-image.nix {
21+
uboot = uboot.reform2-rk3588-dsi;
22+
};
23+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
{
2+
lib,
3+
writeShellApplication,
4+
config,
5+
}:
6+
let
7+
dev = "/dev/" + config.mmc + lib.optionalString config.mmcBoot0 "boot0";
8+
in
9+
writeShellApplication {
10+
name = "reform-flash-uboot";
11+
text = ''
12+
if [ "$(id -u)" -ne 0 ]; then
13+
echo "reform-flash-uboot has to be run as root / using sudo."
14+
exit 1
15+
fi
16+
''
17+
+ lib.optionalString config.warn ''
18+
echo "W: Flashing u-boot to eMMC on $(cat /proc/device-tree/model) is not without risk." >&2
19+
echo "W: If you flash the wrong u-boot or if the flashing process goes wrong, it is" >&2
20+
echo "W: possible to soft-brick your board. Restoring it might need some extra hardware." >&2
21+
echo "W: Please only proceed if you are sure that the benefits outweigh the risks for you." >&2
22+
printf "Are you sure you want to proceed? [y/N] "
23+
read -r response
24+
25+
if [ "$response" != "y" ]; then
26+
echo "Exiting."
27+
exit
28+
fi
29+
''
30+
+ ''
31+
echo "Writing ${config.image} to ${dev}" >&2
32+
''
33+
+ lib.optionalString config.mmcBoot0 ''
34+
echo 0 >"/sys/class/block/${config.mmc}boot0/force_ro"
35+
''
36+
+ ''
37+
dd if='${config.image}' of='${dev}' bs=512 seek='${
38+
builtins.toString (config.ubootOffset / 512)
39+
}' skip='${builtins.toString (config.flashbinOffset / 512)}'
40+
''
41+
+ lib.optionalString config.mmcBoot0 ''
42+
echo 1 >"/sys/class/block/${config.mmc}boot0/force_ro"
43+
'';
44+
}

mnt/reform/rk3588/installer.nix

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@
4444
storeContents = config.installerImage.storeContents;
4545
comp = config.installerImage.squashfsCompression;
4646
};
47-
uboot = pkgs.callPackage ./uboot.nix { };
48-
firmware = pkgs.callPackage ./firmware.nix { inherit uboot; };
47+
packages = pkgs.callPackage ../pkgs { };
48+
ubootImage = packages.ubootImage.reform2-rk3588-dsi;
4949
content = pkgs.callPackage (
5050
{
5151
stdenv,
@@ -215,7 +215,7 @@
215215
eval $(partx $img -o START,SECTORS --nr 1 --pairs)
216216
dd conv=notrunc if=${content} of=$img seek=$START count=$SECTORS
217217
218-
dd conv=notrunc if=${firmware}/rk3588-mnt-reform2-dsi-flash.bin of=$img seek=64
218+
dd conv=notrunc if=${ubootImage}/rk3588-mnt-reform2-dsi-flash.bin of=$img seek=64
219219
220220
if test -n "$compressImage"; then
221221
zstd -T$NIX_BUILD_CORES --rm $img

mnt/reform/rk3588/firmware.nix renamed to mnt/reform/rk3588/uboot-image.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
fetchFromGitHub,
55
}:
66
# script from https://source.mnt.re/reform/reform-rk3588-uboot/-/blob/28289e36cd1cb90b302780e83b014250c880c4ec/build.sh
7-
runCommand "mnt-reform-firmware-rk3855${uboot.variant}" { } ''
7+
runCommand "mnt-reform-uboot-image-rk3855${uboot.variant}" { } ''
88
mkdir $out
99
cp ${uboot}/idbloader.img $out/rk3588-mnt-reform2${uboot.variant}-flash.bin
1010
dd if=${uboot}/u-boot.itb of=$out/rk3588-mnt-reform${uboot.variant}-flash.bin seek=16320

0 commit comments

Comments
 (0)