]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
dfu: mmc: call fs functions instead of run_command
authorSimon Goldschmidt <simon.k.r.goldschmidt@gmail.com>
Fri, 25 Jan 2019 18:58:01 +0000 (19:58 +0100)
committerTom Rini <trini@konsulko.com>
Thu, 31 Jan 2019 02:22:53 +0000 (21:22 -0500)
This unbreaks dfu mmc_file_op which is currently broken since using the
load cmd on a buffer from heap is not allowed - added with
commit aa3c609e2be5 ("fs: prevent overwriting reserved memory")

Fixes: commit aa3c609e2be5 ("fs: prevent overwriting reserved memory")
Reported-by: Stephen Warren <swarren@wwwdotorg.org>
Signed-off-by: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>
Tested-by: Stephen Warren <swarren@nvidia.com>
Acked-by: Lukasz Majewski <lukma@denx.de>
drivers/dfu/dfu_mmc.c
include/dfu.h

index b45e6dc54ca707b56dfe5a9ef463033808c7ec9d..403fd5351d7738f1175dd5da2bc82829fb4d86dc 100644 (file)
@@ -108,17 +108,17 @@ static int mmc_file_buffer(struct dfu_entity *dfu, void *buf, long *len)
 static int mmc_file_op(enum dfu_op op, struct dfu_entity *dfu,
                        void *buf, u64 *len)
 {
-       const char *fsname, *opname;
-       char cmd_buf[DFU_CMD_BUF_SIZE];
-       char *str_env;
+       char dev_part_str[8];
        int ret;
+       int fstype;
+       loff_t size = 0;
 
        switch (dfu->layout) {
        case DFU_FS_FAT:
-               fsname = "fat";
+               fstype = FS_TYPE_FAT;
                break;
        case DFU_FS_EXT4:
-               fsname = "ext4";
+               fstype = FS_TYPE_EXT;
                break;
        default:
                printf("%s: Layout (%s) not (yet) supported!\n", __func__,
@@ -126,48 +126,43 @@ static int mmc_file_op(enum dfu_op op, struct dfu_entity *dfu,
                return -1;
        }
 
+       snprintf(dev_part_str, sizeof(dev_part_str), "%d:%d",
+                dfu->data.mmc.dev, dfu->data.mmc.part);
+
+       ret = fs_set_blk_dev("mmc", dev_part_str, fstype);
+       if (ret) {
+               puts("dfu: fs_set_blk_dev error!\n");
+               return ret;
+       }
+
        switch (op) {
        case DFU_OP_READ:
-               opname = "load";
+               ret = fs_read(dfu->name, (size_t)buf, 0, 0, &size);
+               if (ret) {
+                       puts("dfu: fs_read error!\n");
+                       return ret;
+               }
+               *len = size;
                break;
        case DFU_OP_WRITE:
-               opname = "write";
+               ret = fs_write(dfu->name, (size_t)buf, 0, *len, &size);
+               if (ret) {
+                       puts("dfu: fs_write error!\n");
+                       return ret;
+               }
                break;
        case DFU_OP_SIZE:
-               opname = "size";
+               ret = fs_size(dfu->name, &size);
+               if (ret) {
+                       puts("dfu: fs_size error!\n");
+                       return ret;
+               }
+               *len = size;
                break;
        default:
                return -1;
        }
 
-       sprintf(cmd_buf, "%s%s mmc %d:%d", fsname, opname,
-               dfu->data.mmc.dev, dfu->data.mmc.part);
-
-       if (op != DFU_OP_SIZE)
-               sprintf(cmd_buf + strlen(cmd_buf), " %p", buf);
-
-       sprintf(cmd_buf + strlen(cmd_buf), " %s", dfu->name);
-
-       if (op == DFU_OP_WRITE)
-               sprintf(cmd_buf + strlen(cmd_buf), " %llx", *len);
-
-       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 (op != DFU_OP_WRITE) {
-               str_env = env_get("filesize");
-               if (str_env == NULL) {
-                       puts("dfu: Wrong file size!\n");
-                       return -1;
-               }
-               *len = simple_strtoul(str_env, NULL, 16);
-       }
-
        return ret;
 }
 
index 9340a900a2f82b5e73d805d24321cdd8d358447f..145a1576a3e9e889050c27dbb63e1a56d6ad52aa 100644 (file)
@@ -80,7 +80,6 @@ struct sf_internal_data {
 };
 
 #define DFU_NAME_SIZE                  32
-#define DFU_CMD_BUF_SIZE               128
 #ifndef CONFIG_SYS_DFU_DATA_BUF_SIZE
 #define CONFIG_SYS_DFU_DATA_BUF_SIZE           (1024*1024*8)   /* 8 MiB */
 #endif