-
Notifications
You must be signed in to change notification settings - Fork 4
System call interceptor for Android devices to help AOSP-based ROM device bringup
License
JackpotClavin/Ideal-Init
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
Ideal Init The point of this program is to allow people easily determine which init system-calls must be made during their respective device's boot process in order to more-easily port custom ROMs to their devices. I wrote this utility because Qualcomm's init implementation is very ugly and consists of multiple (and oftentimes useless) init*.rc files and shell scripts. The first (and most important) part of this program is to make the necessary changes to the kernel to print which system calls are being made, so that they can be intercepeted and logged in the kernel's dmesg buffer. Then the user must dump their dmesg onto their computer and and run the program called ideal_init. This program will interpret the intercepted system calls and (hopefully) generate output which resembles a viable (and single) init.<device>.rc. The ideal_init program also filters out the intercepted system calls made by the init processes against the default init.rc scripts that are used for AOSP ROMs, (syscalls made by init.rc, init.trace.rc, etc) so that there is no duplicate** data that may cause adverse effects. A big part of the device's init bringup is when the init scripts set certain device properties. Because 'setprop' is not a system call, a secondary userspace program called 'prop_watch' had to be crafted from the Android toolbox's program called watchprops. This change was needed to spy on whether a script called 'setprop', and this process must be started from your device's init.rc right when it boots (the daemon should be placed in /sbin). Instructions: 1. Revert your device back to 100% stock (and rooted of course) 2. Make the necessary changes from 'required_patches/kernel.diff' to your device's stock kernel source, and add CONFIG_IDEAL_INIT=y to your defconfig 3. Now that you have made the changes to your kernel source, compile the kernel 4. Extract your device's stock boot.img. This will likely create two files; one which is the ramdisk, and one that is the kernel 5. Extract the ramdisk, and make the necessary changes to your ramdisk's init.rc file from 'required_patches/init_rc.diff' 6. Copy the prop_watch binary from the 'bin' folder to your stock ramdisk under /sbin/prop_watch 7. Now that you have edited your stock ramdisk's init.rc file and copied prop_watch to your device's stock ramdisk, remake your ramdisk from the extracted files 8. Remake your boot.img, this time using your kernel compiled from step 3, and your ramdisk with the necesssary changes from step 7 9. Flash your boot.img to your device, and reboot 10. After your device has completely booted, pull your kernel logs with something like: 'adb shell dmesg >> /home/user/syscalls.txt' 11. The file under /home/user/syscalls.txt has all of your kernel's dmesg logs as well as the logged system calls made by your init scripts, now we must extract JUST the logged system calls with something like: 'strings /home/user/syscalls.txt | grep II: >> /home/user/JUST_II_DATA.txt' 12. Copy the file called 'JUST_II_DATA.txt' to the directory this file is in 13. Compile the ideal_init program with 'make' 14. Copy your device's init*.rc files to the directory called 'device_init_files' 15. Copy any init shell scripts from /system/etc to 'device_init_files' 16. Copy any init scripts from: https://android.googlesource.com/platform/system/core/+/<release>/rootdir/ where <release> corresponds to whatever version of Android your stock dump is 17. Plug your phone into your computer, and make sure adb works 18. Run the program ideal_init and it should print out a viable working init.<device>.rc which is a fantastic starting point for porting ROMs to your device What CAN'T this program do/log/catch? It cannot log when variables are exported using the 'export' by init.rc scripts, so things like: 'export EXTERNAL_STORAGE /storage/emulated/legacy' must be done manually by the developer, and must be placed in the proper init trigger. It also cannot catch the 'restorecon' keyword, so those must be added manually. It also cannot catch triggers set by property changes, so things like: on property:init.svc.wpa_supplicant=stopped stop dhcpcd must be added manually. Another thing to mention is that a setprop command made by an init script should be verified that it's in the correct section of the init file. Due to setprop not being a system call, we must use a userspace program to spy on whether a setprop command has been issued; so this program may say that a certain property was set in the 'boot' part of the init process, but in reality it was actually set by in 'early-boot' section of the init process, but by the time the process scheduler ran the prop_watch program to spy on whether a property was set, it may appear that the change was made in 'boot' because the kernel has higher priority than userspace programs. To sum up what Ideal Init cannot do: 1. You must manually add exported variables becuase 'export' is not a syscall 2. You must manually add restorecons because 'restorecon' is not a syscall 3. You must manually add triggers because those are not syscalls 4. You should verify in your device's ramdisk that when a setprop is made in a certain section of the init script, it is properly reflected in the Ideal Init output that it's in the correct section
About
System call interceptor for Android devices to help AOSP-based ROM device bringup
Resources
License
Stars
Watchers
Forks
Releases
No releases published
Packages 0
No packages published