bootload 兩個bin文件合並腳本


1新建一個“合並bin文件.bat”的文件,復制以下代碼 這個文件不需要修改。

::@echo off

::執行批處理文件名 "post"
set run_name=post
set run_name_type=%run_name%.bat
::輸出log文件名
set file_name=%run_name%_log
set file_name_type=%file_name%.txt
::日期時間
set Date=%date%
set Time=%time%
::windows使用
echo. >> %file_name_type%
echo. >> %file_name_type%
echo start-------------------------------------------------------------- >> %file_name_type%
::linux使用
::printf "\n\n" >> %file_name_type%
::printf "start--------------------------------------------------------------\n" >> %file_name_type%
 
echo %Date% >> %file_name_type%
echo %Time% >> %file_name_type%

echo %run_name_type%-^>%file_name_type% >> %file_name_type%
::linux使用
::printf "\n" >> %file_name_type%
::windows使用
echo. >> %file_name_type%
%run_name_type% >> %file_name_type%


::pause

2、新建一個“post.bat”文本,復制以下內容,其中文件名 版本號偏移地址根據自己需求修改。以下如需使用cat命令需自行下載cat.exe放到腳本同文件夾下,若提示hbin不是內部指令獲命令自行下載HBIN.exe放到腳本文件夾下,或放到系統文件夾system32里。

@echo off
::以下根據自己需求更改
::boot bin 文件名
set boot=boot.bin
::APP bin文件名
set app=APP.bin
::app偏移地址
set /a app_offset=0xc800
::軟件版本
set boot_ver=Boot_V842
set app_ver=App_V836
::合成的文件名
set creat_app=ALL_%boot_ver%_%app_ver%.bin 


::以下部分不需要改
del %creat_app%
fsutil  file createnew %creat_app%  %app_offset%
hbin %boot%   %creat_app%
::linux使用
cat  %app% >> %creat_app%

::windows使用
::type  %app% >> %creat_app%

:: boot尺寸
setlocal enabledelayedexpansion
for /f "delims=" %%i in ('dir /a-d /b %boot%') do (    
set /a boot_size=%%~zi 
)

::APP尺寸
for /f "delims=" %%i in ('dir /a-d /b %app%') do (    
set /a app_size=%%~zi 
)

::合成尺寸
for /f "delims=" %%i in ('dir /a-d /b %creat_app%') do (    
set /a creat_app_size=%%~zi 
)
::set /a creat_app_size=%app_offset%+%app_size%

::linux使用
::printf "\n"
::windows使用
echo.

set /a boot_sizek=%boot_size%/1024
set /a boot_sizey=%boot_size%%%(1024)
set /a boot_sizeu=boot_sizey*10000/1024
echo %boot% &echo size = %boot_size%字節  %boot_sizek%KB+%boot_sizey%字節  %boot_sizek%.%boot_sizeu%KB 
::linux使用
::printf "\n"
::windows使用
echo.

set /a app_offsetk=%app_offset%/1024
set /a app_offsety=%app_offset%%%(1024)
set /a app_offsetu=app_offsety*10000/1024
echo app_offset偏移  &echo size = %app_offset%字節  %app_offsetk%KB+%app_offsety%字節  %app_offsetk%.%app_offsetu%KB 
::linux使用
::printf "\n"
::windows使用
echo.

set /a app_sizek=%app_size%/1024
set /a app_sizey=%app_size%%%(1024)
set /a app_sizeu=app_sizey*10000/1024
echo %app%  &echo size = %app_size%字節  %app_sizek%KB+%app_sizey%字節  %app_sizek%.%app_sizeu%KB 
::linux使用
::printf "\n"
::windows使用
echo.

set /a creat_app_sizek=%creat_app_size%/1024
set /a creat_app_sizey=%creat_app_size%%%(1024)
set /a creat_app_sizeu=creat_app_sizey*10000/1024
echo %creat_app% &echo size = %creat_app_size%字節  %creat_app_sizek%KB+%creat_app_sizey%字節  %creat_app_sizek%.%creat_app_sizeu%KB 
echo end-------------------------------------------------------------- 

3、把要合並的bin文件和腳本放到同一文件夾下雙擊“合並bin文件.bat”。輸出log保存在“post_log.txt”如下。除了偏移大小是設定值其他大小值均是腳本讀取的文件大小不需要人為設定。

 
 
start-------------------------------------------------------------- 
2020/02/07 周五 
20:31:36.37 
post.bat->post_log.txt 
 
已創建文件 C:\Users\jixuansong\Desktop\bin文件合並\ALL_Boot_V842_App_V836.bin

boot.bin 
size = 32840字節  32KB+72字節  32.703KB 

app_offset偏移  
size = 51200字節  50KB+0字節  50.0KB 

APP.bin  
size = 111344字節  108KB+752字節  108.7343KB 

ALL_Boot_V842_App_V836.bin  
size = 162544字節  158KB+752字節  158.7343KB 
end-------------------------------------------------------------- 

以上合並的bin文件本人親自對比過結果與需要的一致。關鍵地址對比如下圖

 

 

 

 

 

 

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM