Having spent many hours attempting to get a custom kernel booting for the factory Android image, I found that is was easier to first create an factory Android image that would boot from an SD card. The main advantage is that it removes the arduous steps of packaging a complete image and then re-flashing to Nand for each small change. It also opens up the possibility of booting other Android distributions from an SD card.
To start with I created a mirror image of the nand paritition on an SD card, to do this requires a linux installation. The nand partitions range from A-K as are covered in more detail here. I used gparted to create the partitions with the correct sizes as below, it is important that you leave 16MB free at the start of the SD card for uboot (shown by 'unallocated' partition) . You need to create an extended partition (shown by /dev/sdc4) in order to create more than 4 partitions.
You need to create an additional partition on the SD card to represent the extrernal sd card /mnt/extsd, I created a FAT32 partition which becomes /dev/sdc13 (mmcblk0p13).
Next step is to copy across all the nand partitions from the hackberry. This can be done by booting the hackberry with a linux distro and using the linux dd command to copy the partitions to files. I copied the partitions on to a usb stick (needs to be at least 4GB) as below:
dd if =/dev/block/nanda of=nanda
dd if =/dev/block/nandb of=nandb
dd if=/dev/block/nandc of=nandc
...
...
dd if=/dev/block/nandk of=nandk
Once all the nand files are created we can 'dd' the files to the SD card. The boot partition file nandc is not copied because we need to extract the rootfs from it and create a ext4 partition. The bootloader file nanda is also not copied as we create our uboot on FAT16 partition (/dev/sdc1). Assuming the SD card shows up as /dev/sdc I executed the following (amend /dev/sdc with correct device name for your SD card).
sudo dd if=nandb of=/dev/sdc2
sudo dd if=nandd of=/dev/sdc5 bs=1M
sudo dd if=nande of=/dev/sdc6
sudo dd if=nandf of=/dev/sdc7
sudo dd if=nandg of=/dev/sdc8
sudo dd if=nandh of=/dev/sdc9
sudo dd if=nandi of=/dev/sdc10
sudo dd if=nandj of=/dev/sdc11
sudo dd if=nandk of=/dev/sdc12 bs=1M
sudo sync
Next I extracted the ramdisk rootfs from the nandc file, fortunately I have done this for you. Download the file android_sd.tar.gz, it contains all the additional files required to create a bootable sd card. If your interested how I extract the kernel and rootfs I used the split_bootimg.pl utility, further info here. I also fixed the files init.sun4i.rc and ueventd.sun4i.rc so that they refer to the sdcard paritions /dev/ /dev/mmcblk0pX instead of /dev/nandX.
The mapping between nand and mmcblk0p are shown below
nanda -> mmcblk0p1
nandb -> mmcblk0p2
nandc -> mmcblk0p3
mmcblk0p4
nandd -> mmcblk0p5
nande -> mmcblk0p6
nandf -> mmcblk0p7
nandg -> mmcblk0p8
nandh -> mmcblk0p9
nandi -> mmcblk0p10
nandj -> mmcblk0p11
nandk -> mmcblk0p12
Take the nandc file from the zip file and dd it to the correct SD card parition, in my example it is /dev/sdc eg:
The mapping between nand and mmcblk0p are shown below
nanda -> mmcblk0p1
nandb -> mmcblk0p2
nandc -> mmcblk0p3
mmcblk0p4
nandd -> mmcblk0p5
nande -> mmcblk0p6
nandf -> mmcblk0p7
nandg -> mmcblk0p8
nandh -> mmcblk0p9
nandi -> mmcblk0p10
nandj -> mmcblk0p11
nandk -> mmcblk0p12
sudo dd if=nandc of=/dev/sdc3
I then changed all references in the script files on the system partition (/dev/sdc5 in my example) from /dev/nandX to /dev/mmcblk0pX. The files to amend are:
./etc/vold.fstab
./bin/preinstall.sh
./bin/sop.sh
You need to edit ./etc/vold.fstab and replace the /mnt/extsd with the following:
dev_mount extsd /mnt/extsd auto /devices/virtual/block/mmcblk0p13
Finally I copied the Hackberry uboot files sunxi-spl.bin and u-boot.bin to the SD card to make it bootable. This is the reason for the leaving 16MB free at the start of the SD card.
sudo dd if=sunxi-spl.bin of=/dev/[drive] bs=1024 seek=8
sudo dd if=u-boot.bin of=/dev/[drive] bs=1024 seek=32
sudo sync
I suggest you delete everything of the data partition (eg /dev/sdc6), this will ensure the correct device partitions are found and recorded on the first boot. It would be prudent to hook up a serial console to the Hackberry to monitor boot progress in case of failures. Insert the SD card into the Hackberry and power up.
Once you have Android booting, turn off media scanning for the SD card. This option is in Setting->Storage>"Enable media scanning on SD".
If want to try deploy another kernel (assuming the kernel and modules are compatible with the Android image) then:
./etc/vold.fstab
./bin/preinstall.sh
./bin/sop.sh
You need to edit ./etc/vold.fstab and replace the /mnt/extsd with the following:
dev_mount extsd /mnt/extsd auto /devices/virtual/block/mmcblk0p13
Next I converted the extracted kernel from the nandc file to be uboot compatible, again in the download zip there is a pre-built file (uImage). If your interested, I used the following command to convert the kernel:
mkimage -A ARM -C none -T kernel -O linux -a 40008000 -e 40008000 -d nandc-kernel uImage
Copy the uImage file to first partition on the SD card (this is bootloader FAT16 partition which is empty ). Also copy the uboot config files uEnv.txt and boot.scr to the first partition.
Finally I copied the Hackberry uboot files sunxi-spl.bin and u-boot.bin to the SD card to make it bootable. This is the reason for the leaving 16MB free at the start of the SD card.
sudo dd if=sunxi-spl.bin of=/dev/[drive] bs=1024 seek=8
sudo dd if=u-boot.bin of=/dev/[drive] bs=1024 seek=32
sudo sync
I suggest you delete everything of the data partition (eg /dev/sdc6), this will ensure the correct device partitions are found and recorded on the first boot. It would be prudent to hook up a serial console to the Hackberry to monitor boot progress in case of failures. Insert the SD card into the Hackberry and power up.
Once you have Android booting, turn off media scanning for the SD card. This option is in Setting->Storage>"Enable media scanning on SD".
If want to try deploy another kernel (assuming the kernel and modules are compatible with the Android image) then:
- Copy the newly built uImage file to the first partition of the SD card.
- Copy the modules to the /vendor/modules on the system partition of the SD card.