-
Notifications
You must be signed in to change notification settings - Fork 10
/
Justfile
95 lines (72 loc) · 3.66 KB
/
Justfile
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# SPDX-FileCopyrightText: © 2021 Foundation Devices, Inc. <[email protected]>
#
# SPDX-License-Identifier: GPL-3.0-or-later
contribdir := join(justfile_directory(), "../contrib")
openocd_cfg := join(contribdir, "openocd.cfg")
# Launch OCD, run a command and then exit
@run-ocd-command command:
openocd -f {{openocd_cfg}} -c "init; reset halt; {{command}}" -c "exit"
# Build the bootloader (debug, release, locked or production)
# NOTE: Pass "factory_test" for factory_test to enable it.
build screen="mono" rel="release" factory_test="": clean
#!/usr/bin/env bash
set -e
echo -e "\nBuilding Bootloader..."
echo {{ if screen == "mono" { "Building with SCREEN_MODE=MONO" } else if screen == "color" { "Building with SCREEN_MODE=COLOR" } else { error("Unsupported screen type. Use 'mono' or 'color'") } }}
make {{rel}} SCREEN_MODE={{uppercase(screen)}} FACTORY_TEST={{factory_test}}
if [[ "{{rel}}" == "debug" ]]; then
FOLDER=debug
else
FOLDER=release
fi
# if test -f "secrets"; then
# echo -e "\nAppending secrets to the end..."
# add-secrets -b arm/${FOLDER}/bootloader-{{uppercase(screen)}}.bin -s secrets
# fi
echo -e "\nBootloader Build Complete"
# Clean the bootloader build
clean:
@echo "Cleaning Bootloader..."
make clean
@echo "Bootloader Clean Complete"
# Build and flash the bootloader, appending the existing secrets, if any.
# If no secrets are present in the device, then just flash the raw bootloader.
flash screen="mono" rel="release" factory_test="": (build screen rel factory_test) && (reset)
#!/usr/bin/env bash
set -euo pipefail
EMPTY_SECRETS_BIN=$(mktemp /tmp/foundatiob-bl-flash.XXXXXX)
DEVICE_SECRETS_BIN=$(mktemp /tmp/foundation-bl-flash.XXXXXX)
printf -- 'FF %.0s' {1..256} | xxd -r -p - ${EMPTY_SECRETS_BIN}
just save-secrets {{screen}} ${DEVICE_SECRETS_BIN}
if cmp -s ${DEVICE_SECRETS_BIN} ${EMPTY_SECRETS_BIN};
then
echo "Board doesn't have secrets, flashing raw firmware"
just run-ocd-command "flash write_image erase arm/{{rel}}/bootloader-{{uppercase(screen)}}.bin 0x8000000"
else
echo "Appending existing secrets to the bootloader"
add-secrets -b "arm/{{rel}}/bootloader-{{uppercase(screen)}}.bin" -s ${DEVICE_SECRETS_BIN}
echo "Flashing bootloader with secrets"
just run-ocd-command "flash write_image erase arm/{{rel}}/bootloader-{{uppercase(screen)}}-secrets.bin 0x8000000"
fi
# Remove the tmp files
rm -f ${EMPTY_SECRETS_BIN}
rm -f ${DEVICE_SECRETS_BIN}
# Build and flash the bootloader with no secrets (use to setup a new Secure Element)
flash-only screen="mono" rel="release": && (reset)
just run-ocd-command "flash write_image erase arm/{{rel}}/bootloader-{{uppercase(screen)}}.bin 0x8000000"
# Build and flash the bootloader with saved secrets (use to restore the bootloader of a bricked device)
flash-with-secrets screen="mono" rel="release": && (reset)
add-secrets -b "arm/{{rel}}/bootloader-{{uppercase(screen)}}.bin" -s secrets
just run-ocd-command "flash write_image erase arm/{{rel}}/bootloader-{{uppercase(screen)}}-secrets.bin 0x8000000"
# Reset the Passport
reset: (run-ocd-command "reset")
# Read the "ROM Secrets" from Passport and save them to a file
save-secrets screen="mono" filename="secrets":
#!/usr/bin/env bash
set -euo pipefail
# Get the secrets address depending on the selected screen mode.
BL_NVROM_BASE=$(make bl_nvrom_base SCREEN_MODE={{uppercase(screen)}})
echo "Bootloader secrets address for '{{screen}}': $BL_NVROM_BASE"
just run-ocd-command "dump_image {{filename}} $BL_NVROM_BASE 256"
images:
just ../../../images