Skip to content

Instantly share code, notes, and snippets.

@swiftgeek
Created May 28, 2014 03:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save swiftgeek/95d36b08b363b6a12cc6 to your computer and use it in GitHub Desktop.
Save swiftgeek/95d36b08b363b6a12cc6 to your computer and use it in GitHub Desktop.
My attempt to make update.zip sane (top of the script) + easy way for messing with initramfs contents on galaxy mini (tass)
#!/sbin/sh
# Author: Swift Geek
#Break on any errors
set -e
#
# arg 1 is API version, according to source should be 3, previous ones can trash radio.
#
# arg 2 is the pipefd "API", https://github.com/CyanogenMod/android_bootable_recovery/blob/7d531818bdd94f7dc02bd5faeb882b4f14643999/install.c
# communicate with it using the recovery api (Whole 3 commands)
# progress <frac> <secs> # Unavailable on my devices
# set_progress <frac> # Unavailable on my devices
# ui_print <string> # Doesn't interpret new lines inside string, no arg == print new line
#
# arg 3 is the zip file path including filename
pipefd="$2"
zippath="$3" # if path to zipfile - change to $*_path
# TODO: redo all "API" functions from edify
# TODO: check lockfiles
# TODO: Clean tmpdir and delete it afterwards
# TODO: Actually flash image "usage: flash_image partition file.img"
# TODO: dump_image instead of dd (so no need to guess partition)
ui_print () {
# TIP: the lowest line is never visible on tass!! So making dotted progress bar is impossible for now
n_sub='\nui_print\n' # substitute every new line with this
#ui_string="${*//\\\n/$n_sub}"
printf "ui_print ${*//\\\n/$n_sub}\n" > "/proc/self/fd/$pipefd"
# printf "ui_print\n" > "/proc/self/fd/$pipefd" #Assume that every line should be visible, for now
}
set_progress () {
# Doens't work on Apollo with CWM5.0.2.8 and any of my CWM6 devices
#TODO: check if arg is only one (otherwise print warning that perhaps "progress" should be used instead), check if parse-able
#WARNING: set_progress\n will kill update-binary . Make sure that this doesn't happen
printf "set_progress $1\n" > "/proc/self/fd/$pipefd"
}
progress () {
#Works for me only in CWM5, also in very strange way: has to be commited with `progress 0 0` if $2 was 0
# Progress 0 0 to end timer
# Also accepts negative values!
#TODO: ignore or parse comma as separator (find and replace propably to space, somehow recall function to get args reparsed, check if not too deep with export var)
# change ', ' to ' ', then ',' to ' ' to make sure that comma-edify-compatibility exist in easiest way
printf "progress $*\n" > "/proc/self/fd/$pipefd"
}
ui_print "Pipefd: ${pipefd}\n"
ui_print "PID: $$\n"
#ui_print "ZIP path: $zippath\n"
#sleep 360
#exit 0
#### REPACKING PART ORIGINALLY FROM:
#### PSN>> Memory-MOD-v2 & SWAPALL-v3.0
#### CM10.1 JB
######################################
#### This script (containing snippets and binary from one mentioned above) is just for easier manual editting of initramfs all it does is:
#### 1. Extract&&Unpack initramfs
#### 2. Creates "lock"file and waits for its deletion
#### 3. Repackages and flashes resulting boot.img
#### TODO: Find open source version of mkbootimg and unpack_bootimg
#### TODO: Clean dirs in /tmp first or create own tmpdir; USE `mktemp` from shell -.-!
#### Changes brought to You by: Swift Geek
tmpdir='/tmp/bootimg_edit'
bootimg="$tmpdir/bootimg"
patching="$tmpdir/patching"
workboot="$tmpdir/workboot"
tools="$tmpdir/tools"
#TODO: Unpack, chmod and create dirs
rm -rf $tmpdir || true
mkdir -p $tools
mkdir -p $bootimg
mkdir -p $patching
mkdir -p $workboot
cd $tmpdir
unzip $zippath tools/bootimgtools # $2 here is path inside zip
cd $tools
ln -s ./bootimgtools mkbootimg
ln -s ./bootimgtools unpack_bootimg
chmod a+x bootimgtools
chmod a+x mkbootimg
chmod a+x unpack_bootimg
set_progress 0.3, 0
ui_print "| |\n"
ui_print "| Extracting RAMDISK from your |\n"
ui_print "| current kernel to: |\n"
ui_print "|$patching\n"
#dd if=/dev/block/bml8 of=$workboot/boot.img bs=4096
dump_image boot $workboot/boot.img
$tools/unpack_bootimg -i $workboot/boot.img -o $workboot/
set_progress 0.4, 0
ui_print "| |\n"
cp $workboot/boot.img-zImage $bootimg/boot.img-zImage
cp $workboot/boot.img-ramdisk.gz $patching/boot.img-ramdisk.gz
cd $patching; gunzip -c $patching/boot.img-ramdisk.gz | cpio -i
rm $patching/boot.img-ramdisk.gz
set_progress 0.5, 0
ui_print "|Entering infinity loop ... |\n"
ui_print "|Delete lockfile to continue: |\n"
ui_print "| /tmp/psn.lock |\n"
touch /tmp/psn.lock;
while [ -e /tmp/psn.lock ]; do sleep 1; done;
set_progress 0.6, 0
ui_print "| |\n"
ui_print "|Compressing RAMDISK... |\n"
cd $patching
find . | cpio -o -H newc | gzip > $bootimg/boot.img-ramdisk.gz;
set_progress 0.7, 0
ui_print "| |\n"
ui_print "|Creating boot.img for flashing|\n"
$tools/mkbootimg --kernel $bootimg/boot.img-zImage --ramdisk $bootimg/boot.img-ramdisk.gz --base 13600000 --pagesize 4096 -o /tmp/boot.img
set_progress 0.8, 0
ui_print "| |\n"
ui_print "|Flashing modified boot.img ...|\n"
flash_image boot /tmp/boot.img
ui_print "| Done! Reboot system now! |\n"
# TODO: Clean, add cases for unsuccesful flash and catch errors for stuff before flash_image line - to display "nothing wrong happened"
# TODO: Add cases where flash_image and/or dump_image are not included in recovery
# TODO: Instructions on how to pass update.zip to recovery from android systemy, check Xposed source perhaps
ui_print "|______________________________|\n"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment