-
Notifications
You must be signed in to change notification settings - Fork 3
/
repack_MTK_img.bat
191 lines (191 loc) · 6.66 KB
/
repack_MTK_img.bat
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::: :::
::: Carliv Image Kitchen for Android :::
::: boot+recovery images copyright-2015 carliv@xda :::
::: including support for MTK powered phones images :::
::: :::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
@echo off
cd %~dp0
IF EXIST "%~dp0\bin" SET PATH=%PATH%;"%~dp0\bin"
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
setlocal enabledelayedexpansion
set "red=\033[91m"
set "cyan=\033[96m"
set "yellow=\033[93m"
set "deft=\033[0m"
echo(
echo **********************************************************
echo * *
echo * %cyan%Carliv Image Kitchen for Android %deft%v0.1 * | klr
echo * boot+recovery images copyright-2015 %cyan%carliv@xda%deft% * | klr
echo * including support for MTK powered phones images *
echo * WINDOWS version *
echo * The repacking MTK images script *
echo * *
echo **********************************************************
echo(
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
if "%~nx1" == "" goto noinput
echo You have selected the%yellow% %~nx1 %deft%folder. | klr
echo(
echo Processing the%yellow% %~nx1 folder%deft%. | klr
echo(
set "folder=%~nx1"
icacls %folder% /grant Everyone:(IO)(CI)
cd %folder%
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
echo(
echo Repacking the image....
echo(
for /f "delims=" %%a in ('dir /b *-kernel') do @set nfile=!nfile!%%~na
set "file=%nfile%"
if not exist "%file%.img-kernel" goto error
set kernel=!kernel!%file%.img-kernel
echo The kernel is:%yellow% %kernel%%deft% | klr
echo(
echo Getting the ramdisk compression....
echo(
if not exist "ramdisk" goto error
for /f "delims=" %%a in (%file%.img-ramdisk-compress) do @set compress=!compress!%%a
echo Ramdisk compression:%yellow% %compress%%deft% | klr
goto %compress%
echo(
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:gz
echo(
mkbootfs ramdisk | gzip > %file%.img-ramdisk.gz
set ramdisk=!ramdisk!%file%.img-ramdisk.gz
echo The ramdisk is:%yellow% %ramdisk%%deft% | klr
goto repack
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:lzma
echo(
mkbootfs ramdisk | xz -Flzma > %file%.img-ramdisk.lzma
set ramdisk=!ramdisk!%file%.img-ramdisk.lzma
echo The ramdisk is:%yellow% %ramdisk%%deft% | klr
goto repack
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:xz
echo(
mkbootfs ramdisk | xz -1 -Ccrc32 > %file%.img-ramdisk.xz
set ramdisk=!ramdisk!%file%.img-ramdisk.xz
echo The ramdisk is:%yellow% %ramdisk%%deft% | klr
goto repack
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:bz2
echo(
mkbootfs ramdisk | bzip2 > %file%.img-ramdisk.bz2
set ramdisk=!ramdisk!%file%.img-ramdisk.bz2
echo The ramdisk is:%yellow% %ramdisk%%deft% | klr
goto repack
echo(
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:repack
echo(
echo Getting the image repacking arguments....
echo(
if not exist "%file%.img-board" goto noboard
for /f "delims=" %%a in (%file%.img-board) do @set nameb=!nameb!%%a
echo Board:%yellow% '%nameb%'%deft% | klr
echo(
:noboard
if not exist "%file%.img-base" goto nobase
for /f "delims=" %%a in (%file%.img-base) do @set base=!base!%%a
echo Base:%yellow% %base%%deft% | klr
echo(
:nobase
for /f "delims=" %%a in (%file%.img-pagesize) do @set pagesize=!pagesize!%%a
echo Pagesize:%yellow% %pagesize%%deft% | klr
echo(
if not exist "%file%.img-cmdline" goto nocmdline
for /f "delims=" %%a in (%file%.img-cmdline) do @set scmdline=!scmdline!%%a
echo Command line:%yellow% '%scmdline%'%deft% | klr
echo(
:nocmdline
if not exist "%file%.img-kernel_offset" goto nokoff
for /f "delims=" %%a in (%file%.img-kernel_offset) do @set koff=!koff!%%a
echo Kernel offset:%yellow% %koff%%deft% | klr
echo(
:nokoff
if not exist "%file%.img-ramdisk_offset" goto noramoff
for /f "delims=" %%a in (%file%.img-ramdisk_offset) do @set ramoff=!ramoff!%%a
echo Ramdisk offset:%yellow% %ramoff%%deft% | klr
echo(
:noramoff
if not exist "%file%.img-second_offset" goto nosecoff
for /f "delims=" %%a in (%file%.img-second_offset) do @set fsecoff=!fsecoff!%%a
echo Second offset:%yellow% %fsecoff%%deft% | klr
set secoff=--second_offset %fsecoff%
echo(
:nosecoff
if not exist "%file%.img-second" goto nosecd
set fsecd=!fsecd!%file%.img-second
echo Second bootloader:%yellow% %fsecd%%deft% | klr
set "second=--second %fsecd%"
echo(
:nosecd
if not exist "%file%.img-tags_offset" goto notagoff
for /f "delims=" %%a in (%file%.img-tags_offset) do @set tagoff=!tagoff!%%a
echo Tags offset:%yellow% %tagoff%%deft% | klr
echo(
:notagoff
if not exist "%file%.img-dt" goto nodt
set fdt=!fdt!%file%.img-dt
echo Device tree blob:%yellow% %fdt%%deft% | klr
set "dtb=--dt %fdt%"
echo(
:nodt
echo(
:newimage
echo Please enter the desired name for the new repacked image without extension (img). Like this %yellow%boot%deft%-stock-2201 or carliv-%yellow%recovery%deft%-30 or %yellow%boot%deft%-new. | klr
set /P newimage=Insert the name here: || set newimage="0"
if "%newimage%"=="0" goto noimage
if not "%newimage%"=="%newimage:boot=%" goto command
if not "%newimage%"=="%newimage:recovery=%" goto command
goto wrongname
echo(
:command
echo Your new image is%yellow% %newimage%.img%deft%. | klr
echo(
echo Executing the repacking command....
echo(
mtkbootimg --kernel %kernel% --ramdisk %ramdisk% --pagesize %pagesize% --base %base% --board "%nameb%" --kernel_offset %koff% --ramdisk_offset %ramoff% --tags_offset %tagoff% %second% --cmdline "%scmdline%" %secoff% %dtb% -o ..\%newimage%.img
del "%file%.img-ramdisk.%compress%"
cd ..\
echo(
echo(
echo Done. Your new image was repacked as%yellow% %newimage%.img%deft%. | klr
goto end
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:noinput
echo(
echo(
echo %red%No folder selected. Exit script.%deft% | klr
echo(
goto end
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:wrongname
echo(
echo(
echo %red%The name have to include the type of image in it, %yellow%boot%red% or%yellow% recovery%red%.%deft% | klr
echo(
goto newimage
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:noimage
echo(
echo(
echo %red%Please enter a name for the repacked image first.%deft% | klr
echo(
goto newimage
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:error
echo(
echo(
echo %red%There is an error in your folder. The kernel or ramdisk is missing. Exit script.%deft% | klr
echo(
echo(
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:end
echo(
pause