-
Notifications
You must be signed in to change notification settings - Fork 0
/
create_bl_files.sh
282 lines (254 loc) · 12.6 KB
/
create_bl_files.sh
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
#!/bin/sh
# use PATH_GCCARM env var to override default path for gcc-arm
if [[ -z ${PATH_GCCARM} ]]; then
OBJCOPY="${ARM_GCC_DIR}/bin/arm-none-eabi-objcopy"
if [[ `uname` == CYGWIN* ]]; then OBJCOPY="`cygpath ${OBJCOPY}`"; fi
else
OBJCOPY="${PATH_GCCARM}/bin/arm-none-eabi-objcopy"
fi
# use PATH_SCMD env var to set path for Simplicity Commander
if [[ -n ${PATH_SCMD} ]]; then
COMMANDER="${PATH_SCMD}/commander"
fi
# use PATH_OUT env var to override the full path for the .out file
# default file extension of GCC and IAR
FILE_EXTENSION_GCC="*.axf"
FILE_EXTENSION_IAR="*.out"
# names of the OTA and UART DFU output files
OTA_APPLO_NAME="apploader"
OTA_APPLI_NAME="application"
UARTDFU_FULL_NAME="full"
# names of the sign and encypt key files
GBL_SIGING_KEY_FILE="app-sign-key.pem"
GBL_ENCRYPT_KEY_FILE="app-encrypt-key.txt"
# bootlader file name
BOOTLOADER_FILE="bootloader-second-stage.s37"
# project path
PATH_PROJ="$1"
if [ -z "$PATH_PROJ" ]; then
echo "No project path specified. Using script directory as root."
echo
PATH_PROJ="$(dirname $0)"
fi
# output path of the OTA and UART DFU gbl files
PATH_GBL="${PATH_PROJ}/output_gbl"
# out file path
PATH_OUT=`find ${PATH_PROJ} -type f \( -iname ${FILE_EXTENSION_GCC} -or -iname ${FILE_EXTENSION_IAR} \) -exec echo {} \;`
if [[ -z ${PATH_OUT} ]]; then
echo "Error: neither ${FILE_EXTENSION_GCC} nor ${FILE_EXTENSION_IAR} found"
echo "Was the project compiled and linked successfully?"
read -rsp $'Press enter to continue...\n'
exit
fi
if [[ ! -f "${OBJCOPY}" ]]; then
echo "Error: gcc-arm objcopy not found at '${OBJCOPY}'"
echo "Use PATH_GCCARM env var to override default path for gcc-arm."
echo "Please refer to AN1086 sections 2.3 and 3.10 on how to set the required"
echo "environmental variables."
read -rsp $'Press enter to continue...\n'
exit
fi
if [[ ! -f "${COMMANDER}" ]]; then
echo "Error: Simplicity Commander not found at '${COMMANDER}'"
echo "Use PATH_SCMD env var to override default path for Simplicity Commander."
echo "Please refer to AN1086 sections 2.3 and 3.10 on how to set the required"
echo "environmental variables."
read -rsp $'Press enter to continue...\n'
exit
fi
if [[ -f "$BOOTLOADER_FILE" ]]; then
echo "Bootloader file was found"
else
echo "Bootloader file was not found"
echo "---- BOOTLOADER GENERATION -------------------------------------------"
echo "For adding bootloader to apploader copy a bootloader s37 image, e.g."
echo "'bootloader-storage-internal-single.s37' to the project root folder,"
echo "rename it to 'bootloader-second-stage.s37' and rerun the script file."
echo "----------------------------------------------------------------------"
echo
fi
if [[ -f "$GBL_ENCRYPT_KEY_FILE" ]]; then
echo "Encryption key file was found"
else
echo "Encryption key file was not found"
echo "---- ENCRYPTED GBL FILE GENERATION -----------------------------------"
echo "To generate an encrypted firmware upgrade file,"
echo "copy an encryption key file into the root folder of the project,"
echo "rename it to 'app-encrypt-key.txt' and rerun the script file."
echo "----------------------------------------------------------------------"
echo
fi
if [[ -f "$GBL_SIGING_KEY_FILE" ]]; then
echo "Signing key file was found"
else
echo "Signing key file was not found"
echo "---- SIGNED GBL FILE GENERATION --------------------------------------"
echo "To generate a signed firmware upgrade file,"
echo "copy a signing key file into the root folder of the project,"
echo "rename it to 'app-sign-key.pem' and rerun the script file."
echo "----------------------------------------------------------------------"
echo
fi
echo "**********************************************************************"
echo "Converting .out to .gbl files"
echo "**********************************************************************"
echo
echo ".out file used:"
echo "${PATH_OUT}"
echo
echo "output folder:"
echo "${PATH_GBL}"
mkdir -p ${PATH_GBL}
# create the GBL files
echo
echo "**********************************************************************"
echo "Creating ${OTA_APPLO_NAME}.gbl for OTA"
echo "**********************************************************************"
echo
"${OBJCOPY}" -O srec -j .text_apploader* "${PATH_OUT}" "${PATH_GBL}/${OTA_APPLO_NAME}.srec"
if [ $? -ne 0 ]; then
read -rsp $'Press enter to continue...\n'
exit
fi
if [[ -f $BOOTLOADER_FILE ]]; then
echo "Bootloader file was found"
"${COMMANDER}" gbl create "${PATH_GBL}/${OTA_APPLO_NAME}-bootloader.gbl" --app "${PATH_GBL}/${OTA_APPLO_NAME}.srec" --bootloader ${BOOTLOADER_FILE}
else
"${COMMANDER}" gbl create "${PATH_GBL}/${OTA_APPLO_NAME}.gbl" --app "${PATH_GBL}/${OTA_APPLO_NAME}.srec"
fi
echo
echo "**********************************************************************"
echo "Creating ${OTA_APPLI_NAME}.gbl for OTA"
echo "**********************************************************************"
echo
"${OBJCOPY}" -O srec -R .text_apploader* -R .text_signature* "${PATH_OUT}" "${PATH_GBL}/${OTA_APPLI_NAME}.srec"
if [ $? -ne 0 ]; then
read -rsp $'Press enter to continue...\n'
exit
fi
"${COMMANDER}" gbl create "${PATH_GBL}/${OTA_APPLI_NAME}.gbl" --app "${PATH_GBL}/${OTA_APPLI_NAME}.srec"
# create the full GBL files for UART DFU
echo
echo "**********************************************************************"
echo "Creating ${UARTDFU_FULL_NAME}.gbl for UART DFU"
echo "**********************************************************************"
echo
"${OBJCOPY}" -O srec -R .text_bootloader* "${PATH_OUT}" "${PATH_GBL}/${UARTDFU_FULL_NAME}.srec"
if [ $? -ne 0 ]; then
read -rsp $'Press enter to continue...\n'
exit
fi
"${COMMANDER}" gbl create "${PATH_GBL}/${UARTDFU_FULL_NAME}.gbl" --app "${PATH_GBL}/${UARTDFU_FULL_NAME}.srec"
# create encrypted GBL file for secure boot if encrypt-key file exist
if [[ -f $GBL_ENCRYPT_KEY_FILE ]]; then
echo
echo "**********************************************************************"
echo "Creating encrypted .gbl files"
echo "**********************************************************************"
echo
if [[ -f $BOOTLOADER_FILE ]]; then
echo "Bootloader file was found"
"${COMMANDER}" gbl create "${PATH_GBL}/${OTA_APPLO_NAME}-bootloader-encrypted.gbl" --app "${PATH_GBL}/${OTA_APPLO_NAME}.srec" --encrypt ${GBL_ENCRYPT_KEY_FILE} --bootloader ${BOOTLOADER_FILE}
else
"${COMMANDER}" gbl create "${PATH_GBL}/${OTA_APPLO_NAME}-encrypted.gbl" --app "${PATH_GBL}/${OTA_APPLO_NAME}.srec" --encrypt ${GBL_ENCRYPT_KEY_FILE}
fi
echo
"${COMMANDER}" gbl create "${PATH_GBL}/${OTA_APPLI_NAME}-encrypted.gbl" --app "${PATH_GBL}/${OTA_APPLI_NAME}.srec" --encrypt ${GBL_ENCRYPT_KEY_FILE}
echo
"${COMMANDER}" gbl create "${PATH_GBL}/${UARTDFU_FULL_NAME}-encrypted.gbl" --app "${PATH_GBL}/${UARTDFU_FULL_NAME}.srec" --encrypt ${GBL_ENCRYPT_KEY_FILE}
fi
# create signed GBL file for secure boot if sign-key file exists
if [[ -f $GBL_SIGING_KEY_FILE ]]; then
echo
echo "**********************************************************************"
echo "Creating signed .gbl files"
echo "**********************************************************************"
echo
"${COMMANDER}" convert "${PATH_GBL}/${OTA_APPLO_NAME}.srec" --secureboot --keyfile ${GBL_SIGING_KEY_FILE} -o "${PATH_GBL}/${OTA_APPLO_NAME}-signed.srec"
if [[ -f "${PATH_GBL}/${OTA_APPLO_NAME}-signed.srec" ]]; then
if [[ -f $BOOTLOADER_FILE ]]; then
echo "Bootloader file was found"
"${COMMANDER}" gbl create "${PATH_GBL}/${OTA_APPLO_NAME}-bootloader-signed.gbl" --app "${PATH_GBL}/${OTA_APPLO_NAME}-signed.srec" --sign ${GBL_SIGING_KEY_FILE} --bootloader ${BOOTLOADER_FILE}
else
"${COMMANDER}" gbl create "${PATH_GBL}/${OTA_APPLO_NAME}-signed.gbl" --app "${PATH_GBL}/${OTA_APPLO_NAME}-signed.srec" --sign ${GBL_SIGING_KEY_FILE}
fi
fi
echo
"${COMMANDER}" convert "${PATH_GBL}/${OTA_APPLI_NAME}.srec" --secureboot --keyfile ${GBL_SIGING_KEY_FILE} -o "${PATH_GBL}/${OTA_APPLI_NAME}-signed.srec"
"${COMMANDER}" gbl create "${PATH_GBL}/${OTA_APPLI_NAME}-signed.gbl" --app "${PATH_GBL}/${OTA_APPLI_NAME}-signed.srec" --sign ${GBL_SIGING_KEY_FILE}
echo
if [[ -f "${PATH_GBL}/${OTA_APPLO_NAME}-signed.srec" ]]; then
"${COMMANDER}" convert "${PATH_GBL}/${OTA_APPLO_NAME}-signed.srec" "${PATH_GBL}/${OTA_APPLI_NAME}-signed.srec" -o "${PATH_GBL}/${UARTDFU_FULL_NAME}-signed.srec"
else
cp "${PATH_GBL}/${OTA_APPLI_NAME}-signed.srec" "${PATH_GBL}/${UARTDFU_FULL_NAME}-signed.srec"
fi
"${COMMANDER}" gbl create "${PATH_GBL}/${UARTDFU_FULL_NAME}-signed.gbl" --app "${PATH_GBL}/${UARTDFU_FULL_NAME}-signed.srec" --sign ${GBL_SIGING_KEY_FILE}
# create signed and encrypted GBL file for if both sign-key and encrypt-key file exist
if [[ -f $GBL_ENCRYPT_KEY_FILE ]]; then
echo
echo "**********************************************************************"
echo "Creating signed and encrypted .gbl files"
echo "**********************************************************************"
echo
if [[ -f "${PATH_GBL}/${OTA_APPLO_NAME}-signed.srec" ]]; then
if [[ -f $BOOTLOADER_FILE ]]; then
echo "Bootloader file was found"
"${COMMANDER}" gbl create "${PATH_GBL}/${OTA_APPLO_NAME}-bootloader-signed-encrypted.gbl" --app "${PATH_GBL}/${OTA_APPLO_NAME}-signed.srec" --encrypt ${GBL_ENCRYPT_KEY_FILE} --sign ${GBL_SIGING_KEY_FILE} --bootloader ${BOOTLOADER_FILE}
else
"${COMMANDER}" gbl create "${PATH_GBL}/${OTA_APPLO_NAME}-signed-encrypted.gbl" --app "${PATH_GBL}/${OTA_APPLO_NAME}-signed.srec" --encrypt ${GBL_ENCRYPT_KEY_FILE} --sign ${GBL_SIGING_KEY_FILE}
fi
echo
fi
"${COMMANDER}" gbl create "${PATH_GBL}/${OTA_APPLI_NAME}-signed-encrypted.gbl" --app "${PATH_GBL}/${OTA_APPLI_NAME}-signed.srec" --encrypt ${GBL_ENCRYPT_KEY_FILE} --sign ${GBL_SIGING_KEY_FILE}
echo
"${COMMANDER}" gbl create "${PATH_GBL}/${UARTDFU_FULL_NAME}-signed-encrypted.gbl" --app "${PATH_GBL}/${UARTDFU_FULL_NAME}-signed.srec" --encrypt ${GBL_ENCRYPT_KEY_FILE} --sign ${GBL_SIGING_KEY_FILE}
fi
else
echo
echo "**********************************************************************"
echo "Creating crc .gbl files"
echo "**********************************************************************"
echo
"${COMMANDER}" convert "${PATH_GBL}/${OTA_APPLO_NAME}.srec" --crc -o "${PATH_GBL}/${OTA_APPLO_NAME}-crc.srec"
if [[ -f "${PATH_GBL}/${OTA_APPLO_NAME}-crc.srec" ]]; then
if [[ -f $BOOTLOADER_FILE ]]; then
echo "Bootloader file was found"
"${COMMANDER}" gbl create "${PATH_GBL}/${OTA_APPLO_NAME}-bootloader-crc.gbl" --app "${PATH_GBL}/${OTA_APPLO_NAME}-crc.srec" --bootloader ${BOOTLOADER_FILE}
else
"${COMMANDER}" gbl create "${PATH_GBL}/${OTA_APPLO_NAME}-crc.gbl" --app "${PATH_GBL}/${OTA_APPLO_NAME}-crc.srec"
fi
fi
echo
"${COMMANDER}" convert "${PATH_GBL}/${OTA_APPLI_NAME}.srec" --crc -o "${PATH_GBL}/${OTA_APPLI_NAME}-crc.srec"
"${COMMANDER}" gbl create "${PATH_GBL}/${OTA_APPLI_NAME}-crc.gbl" --app "${PATH_GBL}/${OTA_APPLI_NAME}-crc.srec"
echo
if [[ -f "${PATH_GBL}/${OTA_APPLO_NAME}-crc.srec" ]]; then
"${COMMANDER}" convert "${PATH_GBL}/${OTA_APPLO_NAME}-crc.srec" "${PATH_GBL}/${OTA_APPLI_NAME}-crc.srec" -o "${PATH_GBL}/${UARTDFU_FULL_NAME}-crc.srec"
else
cp "${PATH_GBL}/${OTA_APPLI_NAME}-crc.srec" "${PATH_GBL}/${UARTDFU_FULL_NAME}-crc.srec"
fi
"${COMMANDER}" gbl create "${PATH_GBL}/${UARTDFU_FULL_NAME}-crc.gbl" --app "${PATH_GBL}/${UARTDFU_FULL_NAME}-crc.srec"
# create crc and encrypted GBL file if encrypt-key file exist
if [[ -f $GBL_ENCRYPT_KEY_FILE ]]; then
echo
echo "**********************************************************************"
echo "Creating crc and encrypted .gbl files"
echo "**********************************************************************"
echo
if [[ -f "${PATH_GBL}/${OTA_APPLO_NAME}-crc.srec" ]]; then
if [[ -f $BOOTLOADER_FILE ]]; then
echo "Bootloader file was found"
"${COMMANDER}" gbl create "${PATH_GBL}/${OTA_APPLO_NAME}-bootloader-crc-encrypted.gbl" --app "${PATH_GBL}/${OTA_APPLO_NAME}-crc.srec" --encrypt ${GBL_ENCRYPT_KEY_FILE} --bootloader ${BOOTLOADER_FILE}
else
"${COMMANDER}" gbl create "${PATH_GBL}/${OTA_APPLO_NAME}-crc-encrypted.gbl" --app "${PATH_GBL}/${OTA_APPLO_NAME}-crc.srec" --encrypt ${GBL_ENCRYPT_KEY_FILE}
fi
echo
fi
"${COMMANDER}" gbl create "${PATH_GBL}/${OTA_APPLI_NAME}-crc-encrypted.gbl" --app "${PATH_GBL}/${OTA_APPLI_NAME}-crc.srec" --encrypt ${GBL_ENCRYPT_KEY_FILE}
echo
"${COMMANDER}" gbl create "${PATH_GBL}/${UARTDFU_FULL_NAME}-crc-encrypted.gbl" --app "${PATH_GBL}/${UARTDFU_FULL_NAME}-crc.srec" --encrypt ${GBL_ENCRYPT_KEY_FILE}
fi
fi
# clean up output dir
rm "${PATH_GBL}"/*.srec
read -rsp $'Press enter to continue...\n'