From 2a934139cfeef1249e46f50fbec548f11c2dd8ca Mon Sep 17 00:00:00 2001 From: Bruno Matic Date: Tue, 20 Sep 2022 14:47:49 +0200 Subject: [PATCH] mmc-utils: Fix ffu in case of unsupported MODE_OPERATION_CODES Move up the return in case MODE_OPERATION_CODES is not supported. According to the specification when MODE_OPERATION_CODES is not supported no checks should be done against NUM_OF_FW_SEC_PROG. Signed-off-by: Bruno Matic Fixes: 89cd01ed865a (mmc_utils: add ffu support) Reviewed-by: Avri Altman Link: https://lore.kernel.org/r/20220920124749.24073-1-bruno.matic@nokia.com Signed-off-by: Ulf Hansson --- mmc_cmds.c | 89 ++++++++++++++++++++++++++++-------------------------- 1 file changed, 47 insertions(+), 42 deletions(-) diff --git a/mmc_cmds.c b/mmc_cmds.c index 29abd1d..2957aa9 100644 --- a/mmc_cmds.c +++ b/mmc_cmds.c @@ -2899,6 +2899,16 @@ do_retry: goto out; } + /* + * 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; + goto out; + } + ret = read_extcsd(dev_fd, ext_csd); if (ret) { fprintf(stderr, "Could not read EXT_CSD from %s\n", device); @@ -2929,49 +2939,44 @@ do_retry: goto out; } - /* check mode operation for ffu install*/ - if (!ext_csd[EXT_CSD_FFU_FEATURES]) { - fprintf(stderr, "Please reboot to complete firmware installation on %s\n", device); + 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 */ + multi_cmd->cmds[1].opcode = MMC_SWITCH; + multi_cmd->cmds[1].blksz = 0; + multi_cmd->cmds[1].blocks = 0; + multi_cmd->cmds[1].arg = (MMC_SWITCH_MODE_WRITE_BYTE << 24) | + (EXT_CSD_MODE_OPERATION_CODES << 16) | + (EXT_CSD_FFU_INSTALL << 8) | + EXT_CSD_CMD_SET_NORMAL; + multi_cmd->cmds[1].flags = MMC_RSP_SPI_R1B | MMC_RSP_R1B | MMC_CMD_AC; + multi_cmd->cmds[1].write_flag = 1; + + /* 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, "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 */ - multi_cmd->cmds[1].opcode = MMC_SWITCH; - multi_cmd->cmds[1].blksz = 0; - multi_cmd->cmds[1].blocks = 0; - multi_cmd->cmds[1].arg = (MMC_SWITCH_MODE_WRITE_BYTE << 24) | - (EXT_CSD_MODE_OPERATION_CODES << 16) | - (EXT_CSD_FFU_INSTALL << 8) | - EXT_CSD_CMD_SET_NORMAL; - multi_cmd->cmds[1].flags = MMC_RSP_SPI_R1B | MMC_RSP_R1B | MMC_CMD_AC; - multi_cmd->cmds[1].write_flag = 1; - - /* 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"); - } + fprintf(stderr, "FFU finished successfully\n"); } out: