欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  科技

Dos烧录脚本

程序员文章站 2022-07-02 17:13:11
dos烧录镜像脚本,以防备忘; ......

Dos命令之前更改的太简单,现在加入判断是否进入fasboot模式和判断Android镜像是否存在;代码已经尽量简化成这样,dos命令功能还是比较不好用的,用了一下午的时间。。。

  1 @echo off
  2 
  3 
  4 
  5 
  6 
  7 @set flashpath=Z:\msm8909\out\target\product\msm8909\
  8 @set Dynamic_library_Path=Z:\msm8909\out\target\product\msm8909\obj\lib\sensors.msm8909.so
  9 @set boot_image=%flashpath%boot.img
 10 @set mbn_image=%flashpath%emmc_appsboot.mbn
 11 @set system_image=%flashpath%system.img
 12 @set persist_image=%flashpath%persist.img
 13 @set ramdisk_image=%flashpath%ramdisk.img
 14 @set recover_image=%flashpath%recovery.img
 15 @set cache_image=%flashpath%cache.img
 16 @set Dynamic_library=%Dynamic_library_Path%
 17 @set Dynamic_library_Board_Path=/system/lib/
 18 
 19 ::初始化,下面便是判断是否有文件
 20 @set Image_Index=0
 21 @set Image_Current-path=0
 22 @set Image_Length=8
 23 
 24 @set Image[0]-path=%boot_image%
 25 @set Image[1]-path=%mbn_image%
 26 @set Image[2]-path=%system_image%
 27 @set Image[3]-path=%persist_image%
 28 @set Image[4]-path=%ramdisk_image%
 29 @set Image[5]-path=%recover_image%
 30 @set Image[6]-path=%cache_image%
 31 @set Image[7]-path=%Dynamic_library%
 32 ::初始化
 33 
 34 :LoopStart
 35 
 36 ::清空字符串
 37 @set Image_Current-path=0
 38 
 39 if %Image_Index% equ %Image_Length% goto BeginRun
 40 
 41 for /f "usebackq tokens=1,2,3 delims==-" %%a in (`set Image[%Image_Index%]`) do (
 42     set Image_Current-%%b=%%c
 43 )
 44 
 45 if exist %Image_Current-path% (
 46     @echo 该路径%Image_Current-path%存在......
 47     @echo.
 48 ) else (
 49     @echo %Image_Current-path%
 50     @echo 请确定该文件文件是否存在?如果不存在,请确定路径,打开脚本重新设置。10秒后关闭....
 51     @ping -n 10 127.0.0.1>nul
 52     exit
 53 )
 54 
 55 @set /a Image_Index=%Image_Index%+1
 56 
 57 goto LoopStart
 58 
 59 :BeginRun
 60 @echo 检查Android镜像文件已经完成,请继续下一步......
 61 @echo.
 62 
 63 @echo 1、烧录boot.img
 64 @echo 2、烧录aboot.img
 65 @echo 3、烧录persist.img
 66 @echo 4、烧录ramdisk.img
 67 @echo 5、烧录recovery.img
 68 @echo 6、烧录system.img
 69 @echo 7、烧录cache.img
 70 @echo 8、烧录所有镜像
 71 @echo 9、重新推进sensor.so
 72 
 73 @set /p option=请先设置路径后,再输入要烧录的选项:
 74 
 75 
 76 if "%option%" == "9" (
 77 adb root
 78 adb wait-for-device
 79 adb remount
 80 @echo 重新推进sensor........
 81 adb push %Dynamic_library% %Dynamic_library_Board_Path%
 82 adb reboot
 83 @echo 正在重启...... 5秒后关闭....
 84 @ping -n 5 127.0.0.1>nul
 85 
 86 exit
 87 )
 88 
 89 
 90 ::判断是否进入fastboot模式
 91 fastboot devices>1.txt
 92 set /p message=<1.txt
 93 del 1.txt
 94 if not defined message (
 95     echo 正处于adb mode模式.....
 96     adb wait-for-device
 97     adb reboot-bootloader
 98 ) else ( 
 99     echo 正处于fastboot mode模式.....
100 )
101 
102 
103 @echo.
104 
105 if "%option%" == "1" (
106 @echo 烧录boot.img........
107 fastboot flash boot %boot_image%
108 )
109 
110 if "%option%" == "2" (
111 @echo 烧录aboot.img........
112 fastboot flash aboot %mbn_image%
113 )
114 
115 if "%option%" == "3" (
116 @echo 烧录persist.img..........
117 fastboot flash persist %persist_image%
118 )
119 
120 if "%option%" == "4" (
121 @echo 烧录ramdisk.img..........
122 fastboot flash ramdisk %ramdisk_image%
123 )
124 
125 if "%option%" == "5" (
126 @echo 烧录recovery.img...........
127 fastboot flash recovery %recover_image%
128 )
129 
130 if "%option%" == "6" (
131 @echo 烧录system.img........
132 fastboot flash system %system_image%
133 )
134 
135 if "%option%" == "7" (
136 @echo 烧录cache.img...........
137 fastboot flash cache %cache_image%
138 )
139 
140 if "%option%" == "8" (
141 @echo 烧录所有镜像.............
142 fastboot flash boot %boot_image%
143 fastboot flash aboot %mbn_image%
144 fastboot flash persist %persist_image%
145 fastboot flash ramdisk %ramdisk_image%
146 fastboot flash recovery %recover_image%
147 fastboot flash system %system_image%
148 fastboot flash cache %cache_image%
149 )
150 
151 
152 fastboot reboot
153 @echo 正在重启 请稍后......
154 adb wait-for-device
155 adb root
156 adb wait-for-device
157 
158 
159 @ping -n 5 127.0.0.1>nul
160 adb shell dmesg > kmesg.log
161 @echo kernel log已经导出.....
162 
163 
164 
165 @echo [烧录成功,暂停5秒自动关闭]
166 @ping -n 5 127.0.0.1>nul

 

 

 

其中用到的相应内容有dos命令for循环的使用:

参考博客:http://blog.csdn.net/wh_19910525/article/details/7912440

 

Bat数组使用的情况:http://www.jb51.net/article/67630.htm

 

我自己整理的For f中的tokens和delims怎么用?直接拉上百度知道,整理得到的。就不管链接了,贴上我的有道云笔记链接就行了:http://note.youdao.com/noteshare?id=728873fd0d9b1ea50a73aed3d476135e&sub=FD0225FD68AC400C8C909FE85C293202

 

bat脚本回车命令是echo.

 

批处理语句判断变量是否为空的方法:http://www.bathome.net/thread-4046-1-8.html

 

综上所述:脚本好恶心!