Skip to content

Commit

Permalink
Atom7: Scripting & Branding & Fixing
Browse files Browse the repository at this point in the history
Credits to @sayeed99 and @eoghan2t9 :)
  • Loading branch information
ramrasekar committed Oct 20, 2017
1 parent 344a19b commit e19b6dd
Show file tree
Hide file tree
Showing 16 changed files with 373 additions and 6 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ modules.builtin
*.lzo
*.patch
*.gcno
*.log
*bzImage
*zImage
*.zip

#
# Top-level generic files
Expand Down
2 changes: 1 addition & 1 deletion arch/x86/configs/zenfone2_defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ CONFIG_EXPERIMENTAL=y
CONFIG_INIT_ENV_ARG_LIMIT=32
CONFIG_CROSS_COMPILE=""
CONFIG_LOCALVERSION=""
CONFIG_LOCALVERSION_AUTO=y
# CONFIG_LOCALVERSION_AUTO is not set
CONFIG_HAVE_KERNEL_GZIP=y
CONFIG_HAVE_KERNEL_BZIP2=y
CONFIG_HAVE_KERNEL_LZMA=y
Expand Down
138 changes: 138 additions & 0 deletions buildzf2
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
#!/bin/bash

export ARCH=x86_64
export CCOMPILE=$CROSS_COMPILE
export CROSS_COMPILE=x86_64-linux-android-

#Change Toolchain GCC versions from here
#But I personally prefer Google's x86_64-linux-android-4.9
GCC_VERSION=4.9

TC_PREFIX=x86_64-linux-android
TOOLCHAIN=$TC_PREFIX-$GCC_VERSION
CUR_DIR=$PWD

clear

echo "---------------SETTING UP ENVIRONMENT---------------"
start=`date +%s`
NOW=$(date +"%d-%m-%Y")
echo "Current Date : $NOW"
echo "Applying Build Settings"
export SLEEP=1
echo "Setting CPU Cores/Threads"
export CPUS=`nproc`
echo "Setting Version Number"
export VER=v1$1
echo "Setting Defconfig"
export DEFCONFIG=zenfone2_defconfig
echo "Setting bzImage Location"
export BZIMAGE=arch/x86/boot/bzImage
echo "Environment Setup Complete Now Moving To Compiling"
echo ""
echo ""
echo ""
echo "-----CHECKING IF TOOLCHAIN IS IN CORRECT PATH-------"
sleep $SLEEP
cd ..
TC=$PWD
if [ -f $TC/$TOOLCHAIN/bin/$TC_PREFIX-gcc ];
then
cd $CUR_DIR
echo "ToolChain exists"
echo "Starting Compilation"
echo "SETTING TOOLCHAIN PATH : $TC/$TOOLCHAIN/bin"
export PATH=$TC/$TOOLCHAIN/bin-ccache:$TC/$TOOLCHAIN/bin:$PATH
echo ""
echo ""
echo ""
sleep $SLEEP
echo "------------------COMPILING----------------------"
else
echo "Could not find toolchain at $TC/$TOOLCHAIN/"
echo "DOWNLOADING TOOLCAHIN"
git clone https://github.com/Zenfone2-development/x86_64-linux-android-$GCC_VERSION
echo "Starting Compilation"
echo "SETTING TOOLCHAIN PATH : $TC/$TOOLCHAIN/bin"
export PATH=$TC/$TOOLCHAIN/bin-ccache:$TC/$TOOLCHAIN/bin:$PATH
echo ""
echo ""
echo ""
sleep $SLEEP
cd $CUR_DIR
echo "------------------COMPILING----------------------"
fi



#Build
sleep $SLEEP
#make clean
echo "Starting Build Process"
export USE_CCACHE=1
sleep $SLEEP
if [ -f .config ];
then
echo ".config exists"
echo "Starting Compilation"
echo ""
echo ""
echo ""
echo "------------------COMPILING----------------------"
sleep $SLEEP
else
echo ".config Does Not Exists"
echo "Compiling From $DEFCONFIG"
make $DEFCONFIG
echo "Starting Compilation"
sleep $SLEEP
fi
make $EV -j$CPUS 2>&1 | tee build.log

if [ -f $BZIMAGE ];
then
echo "$BZIMAGE exists"
echo "-------------------SUCCESS-----------------------"
echo ""
echo ""
echo ""
sleep $SLEEP
else
echo "-----------------------------------ERROR------------------------------------"
echo " Failed to compile. Please Check *build.log* For Compile Errors"
echo "-----------------------------------ERROR------------------------------------"
echo "exiting script"
sleep $SLEEP
exit 0
fi

clear
echo "--------------------PACKING-------------------------"
echo "Starting Packing To Recovery Flashable Zip"
cd out/
echo "Removing Old Files"
rm -rf bzImage *.zip
sleep $SLEEP
echo "Copying bzImage"
mv ../arch/x86/boot/bzImage bzImage
sleep $SLEEP
echo "Compiling Atom7_"$VER".zip"
find . -type f -exec zip Atom7_"$VER".zip {} +
nowf=$(date +"%T")
cd ..
echo "Current Date : $NOW"
echo "Applying Build Settings : done"
echo "Version Number = $VER"
echo "cleaning previous files : done"
echo "Starting Build Process : done"
echo "Build complete"

end=`date +%s`
runtime=$((end-start))
echo "Completion Time :"
echo "$runtime sec\n"

echo "------------------- CLEANING------------------------"
make clean && make mrproper
echo "----------------------DONE--------------------------"

84 changes: 84 additions & 0 deletions out/META-INF/com/google/android/update-binary
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
#!/sbin/sh
# AnyKernel2 Backend
# osm0sis @ xda-developers

OUTFD=/proc/self/fd/$2;
ZIP="$3";
DIR=`dirname "$ZIP"`;

ui_print() {
until [ ! "$1" ]; do
echo -e "ui_print $1\nui_print" > $OUTFD;
shift;
done;
}
show_progress() { echo "progress $1 $2" > $OUTFD; }
set_perm_recursive() {
dirs=$(echo $* | awk '{ print substr($0, index($0,$5)) }');
for i in $dirs; do
chown -R $1.$2 $i; chown -R $1:$2 $i;
find "$i" -type d -exec chmod $3 {} +;
find "$i" -type f -exec chmod $4 {} +;
done;
}
file_getprop() { grep "^$2" "$1" | cut -d= -f2; }
getprop() { test -e /sbin/getprop && /sbin/getprop $1 || file_getprop /default.prop $1; }
abort() { ui_print "$*"; exit 1; }

show_progress 1.34 4;
ui_print " ";
mkdir -p /tmp/anykernel;
cd /tmp/anykernel;
unzip -o "$ZIP";

ui_print "$(file_getprop /tmp/anykernel/anykernel.sh kernel.string)";
ui_print "==========================================";
ui_print " Atom7 by @rb_rasekar ";
ui_print "==========================================";

/sbin/busybox mount /system;

if [ "$(file_getprop /tmp/anykernel/anykernel.sh do.devicecheck)" == 1 ]; then
ui_print "Checking device...";
ui_print " ";
for i in 1 2 3 4 5; do
testname="$(file_getprop /tmp/anykernel/anykernel.sh device.name$i)";
if [ "$(getprop ro.product.device)" == "$testname" -o "$(getprop ro.build.product)" == "$testname" ]; then
match=1;
fi;
done;
if [ "$match" != 1 ]; then
umount /system;
abort "Unsupported device. Aborting...";
fi;
fi;

if [ "$(file_getprop /tmp/anykernel/anykernel.sh do.initd)" == 1 ]; then
ui_print "Creating init.d...";
ui_print " ";
mkdir /system/etc/init.d;
set_perm_recursive 0 0 0755 0755 /system/etc/init.d;
fi;

ui_print "Installing Atom7 kernel...";
/sbin/sh /tmp/anykernel/anykernel.sh;
if [ "$(cat /tmp/anykernel/exitcode)" == 1 ]; then
umount /system;
abort;
fi;

if [ "$(file_getprop /tmp/anykernel/anykernel.sh do.modules)" == 1 ]; then
ui_print "Pushing modules...";
ui_print " ";
cp -f /tmp/anykernel/modules/* /system/lib/modules/;
set_perm_recursive 0 0 0755 0644 /system/lib/modules;
fi;

if [ "$(file_getprop /tmp/anykernel/anykernel.sh do.cleanup)" == 1 ]; then
rm -rf /tmp/anykernel;
fi;

umount /system;
ui_print " ";
ui_print "Reboot and enjoy ;)";

1 change: 1 addition & 0 deletions out/META-INF/com/google/android/updater-script
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Dummy file; update-binary is a shell script.
63 changes: 63 additions & 0 deletions out/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
AnyKernel 2.0 - Flashable Zip Template for Kernel Releases with Ramdisk Modifications
by osm0sis @ xda-developers

"AnyKernel is a template for an update.zip that can apply any kernel to any ROM, regardless of ramdisk." - Koush

AnyKernel2 pushes the format even further by allowing kernel developers to modify the underlying ramdisk for kernel feature support easily using a number of included command methods along with properties and variables.

A working script based on DirtyV Kernel for Galaxy Nexus (tuna) is included for reference.

// Properties / Variables

kernel.string=KernelName by YourName @ xda-developers
do.devicecheck=1
do.initd=1
do.modules=1
do.cleanup=1
device.name1=maguro
device.name2=toro
device.name3=toroplus
block=/dev/block/platform/omap/omap_hsmmc.0/by-name/boot;

do.devicecheck=1 specified requires at least device.name1 to be present. This should match ro.product.device or ro.build.product for your device. There is support for up to 5 device.name# properties.

do.initd=1 will create the init.d directory in /system/etc/init.d/ and apply 755 permissions.

do.modules=1 will push the contents of the module directory to /system/lib/modules/ and apply 644 permissions.

do.cleanup=0 will keep the zip from removing it's working directory in /tmp/anykernel - this can be useful if trying to debug in adb shell whether the patches worked correctly.

// Command Methods

dump_boot
backup_file <file>
replace_string <file> <if search string> <original string> <replacement string>
insert_line <file> <if search string> <before/after> <line match string> <inserted line>
replace_line <file> <line replace string> <replacement line>
remove_line <file> <line match string>
prepend_file <file> <if search string> <patch file>
append_file <file> <if search string> <patch file>
replace_file <file> <permissions> <patch file>
write_boot

"if search string" is the string it looks for to decide whether it needs to add the tweak or not, so generally something to indicate the tweak already exists.

Similarly, "line match string" and "line replace string" are the search strings that locate where the modification needs to be made for those commands.

"before/after" requires you simply specify "before" or "after" for the placement of the inserted line, in relation to "line match string".

You may also use ui_print "<text>" to write messages back to the recovery during the modification process.

// Instructions

1- Place zImage in the root (dtb should also go here for devices that require a custom one, both will fallback to the original if not included)
2- Place any required ramdisk files in /ramdisk
3- Place any required patch files (generally partial files which go with commands) in /patch
4- Modify the anykernel.sh to add your kernel's name, boot partition location, permissions for included ramdisk files, and use methods for any required ramdisk modifications
5- zip -r9 UPDATE-AnyKernel2.zip * -x README UPDATE-AnyKernel2.zip

Not required, but any tweaks you can't hardcode into the source should be added with a bootscript.sh like is done in the example provided.


Have fun!

75 changes: 75 additions & 0 deletions out/anykernel.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# AnyKernel 2.0 Ramdisk Mod Script
# osm0sis @ xda-developers

## AnyKernel setup
# EDIFY properties
kernel.string=Zenfone 2 AnyKernel Script
do.devicecheck=0
do.initd=1
do.modules=0
do.cleanup=0
device.name1=Z00A
device.name2=z008
device.name3=
device.name4=
device.name5=

# shell variables
block=/dev/block/by-name/boot;

## end setup


## AnyKernel methods (DO NOT CHANGE)
# set up extracted files and directories
ramdisk=/tmp/anykernel/ramdisk;
bin=/tmp/anykernel/tools;
split_img=/tmp/anykernel/split_img;
patch=/tmp/anykernel/patch;

chmod -R 777 $bin;
mkdir -p $ramdisk $split_img;
#cd /tmp/anykernel;

OUTFD=`ps | grep -v "grep" | grep -oE "update(.*)" | cut -d" " -f3`;
ui_print() { echo "ui_print $1" >&$OUTFD; echo "ui_print" >&$OUTFD; }

# dump boot and extract ramdisk
dump_boot() {
dd if=$block of=/tmp/anykernel/boot.img;
/tmp/anykernel/tools/unmkbootimg /tmp/anykernel/boot.img;
#/tmp/anykernel/tools/unmkbootimg /tmp/anykernel/boot.img;
if [ $? != 0 ]; then
ui_print "Dumping/unpacking image failed. Aborting...";
echo "Unpack Failed" > /tmp/anykernel/exitcode; exit;
fi;
}

# repack ramdisk then build and write image
write_boot() {
/tmp/anykernel/tools/mkbootimg --kernel /tmp/anykernel/bzImage --ramdisk /tmp/anykernel/initramfs.cpio.gz --cmdline "init=/init pci=noearly loglevel=0 vmalloc=256M androidboot.hardware=mofd_v1 watchdog.watchdog_thresh=60 androidboot.spid=xxxx:xxxx:xxxx:xxxx:xxxx:xxxx androidboot.serialno=01234567890123456789 snd_pcm.maximum_substreams=8 ip=50.0.0.2:50.0.0.1::255.255.255.0::usb0:on debug_locks=0 bootboost=1 androidboot.selinux=permissive" --base 0x10000000 --pagesize 2048 --ramdisk_offset 0x01000000 --tags_offset 0x00000100 --second /tmp/anykernel/second.gz -o /tmp/anykernel/boot-new.img;

if [ $? != 0 -o `wc -c < /tmp/anykernel/boot-new.img` -gt `wc -c < /tmp/anykernel/boot.img` ]; then
ui_print "Repacking image failed. Aborting...";
echo "Repack Failed" > /tmp/anykernel/exitcode; exit;
fi;
if [ "$(getprop ro.product.device)" == "Z00A" ]; then
echo "Device : Z00A";
cat /tmp/anykernel/boot-new.img /tmp/anykernel/boot_z00a.sig > /tmp/anykernel/boot.img;
fi
if [ "$(getprop ro.product.device)" == "Z008" ]; then
echo "Device : Z008";
cat /tmp/anykernel/boot-new.img /tmp/anykernel/boot_z008.sig > /tmp/anykernel/boot.img;
fi
dd if=/tmp/anykernel/boot.img of=$block;
}

## end methods

## AnyKernel install
dump_boot;

write_boot;

## end install

Binary file added out/boot_z008.sig
Binary file not shown.
Binary file added out/boot_z00a.sig
Binary file not shown.
Empty file added out/modules/placeholder
Empty file.
Binary file added out/ramdisk/sbin/bb/busybox
Binary file not shown.
Binary file added out/tools/mkbootimg
Binary file not shown.
Binary file added out/tools/unmkbootimg
Binary file not shown.
Loading

0 comments on commit e19b6dd

Please sign in to comment.