static int mmc_file_op(enum dfu_mmc_op op, struct dfu_entity *dfu, u64 offset, void *buf, long *len) { char cmd_buf[DFU_CMD_BUF_SIZE]; char *str_env; int ret; switch (dfu->layout) { case DFU_FS_FAT: sprintf(cmd_buf, "fat%s mmc %d:%d 0x%x %s %lx", op == DFU_OP_READ ? "load" : "write", dfu->data.mmc.dev, dfu->data.mmc.part, (unsigned int) buf, dfu->name, *len); if (op == DFU_OP_READ && offset != 0) sprintf(cmd_buf + strlen(cmd_buf), " %llx", offset); break; case DFU_FS_EXT4: if (offset != 0) { debug("%s: Offset value %llx != 0 not supported!\n", __func__, offset); return -1; } sprintf(cmd_buf, "ext4%s mmc %d:%d /%s 0x%x %ld", op == DFU_OP_READ ? "load" : "write", dfu->data.mmc.dev, dfu->data.mmc.part, dfu->name, (unsigned int) buf, *len); break; default: printf("%s: Layout (%s) not (yet) supported!\n", __func__, dfu_get_layout(dfu->layout)); return -1; } debug("%s: %s 0x%p\n", __func__, cmd_buf, cmd_buf); ret = run_command(cmd_buf, 0); if (ret) { puts("dfu: Read error!\n"); return ret; } if (dfu->layout != DFU_RAW_ADDR && op == DFU_OP_READ) { str_env = getenv("filesize"); if (str_env == NULL) { puts("dfu: Wrong file size!\n"); return -1; } *len = simple_strtoul(str_env, NULL, 16); } return ret; }
static int dfu_read_medium_nand(struct dfu_entity *dfu, u64 offset, void *buf, long *len) { int ret = -1; switch (dfu->layout) { case DFU_RAW_ADDR: ret = nand_block_read(dfu, offset, buf, len); break; default: printf("%s: Layout (%s) not (yet) supported!\n", __func__, dfu_get_layout(dfu->layout)); } return ret; }
int dfu_read_medium_mmc(struct dfu_entity *dfu, void *buf, long *len) { int ret = -1; switch (dfu->layout) { case DFU_RAW_ADDR: ret = mmc_block_read(dfu, buf, len); break; case DFU_FS_FAT: ret = mmc_file_read(dfu, buf, len); break; default: printf("%s: Layout (%s) not (yet) supported!\n", __func__, dfu_get_layout(dfu->layout)); } return ret; }
int dfu_write_medium_mmc(struct dfu_entity *dfu, u64 offset, void *buf, long *len) { int ret = -1; switch (dfu->layout) { case DFU_RAW_ADDR: ret = mmc_block_op(DFU_OP_WRITE, dfu, offset, buf, len); break; case DFU_FS_FAT: case DFU_FS_EXT4: ret = mmc_file_buffer(dfu, buf, len); break; default: printf("%s: Layout (%s) not (yet) supported!\n", __func__, dfu_get_layout(dfu->layout)); } return ret; }