-
Notifications
You must be signed in to change notification settings - Fork 0
/
create_bl_files.bat
171 lines (149 loc) · 6.7 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
@echo off
:: THIS FILE IS GENERATED BY APPBUILDER, DO NOT MODIFY
:: CONFIGURE VIA ENV VARS
:: use PATH_GCCARM env var to override default path for gcc-arm
if "%PATH_GCCARM%"=="" (
set OBJCOPY="C:\SiliconLabs\SimplicityStudio\v4\developer\toolchains\gnu_arm\4.9_2015q3\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 "%PATH_SCMD%"=="" (
set COMMANDER="C:\SiliconLabs\SimplicityStudio\v4\developer\adapter_packs\commander\commander.exe"
) else (
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"
:: output path of the OTA and UART DFU gbl files (relative to project root)
set PATH_GBL=output_gbl
:: 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
:: change the working dir to the dir of the batch file, which should be in the project root
cd %~dp0
for /f "delims=" %%i in ('dir *.axf *.out /b/s') 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.
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.
pause
goto:eof
)
echo **********************************************************************
echo Converting .out to .gbl files
echo **********************************************************************
echo.
echo .out file used:
echo %PATH_OUT%
echo.
echo output folders:
echo %~dp0%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
)
%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 -j .text_application* "%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.
%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" (
%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" (
%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%
)
)
:: clean up output dir
del "%PATH_GBL%\*.srec"
pause