海思3559A EMMC读写API接口说明

前言

由于需要开发OTA升级功能,所以uboot阶段和linux阶段都需要读写EMMC;

Uboot阶段

1. mmc工具

uboot命令行阶段可以使用mmc命令进行读写

 

示例:(1)  read   

               mmc read 0 0x42000000 0x400  0x400

               md 0x42000000 0x100

           (2)write

               mmc write 0x42000000 0x0 0x800

2. API接口

  参考cmd/mmc.c文件,有emmc的读写接口

示例:

struct mmc *mmc;

uint32_t *p =(uint32_t *)0x42000000;

uint32_t magic[10] = {0};

mmc = init_mmc_device(0x0, false);

blk_dread(mmc_get_blk_desc(mmc), 0x39800, 0x1, p);

printf("boot: read emmc magic =0x%x\n", *p);

Linux阶段

       由于EMMC是块设备,所以linux可以直接通过标准read write接口操作即可

eMMC 分区 读写样例

static int realrwdata(rwinfo *info)
{
    int device_fd = -1;
    device_fd = open(info->path, O_RDWR | O_SYNC);
    if (device_fd < 0) {
        return -1;
    }

    lseek(device_fd, info->rw_offset, SEEK_SET);

if(info->rw_type == DATA_W)
    info->data_size = write(device_fd, (char*)info->data_buf, info->rw_size);
else if(info->rw_type == DATA_R)
   info->data_size = read(device_fd, (char*)info->data_buf, info->rw_size);

    fsync(device_fd);
    close(device_fd);
    return info->data_size;
}

猜你喜欢

转载自blog.csdn.net/jzwjzw19900922/article/details/106299751
今日推荐