Add multiple FFU modes based on eMMC specification 6.6.18 for flexible firmware updates
Subsystems (2)
v2 cover Add multiple FFU modes based on eMMC specification 6.6.18 for flexible firmware updates
Hi Avri, Ulf
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.
Kind regards,
Bean
Bean Huo (5):
mmc_utils: Extract FFU code to mmc_ffu.c for future FFU mode expansion
mmc-utils: Add FFU mode 2
mmc-utils: Add new FFU mode using CMD25+CMD12 for Open-ended write
download FW
mmc-utils: Added FFU mode 4 that uses CMD6 and CMD24 for single-block
firmware download
mmc-utils: add FFU mode 5 for firmware download using CMD6 and
repeated CMD24 command
Makefile | 1 + mmc.c | 14 +- mmc.h | 1 + mmc_cmds.c | 274 ------------------------------------- mmc_cmds.h | 52 +++++++ mmc_ffu.c | 392 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 456 insertions(+), 278 deletions(-) create mode 100644 mmc_ffu.c
Signature · 1 line
2.34.1
PATCH v2 1/5 mmc_utils: Extract FFU code to mmc_ffu.c for future FFU mode expansion
From: Bean Huo <[email protected]>
Refactor FFU functionality by extracting existing FFU code from mmc_cmds.c into a dedicated file, mmc_ffu.c. Updated do_ffu in mmc_utils to reflect the new structure and interface. This restructuring provides better code organization and a clearer separation of concerns, making it easier to maintain and extend FFU functionality.
Follow-up patches will focus on implementing additional FFU modes and enhancements.
--- Makefile | 1 + mmc.c | 11 +- mmc_cmds.c | 274 -------------------------------------------- mmc_cmds.h | 52 +++++++++ mmc_ffu.c | 324 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 384 insertions(+), 278 deletions(-) create mode 100644 mmc_ffu.c
Makefile +1 -0
@@ -7,6 +7,7 @@ objects = \ mmc.o \ mmc_cmds.o \ lsmmc.o \ + mmc_ffu.o \ 3rdparty/hmac_sha/hmac_sha2.o \ 3rdparty/hmac_sha/sha2.o
mmc.c +7 -4
@@ -227,11 +227,14 @@ 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_ffu, -4, +"ffu" ,"-i <image name> -p <device> [ -c <chunk-bytes>] [-m <ffu_mode>]\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" , +"[-c <chunk-bytes>] is optional and defaults to its max - 512k. " +"should be in decimal bytes and sector aligned.\n" +"[-m <ffu_mode>] Optional, provides five firmware bundle download command modes:\n" +" -m 1: Default mode, utilizing the CMD6+CMD23+CMD25+CMD6 command sequence. This \n" +" may exit FFU mode during firmware bundle downloading if FW size exceeds the chunk size. \n" ,NULL }, { do_erase, -4,
mmc_cmds.c +0 -274
292 lines not on this page · raw message
mmc_cmds.h +52 -0
61 lines not on this page · raw message
mmc_ffu.c new file +324 -0
324 lines not on this page · raw message
Signature · 1 line
2.34.1
RE: [PATCH v2 1/5] mmc_utils: Extract FFU code to mmc_ffu.c for future FFU mode expansion
Quoted 28 lines
From: Bean Huo <[email protected]>
Refactor FFU functionality by extracting existing FFU code from
mmc_cmds.cinto a dedicated file,mmc_ffu.c. Updateddo_ffuinmmc_utilsto reflect the new structure and interface. This restructuring provides better code organization and a clearer separation of concerns, making it easier to maintain and extend FFU functionality.Follow-up patches will focus on implementing additional FFU modes and enhancements.
Signed-off-by Bean Huo <[email protected]>--- Makefile | 1 + mmc.c | 11 +- mmc_cmds.c | 274 -------------------------------------------- mmc_cmds.h | 52 +++++++++ mmc_ffu.c | 324 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 384 insertions(+), 278 deletions(-) create mode 100644
mmc_ffu.cMakefile +0
-0
Makefile objects = \ · line 10
Quoted 4 lines
Makefile +1
-0@@ -7,6 +7,7 @@ objects = \ mmc.o \ mmc_cmds.o \ lsmmc.o \ + mmc_ffu.o \
I don't think a new module is even needed.
Quoted 27 lines
Makefile +0
-03rdparty/hmac_sha/hmac_sha2.o \ 3rdparty/hmac_sha/sha2.ommc.c +2
-2@@ -227,11 +227,14 @@ 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_ffu, -4, + "ffu", "-i <image name> -p <device> [ -c <chunk-bytes>] [-m<ffu_mode>]\n"
"Run Field Firmware Update with <image name> on <device>.\n"mmc.c +3
-2-"[chunk-bytes] is optional and defaults to its max - 512k. " - "should be in decimal bytes and sector aligned.\n", +"[-c <chunk-bytes>] is optional and defaults to its max - 512k. " +"should be in decimal bytes and sector aligned.\n" + "[-m <ffu_mode>] Optional, provides five firmware bundledownload command modes:\n"
+ " -m 1: Default mode, utilizing the CMD6+CMD23+CMD25+CMD6
command sequence. This \n"
+ " may exit FFU mode during firmware bundle downloading
+ if FW size exceeds the chunk size. \n",
Quoted 2 lines
NULL
},Did you consider, instead of adding a new argument <ffu_mode>, to add new commands? e.g. ffu2, ffu3, etc...
Quoted 314 lines
{ do_erase, -4,mmc_cmds.c +0
-32@@ -58,41 +58,6 @@#define WPTYPE_PWRON 2#define WPTYPE_PERM 3 -static inline __u32 per_byte_htole32(__u8 *arr) -{ -return arr[0 ] | arr[1 ] <<8 | arr[2 ] <<16 | arr[3 ] <<24 ; -} - -static int read_extcsd(int fd, __u8 *ext_csd) -{ -int ret =0 ; -struct mmc_ioc_cmd idata; -memset (&idata,0 ,sizeof (idata)); -memset (ext_csd,0 ,sizeof (__u8) *512 ); - idata.write_flag =0 ; - idata.opcode =MMC_SEND_EXT_CSD ; - idata.arg =0 ; - idata.flags =MMC_RSP_SPI_R1 |MMC_RSP_R1 |MMC_CMD_ADTC ; - idata.blksz =512 ; - idata.blocks =1 ; -mmc_ioc_cmd_set_data (idata, ext_csd); - - ret =ioctl (fd,MMC_IOC_CMD , &idata); -if (ret) -perror ("ioctl" ); - -return ret; -} - -static void fill_switch_cmd (struct mmc_ioc_cmd *cmd,__u8 index,__u8 value) -{ - cmd->opcode =MMC_SWITCH ; - cmd->write_flag =1 ; - cmd->arg = (MMC_SWITCH_MODE_WRITE_BYTE <<24 ) | (index <<16 ) | - (value <<8 ) |EXT_CSD_CMD_SET_NORMAL ; - cmd->flags =MMC_RSP_SPI_R1B |MMC_RSP_R1B |MMC_CMD_AC ; -} -static int write_extcsd_value (int fd,__u8 index,__u8 value,unsigned int timeout_ms){ @@ -2101,18 +2066,6 @@ struct rpmb_frame { u_int16_t req_resp;};
mmc_cmds.c +0
-12-static inline void set_single_cmd (struct mmc_ioc_cmd *ioc,__u32 opcode, -int write_flag,unsigned int blocks, -__u32 arg) -{ - ioc->opcode = opcode; - ioc->write_flag = write_flag; - ioc->arg = arg; - ioc->blksz =512 ; - ioc->blocks = blocks; - ioc->flags =MMC_RSP_SPI_R1 |MMC_RSP_R1 |MMC_CMD_ADTC ; -} -/* Performs RPMB operation. * * @fd: RPMB device on which we should perform ioctl command @@ - 2810,233 +2763,6 @@ out:
return ret;}
mmc_cmds.c +0
-10-static void set_ffu_single_cmd (struct mmc_ioc_multi_cmd *multi_cmd, -__u8 *ext_csd,unsigned int bytes,__u8 *buf, -off_t offset) -{ -__u32 arg =per_byte_htole32 (&ext_csd[EXT_CSD_FFU_ARG_0 ]); - -/* send block count */ -set_single_cmd (&multi_cmd->cmds[1 ],MMC_SET_BLOCK_COUNT ,0 ,0 , - bytes /512 ); - multi_cmd->cmds[1].flags = MMC_RSP_SPI_R1 | MMC_RSP_R1 |
MMC_CMD_AC;mmc_cmds.c +0
-7- -/* -* send image chunk: blksz and blocks essentially do not matter, as -* long as the product is fw_size, but some hosts don't handle larger -* blksz well. -*/ - set_single_cmd(&multi_cmd->cmds[2], MMC_WRITE_MULTIPLE_BLOCK,1,
mmc_cmds.c +0
-74- bytes / 512, arg); -mmc_ioc_cmd_set_data (multi_cmd->cmds[2 ], buf + offset); -} - -int do_ffu (int nargs,char **argv) -{ -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 ); - } - - ret =read_extcsd (dev_fd, ext_csd); -if (ret) { -fprintf (stderr,"Could not read EXT_CSD from %s\n" , device); - goto out; - } - -if (ext_csd[EXT_CSD_REV ] <EXT_CSD_REV_V5_0 ) { -fprintf (stderr, -"The FFU feature is only available on devices >= " -"MMC 5.0, not supported in %s\n" , device); - goto out; - } - -if (!(ext_csd[EXT_CSD_SUPPORTED_MODES ] &EXT_CSD_FFU )) { -fprintf (stderr,"FFU is not supported in %s\n" , device); - goto out; - } - -if (ext_csd[EXT_CSD_FW_CONFIG ] &EXT_CSD_UPDATE_DISABLE ) { -fprintf (stderr,"Firmware update was disabled in %s\n" , device); - goto out; - } - - fw_size =lseek (img_fd,0 ,SEEK_END ); -if (fw_size ==0 ) { -fprintf (stderr,"Wrong firmware size" ); - goto out; - } - -/* 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) { -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);
mmc_cmds.c +0
-6- goto out; - } - -if (nargs ==4 ) { - default_chunk =strtol (argv[3 ],NULL ,10 ); -if (default_chunk >MMC_IOC_MAX_BYTES || default_chunk %512 ){
mmc_cmds.c +0
-58-fprintf (stderr,"Invalid chunk size" ); - goto out; - } - } - -/* 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 ); - -/* return device into normal mode */ -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 ; -while (bytes_left) { -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); - -/* send ioctl with multi-cmd */ - ret =ioctl (dev_fd,MMC_IOC_MULTI_CMD , multi_cmd); - -if (ret) { -perror ("Multi-cmd ioctl" ); -/* -* In case multi-cmd ioctl failed before exiting from -* ffu mode -*/ -ioctl (dev_fd,MMC_IOC_CMD , &multi_cmd->cmds[3 ]); - goto out; - } - - bytes_left -= chunk_size; - off += chunk_size; - } - -/* -* 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);
mmc_cmds.c +0
-12- ret =0 ; - goto out; - } - - 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 ifsect_doneis 0 */mmc_cmds.c +0
-11-if (sect_done ==0 ) { -if (retry--) { -fprintf (stderr,"Programming failed. Retrying... (%d)\n" , retry); - goto do_retry; - } -fprintf (stderr,"Programming failed! Aborting...\n" ); - goto out; - } - -if ((sect_done * sect_size) == fw_size) { - fprintf(stderr, "Programmed %jd/%jd bytes\n", (intmax_t)fw_size,(intmax_t)fw_size);
mmc_cmds.c +0
-4-fprintf (stderr,"Programming finished with status %d \n" , ret); - } -else { - fprintf(stderr, "FW size and number of sectors written mismatch.Status return %d\n", ret);
mmc_cmds.c +0
-9- goto out; - } - -fprintf (stderr,"Installing firmware on %s...\n" , device); -/* Re-enter ffu mode and install the firmware */ - multi_cmd->num_of_cmds =2 ; - -/* set ext_csd to install mode */ - fill_switch_cmd(&multi_cmd->cmds[1],
EXT_CSD_MODE_OPERATION_CODES,mmc_cmds.c +0
-35- 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" ); -/* In case multi-cmd ioctl failed before exiting from ffu mode */ -ioctl (dev_fd,MMC_IOC_CMD , &multi_cmd->cmds[3 ]); - goto out; - } - - ret =read_extcsd (dev_fd, ext_csd); -if (ret) { -fprintf (stderr,"Could not read EXT_CSD from %s\n" , device); - goto out; - } - -/* return status */ - ret = ext_csd[EXT_CSD_FFU_STATUS ]; -if (ret) { -fprintf (stderr,"%s: error %d during FFU install:\n" , device, ret); - goto out; - }else { -fprintf (stderr,"FFU finished successfully\n" ); - } - -out: -free (buf); -free (multi_cmd); -close (img_fd); -close (dev_fd); -return ret; -} -int do_general_cmd_read (int nargs,char **argv) {int dev_fd;mmc_cmds.h +0
-0@@ -16,6 +16,57 @@* Modified to add field firmware update support, * those modifications are Copyright (c) 2016 SanDisk Corp. */
mmc_cmds.h line 28
Quoted 10 lines
mmc_cmds.h +10
-0+#include <sys/ioctl.h> +#include <sys/stat.h> +#include <string.h> +#include "mmc.h" + +static inline __u32 per_byte_htole32 (__u8 *arr) { +return arr[0 ] | arr[1 ] <<8 | arr[2 ] <<16 | arr[3 ] <<24 ; } + + +static inline int read_extcsd (int fd,__u8 *ext_csd)
AFAIK, while the Linux kernel coding conventions do not explicitly forbid implementing C code in header files, they strongly discourage it except in specific cases.
You could just include it in mmc_cmds.h, but again - I don't think a new module is even needed.
Quoted 236 lines
mmc_cmds.h +39
-0+int ret =0 ; +struct mmc_ioc_cmd idata; +memset (&idata,0 ,sizeof (idata)); +memset (ext_csd,0 ,sizeof (__u8) *512 ); + idata.write_flag =0 ; + idata.opcode =MMC_SEND_EXT_CSD ; + idata.arg =0 ; + idata.flags =MMC_RSP_SPI_R1 |MMC_RSP_R1 |MMC_CMD_ADTC ; + idata.blksz =512 ; + idata.blocks =1 ; +mmc_ioc_cmd_set_data (idata, ext_csd); + + ret =ioctl (fd,MMC_IOC_CMD , &idata); +if (ret) +perror ("ioctl" ); + +return ret; +} + +static inline void fill_switch_cmd (struct mmc_ioc_cmd *cmd,__u8 index,__u8 value) +{ + cmd->opcode =MMC_SWITCH ; + cmd->write_flag =1 ; + cmd->arg = (MMC_SWITCH_MODE_WRITE_BYTE <<24 ) | (index <<16 ) | + (value <<8 ) |EXT_CSD_CMD_SET_NORMAL ; + cmd->flags =MMC_RSP_SPI_R1B |MMC_RSP_R1B |MMC_CMD_AC ; +} + +static inline void set_single_cmd (struct mmc_ioc_cmd *ioc,__u32 opcode,int write_flag, +unsigned int blocks,__u32 arg) +{ + ioc->opcode = opcode; + ioc->write_flag = write_flag; + ioc->arg = arg; + ioc->blksz =512 ; + ioc->blocks = blocks; + ioc->flags =MMC_RSP_SPI_R1 |MMC_RSP_R1 |MMC_CMD_ADTC ; +}/* mmc_cmds.c */ int do_read_extcsd (int nargs,char **argv);@@ -50,3 +101,4 @@ int do_general_cmd_read(int nargs, char **argv);int do_softreset (int nargs,char **argv);int do_preidle (int nargs,char **argv);int do_alt_boot_op (int nargs,char **argv); +int do_ffu (int nargs,char **argv);mmc_ffu.c new file +22
-0@@ -0,0 +1,324 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Modified and add more FFU modes. +* And changed and updated by: Bean Huo <[email protected]> +*/ + +#include <stdio.h> +#include <stdlib.h> +#include <stdint.h> +#include <fcntl.h> +#include <sys/ioctl.h> +#include <sys/types.h> +#include <ctype.h> +#include <errno.h> +#include <stdbool.h> +#include <assert.h> +#include <unistd.h> + +#include "mmc.h" +#include "mmc_cmds.h" + +static int do_ffu_download(int *dev_fd, __u8 *ext_csd, __u8 *fw_buf, off_t
fw_size, unsigned intchunk_size);mmc_ffu.c new file +2
-0+ +static void set_ffu_download_cmd(struct mmc_ioc_multi_cmd *multi_cmd,
__u8*ext_csd,mmc_ffu.c new file +6
-0+ unsigned int bytes, __u8 *buf, off_t offset) +{ + __u32 arg = per_byte_htole32(&ext_csd[EXT_CSD_FFU_ARG_0]); + +/* send block count */ + set_single_cmd(&multi_cmd->cmds[1], MMC_SET_BLOCK_COUNT, 0, 0,bytes / 512);
+ multi_cmd->cmds[1].flags =MMC_RSP_SPI_R1|MMC_RSP_R1|MMC_CMD_AC;mmc_ffu.c new file +7
-0+ +/* +* send image chunk: blksz and blocks essentially do not matter, as +* long as the product is fw_size, but some hosts don't handle larger +* blksz well. +*/ + set_single_cmd(&multi_cmd->cmds[2], MMC_WRITE_MULTIPLE_BLOCK,1, bytes / 512, arg);
mmc_ffu.c new file +14
-0+mmc_ioc_cmd_set_data (multi_cmd->cmds[2 ], buf + offset); +} + +static int get_ffu_sectors_programmed (int *dev_fd,__u8 *ext_csd) +{ +int ret; + + ret =read_extcsd (*dev_fd, ext_csd); +if (ret) { +fprintf (stderr,"Could not read EXT_CSD\n" ); +return ret; + } + + ret = per_byte_htole32((__u8*)&ext_csd[EXT_CSD_NUM_OF_FW_SEC_PROG_0]);
mmc_ffu.c new file +31
-0+ +return ret; +} + +static bool ffu_is_supported (__u8 *ext_csd,char *device) +{ +if (ext_csd ==NULL ) { +fprintf (stderr,"ext_cst is NULL\n" ); +return false; + } + +if (ext_csd[EXT_CSD_REV ] <EXT_CSD_REV_V5_0 ) { +fprintf (stderr,"The FFU feature is only available on devices >= " +"MMC 5.0, not supported in %s\n" , device); +return false; + } + +if (!(ext_csd[EXT_CSD_SUPPORTED_MODES ] &EXT_CSD_FFU )) { +fprintf (stderr,"FFU is not supported in %s\n" , device); +return false; + } + +if (ext_csd[EXT_CSD_FW_CONFIG ] &EXT_CSD_UPDATE_DISABLE ) { +fprintf (stderr,"Firmware update was disabled in %s\n" , device); +return false; + } + +return true; +} + +static int do_ffu_download(int *dev_fd, __u8 *ext_csd, __u8 *fw_buf, off_t
fw_size,mmc_ffu.c new file +14
-0+ unsigned int chunk_size) +{ +int ret; +__u8 num_of_cmds =4 ; +off_t bytes_left, off; +unsigned int bytes_per_loop, sect_done, retry =3 ; +struct mmc_ioc_multi_cmd *multi_cmd =NULL ; + +if (!dev_fd || !fw_buf || !ext_csd) { +fprintf (stderr,"unexpected NULL pointer\n" ); +return -EINVAL ; + } +/* allocate maximum required */ + multi_cmd = calloc(1, sizeof(struct mmc_ioc_multi_cmd) +
num_of_cmds*sizeof(struct mmc_ioc_cmd));mmc_ffu.c new file +8
-0+if (!multi_cmd) { +perror ("failed to allocate memory" ); +return -ENOMEM ; + } + +/* prepare multi_cmd for FFU based on cmd to be used */ +/* put device into ffu mode */ + fill_switch_cmd(&multi_cmd->cmds[0], EXT_CSD_MODE_CONFIG,
EXT_CSD_FFU_MODE);mmc_ffu.c new file +3
-0+ +/* return device into normal mode */ + fill_switch_cmd(&multi_cmd->cmds[3], EXT_CSD_MODE_CONFIG,
EXT_CSD_NORMAL_MODE);mmc_ffu.c new file +11
-0+ +do_retry: + bytes_left = fw_size; + off =0 ; + multi_cmd->num_of_cmds = num_of_cmds; + +while (bytes_left) { + bytes_per_loop = bytes_left < chunk_size ? bytes_left : chunk_size; + +/* 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);mmc_ffu.c new file +17
-0+ +/* send ioctl with multi-cmd, download firmware bundle */ + ret =ioctl (*dev_fd,MMC_IOC_MULTI_CMD , multi_cmd); + +if (ret) { +perror ("Multi-cmd ioctl" ); +/* +* In case multi-cmd ioctl failed before exiting from +* ffu mode +*/ +ioctl (*dev_fd,MMC_IOC_CMD , &multi_cmd->cmds[3 ]); + goto out; + } + + sect_done =get_ffu_sectors_programmed (dev_fd, ext_csd); +if (sect_done <=0 ) { +/* By spec, host should re-start download from the first sector if
sect_doneis 0 */mmc_ffu.c new file +4
-0+ioctl (*dev_fd,MMC_IOC_CMD , &multi_cmd->cmds[3 ]); +if (retry >0 ) { + retry--; + fprintf(stderr, "Programming failed. Retrying... (%d)\n",retry);
mmc_ffu.c new file +7
-0+ goto do_retry; + } +fprintf (stderr,"Programming failed! Aborting...\n" ); + ret = sect_done; + goto out; + }else { + fprintf(stderr, "Programmed %d/%jd bytes\r", sect_done * 512,(intmax_t)fw_size);
mmc_ffu.c new file +21
-0+ } + + bytes_left -= bytes_per_loop; + off += bytes_per_loop; + } + + ret =get_ffu_sectors_programmed (dev_fd, ext_csd); +out: +free (multi_cmd); +return ret; + +} + +int do_ffu (int nargs,char **argv) +{ +int opt; +int dev_fd, img_fd; +int ret = -EINVAL ; +unsigned int sect_size; +__u8 ext_csd[512 ]; +__u8 *fw_buf =NULL ;
mmc_ffu.c line 178
Quoted 10 lines
mmc_ffu.c new file +10
-0+off_t fw_size; +char *device, *fw_img; +struct mmc_ioc_multi_cmd *multi_cmd =NULL ; +unsigned int default_chunk =MMC_IOC_MAX_BYTES ; +int sect_done =0 ; +__u8 ffu_mode =1 ; + +assert (nargs >=4 ); + +while ((opt =getopt (nargs, argv,"i:p:m:c:" )) !=-1 ) {
Changing the api for just one command type is problematic.
If we are going to do it, then it should be done in its own designated series, And in a way that will not break the legacy api.
Also, given the extent of use of this feature - I don't think that the api of the current mode (default) should be changed. Meaning people should still be able to run ./mmc ffu <fluf> <dev> as they always did.
Quoted 34 lines
mmc_ffu.c new file +10
-0+ switch (opt) { + case 'i': + fw_img = optarg; + break; + case 'p': + device = optarg; + break; + case 'c': + default_chunk = atoi(optarg); + if (default_chunk > MMC_IOC_MAX_BYTES || default_chunk %512) {
mmc_ffu.c new file +8
-0+fprintf (stderr,"Invalid chunk size" ); +exit (1 ); + } +break ; +case 'm' : + ffu_mode =atoi (optarg); +if (ffu_mode >1 ) { + fprintf(stderr, "Unsupported ffu mode `%d'.\n",
ffu_mode);mmc_ffu.c new file +9
-0+abort (); + } +break ; +default : +/* Unknown option or missing argument for options */ +if (isprint (optopt)) +fprintf (stderr,"Unknown option `-%c'.\n" , optopt); +else + fprintf(stderr, "Unknown option character `\\x%x'.\n",optopt);
mmc_ffu.c new file +4
-0+abort (); + } + } + fprintf(stderr, "eMMC Devie: %s, fw %s, FFU mode %d, chunk size:
Quoted 2 lines
%d\n",
+ device,fw_img,ffu_mode,default_chunk);
I think that all this part, from here and up to pretty much do_retry, Can be packed into a ffu_prepare() handler.
Each do_ffu: do_ffu, do_ffu2, do_ffu3 etc. can call it with its applicable arguments. I think you would end up with much less code this way.
The do_retry part is common to all modes: __do_ffu().
And a 3rd wrapping-up phase, post do_retry.
Thanks,
Avri
Quoted 127 lines
mmc_ffu.c new file +29
-0+ dev_fd =open (device,O_RDWR ); +if (dev_fd <0 ) { +perror ("device open failed" ); +exit (1 ); + } + img_fd =open (fw_img,O_RDONLY ); +if (img_fd <0 ) { +perror ("image open failed" ); +close (dev_fd); +exit (1 ); + } + + ret =read_extcsd (dev_fd, ext_csd); +if (ret) { +fprintf (stderr,"Could not read EXT_CSD from %s\n" , device); + goto out; + } +if (ffu_is_supported (ext_csd, device) <=0 ) + goto out; + + fw_size =lseek (img_fd,0 ,SEEK_END ); +if (fw_size ==0 ) { +fprintf (stderr,"Wrong firmware size" ); + 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);
mmc_ffu.c new file +17
-0+ goto out; + } +/* allocate maximum required */ + fw_buf =malloc (fw_size); +if (!fw_buf) { +perror ("failed to allocate memory" ); + goto out; + } +/* 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; + } + + sect_done = do_ffu_download((int *)&dev_fd, ext_csd, fw_buf, fw_size,
default_chunk);mmc_ffu.c new file +4
-0+ +/* Check programmed sectors */ +if (sect_done >0 && (sect_done *512 ) == fw_size) { + fprintf(stderr, "Programmed %jd/%jd bytes\n", (intmax_t)fw_size,(intmax_t)fw_size);
mmc_ffu.c new file +3
-0+fprintf (stderr,"Programming finished with status %d \n" , ret); + }else { + fprintf(stderr, "Firmware bundle download failed. Operation status%d\n",
sect_done);mmc_ffu.c new file +5
-0+ ret = -EIO ; + goto out; + } +/* +* By spec - check if mode operation codes are supported in ffu features,
mmc_ffu.c new file +4
-0+* 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);
mmc_ffu.c new file +6
-0+ ret =0 ; + goto out; + } + +fprintf (stderr,"Installing firmware on %s...\n" , device); + multi_cmd = calloc(1, sizeof(struct mmc_ioc_multi_cmd) + 2 *
sizeof(struct mmc_ioc_cmd));mmc_ffu.c new file +10
-0+if (!multi_cmd) { +perror ("failed to allocate memory" ); + ret = -ENOMEM ; + goto out; + } + +/* Re-enter ffu mode and install the firmware */ + multi_cmd->num_of_cmds =2 ; +/* put device into ffu mode */ + fill_switch_cmd(&multi_cmd->cmds[0], EXT_CSD_MODE_CONFIG,
EXT_CSD_FFU_MODE);mmc_ffu.c new file +2
-0+/* Re-enter ffu mode and set ext_csd to install mode */ + fill_switch_cmd(&multi_cmd->cmds[1],
EXT_CSD_MODE_OPERATION_CODES,EXT_CSD_FFU_INSTALL);mmc_ffu.c new file +7
-0+ +/* 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);mmc_ffu.c new file +27
-1+/* In case multi-cmd ioctl failed before exiting from ffu mode */ +ioctl (dev_fd,MMC_IOC_CMD , &multi_cmd->cmds[1 ]); + goto out; + } + + ret =read_extcsd (dev_fd, ext_csd); +if (ret) { +fprintf (stderr,"Could not read EXT_CSD from %s\n" , device); + goto out; + } + +/* return status */ + ret = ext_csd[EXT_CSD_FFU_STATUS ]; +if (ret) +fprintf (stderr,"%s: error %d during FFU install:\n" , device, ret); +else +fprintf (stderr,"FFU finished successfully\n" ); + +out: +if (fw_buf) +free (fw_buf); +if (multi_cmd) +free (multi_cmd); +close (img_fd); +close (dev_fd); +return ret; +} --2.34.1
PATCH v2 2/5 mmc-utils: Add FFU mode 2
In reply to Bean HuoFrom: Bean Huo <[email protected]>
Added a new FFU mode 2 that ensures atomic firmware image download to improve reliability and provide a smoother FFU process. In this mode, begins with CMD6, followed by repeated CMD23+CMD25 for downloading the firmware image. Once the entire firmware image is downloaded, the FFU mode is exited with CMD6, ensuring the download is treated as an atomic operation.
--- mmc.c | 4 +-- mmc_ffu.c | 95 +++++++++++++++++++++++++++++++++++++++---------------- 2 files changed, 70 insertions(+), 29 deletions(-)
mmc.c +2 -2
@@ -233,8 +233,8 @@ static struct Command commands[] = {"[-c <chunk-bytes>] is optional and defaults to its max - 512k. " "should be in decimal bytes and sector aligned.\n" "[-m <ffu_mode>] Optional, provides five firmware bundle download command modes:\n" -" -m 1: Default mode, utilizing the CMD6+CMD23+CMD25+CMD6 command sequence. This \n" -" may exit FFU mode during firmware bundle downloading if FW size exceeds the chunk size. \n" , +" -m 1: Default mode (CMD6+CMD23+CMD25+CMD6 repeated), may exit FFU mode if the firmware size exceeds chunk size.\n" +" -m 2: FFU mode 2 (enter FFU mode, CMD23+CMD25 repeated, exit FFU mode), stays in FFU mode until firmware download completes.\n" ,NULL }, { do_erase, -4,
mmc_ffu.c +68 -27
160 lines not on this page · raw message
Signature · 1 line
2.34.1
PATCH v2 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 leveraging CMD25+CMD12 for Open-ended Multiple-block write to download the firmware bundle.
--- mmc.c | 3 ++- mmc.h | 1 + mmc_ffu.c | 9 ++++++++- 3 files changed, 11 insertions(+), 2 deletions(-)
mmc.c +2 -1
@@ -234,7 +234,8 @@ static struct Command commands[] = {"should be in decimal bytes and sector aligned.\n" "[-m <ffu_mode>] Optional, provides five firmware bundle download command modes:\n" " -m 1: Default mode (CMD6+CMD23+CMD25+CMD6 repeated), may exit FFU mode if the firmware size exceeds chunk size.\n" -" -m 2: FFU mode 2 (enter FFU mode, CMD23+CMD25 repeated, exit FFU mode), stays in FFU mode until firmware download completes.\n" , +" -m 2: FFU mode 2 (enter FFU mode, CMD23+CMD25 repeated, exit FFU mode), stays in FFU mode until firmware download completes.\n" +" -m 3: FFU mode 3 (enter FFU mode, CMD25+CMD12 repeated, exit FFU mode), stays in FFU mode until firmware download completes.\n" ,NULL }, { do_erase, -4,
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_ffu.c +8 -1
@@ -48,6 +48,13 @@ static void set_ffu_download_cmd(struct mmc_ioc_multi_cmd *multi_cmd, __u8 *ext_ 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 ; + } }
@@ -233,7 +240,7 @@ int do_ffu(int nargs, char **argv)break ;case 'm' : ffu_mode =atoi (optarg); -if (ffu_mode >2 ) { +if (ffu_mode >3 ) {fprintf (stderr,"Unsupported ffu mode `%d'.\n" , ffu_mode);abort (); }
Signature · 1 line
2.34.1
PATCH v2 4/5 mmc-utils: Added FFU mode 4 that uses CMD6 and CMD24 for single-block firmware download
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 block is written, CMD6 is used to exit FFU mode.
--- mmc.c | 3 ++- mmc_ffu.c | 16 ++++++++++++++-- 2 files changed, 16 insertions(+), 3 deletions(-)
mmc.c +2 -1
@@ -235,7 +235,8 @@ static struct Command commands[] = {"[-m <ffu_mode>] Optional, provides five firmware bundle download command modes:\n" " -m 1: Default mode (CMD6+CMD23+CMD25+CMD6 repeated), may exit FFU mode if the firmware size exceeds chunk size.\n" " -m 2: FFU mode 2 (enter FFU mode, CMD23+CMD25 repeated, exit FFU mode), stays in FFU mode until firmware download completes.\n" -" -m 3: FFU mode 3 (enter FFU mode, CMD25+CMD12 repeated, exit FFU mode), stays in FFU mode until firmware download completes.\n" , +" -m 3: FFU mode 3 (enter FFU mode, CMD25+CMD12 repeated, exit FFU mode), stays in FFU mode until firmware download completes.\n" +" -m 4: FFU mode 4 (CMD6+CMD24+CMD6 repeated), exits FFU mode after each cycle.\n" ,NULL }, { do_erase, -4,
mmc_ffu.c +14 -2
@@ -55,6 +55,11 @@ static void set_ffu_download_cmd(struct mmc_ioc_multi_cmd *multi_cmd, __u8 *ext_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 ); } }
@@ -141,8 +146,10 @@ static int do_ffu_download(int *dev_fd, __u8 *ext_csd, __u8 *fw_buf, off_t fw_sireturn -EINVAL ; } -if (ffu_mode !=1 )/* only in FFU mode 1, mmc_ioc_multi_cmd contains 4 commands */ +if (ffu_mode ==2 || ffu_mode ==3 )/* only in FFU mode 1, mmc_ioc_multi_cmd contains 4 commands */ num_of_cmds =2 ; +else if (ffu_mode ==4 ) + num_of_cmds =3 ;/* allocate maximum required */ multi_cmd =calloc (1 ,sizeof (struct mmc_ioc_multi_cmd ) + num_of_cmds *sizeof (struct mmc_ioc_cmd ));
@@ -240,7 +247,7 @@ int do_ffu(int nargs, char **argv)break ;case 'm' : ffu_mode =atoi (optarg); -if (ffu_mode >3 ) { +if (ffu_mode >4 ) {fprintf (stderr,"Unsupported ffu mode `%d'.\n" , ffu_mode);abort (); }
@@ -254,6 +261,11 @@ int do_ffu(int nargs, char **argv)abort (); } } + +if (ffu_mode ==4 ) +/* FFU mode 4 uses CMD24, the write is limited to single-block operations*/ + default_chunk =512 ; +fprintf (stderr,"eMMC Devie: %s, fw %s, FFU mode %d, chunk size: %d\n" , device, fw_img, ffu_mode, default_chunk); dev_fd =open (device,O_RDWR );
Signature · 1 line
2.34.1
PATCH v2 5/5 mmc-utils: add FFU mode 5 for firmware download using CMD6 and repeated CMD24 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.c | 3 ++- mmc_ffu.c | 20 ++++++++++++++------ 2 files changed, 16 insertions(+), 7 deletions(-)
mmc.c +2 -1
@@ -236,7 +236,8 @@ static struct Command commands[] = {" -m 1: Default mode (CMD6+CMD23+CMD25+CMD6 repeated), may exit FFU mode if the firmware size exceeds chunk size.\n" " -m 2: FFU mode 2 (enter FFU mode, CMD23+CMD25 repeated, exit FFU mode), stays in FFU mode until firmware download completes.\n" " -m 3: FFU mode 3 (enter FFU mode, CMD25+CMD12 repeated, exit FFU mode), stays in FFU mode until firmware download completes.\n" -" -m 4: FFU mode 4 (CMD6+CMD24+CMD6 repeated), exits FFU mode after each cycle.\n" , +" -m 4: FFU mode 4 (CMD6+CMD24+CMD6 repeated), exits FFU mode after each cycle.\n" +" -m 5: FFU mode 5 (CMD6 enter FFU mode, CMD24 repeated, CMD6 exit FFU mode) stays in FFU mode until firmware download completes.\n" ,NULL }, { do_erase, -4,
mmc_ffu.c +14 -6
@@ -60,6 +60,9 @@ static void set_ffu_download_cmd(struct mmc_ioc_multi_cmd *multi_cmd, __u8 *ext_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 { +set_single_cmd (&multi_cmd->cmds[0 ],MMC_WRITE_BLOCK ,1 ,1 , arg); +mmc_ioc_cmd_set_data (multi_cmd->cmds[0 ], buf + offset); } }
@@ -150,6 +153,8 @@ static int do_ffu_download(int *dev_fd, __u8 *ext_csd, __u8 *fw_buf, off_t fw_si num_of_cmds =2 ; else if (ffu_mode == 4) num_of_cmds =3 ; + else if (ffu_mode == 5) + num_of_cmds =1 ;/* allocate maximum required */ multi_cmd =calloc (1 ,sizeof (struct mmc_ioc_multi_cmd ) + num_of_cmds *sizeof (struct mmc_ioc_cmd ));
@@ -171,11 +176,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
@@ -247,7 +255,7 @@ int do_ffu(int nargs, char **argv)break ;case 'm' : ffu_mode =atoi (optarg); -if (ffu_mode >4 ) { +if (ffu_mode >5 ) {fprintf (stderr,"Unsupported ffu mode `%d'.\n" , ffu_mode);abort (); }
@@ -262,8 +270,8 @@ int do_ffu(int nargs, char **argv) } } -if (ffu_mode ==4 ) -/* FFU mode 4 uses CMD24, the write is limited to single-block operations*/ +if (ffu_mode ==4 || ffu_mode ==5 ) +/* FFU mode 4/5 uses CMD24, the write is limited to single-block operations*/ default_chunk =512 ; fprintf(stderr, "eMMC Devie: %s, fw %s, FFU mode %d, chunk size: %d\n",
Signature · 1 line
2.34.1
Hi,
Thank you for this series.
Quoted 8 lines
Hi Avri, Ulf
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.
Ack on that.
I concur that various devices may respond better to different mode.
Thus, allowing different modes to choose from, improves the overall operational stability.
Will try to review it early next week.
Thanks,
Avri
Quoted 9 lines
Hi,
Thank you for this series.Quoted 6 lines
Hi Avri, Ulf
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.
Quoted 8 lines
Quoted 2 lines
The new FFU implementation can support diverse vendor requirements and operational conditions.
Ack on that.
I concur that various devices may respond better to different mode. Thus, allowing different modes to choose from, improves the overall operational stability.Will try to review it early next week.
Gave it a quick look, and some stuff concerning your design pops up:
1) You are changing the api to follow a more common optarg mode.
While I agree that this is a most welcome enhancement - it should be done in its own designated series, And in a way that will not break the legacy api.
2) given the extent of use of this feature - I don't think that the api of the current mode (default) should be changed. Meaning people should still be able to run ./mmc ffu <fluf> <dev> as they always did.
3) Essentially by adding modes you are mainly changing the part that encapsulates the content of the multi-ioctl. If instead of adding a new mode argument, you would add new commands - I think you would end up with much less code. Meaning, we would have now:
./mmc ffu <fluf> <dev> /* the current (default) mode */
./mmc ffu2 <fluf> <dev> /* mode 2 */
./mmc ffu3 <fluf> <dev> /* mode 3 */
Etc.
And each vendor / FAEs / validation team etc. would be able to choose whatever suite best.
Please also note that we have a man page and a docs section.
Will give it a thorough look next week.
Thanks,
Avri
Quoted 3 lines
Thanks,
Avri