mmc-utils: dont divide CMD23 count by sector size
PATCH 1/1 mmc-utils: dont divide CMD23 count by sector size
FFU used to divide the fw_size by native sector size. If native sector size is 4K the accesses need to be aligned and a multiple of 4K, other than that CMD23 SET_BLOCK_COUNT does not change.
The previous handling lead to MMC_SET_BLOCK_COUNT setting a too small block count for the FFU fw_size. While at it also correct CMD25 blksz and blocks fields to reflect the actual transfer.
--- mmc_cmds.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-)
mmc_cmds.c +4 -7
@@ -2768,7 +2768,6 @@ int do_ffu(int nargs, char **argv)ssize_t chunk_size;char *device;struct mmc_ioc_multi_cmd *multi_cmd =NULL ; -__u32 blocks =1 ;if (nargs !=3 ) {fprintf (stderr,"Usage: ffu <image name> </path/to/mmcblkX> \n" );
@@ -2826,15 +2825,13 @@ int do_ffu(int nargs, char **argv) 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; } -/* calculate required fw blocks for CMD25 */ - blocks = fw_size / sect_size; -/* set CMD ARG */ arg = ext_csd[EXT_CSD_FFU_ARG_0 ] | ext_csd[EXT_CSD_FFU_ARG_1] << 8 |
@@ -2857,13 +2854,13 @@ int do_ffu(int nargs, char **argv)/* send block count */ multi_cmd->cmds[1 ].opcode =MMC_SET_BLOCK_COUNT ; - multi_cmd->cmds[1 ].arg = blocks; + multi_cmd->cmds[1 ].arg = fw_size; multi_cmd->cmds[1 ].flags =MMC_RSP_SPI_R1 |MMC_RSP_R1 |MMC_CMD_AC ;/* send image chunk */ multi_cmd->cmds[2 ].opcode =MMC_WRITE_MULTIPLE_BLOCK ; - multi_cmd->cmds[2 ].blksz = sect_size; - multi_cmd->cmds[2 ].blocks = blocks; + multi_cmd->cmds[2 ].blksz = fw_size; + multi_cmd->cmds[2 ].blocks =1 ; multi_cmd->cmds[2 ].arg = arg; multi_cmd->cmds[2 ].flags =MMC_RSP_SPI_R1 |MMC_RSP_R1 |MMC_CMD_ADTC ; multi_cmd->cmds[2 ].write_flag =1 ;
Signature · 4 lines
2.36.1 Hyperstone GmbH | Reichenaustr. 39a | 78467 Konstanz Managing Director: Dr. Jan Peter Berns. Commercial register of local courts: Freiburg HRB381782
dont
^^^^
Don't
Quoted 4 lines
FFU used to divide the
fw_sizeby native sector size. If native sector size is 4K the accesses need to be aligned and a multiple of 4K, other than that CMD23SET_BLOCK_COUNTdoes not change.
I am not sure what are you fixing, aside of violating a spec requirement:
" Downloaded firmware bundle must be DATA_SECTOR_SIZE size aligned (internal padding of the bundle might be required)." So if the fw fluf is not sector-size aligned, you need to make it so.
Thanks,
Avri
Quoted 65 lines
The previous handling lead to
MMC_SET_BLOCK_COUNTsetting a too small block count for the FFUfw_size. While at it also correct CMD25 blksz and blocks fields to reflect the actual transfer.Signed-off-by Christian Loehle <[email protected]>--- mmc_cmds.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-)mmc_cmds.c +1
-4@@ -2768,7 +2768,6 @@ int do_ffu(int nargs, char **argv)ssize_t chunk_size;char *device;struct mmc_ioc_multi_cmd *multi_cmd =NULL ; -__u32 blocks =1 ;if (nargs !=3 ) {fprintf (stderr,"Usage: ffu <image name> </path/to/mmcblkX> \n" );@@ -2826,15 +2825,13 @@ int do_ffu(int nargs, char **argv) 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; } -/* calculate required fw blocks for CMD25 */ - blocks = fw_size / sect_size; -/* set CMD ARG */ arg = ext_csd[EXT_CSD_FFU_ARG_0] |ext_csd[EXT_CSD_FFU_ARG_1] << 8 |mmc_cmds.c +3
-3@@ -2857,13 +2854,13 @@ int do_ffu(int nargs, char **argv)/* send block count */ multi_cmd->cmds[1 ].opcode =MMC_SET_BLOCK_COUNT ; - multi_cmd->cmds[1 ].arg = blocks; + multi_cmd->cmds[1 ].arg = fw_size; multi_cmd->cmds[1 ].flags =MMC_RSP_SPI_R1 |MMC_RSP_R1 |MMC_CMD_AC ;/* send image chunk */ multi_cmd->cmds[2 ].opcode =MMC_WRITE_MULTIPLE_BLOCK ; - multi_cmd->cmds[2 ].blksz = sect_size; - multi_cmd->cmds[2 ].blocks = blocks; + multi_cmd->cmds[2 ].blksz = fw_size; + multi_cmd->cmds[2 ].blocks =1 ; multi_cmd->cmds[2 ].arg = arg; multi_cmd->cmds[2].flags = MMC_RSP_SPI_R1 | MMC_RSP_R1 |MMC_CMD_ADTC; multi_cmd->cmds[2].write_flag = 1;--
2.36.1
Hyperstone GmbH | Reichenaustr. 39a | 78467 Konstanz Managing Director: Dr. Jan Peter Berns. Commercial register of local courts: Freiburg HRB381782