[PATCH 6/6] mmc-utils: ffu: Add optional chunk-size argument

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Normally one would like to perform ffu using the largest possible chunk.
However, since the ffu-timeout is vendor specific, there are times in
which smaller chunks would lead to a more robust ffu process.  Allow
this via an additional optional argument.

Tested-by: Lund Austin <Austin.Lund@xxxxxxxxxx>
Signed-off-by: Avri Altman <avri.altman@xxxxxxx>
---
 mmc.c      |  6 ++++--
 mmc_cmds.c | 18 ++++++++++++------
 2 files changed, 16 insertions(+), 8 deletions(-)

diff --git a/mmc.c b/mmc.c
index 795b4e3..bc8f74e 100644
--- a/mmc.c
+++ b/mmc.c
@@ -228,8 +228,10 @@ static struct Command commands[] = {
 	  NULL
 	},
 	{ do_ffu, -2,
-	  "ffu", "<image name> <device>\n"
-		"Run Field Firmware Update with <image name> on <device>.\n",
+	  "ffu", "<image name> <device> [chunk-bytes]\n"
+		"Run Field Firmware Update with <image name> on <device>.\n"
+		"[chunk-bytes] is optional and defaults to its max - 512k. "
+		"should be in decimal bytes and sector aligned.\n",
 	  NULL
 	},
 	{ do_erase, -4,
diff --git a/mmc_cmds.c b/mmc_cmds.c
index a1adbde..10d063d 100644
--- a/mmc_cmds.c
+++ b/mmc_cmds.c
@@ -2834,11 +2834,9 @@ int do_ffu(int nargs, char **argv)
 	off_t fw_size, bytes_left, off;
 	char *device;
 	struct mmc_ioc_multi_cmd *multi_cmd = NULL;
+	unsigned int default_chunk = MMC_IOC_MAX_BYTES;
 
-	if (nargs != 3) {
-		fprintf(stderr, "Usage: ffu <image name> </path/to/mmcblkX> \n");
-		exit(1);
-	}
+	assert (nargs == 3 || nargs == 4);
 
 	device = argv[2];
 	dev_fd = open(device, O_RDWR);
@@ -2898,6 +2896,14 @@ int do_ffu(int nargs, char **argv)
 		goto out;
 	}
 
+	if (nargs == 4) {
+		default_chunk = strtol(argv[3], NULL, 10);
+		if (default_chunk > MMC_IOC_MAX_BYTES || default_chunk % 512) {
+			fprintf(stderr, "Invalid chunk size");
+			goto out;
+		}
+	}
+
 	/* prepare multi_cmd for FFU based on cmd to be used */
 
 	multi_cmd->num_of_cmds = 4;
@@ -2922,8 +2928,8 @@ do_retry:
 	bytes_left = fw_size;
 	off = 0;
 	while (bytes_left) {
-		unsigned int chunk_size = bytes_left < MMC_IOC_MAX_BYTES ?
-					  bytes_left : MMC_IOC_MAX_BYTES;
+		unsigned int chunk_size = bytes_left < default_chunk ?
+					  bytes_left : default_chunk;
 
 		/* prepare multi_cmd for FFU based on cmd to be used */
 		set_ffu_single_cmd(multi_cmd, ext_csd, chunk_size, buf, off);
-- 
2.40.1




[Index of Archives]     [Linux Memonry Technology]     [Linux USB Devel]     [Linux Media]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux