mirror of
https://github.com/xiaolu/mkbootimg_tools.git
synced 2026-04-09 15:02:31 +02:00
Cosmetic detailing:
- Compare original image size with new size and let user know if it's larger. - Bug fix for usage displayed in terminal - Other changes
This commit is contained in:
80
ARM/mkboot
80
ARM/mkboot
@@ -37,6 +37,7 @@ 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() {
|
||||
@@ -45,6 +46,9 @@ pout() {
|
||||
perr() {
|
||||
$busybox printf "${C_ERR}${*}${C_CLEAR}\n"
|
||||
}
|
||||
pcaut() {
|
||||
$busybox printf "${C_CAUT}${*}${C_CLEAR}\n"
|
||||
}
|
||||
clean()
|
||||
{
|
||||
$busybox rm -rf /tmp/mkboot.*
|
||||
@@ -54,18 +58,17 @@ 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 "<Unpack and repack boot.img tool>"
|
||||
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<Unpack and Repack Image Tool>"
|
||||
perr "Not enough parameters or parameter error!\n"
|
||||
pout "Unpack Image & Decompress Ramdisk <Usage>: \n $($busybox basename $0) [image] [output dir]"
|
||||
pout " $($busybox basename $0) boot.img project_folder\n"
|
||||
pout "Repack Image & Compress Ramdisk <Usage>: \n $($busybox basename $0) [unpacked dir] [new image]"
|
||||
pout " $($busybox basename $0) project_folder newboot.img\n"
|
||||
clean
|
||||
}
|
||||
|
||||
@@ -80,12 +83,31 @@ print_info()
|
||||
[ ! -z $second_size ] && [ $second_size -gt 0 ] && \
|
||||
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_size ] && [ $second_size -gt 0 ] && \
|
||||
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"
|
||||
@@ -96,10 +118,11 @@ mkboot_img()
|
||||
error=0
|
||||
[ $second_size -gt 0 ] && second="--second ${second}"
|
||||
[ $dtb_size -gt 0 ] && dtb="--dt ${dt}"
|
||||
[ ! -z $second_offset ] && second_offset="--second_offset ${second_offset}"
|
||||
|
||||
$mkbootimg --kernel $kernel --ramdisk $ramdisk --board "$board" \
|
||||
--base $base_addr --ramdisk_offset $ramdisk_offset \
|
||||
--kernel_offset $kernel_offset --second_offset $second_offset \
|
||||
--kernel_offset $kernel_offset $second_offset \
|
||||
--tags_offset $tags_offset --cmdline "$cmd_line" \
|
||||
--pagesize $page_size $second $dtb -o $new_img 2>/dev/null || error=1
|
||||
|
||||
@@ -108,6 +131,18 @@ mkboot_img()
|
||||
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
|
||||
@@ -127,13 +162,13 @@ 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
|
||||
@@ -149,17 +184,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
|
||||
@@ -332,7 +367,7 @@ fi
|
||||
|
||||
# Below are the known offsets for non standard mkbootimg.c
|
||||
if [[ ! -z $kernel_offset_warning ]] || [[ ! -z $ramdisk_offset_warning ]] || [[ ! -z $second_offset_warning ]] || [[ ! -z $tags_offset_warning ]] ; then
|
||||
pout "****** WARNING ******* WARNING ******* WARNING ******\n"
|
||||
perr "****** WARNING ******* WARNING ******* WARNING ******\n"
|
||||
pout "This image is built using NON-standard mkbootimg!\n"
|
||||
fi
|
||||
if [ ! -z $base_warning ]; then
|
||||
@@ -352,7 +387,7 @@ if [ ! -z $tags_offset_warning ]; then
|
||||
fi
|
||||
if [[ ! -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
|
||||
@@ -410,6 +445,11 @@ cmd_line=$(echo $cmd_line | sed -e "s/'/'\\\\''/g; 1s/^/'/; \$s/\$/'/")
|
||||
$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\nboard=\"$board\"\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
|
||||
|
||||
@@ -429,10 +469,10 @@ 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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user