DM37xx android2.3.4增加recovery升级功能(一) —— 代码修改

来源:互联网 发布:python编写登录界面 编辑:程序博客网 时间:2024/05/03 09:22

转载请注明文章出处和作者!
出处: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

原创粉丝点击