diff mbox series

[v4,5/5] mmc-utils: Add FFU mode 5 for firmware download using repeated CMD24 single-block write command

Message ID 20241023143839.108572-6-beanhuo@iokpp.de (mailing list archive)
State New
Headers show
Series Add multiple FFU modes in mmc-utils based on eMMC specification 6.6.18 for flexible firmware updates | expand

Commit Message

Bean Huo Oct. 23, 2024, 2:38 p.m. UTC
From: Bean Huo <beanhuo@micron.com>

Add FFU mode 5 which enters FFU mode with CMD6, followed by repeated CMD24 commands to perform
single-block writes for the firmware download. After downloading all firmware data, CMD6 is issued
to exit FFU mode.

Signed-off-by: Bean Huo <beanhuo@micron.com>
Acked-by: Avri Altman <avri.altman@wdc.com>
---
 mmc.1      |  5 ++++-
 mmc.c      |  5 +++++
 mmc_cmds.c | 28 +++++++++++++++++++++-------
 mmc_cmds.h |  1 +
 4 files changed, 31 insertions(+), 8 deletions(-)
diff mbox series

Patch

diff --git a/mmc.1 b/mmc.1
index 273bdcc..052d2d1 100644
--- a/mmc.1
+++ b/mmc.1
@@ -199,7 +199,10 @@  Same as 'ffu1', but uses CMD23+CMD25 for repeated downloads and remains in FFU m
 Same as 'ffu1', but uses CMD25+CMD12 Open-ended Multiple-block write to download and remains in FFU mode until completion.
 .TP
 .BI ffu4 " \fIimage\-file\-name\fR " " \fIdevice\fR " " [\fIchunk\-bytes\fR]
-Same as 'ffu', but uses CMD24 Single-block write to download, exiting FFU mode after each block is written.
+Same as 'ffu1', but uses CMD24 Single-block write to download, exiting FFU mode after each block is written.
+.TP
+.BI ffu5 " \fIimage\-file\-name\fR " " \fIdevice\fR " " [\fIchunk\-bytes\fR]
+Same as 'ffu1', but uses CMD24 Single-block write for repeated downloads, remaining in FFU mode until completion.
 .TP
 .BI erase " " \fItype\fR " " \fIstart-address\fR " " \fIend\-address\fR " " \fIdevice\fR
 Send Erase CMD38 with specific argument to the device.
diff --git a/mmc.c b/mmc.c
index a6474db..928003e 100644
--- a/mmc.c
+++ b/mmc.c
@@ -249,6 +249,11 @@  static struct Command commands[] = {
 	 "Same as 'ffu1', but uses CMD24 Single-block write to download, exiting FFU mode after each block written.\n",
 	 NULL
 	},
+	{ do_ffu5, -2,
+	 "ffu5", "<image name> <device> [chunk-bytes]\n"
+	 "Same as 'ffu1', but uses CMD24 Single-block write for repeated downloads, remaining in FFU mode until completion.\n",
+	 NULL
+	},
 	{ do_erase, -4,
 	"erase", "<type> " "<start address> " "<end address> " "<device>\n"
 		"Send Erase CMD38 with specific argument to the <device>\n\n"
diff --git a/mmc_cmds.c b/mmc_cmds.c
index c9db4b4..024f9d7 100644
--- a/mmc_cmds.c
+++ b/mmc_cmds.c
@@ -2857,6 +2857,9 @@  static void set_ffu_download_cmd(struct mmc_ioc_multi_cmd *multi_cmd,
 		set_single_cmd(&multi_cmd->cmds[1], MMC_WRITE_BLOCK, 1, 1, arg);
 		mmc_ioc_cmd_set_data(multi_cmd->cmds[1], buf + offset);
 		fill_switch_cmd(&multi_cmd->cmds[2], EXT_CSD_MODE_CONFIG, EXT_CSD_NORMAL_MODE);
+	} else if (ffu_mode == 5) {
+		set_single_cmd(&multi_cmd->cmds[0], MMC_WRITE_BLOCK, 1, 1, arg);
+		mmc_ioc_cmd_set_data(multi_cmd->cmds[0], buf + offset);
 	}
 }
 
@@ -2963,6 +2966,9 @@  static int do_ffu_download(int dev_fd, __u8 *ext_csd, __u8 *fw_buf, off_t fw_siz
 	} else if (ffu_mode == 4) {
 		num_of_cmds = 3; /* in FFU mode 4, mmc_ioc_multi_cmd contains 3 commands */
 		chunk_size = 512; /* FFU mode 4 uses CMD24 single-block write */
+	} else if (ffu_mode == 5) {
+		num_of_cmds = 1; /* FFU mode 5, it is single command mode  */
+		chunk_size = 512; /* FFU mode 5 uses CMD24 single-block write */
 	}
 
 	/* allocate maximum required */
@@ -2973,9 +2979,9 @@  static int do_ffu_download(int dev_fd, __u8 *ext_csd, __u8 *fw_buf, off_t fw_siz
 		return -ENOMEM;
 	}
 
-	if (ffu_mode == 2 || ffu_mode == 3) {
+	if (ffu_mode == 2 || ffu_mode == 3 || ffu_mode == 5) {
 		/*
-		 * In FFU mode 2, mode 3, the command to enter FFU mode will be sent
+		 * In FFU mode 2, mode 3, mode 5, the command to enter FFU mode will be sent
 		 * independently, separate from the firmware bundle download command.
 		 */
 		ret = enter_ffu_mode(dev_fd);
@@ -2994,11 +3000,14 @@  do_retry:
 		/* prepare multi_cmd for FFU based on cmd to be used */
 		set_ffu_download_cmd(multi_cmd, ext_csd, bytes_per_loop, fw_buf, off, ffu_mode);
 
-		/* send ioctl with multi-cmd, download firmware bundle */
-		ret = ioctl(dev_fd, MMC_IOC_MULTI_CMD, multi_cmd);
+		if (num_of_cmds > 1)
+			/* send ioctl with multi-cmd, download firmware bundle */
+			ret = ioctl(dev_fd, MMC_IOC_MULTI_CMD, multi_cmd);
+		else
+			ret = ioctl(dev_fd, MMC_IOC_CMD, &multi_cmd->cmds[0]);
 
 		if (ret) {
-			perror("Multi-cmd ioctl");
+			perror("ioctl failed");
 			/*
 			 * In case multi-cmd ioctl failed before exiting from
 			 * ffu mode
@@ -3030,9 +3039,9 @@  do_retry:
 		off += bytes_per_loop;
 	}
 
-	if (ffu_mode == 2 || ffu_mode == 3) {
+	if (ffu_mode == 2 || ffu_mode == 3 || ffu_mode == 5) {
 		/*
-		 * In FFU mode 2, FFU mode 3, the command to exit FFU mode will be sent
+		 * In FFU mode 2, FFU mode 3, FFU mode 5, the command to exit FFU mode will be sent
 		 * independently, separate from the firmware bundle download command.
 		 */
 		ret = exit_ffu_mode(dev_fd);
@@ -3223,6 +3232,11 @@  int do_ffu4(int nargs, char **argv)
 	return __do_ffu(nargs, argv, 4);
 }
 
+int do_ffu5(int nargs, char **argv)
+{
+	return __do_ffu(nargs, argv, 5);
+}
+
 int do_general_cmd_read(int nargs, char **argv)
 {
 	int dev_fd;
diff --git a/mmc_cmds.h b/mmc_cmds.h
index a382349..3cb7480 100644
--- a/mmc_cmds.h
+++ b/mmc_cmds.h
@@ -45,6 +45,7 @@  int do_ffu1(int nargs, char **argv);
 int do_ffu2(int nargs, char **argv);
 int do_ffu3(int nargs, char **argv);
 int do_ffu4(int nargs, char **argv);
+int do_ffu5(int nargs, char **argv);
 int do_read_scr(int argc, char **argv);
 int do_read_cid(int argc, char **argv);
 int do_read_csd(int argc, char **argv);