找回密码
 立即注册
  • QQ空间
  • 回复
  • 收藏

powershell脚本文件问题

我这边有一份把2进制程序文件转换成16进制的并且按照要求拼接的脚本文件,不知道有没有大佬能看得懂,会写的,我需要把这个稍微修改下,但是修改以后不知道能不能正常运行,如果有老哥能看得懂,并且能修改,可以私我下,我想要学学咋修改:下面贴脚本文件代码:
@echo  off
set bck_mAIn_fimware_file=.\ota_gen\flash_boot.main.old.txt
set old_main_fimware_file=flash_boot.main.txt
del flash*.txt
del flash*.bin
if exist  laki_lib2.txt (
del  laki_lib2.txt
)
if exist  api_utility.txt (
del  api_utility.txt
)
if exist  user_app.txt (
del  user_app.txt
)
if exist laki_sldm_lib.txt (
del laki_sldm_lib.txt
)
if exist user_app.bin (
del user_app.bin
)
%自动搜索并获得主程序入口地址%
echo Capture the entrance addr of user_app!
findstr /C:"user_app " ..\..\Listings\laki_sdk.map > 1.txt
for /f "tokens=2" %%i in (1.txt ) do (
echo %%i > 2.txt
)
sed "1s/0x//" 2.txt > 3.txt
set /p mainEntryAddr=< 3.txt
echo Entrance addr of user_app is %mainEntryAddr%
echo=
SET FlashAddrPara=0
SET SourceFile1=first_page.txt
SET SourceFile2=ER$$.ARM.__at_0x500000
%自动搜索并获得主程序bin文件 -- sourcefile3 和 sourcefile4%
echo "Capture files number which named ER$$.ARM.__at_0x500* !"
dir /b ER$$.ARM.__at_0x500* | find /c /v "500000" > 4.txt
set /p file_num=<4.txt
echo Total Files which named ER$$.ARM.__at_0x500* are %file_num% !
echo=
if %file_num% GTR 2 (
goto ERR_PROCEDURE1
)
dir /b ER$$.ARM.__at_0x500* | find /v "500000" > 5.txt
(set /p SourceFile3=&set /p SourceFile4=)<5.txt
echo Capture the file name of api_utility and user_app!
echo API_UTILITY file name is %SourceFile3%
echo USER_APP file name is %SourceFile4%
echo=
del 1.txt 2.txt 3.txt 4.txt 5.txt
SET SourceFile5=ER$$.ARM.__at_0x400400
SET SLDM_OutFile=laki_sldm_lib.txt
SET SLDM_exist=0
echo "Scan whether all necessary files are exited!"
if not exist %SourceFile1% (
goto SF1
) else (
echo %SourceFile1% is exist!
)
if not exist %SourceFile2% (
goto SF2
) else (
echo %SourceFile2% is exist!
)
if not exist %SourceFile3% (
goto SF3
) else (
echo %SourceFile3% is exist!
)
if not exist %SourceFile4% (
goto SF4
) else (
echo %SourceFile4% is exist!
)
echo=
echo Merge HEX files: %SourceFile2% %SourceFile3% %SourceFile4% to user_app.bin
type %SourceFile2% %SourceFile3% %SourceFile4% > user_app.bin
echo=
echo "Scan whether files of SLDM lib is existed!"
if not exist %SourceFile5% (
echo  %SourceFile5% is not exist!
echo SLDM library is not used in current precedure! Ignored!
) else (
echo SLDM library is used in current precedure!
echo Generate TXT file of SLDM lib!
bin2txt.sldm_lib.2ndv.exe %SourceFile5% %SLDM_OutFile%
)
echo=
echo Generate TXT of main!
bin2txt.exe  %mainEntryAddr% 0
del ER*
%合并主函数文件和sldm库文件%
SET txt_inputFile=flash_boot.txt
SET bin_outputFile=flash_boot.bin
echo=
if exist %SLDM_OutFile% (
echo SLDM library is used, merge main precedure and sldm library together!
ren flash_boot.txt flash_boot.main.txt
copy flash_boot.main.txt+%SLDM_OutFile% flash_boot.txt
sed -i "1s/00/01/1" flash_boot.txt
) else (
echo SLDM library is not used in current precedure!
copy flash_boot.txt flash_boot.main.txt
)
echo=
if not exist flash_boot.main.txt (
echo ERR: flash_boot.main.txt is not exist!
) else (
echo Generate bin file of flash_boot.main.txt!
txt2bin.exe flash_boot.main.txt flash_boot.main.bin
)
if not exist flash_boot.txt (
goto SF5
) else (
echo Generate bin file of flash_boot.txt!
txt2bin.exe %txt_inputFile% %bin_outputFile%
echo Both TXT and BIN format of fimware are generated!
echo=
echo Notes of results:
echo Files - flash_boot.txt/flash_boot.bin include main precedure and sldm library!  flash_boot.txt=flash_boot.bin!
echo Files - flash_boot.main.txt/flash_boot.main.bin has main precedure only! flash_boot.main.txt=flash_boot.main.bin!
goto end
)
:SF5
echo %txt_inputFile% is not exist!
goto end
:SF1
echo %SourceFile1% is not exist!
goto end
:SF2
echo %SourceFile2% is not exist!
goto end
:SF3
echo %SourceFile3% is not exist!
goto end
:SF4
echo %SourceFile4% is not exist!
goto end
:ERR_PROCEDURE1
del ER* 1.txt 2.txt 3.txt 4.txt
echo "Total files which named ER$$.ARM.__at_0x500* are larger than 2. Del ER* first first!"
echo Please re-run build and generate fimware again!
echo
goto end
:end
del user_app.bin
pause
exit
回复

使用道具 举报

说点什么

您需要登录后才可以回帖 登录 | 立即注册
HOT • 推荐