Skip to content
This repository has been archived by the owner on Nov 13, 2017. It is now read-only.

Commit

Permalink
Initial support for MTK kernels
Browse files Browse the repository at this point in the history
  • Loading branch information
JustArchi committed Jan 25, 2015
1 parent efe9522 commit d8d11ef
Show file tree
Hide file tree
Showing 21 changed files with 767 additions and 43 deletions.
123 changes: 80 additions & 43 deletions archi
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ set +e
# Initial variables
VERSION="1.0" # Unused
TEMPDIR="TEMP"
TOOLSDIR="tools"
TOOLS=(which whoami basename dirname gcc java perl sed cut wget od wc cpio zip unzip tar)
XDALINK="http://forum.xda-developers.com/showthread.php?t=2597220"
GITHUBLINK="https://github.com/JustArchi/ArchiKitchen.git"
Expand Down Expand Up @@ -227,7 +228,7 @@ TRY_MOUNT() {
echo "Yes it is!"
if [[ ! -x "$TEMPDIR/simg2img" ]]; then
echo "Compiling simg2img..."
gcc -O2 "tools/simg2img/sparse_crc32.c" "tools/simg2img/simg2img.c" -o "$TEMPDIR/simg2img"
gcc -O2 "$TOOLSDIR/simg2img/sparse_crc32.c" "$TOOLSDIR/simg2img/simg2img.c" -o "$TEMPDIR/simg2img"
fi
echo "Converting sparse image to image..."
./$TEMPDIR/simg2img "$1" "$1".simg2img
Expand Down Expand Up @@ -730,7 +731,7 @@ FIX_SYMLINKS() {
KERNEL_EXTRACT() {
if [[ ! -d "$ACTIVE_PROJECT/kernel" ]]; then
if [[ ! -x "$TEMPDIR/mkbootimg" ]]; then
cd tools/mkbootimg
cd "$TOOLSDIR/mkbootimg"
make
if [[ ! -x mkbootimg || ! -x unpackbootimg ]]; then
echo "ERROR! Something went wrong with compilation of mkbootimg!"
Expand All @@ -742,10 +743,15 @@ KERNEL_EXTRACT() {
make clean
cd ../..
fi

if [[ ! -L "$TOOLSDIR/mtk-tools/mkbootimg" ]]; then
ln -s "../../$TEMPDIR/mkbootimg" "$TOOLSDIR/mtk-tools/mkbootimg"
fi

if [[ -f "$ACTIVE_PROJECT/boot.img" ]]; then
mkdir -p "$ACTIVE_PROJECT/kernel"
"$TEMPDIR/unpackbootimg" -i "$ACTIVE_PROJECT/boot.img" -o "$ACTIVE_PROJECT/kernel"
mkdir -p "$ACTIVE_PROJECT/kernel/ramdisk"
mkdir -p "$ACTIVE_PROJECT/kernel/boot.img-ramdisk"
if [[ -f "$ACTIVE_PROJECT/kernel/boot.img-ramdisk.gz" ]]; then
# Detect compression algorithm
if [[ "$(gunzip -t "$ACTIVE_PROJECT/kernel/boot.img-ramdisk.gz" >/dev/null 2>&1; echo $?)" -eq 0 ]]; then
Expand All @@ -765,15 +771,30 @@ KERNEL_EXTRACT() {
CBIN="lzma -9"
DBIN="lzma -dc"
else
echo "ERROR: Could not detect any known format of the ramdisk!"
echo "WARNING: Could not detect any known format of the ramdisk!"
KERNEL_ABORT
PRESS_ENTER
return 1
echo "INFO: Trying to unpack the kernel as MTK..."
mkdir -p "$ACTIVE_PROJECT/kernel"
cd "$ACTIVE_PROJECT/kernel"
local MTK_PROBE="$(../../$TOOLSDIR/mtk-$TOOLSDIR/unpack-MTK.pl "../boot.img" >/dev/null 2>&1; echo $?)"
cd ../..
if [[ "$MTK_PROBE" -eq 0 ]]; then
echo "INFO: Success!"
CBIN="mtk"
DBIN="mtk"
else
echo "ERROR: Could not find any valid method to unpack this kernel. Either it's not valid, or ArchiKitchen can't find out how to deal with it"
KERNEL_ABORT
PRESS_ENTER
return 1
fi
fi
echo "$CBIN" > "$ACTIVE_PROJECT/kernel/ArchiKitchen-compression-method" # Store for future use, if user decides to shut down the kitchen
cd "$ACTIVE_PROJECT/kernel/ramdisk"
$DBIN ../boot.img-ramdisk.gz | cpio -i
cd ../../..
if [[ "$CBIN" != "mtk" && "$DBIN" != "mtk" ]]; then
cd "$ACTIVE_PROJECT/kernel/boot.img-ramdisk"
$DBIN ../boot.img-ramdisk.gz | cpio -i
cd ../../..
fi
fi
else
echo "ERROR: No kernel could be found!"
Expand All @@ -787,7 +808,7 @@ KERNEL_EXTRACT() {
KERNEL_REPACK() {
local EXTRA=()
if [[ -d "$ACTIVE_PROJECT/kernel" ]]; then
if [[ -d "$ACTIVE_PROJECT/kernel/ramdisk" ]]; then
if [[ -d "$ACTIVE_PROJECT/kernel/boot.img-ramdisk" ]]; then
if [[ -z "$CBIN" && -f "$ACTIVE_PROJECT/kernel/ArchiKitchen-compression-method" ]]; then
CBIN="$(cat "$ACTIVE_PROJECT/kernel/ArchiKitchen-compression-method")" # Load compression method if we need it and have it stored
elif [[ -z "$CBIN" ]]; then
Expand All @@ -796,28 +817,44 @@ KERNEL_REPACK() {
PRESS_ENTER
return 1
fi
cd "$ACTIVE_PROJECT/kernel/ramdisk"
find . | cpio -o -H newc | $CBIN > ../boot.img-ramdisk-NEW.gz
cd ../../..
if [[ -f "$ACTIVE_PROJECT/kernel/boot.img-dtb" ]]; then
EXTRA+=(--dt "$ACTIVE_PROJECT/kernel/boot.img-dtb")
local SUCCESS=1
if [[ "$CBIN" != "mtk" ]]; then
cd "$ACTIVE_PROJECT/kernel/boot.img-ramdisk"
find . | cpio -o -H newc | $CBIN > ../boot.img-ramdisk-NEW.gz
cd ../../..
if [[ -f "$ACTIVE_PROJECT/kernel/boot.img-dtb" ]]; then
EXTRA+=(--dt "$ACTIVE_PROJECT/kernel/boot.img-dtb")
fi
SUCCESS="$(
"$TEMPDIR/mkbootimg" --kernel "$ACTIVE_PROJECT/kernel/boot.img-zImage" \
--ramdisk "$ACTIVE_PROJECT/kernel/boot.img-ramdisk-NEW.gz" \
--base "$(cat "$ACTIVE_PROJECT/kernel/boot.img-base")" \
--cmdline "$(cat "$ACTIVE_PROJECT/kernel/boot.img-cmdline")" \
--kernel_offset "$(cat "$ACTIVE_PROJECT/kernel/boot.img-kerneloff")" \
--pagesize "$(cat "$ACTIVE_PROJECT/kernel/boot.img-pagesize")" \
--ramdisk_offset "$(cat "$ACTIVE_PROJECT/kernel/boot.img-ramdiskoff")" \
--tags_offset "$(cat "$ACTIVE_PROJECT/kernel/boot.img-tagsoff")" \
"${EXTRA[@]}" \
-o "$ACTIVE_PROJECT/temp.img" >/dev/null 2>&1
echo $?
)"
else
cd "$ACTIVE_PROJECT/kernel"
SUCCESS="$(
../../tools/mtk-tools/repack-MTK.pl -boot \
boot.img-kernel.img \
boot.img-ramdisk \
temp.img >/dev/null 2>&1
echo $?
)"
cd ../..
fi
"$TEMPDIR/mkbootimg" --kernel "$ACTIVE_PROJECT/kernel/boot.img-zImage" \
--ramdisk "$ACTIVE_PROJECT/kernel/boot.img-ramdisk-NEW.gz" \
--base "$(cat "$ACTIVE_PROJECT/kernel/boot.img-base")" \
--cmdline "$(cat "$ACTIVE_PROJECT/kernel/boot.img-cmdline")" \
--kernel_offset "$(cat "$ACTIVE_PROJECT/kernel/boot.img-kerneloff")" \
--pagesize "$(cat "$ACTIVE_PROJECT/kernel/boot.img-pagesize")" \
--ramdisk_offset "$(cat "$ACTIVE_PROJECT/kernel/boot.img-ramdiskoff")" \
--tags_offset "$(cat "$ACTIVE_PROJECT/kernel/boot.img-tagsoff")" \
"${EXTRA[@]}" \
-o "$ACTIVE_PROJECT/temp.img"
if [[ $? -eq 0 ]]; then
if [[ "$SUCCESS" -eq 0 ]]; then
mv "$ACTIVE_PROJECT/temp.img" "$ACTIVE_PROJECT/boot.img"
KERNEL_ABORT # This is actually used for cleaning only
return 0
else
echo "ERROR: Something went wrong!"
echo "ERROR: Something went wrong! Error code: $SUCCESS"
KERNEL_ABORT
PRESS_ENTER
return 1
Expand All @@ -839,9 +876,9 @@ KERNEL_ABORT() {

# Adds kernel's Init.d
INITD() {
if [[ -f "$ACTIVE_PROJECT/kernel/ramdisk/init.rc" ]]; then
sed -i -e '0,/class_start /s//start sysinit\n\n class_start /' "$ACTIVE_PROJECT/kernel/ramdisk/init.rc"
sed -i -e 's/service media /service sysinit \/system\/bin\/logwrapper \/system\/xbin\/busybox run-parts \/system\/etc\/init.d\n disabled\n oneshot\n\nservice media /' "$ACTIVE_PROJECT/kernel/ramdisk/init.rc"
if [[ -f "$ACTIVE_PROJECT/kernel/boot.img-ramdisk/init.rc" ]]; then
sed -i -e '0,/class_start /s//start sysinit\n\n class_start /' "$ACTIVE_PROJECT/kernel/boot.img-ramdisk/init.rc"
sed -i -e 's/service media /service sysinit \/system\/bin\/logwrapper \/system\/xbin\/busybox run-parts \/system\/etc\/init.d\n disabled\n oneshot\n\nservice media /' "$ACTIVE_PROJECT/kernel/boot.img-ramdisk/init.rc"
cp -R files/initd/system/* "$ACTIVE_PROJECT/system/"
UPDATER_SCRIPT_ADD "files/initd/updater-scripts"
else
Expand Down Expand Up @@ -939,15 +976,15 @@ DEODEX_FILE() {
echo "Disassembling $ODEX..."
rm -rf "$TEMPDIR/$ODEX"
mkdir -p "$TEMPDIR/$ODEX"
java -jar tools/smali/baksmali.jar -a "$API" -d "$ACTIVE_PROJECT/system/framework" -x "$FILEDIR/$ODEX" -o "$TEMPDIR/$ODEX/DECOMPILED"
java -jar "$TOOLSDIR/smali/baksmali.jar" -a "$API" -d "$ACTIVE_PROJECT/system/framework" -x "$FILEDIR/$ODEX" -o "$TEMPDIR/$ODEX/DECOMPILED"
if [[ $? -ne 0 || ! -d "$TEMPDIR/$ODEX/DECOMPILED" ]]; then
echo "ERROR: Could not deodex $ODEX, aborting!"
rm -rf "$TEMPDIR/$ODEX"
PRESS_ENTER
return 1
fi
echo "Assembling disassembled $ODEX into classes.dex..."
java -jar tools/smali/smali.jar -a "$API" -o "$TEMPDIR/$ODEX/classes.dex" "$TEMPDIR/$ODEX/DECOMPILED"
java -jar "$TOOLSDIR/smali/smali.jar" -a "$API" -o "$TEMPDIR/$ODEX/classes.dex" "$TEMPDIR/$ODEX/DECOMPILED"
if [[ $? -ne 0 || ! -f "$TEMPDIR/$ODEX/classes.dex" ]]; then
echo "ERROR: Could not assemble disassembled $ODEX, aborting!"
rm -rf "$TEMPDIR/$ODEX"
Expand Down Expand Up @@ -1137,13 +1174,13 @@ REMOVE_KNOX() {

# Adds or removes insecure ADB
ADB() {
if [[ -d "$ACTIVE_PROJECT/kernel/ramdisk" ]]; then
if [[ "$(grep -qi "ro.adb.secure=1" "$ACTIVE_PROJECT/kernel/ramdisk/default.prop"; echo $?)" -eq 0 ]]; then
SED_CHANGE_WORD "ro.adb.secure=1" "ro.adb.secure=0" "$ACTIVE_PROJECT/kernel/ramdisk/default.prop"
SED_CHANGE_WORD "ro.secure=1" "ro.secure=0" "$ACTIVE_PROJECT/kernel/ramdisk/default.prop"
if [[ -d "$ACTIVE_PROJECT/kernel/boot.img-ramdisk" ]]; then
if [[ "$(grep -qi "ro.adb.secure=1" "$ACTIVE_PROJECT/kernel/boot.img-ramdisk/default.prop"; echo $?)" -eq 0 ]]; then
SED_CHANGE_WORD "ro.adb.secure=1" "ro.adb.secure=0" "$ACTIVE_PROJECT/kernel/boot.img-ramdisk/default.prop"
SED_CHANGE_WORD "ro.secure=1" "ro.secure=0" "$ACTIVE_PROJECT/kernel/boot.img-ramdisk/default.prop"
else
SED_CHANGE_WORD "ro.adb.secure=0" "ro.adb.secure=1" "$ACTIVE_PROJECT/kernel/ramdisk/default.prop"
SED_CHANGE_WORD "ro.secure=0" "ro.secure=1" "$ACTIVE_PROJECT/kernel/ramdisk/default.prop"
SED_CHANGE_WORD "ro.adb.secure=0" "ro.adb.secure=1" "$ACTIVE_PROJECT/kernel/boot.img-ramdisk/default.prop"
SED_CHANGE_WORD "ro.secure=0" "ro.secure=1" "$ACTIVE_PROJECT/kernel/boot.img-ramdisk/default.prop"
fi
fi
}
Expand Down Expand Up @@ -1237,16 +1274,16 @@ PRINT_ROM_STATUS() {
else
echo "[NO]"
fi
if [[ -d "$ACTIVE_PROJECT/kernel/ramdisk" ]]; then
if [[ -d "$ACTIVE_PROJECT/kernel/boot.img-ramdisk" ]]; then
PRINT_LINE
echo -n "ADB? "
if [[ "$(grep -qi "ro.adb.secure=0" "$ACTIVE_PROJECT/kernel/ramdisk/default.prop"; echo $?)" -eq 0 ]]; then
if [[ "$(grep -qi "ro.adb.secure=0" "$ACTIVE_PROJECT/kernel/boot.img-ramdisk/default.prop"; echo $?)" -eq 0 ]]; then
echo "[INSECURE]"
else
echo "[SECURE]"
fi
echo -n "Kernel Init.d? "
if [[ "$(grep -qi "sysinit" "$ACTIVE_PROJECT/kernel/ramdisk/init.rc"; echo $?)" -eq 0 ]]; then
if [[ "$(grep -qi "sysinit" "$ACTIVE_PROJECT/kernel/boot.img-ramdisk/init.rc"; echo $?)" -eq 0 ]]; then
echo "[YES]"
else
echo "[NO]"
Expand All @@ -1266,7 +1303,7 @@ PRINT_SWITCHES() {
echo "z - Zipalign Everything"
echo "knox - Remove KNOX"
echo "-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-"
if [[ -d "$ACTIVE_PROJECT/kernel/ramdisk" ]]; then
if [[ -d "$ACTIVE_PROJECT/kernel/boot.img-ramdisk" ]]; then
echo "kr - Repack kernel (apply all ramdisk changes)"
echo "ka - Abort repacking (abort all ramdisk changes)"
echo
Expand Down Expand Up @@ -1412,7 +1449,7 @@ case "$HOSTARCH" in
esac

# Set common tools
ZIPALIGN="./tools/zipalign/$HOSTARCH/zipalign"
ZIPALIGN="./$TOOLSDIR/zipalign/$HOSTARCH/zipalign"

# Navigate to our folder, even if user didn't execute it from the root dir
cd "$(dirname "$0")"
Expand Down
1 change: 1 addition & 0 deletions tools.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ Also, for a reference where to search for updates
[Bak]smali | https://bitbucket.org/JesusFreke/smali/downloads | 2.0.5
Busybox | https://play.google.com/store/apps/details?id=stericson.busybox | 5 January 2015
Kernel repack tools | https://github.com/osm0sis/mkbootimg | 03905f7e5080c175d711726988ac81a3179e3923
MTK-Tools | https://github.com/bgcngm/mtk-tools | 94e358d027bd677d9943d461ca54bc21d2068ec6
SuperSU | http://download.chainfire.eu/supersu | 2.45
Zipalign | https://developer.android.com/tools/revisions/build-tools.html | November 2014
Empty file modified tools/mkbootimg/NOTICE
100644 → 100755
Empty file.
Empty file modified tools/mkbootimg/bootimg.h
100644 → 100755
Empty file.
Empty file modified tools/mkbootimg/libmincrypt/dsa_sig.c
100644 → 100755
Empty file.
Empty file modified tools/mkbootimg/libmincrypt/p256.c
100644 → 100755
Empty file.
Empty file modified tools/mkbootimg/libmincrypt/p256_ec.c
100644 → 100755
Empty file.
Empty file modified tools/mkbootimg/libmincrypt/p256_ecdsa.c
100644 → 100755
Empty file.
Empty file modified tools/mkbootimg/libmincrypt/rsa.c
100644 → 100755
Empty file.
Empty file modified tools/mkbootimg/libmincrypt/sha.c
100644 → 100755
Empty file.
Empty file modified tools/mkbootimg/libmincrypt/sha256.c
100644 → 100755
Empty file.
Empty file modified tools/mkbootimg/libmincrypt/tools/DumpPublicKey.java
100644 → 100755
Empty file.
Empty file modified tools/mkbootimg/mincrypt/dsa_sig.h
100644 → 100755
Empty file.
Empty file modified tools/mkbootimg/mincrypt/hash-internal.h
100644 → 100755
Empty file.
Empty file modified tools/mkbootimg/mincrypt/p256.h
100644 → 100755
Empty file.
Empty file modified tools/mkbootimg/mincrypt/p256_ecdsa.h
100644 → 100755
Empty file.
Empty file modified tools/mkbootimg/mincrypt/rsa.h
100644 → 100755
Empty file.
Empty file modified tools/mkbootimg/mincrypt/sha.h
100644 → 100755
Empty file.
Empty file modified tools/mkbootimg/mincrypt/sha256.h
100644 → 100755
Empty file.
Loading

0 comments on commit d8d11ef

Please sign in to comment.