海思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;
}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章