Add multiple FFU modes in mmc-utils based on eMMC specification 6.6.18 for flexible firmware updates
v4 cover Add multiple FFU modes in mmc-utils based on eMMC specification 6.6.18 for flexible firmware updates
Following the discussions with Avri at the 2024 ALPSS, I am submitting these patches to introduce multiple FFU modes, as defined in the eMMC specification 6.6.18.
The new FFU implementation can support diverse vendor requirements and operational conditions. The key benefits include:
1, The host can select the most appropriate update mode based on device capabilities and firmware size.
2, The patches ensure that firmware downloads are treated as a single, uninterrupted operation, preventing partial updates that could compromise device stability.
3, Some new modes keep the device in FFU mode throughout the process, reducing the risk of premature exits and update failures.
By supporting these modes, we can better accommodate varying firmware sizes and ensure smoother, more reliable firmware updates across different scenarios.
Summary of Changes:
FFU mode 1:
Uses CMD6 to enter FFU mode, CMD23 to set the block count, CMD25 for multiple-block write, and CMD6 to exit FFU mode. This mode may exit FFU mode during the download if the firmware size exceeds the chunk size.
FFU mode 2:
Similar to mode 1, but repeats CMD23+CMD25 for each chunk, ensuring FFU mode is maintained throughout the firmware download. FFU mode is only exited after the entire firmware has been successfully downloaded.
FFU mode 3: use CMD25+CMD12 for open-ended multiple-block write
Introduces a method using CMD25 for open-ended multiple-block writes followed by CMD12 to stop the transmission. This allows for a smoother and more continuous firmware bundle download.
FFU mode 4: use CMD6 and CMD24 for single-block write
A new mode that uses CMD6 to enter FFU mode, CMD24 for single-block writes, and CMD6 to exit FFU mode after each write cycle. This ensures granular control over each block but may introduce more frequent mode transitions.
FFU mode 5: use CMD6 and repeated CMD24 sequence
In this mode, CMD6 is used to enter FFU mode, followed by repeated CMD24 single-block writes. After all firmware data is written, CMD6 is used to exit FFU mode, ensuring an atomic and uninterrupted download process.
Changelog:
v1 -- v2:
1. Added memset() to clean command structure
v2 -- V3:
1. Refactor patch, and remove ffu dedicated file mmc_ffu.c
v3 -- v4:
1. Incorporated Avri’s comments
2. Due to "ERROR: in command 'ffu', 'ffu' is ambiguous" when using "mmc ffu", update default FFU mode 'ffu' to 'ffu1'
Bean Huo (5):
mmc-utils: Refactor common FFU code into functions to support
additional FFU modes
mmc-utils: Add FFU mode 2
mmc-utils: Add new FFU mode using CMD25+CMD12 for Open-ended write
download FW
mmc-utils: Add FFU mode 4 that uses CMD6 and CMD24 single-block write
to download firmware
mmc-utils: Add FFU mode 5 for firmware download using repeated CMD24
single-block write command
mmc.1 | 14 +- mmc.c | 24 ++- mmc.h | 1 + mmc_cmds.c | 480 +++++++++++++++++++++++++++++++++++++---------------- mmc_cmds.h | 6 +- 5 files changed, 381 insertions(+), 144 deletions(-)
Signature · 1 line
2.34.1
PATCH v4 1/5 mmc-utils: Refactor common FFU code into functions to support additional FFU modes
From: Bean Huo <[email protected]>
Refactor common FFU code into functions to support additional FFU modes. Follow-up patches will focus on implementing additional FFU modes and enhancements.
--- mmc_cmds.c | 326 ++++++++++++++++++++++++++++++++++------------------- 1 file changed, 207 insertions(+), 119 deletions(-)
mmc_cmds.c +207 -119
@@ -29,6 +29,7 @@#include <stdint.h> #include <assert.h> #include <linux/fs.h> /* for BLKGETSIZE */ +#include <stdbool.h> #include "mmc.h" #include "mmc_cmds.h"
@@ -2810,7 +2811,7 @@ out:return ret; } -static void set_ffu_single_cmd (struct mmc_ioc_multi_cmd *multi_cmd, +static void set_ffu_download_cmd (struct mmc_ioc_multi_cmd *multi_cmd,__u8 *ext_csd,unsigned int bytes,__u8 *buf,off_t offset) {
@@ -2831,91 +2832,81 @@ static void set_ffu_single_cmd(struct mmc_ioc_multi_cmd *multi_cmd,mmc_ioc_cmd_set_data (multi_cmd->cmds[2 ], buf + offset); } -int do_ffu (int nargs,char **argv) +/* +* Retrieves the number of sectors programmed during FFU download. +* +* @dev_fd: File descriptor for the eMMC device. +* @ext_csd: Pointer to the buffer holding the Extended CSD register data of the eMMC device. +* +* Return: The number of sectors programmed, or -1 if reading the EXT_CSD fails. +*/ +static int get_ffu_sectors_programmed (int dev_fd,__u8 *ext_csd) { -int dev_fd, img_fd; -int retry =3 , ret = -EINVAL ; -unsigned int sect_size; -__u8 ext_csd[512 ]; -__u8 *buf =NULL ; -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 ; -__u32 sect_done =0 ; - -assert (nargs ==3 || nargs ==4 ); - device = argv[2 ]; - dev_fd =open (device,O_RDWR ); -if (dev_fd <0 ) { -perror ("device open failed" ); -exit (1 ); - } - img_fd =open (argv[1 ],O_RDONLY ); -if (img_fd <0 ) { -perror ("image open failed" ); -close (dev_fd); -exit (1 ); +if (read_extcsd (dev_fd, ext_csd)) { +fprintf (stderr,"Could not read EXT_CSD\n" ); +return -1 ; } - ret =read_extcsd (dev_fd, ext_csd); -if (ret) { -fprintf (stderr,"Could not read EXT_CSD from %s\n" , device); - goto out; - } +return per_byte_htole32 ((__u8 *)&ext_csd[EXT_CSD_NUM_OF_FW_SEC_PROG_0 ]); +} + +static bool ffu_is_supported (__u8 *ext_csd,char *device) +{if (ext_csd[EXT_CSD_REV ] <EXT_CSD_REV_V5_0 ) { -fprintf (stderr, -"The FFU feature is only available on devices >= " +fprintf (stderr,"The FFU feature is only available on devices >= " "MMC 5.0, not supported in %s\n" , device); - goto out; +return false; }if (!(ext_csd[EXT_CSD_SUPPORTED_MODES ] &EXT_CSD_FFU )) {fprintf (stderr,"FFU is not supported in %s\n" , device); - goto out; +return false; }if (ext_csd[EXT_CSD_FW_CONFIG ] &EXT_CSD_UPDATE_DISABLE ) {fprintf (stderr,"Firmware update was disabled in %s\n" , device); - goto out; +return false; } - fw_size =lseek (img_fd,0 ,SEEK_END ); -if (fw_size ==0 ) { -fprintf (stderr,"Wrong firmware size" ); - goto out; - } +return true; +} +/* +* Performs FFU download of the firmware bundle. +* +* @dev_fd: File descriptor for the eMMC device on which the ioctl command will be performed. +* @ext_csd: Extended CSD register data of the eMMC device. +* @fw_buf: Pointer to the firmware buffer containing the firmware data to be downloaded. +* @fw_size: Size of the firmware in bytes. +* @chunk_size: Size of the chunks in which the firmware is sent to the device. +* +* Return: If successful, returns the number of sectors programmed. +* On failure, returns a negative error number. +*/ +static int do_ffu_download (int dev_fd,__u8 *ext_csd,__u8 *fw_buf,off_t fw_size, +unsigned int chunk_size) +{ +int ret; +__u8 num_of_cmds =4 ; +off_t bytes_left, off; +unsigned int bytes_per_loop, retry =3 ; +struct mmc_ioc_multi_cmd *multi_cmd =NULL ; + +if (!fw_buf || !ext_csd) { +fprintf (stderr,"unexpected NULL pointer\n" ); +return -EINVAL ; + }/* allocate maximum required */ - buf =malloc (fw_size); multi_cmd =calloc (1 ,sizeof (struct mmc_ioc_multi_cmd ) + -4 *sizeof (struct mmc_ioc_cmd )); -if (!buf || !multi_cmd) { + num_of_cmds *sizeof (struct mmc_ioc_cmd )); +if (!multi_cmd) {perror ("failed to allocate memory" ); - goto out; - } - -/* ensure fw is multiple of native sector size */ - sect_size = (ext_csd[EXT_CSD_DATA_SECTOR_SIZE ] ==0 ) ?512 :4096 ; -if (fw_size % sect_size) { -fprintf (stderr,"Firmware data size (%jd) is not aligned!\n" , (intmax_t )fw_size); - 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; - } +return -ENOMEM ; }/* prepare multi_cmd for FFU based on cmd to be used */ - - multi_cmd->num_of_cmds =4 ; -/* put device into ffu mode */ fill_switch_cmd (&multi_cmd->cmds[0 ],EXT_CSD_MODE_CONFIG ,EXT_CSD_FFU_MODE );
@@ -2924,25 +2915,18 @@ int do_ffu(int nargs, char **argv)fill_switch_cmd (&multi_cmd->cmds[3 ],EXT_CSD_MODE_CONFIG ,EXT_CSD_NORMAL_MODE ); -/* read firmware */ -lseek (img_fd,0 ,SEEK_SET ); -if (read (img_fd, buf, fw_size) != fw_size) { -perror ("Could not read the firmware file: " ); - ret = -ENOSPC ; - goto out; - } - do_retry: bytes_left = fw_size; off =0 ; + multi_cmd->num_of_cmds = num_of_cmds; +while (bytes_left) { -unsigned int chunk_size = bytes_left < default_chunk ? - bytes_left : default_chunk; + bytes_per_loop = bytes_left < chunk_size ? bytes_left : chunk_size;/* prepare multi_cmd for FFU based on cmd to be used */ -set_ffu_single_cmd (multi_cmd, ext_csd, chunk_size, buf, off); +set_ffu_download_cmd (multi_cmd, ext_csd, bytes_per_loop, fw_buf, off); -/* send ioctl with multi-cmd */ +/* send ioctl with multi-cmd, download firmware bundle */ ret =ioctl (dev_fd,MMC_IOC_MULTI_CMD , multi_cmd);if (ret) {
@@ -2955,83 +2939,187 @@ do_retry: goto out; } - bytes_left -= chunk_size; - off += chunk_size; + ret =get_ffu_sectors_programmed (dev_fd, ext_csd); +if (ret <=0 ) { +ioctl (dev_fd,MMC_IOC_CMD , &multi_cmd->cmds[3 ]); +/* +* By spec, host should re-start download from the first sector if +* programmed count is 0 +*/ +if (ret ==0 && retry >0 ) { + retry--; +fprintf (stderr,"Programming failed. Retrying... (%d)\n" , retry); + goto do_retry; + } +fprintf (stderr,"Programming failed! Aborting...\n" ); + goto out; + }else { +fprintf (stderr, +"Programmed %d/%jd bytes\r" , ret *512 , (intmax_t )fw_size); + } + + bytes_left -= bytes_per_loop; + off += bytes_per_loop; } -/* -* By spec - check if mode operation codes are supported in ffu features, -* if not then skip checking number of sectors programmed after install -*/ -if (!ext_csd[EXT_CSD_FFU_FEATURES ]) { -fprintf (stderr,"Please reboot to complete firmware installation on %s\n" , device); - ret =0 ; + ret =get_ffu_sectors_programmed (dev_fd, ext_csd); +out: +free (multi_cmd); +return ret; +} + +static int do_ffu_install (int dev_fd,const char *device) +{ +int ret; +__u8 ext_csd[512 ]; +struct mmc_ioc_multi_cmd *multi_cmd =NULL ; + + multi_cmd =calloc (1 ,sizeof (struct mmc_ioc_multi_cmd ) +2 *sizeof (struct mmc_ioc_cmd )); +if (!multi_cmd) { +perror ("failed to allocate memory" ); +return -ENOMEM ; + } + +/* Re-enter ffu mode and install the firmware */ + multi_cmd->num_of_cmds =2 ; +fill_switch_cmd (&multi_cmd->cmds[0 ],EXT_CSD_MODE_CONFIG ,EXT_CSD_FFU_MODE ); +fill_switch_cmd (&multi_cmd->cmds[1 ],EXT_CSD_MODE_OPERATION_CODES ,EXT_CSD_FFU_INSTALL ); + +/* send ioctl with multi-cmd */ + ret =ioctl (dev_fd,MMC_IOC_MULTI_CMD , multi_cmd); +if (ret) { +perror ("Multi-cmd ioctl failed setting install mode" ); +fill_switch_cmd (&multi_cmd->cmds[1 ],EXT_CSD_MODE_CONFIG ,EXT_CSD_NORMAL_MODE ); +/* In case multi-cmd ioctl failed before exiting from ffu mode */ +ioctl (dev_fd,MMC_IOC_CMD , &multi_cmd->cmds[1 ]); goto out; } +/* Check FFU install status */ ret =read_extcsd (dev_fd, ext_csd);if (ret) {fprintf (stderr,"Could not read EXT_CSD from %s\n" , device); goto out; } -/* Test if we need to restart the download */ - sect_done =per_byte_htole32 (&ext_csd[EXT_CSD_NUM_OF_FW_SEC_PROG_0 ]); -/* By spec, host should re-start download from the first sector if sect_done is 0 */ -if (sect_done ==0 ) { -if (retry--) { -fprintf (stderr,"Programming failed. Retrying... (%d)\n" , retry); - goto do_retry; +/* Return status */ + ret = ext_csd[EXT_CSD_FFU_STATUS ]; +out: +free (multi_cmd); +return ret; +} + +int do_ffu (int nargs,char **argv) +{ +int dev_fd, img_fd; +int ret = -EINVAL ; +unsigned int sect_size; +__u8 ext_csd[512 ]; +__u8 *fw_buf =NULL ; +off_t fw_size; +char *device; +unsigned int default_chunk =MMC_IOC_MAX_BYTES ; + +assert (nargs ==3 || nargs ==4 ); +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" ); +exit (1 ); } -fprintf (stderr,"Programming failed! Aborting...\n" ); + } + + device = argv[2 ]; + dev_fd =open (device,O_RDWR ); +if (dev_fd <0 ) { +perror ("device open failed" ); +exit (1 ); + } + img_fd =open (argv[1 ],O_RDONLY ); +if (img_fd <0 ) { +perror ("image open failed" ); +close (dev_fd); +exit (1 ); + } + + fw_size =lseek (img_fd,0 ,SEEK_END ); +if (fw_size ==0 ) { +fprintf (stderr,"Wrong firmware size" ); goto out; } -if ((sect_done * sect_size) == fw_size) { -fprintf (stderr,"Programmed %jd/%jd bytes\n" , (intmax_t )fw_size, (intmax_t )fw_size); -fprintf (stderr,"Programming finished with status %d \n" , ret); + ret =read_extcsd (dev_fd, ext_csd); +if (ret) { +fprintf (stderr,"Could not read EXT_CSD from %s\n" , device); + goto out; } -else { -fprintf (stderr,"FW size and number of sectors written mismatch. Status return %d\n" , ret); + +/* Check if FFU is supported by eMMC device */ +if (!ffu_is_supported (ext_csd, device)) { + ret = -ENOTSUP ; goto out; } -fprintf (stderr,"Installing firmware on %s...\n" , device); -/* Re-enter ffu mode and install the firmware */ - multi_cmd->num_of_cmds =2 ; +/* Ensure FW is multiple of native sector size */ + sect_size = (ext_csd[EXT_CSD_DATA_SECTOR_SIZE ] ==0 ) ?512 :4096 ; +if (fw_size % sect_size) { +fprintf (stderr,"Firmware data size (%jd) is not aligned!\n" , (intmax_t )fw_size); + ret = -EINVAL ; + goto out; + } -/* set ext_csd to install mode */ -fill_switch_cmd (&multi_cmd->cmds[1 ],EXT_CSD_MODE_OPERATION_CODES , -EXT_CSD_FFU_INSTALL ); +/* Allocate the firmware buffer with the maximum required size */ + fw_buf =malloc (fw_size); +if (!fw_buf) { +perror ("failed to allocate memory" ); + ret = -ENOMEM ; + goto out; + } -/* send ioctl with multi-cmd */ - ret =ioctl (dev_fd,MMC_IOC_MULTI_CMD , multi_cmd); +/* Read firmware */ +lseek (img_fd,0 ,SEEK_SET ); +if (read (img_fd, fw_buf, fw_size) != fw_size) { +perror ("Could not read the firmware file: " ); + ret = -ENOSPC ; + goto out; + } -if (ret) { -perror ("Multi-cmd ioctl failed setting install mode" ); -/* In case multi-cmd ioctl failed before exiting from ffu mode */ -ioctl (dev_fd,MMC_IOC_CMD , &multi_cmd->cmds[3 ]); +/* Download firmware bundle */ + ret =do_ffu_download (dev_fd, ext_csd, fw_buf, fw_size, default_chunk); +/* Check programmed sectors */ +if (ret >0 && (ret *512 ) == fw_size) { +fprintf (stderr,"Programmed %jd/%jd bytes\n" , (intmax_t )fw_size, (intmax_t )fw_size); + }else { +if (ret >0 && (ret *512 ) != fw_size) +fprintf (stderr,"FW size %jd and bytes %d programmed mismatch.\n" , + (intmax_t )fw_size, ret *512 ); +else +fprintf (stderr,"Firmware bundle download failed with status %d\n" , ret); + + ret = -EIO ; goto out; } - ret =read_extcsd (dev_fd, ext_csd); -if (ret) { -fprintf (stderr,"Could not read EXT_CSD from %s\n" , device); +/* +* By spec - check if MODE_OPERATION_CODES is supported in FFU_FEATURES, if not, proceed +* with CMD0/HW Reset/Power cycle to complete the installation +*/ +if (!ext_csd[EXT_CSD_FFU_FEATURES ]) { +fprintf (stderr,"Please reboot to complete firmware installation on %s\n" , device); + ret =0 ; goto out; } -/* return status */ - ret = ext_csd[EXT_CSD_FFU_STATUS ]; -if (ret) { +fprintf (stderr,"Installing firmware on %s...\n" , device); + ret =do_ffu_install (dev_fd, device); +if (ret)fprintf (stderr,"%s: error %d during FFU install:\n" , device, ret); - goto out; - }else { +else fprintf (stderr,"FFU finished successfully\n" ); - } out: -free (buf); -free (multi_cmd); +if (fw_buf) +free (fw_buf);close (img_fd);close (dev_fd);return ret;
Signature · 1 line
2.34.1
PATCH v4 2/5 mmc-utils: Add FFU mode 2
In reply to Bean HuoFrom: Bean Huo <[email protected]>
Added a new FFU mode 2, in this mode, begins with CMD6, followed by repeated CMD23+CMD25 for downloading the firmware bundle. Once the entire firmware image is downloaded, the FFU mode is exited with CMD6, ensuring the download is treated as an atomic operation.
--- mmc.1 | 5 ++- mmc.c | 9 +++- mmc_cmds.c | 126 +++++++++++++++++++++++++++++++++++++++++------------ mmc_cmds.h | 3 +- 4 files changed, 112 insertions(+), 31 deletions(-)
mmc.1 +4 -1
@@ -185,13 +185,16 @@ The device path should specify the cid sysfs file directory. Print SCR data from \fIdevice\-path\fR. The device path should specify the scr sysfs file directory. .TP -.BI ffu " " \fIimage\-file\-name\fR " " \fIdevice\fR " " [\fIchunk\-bytes\fR] +.BI ffu1 " " \fIimage\-file\-name\fR " " \fIdevice\fR " " [\fIchunk\-bytes\fR] Run Field Firmware Update with \fIimage\-file\-name\fR on the device. .br [\fIchunk\-bytes\fR] is optional and defaults to its max - 512k. should be in decimal bytes and sector aligned. .br if [\fIchunk\-bytes\fR] is omitted, mmc-utils will try to run ffu using the largest possible chunks: max(image-file, 512k). .TP +.BI ffu2 " \fIimage\-file\-name\fR " " \fIdevice\fR " " [\fIchunk\-bytes\fR] +Same as 'ffu1', but uses CMD23+CMD25 for repeated downloads and remains 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. .br
mmc.c +7 -2
@@ -227,13 +227,18 @@ static struct Command commands[] = {"The device path should specify the scr file directory." ,NULL }, - { do_ffu, -2, -"ffu" ,"<image name> <device> [chunk-bytes]\n" + { do_ffu1, -2, +"ffu1" ,"<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_ffu2, -2, +"ffu2" ,"<image name> <device> [chunk-bytes]\n" +"Same as 'ffu1', but uses CMD23+CMD25 for repeated downloads and remains 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"
mmc_cmds.c +99 -27
195 lines not on this page · raw message
mmc_cmds.h +2 -1
@@ -41,7 +41,8 @@ int do_rpmb_read_block(int nargs, char **argv);int do_rpmb_write_block (int nargs,char **argv);int do_cache_en (int nargs,char **argv);int do_cache_dis (int nargs,char **argv); -int do_ffu (int nargs,char **argv); +int do_ffu1 (int nargs,char **argv); +int do_ffu2 (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);
Signature · 1 line
2.34.1
RE: [PATCH v4 2/5] mmc-utils: Add FFU mode 2
mmc.c static struct Command commands[] = { · line 231
Quoted 4 lines
mmc.c +2
-2- { do_ffu,-2 , -"ffu" ,"<image name> <device> [chunk-bytes]\n" + { do_ffu1,-2 , +"ffu1" ,"<image name> <device> [chunk-bytes]\n"
Ah, but didn't we establish that the current API should be retained to act as the default mode?
Thanks,
Avri
Quoted 5 lines
"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
},
Re: [PATCH v4 2/5] mmc-utils: Add FFU mode 2
Quoted 9 lines · Avri Altman
Quoted 4 lines
- {
do_ffu, -2,
- "ffu", "<image name> <device> [chunk-bytes]\n" + {do_ffu1, -2,
+ "ffu1", "<image name> <device> [chunk-bytes]\n"Ah, but didn't we establish that the current API should be retained to act as the default mode?
Thanks,
Avri
Avri,
Corret, the reason for updating the default FFU mode name from 'ffu' to 'ffu1' is to avoid the error: 'ERROR: in command 'ffu', 'ffu' is ambiguous' when using 'mmc ffu'. Without this change, the system will encounter ambiguity.
I am considering a naming scheme like opt_ffu1 and opt_ffu2, that works well for maintaining consistency and keeping the names concise.
ffu2 could become opt_ffu1 (indicating the first optimized or alternate FFU mode).
ffu3 could become opt_ffu2.
ffu4 could become opt_ffu3.
ffu5 could become opt_ffu4.
then keep default ffu name as it is used to be.
how do you think?
Kind regards,
Bean
Re: [PATCH v4 2/5] mmc-utils: Add FFU mode 2
Quoted 32 lines · Bean Huo
Quoted 9 lines · Avri Altman
Quoted 4 lines
- {
do_ffu, -2,
- "ffu", "<image name> <device> [chunk-bytes]\n" + {do_ffu1, -2,
+ "ffu1", "<image name> <device> [chunk-bytes]\n"Ah, but didn't we establish that the current API should be retained to act as the default mode?
Thanks,
AvriAvri,
Corret, the reason for updating the default FFU mode name from 'ffu' to
'ffu1' is to avoid the error: 'ERROR: in command 'ffu', 'ffu' is ambiguous' when using 'mmc ffu'. Without this change, the system will encounter ambiguity.I am considering a naming scheme like
opt_ffu1andopt_ffu2, that works
well for maintaining consistency and keeping the names concise.ffu2 could become
opt_ffu1(indicating the first optimized or alternate
FFU mode).ffu3 could become
opt_ffu2.
ffu4 could becomeopt_ffu3.
ffu5 could becomeopt_ffu4.
Quoted 8 lines
then keep default ffu name as it is used to be.
how do you think?
Kind regards,
Bean
Avri,
how do you think about above my proposal of changing ffux to opt_ffux?
Kind regards,
Bean
RE: [PATCH v4 2/5] mmc-utils: Add FFU mode 2
Quoted 37 lines · Bean Huo
Quoted 36 lines · Avri Altman
Quoted 9 lines
mmc.c static struct Command commands[] = { · line 231
Quoted 4 lines
mmc.c +2
-2- { do_ffu,-2 , -"ffu" ,"<image name> <device> [chunk-bytes]\n" + { do_ffu1,-2 , +"ffu1" ,"<image name> <device> [chunk-bytes]\n" Ah, but didn't we establish that the current API should be retained to act as the default mode?
Thanks,
AvriAvri,
Corret, the reason for updating the default FFU mode name from 'ffu' to
'ffu1' is to avoid the error: 'ERROR: in command 'ffu', 'ffu' is ambiguous' when using 'mmc ffu'. Without this change, the system will encounter ambiguity.I am considering a naming scheme like
opt_ffu1andopt_ffu2, that works well for maintaining consistency and keeping the names concise.ffu2 could become
opt_ffu1(indicating the first optimized or alternate FFU mode).ffu3 could become
opt_ffu2.
ffu4 could becomeopt_ffu3.
ffu5 could becomeopt_ffu4.then keep default ffu name as it is used to be.
how do you think?
Quoted 6 lines
Quoted 2 lines
Kind regards,
BeanAvri,
how do you think about above my proposal of changing ffux to
opt_ffux?
I don't really have a strong opinion about that.
As long as the current mode stay the same.
Thanks,
Avri
Quoted 3 lines
Kind regards,
Bean
Re: [PATCH v4 2/5] mmc-utils: Add FFU mode 2
Quoted 46 lines · Avri Altman
Quoted 46 lines · Bean Huo
Quoted 34 lines · Avri Altman
Quoted 10 lines
Quoted 4 lines
- {
do_ffu, -2,
- "ffu", "<image name> <device> [chunk-bytes]\n" + {do_ffu1, -2,
+ "ffu1", "<image name> <device> [chunk-bytes]\n"Ah, but didn't we establish that the current API should be retained
to act as the default mode?Thanks,
AvriAvri,
Corret, the reason for updating the default FFU mode name from 'ffu'
to
'ffu1' is to avoid the error: 'ERROR: in command 'ffu', 'ffu' is ambiguous' when using 'mmc ffu'. Without this change, the system will
encounter ambiguity.I am considering a naming scheme like
opt_ffu1andopt_ffu2, that works well for maintaining consistency and keeping the names concise.ffu2 could become
opt_ffu1(indicating the first optimized or alternate FFU mode).ffu3 could become
opt_ffu2.
ffu4 could becomeopt_ffu3.
ffu5 could becomeopt_ffu4.Quoted 8 lines
then keep default ffu name as it is used to be.
how do you think?
Kind regards,
BeanAvri,
Quoted 7 lines
Quoted 2 lines
how do you think about above my proposal of changing ffux to
opt_ffux?I don't really have a strong opinion about that.
As long as the current mode stay the same.Thanks,
Avri
To avoid ambiguity while keeping the default FFU mode as 'ffu', I cannot use prefix ffu. I’m considering using the prefix opt_ffu for the optional FFU modes. This would allow us to differentiate between the default FFU implementation and the various optimized or alternative modes without using the "ffu" prefix directly.
opt_ffu1: First optional/optimized FFU modeopt_ffu2: Second optional/optimized FFU modeopt_ffu3, etc.
This would keep the default ffu unchanged while allowing us to add clarity and scalability to the naming of other FFU modes.
Hi Ulf
What’s your thought on this approach?
Kind regards,
Bean
PATCH v4 3/5 mmc-utils: Add new FFU mode using CMD25+CMD12 for Open-ended write download FW
In reply to Bean HuoFrom: Bean Huo <[email protected]>
Introduced a new FFU mode 3 of leveraging CMD25+CMD12 for Open-ended Multiple-block write to download the firmware bundle. In this mmode, the device remains in FFU mode during firmware download until the downloading is completed.
--- mmc.1 | 3 +++ mmc.c | 5 +++++ mmc.h | 1 + mmc_cmds.c | 11 +++++++++++ mmc_cmds.h | 1 + 5 files changed, 21 insertions(+)
mmc.1 +3 -0
@@ -195,6 +195,9 @@ if [\fIchunk\-bytes\fR] is omitted, mmc-utils will try to run ffu using the larg .BI ffu2 " \fIimage\-file\-name\fR " " \fIdevice\fR " " [\fIchunk\-bytes\fR] Same as 'ffu1', but uses CMD23+CMD25 for repeated downloads and remains in FFU mode until completion. .TP +.BI ffu3 " \fIimage\-file\-name\fR " " \fIdevice\fR " " [\fIchunk\-bytes\fR] +Same as 'ffu1', but uses CMD25+CMD12 Open-ended Multiple-block write to download and remains 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. .br
mmc.c +5 -0
@@ -239,6 +239,11 @@ static struct Command commands[] = {"Same as 'ffu1', but uses CMD23+CMD25 for repeated downloads and remains in FFU mode until completion.\n" ,NULL }, + { do_ffu3, -2, +"ffu3" ,"<image name> <device> [chunk-bytes]\n" +"Same as 'ffu', but uses CMD25+CMD12 Open-ended Multiple-block write to download and remains 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"
mmc.h +1 -0
@@ -27,6 +27,7 @@#define MMC_BOOT_INITIATION_ARG 0xFFFFFFFA#define MMC_SWITCH 6/* ac [31:0] See below R1b */ #define MMC_SEND_EXT_CSD 8/* adtc R1 */ +#define MMC_STOP_TRANSMISSION 12/* ac R1b */ #define MMC_SEND_STATUS 13/* ac [31:16] RCA R1 */ #define R1_SWITCH_ERROR (1 << 7)/* sx, c */ #define MMC_SWITCH_MODE_WRITE_BYTE 0x03/* Set target to value */
mmc_cmds.c +11 -0
@@ -2846,6 +2846,12 @@ static void set_ffu_download_cmd(struct mmc_ioc_multi_cmd *multi_cmd, multi_cmd->cmds[0 ].flags =MMC_RSP_SPI_R1 |MMC_RSP_R1 |MMC_CMD_AC ;set_single_cmd (&multi_cmd->cmds[1 ],MMC_WRITE_MULTIPLE_BLOCK ,1 , bytes /512 , arg);mmc_ioc_cmd_set_data (multi_cmd->cmds[1 ], buf + offset); + }else if (ffu_mode ==3 ) { +set_single_cmd (&multi_cmd->cmds[0 ],MMC_WRITE_MULTIPLE_BLOCK ,1 , bytes /512 , arg); + multi_cmd->cmds[0 ].flags =MMC_RSP_R1 |MMC_CMD_ADTC ; +mmc_ioc_cmd_set_data (multi_cmd->cmds[0 ], buf + offset); +set_single_cmd (&multi_cmd->cmds[1 ],MMC_STOP_TRANSMISSION ,0 ,0 ,0 ); + multi_cmd->cmds[1 ].flags =MMC_RSP_SPI_R1B |MMC_RSP_R1B |MMC_CMD_AC ; } }
@@ -3197,6 +3203,11 @@ int do_ffu2(int nargs, char **argv)return __do_ffu (nargs, argv,2 ); } +int do_ffu3 (int nargs,char **argv) +{ +return __do_ffu (nargs, argv,3 ); +} +int do_general_cmd_read (int nargs,char **argv) {int dev_fd;
mmc_cmds.h +1 -0
@@ -43,6 +43,7 @@ int do_cache_en(int nargs, char **argv);int do_cache_dis (int nargs,char **argv);int do_ffu1 (int nargs,char **argv);int do_ffu2 (int nargs,char **argv); +int do_ffu3 (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);
Signature · 1 line
2.34.1
PATCH v4 4/5 mmc-utils: Add FFU mode 4 that uses CMD6 and CMD24 single-block write to download firmware
In reply to Bean HuoFrom: Bean Huo <[email protected]>
FFU mode 4 initiates firmware download with CMD6 to enter FFU mode, followed by CMD24 for single-block write, after each CMD24 single-block write, CMD6 is issued to exit FFU mode. Which means in this mode, during FW downloading, the device will not remain FFU mode.
--- mmc.1 | 3 +++ mmc.c | 7 ++++++- mmc_cmds.c | 25 ++++++++++++++++++++----- mmc_cmds.h | 1 + 4 files changed, 30 insertions(+), 6 deletions(-)
mmc.1 +3 -0
@@ -198,6 +198,9 @@ Same as 'ffu1', but uses CMD23+CMD25 for repeated downloads and remains in FFU m .BI ffu3 " \fIimage\-file\-name\fR " " \fIdevice\fR " " [\fIchunk\-bytes\fR] 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. +.TP .BI erase " " \fItype\fR " " \fIstart-address\fR " " \fIend\-address\fR " " \fIdevice\fR Send Erase CMD38 with specific argument to the device. .br
mmc.c +6 -1
@@ -241,7 +241,12 @@ static struct Command commands[] = { }, { do_ffu3,-2 ,"ffu3" ,"<image name> <device> [chunk-bytes]\n" -"Same as 'ffu', but uses CMD25+CMD12 Open-ended Multiple-block write to download and remains in FFU mode until completion.\n" , +"Same as 'ffu1', but uses CMD25+CMD12 Open-ended Multiple-block write to download and remains in FFU mode until completion.\n" , +NULL + }, + { do_ffu4, -2, +"ffu4" ,"<image name> <device> [chunk-bytes]\n" +"Same as 'ffu1', but uses CMD24 Single-block write to download, exiting FFU mode after each block written.\n" ,NULL }, { do_erase, -4,
mmc_cmds.c +20 -5
@@ -2852,6 +2852,11 @@ static void set_ffu_download_cmd(struct mmc_ioc_multi_cmd *multi_cmd,mmc_ioc_cmd_set_data (multi_cmd->cmds[0 ], buf + offset);set_single_cmd (&multi_cmd->cmds[1 ],MMC_STOP_TRANSMISSION ,0 ,0 ,0 ); multi_cmd->cmds[1 ].flags =MMC_RSP_SPI_R1B |MMC_RSP_R1B |MMC_CMD_AC ; + }else if (ffu_mode ==4 ) { +fill_switch_cmd (&multi_cmd->cmds[0 ],EXT_CSD_MODE_CONFIG ,EXT_CSD_FFU_MODE ); +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 ); } }
@@ -2952,8 +2957,13 @@ static int do_ffu_download(int dev_fd, __u8 *ext_csd, __u8 *fw_buf, off_t fw_sizreturn -EINVAL ; } -if (ffu_mode !=1 )/* in FFU mode 1, mmc_ioc_multi_cmd contains 4 commands */ +if (ffu_mode ==2 || ffu_mode ==3 ) { +/* in FFU mode 2, 3, mmc_ioc_multi_cmd contains 2 commands */ num_of_cmds =2 ; + }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 */ + }/* allocate maximum required */ multi_cmd = calloc(1, sizeof(struct mmc_ioc_multi_cmd) +
@@ -2963,9 +2973,9 @@ static int do_ffu_download(int dev_fd, __u8 *ext_csd, __u8 *fw_buf, off_t fw_sizreturn -ENOMEM ; } -if (ffu_mode !=1 ) { +if (ffu_mode ==2 || ffu_mode ==3 ) {/* -* If the device is not in FFU mode 1, the command to enter FFU mode will be sent +* In FFU mode 2, mode 3, the command to enter FFU mode will be sent * independently, separate from the firmware bundle download command. */ ret =enter_ffu_mode (dev_fd);
@@ -3020,9 +3030,9 @@ do_retry: off += bytes_per_loop; } -if (ffu_mode !=1 ) { +if (ffu_mode ==2 || ffu_mode ==3 ) {/* -* If the device is not in FFU mode 1, the command to exit FFU mode will be sent +* In FFU mode 2, FFU mode 3, the command to exit FFU mode will be sent * independently, separate from the firmware bundle download command. */ ret =exit_ffu_mode (dev_fd);
@@ -3208,6 +3218,11 @@ int do_ffu3(int nargs, char **argv)return __do_ffu (nargs, argv,3 ); } +int do_ffu4 (int nargs,char **argv) +{ +return __do_ffu (nargs, argv,4 ); +} +int do_general_cmd_read (int nargs,char **argv) {int dev_fd;
mmc_cmds.h +1 -0
@@ -44,6 +44,7 @@ int do_cache_dis(int nargs, char **argv);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_read_scr (int argc,char **argv);int do_read_cid (int argc,char **argv);int do_read_csd (int argc,char **argv);
Signature · 1 line
2.34.1
PATCH v4 5/5 mmc-utils: Add FFU mode 5 for firmware download using repeated CMD24 single-block write command
In reply to Bean HuoFrom: Bean Huo <[email protected]>
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.
--- mmc.1 | 5 ++++- mmc.c | 5 +++++ mmc_cmds.c | 28 +++++++++++++++++++++------- mmc_cmds.h | 1 + 4 files changed, 31 insertions(+), 8 deletions(-)
mmc.1 +4 -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.
mmc.c +5 -0
@@ -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"
mmc_cmds.c +21 -7
@@ -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_sizreturn -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;
mmc_cmds.h +1 -0
@@ -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);
Signature · 1 line
2.34.1