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