forked from anduril/jetpack-nixos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
flash-script.nix
76 lines (58 loc) · 2.23 KB
/
flash-script.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
{ lib, flash-tools,
preFlashCommands ? "", flashCommands ? "", postFlashCommands ? "", flashArgs ? [], partitionTemplate ? null,
socType ? null,
# Optional directory containing DTBs to be used by flashing script, which can
# be used by the bootloader(s) and passed to the kernel.
dtbsDir ? null,
# Optional package containing uefi_jetson.efi to replace prebuilt version
uefi-firmware ? null,
# Optional package containing tos.img to replace prebuilt version
tosImage ? null,
# Optional EKS file containing encrypted keyblob
eksFile ? null,
# Additional DTB overlays to use during device flashing
additionalDtbOverlays ? [],
}:
''
set -euo pipefail
if [[ -z ''${WORKDIR-} ]]; then
WORKDIR=$(mktemp -d)
function on_exit() {
rm -rf "$WORKDIR"
}
trap on_exit EXIT
fi
cp -r ${flash-tools}/. "$WORKDIR"
chmod -R u+w "$WORKDIR"
cd "$WORKDIR"
# Make nvidia's flash script happy by adding all this stuff to our PATH
export PATH=${lib.makeBinPath flash-tools.flashDeps}:$PATH
export NO_ROOTFS=1
export NO_RECOVERY_IMG=1
export NO_ESP_IMG=1
export ADDITIONAL_DTB_OVERLAY=''${ADDITIONAL_DTB_OVERLAY:+$ADDITIONAL_DTB_OVERLAY,}${lib.concatStringsSep "," additionalDtbOverlays}
${lib.optionalString (partitionTemplate != null) "cp ${partitionTemplate} flash.xml"}
${lib.optionalString (dtbsDir != null) "cp -r ${dtbsDir}/. kernel/dtb/"}
${lib.optionalString (uefi-firmware != null) ''
cp ${uefi-firmware}/uefi_jetson.bin bootloader/uefi_jetson.bin
# For normal NixOS usage, we'd probably use systemd-boot or GRUB instead,
# but lets replace the upstream L4TLauncher EFI payload anyway
cp ${uefi-firmware}/L4TLauncher.efi bootloader/BOOTAA64.efi
# Replace additional dtbos
cp ${uefi-firmware}/dtbs/*.dtbo kernel/dtb/
''}
${lib.optionalString (tosImage != null) ''
cp ${tosImage}/tos.img bootloader/tos-optee_${socType}.img
''}
${lib.optionalString (eksFile != null) ''
cp ${eksFile} bootloader/eks_${socType}.img
''}
${preFlashCommands}
chmod -R u+w .
'' + (if (flashCommands != "") then ''
${flashCommands}
'' else ''
./flash.sh ${lib.optionalString (partitionTemplate != null) "-c flash.xml"} "$@" ${builtins.toString flashArgs}
'') + ''
${postFlashCommands}
''