使用mfg tool燒寫android5.1的鏡像之后,再使用舊版的mfg tool燒寫linux或者android鏡像,都不能正常啟動,而且運行的uboot還是android5.1版本的uboot。
參考鏈接
http://www.itdadao.com/articles/c15a39492p0.html
http://www.cnblogs.com/heiyue/p/5199851.html#undefined
http://www.cnblogs.com/heiyue/p/5830505.html
https://linux.codingbelief.com/zh/storage/flash_memory/emmc/emmc_partitions.html
https://community.nxp.com/thread/331306
https://freescale.jiveon.com/thread/429311
http://blog.5ibc.net/p/80599.html
emmc boot分區
在同事的幫助下才知道emmc有boot1,boot2以及RPMB(Replay Protected Memory Block),GPAP(General Purpose Area Partitions,最多可以有4個),UDA(User Data Area)分區。而我們一般只知道UDA分區。
我們通常對emmc進行分區,也只是對UDA分區。boot1,boot2,RPMB分區是固定的,我們並不能控制器大小和分區格式。如下圖所示(圖片摘自網絡):

這次的android5.1鏡像將uboot燒寫到了boot1分區,並且將boot1分區使能。那么emmc每次啟動之后就從boot1分區啟動,運行android5.1的uboot,而android5.1的uboot又找不到其對應的kernel等鏡像(因為UDA的區域的鏡像已經燒寫成別的版本),所以就一直卡在啟動的頁面。
並且寫到emmc寄存器中的值是一直保留的,不會因為開機就恢復為默認值。
而原來的工具是將uboot放在UDA分區。
android5.1的mfg tool中,ucl2.xml有那么一段。(我添加了注釋)
<!-- 使emmc的boot0分區變為可讀寫 -->
<CMD state="Updater" type="push" body="$ echo 0 > /sys/block/mmcblk%mmc%boot0/force_ro">access boot partition 1</CMD>
<CMD state="Updater" type="push" body="send" file="files/android/%folder%/u-boot-imx%soc%%plus%.imx" >Sending u-boot.bin</CMD>
<!-- 將uboot燒錄到emmc的boot0分區,在系統盤符里分區的序號是從0開始,也就是boot0, boot1 -->
<CMD state="Updater" type="push" body="$ dd if=$FILE of=/dev/mmcblk%mmc%boot0 bs=512 seek=2">write U-Boot to sd card</CMD>
<!-- 使emmc的boot0分區變為只讀 -->
<CMD state="Updater" type="push" body="$ echo 1 > /sys/block/mmcblk%mmc%boot0/force_ro"> re-enable read-only access </CMD>
<!-- 將boot0分區使能,那么啟動的時候就會從boot1分區啟動,
emmc寄存器序號是從1開始,boot1,boot2.這里的enable 1指的是emmc boot分區的第一個分區,是針對emmc的寄存器而言的。
而上面的/sys/block/mmcblk3boot0指是針對linux系統而言的,其實指的都是統一個分區,就是emmc boot的最開始的分區。
-->
<CMD state="Updater" type="push" body="$ mmc bootpart enable 1 1 /dev/mmcblk%mmc%">enable boot partion 1 to boot</CMD>
emmc boot寄存器
下圖是emmc寄存器設置。
不使能引導,將BOOT_PARTITION_ENABLE設置為0,
使能boot1,將BOOT_PARTITION_ENABLE設置為1,
使能boot2,將BOOT_PARTITION_ENABLE設置為2,
使能UDA,將BOOT_PARTITION_ENABLE設置為7.

解決方法
在uboot中有emmc命令,用於設置emmc的寄存器。uboot版本不同,命令有些不一樣。
FSL 2009.08 U-boot u-boot-fslc branch patches-2014.07
args mmc bootpart mmc partconf dev boot_ack boot_partition partition_access
example for change boot partition to device 2 partition 1:
mmc bootpart 2 1 mmc partconf 2 1 1 1
example for change boot partition to device 2 partition 0:
mmc bootpart 2 0 mmc partconf 2 1 0 1
具體操作如下:
# uboot中首先查看emmc的編號
Tony> mmc list
FSL_SDHC: 0
FSL_SDHC: 1
FSL_SDHC: 2 (eMMC)
# 確定emmc的序號是2
# 查看emmc命令
Tony> mmc
mmc - MMC sub system
Usage:
mmc info - display info of the current MMC device
mmc read addr blk# cnt
mmc write addr blk# cnt
mmc erase blk# cnt
mmc rescan
mmc part - lists available partition on current mmc device
mmc dev [dev] [part] - show or set current mmc device [partition]
mmc list - lists available devices
mmc hwpartition [args...] - does hardware partitioning
arguments (sizes in 512-byte blocks):
[user [enh start cnt] [wrrel {on|off}]] - sets user data area attributes
[gp1|gp2|gp3|gp4 cnt [enh] [wrrel {on|off}]] - general purpose partition
[check|set|complete] - mode, complete set partitioning completed
WARNING: Partitioning is a write-once setting once it is set to complete.
Power cycling is required to initialize partitions after set to complete.
mmc bootbus dev boot_bus_width reset_boot_bus_width boot_mode
- Set the BOOT_BUS_WIDTH field of the specified device
mmc bootpart-resize <dev> <boot part size MB> <RPMB part size MB>
- Change sizes of boot and RPMB partitions of specified device
mmc partconf dev boot_ack boot_partition partition_access
- Change the bits of the PARTITION_CONFIG field of the specified device
mmc rst-function dev value
- Change the RST_n_FUNCTION field of the specified device
WARNING: This is a write-once field and 0 / 1 / 2 are the only valid values.
mmc setdsr <value> - set DSR register value
# 設置emmc的啟動分區,主要是partconf后面的第一個和第三個參數。
# 2是emmc的編號,第三個參數設置啟動的分區,對應寄存器BOOT_PARTITION_ENABLE字段。設為0表示不使能。
Tony> mmc partconf 2 0 0 0
# 或者設置為7表示從UDA啟動, 0和7我都嘗試了,燒錄原來的鏡像都能夠啟動成功。
Tony> mmc partconf 2 0 7 0
或者更改ucl2.xml文件,使能UDA分區。
<!-- 但是設置成0時,燒錄出錯,不知道為什么 -->
<CMD state="Updater" type="push" body="$ mmc bootpart enable 0 1 /dev/mmcblk%mmc%">enable boot partion 1 to boot</CMD>
或者
<!-- 設置成7,燒錄成功,再燒錄原來的系統,能正常運行 -->
<CMD state="Updater" type="push" body="$ mmc bootpart enable 7 1 /dev/mmcblk%mmc%">enable boot partion 1 to boot</CMD>
Author
Tony Liu
2016-11-11, Shenzhen
