Post Builing your own Ouya Kernel

Hi,

I made a tutorial explaining how to compile the ouya's kernel from scratch.

I made this tutorial because I needed to enable the nfs protocol versions 3 and 4 to use file shares from my Synology NAS. The ouya's kernel enabled by default only comes with version 2 and i had problems to mount my NFS shares.

Let's start. my english is not very good then ignore the grammatical errors.

Let's first download the required files. I'm on the premise that you have an ubuntu linux installed on your machine.

*** DOWNLOAD OUYA FIRMWARE ***

1. Open your browser and type:

https://devs.ouya.tv/api/firmware_builds

2. Search for a string like this:

http://cds.t2z5c2q6.hwcdn.net/ota/RC...084-r1_ota.zip (this is the latest version of ouya firmware)

3. Download it:

$ wget http://cds.t2z5c2q6.hwcdn.net/ota/RC...084-r1_ota.zip

2. Create a directory an put the file there:

$ mkdir ouyafiles

4. unzip it:

$ unzip RC-OUYA-1.2.1084-r1_ota.zip

5. Now you have a lot of files and directories. We need only one. The name of file is: boot.img. We need to unzip this file to retrieve the ramdisk file that will be needed along with the compiled kernel. For this we need to download the following perl script:

$ wget http://www.enck.org/tools/split_bootimg_pl.txt

5. Rename the script and change the permissions to execute:

$ mv split_bootimg_pl.txt split_bootimg.pl
$ chmod 755 split_bootimg.pl

6. Run this command to unpack the file:

$ ./split_bootimg.pl boot.img

7. Now you have 2 files: boot.img-kernel and boot.img-ramdisk.gz. We only need the boot.img-ramdisk.gz. Lets unzip this again and rename the unzipped file:

$ gzip -dc ../boot.img-ramdisk.gz | cpio -i
$ mv boot.img-ramdisk ramdisk

8. OK. Now you have this file. We will use it later in the tutorial.

*** DOWNLOAD ANDROID NDK ***

1. Open the Browser and paste this URL: http://developer.android.com/tools/sdk/ndk/index.html

2. Download the Linux 64-bit (x86) package file:

$ wget http://dl.google.com/android/ndk/and...x86_64.tar.bz2

3. Unzip it:

$ tar -jxvf android-ndk-r9d-linux-x86_64.tar.bz2

4. Rename the unzipped directory to "ndk":

$ mv android-ndk-r9d ndk

5. Load the environment variables:

$ export CROSS_COMPILE=/your_home_directory/ndk/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86_64/bin/arm-linux-androideabi-
$ export ARCH=arm

Obs.: (remember the /your_home_directory/ is the default home directory that you user in linux uses to work).

*** DOWNLOAD THE OUYA KERNEL SOURCE ***

1. Open your browser and go to this URL:

https://github.com/ouya/ouya_1_1-kernel

2. In the right side of the page you will have a download button called "Download ZIP". Click and Download it.

3. Unpack it and rename the unzipped directory to "kernel"

4. Maybe the /kernel/drivers/pci/Kconfig file will corrupt before unzip the file. Kconfig is a symbolic link. Remove it and Download again using the command inside the kernel/drivers/pci/ directory:

$ wget https://raw.githubusercontent.com/ou...rs/pci/Kconfig

6. Now you have the default ouya kernel for compile!


*** RECOVER .CONFIG FILE FROM OUYA ***

1. You need to retrieve a file that is in ouya. To retrieve the file you need install the package android-tools-adb. use the following command:

$ sudo apt-get install android-tools-adb

2. Now you have to connect your ouya via usb. By default your ouya don't enable adb. You need to go to DEVELOPMENT screen on your ouya and enable “ADB: ON”.

3. Fine. Now test if the adb is connecting. Try this commands:

$ adb start-server
$ adb devices (this will show something like this “1234567890ABCDEF device”)

PS.: if no devices appears... you need to search in the internet about “how to use adb to connect android devices”

4. Now you will pull the config file:

$ adb pull /proc/config.gz config.gz (this will pull config.gz to your computer)

5. Unzip it and copy to kernel directory:

$ gunzip config.gz
$ cp config /your_home_directory/kernel/.config

6. Now your kernel is ready to compile. We're ensuring that the standards are consistent settings. From now on it is your responsibility to enable and disable kernel configurations.


*** REBUILDING KERNEL ***

1. Go to Kernel Directory:

$ cd /your_home_directory/kernel/

2. Make sure to run the environment variables CROSS_COMPILE and ARCH described above in the tutorial.

$ export CROSS_COMPILE=/your_home_directory/ndk/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86_64/bin/arm-linux-androideabi-
$ export ARCH=arm

3. Use this command to change some settings:

$ make menuconfig

4. Use this command to build the kernel after you change your new settings:

$ make

5. Some warnings will display in your console... its normal.

6. if the process run ok you 'll have a bzImage file under the directory kernel/arch/arm/boot

7. copy this file to the same directory where you store the ramdisk file.

*** UPLOAD THE NEW KERNEL AND THE RAMDISK TO OUYA ***

1. You will need to install the fastboot on linux using this command:

$ apt-get install android-tools-fastboot

2. Now you have to reboot your device in bootloader mode:

$ adb reboot-bootloader

3. You can check if you devices enters in this mode using this command:

$ fastboot devices

4. If it works. You can upload your new kernel and the default ramdisk:

$ fastboot flash:raw boot ./zImage ./ramdisk

The system should now boot with your custom kernel installed!