User:Arete74/Boot Android from SdCard
Boot Android From SdCard
For extract need file from android image , have need of awutils and android tools.
$ git clone https://github.com/Ithamar/awutils.git $ 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 -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:
partition | Size | Name | Fs | Description |
---|---|---|---|---|
/dev/sdc1 | 16MiB | bootloader | VFAT | Files to assist the bootloader. |
/dev/sdc2 | 36MiB | boot | EXT4 | ramdisk |
/dev/sdc3 | 500 MiB | system | EXT4 | Android's /system partition |
/dev/sdc4 | Fill all space | extend | Extend Partition | |
/dev/sdc5 | 300MiB | data | EXT4 | |
/dev/sdc6 | 16 MiB | misc | EXT4 | |
/dev/sdc7 | 36 Mib | recovery | EXT4 | Android's recovery partition |
/dev/sdc8 | 125 MiB | cache | EXT4 | |
/dev/sdc9 | 16 MiB | private | EXT4 | |
/dev/sdc10 | 1-2 GiB | UDISK | VFAT |
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 1,16,c ,36,83 ,63,83 ,,5 ,300,83 ,16,83 ,36,83 ,125,83 ,16,83 ,,83 EOT
Format
$ mkfs.vfat -n bootloader /dev/sdc1 $ mkfs.ext4 -L boot /dev/sdc2 $ mkfs.ext4 -L system /dev/sdc3 $ mkfs.ext4 -L data /dev/sdc5 $ mkfs.ext4 -L misc /dev/sdc6 $ mkfs.ext4 -L recovery /dev/sdc7 $ mkfs.ext4 -L cache /dev/sdc8 $ mkfs.ext4 -L private /dev/sdc9 $ mkfs.vfat -n UDISK /dev/sdc10
remove huge_file option from EXT4 fs (android kernel not have this option!!!)
$ tune2fs -O ^huge_file /dev/sdc2 $ tune2fs -O ^huge_file /dev/sdc3 $ tune2fs -O ^huge_file /dev/sdc5 $ tune2fs -O ^huge_file /dev/sdc6 $ tune2fs -O ^huge_file /dev/sdc7 $ tune2fs -O ^huge_file /dev/sdc8 $ tune2fs -O ^huge_file /dev/sdc9
BootLoader
$ 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 $ 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
Now you can boot Android from sd card