diff --git a/ARM/README.md b/ARM/README.md index 83a4774..fe21a37 100755 --- a/ARM/README.md +++ b/ARM/README.md @@ -1,7 +1,3 @@ -Original Source Modified By: -Modding.MyMind XDA \ -ModdingMyMind AF - Built to be used on Arm devices. Move the bash binary to /system/xbin. diff --git a/ARM/mkboot b/ARM/mkboot index 106a06d..211e0e6 100755 --- a/ARM/mkboot +++ b/ARM/mkboot @@ -37,14 +37,18 @@ file=$tooldir/file old_bootimg=true C_OUT="\033[0;1m" C_ERR="\033[31;1m" +C_CAUT="\033[33;1m" C_CLEAR="\033[0;0m" - + pout() { $busybox printf "${C_OUT}${*}${C_CLEAR}\n" } perr() { $busybox printf "${C_ERR}${*}${C_CLEAR}\n" } +pcaut() { + $busybox printf "${C_CAUT}${*}${C_CLEAR}\n" +} clean() { $busybox rm -rf /tmp/mkboot.* @@ -54,55 +58,92 @@ clean() # Check for busybox if [ -z $busybox ]; then - clear; pout "Busybox is NOT installed!\nThis may cause issues with the script!\nUse at your own risk or install busybox!"; sleep 3 + clear; pcaut "Busybox is NOT installed!\nThis may cause issues with the script!\nUse at your own peril or install busybox!"; sleep 2 fi usage() { - pout "" - pout "----------------------------------------------------------------------" - pout "Not enough parameters or parameter error!" - pout "unpack boot.img & decompress ramdisk:\n $($busybox basename $0) [img] [output dir]" - pout " $($busybox basename $0) boot.img boot20130905" - pout "Use the unpacked directory repack boot.img(img_info):\n $($busybox basename $0) [unpacked dir] [newbootfile]" - pout " $($busybox basename $0) boot20130905 newboot.img" + pcaut "\n" + perr "Not enough parameters or parameter error!\n" + pout "Unpack Image & Decompress Ramdisk : \n $($busybox basename $0) [image] [output dir]" + pout " $($busybox basename $0) boot.img project_folder\n" + pout "Repack Image & Compress Ramdisk : \n $($busybox basename $0) [unpacked dir] [new image]" + pout " $($busybox basename $0) project_folder newboot.img\n" clean } print_info() { + [ ! -z "$board" ] && pout " board : $board" pout " kernel : $kernel" pout " ramdisk : $ramdisk" pout " page size : $page_size" pout " kernel size : $kernel_size" pout " ramdisk size : $ramdisk_size" [ ! -z $second_size ] && [ $second_size -gt 0 ] && \ - pout " second_size : $second_size" + pout " second size : $second_size" [ $dtb_size -gt 0 ] && pout " dtb size : $dtb_size" +if [ ! -z $base_warning ]; then + pcaut " base : $base_addr (Non Standard)" +else pout " base : $base_addr" +fi +if [ ! -z $kernel_offset_warning ]; then + pcaut " kernel offset : $kernel_offset (Non Standard)" +else pout " kernel offset : $kernel_offset" +fi +if [ ! -z $ramdisk_offset_warning ]; then + pcaut " ramdisk offset : $ramdisk_offset (Non Standard)" +else pout " ramdisk offset : $ramdisk_offset" - [ -z $second_offset ] || pout " second_offset : $second_offset" +fi +if [ ! -z $second_offset_warning ]; then + [ -z $second_offset ] || pcaut " second offset : $second_offset (Non Standard)" +else + [ -z $second_offset ] || pout " second offset : $second_offset" +fi +if [ ! -z $tags_offset_warning ]; then + pcaut " tags offset : $tags_offset (Non Standard)" +else pout " tags offset : $tags_offset" +fi [ $dtb_size -gt 0 ] && pout " dtb img : $dt" + [ $second_size -gt 0 ] && pout " second img : $second" pout " cmd line : $cmd_line" } mkboot_img() { error=0 - if [ $dtb_size -gt 0 ]; then - dtb="--dt ${dt}" - fi - $mkbootimg --kernel $kernel --ramdisk $ramdisk \ + [ $second_size -gt 0 ] && second="--second ${second}" + [ $dtb_size -gt 0 ] && dtb="--dt ${dt}" + [ ! -z $second_offset ] && second_offset="--second_offset ${second_offset}" + [ ! -z "$board" ] && board="--board $board" + + $mkbootimg --kernel $kernel --ramdisk $ramdisk $board \ --base $base_addr --ramdisk_offset $ramdisk_offset \ + --kernel_offset $kernel_offset $second_offset \ --tags_offset $tags_offset --cmdline "$cmd_line" \ - --pagesize $page_size $dtb -o $new_img 2>/dev/null || error=1 + --pagesize $page_size $second $dtb -o $new_img 2>/dev/null || error=1 + [ $error -eq 1 ] && return $error ramdisk_size=$($busybox stat -c "%s" $ramdisk) boot_size=$($busybox stat -c "%s" $new_img) pout "\nKernel size: $kernel_size, new ramdisk size: $ramdisk_size, $($busybox basename $new_img): $boot_size." pout "\n$($busybox basename $new_img) has been created.\n" + +# Check if new build is larger than original +# Give caution if it is to insure size is not larger than the partition +# A courtesy warning +if [[ "$image_size" -lt "$boot_size" ]]; then + beefed_up=$(( $boot_size - $image_size )) + pcaut "\n****** CAUTION ******* CAUTION ******* CAUTION ******" + pout "\n$($busybox basename $new_img) is $beefed_up bytes larger than" + pout "the original build! Make sure this new" + pout "size is not larger than the actual partition!" + pcaut "\n****** CAUTION ******* CAUTION ******* CAUTION ******\n" +fi } #decide action @@ -122,14 +163,16 @@ if [ ! -z $mkboot_from_dir ]; then new_img=$2 cd $unpacked_dir if [ ! -s img_info ]; then - pout "Missing img_info file! Can't rebuild $2." + perr "Missing img_info file! Can't rebuild $2." clean fi eval $(cat img_info) + if [ -z $kernel ] || [ -z $ramdisk ] || [ -z $base_addr ]; then - pout "Lacking parameters in img_info." + perr "Lacking parameters in img_info." clean fi + [ -z $second_size ] && second_size=0 [ -z $dtb_size ] && dtb_size=0 if [ -d $ramdisk ]; then compression_type=$($file -m $magic ./ramdisk.* | $busybox cut -d: -f2 | $busybox cut -d" " -f2) @@ -142,17 +185,17 @@ if [ ! -z $mkboot_from_dir ]; then lz4) compression_warning=$compression_type; compression_repack="$lz4 -l";; esac; if [ -z $compression_warning ]; then - pout "\n****** HAZARD ******* HAZARD ******* HAZARD ******" + perr "\n****** HAZARD ******* HAZARD ******* HAZARD ******" pout "\nRamdisk is $compression_type format. Can't repack ramdisk." pout "This tool currently does not support $compression_type." - pout "\n****** HAZARD ******* HAZARD ******* HAZARD ******\n" + perr "\n****** HAZARD ******* HAZARD ******* HAZARD ******\n" exit fi if [ $compression_type != "gzip" ]; then if [ $compression_type != "lzma" ]; then if [ $compression_type != "lz4" ]; then if [ $compression_type != "xz" ]; then - pout "\nRamdisk is unknown format. Can't repack ramdisk." + perr "\nRamdisk is unknown format. Can't repack ramdisk." exit 0 else # XZ @@ -209,7 +252,7 @@ pout "\nUnpack & decompress $1 to $2\n" cp -f $1 $tempdir/ cd $tempdir bootimg=$($busybox basename $1) -offset=$($grep -abo ANDROID! $bootimg | $busybox cut -f 1 -d :) +offset=$($grep -abo ANDROID! $bootimg | $busybox cut -f 1 -d : | head -1) [ -z $offset ] && clean if [ $offset -gt 0 ]; then $busybox dd if=$bootimg of=bootimg bs=$offset skip=1 2>/dev/null @@ -222,77 +265,110 @@ second_addr=0x$($od -A n -X -j 28 -N 4 $bootimg | $busybox sed 's/ //g' | $busyb tags_addr=0x$($od -A n -X -j 32 -N 4 $bootimg | $busybox sed 's/ //g' | $busybox sed 's/^0*//g') kernel_size=$($od -A n -D -j 8 -N 4 $bootimg | $busybox sed 's/ //g') -base_addr=0x$($od -A n -x -j 14 -N 2 $bootimg | $busybox sed 's/ //g')0000 +#base_addr=0x$($od -A n -x -j 14 -N 2 $bootimg | $busybox sed 's/ //g')0000 ramdisk_size=$($od -A n -D -j 16 -N 4 $bootimg | $busybox sed 's/ //g') second_size=$($od -A n -D -j 24 -N 4 $bootimg | $busybox sed 's/ //g') page_size=$($od -A n -D -j 36 -N 4 $bootimg | $busybox sed 's/ //g') dtb_size=$($od -A n -D -j 40 -N 4 $bootimg | $busybox sed 's/ //g') -cmd_line=$($od -A n --strings -j 64 -N 512 $bootimg) +#cmd_line=$($od -A n --strings -j 64 -N 512 $bootimg) +#board=$($od -A n --strings -j 48 -N 16 $bootimg) +cmd_line=$($od -A n -S1 -j 64 -N 512 $bootimg) +board=$($od -A n -S1 -j 48 -N 16 $bootimg) +base_addr=$((kernel_addr-0x00008000)) kernel_offset=$((kernel_addr-base_addr)) ramdisk_offset=$((ramdisk_addr-base_addr)) second_offset=$((second_addr-base_addr)) tags_offset=$((tags_addr-base_addr)) +base_addr=$(printf "%08x" $base_addr) +kernel_offset=$(printf "%08x" $kernel_offset) +ramdisk_offset=$(printf "%08x" $ramdisk_offset) +second_offset=$(printf "%08x" $second_offset) +tags_offset=$(printf "%08x" $tags_offset) + +base_addr=0x${base_addr:0-8} +kernel_offset=0x${kernel_offset:0-8} +ramdisk_offset=0x${ramdisk_offset:0-8} +second_offset=0x${second_offset:0-8} +tags_offset=0x${tags_offset:0-8} + ######################################################### # BELOW SECTION HANDLES NON STANDARD IMAGES -non_standard_base=$((tags_addr-0x00000100)) # Need this to get the TRUE Base Address -non_standard_base_addr=$($busybox printf "0x%08x" $non_standard_base) -base_addr_verify=$($busybox printf "0x%08x" $base_addr) -base_addr=$($busybox printf "0x%08x" $base_addr) +non_standard_base_addr=$((tags_addr-0x00000100)) # Need this to get the TRUE Base Address +non_standard_base_addr=$($busybox printf "%08x" $non_standard_base_addr) +non_standard_base_addr=0x${non_standard_base_addr:0-8} -if [ $base_addr == $non_standard_base ]; then - base_addr=$($busybox printf "0x%08x" $base_addr) +if [ $base_addr == $non_standard_base_addr ]; then + base_addr=$base_addr else - base_addr=$($busybox printf "0x%08x" $non_standard_base_addr) + base_addr=$non_standard_base_addr fi # Accurate offsets used on images with non standard mkbootimg.c -kernel_offset_ns=$((kernel_addr-non_standard_base)) -ramdisk_offset_ns=$((ramdisk_addr-non_standard_base)) -second_offset_ns=$((second_addr-non_standard_base)) -tags_offset_ns=$((tags_addr-non_standard_base)) +kernel_offset_ns=$((kernel_addr-non_standard_base_addr)) +kernel_offset_ns=$($busybox printf "%08x" $kernel_offset_ns) +kernel_offset_ns=0x${kernel_offset_ns:0-8} +ramdisk_offset_ns=$((ramdisk_addr-non_standard_base_addr)) +ramdisk_offset_ns=$($busybox printf "%08x" $ramdisk_offset_ns) +ramdisk_offset_ns=0x${ramdisk_offset_ns:0-8} +second_offset_ns=$((second_addr-non_standard_base_addr)) +second_offset_ns=$($busybox printf "%08x" $second_offset_ns) +second_offset_ns=0x${second_offset_ns:0-8} +tags_offset_ns=$((tags_addr-non_standard_base_addr)) +tags_offset_ns=$($busybox printf "%08x" $tags_offset_ns) +tags_offset_ns=0x${tags_offset_ns:0-8} # Do the Offsets match with the Base Address for standard mkbootimg.c? kernel_offset_s=$((kernel_addr-0x00008000)) +kernel_offset_s=$($busybox printf "%08x" $kernel_offset_s) +kernel_offset_s=0x${kernel_offset_s:0-8} ramdisk_offset_s=$((ramdisk_addr-0x01000000)) +ramdisk_offset_s=$($busybox printf "%08x" $ramdisk_offset_s) +ramdisk_offset_s=0x${ramdisk_offset_s:0-8} second_offset_s=$((second_addr-0x00f00000)) +second_offset_s=$($busybox printf "%08x" $second_offset_s) +second_offset_s=0x${second_offset_s:0-8} tags_offset_s=$((tags_addr-0x00000100)) +tags_offset_s=$($busybox printf "%08x" $tags_offset_s) +tags_offset_s=0x${tags_offset_s:0-8} -if [ $non_standard_base -eq $kernel_offset_s ]; then - kernel_offset=$($busybox printf "0x%08x" $kernel_offset) +if [ $non_standard_base_addr == $kernel_offset_s ]; then + kernel_offset=$kernel_offset else - kernel_offset_ns=$($busybox printf "0x%08x" $kernel_offset_ns) - kernel_offset=$($busybox printf "0x%08x" $kernel_offset_ns) - kernel_offset_warning=$kernel_offset_ns + kernel_offset=$kernel_offset_ns + kernel_offset_warning=$kernel_offset fi -if [ $non_standard_base -eq $ramdisk_offset_s ]; then - ramdisk_offset=$($busybox printf "0x%08x" $ramdisk_offset) +if [ $non_standard_base_addr == $ramdisk_offset_s ]; then + ramdisk_offset=$ramdisk_offset else - ramdisk_offset_ns=$($busybox printf "0x%08x" $ramdisk_offset_ns) - ramdisk_offset=$($busybox printf "0x%08x" $ramdisk_offset_ns) - ramdisk_offset_warning=$ramdisk_offset_ns + ramdisk_offset=$ramdisk_offset_ns + ramdisk_offset_warning=$ramdisk_offset fi -if [ $non_standard_base -eq $second_offset_s ]; then - second_offset=$($busybox printf "0x%08x" $second_offset) +if [ $non_standard_base_addr == $second_offset_s ]; then + second_offset=$second_offset else - second_offset_ns=$($busybox printf "0x%08x" $second_offset_ns) - second_offset=$($busybox printf "0x%08x" $second_offset_ns) - second_offset_warning=$second_offset_ns + second_offset=$second_offset_ns + second_offset_warning=$second_offset fi -if [ $base_addr_verify != $non_standard_base_addr ]; then +if [ $base_addr != 0x10000000 ]; then base_warning=$non_standard_base_addr fi -tags_offset=$($busybox printf "0x%08x" $tags_offset_ns) +if [ $non_standard_base_addr == $tags_offset_s ]; then + tags_offset=$tags_offset +else + tags_offset=$tags_offset_ns + tags_offset_warning=$tags_offset +fi # Below are the known offsets for non standard mkbootimg.c -if [[ ! -z $kernel_offset_warning ]] || [[ ! -z $ramdisk_offset_warning ]] || [[ ! -z $second_offset_warning ]]; then - pout "****** WARNING ******* WARNING ******* WARNING ******\n" +if [[ ! -z $base_warning ]] || [[ ! -z $kernel_offset_warning ]] || [[ ! -z $ramdisk_offset_warning ]] || [[ ! -z $second_offset_warning ]] || [[ ! -z $tags_offset_warning ]]; then + perr "****** WARNING ******* WARNING ******* WARNING ******\n" pout "This image is built using NON-standard mkbootimg!\n" fi if [ ! -z $base_warning ]; then @@ -307,9 +383,12 @@ fi if [ ! -z $second_offset_warning ]; then pout "SECOND_OFFSET is $second_offset_ns" fi -if [[ ! -z $kernel_offset_warning ]] || [[ ! -z $ramdisk_offset_warning ]] || [[ ! -z $second_offset_warning ]]; then +if [ ! -z $tags_offset_warning ]; then + pout "TAGS_OFFSET is $tags_offset_ns" +fi +if [[ ! -z $base_warning ]] || [[ ! -z $kernel_offset_warning ]] || [[ ! -z $ramdisk_offset_warning ]] || [[ ! -z $second_offset_warning ]] || [[ ! -z $tags_offset_warning ]] ; then pout "\nYou can modify mkbootimg.c with the above value(s)" - pout "\n****** WARNING ******* WARNING ******* WARNING ******\n" + perr "\n****** WARNING ******* WARNING ******* WARNING ******\n" fi # ABOVE SECTION HANDLES NON STANDARD IMAGES @@ -327,17 +406,29 @@ d_offset=$((s_offset+s_count)) #zImage $busybox dd if=$bootimg of=zImage_tmp bs=$page_size skip=$k_offset count=$k_count 2>/dev/null $busybox dd if=zImage_tmp of=zImage bs=$kernel_size count=1 2>/dev/null + #ramdisk.gz $busybox dd if=$bootimg of=ramdisk_tmp bs=$page_size skip=$r_offset count=$r_count 2>/dev/null $busybox dd if=ramdisk_tmp of=ramdisk.gz bs=$ramdisk_size count=1 2>/dev/null + +#second image +if [ $second_size -gt 0 ]; then + $busybox dd if=$bootimg of=second.img_tmp bs=$page_size skip=$s_offset count=$s_count 2>/dev/null + $busybox dd if=second.img_tmp of=second.img bs=$second_size count=1 2>/dev/null + second="$tempdir/second.img" + second=$($busybox basename $second) + secondb_name="second=$second" + secondb_size="second_size=$second_size" +fi + #dtb if [ $dtb_size -gt 0 ]; then $busybox dd if=$bootimg of=dt.img_tmp bs=$page_size skip=$d_offset count=$d_count 2>/dev/null $busybox dd if=dt.img_tmp of=dt.img bs=$dtb_size count=1 2>/dev/null dt="$tempdir/dt.img" dt=$($busybox basename $dt) - dt_name="dt=$dt\n" - dt_size="dtb_size=$dtb_size\n" + dt_name="dt=$dt" + dt_size="dtb_size=$dtb_size" fi $busybox rm -f *_tmp $($busybox basename $1) $bootimg @@ -347,10 +438,22 @@ ramdisk=ramdisk #print boot.img info print_info +# Properly escape double quotes +# Keep double quotes intact +cmd_line=$(echo $cmd_line | sed -e "s/'/'\\\\''/g; 1s/^/'/; \$s/\$/'/") + #write info to img_info,decompression ramdisk.gz -$busybox printf "kernel=zImage\nramdisk=ramdisk\n${dt_name}page_size=$page_size\n\ -kernel_size=$kernel_size\nramdisk_size=$ramdisk_size\n${dt_size}base_addr=$base_addr\nkernel_offset=$kernel_offset\n\ -ramdisk_offset=$ramdisk_offset\ntags_offset=$tags_offset\ncmd_line=\"$cmd_line\"\n" > img_info + +[ ! -z "$board" ] && liveboard="board=\"$board\"" + +$busybox printf "kernel=zImage\nramdisk=ramdisk\n${secondb_name}\n${dt_name}\npage_size=$page_size\n\ +kernel_size=$kernel_size\nramdisk_size=$ramdisk_size\n${secondb_size}\n${dt_size}\nbase_addr=$base_addr\nkernel_offset=$kernel_offset\n\ +ramdisk_offset=$ramdisk_offset\nsecond_offset=$second_offset\ntags_offset=$tags_offset\ncmd_line=$cmd_line\n$liveboard\n" > img_info + +# Include original image size in bytes to img_info +image_size=$($busybox stat -c "%s" '../'$1) +$busybox printf "image_size=$image_size" >> img_info + $busybox mkdir ramdisk cd ramdisk @@ -364,16 +467,16 @@ case $compression_type in lz4) compression_ext=lz4; decomp_ramdisk="$lz4 -d"; extra="< ../ramdisk.cpio";; esac; -if [[ $compression_ext != "lz4" ]]; then +if [[ $compression_ext != lz4 ]]; then decomp_ramdisk="$compression_type -d -c" fi decomp_ramdisk2="$cpio -i -d -m --no-absolute-filenames" if [ -z $compression_ext ]; then - pout "\n****** HAZARD ******* HAZARD ******* HAZARD ******" + perr "\n****** HAZARD ******* HAZARD ******* HAZARD ******" pout "\nRamdisk is $compression_warning format. Can't unpack ramdisk." pout "This tool currently does not support $compression_warning." - pout "\n****** HAZARD ******* HAZARD ******* HAZARD ******\n" + perr "\n****** HAZARD ******* HAZARD ******* HAZARD ******\n" exit fi @@ -384,7 +487,3 @@ $decomp_ramdisk "../ramdisk.$compression_ext" | $decomp_ramdisk2 $extra #Unpack Finish to exit. pout "Unpack completed.\n" exit - - - - diff --git a/ARM/mkbootfs b/ARM/mkbootfs index b53321b..c177ea6 100755 Binary files a/ARM/mkbootfs and b/ARM/mkbootfs differ diff --git a/ARM/mkbootimg b/ARM/mkbootimg index b83d51f..9cfb1e4 100755 Binary files a/ARM/mkbootimg and b/ARM/mkbootimg differ