elftool fails to repack the ELF boot image on Sony devices when a custom dtb file is not provided within the AnyKernel2 zip, because the "dtb" variable, that contains the name of the dtb file, is overridden before the dtb filename is actually passed to the "rpm" variable. Swapping these two lines of code fixes the issue (tested by me on a Sony Xperia SP).
Currently, trying to use insert_line to insert something on the second
to last line fails and places it on the last line.
AK2 line:
insert_line test "sched_boost 0" after "on property:sys.boot_completed=1" " write /proc/sys/kernel/sched_boost 0"
Before:
on property:sys.boot_completed=1
bootchart stop
After:
on property:sys.boot_completed=1
bootchart stop
write /proc/sys/kernel/sched_boost 0
Expected result:
on property:sys.boot_completed=1
write /proc/sys/kernel/sched_boost 0
bootchart stop
In this example, the file length is 2 but the line we're inserting
at is also 2, which is perfectly fine because everything will get
shifted down by 1. Only if the file length is less than the desired
position (in this example, 3) should be handled by >>. All three
cases are now handled fine by insert_line (position 1, 2, and 3).
Signed-off-by: Nathan Chancellor <natechancellor@gmail.com>
- introduce reset_ak function to reset the /tmp/anykernel directory to allow for multi-partition mods; use after changing the AK2 shell (block, etc.) variables again
- make patch_cmdline more intuitive; match the string, and if it doesn't exist add the replacement string, and if so replace with it
- allow AVBv1 signing of recovery by adding simple partition type detection based on name
- restore LD_LIBRARY_PATH after AVBv1 signing to be friendly to recovery when flashed in between other zips
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>
- split dump_boot into split_boot + unpack_ramdisk and write_boot into repack_ramdisk + flash_boot
- fully backwards compatible as dump_boot and write_boot still exist and call these new functions (i.e. no changes needed to anykernel.sh)
- those that wish to do zImage-only AK2 packages can now use split_boot intead of dump_boot and and flash_boot instead of repack_ramdisk in their anykernel.sh
- add failsafe check for failed boot-new.img creation to ensure abort before wiping target partition in edge cases
- 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
- dtbo may be added as dtbo or dtbo.img to the base of the zip
- new Pixel 2 ro.boot.slot doesn't contain _ like Pixel ro.boot.slot_suffix does
Thanks @nathanchance for the majority of the work and research on this one, via #12
- ramdisk_compression=auto; (or undefined) in anykernel.sh is the default, automatically repacking with the detected unpack format
- changing auto to gz lzo lzma xz bz2 lz4-l (for lz4 legacy) or lz4 force the repack as that format
- to this point only gzip was supported, so add support for bzip2, lzop, lzma, xz and lz4 by detecting file magic via plaintext od dump comparison
- busybox contains all necessary formats except for lzma/xz compression (has decompression), and lz4 so add both of these binaries to the minimal default setup
ARM binaries; see AIK-mobile v2.9 for other architectures and optional binaries:
https://forum.xda-developers.com/showthread.php?t=2073775
Users may forget to place the commas for removal or they may want to
remove something in the middle. This will remove all commas at the
beginning and end and will make sure there are only single commas
between entries.
Examples:
Options: ro,barrier=1,discard,errors=panic
patch_fstab fstab.qcom /system ext4 options "discard,errors=panic" ""
patch_fstab fstab.qcom /system ext4 options ",errors=panic" ""
patch_fstab fstab.qcom /system ext4 options "errors=panic" ""
patch_fstab fstab.qcom /system ext4 options "discard" ""
Signed-off-by: Nathan Chancellor <natechancellor@gmail.com>
After aa1377c, trying to remove part of the original string was not
possible.
Example:
patch_fstab fstab.qcom /system ext4 flags “wait,verify” “wait”
Because "wait" is within "wait,verify", the entire if block will miss
since grep will succeed in finding it. To work around this, we'll
allow users to leave the last part blank and put in the part they
want to remove as the fifth parameter.
Example:
patch_fstab fstab.qcom /system ext4 flags “,verify” “”
Signed-off-by: Nathan Chancellor <natechancellor@gmail.com>
- add workaround for malformed ramdisks without leading directory cpio entries
- explicitly set ramdisk root directory to 755 (AOSP default) to avoid issues in some environments
- remove more things confusing to new adopters (AK2 does not root)
- update patch_fstab examples for corrected syntax
DO NOT MERGE if you have already updated your ramdisk properly for your device
- the 'original string' ($5) was not being used, instead the entire part was always being replaced with the 'replacement string' ($6)
- replace the target 'original string' of the entry part with 'replacement string' as expected/intended
NOTE: any properly written patch_fstab commands with original string as the complete original part WILL remain working as this is a backwards compatible change
- add built-in support for rkcrc for Rockchip board devices signed ramdisk image (see: https://github.com/rockchip-linux/rkflashtool)
- add built-in detection and support for Barnes & Noble Nook 'Green Loader/Green Recovery' signature
- 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