Thread: Hardware OTG support
View Single Post
Old 03-13-2013, 02:45 AM   #58
RMH
Junior Member
RMH is a splendid one to beholdRMH is a splendid one to beholdRMH is a splendid one to beholdRMH is a splendid one to beholdRMH is a splendid one to beholdRMH is a splendid one to beholdRMH is a splendid one to beholdRMH is a splendid one to beholdRMH is a splendid one to beholdRMH is a splendid one to beholdRMH is a splendid one to behold
 
Posts: 1
Karma: 19958
Join Date: Mar 2013
Device: Kindle Touch
Compile K5 kernel

First, apologies for necro-posting but this really seemed to be the most appropriate thread...

I've been attempting to compile a Lab126 kernel for my Kindle Touch with the eventual goal of porting Choff's USB OTG code in. This is a bit of a slow process for me as it's the first time I have compiled... well, anything in Linux. I am gradually working my way through the process with great help from many posts here.

I have discovered a few things in the process that I feel are worth sharing.

I started with a pretty much unmodified version of Ubuntu 12.04 LTS. I grabbed a copy of the K5 5.1.2 source and extracted it. I also extracted the linux-2.6.31.tar.gz file inside to use as my starting point. I picked 5.1.2 mainly because it's the version I still have on my Touch since I like some of the community features (thanks to Ixtab especially). For simplicity, let's say this gets extracted to ~/kindle_5.1.2/linux-2.6.31/.

I then proceeded to follow Choff's K4 instructions. I'll take some liberties with the order of things because I ran into plenty of dead ends and had to backtrack. Of course that's on me, not Choff. Anyway, the first thing needed was a copy of the initramfs. I extracted this myself using Choff's instructions but it looks like knc1 determined it is GPL'd and, as such, has posted it here.

To use knc1's version, it needs to be extracted and repackaged with the cpio format. I think there may be a way to avoid this but it worked for me. So with some customizing of Choff's steps, the commands should be...
Code:
sudo tar -xzvf main-5.1.2-irfs.tar.gz
cd km-5.1.2-irfs
sudo find . | cpio -o -H newc > ../initramfs.cpio
I took the resultant initramfs.cpio file and copied it to the location where I had extracted linux-2.6.31.tar.gz, which we're still saying is ~/kindle_5.1.2/linux-2.6.31/.

Next I found Amazon's provided code doesn't compile. (Don't worry about how. This is where I'm taking liberties in the order.) The problem is a missing kindle_version.h file referenced in ~/kindle_5.1.2/linux-2.6.31/drivers/rtc/rtc-mxc_v2.c. Rather than attempting to find a good kindle_version.h file, I grabbed Amazon's 5.3.2 source and checked the rtc-mxc_v2.c file buried in it (Kindle_src_5.3.2.tar.gz/gplrelease/linux-2.6.31.tar.gz/drivers/rtc/rtc-mxc_v2.c).

It turns out Amazon removed the requirement for that kindle_version.h file in the newer rtc-mxc_v2.c and the only real changes were the removal of some debug/error messages. So I copied this newer version over top of the old one.

This gets everything ready to compile. I tried Choff's suggested compiler but apparently it doesn't produce a compatible kernel on the Touch (or at least not kexec-able, which was my goal). This took a while to figure out and I'm still not sure what was actually wrong since I don't want to crack open my Kindle to investigate via the serial port. Still, I know this was the problem because next I went to knc1's KeK and got the compiler version that he recommended, specifically arm-2010.09-50-arm-none-linux-gnueabi-i686-pc-linux-gnu.tar.bz2. After downloading this and extracting it to ~/arm-2010.09/, I was able to compile. Here are the commands I used.

First, configuring options...
Code:
cd ~/kindle_5.1.2/linux-2.6.31/
make ARCH=arm CROSS_COMPILE=~/arm-2010.09/bin/arm-none-linux-gnueabi- imx50_yoshi_defconfig
make ARCH=arm CROSS_COMPILE=~/arm-2010.09/bin/arm-none-linux-gnueabi- menuconfig
... and this gives a menu where we have to set one option. Select "General setup --->" by pressing <Enter> and turn on "Initial RAM filesystem and RAM disk (initramfs/initrd) support" by scrolling to it and pressing <Y> or <space>. Then scroll down one more, press <Enter> on "Initramfs source file(s)" and set it to "initramfs.cpio". Hit <ESC> a few times to back out, making sure to answer "Yes" when it asks if you want to save the changes.

Now back to the commands, the actual kernel compile is ready and can be started with...
Code:
make ARCH=arm CROSS_COMPILE=~/arm-2010.09/bin/arm-none-linux-gnueabi- -j2 uImage
... while the supporting modules (if they are wanted) can be compiled with...
Code:
make ARCH=arm CROSS_COMPILE=~/arm-2010.09/bin/arm-none-linux-gnueabi- -j2 targz-pkg
This got me the new kernel named "uImage" in ~/kindle_5.1.2/linux-2.6.31/arch/arm/boot/. I copied this to my Kindle Touch, booted it successfully with kexec, and discovered one more flaw in Amazon's code. Apparently 5.1.2's source is not entirely matching 5.1.2 in reality because the ar6003 wifi driver was throwing errors about an undefined symbol "mx50_pcbsn_x". This symbol doesn't exist anywhere in the 5.1.2 code but is all over the place in the 5.3.2 code. I confirmed that the ar6003.ko file compiled from the 5.1.2 source can be loaded via insmod, which fixes this temporarily; But it re-breaks -- I think when wifi is turned off and back on -- and I personally am not ready to overwrite the modules on the root filesystem.

I think my next step is to take the diffs from Choff's code and attempt to apply them to this compiling 5.1.2 code. With my inexperience, I imagine this will take me at least a few weeks to accomplish though. And it may be held up if I discover any new problems on the way.

Last edited by RMH; 04-01-2013 at 12:22 AM. Reason: Noticed typo on module cross compile argument
RMH is offline   Reply With Quote