AM335x Android eMMC booting

'''  Content is no longer maintained and is being kept for reference only! ''' = Introduction = '''  Content is no longer maintained and is being kept for reference only! '''
 * AM335xEVM has on board NAND and MMC interface. Either interface can be used for booting a system.
 * NAND boot is raw boot, as it reads raw data and manipulates it.
 * MMC boot is FAT boot, as it reads file from MMC sector and manipulates it.
 * MMC and NAND boot is already supported by android devkit releases available at http://arowboat.org.
 * This wiki highlights on:
 * Using the available MMC interface on the AM335xEVM to simulate the eMMC functionality.
 * Adding eMMC support for fastboot.
 * Updating images to eMMC over fastboot.
 * Boot android from eMMC using RAW boot technique.
 * Wiki will also act as porting guide to port eMMC support on other platforms.

All patches described in this documents are validated on Texas Instruments' AM335xEVM board.

= What is eMMC? = eMMC describes an architecture consisting of an embedded storage solution with MMC interface, flash memory and controller. In one line it is a flash/NAND over MMC interface.

The OMAP processor follows a 2 stage boot process. Details on the boot procedure can be found at the boot sequence page.

= What is fastboot? =
 * Fastboot is the method that android uses to flash the android built onto the target.
 * Fastboot protocol specification is found here.
 * Fastboot speeds up your development NOT the time it takes to boot.
 * Also, fastboot is used to update x-loader, bootloader, kernel, systemfs, userdata etc. by oem.

= eMMC layout = In the discussion that follows, “sector” refers to a 512-byte disk sector, addressed by its Logical Block Address (LBA). Although the UEFI specs allow for disk sectors of other sizes, in practice 512 bytes is the norm.

Protective master boot record
The master boot record is the first sector on the hard drive (LBA 0). As mentioned above, legacy BIOSes will boot from this sector. To protect the GUID partitions on the drive from legacy OSes, the MBR partition table normally contains a single partition entry of type 0xEE, filling the entire drive.

GUID Partition Table (GPT)
The second sector (LBA 1) contains the primary GPT header, followed immediately by 16K (32 sectors) of the primary GUID Partition Entry Array. In conformance with the EFI spec, another copy of these data should be located at the end of the disk as well, with the secondary GPT header in the last accessible sector and the secondary GUID Partition Entry Array immediately preceding it. In current implementation secondary GPT is not included.

eMMC partition layout

 * GPT allows a large number of partitions on a drive. Choosing a partition scheme may vary across OEM vendor. Partition scheme described here is most chosen by OEM for mobile/hand-held device for a 1GB eMMC.

= Fastboot flowchart = 500px

= Support for eMMC fastboot update and raw boot on AM335xEVM =

Prepare the u-boot source code
/* download u-boot source, if not available */ $git clone git://gitorious.org/rowboat/u-boot.git $cd u-boot
 * Download source (if it is not downloaded).

/* checkout mentioned commit id, branch:am335x-master-android-ics */ $git checkout 429a3860feea2711d3f1561ac1a431b849f45729

Selection of eMMC boot or NAND boot in u-boot
With the u-boot with the eMMC RAW boot patches integrated, has support for RAW booting from eMMC and flashing the images to eMMC through Fastboot for AM335x.

Enable "#define CONFIG_STORAGE_EMMC" Disable "#define FASTBOOT_PORT_OMAPZOOM_NAND_FLASHING" Disable "#define CONFIG_STORAGE_EMMC" Enable "#define FASTBOOT_PORT_OMAPZOOM_NAND_FLASHING" When eMMC boot mode is enabled, the normal SD/MMC FAT boot will not work. For getting the SD?MMC FAT boot user has to enable the configuration for NAND boot.
 * The code is enabled for SD/MMC boot by default. Also it can be used for NAND boot by loading the images to NAND using Fastboot.
 * For enabling eMMC booting with Fastboot, do the following modifications in "include/configs/am335x_evm.h":
 * And for NAND boot with Fastboot, do the following modifications in "include/configs/am335x_evm.h":

Selection of MMC0 or MMC1 as boot device for eMMC Raw boot on AM335xEVM
SW3 (8:1): 11100011 (ON | ON | ON | OFF | OFF | OFF | ON | ON) This will change the SYSBOOT[4:0] to 11100
 * The AM335x General Purpose EVM has two SD/MMC connectors.
 * The SD/MMC0 connector is placed on the Base board and is available for all the 7 Profile modes.
 * The SD/MMC1 connector is placed on the General purpose Daughterboard and is available only on Profile 2.
 * The code adds two Macros to the board config file (include/configs/am335x_evm.h), named:
 * CONFIG_USE_MMC0: To enable the SD/MMC0 as the boot device.
 * CONFIG_USE_MMC1: To enable the SD/MMC1 as the boot device.
 * By default when the CONFIG_STORAGE_EMMC boot option is enabled the MMC0 device gets selected as the boot medium.
 * For eMMC booting support for SD/MMC0 or SD/MMC1 the boot mode switch should be set as:
 * Also configure the AM335xEVM to Profile 2 mode, in order to enable both the MMC slots.
 * All the binaries can be flashed to the device, with the eMMC card interfaced to the respective slot, as per the enabled Macro in the board config file, using fastboot.
 * After flashing those binaries, on reboot the device boots Android through the raw read from the eMMC.

u-boot build
$make CROSS_COMPILE=arm-eabi- distclean $make CROSS_COMPILE=arm-eabi- am335x_evm_config $make CROSS_COMPILE=arm-eabi- The above commands will generate MLO and u-boot.img files. $dd if= of=./MLO.final $dd if=/MLO of=./MLO.final conv=notrunc oflag=append
 * Build u-boot (both MLO and u-boot.img)
 * Append eMMC raw header to MLO
 * Download eMMC raw header here (right click and "save link as").

Prepare the kernel source code
/* download kernel source, if not available */ $git clone git://gitorious.org/rowboat/kernel.git $cd kernel
 * Download source (if it is not downloaded).

/* checkout mentioned commit id, branch:rowboat-am335x-kernel-3.2 */ $git checkout 27694c7773a621dd8616dbbc741b5e978e36034a

kernel build
$make ARCH=arm CROSS_COMPILE=arm-eabi- distclean $make ARCH=arm CROSS_COMPILE=arm-eabi- am335x_evm_android_defconfig $make ARCH=arm CROSS_COMPILE=arm-eabi- uImage
 * Build kernel

Build android file system

 * Follow build steps mentioned here.

= Prepare Images =

boot.img
$mkdir /images $cd /images $cp /kernel/arch/arm/boot/zImage. on fs   mount ext4 /dev/block/mmcblk0p6 /system wait ro    mount ext4 /dev/block/mmcblk0p8 /data wait noatime nosuid nodev mount ext4 /dev/block/mmcblk0p7 /cache wait noatime nosuid nodev $cd  $find out/target/product/am335xevm -name *.img -exec rm -f {} \; $make TARGET_PRODUCT=am335xevm OMAPES=4.x $cd /images $cp /out/target/product/am335xevm/ramdisk.img. $cp /out/host/linux-x86/bin/mkbootimg. $./mkbootimg --kernel zImage --ramdisk ramdisk.img --base 0x80000000 --cmdline "console=ttyO0,115200n8 androidboot.console=ttyO0 mem=256M root=/dev/ram0 rw initramfs=0x81000000,8M init=/init ip=off omap_vout.vid1_static_vrfb_alloc=y vram="2M" omapfb.vram=0:2M" -o boot.img
 * Update init.rc file and rebuild images
 * Add following lines to /out/target/product/am335x3evm/root/init.rc
 * Rebuild images
 * Prepare boot.img

system.img
$cd /images /* creating 192MB, it can be configure as per need */ $dd if=/dev/zero of=./system.img bs=1M count=192 $mkfs.ext4 system.img $mkdir mnt-point $sudo mount -t ext4 -o loop system.img mnt-point/ $cp -rfp /out/target/product/am335xevm/system/* mnt-point/ $sudo umount mnt-point

userdata.img
$cd /images /* creating 192MB, it can be configure as per need */ $dd if=/dev/zero of=./userdata.img bs=1M count=192 $mkfs.ext4 userdata.img $sudo mount -t ext4 -o loop userdata.img mnt-point/ $cp -rfp /out/target/product/am335xevm/data/* mnt-point/ $cp -rfp /out/target/product/am335xevm/root/data/* mnt-point/ $sudo umount mnt-point

cache.img
$cd /images /* creating 192MB, it can be configure as per need */ $dd if=/dev/zero of=./cache.img bs=1M count=192 $mkfs.ext4 cache.img

=Using Fastboot=

Creating the GPT table on eMMC and flash raw images
Fastboot entered...
 * Create MMC card for FAT boot mentioned here.
 * On Target
 * 1) Connect target to host machine using USB cable. Connect USB cable to OTG port on target.
 * 2) Boot target and enter any key at the U-boot prompt.
 * 3) At the u-boot prompt enter following command:
 * 1) fastboot

/* locate fastboot in android filesystem */ $cd <ANDROID_SOURCE>/out/host/linux-x86/bin/
 * On Host Machine

/* search for fastboot devices */ $./fastboot devices

/* create GPT table on eMMC/SD card */ $./fastboot oem format

/* flash all partitions: ./fastboot flash */

/* flash SPL */ $./fastboot flash spl <YOUR_PATH>/images/MLO.final

/* flash bootloader */ $./fastboot flash bootloader <YOUR_PATH>/images/u-boot.img

/* flash boot image */ $./fastboot flash boot <YOUR_PATH>/images/boot.img

/* flash file system - system image */ $./fastboot flash system <YOUR_PATH>/images/system.img

/* flash user data */ $./fastboot flash userdata <YOUR_PATH>/images/userdata.img

/* flash cache partition */ $./fastboot flash cache <YOUR_PATH>/images/cache.img

/* reboot target */ $./fastboot reboot

Flashing of system.img, userdata.img, cache.img, each may take around 10-12 minutes.

= How to change GPT(GUID Partition Table) configuration = static struct partition partitions[] = { { "-", 128 },       { "spl", 128 }, { "bootloader", 512 }, /* "misc" partition is required for recovery */ { "misc", 128 }, { "-", 128 },       { "recovery", 8*1024 }, { "boot", 8*1024 }, { "system", 256*1024 }, { "cache", 256*1024 }, { "userdata", 256*1024}, { "media", 0 }, { 0, 0 }, };
 * GPT configuration has been defined in "<ANDROID_PATH>/u-boot/board/ti/am335x/mmc.c" as below. Kindly change as per need

Technical Support and Product Updates
For further information or to report any problems, contact http://e2e.ti.com/android http://support.ti.com

For community support join http://groups.google.com/group/rowboat For IRC #rowboat on irc.freenode.net