- some apps copy the zip to be flashed to the app cache, which would result in the .tgz going either somewhere unknown/inaccessbile to the user or get deleted when the app cleans up after flash, so instead send to /sdcard if the device is booted to Android
- abstract out execution directory as $home to fascilitate testing individual scripts (defaults to /tmp/anykernel)
- general script clean ups for uniformity, readability, speed and simplicity
- simplify consecutive `ui_print` commands where possible
Backend only fixes:
- use busybox umount and mount whenever possible to avoid linker warnings in stderr during system-as-root setup
- use `busybox --install -s` for bin/* setup
- consolidate setup to abort earlier if there are issues
- add backwards compatible symlinks for those who might not have updated their anykernel.sh with ak3-core.sh (to be renamed in subsequent commit)
Tools only fixes:
- add magiskboot to replace separate support for AOSP and PXA-AOSP formats, with MTK headers, BLOB, DHTB, SEAndroid and Nook signing
- add magiskpolicy to allow for easy sepolicy patching
- remove xz and lz4 since magiskboot supports these
AK3 Core only fixes:
- use full `ui_print` function implementation like the backend
- add `abort` function to simplify exit on errors
- fix $patch directory being excluded from `reset_ak`
- update $ramdisk_compression handling for magiskboot
- magiskboot also resolves long-standing request for built-in Bump support (#18)
- update Sony ELF and related support for initial repack as AOSP by using mkbootimg as plug-and-play optional add-in binary
- update Sony ELF MTK header support using mkmtkhdr only when ELF is initially unpacked by unpackelf
- add support for MTK RECOVERY ramdisk header type with Sony ELF
- simplify U-Boot dumpimage/mkimage and Sony ELF unpackelf/mkbootimg split_img file handling
- update patch_cmdline to handle both magiskboot as header prop file, and unpackelf or mboot as cmdline.txt
- use `cp -fp` for `backup_file` and `restore_file` to hopefully better preserve attributes if used outside of the ramdisk
- refactor setup into `setup_ak` to simplify `reset_ak` trigger to find slot and block again
- add fallback to busybox for compression formats (i.e. lzop) which magiskboot cannot handle
IMPORTANT NOTES:
1) forcing repack with uncompressed cpio ramdisk is not currently supported by magiskboot
2) forcing repack with lzop ramdisk when previously another format is not currently supported by magiskboot
- some ROMs have taken it upon themselves to go against AOSP, i.e. where starting with Pie AOSP now versions it as only 9, some ROMs are still making it 9.0
- introduce integer 2 float function that will add a decimal place to all for comparisons
- this should support the majority of ROMs, but anything crazy like 9.0.0, or crazier like 09.0.0 should be frowned upon by the community and the ROM devs should be made to get it together and follow AOSP
- checks the supported.versions prop in anykernel.sh and matches against it to prevent users flashing incorrect kernels for ROM versions
- supported.versions can be a list, e.g. "7.1.2, 8.0, 8.1" or a range, e.g. "8.1 - 9" of versions in the correct formatting for that Android version in ro.build.version.release in /system/build.prop
- getprop failures are not only a system-as-root device issue, as it now also happens on OnePlus 5T in recovery when ROM is Pie Open Beta
- this appears to come down to a libc mismatch between recovery and ROM resulting in direct property checks failing but getprop without arguments printing all properties working
- revert most of https://github.com/osm0sis/AnyKernel2/commit/b1524da099efa716616a8eb3357876bca6a73540 since this should remain resolved with the new implementation
- keep the old check and file_getprop fallback for devices without getprop entirely
- add new getprop fallback that parses the full getprop output
- some custom ROMs on some devices (e.g. Lineage on Pocophone) bind mount modules in /system over modules on /vendor, so remount rw at the bind target to ensure the bind source is also remounted and replaced
- toybox mount doesn't accept the /. prefixed paths from find so ensure we use busybox for mounts
Thanks franciscofranco and topjohnwu for the tips!
- adapted from https://github.com/nathanchance/AnyKernel2/commit/3dfba3dcabff3cf1f859276e1851ae35891d8801
- works around odd behaviors in TWRP on system-as-root devices, but retains working fallback using /system/system/build.prop if getprop also fails
- simplify unmount_all stderr redirection
Please see the above linked commit for further details.
Thanks to nathanchance for reporting, the device-specific workaround, and much testing
- remove "kernel" from "Installing" wording since AK2 is also used on recoveries, and multi-partition Treble devices and this could be misleading
- fix getprop build.prop fallback on /system/system devices
- place version text in a file named "version" in the root of the zip and it will display after the kernel.string when flashing
- useful in conjunction with build scripts, i.e. a generated version file not actually part of the kernel AK2 repo
After working on the OnePlus 5/T with custom ROMs on Android 8.1.0, I
have noticed that several of them have modules in /system/lib/modules
with a context of "u:object_r:vendor_file:s0", which goes against the
assumption made in commit 6b11373 ("update-binary: Change how we handle
modules"). Because the context is changed, there is an SELinux denial
when trying to load the module during init.
While it would be nice for ROMs to fix that on their own, I suspect
they are not entirely at fault. Google's documentation does state that
all modules should be loaded from vendor whenever possible so I would
guess Google decided to force *.ko objects to have a vendor_file
context. This is all speculation as I haven't cared to do research into
the subject.
Easiest way around this is to just worry about applying contexts to new
modules. cp does not override contexts so if the module was already
present, we can assume it has the correct context to begin with.
Signed-off-by: Nathan Chancellor <natechancellor@gmail.com>
As of Oreo, Google is requiring that kernel modules be used whenever
possible and that their location be in /vendor. With Lineage 15.1,
devices without a separate /vendor partition will use /system/vendor,
which symlinked to /vendor.
To make this more flexible and future proof, allow developers to specify
where each module needs to go by setting the path in the modules folder.
If a module needs to go to /system/vendor/lib/modules, then the module
should be placed in modules/system/vendor/lib/modules. Contexts and
permissions will still be updated automatically.
Android documentation: https://source.android.com/devices/architecture/kernel/modular-kernels
Lineage 15.1 commit: https://github.com/LineageOS/android_vendor_lineage/commit/bf38db2a5e358a5449458b3dee2dd9d4015b8147
Signed-off-by: Nathan Chancellor <natechancellor@gmail.com>
- hide some expected stderr for AK2 mods with no additional ramdisk files
- fix U-Boot support by passing correct repacked ramdisk filename
- fix multi-compression support during repack derp
- fix cleanup on successful flash not working due to double match from cleanuponabort
- fix busybox getting permissions on some devices where chmod does not accept -R to recurse
- use busybox for more possibly non-standard broken recovery shell commands
- silence some more generally expected/inconsequential stderr
- symlinks under /system/lib/modules were getting broken, so follow them instead to replace the target file, avoiding issues with multiple versions of the same module and running out of free space (e.g. OnePlus devices link /system/lib/modules/wlan.ko to /system/lib/modules/qca_cld3/qca_cld3_wlan.ko)
- set contexts on copied modules (following symlinks) to system_file to avoid SELinux issues where unlabeled module files might not be allowed to load
- to make it easier to diagnose issues with patches, image creation or flashing, adding "-debugging" to the end of the AK2 zip filename will enable the creation of a tar.gz of the entire /tmp directory after the installation process (but before cleanup, of course), this includes recovery.log, boot.img, boot-new.img and any other remnants to allow more thorough, direct debugging at a later time
- if it does not exist yet (i.e. hasn't been extracted) then assume cleanuponabort=1 since there wouldn't be anything to see on a failed extraction
- hide any missing file errors from file_getprop here now that we've taken care of that case
"Some older scripts may still use ‘.’ in place of the ‘:’ separator. POSIX 1003.1-2001 does not require support for that, but for backward compatibility GNU chown supports ‘.’ so long as no ambiguity results. New scripts should avoid the use of ‘.’ because it is not portable, and because it has undesirable results if the entire owner‘.’group happens to identify a user whose name contains ‘.’."
Source: http://gnu.org/software/coreutils/manual/html_node/chown-invocation.html#chown-invocation.
- fixes flashing slowdown in TWRP 3.0.0: TWRP3 (currently) appears to have a bugged busybox/ln command which takes an excessive amount of time, no reason not to use our own instead
- fail on recoveries where symlinking our busybox environment doesn't work (CM Recovery on some devices)
- use the included busybox for awk since toybox is lacking (CM Recovery)
- fix fallback broken unzip detection now that we create a subdirectory prior
- probably best to execute the bump/loki/whatever script using our included ash shell instead of the recovery sh.
- add busybox to the zip to provide a uniform expected environment
- set up busybox symlinks in /tmp and execute anykernel.sh from a shell created with these at the front of the path, overriding the recovery applets
- fix copy of any subdirectories under modules/
- adjust display of modules installation text to match the others
- add support for custom user scripts (at /data/custom_boot_image_patch.sh - same as latest SuperSU zips) to automatically execute before reflashing the rebuilt boot image for bump, loki etc. modifications