Add multiple FFU modes based on eMMC specification 6.6.18 for flexible firmware updates
Subsystems (2)
cover Add multiple FFU modes based on eMMC specification 6.6.18 for flexible firmware updates
Hi Avri,
Based on our discussion during 2024 ALPSS, here are the patches for eMMC FFU.
This patch series introduces several new FFU modes, as outlined in the eMMC specification 6.6.18, to enhance the flexibility and reliability of firmware downloads to eMMC devices in the filed.
The purpose of these patches is to offer different FFU modes to compatible with different vendors, allowing for various command sequences to optimize for different operational needs, ensuring both atomicity and smoothness of firmware updates. These additional FFU modes provide multiple options for performing firmware updates under different circumstances:
1, The host can choose between different update strategies depending on the device’s capabilities and the size of the firmware bundle.
2, Ensuring that firmware downloads are treated as a single operation, preventing partial updates that could leave the device in an unstable state.
3, Some modes are designed to keep the device in FFU mode throughout the entire process, minimizing the risk of premature exits or failures during updates.
By supporting these modes, we aim to enhance the robustness and flexibility of the FFU process, accommodating a wider range of firmware sizes and ensuring smoother, more reliable FFU in the field.
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 commands
Makefile | 1 + mmc.c | 14 +- mmc.h | 1 + mmc_cmds.c | 274 -------------------------------------- mmc_cmds.h | 52 ++++++++ mmc_ffu.c | 385 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 449 insertions(+), 278 deletions(-) create mode 100644 mmc_ffu.c
Signature · 1 line
2.34.1
PATCH 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
PATCH 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 | 93 +++++++++++++++++++++++++++++++++++++++---------------- 2 files changed, 68 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 +66 -27
158 lines not on this page · raw message
Signature · 1 line
2.34.1
PATCH 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 ; + } }
@@ -231,7 +238,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 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 | 11 +++++++++-- 2 files changed, 11 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 +9 -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 ); } }
@@ -139,8 +144,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 ));
@@ -238,7 +245,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 (); }
Signature · 1 line
2.34.1
PATCH 5/5 mmc-utils: add FFU mode 5 for firmware download using CMD6 and repeated CMD24 commands
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 | 16 ++++++++++++---- 2 files changed, 14 insertions(+), 5 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 +12 -4
@@ -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); } }
@@ -148,6 +151,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 ));
@@ -169,11 +174,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
@@ -245,7 +253,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 (); }
Signature · 1 line
2.34.1