* [PATCHv2] mmc-utils: Fix 4k sector size block count in FFU
@ 2022-06-24 13:18 Christian Löhle
2022-06-24 13:53 ` Avri Altman
2022-07-13 11:03 ` Ulf Hansson
0 siblings, 2 replies; 3+ messages in thread
From: Christian Löhle @ 2022-06-24 13:18 UTC (permalink / raw)
To: Avri Altman, ulf.hansson, linux-mmc
FFU used the wrong assumption, that CMD23 work in
4k sector chunks when setting the block count.
Instead the CMD23 block count argument just needs
to be a multiple of 8, which the fw_size is anyway.
Fixes: 89cd01ed865a (mmc_utils: add ffu support)
Signed-off-by: Christian Loehle <cloehle@hyperstone.com>
---
mmc_cmds.c | 15 ++++++++-------
1 file changed, 8 insertions(+), 7 deletions(-)
diff --git a/mmc_cmds.c b/mmc_cmds.c
index bb0f022..12b7802 100644
--- a/mmc_cmds.c
+++ b/mmc_cmds.c
@@ -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,17 @@ 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 / 512;
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;
+ /*
+ * blksz and blocks essentially do not matter, as long as the product
+ * is fw_size, but some hosts don't handle larger blksz well.
+ */
+ multi_cmd->cmds[2].blksz = 512;
+ multi_cmd->cmds[2].blocks = fw_size / 512;
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
^ permalink raw reply related [flat|nested] 3+ messages in thread
* RE: [PATCHv2] mmc-utils: Fix 4k sector size block count in FFU
2022-06-24 13:18 [PATCHv2] mmc-utils: Fix 4k sector size block count in FFU Christian Löhle
@ 2022-06-24 13:53 ` Avri Altman
2022-07-13 11:03 ` Ulf Hansson
1 sibling, 0 replies; 3+ messages in thread
From: Avri Altman @ 2022-06-24 13:53 UTC (permalink / raw)
To: Christian Löhle, ulf.hansson, linux-mmc
> FFU used the wrong assumption, that CMD23 work in
> 4k sector chunks when setting the block count.
> Instead the CMD23 block count argument just needs
> to be a multiple of 8, which the fw_size is anyway.
>
> Fixes: 89cd01ed865a (mmc_utils: add ffu support)
> Signed-off-by: Christian Loehle <cloehle@hyperstone.com>
Reviewed-by: Avri Altman <avri.altman@wdc.com>
Thanks,
Avri
> ---
> mmc_cmds.c | 15 ++++++++-------
> 1 file changed, 8 insertions(+), 7 deletions(-)
>
> diff --git a/mmc_cmds.c b/mmc_cmds.c
> index bb0f022..12b7802 100644
> --- a/mmc_cmds.c
> +++ b/mmc_cmds.c
> @@ -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,17 @@ 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 / 512;
> 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;
> + /*
> + * blksz and blocks essentially do not matter, as long as the product
> + * is fw_size, but some hosts don't handle larger blksz well.
> + */
> + multi_cmd->cmds[2].blksz = 512;
> + multi_cmd->cmds[2].blocks = fw_size / 512;
> 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
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCHv2] mmc-utils: Fix 4k sector size block count in FFU
2022-06-24 13:18 [PATCHv2] mmc-utils: Fix 4k sector size block count in FFU Christian Löhle
2022-06-24 13:53 ` Avri Altman
@ 2022-07-13 11:03 ` Ulf Hansson
1 sibling, 0 replies; 3+ messages in thread
From: Ulf Hansson @ 2022-07-13 11:03 UTC (permalink / raw)
To: Christian Löhle; +Cc: Avri Altman, linux-mmc
On Fri, 24 Jun 2022 at 15:18, Christian Löhle <CLoehle@hyperstone.com> wrote:
>
> FFU used the wrong assumption, that CMD23 work in
> 4k sector chunks when setting the block count.
> Instead the CMD23 block count argument just needs
> to be a multiple of 8, which the fw_size is anyway.
>
> Fixes: 89cd01ed865a (mmc_utils: add ffu support)
> Signed-off-by: Christian Loehle <cloehle@hyperstone.com>
Applied for https://git.kernel.org/pub/scm/utils/mmc/mmc-utils.git
master, thanks!
Kind regards
Uffe
> ---
> mmc_cmds.c | 15 ++++++++-------
> 1 file changed, 8 insertions(+), 7 deletions(-)
>
> diff --git a/mmc_cmds.c b/mmc_cmds.c
> index bb0f022..12b7802 100644
> --- a/mmc_cmds.c
> +++ b/mmc_cmds.c
> @@ -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,17 @@ 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 / 512;
> 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;
> + /*
> + * blksz and blocks essentially do not matter, as long as the product
> + * is fw_size, but some hosts don't handle larger blksz well.
> + */
> + multi_cmd->cmds[2].blksz = 512;
> + multi_cmd->cmds[2].blocks = fw_size / 512;
> 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
>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-07-13 11:04 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-24 13:18 [PATCHv2] mmc-utils: Fix 4k sector size block count in FFU Christian Löhle
2022-06-24 13:53 ` Avri Altman
2022-07-13 11:03 ` Ulf Hansson
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.