dm37xx android2.3.4增加recovery升級功能(一) —— 代碼修改

來源:互聯網
上載者:User

轉載請註明文章出處和作者!

出處:http://blog.csdn.net/xl19862005

作者:大熊(Xandy)


今天在給TI omap3的android系統增加recovery模式升級功能時發現,這部分TI根本沒有做,只能自己來處理了,參照以前freescale i.mx53平台的做法,分別修改bootloader及recovery包,現在將工作過程記錄如下:
1、bootloader部分修改
1.1、增加cache及recovery分區
/* Initialize the name of fastboot flash name mappings */
fastboot_ptentry ptn[] = {
{
.name   = "xloader",
.start  = 0x0000000,
.length = 0x0020000,
/* Written into the first 4 0x20000 blocks
  Use HW ECC */
.flags  = FASTBOOT_PTENTRY_FLAGS_WRITE_I |
         FASTBOOT_PTENTRY_FLAGS_WRITE_HW_ECC |
 FASTBOOT_PTENTRY_FLAGS_HW_ECC_LAYOUT_2 |
 FASTBOOT_PTENTRY_FLAGS_REPEAT_4,
},
{
.name   = "bootloader",
.start  = 0x0080000,
.length = 0x01C0000,
/* Skip bad blocks on write
  Use HW ECC */
.flags  = FASTBOOT_PTENTRY_FLAGS_WRITE_I |
         FASTBOOT_PTENTRY_FLAGS_WRITE_HW_ECC |
 FASTBOOT_PTENTRY_FLAGS_HW_ECC_LAYOUT_2,
},
{
.name   = "environment",
.start  = SMNAND_ENV_OFFSET,  /* set in config file */
.length = 0x0040000,
.flags  = FASTBOOT_PTENTRY_FLAGS_WRITE_HW_ECC |
 FASTBOOT_PTENTRY_FLAGS_HW_ECC_LAYOUT_1 |
 FASTBOOT_PTENTRY_FLAGS_WRITE_ENV,
},
{
.name   = "kernel",
/* Test with start close to bad block
  The is dependent on the individual board.
  Change to what is required */
/* .start  = 0x0a00000, */
/* The real start */
.start  = 0x0280000,
.length = 0x0500000,
.flags  = FASTBOOT_PTENTRY_FLAGS_WRITE_HW_ECC |
         
FASTBOOT_PTENTRY_FLAGS_HW_ECC_LAYOUT_1 |
  FASTBOOT_PTENTRY_FLAGS_WRITE_I,
},
{
.name = "cache",
/* Test with start close to bad block
  The is dependent on the individual board.
  Change to what is required */
/* .start  = 0x0a00000, */
/* The real start */
.start
= 0x00780000,
.length = 0x0100000,
.flags
= FASTBOOT_PTENTRY_FLAGS_WRITE_HW_ECC |
FASTBOOT_PTENTRY_FLAGS_HW_ECC_LAYOUT_1 |
FASTBOOT_PTENTRY_FLAGS_WRITE_I,
},
{
.name = "recovery",
/* Test with start close to bad block
  The is dependent on the individual board.
  Change to what is required */
/* .start  = 0x0a00000, */
/* The real start */
.start
= 0x00880000,
.length = 0x06400000, //100MiB 這裡經修改,為什麼要修改成這樣,在後面將會說明
.flags= FASTBOOT_PTENTRY_FLAGS_WRITE_HW_ECC |
FASTBOOT_PTENTRY_FLAGS_HW_ECC_LAYOUT_1 |
FASTBOOT_PTENTRY_FLAGS_WRITE_I,
},
{
.name   = "system",
.start  = 0x06C80000,
.length = 0x10000000,
.flags  = FASTBOOT_PTENTRY_FLAGS_WRITE_HW_ECC |
         
FASTBOOT_PTENTRY_FLAGS_HW_ECC_LAYOUT_1 |
      FASTBOOT_PTENTRY_FLAGS_WRITE_I,
},
};
注意這裡的start及length之間的關係,length一定要比所將要刷入該分區的img檔案大,編譯後我的recovery.img大小為2.3M左右,這裡我分區了recovery分區5M的大小。

分區的修改要與核心中的一致,如我的核心裡修改成了如下:

static struct mtd_partition zt6810_nand_partitions[] = {
/* All the partition sizes are listed in terms of NAND block size */
{
.name = "X-Loader",
.offset
= 0,
.size = 0x00020000,// 4 * NAND_BLOCK_SIZE,
.mask_flags
= MTD_WRITEABLE, /* force read-only */
},
{
.name = "U-Boot",
.offset
=  0x0080000,//MTDPART_OFS_APPEND, /* Offset = 0x80000 */
.size = 0x001C0000,//10 * NAND_BLOCK_SIZE,
.mask_flags
= MTD_WRITEABLE, /* force read-only */
},
{
.name = "U-Boot Env",
.offset
= 0x260000,//MTDPART_OFS_APPEND, /* Offset = 0x1c0000 */
.size = 0x00040000,//6 * NAND_BLOCK_SIZE,
},
{
.name = "Kernel",
.offset
= 0x0280000,//MTDPART_OFS_APPEND, /* Offset = 0x280000 */
.size = 0x00500000,//40 * NAND_BLOCK_SIZE,
},
{
.name = "cache",/*Xandy add for recovery cache*/
.offset = 0x00780000,//MTDPART_OFS_APPEND,/* Offset = 0x280000 */
.size = 0x00100000,//5 * NAND_BLOCK_SIZE,
},
{
.name = "recovery",/*Xandy add for recovery */

.offset = 0x00880000,//MTDPART_OFS_APPEND,/* Offset = 0x280000 */
.size = 0x06400000,/*100MiB*///40 * NAND_BLOCK_SIZE,
},
{
.name = "File System",
.offset
= 0x06C80000,//MTDPART_OFS_APPEND, /* Offset = 0x780000 */
.size = MTDPART_SIZ_FULL,
},
};
1.2、修改bootcommand
/*ubi.mtd=5 指示整個系統的根檔案系統在第五個mtd 上
**與board/csst/zt6810.c中的fastboot_ptentry ptn 分區一一對應
***/

/*Xandy add for recovery*/
/* Nand flash boot */
#define CONFIG_ANDROID_RECOVERY_BOOTARGS_NAND \
"setenv bootargs ${bootargs} init=/init console=ttyO2,115200n8 noinitrd ip=off " \
"rootwait mem=512M rw ubi.mtd=5,2048 rootfstype=ubifs root=ubi0:rootfs rootdelay=2 " \
"omapdss.def_disp=lcd " \
"vram=8M omapfb.vram=0:8M mpurate=1000\0" 
#define CONFIG_ANDROID_RECOVERY_BOOTCMD_NAND  \
"run bootargs_android_recovery;nand read ${loadaddr} 280000 500000;bootm"

#define CONFIG_ANDROID_RECOVERY_CMD_FILE "/recovery/command"

#define CONFIG_ANDROID_SYSTEM_PARTITION_MMC 2
#define CONFIG_ANDROID_RECOVERY_PARTITION_MMC 4
#define CONFIG_ANDROID_CACHE_PARTITION_MMC 6
#endif

/*"bootargs=init=/init console=ttyO2,115200n8 no_console_suspend noinitrd ip=off "
*no_console_suspend 系統suspend後串口不休眠  
*/ 

#ifdef CONFIG_SYS_USE_UBI
#define CONFIG_EXTRA_ENV_SETTINGS \
"loadaddr=0x82000000\0" \
"nandboot=echo Booting from nand ...; " \
"nand read ${loadaddr} 280000 500000; bootm ${loadaddr}\0" \
"bootcmd=run nandboot\0" \
"bootargs=init=/init console=ttyO2,115200n8 noinitrd ip=off " \
"androidboot.console=ttyO2 rootwait mem=512M rwubi.mtd=6,2048 " \
"rootfstype=ubifs root=ubi0:rootfs rootdelay=2 " \
"omapdss.def_disp=lcd " \
"vram=8M omapfb.vram=0:8M mpurate=1000\0"    
     
#endif
這裡要注意
ubi.mtd=6,2048,這個參數的設定,ubi.mtd=x,這裡的x與1.1中的的分區一一對應,分區編號從0開始!
1.3、添加librecovery.a
這部分直接從freescale的bootloader裡把recovery.c及.h檔案copy過來進行修改,一開始我將這些檔案放在board/(vendor)/recovery目錄下(這裡的vendor目錄對應當前工程目錄)並增加相應的Makefile,在編譯的時候發現這部分源碼怎麼了不參考編譯,後來查看bootloader根目錄下的Makefile檔案發現有如下內容:
LIBS += $(shell if [ -f board/$(VENDOR)/common/Makefile ]; then echo \
"board/$(VENDOR)/common/lib$(VENDOR).a"; fi)
所以才發現自己沒有將所加入的檔案沒有加入根目錄下的Makefile裡面,所以無法得到期望的.a檔案,果斷將recovery目錄重新命名成common,再將編譯,OK,通過。
1.4、在start_armboot中加入進入recovery系統的判斷
void start_armboot (void)
{
.
.
.
.
#ifdef CONFIG_ANDROID_RECOVERY
check_recovery_mode();
#endif

#if defined(CONFIG_CMD_NET)
#if defined(CONFIG_NET_MULTI)
puts ("Net:   ");
#endif
eth_initialize(gd->bd);
#if defined(CONFIG_RESET_PHY_R)
debug ("Reset Ethernet PHY\n");
reset_phy();
#endif
#endif
/* main_loop() can return to retry autoboot, if so just run it again. */
for (;;) {
main_loop ();
}

/* NOTREACHED - no way out of command loop except booting */
}
check_recovery_mode是如何判斷是否要進行到recovery的模式的呢?
這部分內容在我去年寫的《android recovery模式及ROM製作》這篇部落格裡有詳細的介紹,原文地址:

http://blog.csdn.net/xl19862005/article/details/8517918




聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.