-
Notifications
You must be signed in to change notification settings - Fork 1
/
create_bl_files.bat
281 lines (254 loc) · 11.8 KB
/
create_bl_files.bat
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
@echo off
:: use PATH_GCCARM env var to override default path for gcc-arm
if "%PATH_GCCARM%"=="" (
set OBJCOPY="%ARM_GCC_DIR%\bin\arm-none-eabi-objcopy.exe"
) else (
set OBJCOPY=%PATH_GCCARM%\bin\arm-none-eabi-objcopy.exe
)
:: use PATH_SCMD env var to override default path for Simplicity Commander
if NOT "%PATH_SCMD%"=="" (
set COMMANDER=%PATH_SCMD%\commander.exe
)
:: use PATH_OUT env var to override the full path for the .out file
:: default file extension of GCC and IAR
set FILE_EXTENSION_GCC="*.axf"
set FILE_EXTENSION_IAR="*.out"
:: names of the OTA and UART DFU output files
set OTA_APPLO_NAME=apploader
set OTA_APPLI_NAME=application
set UARTDFU_FULL_NAME=full
:: names of the sign and encypt key files
set GBL_SIGING_KEY_FILE=app-sign-key.pem
set GBL_ENCRYPT_KEY_FILE=app-encrypt-key.txt
:: bootlader file name
set BOOTLOADER_FILE=bootloader-second-stage.s37
:: project path
set PATH_PROJ=%~dp1
if "%PATH_PROJ%" == "" (
echo No project path specified. Using current directory.
echo.
set PATH_PROJ=%~dp0
)
:: output path of the OTA and UART DFU gbl files
set PATH_GBL="%PATH_PROJ%\output_gbl"
for /f "delims=" %%i in ('dir %PATH_PROJ%\*.axf %PATH_PROJ%\*.out /b/s/od') do set PATH_OUT=%%i
if "%PATH_OUT%"=="" (
echo Error: neither %FILE_EXTENSION_GCC% nor %FILE_EXTENSION_IAR% found
echo Was the project compiled and linked successfully?
pause
goto:eof
)
if not exist "%OBJCOPY%" (
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.
pause
goto:eof
)
if not exist "%COMMANDER%" (
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.
pause
goto:eof
)
if exist "%BOOTLOADER_FILE%" (
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.
)
if exist "%GBL_ENCRYPT_KEY_FILE%" (
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.
)
if exist "%GBL_SIGING_KEY_FILE%" (
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.
)
echo **********************************************************************
echo Converting .out to .gbl files
echo **********************************************************************
echo.
echo .out file used:
echo %PATH_OUT%
echo.
echo output folder:
echo %PATH_GBL%
if not exist %PATH_GBL% (
mkdir %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 errorlevel 1 (
pause
goto:eof
)
if exist %BOOTLOADER_FILE% (
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"
)
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 errorlevel 1 (
pause
goto:eof
)
%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 errorlevel 1 (
pause
goto:eof
)
%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 exist %GBL_ENCRYPT_KEY_FILE% (
echo.
echo **********************************************************************
echo Creating encrypted .gbl files
echo **********************************************************************
echo.
if exist %BOOTLOADER_FILE% (
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%
)
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%
)
:: create signed GBL file for secure boot if sign-key file exists
if exist %GBL_SIGING_KEY_FILE% (
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 exist "%PATH_GBL%\%OTA_APPLO_NAME%-signed.srec" (
if exist %BOOTLOADER_FILE% (
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%
)
)
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 exist "%PATH_GBL%\%OTA_APPLO_NAME%-signed.srec" (
%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 (
copy "%PATH_GBL%\%OTA_APPLI_NAME%-signed.srec" "%PATH_GBL%\%UARTDFU_FULL_NAME%-signed.srec" >NUL
)
%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 exist %GBL_ENCRYPT_KEY_FILE% (
echo.
echo **********************************************************************
echo Creating signed and encrypted .gbl files
echo **********************************************************************
echo.
if exist "%PATH_GBL%\%OTA_APPLO_NAME%-signed.srec" (
if exist %BOOTLOADER_FILE% (
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%
)
echo.
)
%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%
)
) 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 exist "%PATH_GBL%\%OTA_APPLO_NAME%-crc.srec" (
if exist %BOOTLOADER_FILE% (
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"
)
)
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 exist "%PATH_GBL%\%OTA_APPLO_NAME%-crc.srec" (
%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 (
copy "%PATH_GBL%\%OTA_APPLI_NAME%-crc.srec" "%PATH_GBL%\%UARTDFU_FULL_NAME%-crc.srec" >NUL
)
%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 exist %GBL_ENCRYPT_KEY_FILE% (
echo.
echo **********************************************************************
echo Creating crc and encrypted .gbl files
echo **********************************************************************
echo.
if exist "%PATH_GBL%\%OTA_APPLO_NAME%-crc.srec" (
if exist %BOOTLOADER_FILE% (
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%
)
echo.
)
%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%
)
)
:: clean up output dir
del "%PATH_GBL%\*.srec"
pause