├── .gitignore ├── META-INF └── com │ └── google │ └── android │ ├── update-binary │ └── updater-script ├── README.md ├── anykernel.sh ├── ramdisk ├── init.qcom.rc └── init.renderzenith.sh └── tools ├── ak2-core.sh ├── busybox ├── lz4 ├── mkbootimg ├── unpackbootimg └── xz /.gitignore: -------------------------------------------------------------------------------- 1 | zImage* 2 | -------------------------------------------------------------------------------- /META-INF/com/google/android/update-binary: -------------------------------------------------------------------------------- 1 | #!/sbin/sh 2 | # AnyKernel2 Backend (DO NOT CHANGE) 3 | # osm0sis @ xda-developers 4 | 5 | OUTFD=/proc/self/fd/$2; 6 | ZIPFILE="$3"; 7 | DIR=`dirname "$ZIPFILE"`; 8 | 9 | ui_print() { 10 | until [ ! "$1" ]; do 11 | echo -e "ui_print $1\nui_print" > $OUTFD; 12 | shift; 13 | done; 14 | } 15 | show_progress() { echo "progress $1 $2" > $OUTFD; } 16 | file_getprop() { $bb grep "^$2=" "$1" | $bb cut -d= -f2-; } 17 | cleanup() { 18 | cd /tmp; 19 | rm -rf /tmp/anykernel; 20 | } 21 | debugging() { 22 | case $(basename "$ZIPFILE" .zip) in 23 | *-debugging) 24 | ui_print " "; 25 | ui_print "Creating debugging archive in zip directory..."; 26 | $bb tar -czvf "$DIR/anykernel2-$(date +%Y-%m-%d_%H%M%S)-debug.tgz" /tmp/*; 27 | ;; 28 | esac; 29 | } 30 | is_mounted() { $bb mount | $bb grep " $1 "; } 31 | unmount_all() { 32 | (umount /system; 33 | if [ -d /system_root -a ! -f /system/build.prop ]; then 34 | umount /system_root; 35 | fi; 36 | umount /system; 37 | umount /vendor; 38 | umount /data) 2>/dev/null; 39 | } 40 | abort() { 41 | ui_print "$*"; 42 | debugging; 43 | if [ ! -f anykernel.sh -o "$(file_getprop anykernel.sh do.cleanuponabort 2>/dev/null)" == 1 ]; then 44 | cleanup; 45 | fi; 46 | unmount_all; 47 | exit 1; 48 | } 49 | 50 | show_progress 1.34 4; 51 | ui_print " "; 52 | cleanup; 53 | mkdir -p /tmp/anykernel/bin; 54 | cd /tmp/anykernel; 55 | unzip -o "$ZIPFILE"; 56 | if [ $? != 0 -o -z "$(ls tools)" ]; then 57 | abort "Unzip failed. Aborting..."; 58 | fi; 59 | bb=/tmp/anykernel/tools/busybox; 60 | chmod 755 $bb; 61 | $bb chmod -R 755 tools bin; 62 | 63 | if [ -f banner ]; then 64 | while IFS='' read -r line || $bb [[ -n "$line" ]]; do 65 | ui_print "$line"; 66 | done < banner; 67 | ui_print " "; 68 | ui_print " "; 69 | fi; 70 | 71 | ui_print "$(file_getprop anykernel.sh kernel.string)"; 72 | if [ -f version ]; then 73 | ui_print " "; 74 | while IFS='' read -r line || $bb [[ -n "$line" ]]; do 75 | ui_print "$line"; 76 | done < version; 77 | ui_print " "; 78 | fi; 79 | ui_print " "; 80 | ui_print "AnyKernel2 by osm0sis @ xda-developers"; 81 | ui_print " "; 82 | ui_print " "; 83 | 84 | unmount_all; 85 | if [ ! "$(is_mounted /system)" ]; then 86 | $bb mount -o ro -t auto /system; 87 | fi; 88 | ($bb mount -o ro -t auto /vendor; 89 | $bb mount /data) 2>/dev/null; 90 | if [ -f /system/system/build.prop ]; then 91 | umount /system; 92 | (umount /system; 93 | mkdir /system_root) 2>/dev/null; 94 | $bb mount -o ro -t auto /dev/block/bootdevice/by-name/system /system_root; 95 | $bb mount -o bind /system_root/system /system; 96 | fi; 97 | savedpath="$LD_LIBRARY_PATH"; 98 | savedpre="$LD_PRELOAD"; 99 | unset LD_LIBRARY_PATH; 100 | unset LD_PRELOAD; 101 | 102 | if [ ! "$(getprop 2>/dev/null)" ]; then 103 | getprop() { 104 | local propval="$(file_getprop /default.prop $1 2>/dev/null)"; 105 | test "$propval" || local propval="$(file_getprop /system/build.prop $1 2>/dev/null)"; 106 | test "$propval" && echo "$propval" || echo ""; 107 | } 108 | elif [ ! "$(getprop ro.product.device 2>/dev/null)" -a ! "$(getprop ro.build.product 2>/dev/null)" ]; then 109 | getprop() { 110 | ($(which getprop) | $bb grep "$1" | $bb cut -d[ -f3 | $bb cut -d] -f1) 2>/dev/null; 111 | } 112 | fi; 113 | 114 | if [ "$(file_getprop anykernel.sh do.devicecheck)" == 1 ]; then 115 | ui_print "Checking device..."; 116 | device="$(getprop ro.product.device)"; 117 | product="$(getprop ro.build.product)"; 118 | for testname in $(file_getprop anykernel.sh 'device.name.*'); do 119 | if [ "$device" == "$testname" -o "$product" == "$testname" ]; then 120 | ui_print "$testname"; 121 | match=1; 122 | break; 123 | fi; 124 | done; 125 | ui_print " "; 126 | if [ ! "$match" ]; then 127 | abort "Unsupported device. Aborting..."; 128 | fi; 129 | fi; 130 | 131 | int2float() { test "$1" -eq "$1" 2>/dev/null && $bb printf '%0.1f\n' "$1" || echo "$1"; } 132 | supported_ver="$(file_getprop anykernel.sh supported.versions | $bb tr -d '[:space:]')"; 133 | if [ "$supported_ver" ]; then 134 | ui_print "Checking Android version..."; 135 | android_ver="$(file_getprop /system/build.prop ro.build.version.release)"; 136 | if [ "$(echo $supported_ver | $bb grep -)" ]; then 137 | lo_ver=$(echo $supported_ver | $bb cut -d- -f1); 138 | hi_ver=$(echo $supported_ver | $bb cut -d- -f2); 139 | if [ "$(echo -e "$(int2float $hi_ver)\n$(int2float $lo_ver)\n$(int2float $android_ver)" | $bb sort -g | $bb grep -n "$(int2float $android_ver)" | $bb grep '^2:')" ]; then 140 | supported=1; 141 | fi; 142 | else 143 | for ver in $(echo $supported_ver | $bb sed 's;,; ;g'); do 144 | if [ "$(int2float $ver)" == "$(int2float $android_ver)" ]; then 145 | supported=1; 146 | break; 147 | fi; 148 | done; 149 | fi; 150 | if [ "$supported" ]; then 151 | ui_print "$android_ver"; 152 | ui_print " "; 153 | else 154 | ui_print " "; 155 | abort "Unsupported Android version. Aborting..."; 156 | fi; 157 | fi; 158 | 159 | ui_print "Installing..."; 160 | for i in $($bb --list); do 161 | $bb ln -s $bb bin/$i; 162 | done; 163 | if [ $? != 0 -o -z "$(ls bin)" ]; then 164 | abort "Recovery busybox setup failed. Aborting..."; 165 | fi; 166 | PATH="/tmp/anykernel/bin:$PATH" $bb ash anykernel.sh $2; 167 | if [ $? != 0 ]; then 168 | abort; 169 | fi; 170 | 171 | if [ "$(file_getprop anykernel.sh do.modules)" == 1 ]; then 172 | ui_print " "; 173 | ui_print "Pushing modules..."; 174 | $bb mount -o rw,remount -t auto /system; 175 | $bb mount -o rw,remount -t auto /vendor 2>/dev/null; 176 | cd /tmp/anykernel/modules; 177 | for module in $(find . -name '*.ko'); do 178 | modtarget=$(echo $module | $bb cut -c2-); 179 | if [ ! -e $modtarget ]; then 180 | case $module in 181 | */vendor/*) modcon=vendor;; 182 | *) modcon=system;; 183 | esac; 184 | fi; 185 | if [ "$(is_mounted $modtarget)" ]; then 186 | $bb mount -o rw,remount -t auto $modtarget; 187 | fi; 188 | mkdir -p $(dirname $modtarget); 189 | $bb cp -rLf $module $modtarget; 190 | $bb chown 0:0 $modtarget; 191 | $bb chmod 644 $modtarget; 192 | if [ "$modcon" ]; then 193 | chcon "u:object_r:${modcon}_file:s0" $modtarget; 194 | fi; 195 | if [ "$(is_mounted $modtarget)" ]; then 196 | $bb mount -o ro,remount -t auto $modtarget; 197 | fi; 198 | done; 199 | cd /tmp/anykernel; 200 | $bb mount -o ro,remount -t auto /system; 201 | $bb mount -o ro,remount -t auto /vendor 2>/dev/null; 202 | fi; 203 | 204 | debugging; 205 | 206 | if [ "$(file_getprop anykernel.sh do.cleanup)" == 1 ]; then 207 | cleanup; 208 | fi; 209 | 210 | test "$savedpath" && export LD_LIBRARY_PATH="$savedpath"; 211 | test "$savedpre" && export LD_PRELOAD="$savedpre"; 212 | 213 | unmount_all; 214 | 215 | ui_print " "; 216 | ui_print " "; 217 | ui_print "Done!"; 218 | -------------------------------------------------------------------------------- /META-INF/com/google/android/updater-script: -------------------------------------------------------------------------------- 1 | # Dummy file; update-binary is a shell script. 2 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ---------------------------------------------------------------------------------- 2 | AnyKernel2 - Flashable Zip Template for Kernel Releases with Ramdisk Modifications 3 | ---------------------------------------------------------------------------------- 4 | ### by osm0sis @ xda-developers ### 5 | 6 | "AnyKernel is a template for an update.zip that can apply any kernel to any ROM, regardless of ramdisk." - Koush 7 | 8 | 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. 9 | 10 | A working script based on DirtyV Kernel for Galaxy Nexus (tuna) is included for reference. 11 | 12 | ## // Properties / Variables ## 13 | ``` 14 | kernel.string=KernelName by YourName @ xda-developers 15 | do.devicecheck=1 16 | do.modules=1 17 | do.cleanup=1 18 | do.cleanuponabort=0 19 | device.name1=maguro 20 | device.name2=toro 21 | device.name3=toroplus 22 | supported.versions=6.0 - 7.1.2 23 | 24 | block=/dev/block/platform/omap/omap_hsmmc.0/by-name/boot; 25 | is_slot_device=0; 26 | ramdisk_compression=auto; 27 | ``` 28 | 29 | __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 as many device.name# properties as needed. You may remove any empty ones that aren't being used. 30 | 31 | __do.modules=1__ will push the contents of the module directory to the same location relative to root (/) and apply 644 permissions. 32 | 33 | __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. 34 | 35 | __do.cleanuponabort=0__ will keep the zip from removing it's working directory in /tmp/anykernel in case of installation abort. 36 | 37 | __supported.versions=__ will match against ro.build.version.release from the current ROM's build.prop. It can be set to a list or range. As a list, e.g. `7.1.2` or `8.1.0, 9` it will look for exact matches, as a range, e.g. `7.1.2 - 9` it will check to make sure the current version falls within those limits. Whitespace optional, and supplied version values should be in the same number format they are in the build.prop value for that Android version. 38 | 39 | `block=auto` instead of a direct block filepath enables detection of the device boot partition for use with broad, device non-specific zips. Also accepts specifically `boot` or `recovery`. 40 | 41 | `is_slot_device=1` enables detection of the suffix for the active boot partition on slot-based devices and will add this to the end of the supplied `block=` path. Also accepts `auto` for use with broad, device non-specific zips. 42 | 43 | `ramdisk_compression=auto` allows automatically repacking the ramdisk with the format detected during unpack, changing `auto` to `gz`, `lzo`, `lzma`, `xz`, `bz2`, `lz4`, or `lz4-l` (for lz4 legacy) instead forces the repack as that format. 44 | 45 | ## // Command Methods ## 46 | ``` 47 | dump_boot 48 | split_boot 49 | unpack_ramdisk 50 | backup_file 51 | restore_file 52 | replace_string 53 | replace_section 54 | remove_section 55 | insert_line 56 | replace_line 57 | remove_line 58 | prepend_file 59 | insert_file 60 | append_file 61 | replace_file 62 | patch_fstab 63 | patch_cmdline 64 | patch_prop 65 | patch_ueventd 66 | repack_ramdisk 67 | flash_boot 68 | write_boot 69 | reset_ak 70 | flash_dtbo 71 | ``` 72 | 73 | __"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. __"cmdline entry name"__ behaves somewhat like this as a match check for the name of the cmdline entry to be changed/added by the _patch_cmdline_ function, followed by the full entry to replace it. __"prop name"__ also serves as a match check in _patch_prop_ for a property in the given prop file, but is only the prop name as the prop value is specified separately. 74 | 75 | Similarly, __"line match string"__ and __"line replace string"__ are the search strings that locate where the modification needs to be made for those commands, __"begin search string"__ and __"end search string"__ are both required to select the first and last lines of the script block to be replaced for _replace_section_, and __"mount match name"__ and __"fs match type"__ are both required to narrow the _patch_fstab_ command down to the correct entry. 76 | 77 | __"scope"__ may be specified as __"global"__ to force all instances of the string targeted by _replace_string_ to be replaced. Omitted or set to anything else and it will perform the default first-match replacement. 78 | 79 | __"before|after"__ requires you simply specify __"before"__ or __"after"__ for the placement of the inserted line, in relation to __"line match string"__. 80 | 81 | __"block|mount|fstype|options|flags"__ requires you specify which part (listed in order) of the fstab entry you want to check and alter. 82 | 83 | _dump_boot_ and _write_boot_ are the default method of unpacking/repacking, but for more granular control, or omitting ramdisk changes entirely ("OG AK" mode), these can be separated into _split_boot; unpack_ramdisk_ and _repack_ramdisk; flash_boot_ respectively. _flash_dtbo_ can be used to flash a dtbo image. It is automatically included in _write_boot_ but can be called separately if using "OG AK" mode or creating a dtbo only zip. 84 | 85 | Multi-partition zips can be created by removing the ramdisk and patch folders from the zip and including instead "-files" folders named for the partition (without slot suffix), e.g. boot-files + recovery-files, or kernel-files + ramdisk-files (on some Treble devices). These then contain zImage, and ramdisk, patch, etc. subfolders for each partition. To setup for the next partition, simply set `block=` and `ramdisk_compression=` for the new target partition and use the _reset_ak_ command. 86 | 87 | _backup_file_ may be used for testing to ensure ramdisk changes are made correctly, transparency for the end-user, or in a ramdisk-only "mod" zip. In the latter case _restore_file_ could also be used to create a "restore" zip to undo the changes, but should be used with caution since the underlying patched files could be changed with ROM/kernel updates. 88 | 89 | You may also use _ui_print "\"_ to write messages back to the recovery during the modification process, and _file_getprop "\" "\"_ and _contains "\" "\"_ to simplify string testing logic you might want in your script. 90 | 91 | ## // Binary Inclusion ## 92 | 93 | The AK2 repo includes my latest static ARM builds of `mkbootimg`, `unpackbootimg`,`busybox`, `xz` and `lz4` by default to keep the basic package small. Builds for other architectures and optional binaries (see below) are available from my latest AIK-mobile and FlashIt packages, respectively, here: 94 | 95 | https://forum.xda-developers.com/showthread.php?t=2073775 (Android Image Kitchen thread) 96 | https://forum.xda-developers.com/showthread.php?t=2239421 (Odds and Ends thread) 97 | 98 | Optional supported binaries which may be placed in /tools to enable built-in expanded functionality are as follows: 99 | * `mkbootfs` - for broken recoveries, or, booted flash support for a script/app via bind mount to /tmp (deprecated/use with caution) 100 | * `flash_erase`, `nanddump`, `nandwrite` - MTD block device support for devices where the `dd` command is not sufficient 101 | * `pxa-unpackbootimg`, `pxa-mkbootimg` - Samsung/Marvell PXA1088/PXA1908 boot.img format variant support 102 | * `dumpimage`, `mkimage` - DENX U-Boot uImage format support 103 | * `unpackelf` - Sony ELF kernel.elf format support, repacking as AOSP standard boot.img for unlocked bootloaders 104 | * `elftool`, `unpackelf` - Sony ELF kernel.elf format support, repacking as ELF for older Sony devices 105 | * `mkmtkhdr` - MTK device boot image section headers support 106 | * `futility` + `chromeos` test keys directory - Google ChromeOS signature support 107 | * `BootSignature_Android.jar` + `avb` keys directory - Google Android Verified Boot (AVB) signature support 108 | * `blobpack` - Asus SignBlob signature support 109 | * `dhtbsign` - Samsung/Spreadtrum DHTB signature support 110 | * `rkcrc` - Rockchip KRNL ramdisk image support 111 | 112 | ## // Instructions ## 113 | 114 | 1. Place zImage in the root (dtb and/or dtbo should also go here for devices that require custom ones, each will fallback to the original if not included) 115 | 116 | 2. Place any required ramdisk files in /ramdisk and modules in /modules (with the full path like /modules/system/lib/modules) 117 | 118 | 3. Place any required patch files (generally partial files which go with commands) in /patch 119 | 120 | 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 (optionally, also place banner and/or version files in the root to have these displayed during flash) 121 | 122 | 5. `zip -r9 UPDATE-AnyKernel2.zip * -x .git README.md *placeholder` 123 | 124 | If supporting a recovery that forces zip signature verification (like Cyanogen Recovery) then you will need to also sign your zip using the method I describe here: 125 | 126 | http://forum.xda-developers.com/android/software-hacking/dev-complete-shell-script-flashable-zip-t2934449 127 | 128 | Not required, but any tweaks you can't hardcode into the source (best practice) should be added with an additional init.tweaks.rc or bootscript.sh to minimize the necessary ramdisk changes. 129 | 130 | It is also extremely important to note that for the broadest AK2 compatibility it is always better to modify a ramdisk file rather than replace it. 131 | 132 | If running into trouble when flashing an AK2 zip, the suffix -debugging may be added to the zip's filename to enable creation of a debug .tgz of /tmp for later examination while booted or on desktop. 133 | 134 | For further support and usage examples please see the AnyKernel2 XDA thread: https://forum.xda-developers.com/showthread.php?t=2670512 135 | 136 | Have fun! 137 | -------------------------------------------------------------------------------- /anykernel.sh: -------------------------------------------------------------------------------- 1 | # AnyKernel2 Ramdisk Mod Script 2 | # osm0sis @ xda-developers 3 | 4 | ## AnyKernel setup 5 | # begin properties 6 | properties() { ' 7 | kernel.string=RenderZenith by RenderBroken and joshuous 8 | do.devicecheck=1 9 | do.modules=0 10 | do.cleanup=1 11 | do.cleanuponabort=0 12 | device.name1=OnePlus5T 13 | device.name2=dumpling 14 | device.name3=OnePlus5 15 | device.name4=cheeseburger 16 | device.name5= 17 | supported.versions=9 18 | '; } # end properties 19 | 20 | # shell variables 21 | block=/dev/block/bootdevice/by-name/boot 22 | is_slot_device=0; 23 | ramdisk_compression=auto; 24 | 25 | 26 | ## AnyKernel methods (DO NOT CHANGE) 27 | # import patching functions/variables - see for reference 28 | . /tmp/anykernel/tools/ak2-core.sh; 29 | 30 | 31 | ## AnyKernel file attributes 32 | # set permissions/ownership for included ramdisk files 33 | chmod -R 750 $ramdisk/*; 34 | chown -R root:root $ramdisk/*; 35 | 36 | 37 | ## AnyKernel install 38 | dump_boot; 39 | 40 | # begin ramdisk changes 41 | 42 | # Remove recovery service so that TWRP isn't overwritten 43 | remove_section init.rc "service flash_recovery" "" 44 | 45 | # end ramdisk changes 46 | 47 | write_boot; 48 | 49 | ## end install 50 | 51 | -------------------------------------------------------------------------------- /ramdisk/init.qcom.rc: -------------------------------------------------------------------------------- 1 | on property:vendor.post_boot.parsed=1 2 | exec u:r:magisk:s0 root root -- /init.renderzenith.sh 3 | -------------------------------------------------------------------------------- /ramdisk/init.renderzenith.sh: -------------------------------------------------------------------------------- 1 | #!/system/bin/sh 2 | 3 | # Schedutil config 4 | echo "schedutil" > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor 5 | echo "schedutil" > /sys/devices/system/cpu/cpu4/cpufreq/scaling_governor 6 | 7 | # SchedTune 8 | echo "1" > /dev/stune/foreground/schedtune.prefer_idle 9 | echo "1" > /dev/stune/top-app/schedtune.prefer_idle 10 | echo "0" > /dev/stune/top-app/schedtune.boost 11 | echo "1" > /dev/stune/top-app/schedtune.sched_boost 12 | 13 | # cpuset 14 | echo "0-3,6-7" > /dev/cpuset/foreground/cpus 15 | echo "0-3" > /dev/cpuset/restricted/cpus 16 | -------------------------------------------------------------------------------- /tools/ak2-core.sh: -------------------------------------------------------------------------------- 1 | ## AnyKernel methods (DO NOT CHANGE) 2 | # osm0sis @ xda-developers 3 | 4 | # set up extracted files and directories 5 | ramdisk=/tmp/anykernel/ramdisk; 6 | bin=/tmp/anykernel/tools; 7 | split_img=/tmp/anykernel/split_img; 8 | patch=/tmp/anykernel/patch; 9 | 10 | chmod -R 755 $bin; 11 | mkdir -p $split_img; 12 | 13 | FD=$1; 14 | OUTFD=/proc/self/fd/$FD; 15 | 16 | # ui_print 17 | ui_print() { echo -e "ui_print $1\nui_print" > $OUTFD; } 18 | 19 | # contains 20 | contains() { test "${1#*$2}" != "$1" && return 0 || return 1; } 21 | 22 | # file_getprop 23 | file_getprop() { grep "^$2=" "$1" | cut -d= -f2-; } 24 | 25 | # reset anykernel directory 26 | reset_ak() { 27 | local i; 28 | rm -rf $(dirname /tmp/anykernel/*-files/current)/ramdisk; 29 | for i in $ramdisk $split_img /tmp/anykernel/rdtmp /tmp/anykernel/boot.img /tmp/anykernel/*-new*; do 30 | cp -af $i $(dirname /tmp/anykernel/*-files/current); 31 | done; 32 | rm -rf $ramdisk $split_img $patch /tmp/anykernel/rdtmp /tmp/anykernel/boot.img /tmp/anykernel/*-new* /tmp/anykernel/*-files/current; 33 | . /tmp/anykernel/tools/ak2-core.sh $FD; 34 | } 35 | 36 | # dump boot and extract ramdisk 37 | split_boot() { 38 | local nooktest nookoff dumpfail; 39 | if [ ! -e "$(echo $block | cut -d\ -f1)" ]; then 40 | ui_print " "; ui_print "Invalid partition. Aborting..."; exit 1; 41 | fi; 42 | if [ -f "$bin/nanddump" ]; then 43 | $bin/nanddump -f /tmp/anykernel/boot.img $block; 44 | else 45 | dd if=$block of=/tmp/anykernel/boot.img; 46 | fi; 47 | nooktest=$(strings /tmp/anykernel/boot.img | grep -E 'Red Loader|Green Loader|Green Recovery|eMMC boot.img|eMMC recovery.img|BauwksBoot'); 48 | if [ "$nooktest" ]; then 49 | case $nooktest in 50 | *BauwksBoot*) nookoff=262144;; 51 | *) nookoff=1048576;; 52 | esac; 53 | mv -f /tmp/anykernel/boot.img /tmp/anykernel/boot-orig.img; 54 | dd bs=$nookoff count=1 conv=notrunc if=/tmp/anykernel/boot-orig.img of=$split_img/boot.img-master_boot.key; 55 | dd bs=$nookoff skip=1 conv=notrunc if=/tmp/anykernel/boot-orig.img of=/tmp/anykernel/boot.img; 56 | fi; 57 | if [ -f "$bin/unpackelf" -a "$($bin/unpackelf -i /tmp/anykernel/boot.img -h -q 2>/dev/null; echo $?)" == 0 ]; then 58 | if [ -f "$bin/elftool" ]; then 59 | mkdir $split_img/elftool_out; 60 | $bin/elftool unpack -i /tmp/anykernel/boot.img -o $split_img/elftool_out; 61 | cp -f $split_img/elftool_out/header $split_img/boot.img-header; 62 | fi; 63 | $bin/unpackelf -i /tmp/anykernel/boot.img -o $split_img; 64 | mv -f $split_img/boot.img-ramdisk.cpio.gz $split_img/boot.img-ramdisk.gz; 65 | elif [ -f "$bin/dumpimage" ]; then 66 | $bin/dumpimage -l /tmp/anykernel/boot.img; 67 | $bin/dumpimage -l /tmp/anykernel/boot.img > $split_img/boot.img-header; 68 | grep "Name:" $split_img/boot.img-header | cut -c15- > $split_img/boot.img-name; 69 | grep "Type:" $split_img/boot.img-header | cut -c15- | cut -d\ -f1 > $split_img/boot.img-arch; 70 | grep "Type:" $split_img/boot.img-header | cut -c15- | cut -d\ -f2 > $split_img/boot.img-os; 71 | grep "Type:" $split_img/boot.img-header | cut -c15- | cut -d\ -f3 | cut -d- -f1 > $split_img/boot.img-type; 72 | grep "Type:" $split_img/boot.img-header | cut -d\( -f2 | cut -d\) -f1 | cut -d\ -f1 | cut -d- -f1 > $split_img/boot.img-comp; 73 | grep "Address:" $split_img/boot.img-header | cut -c15- > $split_img/boot.img-addr; 74 | grep "Point:" $split_img/boot.img-header | cut -c15- > $split_img/boot.img-ep; 75 | $bin/dumpimage -i /tmp/anykernel/boot.img -p 0 $split_img/boot.img-zImage; 76 | test $? != 0 && dumpfail=1; 77 | if [ "$(cat $split_img/boot.img-type)" == "Multi" ]; then 78 | $bin/dumpimage -i /tmp/anykernel/boot.img -p 1 $split_img/boot.img-ramdisk.gz; 79 | fi; 80 | test $? != 0 && dumpfail=1; 81 | elif [ -f "$bin/rkcrc" ]; then 82 | dd bs=4096 skip=8 iflag=skip_bytes conv=notrunc if=/tmp/anykernel/boot.img of=$split_img/boot.img-ramdisk.gz; 83 | elif [ -f "$bin/pxa-unpackbootimg" ]; then 84 | $bin/pxa-unpackbootimg -i /tmp/anykernel/boot.img -o $split_img; 85 | else 86 | $bin/unpackbootimg -i /tmp/anykernel/boot.img -o $split_img; 87 | fi; 88 | if [ $? != 0 -o "$dumpfail" ]; then 89 | ui_print " "; ui_print "Dumping/splitting image failed. Aborting..."; exit 1; 90 | fi; 91 | if [ -f "$bin/unpackelf" -a -f "$split_img/boot.img-dtb" ]; then 92 | case $(od -ta -An -N4 $split_img/boot.img-dtb | sed -e 's/del //' -e 's/ //g') in 93 | QCDT|ELF) ;; 94 | *) gzip $split_img/boot.img-zImage; 95 | mv -f $split_img/boot.img-zImage.gz $split_img/boot.img-zImage; 96 | cat $split_img/boot.img-dtb >> $split_img/boot.img-zImage; 97 | rm -f $split_img/boot.img-dtb;; 98 | esac; 99 | fi; 100 | } 101 | unpack_ramdisk() { 102 | local compext unpackcmd; 103 | if [ -f "$bin/mkmtkhdr" ]; then 104 | dd bs=512 skip=1 conv=notrunc if=$split_img/boot.img-ramdisk.gz of=$split_img/temprd; 105 | mv -f $split_img/temprd $split_img/boot.img-ramdisk.gz; 106 | fi; 107 | mv -f $ramdisk /tmp/anykernel/rdtmp; 108 | case $(od -ta -An -N4 $split_img/boot.img-ramdisk.gz) in 109 | ' us vt'*|' us rs'*) compext="gz"; unpackcmd="gzip";; 110 | ' ht L Z O') compext="lzo"; unpackcmd="lzop";; 111 | ' ] nul nul nul') compext="lzma"; unpackcmd="$bin/xz";; 112 | ' } 7 z X') compext="xz"; unpackcmd="$bin/xz";; 113 | ' B Z h'*) compext="bz2"; unpackcmd="bzip2";; 114 | ' stx ! L can') compext="lz4-l"; unpackcmd="$bin/lz4";; 115 | ' etx ! L can'|' eot " M can') compext="lz4"; unpackcmd="$bin/lz4";; 116 | *) ui_print " "; ui_print "Unknown ramdisk compression. Aborting..."; exit 1;; 117 | esac; 118 | mv -f $split_img/boot.img-ramdisk.gz $split_img/boot.img-ramdisk.cpio.$compext; 119 | mkdir -p $ramdisk; 120 | chmod 755 $ramdisk; 121 | cd $ramdisk; 122 | $unpackcmd -dc $split_img/boot.img-ramdisk.cpio.$compext | EXTRACT_UNSAFE_SYMLINKS=1 cpio -i -d; 123 | if [ $? != 0 -o -z "$(ls $ramdisk)" ]; then 124 | ui_print " "; ui_print "Unpacking ramdisk failed. Aborting..."; exit 1; 125 | fi; 126 | test ! -z "$(ls /tmp/anykernel/rdtmp)" && cp -af /tmp/anykernel/rdtmp/* $ramdisk; 127 | } 128 | dump_boot() { 129 | split_boot; 130 | unpack_ramdisk; 131 | } 132 | 133 | # repack ramdisk then build and write image 134 | repack_ramdisk() { 135 | local compext repackcmd; 136 | case $ramdisk_compression in 137 | auto|"") compext=`echo $split_img/*-ramdisk.cpio.* | rev | cut -d. -f1 | rev`;; 138 | *) compext=$ramdisk_compression;; 139 | esac; 140 | case $compext in 141 | gz) repackcmd="gzip";; 142 | lzo) repackcmd="lzo";; 143 | lzma) repackcmd="$bin/xz -Flzma";; 144 | xz) repackcmd="$bin/xz -Ccrc32";; 145 | bz2) repackcmd="bzip2";; 146 | lz4-l) repackcmd="$bin/lz4 -l";; 147 | lz4) repackcmd="$bin/lz4";; 148 | esac; 149 | if [ -f "$bin/mkbootfs" ]; then 150 | $bin/mkbootfs $ramdisk | $repackcmd -9c > /tmp/anykernel/ramdisk-new.cpio.$compext; 151 | else 152 | cd $ramdisk; 153 | find . | cpio -H newc -o | $repackcmd -9c > /tmp/anykernel/ramdisk-new.cpio.$compext; 154 | fi; 155 | if [ $? != 0 ]; then 156 | ui_print " "; ui_print "Repacking ramdisk failed. Aborting..."; exit 1; 157 | fi; 158 | cd /tmp/anykernel; 159 | if [ -f "$bin/mkmtkhdr" ]; then 160 | $bin/mkmtkhdr --rootfs ramdisk-new.cpio.$compext; 161 | mv -f ramdisk-new.cpio.$compext-mtk ramdisk-new.cpio.$compext; 162 | fi; 163 | } 164 | flash_dtbo() { 165 | for i in dtbo dtbo.img; do 166 | if [ -f /tmp/anykernel/$i ]; then 167 | dtbo=$i; 168 | break; 169 | fi; 170 | done; 171 | if [ "$dtbo" ]; then 172 | dtbo_block=/dev/block/bootdevice/by-name/dtbo$slot; 173 | if [ ! -e "$(echo $dtbo_block)" ]; then 174 | ui_print " "; ui_print "dtbo partition could not be found. Aborting..."; exit 1; 175 | fi; 176 | if [ -f "$bin/flash_erase" -a -f "$bin/nandwrite" ]; then 177 | $bin/flash_erase $dtbo_block 0 0; 178 | $bin/nandwrite -p $dtbo_block /tmp/anykernel/$dtbo; 179 | else 180 | dd if=/dev/zero of=$dtbo_block 2>/dev/null; 181 | dd if=/tmp/anykernel/$dtbo of=$dtbo_block; 182 | fi; 183 | fi; 184 | } 185 | flash_boot() { 186 | local name arch os type comp addr ep cmdline cmd board base pagesize kerneloff ramdiskoff tagsoff osver oslvl second secondoff hash unknown i kernel rd dtb rpm pk8 cert avbtype dtbo dtbo_block; 187 | cd $split_img; 188 | if [ -f "$bin/mkimage" ]; then 189 | name=`cat *-name`; 190 | arch=`cat *-arch`; 191 | os=`cat *-os`; 192 | type=`cat *-type`; 193 | comp=`cat *-comp`; 194 | test "$comp" == "uncompressed" && comp=none; 195 | addr=`cat *-addr`; 196 | ep=`cat *-ep`; 197 | else 198 | if [ -f *-cmdline ]; then 199 | cmdline=`cat *-cmdline`; 200 | cmd="$split_img/boot.img-cmdline@cmdline"; 201 | fi; 202 | if [ -f *-board ]; then 203 | board=`cat *-board`; 204 | fi; 205 | base=`cat *-base`; 206 | pagesize=`cat *-pagesize`; 207 | kerneloff=`cat *-kerneloff`; 208 | ramdiskoff=`cat *-ramdiskoff`; 209 | if [ -f *-tagsoff ]; then 210 | tagsoff=`cat *-tagsoff`; 211 | fi; 212 | if [ -f *-osversion ]; then 213 | osver=`cat *-osversion`; 214 | fi; 215 | if [ -f *-oslevel ]; then 216 | oslvl=`cat *-oslevel`; 217 | fi; 218 | if [ -f *-headerversion ]; then 219 | hdrver=`cat *-headerversion`; 220 | fi; 221 | if [ -f *-second ]; then 222 | second=`ls *-second`; 223 | second="--second $split_img/$second"; 224 | secondoff=`cat *-secondoff`; 225 | secondoff="--second_offset $secondoff"; 226 | fi; 227 | if [ -f *-recoverydtbo ]; then 228 | recoverydtbo=`ls *-recoverydtbo`; 229 | recoverydtbo="--recovery_dtbo $split_img/$recoverydtbo"; 230 | fi; 231 | if [ -f *-hash ]; then 232 | hash=`cat *-hash`; 233 | test "$hash" == "unknown" && hash=sha1; 234 | hash="--hash $hash"; 235 | fi; 236 | if [ -f *-unknown ]; then 237 | unknown=`cat *-unknown`; 238 | fi; 239 | fi; 240 | for i in zImage zImage-dtb Image.gz Image Image-dtb Image.gz-dtb Image.bz2 Image.bz2-dtb Image.lzo Image.lzo-dtb Image.lzma Image.lzma-dtb Image.xz Image.xz-dtb Image.lz4 Image.lz4-dtb Image.fit; do 241 | if [ -f /tmp/anykernel/$i ]; then 242 | kernel=/tmp/anykernel/$i; 243 | break; 244 | fi; 245 | done; 246 | if [ ! "$kernel" ]; then 247 | kernel=`ls *-zImage`; 248 | kernel=$split_img/$kernel; 249 | fi; 250 | if [ -f /tmp/anykernel/ramdisk-new.cpio.* ]; then 251 | rd=`echo /tmp/anykernel/ramdisk-new.cpio.*`; 252 | else 253 | rd=`ls *-ramdisk.*`; 254 | rd="$split_img/$rd"; 255 | fi; 256 | for i in dtb dt.img; do 257 | if [ -f /tmp/anykernel/$i ]; then 258 | dtb="--dt /tmp/anykernel/$i"; 259 | rpm="/tmp/anykernel/$i,rpm"; 260 | break; 261 | fi; 262 | done; 263 | if [ ! "$dtb" -a -f *-dtb ]; then 264 | dtb=`ls *-dtb`; 265 | rpm="$split_img/$dtb,rpm"; 266 | dtb="--dt $split_img/$dtb"; 267 | fi; 268 | cd /tmp/anykernel; 269 | if [ -f "$bin/mkmtkhdr" ]; then 270 | case $kernel in 271 | $split_img/*) ;; 272 | *) $bin/mkmtkhdr --kernel $kernel; kernel=$kernel-mtk;; 273 | esac; 274 | fi; 275 | if [ -f "$bin/mkimage" ]; then 276 | test "$type" == "Multi" && uramdisk=":$rd"; 277 | $bin/mkimage -A $arch -O $os -T $type -C $comp -a $addr -e $ep -n "$name" -d $kernel$uramdisk boot-new.img; 278 | elif [ -f "$bin/elftool" ]; then 279 | $bin/elftool pack -o boot-new.img header=$split_img/boot.img-header $kernel $rd,ramdisk $rpm $cmd; 280 | elif [ -f "$bin/rkcrc" ]; then 281 | $bin/rkcrc -k $rd boot-new.img; 282 | elif [ -f "$bin/pxa-mkbootimg" ]; then 283 | $bin/pxa-mkbootimg --kernel $kernel --ramdisk $rd $second --cmdline "$cmdline" --board "$board" --base $base --pagesize $pagesize --kernel_offset $kerneloff --ramdisk_offset $ramdiskoff $secondoff --tags_offset "$tagsoff" --unknown $unknown $dtb --output boot-new.img; 284 | else 285 | $bin/mkbootimg --kernel $kernel --ramdisk $rd $second $recoverydtbo --cmdline "$cmdline" --board "$board" --base $base --pagesize $pagesize --kernel_offset $kerneloff --ramdisk_offset $ramdiskoff $secondoff --tags_offset "$tagsoff" --os_version "$osver" --os_patch_level "$oslvl" --header_version "$hdrver" $hash $dtb --output boot-new.img; 286 | fi; 287 | if [ $? != 0 ]; then 288 | ui_print " "; ui_print "Repacking image failed. Aborting..."; exit 1; 289 | fi; 290 | if [ -f "$bin/futility" -a -d "$bin/chromeos" ]; then 291 | $bin/futility vbutil_kernel --pack boot-new-signed.img --keyblock $bin/chromeos/kernel.keyblock --signprivate $bin/chromeos/kernel_data_key.vbprivk --version 1 --vmlinuz boot-new.img --bootloader $bin/chromeos/empty --config $bin/chromeos/empty --arch arm --flags 0x1; 292 | if [ $? != 0 ]; then 293 | ui_print " "; ui_print "Signing image failed. Aborting..."; exit 1; 294 | fi; 295 | mv -f boot-new-signed.img boot-new.img; 296 | fi; 297 | if [ -f "$bin/BootSignature_Android.jar" -a -d "$bin/avb" ]; then 298 | pk8=`ls $bin/avb/*.pk8`; 299 | cert=`ls $bin/avb/*.x509.*`; 300 | case $block in 301 | *recovery*|*SOS*) avbtype=recovery;; 302 | *) avbtype=boot;; 303 | esac; 304 | if [ "$(/system/bin/dalvikvm -Xbootclasspath:/system/framework/core-oj.jar:/system/framework/core-libart.jar:/system/framework/conscrypt.jar:/system/framework/bouncycastle.jar -Xnodex2oat -Xnoimage-dex2oat -cp $bin/BootSignature_Android.jar com.android.verity.BootSignature -verify boot.img 2>&1 | grep VALID)" ]; then 305 | /system/bin/dalvikvm -Xbootclasspath:/system/framework/core-oj.jar:/system/framework/core-libart.jar:/system/framework/conscrypt.jar:/system/framework/bouncycastle.jar -Xnodex2oat -Xnoimage-dex2oat -cp $bin/BootSignature_Android.jar com.android.verity.BootSignature /$avbtype boot-new.img $pk8 $cert boot-new-signed.img; 306 | if [ $? != 0 ]; then 307 | ui_print " "; ui_print "Signing image failed. Aborting..."; exit 1; 308 | fi; 309 | fi; 310 | mv -f boot-new-signed.img boot-new.img; 311 | fi; 312 | if [ -f "$bin/blobpack" ]; then 313 | printf '-SIGNED-BY-SIGNBLOB-\00\00\00\00\00\00\00\00' > boot-new-signed.img; 314 | $bin/blobpack tempblob LNX boot-new.img; 315 | cat tempblob >> boot-new-signed.img; 316 | mv -f boot-new-signed.img boot-new.img; 317 | fi; 318 | if [ -f "/data/custom_boot_image_patch.sh" ]; then 319 | ash /data/custom_boot_image_patch.sh /tmp/anykernel/boot-new.img; 320 | if [ $? != 0 ]; then 321 | ui_print " "; ui_print "User script execution failed. Aborting..."; exit 1; 322 | fi; 323 | fi; 324 | if [ "$(strings /tmp/anykernel/boot.img | grep SEANDROIDENFORCE )" ]; then 325 | printf 'SEANDROIDENFORCE' >> boot-new.img; 326 | fi; 327 | if [ -f "$bin/dhtbsign" ]; then 328 | $bin/dhtbsign -i boot-new.img -o boot-new-signed.img; 329 | mv -f boot-new-signed.img boot-new.img; 330 | fi; 331 | if [ -f "$split_img/boot.img-master_boot.key" ]; then 332 | cat $split_img/boot.img-master_boot.key boot-new.img > boot-new-signed.img; 333 | mv -f boot-new-signed.img boot-new.img; 334 | fi; 335 | if [ ! -f /tmp/anykernel/boot-new.img ]; then 336 | ui_print " "; ui_print "Repacked image could not be found. Aborting..."; exit 1; 337 | elif [ "$(wc -c < boot-new.img)" -gt "$(wc -c < boot.img)" ]; then 338 | ui_print " "; ui_print "New image larger than boot partition. Aborting..."; exit 1; 339 | fi; 340 | if [ -f "$bin/flash_erase" -a -f "$bin/nandwrite" ]; then 341 | $bin/flash_erase $block 0 0; 342 | $bin/nandwrite -p $block /tmp/anykernel/boot-new.img; 343 | else 344 | dd if=/dev/zero of=$block 2>/dev/null; 345 | dd if=/tmp/anykernel/boot-new.img of=$block; 346 | fi; 347 | } 348 | write_boot() { 349 | repack_ramdisk; 350 | flash_boot; 351 | flash_dtbo; 352 | } 353 | 354 | # backup_file 355 | backup_file() { test ! -f $1~ && cp $1 $1~; } 356 | 357 | # restore_file 358 | restore_file() { test -f $1~ && mv -f $1~ $1; } 359 | 360 | # replace_string 361 | replace_string() { 362 | test "$5" == "global" && local scope=g; 363 | if [ -z "$(grep "$2" $1)" ]; then 364 | sed -i "s;${3};${4};${scope}" $1; 365 | fi; 366 | } 367 | 368 | # replace_section 369 | replace_section() { 370 | local begin endstr last end; 371 | begin=`grep -n "$2" $1 | head -n1 | cut -d: -f1`; 372 | if [ "$begin" ]; then 373 | if [ "$3" == " " -o -z "$3" ]; then 374 | endstr='^[[:space:]]*$'; 375 | last=$(wc -l $1 | cut -d\ -f1); 376 | else 377 | endstr="$3"; 378 | fi; 379 | for end in $(grep -n "$endstr" $1 | cut -d: -f1) $last; do 380 | if [ "$end" ] && [ "$begin" -lt "$end" ]; then 381 | sed -i "${begin},${end}d" $1; 382 | test "$end" == "$last" && echo >> $1; 383 | sed -i "${begin}s;^;${4}\n;" $1; 384 | break; 385 | fi; 386 | done; 387 | fi; 388 | } 389 | 390 | # remove_section 391 | remove_section() { 392 | local begin endstr last end; 393 | begin=`grep -n "$2" $1 | head -n1 | cut -d: -f1`; 394 | if [ "$begin" ]; then 395 | if [ "$3" == " " -o -z "$3" ]; then 396 | endstr='^[[:space:]]*$'; 397 | last=$(wc -l $1 | cut -d\ -f1); 398 | else 399 | endstr="$3"; 400 | fi; 401 | for end in $(grep -n "$endstr" $1 | cut -d: -f1) $last; do 402 | if [ "$end" ] && [ "$begin" -lt "$end" ]; then 403 | sed -i "${begin},${end}d" $1; 404 | break; 405 | fi; 406 | done; 407 | fi; 408 | } 409 | 410 | # insert_line 411 | insert_line() { 412 | local offset line; 413 | if [ -z "$(grep "$2" $1)" ]; then 414 | case $3 in 415 | before) offset=0;; 416 | after) offset=1;; 417 | esac; 418 | line=$((`grep -n "$4" $1 | head -n1 | cut -d: -f1` + offset)); 419 | if [ -f $1 -a "$line" ] && [ "$(wc -l $1 | cut -d\ -f1)" -lt "$line" ]; then 420 | echo "$5" >> $1; 421 | else 422 | sed -i "${line}s;^;${5}\n;" $1; 423 | fi; 424 | fi; 425 | } 426 | 427 | # replace_line 428 | replace_line() { 429 | if [ ! -z "$(grep "$2" $1)" ]; then 430 | local line=`grep -n "$2" $1 | head -n1 | cut -d: -f1`; 431 | sed -i "${line}s;.*;${3};" $1; 432 | fi; 433 | } 434 | 435 | # remove_line 436 | remove_line() { 437 | if [ ! -z "$(grep "$2" $1)" ]; then 438 | local line=`grep -n "$2" $1 | head -n1 | cut -d: -f1`; 439 | sed -i "${line}d" $1; 440 | fi; 441 | } 442 | 443 | # prepend_file 444 | prepend_file() { 445 | if [ -z "$(grep "$2" $1)" ]; then 446 | echo "$(cat $patch/$3 $1)" > $1; 447 | fi; 448 | } 449 | 450 | # insert_file 451 | insert_file() { 452 | local offset line; 453 | if [ -z "$(grep "$2" $1)" ]; then 454 | case $3 in 455 | before) offset=0;; 456 | after) offset=1;; 457 | esac; 458 | line=$((`grep -n "$4" $1 | head -n1 | cut -d: -f1` + offset)); 459 | sed -i "${line}s;^;\n;" $1; 460 | sed -i "$((line - 1))r $patch/$5" $1; 461 | fi; 462 | } 463 | 464 | # append_file 465 | append_file() { 466 | if [ -z "$(grep "$2" $1)" ]; then 467 | echo -ne "\n" >> $1; 468 | cat $patch/$3 >> $1; 469 | echo -ne "\n" >> $1; 470 | fi; 471 | } 472 | 473 | # replace_file 474 | replace_file() { 475 | cp -pf $patch/$3 $1; 476 | chmod $2 $1; 477 | } 478 | 479 | # patch_fstab 480 | patch_fstab() { 481 | local entry part newpart newentry; 482 | entry=$(grep "$2" $1 | grep "$3"); 483 | if [ -z "$(echo "$entry" | grep "$6")" -o "$6" == " " -o -z "$6" ]; then 484 | case $4 in 485 | block) part=$(echo "$entry" | awk '{ print $1 }');; 486 | mount) part=$(echo "$entry" | awk '{ print $2 }');; 487 | fstype) part=$(echo "$entry" | awk '{ print $3 }');; 488 | options) part=$(echo "$entry" | awk '{ print $4 }');; 489 | flags) part=$(echo "$entry" | awk '{ print $5 }');; 490 | esac; 491 | newpart=$(echo "$part" | sed -e "s;${5};${6};" -e "s; ;;g" -e 's;,\{2,\};,;g' -e 's;,*$;;g' -e 's;^,;;g'); 492 | newentry=$(echo "$entry" | sed "s;${part};${newpart};"); 493 | sed -i "s;${entry};${newentry};" $1; 494 | fi; 495 | } 496 | 497 | # patch_cmdline 498 | patch_cmdline() { 499 | local cmdfile cmdtmp match; 500 | cmdfile=`ls $split_img/*-cmdline`; 501 | if [ -z "$(grep "$1" $cmdfile)" ]; then 502 | cmdtmp=`cat $cmdfile`; 503 | echo "$cmdtmp $2" > $cmdfile; 504 | sed -i -e 's; *; ;g' -e 's;[ \t]*$;;' $cmdfile; 505 | else 506 | match=$(grep -o "$1.*$" $cmdfile | cut -d\ -f1); 507 | sed -i -e "s;${match};${2};" -e 's; *; ;g' -e 's;[ \t]*$;;' $cmdfile; 508 | fi; 509 | } 510 | 511 | # patch_prop 512 | patch_prop() { 513 | if [ -z "$(grep "^$2=" $1)" ]; then 514 | echo -ne "\n$2=$3\n" >> $1; 515 | else 516 | local line=`grep -n "^$2=" $1 | head -n1 | cut -d: -f1`; 517 | sed -i "${line}s;.*;${2}=${3};" $1; 518 | fi; 519 | } 520 | 521 | # patch_ueventd 522 | patch_ueventd() { 523 | local file dev perm user group newentry line; 524 | file=$1; dev=$2; perm=$3; user=$4; 525 | shift 4; 526 | group="$@"; 527 | newentry=$(printf "%-23s %-4s %-8s %s\n" "$dev" "$perm" "$user" "$group"); 528 | line=`grep -n "$dev" $file | head -n1 | cut -d: -f1`; 529 | if [ "$line" ]; then 530 | sed -i "${line}s;.*;${newentry};" $file; 531 | else 532 | echo -ne "\n$newentry\n" >> $file; 533 | fi; 534 | } 535 | 536 | # allow multi-partition ramdisk modifying configurations (using reset_ak) 537 | if [ ! -d "$ramdisk" -a ! -d "$patch" ]; then 538 | if [ -d "$(basename $block)-files" ]; then 539 | cp -af /tmp/anykernel/$(basename $block)-files/* /tmp/anykernel; 540 | else 541 | mkdir -p /tmp/anykernel/$(basename $block)-files; 542 | fi; 543 | touch /tmp/anykernel/$(basename $block)-files/current; 544 | fi; 545 | test ! -d "$ramdisk" && mkdir -p $ramdisk; 546 | 547 | # slot detection enabled by is_slot_device=1 or auto (from anykernel.sh) 548 | case $is_slot_device in 549 | 1|auto) 550 | slot=$(getprop ro.boot.slot_suffix 2>/dev/null); 551 | test ! "$slot" && slot=$(grep -o 'androidboot.slot_suffix=.*$' /proc/cmdline | cut -d\ -f1 | cut -d= -f2); 552 | if [ ! "$slot" ]; then 553 | slot=$(getprop ro.boot.slot 2>/dev/null); 554 | test ! "$slot" && slot=$(grep -o 'androidboot.slot=.*$' /proc/cmdline | cut -d\ -f1 | cut -d= -f2); 555 | test "$slot" && slot=_$slot; 556 | fi; 557 | if [ ! "$slot" -a "$is_slot_device" == 1 ]; then 558 | ui_print " "; ui_print "Unable to determine active boot slot. Aborting..."; exit 1; 559 | fi; 560 | ;; 561 | esac; 562 | 563 | # target block partition detection enabled by block=boot recovery or auto (from anykernel.sh) 564 | test "$block" == "auto" && block=boot; 565 | case $block in 566 | boot|recovery) 567 | case $block in 568 | boot) parttype="ramdisk boot BOOT LNX android_boot KERN-A kernel KERNEL";; 569 | recovery) parttype="ramdisk_recovey recovery RECOVERY SOS android_recovery";; 570 | esac; 571 | for name in $parttype; do 572 | for part in $name $name$slot; do 573 | if [ "$(grep -w "$part" /proc/mtd 2> /dev/null)" ]; then 574 | mtdmount=$(grep -w "$part" /proc/mtd); 575 | mtdpart=$(echo $mtdmount | cut -d\" -f2); 576 | if [ "$mtdpart" == "$part" ]; then 577 | mtd=$(echo $mtdmount | cut -d: -f1); 578 | else 579 | ui_print " "; ui_print "Unable to determine mtd $block partition. Aborting..."; exit 1; 580 | fi; 581 | target=/dev/mtd/$mtd; 582 | elif [ -e /dev/block/by-name/$part ]; then 583 | target=/dev/block/by-name/$part; 584 | elif [ -e /dev/block/bootdevice/by-name/$part ]; then 585 | target=/dev/block/bootdevice/by-name/$part; 586 | elif [ -e /dev/block/platform/*/by-name/$part ]; then 587 | target=/dev/block/platform/*/by-name/$part; 588 | elif [ -e /dev/block/platform/*/*/by-name/$part ]; then 589 | target=/dev/block/platform/*/*/by-name/$part; 590 | fi; 591 | test -e "$target" && break 2; 592 | done; 593 | done; 594 | if [ "$target" ]; then 595 | block=$(echo -n $target); 596 | else 597 | ui_print " "; ui_print "Unable to determine $block partition. Aborting..."; exit 1; 598 | fi; 599 | ;; 600 | *) 601 | if [ "$slot" ]; then 602 | test -e "$block$slot" && block=$block$slot; 603 | fi; 604 | ;; 605 | esac; 606 | 607 | ## end methods 608 | 609 | -------------------------------------------------------------------------------- /tools/busybox: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EAS-Project/AnyKernel2/f6f5e239fde93a3e4c62e069b00424fab1e06443/tools/busybox -------------------------------------------------------------------------------- /tools/lz4: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EAS-Project/AnyKernel2/f6f5e239fde93a3e4c62e069b00424fab1e06443/tools/lz4 -------------------------------------------------------------------------------- /tools/mkbootimg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EAS-Project/AnyKernel2/f6f5e239fde93a3e4c62e069b00424fab1e06443/tools/mkbootimg -------------------------------------------------------------------------------- /tools/unpackbootimg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EAS-Project/AnyKernel2/f6f5e239fde93a3e4c62e069b00424fab1e06443/tools/unpackbootimg -------------------------------------------------------------------------------- /tools/xz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EAS-Project/AnyKernel2/f6f5e239fde93a3e4c62e069b00424fab1e06443/tools/xz --------------------------------------------------------------------------------