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

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

Extract file from Android Image
In this guide the name the Android Image is android.img $ awimage -u android.img

this command create an folder 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).

for simplicity rename: $ mv RFSFAT16_BOOT_00000000000 boot.img $ mv RFSFAT16_RECOVERY_0000000 recovery.img $ mv RFSFAT16_SYSTEM_000000000 system.img

Extract kernel and ramdisk
For extract kernel and boot ramdisk 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 *

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 $ sudo 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 *

SdCard Partition
Partitions description:

WARNING: Require at start 17MB unallocated, for flash sunxi-spl and u-boot.bin without corrupt 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
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

Copy File
Copy file to bootloader partition

$ mount ${card}1 /mnt/ $ cp uImage /mnt $ cp 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

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

Now you can boot Android from sd card