dimanche 25 novembre 2012

Booting the Android ICS system from SDCard

Update: from the information below, I recently added the "recovery" partition, so it shifts partition numbers.
The mele flash kitchen_v2 contains scripts to generate the sdcard version, look here:
Mele A2000: my own Linux flash kitchen

Testing new firmwares could be a pain since everything is wiped out at each update.
My idea (an I see some people had the same idea before) is to write the Android partitions on sdcard and boot from it.

There are already Linux distributions that boot from SDCard, like ArchLinux:
http://archlinuxarm.org/platforms/armv7/mele-a100
I have taken this Linux distribution as the base system.

The principle is quite easy: take a SDCard u-boot, give it the Android kernel, create the Android partitions on SDCard, fill them to make Android happy, change all "nandx" references by "mmcblk0px" in init scripts.

The Android system boots and does not need any access to NAND, a good point since I can test firmwares without affecting my flashed one.

Partitioning

Under linux, I have partitioned the SDCard (SDHC class 10, for boot speed) with fdisk.
Here is the resulting partitions:

Note that a free space of 16MB is kept at start of sdcard, it embeds the spl bootloader
I put 4GB for "data" and 10GB for /sdcard (16GB SDCard gives lot of space).
Exact size doesn't matter; if you set to 15,95MB one partition, that's not a big issue. The important thing is the number of partitions, see below.

So the matching nand-sdcard partitions are:

-nand- -sdcard-   -name-      -format-
nanda  mmcblk0p1  bootloader  vfat
nandb  -N/A-      env
nandc  mmcblk0p2  boot        ext4
nandd  mmcblk0p3  system      ext4
nande  mmcblk0p5  data        ext4
nandf  mmcblk0p6  misc        ext4
nandg  -N/A-      recovery
nandh  mmcblk0p7  cache       ext4
nandi  mmcblk0p8  private     vfat 
nandj  -N/A-      sysrecovery
nandk  mmcblk0p9  UDISK       vfat

Note: I just found out that link: http://linux-sunxi.org/Android/partitions
Almost same thing...
Note(2): under linux, mmcblk0p1 is /dev/sdb1, mmcblk0p2 is /dev/sdb2, ...

Filling partitions

Then I formatted partitions using mkfs.vfat for FAT partitions, and mkfs.ext4 for ext4 partitions that need to be formatted (look at the above table for the ones that need to be formatted, the others will be formatted by Android).
Then, from ArchlinuxARM/Mele-Bootloader I did:
# write SPL
dd if=sun4i-spl.bin of=$DRIVE bs=1024 seek=8
# write mele u-boot
dd if=mele-u-boot.bin of=$DRIVE bs=1024 seek=32
where DRIVE is /dev/sdb is sdcard is on sdb.

In the bootloader partition, I put the Mele's script.bin, and the Mele's kernel (the 3.0.8+ one), transformed into a u-boot image using this:
mkimage -A ARM -C none -T kernel -O linux  -a 40008000 -e 40008000 -d zImage uImage
I added uEnv.txt:
boot_mmc=fatload mmc 0 0x43000000 ${fexfile}; fatload mmc 0 0x48000000 ${kernel}; bootm 0x48000000
extraargs=rootwait init=/init mac_addr=00:BA:D0:MA:C0:FF
fexfile=script.bin

The "boot" partition contains the initrd contents of root.fex, and must be in mmcblk0p2 (default root partition of the spl u-boot, you can change it with root=xxx in extraargs variable)

The "system" partitions contents the files of the /system partition (system.fex mounted partition)
That's all.

Changing init scripts

In "boot" partition, you need to edit init.sun4i.rc and uevent.sun4i.rc, to change all "nandX" references into "mmcblk0pN" references conforming to the above table.
grep -r nand * shows you all the files that need to be modified.

In the same manner, change /system:
bin/sop.sh
bin/preinstall.sh
bin/data_resume.sh
etc/vold.fstab

The proof

Here is the mount table from my functional system:
root@android:/ # busybox mount                                                                                                      
rootfs on / type rootfs (rw)                                                                                                        
/dev/root on / type ext4 (ro,relatime,user_xattr,barrier=1,data=ordered)                                                            
devtmpfs on /dev type devtmpfs (rw,relatime,size=156796k,nr_inodes=39199,mode=755)                                                  
tmpfs on /dev type tmpfs (rw,nosuid,relatime,mode=755)                                                                              
devpts on /dev/pts type devpts (rw,relatime,mode=600,ptmxmode=000)                                                                  
proc on /proc type proc (rw,relatime)                                                                                               
sysfs on /sys type sysfs (rw,relatime)                                                                                              
tmpfs on /mnt type tmpfs (rw,relatime,mode=777,gid=1000)                                                                            
tmpfs on /mnt/asec type tmpfs (rw,relatime,mode=755,gid=1000)                                                                       
tmpfs on /mnt/obb type tmpfs (rw,relatime,mode=755,gid=1000)                                                                        
/dev/block/mmcblk0p3 on /system type ext4 (ro,relatime,user_xattr,barrier=0,data=ordered)                                           
/dev/block/mmcblk0p5 on /data type ext4 (rw,nosuid,nodev,noatime,user_xattr,barrier=0,journal_checksum,data=ordered,noauto_da_alloc)
/dev/block/mmcblk0p7 on /cache type ext4 (rw,nosuid,nodev,noatime,user_xattr,barrier=0,journal_checksum,data=ordered,noauto_da_alloc
)                                                                                                                                   
/dev/block/mmcblk0p8 on /mnt/private type vfat (rw,relatime,fmask=0000,dmask=0000,allow_utime=0022,codepage=cp437,iocharset=ascii,sh
ortname=mixed,errors=remount-ro)                                                                                                    
/dev/block/vold/179:1 on /mnt/extsd/179_1 type vfat (rw,dirsync,nosuid,nodev,noexec,relatime,uid=1000,gid=1023,fmask=0702,dmask=0702
,allow_utime=0020,codepage=cp437,iocharset=ascii,shortname=mixed,utf8,errors=remount-ro)                                            
/dev/block/vold/179:6 on /mnt/extsd/179_6 type vfat (rw,dirsync,nosuid,nodev,noexec,relatime,uid=1000,gid=1023,fmask=0702,dmask=0702
,allow_utime=0020,codepage=cp437,iocharset=ascii,shortname=mixed,utf8,errors=remount-ro)                                            
/dev/block/vold/179:8 on /mnt/extsd/179_8 type vfat (rw,nosuid,nodev,noexec,relatime,fmask=0000,dmask=0000,allow_utime=0022,codepage
=cp437,iocharset=ascii,shortname=mixed,errors=remount-ro)                                                                           
/dev/block/vold/179:9 on /mnt/extsd/179_9 type vfat (rw,dirsync,nosuid,nodev,noexec,relatime,uid=1000,gid=1023,fmask=0702,dmask=0702
,allow_utime=0020,codepage=cp437,iocharset=ascii,shortname=mixed,utf8,errors=remount-ro)                                            

And the storage screenshot:

15 commentaires:

  1. Ce commentaire a été supprimé par l'auteur.

    RépondreSupprimer
    Réponses
    1. You beat me in achieving this. I could boot the Mele but your procedure
      is more functional.

      However I am unable to get the sound to work and video playback also does not work. Sometimes I get a message there is no external SD card.

      Does this happen with you? Would like to see if we can do something further on this. I could not get your mail id; can you plz mail me nanditamanohar at gmail com .

      Supprimer
  2. Thierry you said this:

    But there may be a way to improve A/V sync by patching the kernel.
    I found this thread:
    http://scrolltabletforum.co.uk/site/viewtopic.php?f=48&t=1964&start=90#p24948
    The thread is originally a patch for the Allwinner A10 Gingerbread firmware. But this post is a firmware containing ICS version. Downloading, to see what kernel is included.

    A user answer this:

    Daniel Flosa14 novembre 2012 21:21
    This update worked for me. Thanks Thierry. Defo a keeper. I installed it on a a3600. Tested videos all working specially on stock video player TvdVideo. Bit faster/snappier. All sounds perfect..louder than previous versions. Only complain from the kids is Bad Piggies not working :D.

    Thanks again and excellent work.





    Now, i ask to you, how i can use this patch?
    I have to flash from ClockWorkMOD?
    Or what?

    Thanks for the help, Gabriele.

    RépondreSupprimer
    Réponses
    1. Hmm.. no, the answer is not related to my suggestion.
      The user "Varun" was complaining against the A/V sync:
      http://tmerle.blogspot.fr/2012/11/melehtpc0929betav13-revised-version.html?showComment=1352470531629#c7678808432807877607
      I suggested a firmware for another device, but did not find time to analyse it.
      Daniel was commenting the v4 firmware, but not this fix.

      Supprimer
  3. Ok, thanks for the explaination :)
    Gabriele.

    RépondreSupprimer
  4. i dont understand these two steps...Please help

    The "boot" partition contains the initrd contents of root.fex, and must be in mmcblk0p2 (default root partition of the spl u-boot, you can change it with root=xxx in extraargs variable)

    The "system" partitions contents the files of the /system partition (system.fex mounted partition)

    should i extract the img file and put in sdcard or should copy the img file directly...?

    Thanks for this great tutorial.

    RépondreSupprimer
    Réponses
    1. Well, you can simply perform a make build_sdcard after having renamed the .img file as original.img, at the mele flash kitchen root.

      In the sdcard/tmp/boot subdirectory, you must put the extracted rootfs.fex (use abootimg -x to extract rootfs.fex).
      The sdcard/tmp/system subdirectory must contain the system.fex directory.

      But if you read the Makefile, you will see all the commands to do in sequence.

      Supprimer
    2. It worked thank you...Now if i want to change the sdcard(UDISK) size in the nand itself what should i do?which file i should edit before giving the "pack" command?

      Supprimer
    3. Well done! You mean change the nandk partition size? The size of UDISK in nand is automatically set depending on the complete nand size (remaining after nandj). Another solution to get space on /sdcard

      vold.fstab the proper

      partition...

      Supprimer
    4. Yes..I have 2GB space for nandk in my device but i want to split it into two 1 GB ie: nandk-1GB and nandl-1GB. So that i can have two SDcard. Is it possible having a nandl partition? or the partition count matters in android as you said above.

      Supprimer
    5. IMHO it should be possible. The strong requirement is sufficient partitions. If there are more, it should not harm.
      The question is how to resize nandk and create nandl... I really don't know...

      Supprimer
  5. hello Thierry :)

    (i'm noobs in android/linux) I have a question;
    I see your instructions are very clear; but i want to do the same for Android Tablet having ICS n kernel 3.0.8;

    What I want to do is.... boot Ubantu from SD card with 3.0.26 or higher kernel while retaining present ICS with 3.0.8 kernel ;

    So that I can use both Android and Ubantu with different kernels
    Can this be achieved by your instructions?

    Thanks in advance:)

    RépondreSupprimer
  6. What useful information for me. Thank you for the tips. It really helped a lot

    Judithpof
    sd card recovery mac serial

    RépondreSupprimer