makeimg.bat 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. @rem 参数0: exe
  2. @rem 参数1: 输入bin文件 ,原始文件或者压缩档文件
  3. @rem 参数2: 输出文件(目标生成文件)
  4. @rem 参数3: 输入文件类型,0是旧参数布局的image文件,3是新参数布局的image文件
  5. @rem 参数4: 是否压缩文件:0:plain文件,1:压缩类型文件
  6. @rem 参数5: 版本号文件
  7. @rem 参数6:升级文件再FLASH里的存放位置(相对位置)
  8. @rem 参数7:升级后的文件启动位置(相对位置)
  9. @rem 参数8:原始bin文件
  10. @echo off
  11. @rem if debug_info=1, Debugging Print Information will be turned on
  12. set debug_info=0
  13. @rem if make_fal=1, Partition tables are put into firmware
  14. set make_fal=0
  15. @rem Setting firmware output directory
  16. set out_path=.\Bin
  17. @rem Setting the bin file path
  18. set bin_file=.\rtthread.bin
  19. @rem Setting winnermicro libraries path
  20. set wmlib_path=.\packages\wm_libraries-
  21. @rem Setting the 1M flash layout file
  22. set layout_1M_file=.
  23. @rem Setting the 2M flash layout file
  24. set layout_2M_file=.
  25. @rem Setting the makeimg by adding rtt flash original fls
  26. set makeimg_new_fls=.
  27. @rem find winnermicro libraries full path
  28. for /f "delims=" %%i in ('dir /ad /b /s %wmlib_path%*') do (set wmlib_path_full=%%i)
  29. @rem Setting the version.txt file path
  30. set version_file=%wmlib_path_full%\Tools\version.txt
  31. @rem Setting the secboot.img file path
  32. set secboot_file=%wmlib_path_full%\Tools\secboot.img
  33. @rem Setting the wm_gzip.exe file path
  34. set wm_gzip_file=%wmlib_path_full%\Tools\wm_gzip.exe
  35. @rem Setting the makeimg.exe file path
  36. set makeimg_file=%wmlib_path_full%\Tools\makeimg.exe
  37. @rem Setting the makeimg_all.exe file path
  38. set makeimg_all_file=%wmlib_path_full%\Tools\makeimg_all.exe
  39. @rem Prepare to generate firmware
  40. @rem Get the full path
  41. if "%out_path:~0,1%" == "." (set out_path=%~dp0%out_path%)
  42. if "%bin_file:~0,1%" == "." (set bin_file=%~dp0%bin_file%)
  43. @rem Create output folder
  44. if not exist "%out_path%" (md "%out_path%")
  45. @rem Copy the required files
  46. if exist "%bin_file%" (copy "%bin_file%" "%out_path%") else (echo makeimg err! No bin file found: %bin_file% & goto end)
  47. if exist "%version_file%" (copy "%version_file%" "%out_path%") else (echo makeimg err! No version file found: %version_file% & goto end)
  48. if exist "%secboot_file%" (copy "%secboot_file%" "%out_path%") else (echo makeimg err! No secboot file found: %secboot_file% & goto end)
  49. @rem Check the existence of firmware generation tools
  50. if not exist "%wm_gzip_file%" (echo makeimg err! No wm_gzip file found: "%wm_gzip_file%" & goto end)
  51. if not exist "%makeimg_file%" (echo makeimg err! No makeimg file found: "%makeimg_file%" & goto end)
  52. if not exist "%makeimg_all_file%" (echo makeimg err! No makeimg_all file found: "%makeimg_all_file%" & goto end)
  53. @rem Get File Names and File Extensions
  54. for /f "delims=" %%A in ('dir /b %bin_file%') do set "bin_file_name=%%A"
  55. for /f "delims=." %%A in ('dir /b %bin_file%') do set bin_name=%%A
  56. for /f "delims=%bin_name%" %%A in ('dir /b %bin_file%') do set bin_extend=%%A
  57. for /f "delims=" %%A in ('dir /b %version_file%') do set "version_file_name=%%A"
  58. for /f "delims=" %%A in ('dir /b %secboot_file%') do set "secboot_file_name=%%A"
  59. @rem Print Debug Information
  60. if not "%debug_info%"=="0" (echo bin_file_name:%bin_file_name% & echo bin_name:%bin_name% & echo bin_extend:%bin_extend% & echo version_file_name:%version_file_name% & echo secboot_file_name:%secboot_file_name%)
  61. echo makeimg 1M Flash...
  62. @rem Start making 1M flash firmware
  63. set file_pos_1M=_1M
  64. @rem Create command parameters
  65. set wm_gzip_cmd="%out_path%\%bin_file_name%"
  66. set makeimg_img_cmd="%out_path%\%bin_file_name%" "%out_path%\%bin_name%%file_pos_1M%.img" 0 0 "%out_path%\%version_file_name%" 90000 10100
  67. set makeimg_gz_img_cmd="%out_path%\%bin_file_name%.gz" "%out_path%\%bin_name%_GZ%file_pos_1M%.img" 0 1 "%out_path%\%version_file_name%" 90000 10100 "%out_path%\%bin_file_name%"
  68. set makeimg_sec_img_cmd="%out_path%\%bin_file_name%" "%out_path%\%bin_name%_SEC%file_pos_1M%.img" 0 0 "%out_path%\%version_file_name%" 90000 10100
  69. set makeimg_all_cmd="%out_path%\%secboot_file_name%" "%out_path%\%bin_name%%file_pos_1M%.img" "%out_path%\%bin_name%%file_pos_1M%.FLS"
  70. @rem Print command Information
  71. if not "%debug_info%"=="0" (echo wm_gzip %wm_gzip_cmd%)
  72. if not "%debug_info%"=="0" (echo makeimg %makeimg_img_cmd%)
  73. if not "%debug_info%"=="0" (echo makeimg %makeimg_gz_img_cmd%)
  74. if not "%debug_info%"=="0" (echo makeimg %makeimg_sec_img_cmd%)
  75. if not "%debug_info%"=="0" (echo makeimg_all %makeimg_all_cmd%)
  76. @rem Execute firmware generation commands
  77. "%wm_gzip_file%" %wm_gzip_cmd%
  78. "%makeimg_file%" %makeimg_img_cmd%
  79. "%makeimg_file%" %makeimg_gz_img_cmd%
  80. "%makeimg_file%" %makeimg_sec_img_cmd%
  81. "%makeimg_all_file%" %makeimg_all_cmd%
  82. @rem Delete temporary files
  83. if exist "%out_path%\%bin_name%%file_pos_1M%.img" (del "%out_path%\%bin_name%%file_pos_1M%.img")
  84. if exist "%out_path%\%bin_file_name%.gz" (del "%out_path%\%bin_file_name%.gz")
  85. @rem Start making 2M flash firmware
  86. echo makeimg 2M Flash...
  87. set file_pos_2M=_2M
  88. @rem Create command parameters
  89. set wm_gzip_cmd="%out_path%\%bin_file_name%"
  90. set makeimg_img_cmd="%out_path%\%bin_file_name%" "%out_path%\%bin_name%%file_pos_2M%.img" 3 0 "%out_path%\%version_file_name%" 100000 10100
  91. set makeimg_gz_img_cmd="%out_path%\%bin_file_name%.gz" "%out_path%\%bin_name%_GZ%file_pos_2M%.img" 3 1 "%out_path%\%version_file_name%" 100000 10100 "%out_path%\%bin_file_name%"
  92. set makeimg_sec_img_cmd="%out_path%\%bin_file_name%" "%out_path%\%bin_name%_SEC%file_pos_2M%.img" 3 0 "%out_path%\%version_file_name%" 100000 10100
  93. set makeimg_all_cmd="%out_path%\%secboot_file_name%" "%out_path%\%bin_name%%file_pos_2M%.img" "%out_path%\%bin_name%%file_pos_2M%.FLS"
  94. @rem Print command Information
  95. if not "%debug_info%"=="0" (echo wm_gzip %wm_gzip_cmd%)
  96. if not "%debug_info%"=="0" (echo makeimg %makeimg_img_cmd%)
  97. if not "%debug_info%"=="0" (echo makeimg %makeimg_gz_img_cmd%)
  98. if not "%debug_info%"=="0" (echo makeimg %makeimg_sec_img_cmd%)
  99. if not "%debug_info%"=="0" (echo makeimg_all %makeimg_all_cmd%)
  100. @rem Execute firmware generation commands
  101. "%wm_gzip_file%" %wm_gzip_cmd%
  102. "%makeimg_file%" %makeimg_img_cmd%
  103. "%makeimg_file%" %makeimg_gz_img_cmd%
  104. "%makeimg_file%" %makeimg_sec_img_cmd%
  105. "%makeimg_all_file%" %makeimg_all_cmd%
  106. @rem Delete temporary files
  107. if exist "%out_path%\%bin_name%%file_pos_2M%.img" (del "%out_path%\%bin_name%%file_pos_2M%.img")
  108. if exist "%out_path%\%bin_file_name%.gz" (del "%out_path%\%bin_file_name%.gz")
  109. @rem Partition tables are put into firmware
  110. if not "%make_fal%"=="1" ( goto end)
  111. @rem Get the full path
  112. if "%layout_1M_file:~0,1%" == "." (set layout_1M_file=%~dp0%layout_1M_file%)
  113. if "%layout_2M_file:~0,1%" == "." (set layout_2M_file=%~dp0%layout_2M_file%)
  114. if "%makeimg_new_fls:~0,1%" == "." (set makeimg_new_fls=%~dp0%makeimg_new_fls%)
  115. @rem Check whether the file exists
  116. if not exist "%layout_1M_file%" (echo makeimg err! No makeimg file found: "%layout_1M_file%" & goto end)
  117. if not exist "%layout_2M_file%" (echo makeimg err! No makeimg file found: "%layout_2M_file%" & goto end)
  118. if not exist "%makeimg_new_fls%" (echo makeimg err! No makeimg file found: "%makeimg_new_fls%" & goto end)
  119. @rem Create command parameters to new fls
  120. set makeimg_new_cmd_1M="%out_path%\%bin_name%%file_pos_1M%.FLS" "%layout_1M_file%" "%out_path%\%bin_name%_layout%file_pos_1M%.FLS"
  121. @rem Execute generation fls cmd
  122. "%makeimg_new_fls%" %makeimg_new_cmd_1M%
  123. @rem Create command parameters to new fls
  124. set makeimg_new_cmd_2M="%out_path%\%bin_name%%file_pos_2M%.FLS" "%layout_2M_file%" "%out_path%\%bin_name%_layout%file_pos_2M%.FLS"
  125. @rem Execute generation fls cmd
  126. "%makeimg_new_fls%" %makeimg_new_cmd_2M%
  127. @rem Delete temporary files
  128. if exist "%out_path%\%bin_name%_1M.FLS" (del "%out_path%\%bin_name%%file_pos_1M%.FLS")
  129. if exist "%out_path%\%bin_name%_2M.FLS" (del "%out_path%\%bin_name%%file_pos_2M%.FLS")
  130. :end
  131. echo end