Linux和Uboot下eMMC boot分区读写(2)

static int do_mmc_bootmode(cmd_tbl_t *cmdtp, int flag,
            int argc, char * const argv[])
{
    struct mmc *mmc;
    int ret = BOOTMODE_NORMAL;
    u32 blk, cnt, n;
    void *addr;
    char original_part;

addr = (void *)malloc(512);
    blk = BOOTMODE_BLK_NUM;
    cnt = BOOTMODE_BLK_COUNT;

mmc = init_mmc_device(curr_device, false);
    if (!mmc)
    {
        free(addr);
        return CMD_RET_FAILURE;
    }

/* Switch to the Boot 2 partition */
    original_part = mmc->block_dev.hwpart;
    blk_select_hwpart_devnum(IF_TYPE_MMC, curr_device, MMC_PART_BOOT2);
    mmc_set_part_conf(mmc, 0, MMC_PART_BOOT2, 2);------------------------------------------切换到eMMC boot1分区。
    n = blk_dread(mmc_get_blk_desc(mmc), blk, cnt, addr);----------------------------------读取一个block。
    if(n != cnt)
    {
        free(addr);
        return CMD_RET_FAILURE;
    }
    /* flush cache after read */
    flush_cache((ulong)addr, cnt * 512); /* FIXME */

if(*(unsigned int *)addr == BOOTMODE_UPDATE_MAGIC)
    {
        ret = BOOTMODE_UPDATE;
    }
    else
    {
        ret = BOOTMODE_NORMAL;
    }

#if 0
    for(int i = 0; i < 512/16; i++)
        printf("%08x %08x %08x %08x\n", *((int *)addr+i*4), *((int *)addr+i*4+1), *((int *)addr+i*4+2), *((int *)addr+i*4+3));
#endif
    /* Switch to original partition. */
    blk_select_hwpart_devnum(IF_TYPE_MMC, curr_device, original_part);----------------------切换到默认分区。

free(addr);

return ret;
}

至此可以在Linux和Uboot下对boot分区进行操作,进行bootloader烧写或者进行重要数据更新。

Linux公社的RSS地址https://www.linuxidc.com/rssFeed.aspx

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/12047.html