Commit eea4e6fe82fef9975e0153644935b89882890450

Authored by Łukasz Majewski
Committed by Pantelis Antoniou
1 parent 93bfd61677

dfu: mmc: Replace calls to u-boot commands with native mmc API

For some time we have been using the run_command() with properly crafted
string. Such approach turned to be unreliable and error prone.

Switch to "native" mmc subsystem API would allow better type checking and
shall improve speed.

Also, it seems that this API is changing less often than u-boot commands.
The approach similar to env operations on the eMMC has been reused.

Signed-off-by: Lukasz Majewski <l.majewski@samsung.com>

Showing 1 changed file with 24 additions and 7 deletions Side-by-side Diff

drivers/dfu/dfu_mmc.c
... ... @@ -12,6 +12,7 @@
12 12 #include <errno.h>
13 13 #include <div64.h>
14 14 #include <dfu.h>
  15 +#include <mmc.h>
15 16  
16 17 static unsigned char __aligned(CONFIG_SYS_CACHELINE_SIZE)
17 18 dfu_file_buf[CONFIG_SYS_DFU_MAX_FILE_SIZE];
... ... @@ -20,8 +21,8 @@
20 21 static int mmc_block_op(enum dfu_op op, struct dfu_entity *dfu,
21 22 u64 offset, void *buf, long *len)
22 23 {
23   - char cmd_buf[DFU_CMD_BUF_SIZE];
24   - u32 blk_start, blk_count;
  24 + struct mmc *mmc = find_mmc_device(dfu->dev_num);
  25 + u32 blk_start, blk_count, n = 0;
25 26  
26 27 /*
27 28 * We must ensure that we work in lba_blk_size chunks, so ALIGN
28 29  
... ... @@ -38,12 +39,28 @@
38 39 return -EINVAL;
39 40 }
40 41  
41   - sprintf(cmd_buf, "mmc %s %p %x %x",
42   - op == DFU_OP_READ ? "read" : "write",
43   - buf, blk_start, blk_count);
  42 + debug("%s: %s dev: %d start: %d cnt: %d buf: 0x%p\n", __func__,
  43 + op == DFU_OP_READ ? "MMC READ" : "MMC WRITE", dfu->dev_num,
  44 + blk_start, blk_count, buf);
  45 + switch (op) {
  46 + case DFU_OP_READ:
  47 + n = mmc->block_dev.block_read(dfu->dev_num, blk_start,
  48 + blk_count, buf);
  49 + break;
  50 + case DFU_OP_WRITE:
  51 + n = mmc->block_dev.block_write(dfu->dev_num, blk_start,
  52 + blk_count, buf);
  53 + break;
  54 + default:
  55 + error("Operation not supported\n");
  56 + }
44 57  
45   - debug("%s: %s 0x%p\n", __func__, cmd_buf, cmd_buf);
46   - return run_command(cmd_buf, 0);
  58 + if (n != blk_count) {
  59 + error("MMC operation failed");
  60 + return -EIO;
  61 + }
  62 +
  63 + return 0;
47 64 }
48 65  
49 66 static int mmc_file_buffer(struct dfu_entity *dfu, void *buf, long *len)