Quantcast
Channel: xda-developers - Android Software and Hacking General [Developers Only]
Viewing all articles
Browse latest Browse all 3614

Ideal Init for AOSP-based ROMs

$
0
0
I wrote this program because the Android's init process Qualcomm phones is absolutely terrible. It's full of things like the following hidden code segment:

Code:

        if [ -f /sys/devices/soc0/soc_id ]; then
            soc_id=`cat /sys/devices/soc0/soc_id`
        else
            soc_id=`cat /sys/devices/system/soc/soc0/id`
        fi

        if [ -f /sys/devices/f9967000.i2c/i2c-0/0-0072/enable_irq ]; then
                echo 1 > /sys/devices/f9967000.i2c/i2c-0/0-0072/enable_irq
        else
                echo "doesn't find slimport enable_irq"
        fi

        case "$soc_id" in
            "208" | "211" | "214" | "217" | "209" | "212" | "215" | "218" | "194" | "210" | "213" | "216")
                for devfreq_gov in /sys/class/devfreq/qcom,cpubw*/governor
                do
                    echo "cpubw_hwmon" > $devfreq_gov
                done
                echo "interactive" > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
                echo "interactive" > /sys/devices/system/cpu/cpu1/cpufreq/scaling_governor
                echo "interactive" > /sys/devices/system/cpu/cpu2/cpufreq/scaling_governor
                echo "interactive" > /sys/devices/system/cpu/cpu3/cpufreq/scaling_governor
                #echo "20000 1400000:40000 1700000:20000" > /sys/devices/system/cpu/cpufreq/interactive/above_hispeed_delay
                echo 90 > /sys/devices/system/cpu/cpufreq/interactive/go_hispeed_load
                echo 1190400 > /sys/devices/system/cpu/cpufreq/interactive/hispeed_freq
                echo 1 > /sys/devices/system/cpu/cpufreq/interactive/io_is_busy
                #echo "85 1500000:90 1800000:70" > /sys/devices/system/cpu/cpufreq/interactive/target_loads
                echo 40000 > /sys/devices/system/cpu/cpufreq/interactive/min_sample_time
                echo 20 > /sys/module/cpu_boost/parameters/boost_ms
                #echo 1728000 > /sys/module/cpu_boost/parameters/sync_threshold
                #echo 100000 > /sys/devices/system/cpu/cpufreq/interactive/sampling_down_factor
                echo 1497600 > /sys/module/cpu_boost/parameters/input_boost_freq
                echo 40 > /sys/module/cpu_boost/parameters/input_boost_ms

                #Set LGE Interactive-Grid parameters for G3 models
                echo "20000 1100000:40000 1500000:20000" > /sys/devices/system/cpu/cpufreq/interactive/above_hispeed_delay
                echo "85 1500000:90" > /sys/devices/system/cpu/cpufreq/interactive/target_loads
                echo 960000 > /sys/module/cpu_boost/parameters/sync_threshold
                echo 0 > /sys/devices/system/cpu/cpufreq/interactive/sampling_down_factor

                echo 1 > /sys/devices/system/cpu/cpufreq/interactive/is_grid
                echo 40000 > /sys/devices/system/cpu/cpufreq/interactive/above_optimal_max_freq_delay
                echo 960000 > /sys/devices/system/cpu/cpufreq/interactive/optimal_max_freq
                echo 7 > /sys/devices/system/cpu/cpufreq/interactive/middle_grid_step
                echo 37 > /sys/devices/system/cpu/cpufreq/interactive/middle_grid_load
                echo 14 > /sys/devices/system/cpu/cpufreq/interactive/high_grid_step
                echo 46 > /sys/devices/system/cpu/cpufreq/interactive/high_grid_load
                echo 1000 > /sys/class/devfreq/g3-display.0/polling_interval

                setprop ro.qualcomm.perf.cores_online 2
            ;;
            *)
                echo "ondemand" > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
                echo "ondemand" > /sys/devices/system/cpu/cpu1/cpufreq/scaling_governor
                echo "ondemand" > /sys/devices/system/cpu/cpu2/cpufreq/scaling_governor
                echo "ondemand" > /sys/devices/system/cpu/cpu3/cpufreq/scaling_governor
                echo 50000 > /sys/devices/system/cpu/cpufreq/ondemand/sampling_rate
                echo 90 > /sys/devices/system/cpu/cpufreq/ondemand/up_threshold
                echo 1 > /sys/devices/system/cpu/cpufreq/ondemand/io_is_busy
                echo 2 > /sys/devices/system/cpu/cpufreq/ondemand/sampling_down_factor
                echo 10 > /sys/devices/system/cpu/cpufreq/ondemand/down_differential
                echo 70 > /sys/devices/system/cpu/cpufreq/ondemand/up_threshold_multi_core
                echo 3 > /sys/devices/system/cpu/cpufreq/ondemand/down_differential_multi_core
                echo 960000 > /sys/devices/system/cpu/cpufreq/ondemand/optimal_freq
                echo 960000 > /sys/devices/system/cpu/cpufreq/ondemand/sync_freq
                # even if scaling_max_freq go down because of themal mitigation, input_boost frequency does not go down.
                # echo 1190400 > /sys/devices/system/cpu/cpufreq/ondemand/input_boost
                echo 80 > /sys/devices/system/cpu/cpufreq/ondemand/up_threshold_any_cpu_load

                #Set LGE Ondemand-Grid parameters for msm8974aa
                echo 960000 > /sys/devices/system/cpu/cpufreq/ondemand/optimal_max_freq
                echo 7 > /sys/devices/system/cpu/cpufreq/ondemand/middle_grid_step
                echo 40 > /sys/devices/system/cpu/cpufreq/ondemand/middle_grid_load
                echo 14 > /sys/devices/system/cpu/cpufreq/ondemand/high_grid_step
                echo 50 > /sys/devices/system/cpu/cpufreq/ondemand/high_grid_load
            ;;
        esac


What is $soc_id equal to? Now we have to audit trail to see what and when $soc_id has been set to, which will open up another can of worms to see when it was initialized to, and what are the implications of having $soc_id set to a certain value, rather than another further down in the init process? Why can't we just extract all of the actual information to the boot process and leave the other junk (support for CPUs which are 5+ years old, unused features, etc) behind?

Enter Ideal Init. What Ideal Init is, consists of some changes to your device's stock kernel, some changes to your device's stock ramdisk. Once you make the changes to the kernel and ramdisk, you create a boot.img with the new and updated kernel and ramdisk, and flash it to your device. The changes you just made to the kernel and ramdisk now allow the system calls made by your device's init.*.rc scripts and init shell scripts to be logged and dumped for later use.

From there you can dump your device's logs using the dmesg command, and run the ideal_init program on your computer to interpret these intercepted system calls and output a valid init.<device>.rc. Then you can revert back to your original setup.

Basically, this program turns all of these init scripts and these init shell scripts and extracts only the information that was actually used in the boot process to create something like this

Check out the README for detailed instructions
https://github.com/JackpotClavin/Ideal-Init

Hope this helps the device bringup for future ROMs

Viewing all articles
Browse latest Browse all 3614

Trending Articles