OpenHarmony 升级解读之uboot源码 原创 精华

发布于 2022-1-31 18:23
浏览
6收藏

春节不停更,此文正在参加「星光计划-春节更帖活动」
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分区具体内容的划分

OpenHarmony 升级解读之uboot源码-开源基础软件社区

如果分析有问题,评论区回复谢谢!

©著作权归作者所有,如需转载,请注明出处,否则将追究法律责任
已于2022-2-8 11:04:12修改
6
收藏 6
回复
举报
回复
添加资源
添加资源将有机会获得更多曝光,你也可以直接关联已上传资源 去关联
    相关推荐