|
| 1 | +############################################################################ |
| 2 | +# |
| 3 | +# Copyright (c) 2012 - dsixda (dislam@rocketmail.com) |
| 4 | +# |
| 5 | +# Android Kitchen is 100% free. This script file is intended for personal |
| 6 | +# and/or educational use only. It may not be duplicated for monetary |
| 7 | +# benefit or any other purpose without the permission of the developer. |
| 8 | +# |
| 9 | +############################################################################ |
| 10 | + |
| 11 | +# |
| 12 | +# This script has three optional parameters: |
| 13 | +# |
| 14 | +# $1 = page size / kernel offset in boot.img (in decimal) |
| 15 | +# $2 = kernel base offset (in hexadecimal, e.g. 0x200000; needs $1 defined) |
| 16 | +# $3 = command line (needs $1 and $2 defined) |
| 17 | +# |
| 18 | + |
| 19 | +echo |
| 20 | + |
| 21 | +if [ -d BOOT-EXTRACTED ] |
| 22 | +then |
| 23 | + echo Found BOOT-EXTRACTED folder, checking contents ... |
| 24 | + |
| 25 | + if [ -d BOOT-EXTRACTED/boot.img-ramdisk ] |
| 26 | + then |
| 27 | + echo Found boot.img-ramdisk |
| 28 | + |
| 29 | + if [ -e BOOT-EXTRACTED/zImage ] |
| 30 | + then |
| 31 | + echo Found zImage |
| 32 | + else |
| 33 | + echo Did not find BOOT-EXTRACTED/zImage |
| 34 | + exit 0 |
| 35 | + fi |
| 36 | + |
| 37 | + else |
| 38 | + echo Did not find boot-extracted/boot.img-ramdisk folder! |
| 39 | + exit 0 |
| 40 | + fi |
| 41 | + |
| 42 | +else |
| 43 | + echo Did not find BOOT-EXTRACTED folder! |
| 44 | + exit 0 |
| 45 | +fi |
| 46 | + |
| 47 | + |
| 48 | +if [ -d WORKING_* ] |
| 49 | +then |
| 50 | + echo Working folder found |
| 51 | +else |
| 52 | + echo Working folder not found! |
| 53 | + exit 0 |
| 54 | +fi |
| 55 | + |
| 56 | + |
| 57 | + |
| 58 | +if [ "$1" == "" ] |
| 59 | +then |
| 60 | + |
| 61 | + # |
| 62 | + # Determine the kernel offset to be used in the new boot.img, |
| 63 | + # based on the current boot.img or /boot folder. |
| 64 | + # |
| 65 | + |
| 66 | + cd WORKING_* |
| 67 | + |
| 68 | + if [ -e boot.img ] |
| 69 | + then |
| 70 | + |
| 71 | + cd .. |
| 72 | + scripts/check_kernel_offset |
| 73 | + res=$? |
| 74 | + |
| 75 | + if [ "$res" != "0" ] |
| 76 | + then |
| 77 | + exit 0 |
| 78 | + fi |
| 79 | + |
| 80 | + else |
| 81 | + |
| 82 | + if [ ! -e boot/initrd.gz ] || [ ! -e boot/zImage ] |
| 83 | + then |
| 84 | + echo "boot.img not found under working folder!" |
| 85 | + cd .. |
| 86 | + exit 0 |
| 87 | + else |
| 88 | + |
| 89 | + # Using a fake base address and command line to create the boot.img, since |
| 90 | + # we don't have a boot.img and are using the NAND method; boot.img won't |
| 91 | + # be in final NAND ROM. |
| 92 | + |
| 93 | + base=0x11800000 |
| 94 | + cmd_line="dsixda NAND" |
| 95 | + |
| 96 | + cd .. |
| 97 | + fi |
| 98 | + fi |
| 99 | + |
| 100 | +else |
| 101 | + |
| 102 | + # |
| 103 | + # Using hard-coded values |
| 104 | + # |
| 105 | + |
| 106 | + scripts/set_kernel_offset_files $1 |
| 107 | + |
| 108 | + if [ "$2" != "" ] |
| 109 | + then |
| 110 | + base=$2 |
| 111 | + |
| 112 | + if [ "$3" != "" ] |
| 113 | + then |
| 114 | + cmd_line=$3 |
| 115 | + fi |
| 116 | + fi |
| 117 | + |
| 118 | +fi |
| 119 | + |
| 120 | + |
| 121 | + |
| 122 | +# |
| 123 | +# Check for MT65xx |
| 124 | +# |
| 125 | + |
| 126 | +cd WORKING_* |
| 127 | +working_folder=`pwd` |
| 128 | +cd .. |
| 129 | +dec_offset=`scripts/get_boot_img_page_size $working_folder` |
| 130 | +scripts/check_mt65xx_bootimg $working_folder $dec_offset 1>/dev/null |
| 131 | +mt65xx=$? |
| 132 | + |
| 133 | + |
| 134 | + |
| 135 | +# |
| 136 | +# Compile mkboot* |
| 137 | +# |
| 138 | + |
| 139 | +if [ "$mt65xx" == "1" ] |
| 140 | +then |
| 141 | + mkbootimg_src=mkbootimg_mt65xx.c |
| 142 | +else |
| 143 | + mkbootimg_src=mkbootimg.c |
| 144 | +fi |
| 145 | +mkbootimg_out=mkbootimg |
| 146 | + |
| 147 | +if [ `uname | grep CYGWIN` ] |
| 148 | +then |
| 149 | + mkbootfs_file=mkbootfs.exe |
| 150 | + mkbootimg_file=$mkbootimg_out.exe |
| 151 | +else |
| 152 | + mkbootfs_file=mkbootfs |
| 153 | + mkbootimg_file=$mkbootimg_out |
| 154 | +fi |
| 155 | + |
| 156 | + |
| 157 | +if [ -e tools/mkboot/$mkbootfs_file ] |
| 158 | +then |
| 159 | + echo "Found $mkbootfs_file" |
| 160 | +else |
| 161 | + echo |
| 162 | + echo "Compiling mkbootfs ..." |
| 163 | + cd tools/mkboot |
| 164 | + gcc -o mkbootfs mkbootfs.c 2>/dev/null |
| 165 | + cd ../.. |
| 166 | + |
| 167 | + if [ -e tools/mkboot/$mkbootfs_file ] |
| 168 | + then |
| 169 | + echo mkbootfs successfully compiled |
| 170 | + else |
| 171 | + echo "Error: mkbootfs not successfully compiled!" |
| 172 | + exit 0 |
| 173 | + fi |
| 174 | +fi |
| 175 | + |
| 176 | + |
| 177 | +if [ -e tools/mkboot/$mkbootimg_file ] |
| 178 | +then |
| 179 | + rm -f $mkbootimg_file |
| 180 | +fi |
| 181 | + |
| 182 | +echo |
| 183 | +echo "Compiling mkbootimg ..." |
| 184 | +cd tools/mkboot |
| 185 | +gcc -c rsa.c |
| 186 | +gcc -c sha.c |
| 187 | +gcc rsa.o sha.o $mkbootimg_src -w -o $mkbootimg_out |
| 188 | +rm *.o |
| 189 | +cd ../.. |
| 190 | + |
| 191 | +if [ -e tools/mkboot/$mkbootimg_file ] |
| 192 | +then |
| 193 | + echo "$mkbootimg_out successfully compiled" |
| 194 | +else |
| 195 | + echo "Error: $mkbootimg_out not successfully compiled!" |
| 196 | + exit 0 |
| 197 | +fi |
| 198 | + |
| 199 | + |
| 200 | +cp tools/mkboot/$mkbootfs_file BOOT-EXTRACTED/ |
| 201 | +cp tools/mkboot/$mkbootimg_file BOOT-EXTRACTED/ |
| 202 | +cd BOOT-EXTRACTED |
| 203 | + |
| 204 | + |
| 205 | +# |
| 206 | +# Run mkbootfs |
| 207 | +# |
| 208 | + |
| 209 | +echo |
| 210 | +echo "Creating ramdisk cpio archive ..." |
| 211 | +./$mkbootfs_file boot.img-ramdisk | lz4 > ramdisk.lz4 |
| 212 | + |
| 213 | + |
| 214 | + |
| 215 | + |
| 216 | +cd .. |
| 217 | +cd WORKING_* |
| 218 | + |
| 219 | +if [ -e boot.img ] |
| 220 | +then |
| 221 | + |
| 222 | + cd .. |
| 223 | + echo |
| 224 | + |
| 225 | + # |
| 226 | + # Get original size of boot.img |
| 227 | + # |
| 228 | + size_orig=`scripts/get_boot_img_size` |
| 229 | + |
| 230 | + |
| 231 | + # |
| 232 | + # Determine kernel base address before running mkbootimg |
| 233 | + # |
| 234 | + |
| 235 | + if [ "$base" == "" ] |
| 236 | + then |
| 237 | + echo "Attempting to determine kernel base address ..." |
| 238 | + base=`scripts/get_kernel_base_addr` |
| 239 | + fi |
| 240 | + |
| 241 | + echo "Using base address of $base" |
| 242 | + |
| 243 | + |
| 244 | + # |
| 245 | + # Determine ramdisk load address |
| 246 | + # |
| 247 | + ramdisk_addr=`scripts/get_ramdisk_addr` |
| 248 | + |
| 249 | + echo "Using ramdisk load address of $ramdisk_addr" |
| 250 | + |
| 251 | + |
| 252 | + # |
| 253 | + # If no parameters entered, then find out the command line |
| 254 | + # |
| 255 | + # NOTE: Check the first two parameters to determine whether the user set the |
| 256 | + # command line to an empty string intentionally |
| 257 | + # |
| 258 | + if [ "$3" == "" ] && [ "$1" == "" ] |
| 259 | + then |
| 260 | + echo "Attempting to determine command line parameter ..." |
| 261 | + cmd_line=`scripts/get_cmdline` |
| 262 | + fi |
| 263 | + |
| 264 | + if [ "$cmd_line" == "" ] |
| 265 | + then |
| 266 | + echo "No cmdline" |
| 267 | + else |
| 268 | + echo "Using cmdline: $cmd_line" |
| 269 | + fi |
| 270 | + |
| 271 | +else |
| 272 | + cd .. |
| 273 | +fi |
| 274 | + |
| 275 | + |
| 276 | +################################################# |
| 277 | +# |
| 278 | +# Run mkbootimg to build new boot.img |
| 279 | +# |
| 280 | +################################################# |
| 281 | + |
| 282 | +cd BOOT-EXTRACTED |
| 283 | + |
| 284 | +echo |
| 285 | +echo "Building new boot.img ..." |
| 286 | + |
| 287 | +ramdisk_params="" |
| 288 | +if [ "$ramdisk_addr" != "" ] |
| 289 | +then |
| 290 | + ramdisk_params="--ramdiskaddr $ramdisk_addr" |
| 291 | +fi |
| 292 | + |
| 293 | +if [ "$cmd_line" == "" ] |
| 294 | +then |
| 295 | + ./$mkbootimg_file --kernel zImage --ramdisk ramdisk.lz4 -o newBoot.img --base $base $ramdisk_params |
| 296 | +else |
| 297 | + ./$mkbootimg_file --kernel zImage --ramdisk ramdisk.lz4 --cmdline "$cmd_line" -o newBoot.img --base $base $ramdisk_params |
| 298 | +fi |
| 299 | + |
| 300 | + |
| 301 | +if [ -e newBoot.img ] |
| 302 | +then |
| 303 | + echo |
| 304 | + echo "newBoot.img created" |
| 305 | + |
| 306 | + echo "Moving to working folder as boot.img" |
| 307 | + cd ../WORKING_* |
| 308 | + mv -f ../BOOT-EXTRACTED/newBoot.img boot.img |
| 309 | + |
| 310 | + if [ "$size_orig" != "" ] |
| 311 | + then |
| 312 | + |
| 313 | + # |
| 314 | + # Get new size of boot.img |
| 315 | + # |
| 316 | + cd .. |
| 317 | + size_new=`scripts/get_boot_img_size` |
| 318 | + cd WORKING_* |
| 319 | + |
| 320 | + if [ "$size_new" != "" ] |
| 321 | + then |
| 322 | + echo |
| 323 | + echo "boot.img size" |
| 324 | + echo "Old: $size_orig" |
| 325 | + echo "New: $size_new" |
| 326 | + fi |
| 327 | + fi |
| 328 | + |
| 329 | + if [ -d boot ] && [ -e boot/initrd.gz ] && [ -e boot/zImage ] |
| 330 | + then |
| 331 | + echo |
| 332 | + echo "Removing NAND boot folder ..." |
| 333 | + rm -rf boot |
| 334 | + fi |
| 335 | + |
| 336 | + cd .. |
| 337 | + |
| 338 | + echo |
| 339 | + echo "Removing BOOT-EXTRACTED folder ..." |
| 340 | + rm -rf BOOT-EXTRACTED |
| 341 | + |
| 342 | + exit_code=1 |
| 343 | + |
| 344 | +else |
| 345 | + echo |
| 346 | + echo "newBoot.img not created!" |
| 347 | + |
| 348 | + rm $mkbootfs_file |
| 349 | + rm $mkbootimg_file |
| 350 | + |
| 351 | + cd .. |
| 352 | + exit_code=0 |
| 353 | +fi |
| 354 | + |
| 355 | +./scripts/press_enter |
| 356 | +./menu |
0 commit comments