View Single Post
Old 09-17-2010, 05:13 PM   #1
choff
Member
choff walks where angels fear to fly.choff walks where angels fear to fly.choff walks where angels fear to fly.choff walks where angels fear to fly.choff walks where angels fear to fly.choff walks where angels fear to fly.choff walks where angels fear to fly.choff walks where angels fear to fly.choff walks where angels fear to fly.choff walks where angels fear to fly.choff walks where angels fear to fly.
 
Posts: 12
Karma: 152738
Join Date: Jul 2010
Device: Kindle DXG
Installing a "normal" Debian ARMEL Linux on the Kindle

Hey guys,

recently I got a regular Debian Linux to run on the Kindle. In this article I will describe how I got it up and running.

Prerequisites:
  • Time and patience :-). The whole thing took me about 4 full days to set up. I hope that this post will make things easier for you, but you'd better have some spare time left before you get started.
  • A serial connection to your Kindle for bootloader access. If your Kindle is still working, you can also chroot into your filesystem image, but I started from scratch by compiling my own Kernel and initramfs.
    The serial connection is not all that hard to get working once the gray bezel is removed. I suggest you use the pins of the J9 connector and use a FTDI TTL-232R converter cable (3.3 or 5V). No soldering required. See http://www.youtube.com/watch?v=vRigHZSvcyc. The video's a bit goofy, but it should be enough to get you started

Overview

Here is a small overview of what we are going to do.
First of all, we'll install Debian Armel on a QEMU virtual machine. Then we'll copy the ARMEL filesystem image over to the Kindle's USB-accessible FAT partition.
After that we are going to create an initramfs(a small initial root filesystem loaded by the Kernel) which will start our newly created Debian Linux. Then we'll build the Kernel for the Kindle with our initramfs statically linked into it.
Finally, we will transfer the Kernel and start it via the U-Boot bootloader.

Part 1: Create a Debian Linux for ARM
I won't go into this in detail as there is already some information on the internet. A good tutorial can be found here: http://blog.troyastle.com/2010/07/bu...n-vm-with.html
Also, make sure you don't create a root filesystem with eight GB as described in this article :-). 1.3 GB should be enough for a basic Linux and a tiny X server.
You'll notice that the VM is awfully slow, so it's always good to have a book at hand to busy yourself in the idle time during the install and fetching of additional packages.

Part 2: Transfer Linux filesystem image on the Kindle's USB-Partition
If your Kindle is still alive, just copy the image over via
Code:
dd bs=32256 skip=1 < image > /media/kindle/ubuntu
. Otherwise, you can still enter recovery mode by
  • Disconnecting your Kindle from USB(make sure that it has got a little battery power left)
  • Pressing the power button for a minute
  • After releasing the power button, press the Home button immediatly for about 15-40 seconds until the screen flashes and your Kindle tries to reboot. If your root filesystem is busted(such as mine), you will have to type "reset" on the keyboard when prompted and you will be in recovery mode. Connect to your Kindle via USB and copy the image over with the above dd command. Do not press "1"(not sure if it will do any harm, though).
  • Unmount the Kindle on the host PC

Part 3: Creating the initramfs
For this part, we'll need
  • the busybox sources(the binary in Debian's nice busybox-static package won't do the trick as it is lacking switch_root support)
  • CodeSourcery's G++ Lite Edition for ARM(target OS GNU/Linux) from http://www.codesourcery.com/sgpp/lit...@template=lite
  • Amazon's sources

First you'll need to create a directory to hold your initramfs. Compile a busybox binary by running
Code:
make ARCH=arm menuconfig
and do the following modifications to your busybox configuration:
  • select the path to the initramfs as installation prefix
  • set the cross compiler prefix to the prefix of your ARM cross compiler (e.g. "[...]/CodeSourceryARMCrossLinux/bin/arm-none-linux-gnueabi-")
  • disable some unnecessary features in order to save space. This is really important since the data transfer of the kernel via serial line will take some time. Additionally, the size of the partition containing the 2 kernel images(normal and recovery) is only 8Mb.
Finally, run "make install" which will copy busybox to your initramfs and create all the necessary symlinks for you.

Now we'll need to create some device nodes inside our initramfs. If your Kindle is still running, you can simply "ls -l" in the Kindle's /dev directory and you'll see the major and minor device numbers which you can pass to mknod, otherwise here's a listing of all device nodes that could be important:
Code:
crw------- 1 root root   5,   1 2010-08-19 14:26 console
brw-rw---- 1 root root   7,   0 2010-08-19 14:26 loop0
brw-rw---- 1 root root   7,   1 2010-08-19 14:26 loop1
brw-rw---- 1 root root   7,   2 2010-08-19 14:26 loop2
crw-rw---- 1 root root   1,   1 2010-08-19 14:26 mem
brw-rw---- 1 root root 179,   0 2010-08-19 14:26 mmcblk0
brw-rw---- 1 root root 179,   1 2010-08-19 14:26 mmcblk0p1
brw-rw---- 1 root root 179,   2 2010-08-19 14:26 mmcblk0p2
brw-rw---- 1 root root 179,   3 2010-08-19 14:26 mmcblk0p3
brw-rw---- 1 root root 179,   4 2010-08-19 14:26 mmcblk0p4
crw-rw-rw- 1 root root   1,   3 2010-08-19 14:26 null
crw-rw---- 1 root root 250,   0 2010-08-19 14:26 pmic
crw-rw---- 1 root root   1,   8 2010-08-19 14:26 random
crw-rw---- 1 root root   5,   0 2010-08-19 14:26 tty
crw-rw---- 1 root root 207,  16 2010-08-19 14:26 ttymxc0
crw-rw---- 1 root root 189,   0 2010-08-19 14:26 usb1
crw-rw---- 1 root root  10, 130 2010-08-19 14:26 watchdog
crw-rw---- 1 root root   1,   5 2010-08-19 14:26 zero
But the most important part is still missing: The init script which is executed by the kernel and is supposed to mount our new root, which would be the file system image we copied earlier.

I have attached my script. You will notice that it first creates a loop device for /dev/mmcblk0p4 with an offset of 1024(the start of the FAT partition) and then mounts the file system image(again by creating a loop device).

We are almost done! But we still need to compress the initramfs:
Code:
sudo find . | cpio -H newc -o > ../initramfs.cpio
Part 4: Build Kindle kernel
Simply follow the instructions from http://www.mobileread.com/forums/showthread.php?t=91862, but set CONFIG_INITRAMFS_SOURCE to the path of your initramfs.cpio.

Part 5: Transfer image to device & boot
Enter the U-Boot bootloader and type "run uboot_serial", which will wait for an YModem-G file transfer from your host. Use Minicom and send the file via ZModem(the YModem option won't work!). Do not try to send files via Kermit! U-Boot Kermit supports seems to be broken and didn't work with Kermit, Minicom and HyperTerminal.
Now just run
Code:
setenv bootargs "init=/bin/sh"
bootm 0x84000000
and pray that everything works :-).

You can get the normal System V init sequence to work by removing all lines containing "getty" from /etc/inittab. Remount the root of your filesystem and reset your kindle and start your linux again, this time without bootargs. If you're lucky, you should see a login prompt on the screen.

Limitations
Reboot and shutdown just freeze the Kindle until the battery is removed. Even reset does not work. I'll look into this.
However, I was able to get a KDrive X server to run.
Attached Files
File Type: gz init.tar.gz (913 Bytes, 269 views)

Last edited by choff; 09-18-2010 at 07:04 AM.
choff is offline   Reply With Quote