Read firmware image in chunch of sect_size bytes, to support non 512B sector size. Signed-off-by: Gwendal Grignou <gwendal@xxxxxxxxxxxx> --- Changes since v1: - Use sect_size to allocate buf, - Initalize memory to NULL. mmc_cmds.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/mmc_cmds.c b/mmc_cmds.c index 44623fe..9cba6c8 100644 --- a/mmc_cmds.c +++ b/mmc_cmds.c @@ -2402,12 +2402,12 @@ int do_ffu(int nargs, char **argv) int sect_done = 0, retry = 3, ret = -EINVAL; unsigned int sect_size; __u8 ext_csd[512]; - __u8 *buf; + __u8 *buf = NULL; __u32 arg; off_t fw_size; ssize_t chunk_size; char *device; - struct mmc_ioc_multi_cmd *multi_cmd; + struct mmc_ioc_multi_cmd *multi_cmd = NULL; if (nargs != 3) { fprintf(stderr, "Usage: ffu <image name> </path/to/mmcblkX> \n"); @@ -2427,14 +2427,6 @@ int do_ffu(int nargs, char **argv) exit(1); } - buf = malloc(512); - multi_cmd = calloc(1, sizeof(struct mmc_ioc_multi_cmd) + - 3 * sizeof(struct mmc_ioc_cmd)); - if (!buf || !multi_cmd) { - perror("failed to allocate memory"); - goto out; - } - ret = read_extcsd(dev_fd, ext_csd); if (ret) { fprintf(stderr, "Could not read EXT_CSD from %s\n", device); @@ -2471,6 +2463,14 @@ int do_ffu(int nargs, char **argv) goto out; } + buf = malloc(sect_size); + multi_cmd = calloc(1, sizeof(struct mmc_ioc_multi_cmd) + + 3 * sizeof(struct mmc_ioc_cmd)); + if (!buf || !multi_cmd) { + perror("failed to allocate memory"); + goto out; + } + /* set CMD ARG */ arg = ext_csd[EXT_CSD_FFU_ARG_0] | ext_csd[EXT_CSD_FFU_ARG_1] << 8 | @@ -2510,7 +2510,7 @@ int do_ffu(int nargs, char **argv) do_retry: /* read firmware chunk */ lseek(img_fd, 0, SEEK_SET); - chunk_size = read(img_fd, buf, 512); + chunk_size = read(img_fd, buf, sect_size); while (chunk_size > 0) { /* send ioctl with multi-cmd */ @@ -2548,7 +2548,7 @@ do_retry: } /* read the next firmware chunk (if any) */ - chunk_size = read(img_fd, buf, 512); + chunk_size = read(img_fd, buf, sect_size); } if ((sect_done * sect_size) == fw_size) { -- 2.16.4 -- To unsubscribe from this list: send the line "unsubscribe linux-mmc" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html