abup.bat 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. @echo off
  2. setlocal EnableDelayedExpansion
  3. set bin_patch=%1
  4. set zip_patch=%2
  5. set def_path=%3
  6. set build=%4
  7. set version=version
  8. set fota=IOT5.0_LUSUN11_R50426
  9. set algorithm=0
  10. set base=0
  11. set bl=0
  12. set app=0
  13. set user=0
  14. set addr=0
  15. set block=0
  16. set wosun=0
  17. set addr1=0
  18. set size=0
  19. set lusun_ver=0
  20. set wosun_ver=0
  21. set app_ver=0
  22. set abup=abup.bin
  23. set rtthread=rtthread.bin
  24. set fromelf=fromelf.exe
  25. if "%def_path%" == "rtconfig.h" (
  26. copy %rtthread% %abup%
  27. ) else (
  28. if not "x!bin_patch:%fromelf%=!"=="x%bin_patch%" (
  29. %bin_patch% --bin -o %4\%abup% %4\%4.axf
  30. ) else (
  31. echo N
  32. )
  33. copy %4\%abup% %abup%
  34. )
  35. for /f "tokens=2 delims==" %%a in ('wmic path win32_operatingsystem get LocalDateTime /value') do (
  36. set datetime=%%a
  37. )
  38. set d=%datetime:~0,4%%datetime:~4,2%%datetime:~6,2%
  39. set h=%time:~0,2%
  40. set h=%h: =0%
  41. set t=%h%%time:~3,2%%time:~6,2%
  42. call:findstr1 ABUP_FIRMWARE_VERSION %def_path% version
  43. call:findstr1 ADUPS_FOTA_LUSUN_VERSION %def_path% lusun_ver
  44. call:findstr1 ADUPS_FOTA_WOSUN_VERSION %def_path% wosun_ver
  45. call:findstr2 ABUP_FOTA_ALGORITHM %def_path% algorithm
  46. call:findstr2 ABUP_FLASH_BASE_ADDR %def_path% base
  47. call:findstr2 ABUP_BL_SIZE %def_path% bl
  48. call:findstr2 ABUP_APP_SIZE %def_path% app
  49. call:findstr2 ABUP_USER_DATA_SIZE %def_path% user
  50. call:findstr2 ABUP_DEFAULT_SECTOR_SIZE %def_path% block
  51. call:findstr2 ABUP_UPDATE_SIZE %def_path% size
  52. call:findstr2 ABUP_WOSUN_STREAM_TYPE %def_path% wosun
  53. for %%s in ( %def_path%) do (
  54. findstr "ADUPS_FOTA_SERVICE" %%s >adups_info.txt
  55. set /p line=<adups_info.txt
  56. )
  57. if "%algorithm%"=="0" (
  58. echo #define ADUPS_FOTA_SDK_VER "%lusun_ver%" >> adups_info.txt
  59. ) else (
  60. echo #define ADUPS_FOTA_SDK_VER "%wosun_ver%" >> adups_info.txt
  61. )
  62. if "%5"=="RTT" (
  63. call:findstr1 ADUPS_FOTA_RTT_VERSION %def_path% app_ver
  64. echo RTT
  65. ) else (
  66. call:findstr1 ADUPS_FOTA_APP_VERSION %def_path% app_ver
  67. echo not RTT
  68. )
  69. echo %app_ver%
  70. echo #define ADUPS_FOTA_APP_VER "%app_ver%" >> adups_info.txt
  71. set /A addr=base+bl
  72. call:hexfun %addr% addr1
  73. set "addr1=00000000%addr1%"
  74. set "addr1=%addr1:~-8,8%"
  75. set /A size=size/1024
  76. set /A block=block/1024
  77. echo abup fota used size=%size%
  78. set /A size=size-2*block
  79. echo abup fota delta size=%size%
  80. if "%algorithm%"=="0" (echo lusun) else (
  81. if "%wosun%"=="0" (echo wosun bz) else (echo wosun lzma)
  82. echo #define ADUPS_FOTA_SDK_MAX_MCU_NUM "" >> adups_info.txt
  83. echo #define ADUPS_FOTA_FILENAME1 "%abup%-D" >> adups_info.txt
  84. echo #define ADUPS_FOTA_ADDRESS1 "0x%addr1%" >> adups_info.txt
  85. echo #define ADUPS_FOTA_REGION_LEN "%size%" >> adups_info.txt
  86. echo #define ADUPS_FOTA_BLOCK_LEN "%block%" >> adups_info.txt
  87. echo #define ADUPS_FOTA_PATCH_FORMAT "%wosun%" >> adups_info.txt
  88. echo #define ADUPS_BUILD_TIME "%d%_%t%" >> adups_info.txt
  89. )
  90. echo version=%version% >> adups_info.txt
  91. echo+%zip_patch%|findstr "7z.exe"
  92. if %errorlevel% equ 0 (
  93. %zip_patch% a -tzip %version%_%d%_%t%.zip adups_info.txt ./%abup%
  94. ) else (
  95. %zip_patch% a -ep1 -o+ -inul -iback %version%_%d%_%t%.zip adups_info.txt ./%abup%
  96. )
  97. del %abup% /s
  98. del adups_info.txt /s
  99. echo complete
  100. GOTO:EOF
  101. :findstr1
  102. for /f tokens^=^2^ delims^=^"^= %%i in ('findstr "%1" %2') do set "%3=%%i"
  103. GOTO:EOF
  104. :findstr2
  105. for /f "tokens=2,3" %%i in ('findstr "%1" %2') do if %%i==%1 set /A "%3=%%j"
  106. GOTO:EOF
  107. :hexfun
  108. set str=
  109. set code=0123456789ABCDEF
  110. set "var=%1"
  111. :again
  112. set /a tra=%var%%%16
  113. call,set tra=%%code:~%tra%,1%%
  114. set /a var/=16
  115. call:set_YU %var%
  116. set str=%tra%%str%
  117. if %var% geq 16 goto again
  118. set "%2=%ret%%str%"
  119. GOTO:EOF
  120. :set_YU
  121. set ret=
  122. if "%1" == "10" set ret=A
  123. if "%1" == "11" set ret=B
  124. if "%1" == "12" set ret=C
  125. if "%1" == "13" set ret=D
  126. if "%1" == "14" set ret=E
  127. if "%1" == "15" set ret=F
  128. if %1 lss 10 set ret=%1
  129. GOTO:EOF