Boot Android from SdCard

Boot Android From SdCard
For extract need file from android image, have need of awutils and android tools. $ wget http://dl.linux-sunxi.org/users/arete74/tools.tar.gz  $ tar -zxvf tools.tar.gz

AWUtils $ git clone https://github.com/Ithamar/awutils.git $ cd awutils $ make

Extract file from Android Image
Resources for Cubieboard A10: http://docs.cubieboard.org/tutorials/cb1/installation/cubieboard_android-4.0.x_release http://dl.cubieboard.org/model/cubieboard1/Image/android/

In this guide the name of the Android Image is android.img $ awimage -u android.img

This command creates a folder called android.dump with many files. The three following files are the ones we are interested :

RFSFAT16_BOOT_00000000000 (the boot partition)

RFSFAT16_RECOVERY_0000000 (the recovery partition)

RFSFAT16_SYSTEM_000000000 (the system partition, ext4 sparse)

RFSFAT16_BOOTLOADER_00000 (the bootloader partition)

For simplicity rename: cp android.img.dump/RFSFAT16_BOOT_00000000000 ../boot.img cp android.img.dump/RFSFAT16_RECOVERY_0000000 ../recovery.img cp android.img.dump/RFSFAT16_SYSTEM_000000000 ../system.img cp android.img.dump/RFSFAT16_BOOTLOADER_00000 ../bootloader.img cd ..

Extract Kernel and Ramdisk
For extract kernel and boot RAM disk try this command:

$ ./tools/split_bootimg.pl boot.img Page size: 2048 (0x00000800) Kernel size: 4215036 (0x004050fc) Ramdisk size: 974998 (0x000ee096) Second size: 0 (0x00000000) Board name: Command line: console=ttyS0,115200 rw init=/init loglevel=5 Writing boot.img-kernel ... complete. Writing boot.img-ramdisk.gz ... complete.

decompress the ramdisk data $ mkdir boot $ cd boot $ gunzip -c ../boot.img-ramdisk.gz | cpio -i $ tar -cpvf ../boot.tar * $ cd ..

Convert kernel to uImage $ mkimage -A arm -O linux -T kernel -C none -a 0x40008000 -e 0x40008000 -n "Linux 2.6" -d boot.img-kernel uImage

Extract system image
$ ./tools/simg2img system.img system1.img $ mkdir system $ mount -o loop system1.img system $ cd system $ tar -cpvf ../system.tar * $ cd .. $ umount system

Extract recovery image
$ ./tools/split_bootimg.pl recovery.img Page size: 2048 (0x00000800) Kernel size: 4215036 (0x004050fc) Ramdisk size: 974998 (0x000ee096) Second size: 0 (0x00000000) Board name: Command line: console=ttyS0,115200 rw init=/init loglevel=5 Writing recovery.img-kernel ... complete. Writing recovery.img-ramdisk.gz ... complete.

decompress the ramdisk data $ mkdir recovery $ cd recovery $ gunzip -c ../recovery.img-ramdisk.gz | cpio -i $ tar -cpvf ../recovery.tar * $ cd ..

SD card Partition
Partitions description:

WARNING: At the start we need a 17 MB unallocated partition, required for flash sunxi-spl and u-boot.bin without corrupting the SD.

First identify the device of the card and export it as $card.

$ card=/dev/sdc

dd if=/dev/zero of=$card bs=1M count=1 sfdisk -R $card cat <<EOT | sfdisk --in-order -uM $card 17,16,c ,36,83 ,500,83 ,,5 ,300,83 ,16,83 ,36,83 ,125,83 ,16,83 ,,83 EOT

Format
mkfs.vfat -n bootloader ${card}1 mkfs.ext4 -L boot      ${card}2 mkfs.ext4 -L system    ${card}3 mkfs.ext4 -L data      ${card}5 mkfs.ext4 -L misc      ${card}6 mkfs.ext4 -L recovery  ${card}7 mkfs.ext4 -L cache     ${card}8 mkfs.ext4 -L private   ${card}9 mkfs.vfat -n UDISK     ${card}10

remove huge_file option from EXT4 fs (android kernel not have this option!!!)

tune2fs -O ^huge_file ${card}2 tune2fs -O ^huge_file ${card}3 tune2fs -O ^huge_file ${card}5 tune2fs -O ^huge_file ${card}6 tune2fs -O ^huge_file ${card}7 tune2fs -O ^huge_file ${card}8 tune2fs -O ^huge_file ${card}9

BootLoader
For SD card booting you'll need one of this pair of files for Hackberry:
 * 1GB: sunxi-spl.bin u-boot.bin
 * 512MB: sunxi-spl.bin u-boot.bin

dd if=spl/sunxi-spl.bin of=$card bs=1024 seek=8 dd if=u-boot.bin of=$card bs=1024 seek=32

Note: The above will not work for the Cubieboard A10, you will need to compile u-boot your self.

For Cubieboard A10:

git clone https://github.com/linux-sunxi/u-boot-sunxi.wiki.git make cubieboard_config make

Note: It is recommended for best results that you compile it if you can on the device you plan to use it on.

For cross compilation:

git clone https://github.com/linux-sunxi/u-boot-sunxi.wiki.git make cubieboard_config CROSS_COMPILE=arm-linux-gnueabihf-

Next, install your new u-boot on your sdcard:

dd if=u-boot-sunxi-with-spl.bin of=/dev/sdX bs=1024 seek=8

or if you prefer to install the components separately:

dd if=spl/sunxi-spl.bin of=/dev/sdX bs=1024 seek=8 dd if=u-boot.img of=/dev/sdX bs=1024 seek=40

If you have issues at boot time you will find that setting up debug serial console will help a lot to find your issue.

Reference: https://github.com/linux-sunxi/u-boot-sunxi/wiki

mkdir bootloader mount -o loop bootloader.img bootloader

Copy to SD card
Copy file to bootloader partition

mount ${card}1 /mnt/ cp uImage /mnt cp bootloader/script.bin /mnt cat >/mnt/uEnv.txt << EOT fexfile=script.bin kernel=uImage extraargs=root=/dev/mmcblk0p2 loglevel=8 rootwait console=ttyS0,115200 rw init=/init mac_addr=00:AE:99:A3:E4:AF boot_mmc=fatload mmc 0 0x43000000 ${fexfile}; fatload mmc 0 0x48000000 ${kernel}; bootm 0x48000000 EOT

Recovery uEnv.txt

cat >/mnt/uEnv_recovery.txt << EOT fexfile=script.bin kernel=uImage extraargs=root=/dev/mmcblk0p7 loglevel=8 rootwait console=ttyS0,115200 rw init=/init mac_addr=00:AE:99:A3:E4:AF boot_mmc=fatload mmc 0 0x43000000 ${fexfile}; fatload mmc 0 0x48000000 ${kernel}; bootm 0x48000000 EOT umount /mnt umount bootloader

Copy data to Ramdisk partition mount ${card}2 /mnt tar -xpvf boot.tar -C /mnt

Modify the name partition in init.sun4i.rc

sed -i "s/nandd/mmcblk0p3/g" /mnt/init.sun4i.rc sed -i "s/nande/mmcblk0p5/g"  /mnt/init.sun4i.rc sed -i "s/nandh/mmcblk0p8/g"  /mnt/init.sun4i.rc sed -i "s/nandi/mmcblk0p10/g" /mnt/init.sun4i.rc umount /mnt

Copy data to system partition mount ${card}3 /mnt tar -xpvf system.tar -C /mnt umount /mnt

Copy data to recovery partition mount ${card}7 /mnt tar -xpvf recovery.tar -C /mnt sed -i "s/nandf/mmcblk0p6/g" /mnt/ueventd.sun4i.rc umount /mnt sync

Now you can boot Android from SD card.

Automated Flash Kitchen
Thierry Merle has assembled a Flash Kitchen originally for the Mele A2000 but it also works for other A10 devices.

Download v2 from here: http://tmerle.blogspot.fr/2012/09/mele-a2000-my-own-linux-flash-kitchen.html

After having put the original.img file (PhoenixCard source image), run "make build_sdcard" as root and it should create everything needed to generate the SD card boot files in sdcard/.

Then, you will have to 'cd sdcard/', then run 'make DEV=/dev/sdX' (where X is the device letter of your SD card).

Requirements
Wine - in order to extract/build the flash image (look below for enhancements).

Root access for scripts other than img_1extract.sh/img_2build.sh.

The script will create /system in your root directory. This is necessary if you make symbolic links in "system" filesystem.

Of course, you need an original image (that you will rename as original.img) to start hacking.

Enhancements

 * If you don't have Wine you can use Ithamar's awutils in img_1extract.sh instead of unimg.exe. You can find more info in Awutils.


 * Here's abootimg statically linked and stripped for i386 and amd64: https://www.dropbox.com/s/xbe2u7ai6aqaob1/abootimg_i386+amd64_statically_linked+stripped.tar.xz

i386 is untested natively so to be sure also included are the static libraries libblkid.a and libuuid.a and you might need blkid.h

Change the LDLIBS line in the Makefile as follows:

LDLIBS=-static -lblkid -luuid -L.


 * #!/bin/bash and function function_name work better together in mkA10card.sh


 * "partition ends on cylinder 1023, beyond the end of the disk"

You have to make some adjustments to partitions.txt. It's for a 16 GB SD card and so Disk Utility will show something like Capacity: 18446744 TB (-8,198,815,744 bytes). So you have to calculate partitions.txt yourself.

General information
tar: .: Cannot change ownership to uid 1000, gid 1000: Operation not permitted" FAT does not allow UID, GID and symlinks. You have to copy the files manually.
 * When make fails and you want to run it again: