makeimg.bat 7.2 KB

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