Wednesday, January 8, 2014

Build your very own KitKat ROM for the Galaxy Nexus


Annoyed that Google refused the update the very capable Galaxy Nexus to KitKat? Well now you can easily compile your own ROM.

To start, build Android 4.3 Jelly Bean for your Galaxy Nexus from the instructions given in my previous blog post. 

Once you have 4.3 working on your phone without any issues, download the source for 4.4.2 from AOSP into a new folder, say kitkat.

First, get all the Galaxy Nexus specific makefiles from 4.3.
To do this, copy device/samsung/maguro and device/samsung/tuna to your kitkat folder into the same folders.

Now open device/samsung/tuna/libsensors/Android.mk.

Change LOCAL_C_INCLUDES += hardware/invensense/libsensors
to LOCAL_C_INCLUDES += hardware/invensense/60xx/libsensors


In KitKat, Google changed the directory structure for the driver code, so this is necessary.

In 4.4, Google change the API for sensors and added the following two new fields -

/* number of events reserved for this sensor in the batch mode FIFO.
 * If there is a dedicated FIFO for this sensor, then this is the
 * size of this FIFO. If the FIFO is shared with other sensors,
 * this is the size reserved for that sensor and it can be zero.
 */
uint32_t        fifoReservedEventCount;

/* maximum number of events of this sensor that could be batched.
 * This is especially relevant when the FIFO is shared between
 * several sensors; this value is then set to the size of that FIFO.
 */
uint32_t        fifoMaxEventCount;


You can see the change in sensors.h.
To incorporate these changes, open device/samsung/tuna/libsensors/sensors.cpp, and change the line

 { "GP2A Light sensor",
          "Sharp",
          1, SENSORS_LIGHT_HANDLE,
          SENSOR_TYPE_LIGHT, powf(10, 125.0f/ 24.0f) * 4, 1.0f, 0.75f, 0, { } }
to

  { "GP2A Light sensor",
          "Sharp",
          1, SENSORS_LIGHT_HANDLE,
          SENSOR_TYPE_LIGHT, powf(10, 125.0f/ 24.0f) * 4, 1.0f, 0.75f, 0, 0, 0, { } }




At this point, you can build the source, and flash the images to your Galaxy Nexus to get a working
KitKat ROM, but WiFI will not work, and you will have many graphics glitches.

To fix WiFI, open device/samsung/tuna/init.tuna.rc and modify the following lines -

Change the line
service p2p_supplicant /system/bin/wpa_supplicant \
-iwlan0 -Dnl80211 -c/data/misc/wifi/wpa_supplicant.conf \
-I/system/etc/wifi/wpa_supplicant_overlay.conf -N \
-ip2p0 -Dnl80211 -c/data/misc/wifi/p2p_supplicant.conf \
-I/system/etc/wifi/wpa_supplicant_overlay.conf \
-e/data/misc/wifi/entropy.bin -puse_p2p_group_interface=1

To

service p2p_supplicant /system/bin/wpa_supplicant \
        -iwlan0 -Dnl80211 -c/data/misc/wifi/wpa_supplicant.conf \
        -I/system/etc/wifi/wpa_supplicant_overlay.conf \
        -O/data/misc/wifi/sockets \
        -N -ip2p0 -Dnl80211 -c/data/misc/wifi/p2p_supplicant.conf \
        -I/system/etc/wifi/p2p_supplicant_overlay.conf \
        -puse_p2p_group_interface=1 \
        -e/data/misc/wifi/entropy.bin -g@android:wpa_wlan0

And the line

service wpa_supplicant /system/bin/wpa_supplicant \
-iwlan0 -Dnl80211 -c/data/misc/wifi/wpa_supplicant.conf \
-I/system/etc/wifi/wpa_supplicant_overlay.conf \
-e/data/misc/wifi/entropy.bin

To

service wpa_supplicant /system/bin/wpa_supplicant \
-iwlan0 -Dnl80211 -c/data/misc/wifi/wpa_supplicant.conf \
-I/system/etc/wifi/wpa_supplicant_overlay.conf \
        -O/data/misc/wifi/sockets \
        -e/data/misc/wifi/entropy.bin -g@android:wpa_wlan0



Note that you will still have graphics glitches in places where the Chrome WebView is used, but you can minimize these by downloading a newer kernel from CyanogenMod, or get TinyKernel for Galaxy Nexus.