fastboot_imx_flashall.bat
10.9 KB
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
283
284
285
286
287
288
289
290
291
:: This script is used for flashing i.MX android images whit fastboot.
@echo off
::---------------------------------------------------------------------------------
::Variables
::---------------------------------------------------------------------------------
:: For batch script, %0 is not script name in a so-called function, so save the script name here
set script_first_argument=%0
:: For users execute this script in powershell, clear the quation marks first.
set script_first_argument=%script_first_argument:"=%
:: reserve last 25 characters, which is the lenght of the name of this script file.
set script_name=%script_first_argument:~-25%
set soc_name=
set device_character=
set /A card_size=0
set slot=
set bootimage=boot.img
set systemimage_file=system.img
set vendor_file=vendor.img
set partition_file=partition-table.img
set /A support_dtbo=0
set /A support_recovery=0
set /A support_dualslot=0
set /A support_m4_os=0
set /A support_dual_bootloader=0
set dual_bootloader_partition=
set bootloader_flashed_to_board=
set uboot_proper_to_be_flashed=
set bootloader_partition=bootloader
set boot_partition=boot
set recovery_partition=recovery
set system_partition=system
set vendor_partition=vendor
set vbmeta_partition=vbmeta
set dtbo_partition=dtbo
set m4_os_partition=m4_os
set /A flash_m4=0
set /A statisc=0
set /A lock=0
set /A erase=0
set image_directory=
set ser_num=
set fastboot_tool=fastboot
set /A error_level=0
::---------------------------------------------------------------------------------
::Parse command line
::---------------------------------------------------------------------------------
:: If no option provied when executing this script, show help message and exit.
if [%1] == [] call :help goto :eof
:parse_loop
if [%1] == [] goto :parse_end
if %1 == -h call :help & goto :eof
if %1 == -f set soc_name=%2& shift & shift & goto :parse_loop
if %1 == -c set /A card_size=%2& shift & shift & goto :parse_loop
if %1 == -d set device_character=%2& shift & shift & goto :parse_loop
if %1 == -a set slot=_a& shift & goto :parse_loop
if %1 == -b set slot=_b& shift & goto :parse_loop
if %1 == -m set /A flash_m4=1 & shift & goto :parse_loop
if %1 == -l set /A lock=1 & shift & goto :parse_loop
if %1 == -e set /A erase=1 & shift & goto :parse_loop
if %1 == -D set image_directory=%2& shift & shift & goto :parse_loop
if %1 == -s set ser_num=%2&shift &shift & goto :parse_loop
call :help & goto :eof
:parse_end
:: If sdcard size is not correctly set, exit
if %card_size% neq 0 set /A statisc+=1
if %card_size% neq 7 set /A statisc+=1
if %card_size% neq 14 set /A statisc+=1
if %card_size% neq 28 set /A statisc+=1
if %statisc% == 4 echo card_size is not a legal value & goto :eof
if %card_size% gtr 0 set partition_file=partition-table-%card_size%GB.img
:: if directory is specified, and the last character is not backslash, add one backslash
if not [%image_directory%] == [] if not %image_directory:~-1% == \ (
set image_directory=%image_directory%\
)
if not [%ser_num%] == [] set fastboot_tool=fastboot -s %ser_num%
::---------------------------------------------------------------------------------
:: Invoke function to flash android images
::---------------------------------------------------------------------------------
call :flash_android || set /A error_level=1 && goto :exit
if %erase% == 1 (
%fastboot_tool% erase userdata
%fastboot_tool% erase misc
if %soc_name:imx8=% == %soc_name% (
%fastboot_tool% erase cache
)
)
if %lock% == 1 %fastboot_tool% oem lock
echo #######ALL IMAGE FILES FLASHED#######
::---------------------------------------------------------------------------------
:: The execution will end.
::---------------------------------------------------------------------------------
goto :eof
::----------------------------------------------------------------------------------
:: Function definition
::----------------------------------------------------------------------------------
:help
echo Version: 1.2
echo Last change: Add -s option. fix errors when -D option not specified. handle situations that illegal options provided.
echo.
echo eg: fastboot_imx_flashall.bat -f imx8mm -a -D C:\Users\user_01\Android\images\2018.10.07\evk_8mm
echo eg: fastboot_imx_flashall.bat -f imx7ulp -D C:\Users\user_01\Android\images\2018.10.07\evk_7ulp
echo.
echo Usage: %script_name% ^<option^>
echo.
echo options:
echo -h displays this help message
echo -f soc_name flash android image file with soc_name
echo -a only flash image to slot_a
echo -b only flash image to slot_b
echo -c card_size optional setting: 7 / 14 / 28
echo If not set, use partition-table.img (default)
echo If set to 7, use partition-table-7GB.img for 8GB SD card
echo If set to 14, use partition-table-14GB.img for 16GB SD card
echo If set to 28, use partition-table-28GB.img for 32GB SD card
echo Make sure the corresponding file exist for your platform
echo -m flash m4 image
echo -d dev flash dtbo, vbmeta and recovery image file with dev
echo If not set, use default dtbo, vbmeta and recovery image
echo -e erase user data after all image files being flashed
echo -l lock the device after all image files being flashed
echo -D directory the directory of of images
echo No need to use this option if images are in current working directory
echo -s ser_num the serial number of board
echo If only one board connected to computer, no need to use this option
goto :eof
:flash_partition
set partition_to_be_flashed=%1
:: if there is slot information, delete it.
set local_str=%1
set local_str=%local_str:_a=%
set local_str=%local_str:_b=%
set img_name=%local_str%-%soc_name%.img
if not [%partition_to_be_flashed:bootloader_=%] == [%partition_to_be_flashed%] (
set img_name=%uboot_proper_to_be_flashed%
goto :start_to_flash
)
if not [%partition_to_be_flashed:system=%] == [%partition_to_be_flashed%] (
set img_name=%systemimage_file%
goto :start_to_flash
)
if not [%partition_to_be_flashed:vendor=%] == [%partition_to_be_flashed%] (
set img_name=%vendor_file%
goto :start_to_flash
)
if not [%partition_to_be_flashed:m4_os=%] == [%partition_to_be_flashed%] (
set img_name=%soc_name%_m4_demo.img
goto :start_to_flash
)
if not [%partition_to_be_flashed:vbmeta=%] == [%partition_to_be_flashed%] if not [%device_character%] == [] (
set img_name=%local_str%-%soc_name%-%device_character%.img
goto :start_to_flash
)
if not [%partition_to_be_flashed:dtbo=%] == [%partition_to_be_flashed%] if not [%device_character%] == [] (
set img_name=%local_str%-%soc_name%-%device_character%.img
goto :start_to_flash
)
if not [%partition_to_be_flashed:recovery=%] == [%partition_to_be_flashed%] if not [%device_character%] == [] (
set img_name=%local_str%-%soc_name%-%device_character%.img
goto :start_to_flash
)
if not [%partition_to_be_flashed:bootloader=%] == [%partition_to_be_flashed%] (
set img_name=%bootloader_flashed_to_board%
goto :start_to_flash
)
if %support_dtbo% == 1 (
if not [%partition_to_be_flashed:boot=%] == [%partition_to_be_flashed%] (
set img_name=%bootimage%
goto :start_to_flash
)
)
if not [%partition_to_be_flashed:gpt=%] == [%partition_to_be_flashed%] (
set img_name=%partition_file%
goto :start_to_flash
)
:start_to_flash
echo flash the file of %img_name% to the partition of %partition_to_be_flashed%
%fastboot_tool% flash %1 %image_directory%%img_name% || set /A error_level=1 && goto :exit
goto :eof
:flash_userpartitions
if %support_dual_bootloader% == 1 call :flash_partition %dual_bootloader_partition% || set /A error_level=1 && goto :exit
if %support_dtbo% == 1 call :flash_partition %dtbo_partition% || set /A error_level=1 && goto :exit
if %support_recovery% == 1 call :flash_partition %recovery_partition% || set /A error_level=1 && goto :exit
call :flash_partition %boot_partition% || set /A error_level=1 && goto :exit
call :flash_partition %system_partition% || set /A error_level=1 && goto :exit
call :flash_partition %vendor_partition% || set /A error_level=1 && goto :exit
call :flash_partition %vbmeta_partition% || set /A error_level=1 && goto :exit
goto :eof
:flash_partition_name
set boot_partition=boot%1
set recovery_partition=recovery%1
set system_partition=system%1
set vendor_partition=vendor%1
set vbmeta_partition=vbmeta%1
set dtbo_partition=dtbo%1
if %support_dual_bootloader% == 1 (
set dual_bootloader_partition=bootloader%1
)
goto :eof
:flash_android
call :flash_partition gpt || set /A error_level=1 && goto :exit
%fastboot_tool% getvar all 2> fastboot_var.log
find "bootloader_a" fastboot_var.log > nul && set /A support_dual_bootloader=1
find "dtbo" fastboot_var.log > nul && set /A support_dtbo=1
find "recovery" fastboot_var.log > nul && set /A support_recovery=1
::use boot_b to check whether current gpt support a/b slot
find "boot_b" fastboot_var.log > nul && set /A support_dualslot=1
find "m4_os" fastboot_var.log > nul && set /A support_m4_os=1
if %support_dual_bootloader% == 1 (
set bootloader_flashed_to_board=spl-%soc_name%.bin
set uboot_proper_to_be_flashed=bootloader-%soc_name%.img
) else (
set bootloader_flashed_to_board=u-boot-%soc_name%.imx
if [%soc_name%] == [imx8mm] (
if [%device_character%] == [ddr4] (
set bootloader_flashed_to_board=u-boot-%soc_name%-ddr4.imx
)
)
)
if not %soc_name:imx8=% == %soc_name% set bootloader_partition=bootloader0
call :flash_partition %bootloader_partition% || set /A error_level=1 && goto :exit
if %support_dualslot% == 0 set slot=
if %flash_m4% == 1 if %support_m4_os% == 1 call :flash_partition %m4_os_partition% || set /A error_level=1 && goto :exit
if [%slot%] == [] if %support_dualslot% == 1 (
:: flash image to both a and b slot
call :flash_partition_name _a || set /A error_level=1 && goto :exit
call :flash_userpartitions || set /A error_level=1 && goto :exit
call :flash_partition_name _b || set /A error_level=1 && goto :exit
call :flash_userpartitions || set /A error_level=1 && goto :exit
)
if not [%slot%] == [] if %support_dualslot% == 1 (
call :flash_partition_name %slot% || set /A error_level=1 && goto :exit
call :flash_userpartitions || set /A error_level=1 && goto :exit
%fastboot_tool% set_active %slot:~-1%
)
if %support_dualslot% == 0 (
call :flash_partition_name %slot% || set /A error_level=1 && goto :exit
call :flash_userpartitions || set /A error_level=1 && goto :exit
)
del fastboot_var.log
goto :eof
:exit
exit /B %error_level%