summaryrefstree
path: root/update_image.bat
blob: 36ab7707a2d9f0a31a50c153f2026c1d01c9e33c (plain)
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
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
::=================MAIN================================================
::=============MARCO_DEFINE===============================
@set FASTBOOT_BIN=fastboot
@set MARCO_PACKAGE_VARIANT_USERDEBUG=userdebug
@set MARCO_PACKAGE_VARIANT_USER=user
@set MARCO_PACKAGE_VARIANT_ENG=eng
@set EVB_NAME=EV
@set SR_NAME=SR
::=========Additional Override Define For Input Para Use========
@set MARCO_PACKAGE_VARIANT_FACTORY=fac
@set MARCO_PACKAGE_VARIANT_SHIPPING=shipping
@set SKIP_REBOOT=0
::==============GLOBLE DEFINE=========================================
@set PACKAGE_VARIANT=
@set PROJECT=
@set ERASE_DATA_CACHE=
@set DEVICE_SSN=
@set PACKAGE_TARGET_SKU=
@set UPDATE_SCRIPT_NAME=
@set STAGE_ID=
@set PROJECT_VERSION=
@set ABD_ENABLED=
::===========get command form parent caller========================
::usage update_image.bat [-w or data_erase] [no_ssn or -s ssn_num] [--shipping] [adb_enable]
::-w			     1--erase userdata and cache  0--do not erase
::shipping         shipping update image
::no_ssn	   update images for single device

:loop_args
@echo off
if "%1" NEQ "" (
  if "%1"=="--shipping" (
	 set PACKAGE_VARIANT=%MARCO_PACKAGE_VARIANT_SHIPPING%
   )
   if "%1"=="--fac" (
    set PACKAGE_VARIANT=%MARCO_PACKAGE_VARIANT_FACTORY%
   )
   if "%1"=="-w" (
     set ERASE_DATA_CACHE=1
   )
   if "%1"=="data_erase" (
     set ERASE_DATA_CACHE=1
   )
   if "%1"=="non_data_erase" (
     set ERASE_DATA_CACHE=0
   )
   if "%1"=="no_ssn" (
     set FB=%FASTBOOT_BIN%
   )
   if "%1"=="adb_enable" (
     set ABD_ENABLED=1
   )
   if "%1"=="adb_disable" (
     set ABD_ENABLED=0
   )
   if "%1"=="--skip" (
     set SKIP_REBOOT=1
   )
   if "%1"=="-s" (
     set DEVICE_SSN=%2
     SHIFT
   )
  SHIFT
  goto loop_args
) else (
 goto setfb
)
:setfb
@if "%DEVICE_SSN%" neq "" (
 @set FB=%FASTBOOT_BIN% -s %DEVICE_SSN%
) else (
 @set FB=%FASTBOOT_BIN%
)
@echo on
@echo check fastboot cmd
@%FB% getvar product
@if %ERRORLEVEL% neq 0 (
    @set FB=%FASTBOOT_BIN%
    @%FB% getvar product
    @if %ERRORLEVEL% neq 0 (
        @echo Usage update_image.bat [1 or 0] [no_ssn or -s ssn_num] [--shipping] [adb_enable]
        @goto Error
    )
)
@echo fastboot cmd : %FB%
@echo on
::============get package and system information====================
@if "%PACKAGE_VARIANT%" neq "" (goto skip_get_package_info)
@call :get_package_info PACKAGE_VARIANT TARGET_BUILD_VARIANT
:skip_get_package_info
@call :get_package_info PACKAGE_TARGET_SKU TARGET_SKU
@call :get_project_name PROJECT
@call :get_package_project_name PACKAGE_PROJECT
@call :get_stage_id STAGE_ID
@call :get_package_info PROJECT_VERSION PROJECT_BUILD_VERSION

::============echo the package and harware information===============
@echo fastboot:%FB%
@echo package version:%PACKAGE_VARIANT%
@echo project name:%PROJECT%
@echo package project name:%PACKAGE_PROJECT%
@echo package sku:%PACKAGE_TARGET_SKU%
@echo stage id:%STAGE_ID%
@echo project build version:%PROJECT_VERSION%

@if "%PACKAGE_VARIANT%"=="%MARCO_PACKAGE_VARIANT_SHIPPING%" (
    @echo Cautious, This is shipping flash route
)
@if "%PACKAGE_VARIANT%"=="%MARCO_PACKAGE_VARIANT_FACTORY%" (
    @echo Cautious, This is factory flash route
)

::===========check project  name and cpu type======================
@if  [%PROJECT%]==[] (
    @echo project name is not recognized
    @goto Error
)

@echo on
@echo %PROJECT%|findstr "%PACKAGE_PROJECT%"
@if %ERRORLEVEL% neq 0 (
    echo This image is for ZS620KL, make sure you use the right image!
    echo Finally, If there is still any problem,You Can contact BSP Project Team for help
	@goto Error
)

@echo on
@set PROJECT_VERSION="%PROJECT_VERSION%"
:SPLIT_VERSION
@for /f "delims=., tokens=1,*" %%i in (%PROJECT_VERSION%) do (
    @set CHECK_VERSION_NUM1=%CHECK_VERSION_NUM2%
    @set CHECK_VERSION_NUM2=%CHECK_VERSION_NUM3%
    @set CHECK_VERSION_NUM3=%CHECK_VERSION_NUM4%
    @set CHECK_VERSION_NUM4=%%i
    @set PROJECT_VERSION="%%j"
    @if "%%j" neq "" (
        @goto SPLIT_VERSION
    )
)

@echo off
@set STAGE_ID_HEAD=%STAGE_ID:~0,2%
@set /a RESULT_CMP=3
@if "%STAGE_ID_HEAD%" EQU "%EVB_NAME%" (
    @set /a RESULT_CMP=1
)
@if "%STAGE_ID_HEAD%" EQU "%SR_NAME%" (
    @set /a RESULT_CMP=2
)
::@if %RESULT_CMP% GEQ 3 (
::	@if %CHECK_VERSION_NUM1% LEQ 80 (
::        @if %CHECK_VERSION_NUM2% LEQ 1 (
::            @if %CHECK_VERSION_NUM3% LEQ 2 (
::                @if %CHECK_VERSION_NUM4% LEQ 86 (
::                    @echo Image is too old, please update.
::                    @echo You Can contact BSP Project Team for help
::                    @goto Error
::                )
::            )
::        )
::	)
::)
@echo on
::===========erase or flash image ==============================
@echo ===================================================
@echo "flash image now"
@echo ===================================================

:: ======================= flash: partition 0 ===============
::@echo Erase LUN 0
::@%FB% oem erase LUN 0
::@if %ERRORLEVEL% neq 0 (
::    goto Error
::)

::@echo Flash GPT 0
::@echo %PROJECT%
::@%FB% flash partition:0 gpt_both0.bin
::@if %ERRORLEVEL% neq 0 (
::    goto Error
::)

::   @echo flash persist
:: ======================= flash: persist in all mode  ============================
::   @%FB% erase persist > nul 2>&1
::   @%FB% flash persist persist.img
::   	@if %ERRORLEVEL% neq 0 (
::		goto Error
::    )

   @echo erase misc
:: ======================= erase: misc in all mode  ============================
    @%FB% erase misc > nul 2>&1
    @%FB% flash misc misc.img
   	@if %ERRORLEVEL% neq 0 (
		goto Error
    )

   @echo erase ssd
:: ======================= erase: ssd in all mode  ============================
   @%FB% erase ssd > nul 2>&1
   	@if %ERRORLEVEL% neq 0 (
		goto Error
    )

   @echo flash system
:: ======================= flash:system in all mode========================================
:: =============need erase before flashing======
    @%FB% erase system_a > nul 2>&1
    @%FB% flash system_a system.img
    @if %ERRORLEVEL% neq 0 (
		goto Error
    )
@if exist system_other.img (
    @%FB% erase system_b > nul 2>&1
    @%FB% flash system_b system_other.img
    @if %ERRORLEVEL% neq 0 (
		goto Error
    )
) else (
    @echo without system_other
)
   @echo flash xrom
:: ======================= flash:xrom in all mode========================================
:: =============need erase before flashing======
@if exist xrom.img (
    @%FB% erase xrom_a > nul 2>&1
    @%FB% flash xrom_a xrom.img
    @if %ERRORLEVEL% neq 0 (
		goto Error
    )
) else (
    @echo without xrom
)

:: ======================= flash: partition 1 ===============
::@if %RESULT_CMP% LSS 3 (
::    @echo Erase LUN 1
::    @%FB% oem erase LUN 1
::    @if %ERRORLEVEL% neq 0 (
::        goto Error
::    )

::    @echo Flash GPT 1
::    @echo %PROJECT%
::    @%FB% flash partition:1 gpt_both1.bin
::    @if %ERRORLEVEL% neq 0 (
::        goto Error
::    )
::)
   @echo flash xbl_a
:: ======================= flash: XBL & XBL_CONFIG in all mode  ============================
   @%FB% flash xbl_a firmware\xbl.elf
   	@if %ERRORLEVEL% neq 0 (
		goto Error
    )

   @%FB% flash xbl_config_a firmware\xbl_config.elf
    @if %ERRORLEVEL% neq 0 (
		goto Error
    )

:: ======================= flash: partition 2 ===============
::@if %RESULT_CMP% LSS 3 (
::    @echo Erase LUN 2
::    @%FB% oem erase LUN 2
::    @if %ERRORLEVEL% neq 0 (
::        goto Error
::    )

::    @echo Flash GPT 2
::    @echo %PROJECT%
::    @%FB% flash partition:2 gpt_both2.bin
::    @if %ERRORLEVEL% neq 0 (
::        goto Error
::    )
::)

   @echo flash xbl_b
:: ======================= flash: XBL & XBL_CONFIG in all mode  ============================
   @%FB% flash xbl_b firmware\xbl.elf
   	@if %ERRORLEVEL% neq 0 (
		goto Error
    )

   @%FB% flash xbl_config_b firmware\xbl_config.elf
    @if %ERRORLEVEL% neq 0 (
		goto Error
    )

:: ======================= flash: partition 3 ===============
@if %RESULT_CMP% LSS 3 (
    @echo Erase LUN 3
    @%FB% oem erase LUN 3
    @if %ERRORLEVEL% neq 0 (
        goto Error
    )

    @echo Flash GPT 3
    @echo %PROJECT%
    @%FB% flash partition:3 gpt_both3.bin
    @if %ERRORLEVEL% neq 0 (
        goto Error
    )
)

:: ======================= flash: partition 4 ===============
::@echo Erase LUN 4
::@%FB% oem erase LUN 4
::@if %ERRORLEVEL% neq 0 (
::    goto Error
::)

::@echo Flash GPT 4
::@echo %PROJECT%
::@%FB% flash partition:4 gpt_both4.bin
::@if %ERRORLEVEL% neq 0 (
::    goto Error
::)

::@echo %PROJECT%
::@%FB% flash partition:4 gpt_both4.bin
::@if %ERRORLEVEL% neq 0 (
::    goto Error
::)
   @echo flash aop
:: ======================= A/B partition ===============================
:: ======================= flash: aop in all mode ===============================
    @%FB% flash aop_a firmware\aop.mbn
   	@if %ERRORLEVEL% neq 0 (
		goto Error
    )

    @%FB% flash aop_b firmware\aop.mbn
   	@if %ERRORLEVEL% neq 0 (
		goto Error
    )

   @echo flash tz
:: ======================= flash: TZ in all mode ===============================
    @%FB% flash tz_a firmware\tz.mbn
   	@if %ERRORLEVEL% neq 0 (
		goto Error
    )

    @%FB% flash tz_b firmware\tz.mbn
   	@if %ERRORLEVEL% neq 0 (
		goto Error
    )

   @echo flash hyp
:: ======================= flash: hyp in all mode ===============================
    @%FB% flash hyp_a firmware\hyp.mbn
   	@if %ERRORLEVEL% neq 0 (
		goto Error
    )

    @%FB% flash hyp_b firmware\hyp.mbn
   	@if %ERRORLEVEL% neq 0 (
		goto Error
    )

   @echo flash modem
:: ======================= flash:Modem in all mode=====================================
:: =============Modem need erase partiting before flashing============
@if %RESULT_CMP% LSS 3 (
    @%FB% flash modem_a NON-HLOS.bin
)else (
    @%FB% flash modem_a firmware\NON-HLOS.bin
)
   	@if %ERRORLEVEL% neq 0 (
		goto Error
    )

@if %RESULT_CMP% LSS 3 (
    @%FB% flash modem_b NON-HLOS.bin
)else (
    @%FB% flash modem_b firmware\NON-HLOS.bin
)
   	@if %ERRORLEVEL% neq 0 (
		goto Error
    )

   @echo flash bluetooth
:: ======================= flash: btfm in all mode ===============================
    @%FB% flash bluetooth_a firmware\BTFM.bin
   	@if %ERRORLEVEL% neq 0 (
		goto Error
    )

    @%FB% flash bluetooth_b firmware\BTFM.bin
   	@if %ERRORLEVEL% neq 0 (
		goto Error
    )

   @echo flash abl
:: ======================= flash: abl in all mode=======================
    @%FB% flash abl_a abl.elf
   	@if %ERRORLEVEL% neq 0 (
		goto Error
    )

    @%FB% flash abl_b abl.elf
   	@if %ERRORLEVEL% neq 0 (
		goto Error
    )

   @echo flash dsp
:: ======================= flash: dsp in all mode ======================================
    @%FB% flash dsp_a firmware\dspso.bin
   	@if %ERRORLEVEL% neq 0 (
		goto Error
    )

    @%FB% flash dsp_b firmware\dspso.bin
   	@if %ERRORLEVEL% neq 0 (
		goto Error
    )

   @echo flash keymaster
:: ======================= flash: keymaster in all mode==================
    @%FB% flash keymaster_a firmware\keymaster64.mbn
   	@if %ERRORLEVEL% neq 0 (
		goto Error
    )

    @%FB% flash keymaster_b firmware\keymaster64.mbn
   	@if %ERRORLEVEL% neq 0 (
		goto Error
    )

    @echo flash kernel
:: ======================= flash:Kernel in all mode====================================
    @%FB% erase boot_a > nul 2>&1
    @%FB% flash boot_a boot.img
   	@if %ERRORLEVEL% neq 0 (
		goto Error
    )

    @echo flash cmnlib
:: ======================= flash: cmnlib in all mode========================
    @%FB% flash cmnlib_a firmware\cmnlib.mbn
   	@if %ERRORLEVEL% neq 0 (
		goto Error
    )

    @%FB% flash cmnlib_b firmware\cmnlib.mbn
   	@if %ERRORLEVEL% neq 0 (
		goto Error
    )

    @echo flash cmnlib_64
:: ======================= flash: cmnlib64 in all mode====================
    @%FB% flash cmnlib64_a firmware\cmnlib64.mbn
   	@if %ERRORLEVEL% neq 0 (
		goto Error
    )

    @%FB% flash cmnlib64_b firmware\cmnlib64.mbn
   	@if %ERRORLEVEL% neq 0 (
		goto Error
    )

    @echo flash devcfg
:: ======================= flash: devcfg in all mode=======================
    @%FB% flash devcfg_a firmware\devcfg.mbn
   	@if %ERRORLEVEL% neq 0 (
		goto Error
    )

    @%FB% flash devcfg_b firmware\devcfg.mbn
   	@if %ERRORLEVEL% neq 0 (
		goto Error
    )

   @echo flash qupfw
:: ======================= flash: qupfw in all mode=======================
    @%FB% flash qupfw_a firmware\qupv3fw.elf
   	@if %ERRORLEVEL% neq 0 (
		goto Error
    )

    @%FB% flash qupfw_b firmware\qupv3fw.elf
   	@if %ERRORLEVEL% neq 0 (
		goto Error
    )

    @echo flash vendor
:: ======================= flash:vendor in all mode====================================
    @%FB% erase vendor_a > nul 2>&1
    @%FB% flash vendor_a vendor.img
   	@if %ERRORLEVEL% neq 0 (
		goto Error
    )

    @echo flash vbmeta
:: ======================= flash:vbmeta in all mode====================================
    @%FB% erase vbmeta_a > nul 2>&1
    @%FB% flash vbmeta_a vbmeta.img
    @if %ERRORLEVEL% neq 0 (
		goto Error
    )

    @%FB% erase vbmeta_b > nul 2>&1
    @%FB% flash vbmeta_b vbmeta.img
    @if %ERRORLEVEL% neq 0 (
		goto Error
    )

    @echo flash dtbo
:: ======================= flash:dtbo in all mode====================================
    @%FB% erase dtbo_a > nul 2>&1
    @%FB% flash dtbo_a dtbo.img
    @if %ERRORLEVEL% neq 0 (
		goto Error
    )

    @echo flash storsec
:: ======================= flash: storsec in all mode=======================
    @%FB% flash storsec_a firmware\storsec.mbn
   	@if %ERRORLEVEL% neq 0 (
		goto Error
    )

    @%FB% flash storsec_b firmware\storsec.mbn
   	@if %ERRORLEVEL% neq 0 (
		goto Error
    )
:: ======================= flash: ImageFv in all mode==================
    @%FB% flash ImageFv_a firmware\imagefv.elf
    @if %ERRORLEVEL% neq 0 (
    goto Error
    )
    @%FB% flash ImageFv_b firmware\imagefv.elf
    @if %ERRORLEVEL% neq 0 (
    goto Error
    )
:: ======================= non A/B partition ===============================
    @echo flash apdp
:: ======================= flash:apdp in userdebug, otherwise erase ====================
    @if  "%PACKAGE_VARIANT%"=="%MARCO_PACKAGE_VARIANT_USER%" (
      @%FB% erase apdp
	  @if %ERRORLEVEL% neq 0 (
		goto Error
	  )
    ) else (
      @%FB% erase apdp > nul 2>&1
      @%FB% flash apdp apdp.mbn
	  @if %ERRORLEVEL% neq 0 (
		goto Error
      )
    )

    @echo flash msadp
:: ======================= flash:msadp in userdebug,otherwise erase =====================
    @if  "%PACKAGE_VARIANT%"=="%MARCO_PACKAGE_VARIANT_USER%" (
      @%FB% erase msadp
	  @if %ERRORLEVEL% neq 0 (
		goto Error
      )
    ) else (
      @%FB% erase msadp > nul 2>&1
      @%FB% flash msadp msadp.mbn
	  @if %ERRORLEVEL% neq 0 (
		goto Error
      )
    )
goto skip1
    @echo flash splash
:: ======================= flash: splash in all mode==================
    @%FB% erase splash > nul 2>&1
    @%FB% flash splash splash.bin
   	@if %ERRORLEVEL% neq 0 (
		goto Error
    )
:skip1
:: ======================= flash: logfs in all mode==================
    @%FB% flash logfs firmware\logfs_ufs_8mb.bin
   	@if %ERRORLEVEL% neq 0 (
		goto Error
    )

:: ======================= flash: partition 5 ===============
@if %RESULT_CMP% LSS 3 (
    @echo Erase LUN 5
    @%FB% oem erase LUN 5
    @if %ERRORLEVEL% neq 0 (
        goto Error
    )

    @echo Flash GPT 5
    @echo %PROJECT%
    @%FB% flash partition:5 gpt_both5.bin
    @if %ERRORLEVEL% neq 0 (
        goto Error
    )
)

:: =======================erase: userdata & cache with -w option===========================
:: =======================If not set, default with erase action ===========================
@if "%ERASE_DATA_CACHE%" =="1" (
    @echo "%FB% -w"
    @%FB% -w
)


::=======================enable adb================================================
@if "%ABD_ENABLED%"=="1" (
  @echo "adb enable"
  @%FB% oem adb_enable
  @if %ERRORLEVEL% neq 0 (
    @echo enable adb error.....
    @goto Error
  )
)
:: ============== special case for factory's full reset =====================================
:: ========== Be Carefull, The Factory.bat will do some erase function .=====================
:: ========== So when moving the line of @call factory.bat %FB% =============================
:: ========== please make sure the factory.bat's erase function take effect first============
:: ========== or the flashing process may be useless ========================================

    @if  "%PACKAGE_VARIANT%"=="%MARCO_PACKAGE_VARIANT_FACTORY%" (
      @call factory.bat %FB%
	  @if %ERRORLEVEL% neq 0 (
    	goto Error
      )
    )

::=====================print success message========================================
@if %RESULT_CMP% LSS 3 (
    @%FB% format:ext4 factory
    @if %ERRORLEVEL% neq 0 (
        @echo fail
        @goto Error
    )
)

::=====================reset active========================================
@echo "set active slot a"
@echo off
@%FB% set_active a
@if %ERRORLEVEL% neq 0 (
	@echo fail
	@goto Error
)

@echo ====================
@echo "Download Complete !"
@echo ====================

::========================end MAIN============================================
@goto :End_MAIN

::=======================functions============================
:: get package information for file buid_info
:: %~1 output, the value return
:: %~2 input, the keyword string to mach
:get_package_info
@echo off
set keyword=%~2
for /f "eol=# delims== tokens=1,2" %%i  in (build_info) do (
    if "%%i"=="%keyword%"   (
    set keyval=%%j
    goto break_in_get_package_info
    )
)
:break_in_get_package_info
set keyval=%keyval: =%
set %~1=%keyval%
@echo on
@goto :eof

::====== function: get_project_name==========
::%~1 output, the value of project
:get_project_name
@echo off
set keyval=
set project_name=
for /f "tokens=1,2" %%i  in ('%FB% getvar product 2^>^&1 ^| findstr product') do (
	set keyval=%%j
	goto break_in_get_project_name
)
:break_in_get_project_name
set keyval=%keyval: =%
set %~1=%keyval%
@echo on
@goto :eof

:get_stage_id
@echo off
set keyval=
for /f "tokens=1,2" %%i  in ('%FB% getvar stage-id 2^>^&1 ^| findstr stage-id') do (
	set keyval=%%j
	goto break_in_stage_id
)
:break_in_stage_id
set keyval=%keyval: =%
set %~1=%keyval%
@echo on
@goto :eof

:get_package_project_name
@echo off
set keyword=TARGET_PRODUCT
set keyval=
set project_name=
for /f "eol=# delims== tokens=1,2" %%i  in (build_info) do (
	if "%%i"=="%keyword%" (
		set keyval=%%j
		goto break_in_get_package_project_name
    )
)
:break_in_get_package_project_name
set keyval=%keyval: =%
if "%keyval%"=="ZS620KL" (
	set project_name=ZS620KL
)
set %~1=%project_name%
@echo on
@goto :eof


::======= succ exit==============================
:End_MAIN
@if %SKIP_REBOOT% neq 0 (
  @goto SKIP_SUCCESS_SHPPING
)
@echo pass
@if "%PACKAGE_VARIANT%"=="%MARCO_PACKAGE_VARIANT_SHIPPING%" goto SKIP_SUCCESS_SHPPING
@echo press any key to continue, system will reboot!
@pause
:SKIP_SUCCESS_PAUSE
@%FB% reboot
:SKIP_SUCCESS_SHPPING
@exit /b 0

::======= Fail in subbat==============================
:FAIL_IN_SUBBAT
@exit /b 1

::======= error exit==============================
:Error
@echo ...
@echo Update image failed
@echo If there is any problem after running err_handle,You Can contact BSP Project Team for help
@echo ====================
@echo Download failed
@echo ====================
@if "%PACKAGE_VARIANT%"=="%MARCO_PACKAGE_VARIANT_SHIPPING%" goto SKIP_FAIL_PAUSE
@pause
:SKIP_FAIL_PAUSE
@exit /b 1