OpenHarmony 升级解读之uboot源码 原创 精华
民之码农
发布于 2022-1-31 18:23
浏览
7收藏
春节不停更,此文正在参加「星光计划-春节更帖活动」
OpenHarmony 3.1Beta版本标准系统升级uboot源码解读
@[toc](内容
一、uboot标准升级处理
1.代码位置
device\hisilicon\third_party\uboot\u-boot-2020.01\board\hisilicon\hi3516dv300\hi3516dv300.c
2.misc_init_r函数对升级进行处理
int misc_init_r(void)
{
const char cmdBuf[] = "mmc read 0x0 0x80000000 0x800 0x4800; bootm 0x80000000";
#ifdef CONFIG_RANDOM_ETHADDR
random_init_r();
#endif
env_set("verify", "n");
#if (CONFIG_AUTO_UPDATE == 1)
if (EmmcInitParam() == -1) {
return 0;
}
ReadMiscLogoBuffer();
ChangeBootArgs();
env_set("bootargs", g_bootArgsStr);
env_set("bootcmd", cmdBuf);
misc_init_r 函数中重新设置bootarg和bootcmd的参数
3.EmmcInitParam函数对标准系统升级进行处理
int EmmcInitParam(void) // get "boot_updater" string in misc,then set env
{
const char rebootHead[] = "mem=640M console=ttyAMA0,115200 mmz=anonymous,0,0xA8000000,384M "
"clk_ignore_unused androidboot.selinux=permissive skip_initramfs rootdelay=10 hardware=Hi3516DV300 "
"default_boot_device=soc/10100000.himci.eMMC init=/init "
"root=/dev/ram0 blkdevparts=";
const char defaultRebootStr[] = "mem=640M console=ttyAMA0,115200 mmz=anonymous,0,0xA8000000,384M "
"clk_ignore_unused androidboot.selinux=permissive skip_initramfs rootdelay=10 hardware=Hi3516DV300 "
"default_boot_device=soc/10100000.himci.eMMC init=/init "
"root=/dev/ram0 blkdevparts=mmcblk0:1M(boot),15M(kernel),20M(updater),"
"2M(misc),3307M(system),256M(vendor),-(userdata)";
const char updaterHead[] = "mem=640M console=ttyAMA0,115200 mmz=anonymous,0,0xA8000000,384M clk_ignore_unused "
"androidboot.selinux=permissive skip_initramfs "
"rootdelay=10 hardware=Hi3516DV300 default_boot_device=soc/10100000.himci.eMMC init=/init root=/dev/mmcblk0p3 "
"rootfstype=ext4 rw blkdevparts=";
const char defaultUpdaterStr[] = "mem=640M console=ttyAMA0,115200 mmz=anonymous,0,0xA8000000,384M "
"clk_ignore_unused androidboot.selinux=permissive skip_initramfs rootdelay=10 hardware=Hi3516DV300 "
"default_boot_device=soc/10100000.himci.eMMC init=/init "
"root=/dev/mmcblk0p3 rootfstype=ext4 rw blkdevparts=mmcblk0:1M(boot),15M(kernel),20M(updater),"
"2M(misc),3307M(system),256M(vendor),-(userdata)";
char block2[EMMC_SECTOR_SIZE*EMMC_SECTOR_CNT];
if (BlkDevRead(block2, MISC_LOCATION*(M_1/EMMC_SECTOR_SIZE), EMMC_SECTOR_CNT) < 0) {
return -1;
}
struct UpdateMessage *p = (struct UpdateMessage *)block2;
block2[MAX_COMMAND_SIZE - 1] = block2[MAX_COMMAND_SIZE + MAX_UPDATE_SIZE - 1] =
block2[EMMC_SECTOR_SIZE * EMMC_SECTOR_CNT - 1] = 0;
p->command[0] = p->command[0] == ((char)-1) ? 0 : p->command[0];
p->update[0] = p->update[0] == ((char)-1) ? 0 : p->update[0];
block2[PARTITION_INFO_POS] = block2[PARTITION_INFO_POS] == (char)-1 ? 0 : block2[PARTITION_INFO_POS];
block2[PARTITION_INFO_POS + PARTITION_INFO_MAX_LENGTH] = 0;
g_isRecovery = 0;
if ((memcmp(p->command, "boot_updater", UPDATE_BOOT_LENGTH) == 0)
|| (memcmp(p->command, "boot_flash", FLASH_BOOT_LENGTH) == 0)) {
g_isRecovery = 1;
}
unsigned int partitionStrLen = strlen(&block2[PARTITION_INFO_POS]);
if (memcmp(&block2[PARTITION_INFO_POS], "mmcblk0", MMC_LENGTH)) {
if (g_isRecovery) {
memcpy(g_bootArgsStr, defaultUpdaterStr, strlen(defaultUpdaterStr) + 1);
} else {
memcpy(g_bootArgsStr, defaultRebootStr, strlen(defaultRebootStr) + 1);
}
} else {
if (g_isRecovery) {
memcpy(g_bootArgsStr, updaterHead, strlen(updaterHead) + 1);
} else {
memcpy(g_bootArgsStr, rebootHead, strlen(rebootHead) + 1);
}
memcpy(g_bootArgsStr + strlen(g_bootArgsStr), &block2[PARTITION_INFO_POS], partitionStrLen + 1);
}
printf("@@@ g_isRecovery = %d\n", g_isRecovery);
printf("@@@ bootArgs from misc = %s\n", g_bootArgsStr);
return g_isRecovery;
}
EmmcInitParam 函数根据misc分区的commad的内容确定是否升级;
if (BlkDevRead(block2, MISC_LOCATION*(M_1/EMMC_SECTOR_SIZE), EMMC_SECTOR_CNT) < 0) {
return -1;
}
这部分代码是读取misc分区的内容
if ((memcmp(p->command, "boot_updater", UPDATE_BOOT_LENGTH) == 0)
|| (memcmp(p->command, "boot_flash", FLASH_BOOT_LENGTH) == 0)) {
g_isRecovery = 1;
}
如果command内容如果是boot_updater 或者boot_flash 确认是OTA升级,从updater分区启动
如果misc分区中的内容包含有启动分区划分的标识"mmcblk0",就将misc分区中的Emmc分区划分参数拼接到bootargs中使用;
二、misc分区具体内容的划分
如果分析有问题,评论区回复谢谢!
©著作权归作者所有,如需转载,请注明出处,否则将追究法律责任
已于2022-2-8 11:04:12修改
赞
7
收藏 7
回复
相关推荐
顶顶顶,大佬除夕也发文,厉害了
提前写好的,晚上在玩电脑,就随意发了,试试感觉哈
大佬 您好! 在使用是差分升级包进行升级时,是否需要将修改bootargs传参中文件系统挂载参数为只读 uboot代码修改路径:./cmd/pxe.c 为什么要这样修改,修改之后,在升级差分包的时候就会出现读取loadScript.us 这个文件失败,报错是无效参数
2013-01-18 01:07:36 [ERROR]UPDATER_BINARY pkg_managerImpl.cpp 454 : Fail to open file loadScript.us error:Invalid argument
2013-01-18 01:07:36 [ERROR]UPDATER_BINARY pkg_managerImpl.cpp 402 : Failed to create stream
2013-01-18 01:07:36 [ERROR]UPDATER_BINARY script_managerImpl.cpp 120 : Failed to create script stream loadScript.us
2013-01-18 01:07:36 [ERROR]UPDATER_BINARY script_managerImpl.cpp 95 : Failed to extract and execute script
2013-01-18 01:07:36 [INFO]UPDATER_BINARY pkg_managerImpl.cpp 69 : ReleasePackageInstance 0xf7a5c680
2013-01-18 01:07:52 [INFO]UPDATER updater.cpp 179 : update success , do reboot now
loadScript.us 这个文件是获取misc分区状态的,如果是1 ,就会修改为0,
大佬 有无最新版的解读 :>