From patchwork Sun Jun 25 10:38:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Avri Altman X-Patchwork-Id: 13291871 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7BA7BEB64DC for ; Sun, 25 Jun 2023 10:38:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231303AbjFYKie (ORCPT ); Sun, 25 Jun 2023 06:38:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57546 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230029AbjFYKic (ORCPT ); Sun, 25 Jun 2023 06:38:32 -0400 Received: from esa5.hgst.iphmx.com (esa5.hgst.iphmx.com [216.71.153.144]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7544FE44 for ; Sun, 25 Jun 2023 03:38:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1687689512; x=1719225512; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=MS+iE3tmGZDg6oxTGv/Nw5+qXdl+a4OOoBrBlUJwlcc=; b=mlpMAiBtzbsNxCp5p4XUQ9fB/J/7bVviCkb7bmhXeo5TrmYCbH1fjusu Fqia7E40tx0Yd+KKUPmWBqdLRMWgHV8JkBWuGCtMXoOxy8srfrFFvLT/S C/n7mOFqI3uKw1cjNSYDzRXrjjZDjlZkd7ZpYj/92Ex8gdoWt7x005q2j 1gwu9tj7vEo7blRrGwOQV9zfLVNEcIeTBvEr6Vs0jteea5gINStbG+Jgp BZ+N24y7RR7y/pYQwN23lPSpsVFEpuh5TEsIr3T0BJ6t8QEW0ZKcMxQt5 vRUrHQ1UhCnxIFlxUHwIfcJufG8JVVUGjJwjN8LwKZW7wDhrkCqfACTpK A==; X-IronPort-AV: E=Sophos;i="6.01,157,1684771200"; d="scan'208";a="236159312" Received: from h199-255-45-15.hgst.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 25 Jun 2023 18:38:32 +0800 IronPort-SDR: U8SxvUUfj3LJnIfhuH7mIfKgMkBLDKW/POQ6dp8GR9k8AGnOP0JEsD01YDcvBqSYWMUgmAP4Lr 5zgh8tdSIKa5jjJ2pGYsP+5Q3c12VqRY95LzVFIN1uqsII/PXPvmM7SotRD6yXTSUPsZQJAu4j 1qXTO43j6wtW39zg6hldLPrHZTLYI2cN8JvwqZiLhcKcWMu1wNatN4zRX1wEDTNgg/n7rmte3l lnzb3iw966pkesO/lFxUrSwkrwqLDHJSRH9/QVHNjWqOk7Mk8Vzq8J7ZZEc/fywxN1QTGZidUa exo= Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 25 Jun 2023 02:47:12 -0700 IronPort-SDR: YQZo9Cme1VeUGrAzwDdCpbY4ffW9dblMU56n7npGwLMDV4gpB9ptUMAmGb75kNLGqBURhBcT8Y 9VLiWie+rUjaX3H8Y1fnuk+WqBvsaDZnPJkKzgwYdMqnbtcDgyj0+mgKKYwA/c7LzhowGOH3X6 /aWYw0w5Gwde9b1nFFIvC4SPdMKd4xVFuDMzJdFeAJssymBXvNs8hiJPCDdMZPJ4Gt2LAyZP6+ zyvL9Z/OW1Yid8zX5cdkE5dvti4dHybwztG+Y3BER+gALveZr/I1Gh5UvpsycEKlySNwkdoqUx +6U= WDCIronportException: Internal Received: from bxygm33.ad.shared ([10.45.31.229]) by uls-op-cesaip01.wdc.com with ESMTP; 25 Jun 2023 03:38:31 -0700 From: Avri Altman To: Ulf Hansson , linux-mmc@vger.kernel.org Cc: Avri Altman Subject: [PATCH 1/6] mmc-utils: Add fill_switch_cmd handler Date: Sun, 25 Jun 2023 13:38:09 +0300 Message-Id: <20230625103814.105-2-avri.altman@wdc.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230625103814.105-1-avri.altman@wdc.com> References: <20230625103814.105-1-avri.altman@wdc.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org Writing the ext_csd (MMC_SWITCH) is done in several places throught the code. Prepare a single handler for that. This patch has no functional change. Signed-off-by: Avri Altman --- mmc_cmds.c | 50 ++++++++++++++++++-------------------------------- 1 file changed, 18 insertions(+), 32 deletions(-) diff --git a/mmc_cmds.c b/mmc_cmds.c index 26bdc38..da89724 100644 --- a/mmc_cmds.c +++ b/mmc_cmds.c @@ -79,19 +79,22 @@ int read_extcsd(int fd, __u8 *ext_csd) 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; +} + int write_extcsd_value(int fd, __u8 index, __u8 value, unsigned int timeout_ms) { int ret = 0; - struct mmc_ioc_cmd idata; + struct mmc_ioc_cmd idata = {}; + + fill_switch_cmd(&idata, index, value); - memset(&idata, 0, sizeof(idata)); - idata.write_flag = 1; - idata.opcode = MMC_SWITCH; - idata.arg = (MMC_SWITCH_MODE_WRITE_BYTE << 24) | - (index << 16) | - (value << 8) | - EXT_CSD_CMD_SET_NORMAL; - idata.flags = MMC_RSP_SPI_R1B | MMC_RSP_R1B | MMC_CMD_AC; /* Kernel will set cmd_timeout_ms if 0 is set */ idata.cmd_timeout_ms = timeout_ms; @@ -2887,13 +2890,8 @@ int do_ffu(int nargs, char **argv) multi_cmd->num_of_cmds = 4; /* put device into ffu mode */ - multi_cmd->cmds[0].opcode = MMC_SWITCH; - multi_cmd->cmds[0].arg = (MMC_SWITCH_MODE_WRITE_BYTE << 24) | - (EXT_CSD_MODE_CONFIG << 16) | - (EXT_CSD_FFU_MODE << 8) | - EXT_CSD_CMD_SET_NORMAL; - multi_cmd->cmds[0].flags = MMC_RSP_SPI_R1B | MMC_RSP_R1B | MMC_CMD_AC; - multi_cmd->cmds[0].write_flag = 1; + fill_switch_cmd(&multi_cmd->cmds[0], EXT_CSD_MODE_CONFIG, + EXT_CSD_FFU_MODE); /* send block count */ multi_cmd->cmds[1].opcode = MMC_SET_BLOCK_COUNT; @@ -2914,13 +2912,8 @@ int do_ffu(int nargs, char **argv) mmc_ioc_cmd_set_data(multi_cmd->cmds[2], buf); /* return device into normal mode */ - multi_cmd->cmds[3].opcode = MMC_SWITCH; - multi_cmd->cmds[3].arg = (MMC_SWITCH_MODE_WRITE_BYTE << 24) | - (EXT_CSD_MODE_CONFIG << 16) | - (EXT_CSD_NORMAL_MODE << 8) | - EXT_CSD_CMD_SET_NORMAL; - multi_cmd->cmds[3].flags = MMC_RSP_SPI_R1B | MMC_RSP_R1B | MMC_CMD_AC; - multi_cmd->cmds[3].write_flag = 1; + fill_switch_cmd(&multi_cmd->cmds[3], EXT_CSD_MODE_CONFIG, + EXT_CSD_NORMAL_MODE); /* read firmware */ lseek(img_fd, 0, SEEK_SET); @@ -2986,15 +2979,8 @@ do_retry: 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; + fill_switch_cmd(&multi_cmd->cmds[1], EXT_CSD_MODE_OPERATION_CODES, + EXT_CSD_FFU_INSTALL); /* send ioctl with multi-cmd */ ret = ioctl(dev_fd, MMC_IOC_MULTI_CMD, multi_cmd); From patchwork Sun Jun 25 10:38:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Avri Altman X-Patchwork-Id: 13291872 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 36D73EB64DC for ; Sun, 25 Jun 2023 10:38:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230029AbjFYKin (ORCPT ); Sun, 25 Jun 2023 06:38:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57564 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231389AbjFYKil (ORCPT ); Sun, 25 Jun 2023 06:38:41 -0400 Received: from esa5.hgst.iphmx.com (esa5.hgst.iphmx.com [216.71.153.144]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EBCBCE44 for ; Sun, 25 Jun 2023 03:38:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1687689521; x=1719225521; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=MWJLiWUXbMwqaIOfCZ1EtBsphwfasQAQddP1C9KPvTI=; b=kV5vml3XpSXSzNSfYUt6rZqIhcULGvRKJi4yEfp5H+lNbFMIBp34mQi3 pSn/hlGWiWaMqMTN4vwvfWYfKKhDapydnfABLF0vS8JmyzU6tZ97u3b3q AyTzT1i2u3hBKfbxmt62XJ/CqeYQ8MlhiZ2SM//EepoHfB24PvvVu7jqe c99fW7/L/TloxtcRjHPTICbxQDiod0E/nqGoGQ5JfSDw5Emfw9qcR487g H0Es7ywYpiPD+0sRVp0FjDrVQ75PnrCxIXKwMn4ukKKgl5wvkgQ2pW7Ib J/TLS7fzSNIs+y9fQkfyMdB+5K69rcWzR1mPaYPdC5XK6h/LFmpBvKlMf Q==; X-IronPort-AV: E=Sophos;i="6.01,157,1684771200"; d="scan'208";a="236159314" Received: from h199-255-45-15.hgst.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 25 Jun 2023 18:38:41 +0800 IronPort-SDR: miFaXqsed8E/gttjPitGYcAENVgS5ysu5TqD9pgKyP7rGjkE2oO026E6HOeWnEyBqaT4tvrTga seu0zlIaigWz51VUnM1HQvOlDnIIUHctkxoQKN2eQgJ6CfNf5+a5fuzmbVfO0zevPSsDPn0pTn 6OcFr3bj5wshhzZdrsQBLDfz6qa2BLPPvAvCMC9CqmAIUNHDy/T4uD0/TyGndbRaQKtqknVciG gpY4MQB2l1SSuRi4/pcf9Z7aF4MCKQsXf6KTgUvHb5eYYJrcK0AzdvoyAamD49et8U/uuP1ce8 Vos= Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 25 Jun 2023 02:47:21 -0700 IronPort-SDR: BEGS0jaXdn1IY73vxj+57h9Ma2hLPvSIz8euCfzIsteWA4j4EoPhj99SQOyuSPjXoIQb8+4nAD cEX2LWSNHrwil7Y8bjIas07rQ8UUaQqgx9sF+iyA0gonpRFFewTU+M49tNyAhif0nrx1Qnbp+V Gu4l9K5gfeGlH73lvoU1TTUfotMhcIo4kO7tH+zyKR3wVTiJ94VbzUBIbSq0lOuvWVvptWQGSD yNUTIQDP/+Tj3l8sLufhb9AbTBSQZsXNdGHrA/Dijv4Q49+rcq6dUCokebuQxI+E/+HLXeZdtY 6Y4= WDCIronportException: Internal Received: from bxygm33.ad.shared ([10.45.31.229]) by uls-op-cesaip01.wdc.com with ESMTP; 25 Jun 2023 03:38:40 -0700 From: Avri Altman To: Ulf Hansson , linux-mmc@vger.kernel.org Cc: Avri Altman Subject: [PATCH 2/6] mmc-utils: Add arg argument to set_single_cmd Date: Sun, 25 Jun 2023 13:38:10 +0300 Message-Id: <20230625103814.105-3-avri.altman@wdc.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230625103814.105-1-avri.altman@wdc.com> References: <20230625103814.105-1-avri.altman@wdc.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org Will prove itself useful in a minute. No functional change. Signed-off-by: Avri Altman --- mmc_cmds.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/mmc_cmds.c b/mmc_cmds.c index da89724..8650c2f 100644 --- a/mmc_cmds.c +++ b/mmc_cmds.c @@ -2095,11 +2095,12 @@ struct rpmb_frame { }; static inline void set_single_cmd(struct mmc_ioc_cmd *ioc, __u32 opcode, - int write_flag, unsigned int blocks) + int write_flag, unsigned int blocks, + __u32 arg) { ioc->opcode = opcode; ioc->write_flag = write_flag; - ioc->arg = 0x0; + ioc->arg = arg; ioc->blksz = 512; ioc->blocks = blocks; ioc->flags = MMC_RSP_SPI_R1 | MMC_RSP_R1 | MMC_CMD_ADTC; @@ -2152,18 +2153,18 @@ static int do_rpmb_op(int fd, /* Write request */ ioc = &mioc->cmds[0]; - set_single_cmd(ioc, MMC_WRITE_MULTIPLE_BLOCK, (1 << 31) | 1, 1); + set_single_cmd(ioc, MMC_WRITE_MULTIPLE_BLOCK, (1 << 31) | 1, 1, 0); mmc_ioc_cmd_set_data((*ioc), frame_in); /* Result request */ ioc = &mioc->cmds[1]; frame_status.req_resp = htobe16(MMC_RPMB_READ_RESP); - set_single_cmd(ioc, MMC_WRITE_MULTIPLE_BLOCK, 1, 1); + set_single_cmd(ioc, MMC_WRITE_MULTIPLE_BLOCK, 1, 1, 0); mmc_ioc_cmd_set_data((*ioc), &frame_status); /* Get response */ ioc = &mioc->cmds[2]; - set_single_cmd(ioc, MMC_READ_MULTIPLE_BLOCK, 0, 1); + set_single_cmd(ioc, MMC_READ_MULTIPLE_BLOCK, 0, 1, 0); mmc_ioc_cmd_set_data((*ioc), frame_out); break; @@ -2179,12 +2180,12 @@ static int do_rpmb_op(int fd, /* Read request */ ioc = &mioc->cmds[0]; - set_single_cmd(ioc, MMC_WRITE_MULTIPLE_BLOCK, 1, 1); + set_single_cmd(ioc, MMC_WRITE_MULTIPLE_BLOCK, 1, 1, 0); mmc_ioc_cmd_set_data((*ioc), frame_in); /* Get response */ ioc = &mioc->cmds[1]; - set_single_cmd(ioc, MMC_READ_MULTIPLE_BLOCK, 0, out_cnt); + set_single_cmd(ioc, MMC_READ_MULTIPLE_BLOCK, 0, out_cnt, 0); mmc_ioc_cmd_set_data((*ioc), frame_out); break; From patchwork Sun Jun 25 10:38:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Avri Altman X-Patchwork-Id: 13291873 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9DC07EB64DC for ; Sun, 25 Jun 2023 10:39:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231213AbjFYKjM (ORCPT ); Sun, 25 Jun 2023 06:39:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57576 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231389AbjFYKjK (ORCPT ); Sun, 25 Jun 2023 06:39:10 -0400 Received: from esa4.hgst.iphmx.com (esa4.hgst.iphmx.com [216.71.154.42]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ECAC9E45 for ; Sun, 25 Jun 2023 03:38:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1687689532; x=1719225532; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ShbTF5dHVyImpmx9MkyIpFezNqlNxYrjX59ePKZRqrY=; b=gacloTP2etHGIgu6yCc3grnSo8wvQ6E1k4Y6II6Gp5zuWjykfnW3vhBw BeYh21TLCmH/k7Q3aArE9+wrKwh32Bs2jePw13xGiVf0bnQyLUYyi3x+I W15g0btwbTl02A0iS6JHt00tr8eX0J444AkK7gN7/9yDm621bmRxLKqbK ykLXoEWVUDeCpCeP52aeu0h5Yn/vihrFBiA+w/8+Qto+cVQ+kiuQrm6Aw 55RIwSpAQa5fxptm5owN0H8O1/Nc+VkB0P6jLLfXe9itMIRwGSwZ5wWBF GPIv9U6PeJx31ZM/hZ6vg02k8SH4d3lA9zVDC9laEoRkB7rsoKfAhLb4l g==; X-IronPort-AV: E=Sophos;i="6.01,157,1684771200"; d="scan'208";a="234861676" Received: from h199-255-45-15.hgst.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 25 Jun 2023 18:38:52 +0800 IronPort-SDR: dq0bnib1Iyni+Fa5wGyOCUasl8E/EEsc6Ze9+W5JrI+wZsawhYeTleKMVlg5wK6PQMIcEa2OdV qRRHX03ratMo+/zvoEHe7tP5rkt2Mf0SeZ/8N655+ikC4S/zcLY9YZpXRiw3CpVcsJxv0hZvpG kZaJokMe1EbLKql1ivlIA0Z7V9LEBlIjPT8cuyk9yMdskZfFL7514a8tSvaDNMfjoFr8qnB+8v uH/iRrzV1Q7JubP67INJLyVwmSm7IuBJUsDO4dGotIagu2k63v6FXTLFksZjH39wrSNGEnFqan cy4= Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 25 Jun 2023 02:47:33 -0700 IronPort-SDR: hVv1vTsNogxcXPYRfuCBaoh1BWCh035BnABpRVKc4JjH2g7qbPkEcTluRSCPhLTeSR+7SHe6h8 LhspKPQ7SfmNkEoAlLp7wHC1eP7+OocZiNtSwAEgashB+akiQl1uKwSPp24qv/8/sS4BvU6bWD AJa6RoiohHLpxRmUu7tMIcqmyN+Btlp8pTaLFYKuaGJTuW8Xg6Cpl10V9r+JvFy8GnSPIeFerB 7OBmoh9Btj9gHkt1aSzOC7mhzKF94DmV7D/3J2FOi3deGlT2ZfUfr6whyc90q7tihfigBHNYCM hzM= WDCIronportException: Internal Received: from bxygm33.ad.shared ([10.45.31.229]) by uls-op-cesaip01.wdc.com with ESMTP; 25 Jun 2023 03:38:52 -0700 From: Avri Altman To: Ulf Hansson , linux-mmc@vger.kernel.org Cc: Avri Altman Subject: [PATCH 3/6] mmc-utils: ffu: Simplify ext_csd bytes parsing Date: Sun, 25 Jun 2023 13:38:11 +0300 Message-Id: <20230625103814.105-4-avri.altman@wdc.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230625103814.105-1-avri.altman@wdc.com> References: <20230625103814.105-1-avri.altman@wdc.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org The ext_csd register has this habbit of linking a contiguous set of bytes into one meaningful double-word. It does that where the least significant value is in the lower index - hence little-endian. Signed-off-by: Avri Altman --- mmc_cmds.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/mmc_cmds.c b/mmc_cmds.c index 8650c2f..adb72af 100644 --- a/mmc_cmds.c +++ b/mmc_cmds.c @@ -2880,10 +2880,7 @@ int do_ffu(int nargs, char **argv) } /* set CMD ARG */ - arg = ext_csd[EXT_CSD_FFU_ARG_0] | - ext_csd[EXT_CSD_FFU_ARG_1] << 8 | - ext_csd[EXT_CSD_FFU_ARG_2] << 16 | - ext_csd[EXT_CSD_FFU_ARG_3] << 24; + arg = htole32(*((__u32 *)&ext_csd[EXT_CSD_FFU_ARG_0])); /* prepare multi_cmd for FFU based on cmd to be used */ @@ -2952,10 +2949,7 @@ do_retry: } /* Test if we need to restart the download */ - sect_done = ext_csd[EXT_CSD_NUM_OF_FW_SEC_PROG_0] | - ext_csd[EXT_CSD_NUM_OF_FW_SEC_PROG_1] << 8 | - ext_csd[EXT_CSD_NUM_OF_FW_SEC_PROG_2] << 16 | - ext_csd[EXT_CSD_NUM_OF_FW_SEC_PROG_3] << 24; + sect_done = htole32(*((__u32 *)&ext_csd[EXT_CSD_NUM_OF_FW_SEC_PROG_0])); /* By spec, host should re-start download from the first sector if sect_done is 0 */ if (sect_done == 0) { if (retry--) { From patchwork Sun Jun 25 10:38:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Avri Altman X-Patchwork-Id: 13291874 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 190D9C001B0 for ; Sun, 25 Jun 2023 10:39:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231389AbjFYKjM (ORCPT ); Sun, 25 Jun 2023 06:39:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57592 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231438AbjFYKjL (ORCPT ); Sun, 25 Jun 2023 06:39:11 -0400 Received: from esa1.hgst.iphmx.com (esa1.hgst.iphmx.com [68.232.141.245]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5340EE46 for ; Sun, 25 Jun 2023 03:39:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1687689545; x=1719225545; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=dDNFcDZZ+TK/O446jyxYdu4diRUG5fN1WskB4PdK1GQ=; b=UjAItU+86isl5cHisJRTR2NAHMaGRCMOomxR/huc0/wp+qorHvkEYq/0 QvLdYyMXZ2H3TnrozuGT+wxebgD6AmewCT7xpjTuCDlqQrSkcj4ZYv1yL CXS/TeWvZC3dPbf1hu6ncyexZY9MkAylPaHTmD3umINg31MARY9NVKhIm QCZBfEzrgVyfAxOdnqxFjzqhjXXT4KoWkIKK3+LuvcYANX9kQlQJCvVWF ctoI1l3Uoi3WlXkMorv2qhzeCCJuOz9vkj4OWL4gqbEBPEBEfvt6E19w0 uBNUuF/KxYPWy/F1EpKwwmJYdfTtbZjP1B4ZPt0/r4u7q2dtprll95yuX Q==; X-IronPort-AV: E=Sophos;i="6.01,157,1684771200"; d="scan'208";a="348334278" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 25 Jun 2023 18:39:05 +0800 IronPort-SDR: F6IN0F4URqPEfkr7kYBUFUKEBgRU/jVTFc6OHtS6gHEoHp8WAzxB+oO7nz9zTiScng/z6HdqW6 pqgUBP3jG4EkWgUGWWQcwXkPpTpbkJYeNXInhRIcyO8cKG4jdCWe6we09aAmRSjlbiI0EnUCKa 5cUdkXHHdtpe1Oz3AcuJKB/9auAc3f/JGWw49NqFOTV5Yx/P35GoSTBN14KlYNiIrnctj2MsHP /Krekt/CTpvsunRVWJpNYp1RafKlgyzynpNw2myJvwqQ3yI6U8w7ZoVI7KnDYWUnTrYXvVF2hD +xI= Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 25 Jun 2023 02:53:27 -0700 IronPort-SDR: qqYhXHlPsYLPL/Thfx9l1lZ//0K/TVkp8Oj67Mc9d4mFBXOK8Tw0cKJc/s1mrZtdQj+9ngyXUT rAkRaa2QapO2veYSj26fOBQF9N2OE/8gXXjeSUcdh/i+6rrPsJQYhdAN0X11UsU8rQZMbhKma5 jXNSgnBkES/C5t4TJ0qpws9FRcZ9TQSrnxTWMxN2WPKZLTqGJXPQRblTYevfdgETcdUYndl+Qe buv58mt2Q2+u8z5aI1xBMtyN8yo3Y8KZx+jfJEEsW0xIAxRe5fpZR1fzI8LP3/KWGV0scI2KI1 dqY= WDCIronportException: Internal Received: from bxygm33.ad.shared ([10.45.31.229]) by uls-op-cesaip01.wdc.com with ESMTP; 25 Jun 2023 03:39:05 -0700 From: Avri Altman To: Ulf Hansson , linux-mmc@vger.kernel.org Cc: Avri Altman Subject: [PATCH 4/6] mmc-utils: ffu: Add ffu multi-command set handler Date: Sun, 25 Jun 2023 13:38:12 +0300 Message-Id: <20230625103814.105-5-avri.altman@wdc.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230625103814.105-1-avri.altman@wdc.com> References: <20230625103814.105-1-avri.altman@wdc.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org In preparation of sending the fw image in several chunks. While at it, make use of set_single_cmd() to preapare CMD23 and CMD25. Signed-off-by: Avri Altman --- mmc_cmds.c | 43 +++++++++++++++++++++---------------------- 1 file changed, 21 insertions(+), 22 deletions(-) diff --git a/mmc_cmds.c b/mmc_cmds.c index adb72af..0321118 100644 --- a/mmc_cmds.c +++ b/mmc_cmds.c @@ -2803,6 +2803,26 @@ out: return ret; } +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 = htole32(*((__u32 *)&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; + + /* + * 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_ioc_cmd_set_data(multi_cmd->cmds[2], buf + offset); +} int do_ffu(int nargs, char **argv) { @@ -2811,7 +2831,6 @@ int do_ffu(int nargs, char **argv) unsigned int sect_size; __u8 ext_csd[512]; __u8 *buf = NULL; - __u32 arg; off_t fw_size; char *device; struct mmc_ioc_multi_cmd *multi_cmd = NULL; @@ -2879,35 +2898,15 @@ int do_ffu(int nargs, char **argv) goto out; } - /* set CMD ARG */ - arg = htole32(*((__u32 *)&ext_csd[EXT_CSD_FFU_ARG_0])); - /* prepare multi_cmd for FFU based on cmd to be used */ - /* prepare multi_cmd to be sent */ 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); - /* send block count */ - multi_cmd->cmds[1].opcode = MMC_SET_BLOCK_COUNT; - 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; - /* - * 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; - mmc_ioc_cmd_set_data(multi_cmd->cmds[2], buf); + set_ffu_single_cmd(multi_cmd, ext_csd, fw_size, buf, 0); /* return device into normal mode */ fill_switch_cmd(&multi_cmd->cmds[3], EXT_CSD_MODE_CONFIG, From patchwork Sun Jun 25 10:38:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Avri Altman X-Patchwork-Id: 13291875 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3BCBDEB64DD for ; Sun, 25 Jun 2023 10:39:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231472AbjFYKjQ (ORCPT ); Sun, 25 Jun 2023 06:39:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57598 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231438AbjFYKjP (ORCPT ); Sun, 25 Jun 2023 06:39:15 -0400 Received: from esa6.hgst.iphmx.com (esa6.hgst.iphmx.com [216.71.154.45]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A870CE44 for ; Sun, 25 Jun 2023 03:39:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1687689554; x=1719225554; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=KNgCFGINjqnl5pO21kpxt1eMm28/6BzGbKhBD4WEPrI=; b=ct2pGnX8H86SrOchT2S8W8fVktzIyB3ZZsC8Lv91Gzuly8A3RppV1CJK h7TpEMnd49sA5QS3+aYvuOU/YIW0c7NbE46Yfqm/MUY4D+mCi7Ak2htmw lbpXbGd6hS5DdnMu9H9eIUtEsiS6cbpyg+L7I/iet+ljIGPeuyOMgfBDW k7QgIdsNm/qOMgZLRdZy67gBcpQUZl29OtVQ5U1wItFbDpceL3JU/GE6w PO/CGzAc4E8pnvc7lD67xQD/G/ehZbqQDl/oWCiMyCPU+qWwcx4zTE2Kz 5apY4k1vXJGdcBpED7/Zs0Qzg64GilPDW8LbcGaMzKNpS2z9+OPNXF548 w==; X-IronPort-AV: E=Sophos;i="6.01,157,1684771200"; d="scan'208";a="236798744" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 25 Jun 2023 18:39:13 +0800 IronPort-SDR: YWvtwt6kPQtF45EXvLJs1NX/Fa/5ZvocYbAwIMww/jZjYEVIxp0VqqSeTN0bfiuR89ztLhHG+/ Phn4dlafgRpekRxXt3b1F4f8kuGIeojbxVhOk/y91DmRrjetQMuk1sDSSgKADFi0wRERumIShx QAZe2Wk+UH9cfABu7iCNtxwyOhHp8BG3USWbP78xcOiHC8yGq9du9lWnHTqLkFeGxAauylUlvq IP4MWtq0XU5YzWOWqpqipBn6NL6yccaoZEnBGOxhayr2+jEI25rfux6Xb/Tj42jjXCUHPE94j2 Blo= Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 25 Jun 2023 02:47:54 -0700 IronPort-SDR: A4IyB2U6v0kxhKlsNMC4f6ZkYPRncEE5U6fLV3MDpSG+0CXX0s2ZcSCy8jd2ikrfvfV8aPxgmx ixQVIERrfTuTskNHT2VpIdR5eHBDT/JpuqhIJFUCmvEP9pjddvy9l7lcW2CCQykjq3/yCxnqhM Xz14tk+P05Qpw2B2MFNJOWxo7ova+fABqL/YY4GSWaM1ybUcz+3R5YFAftPRFtTeU2AEXDl8Ji GsL/Eh7mp3FpjgEzkTex6aG6yD20c3Qqa0+SdplLkCa10WCFtqe2JKVEki7nNCrA3/wxBVBi8D DMk= WDCIronportException: Internal Received: from bxygm33.ad.shared ([10.45.31.229]) by uls-op-cesaip01.wdc.com with ESMTP; 25 Jun 2023 03:39:12 -0700 From: Avri Altman To: Ulf Hansson , linux-mmc@vger.kernel.org Cc: Avri Altman , Lund Austin Subject: [PATCH 5/6] mmc-utils: ffu: Allow ffu of large images Date: Sun, 25 Jun 2023 13:38:13 +0300 Message-Id: <20230625103814.105-6-avri.altman@wdc.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230625103814.105-1-avri.altman@wdc.com> References: <20230625103814.105-1-avri.altman@wdc.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org ffu is done using a single multi-ioctl to carry the entire firmware image. This is limiting the fw image size to be at most 512KB, as the mmc driver restricts each single ioc data to be at most MMC_IOC_MAX_BYTES. the spec however, allows the fw image to be written using multiple write commands. To overcome this limitation, if the fw image is larger than 512KB, split it into a series of 512KB chunks. fixes: 1b8b13beb424 (mmc-utils: let FFU mode use CMD23 and CMD25) Reported-by: Lund Austin Tested-by: Lund Austin Signed-off-by: Avri Altman --- mmc_cmds.c | 36 +++++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/mmc_cmds.c b/mmc_cmds.c index 0321118..a1adbde 100644 --- a/mmc_cmds.c +++ b/mmc_cmds.c @@ -2831,7 +2831,7 @@ int do_ffu(int nargs, char **argv) unsigned int sect_size; __u8 ext_csd[512]; __u8 *buf = NULL; - off_t fw_size; + off_t fw_size, bytes_left, off; char *device; struct mmc_ioc_multi_cmd *multi_cmd = NULL; @@ -2877,7 +2877,7 @@ int do_ffu(int nargs, char **argv) } fw_size = lseek(img_fd, 0, SEEK_END); - if (fw_size > MMC_IOC_MAX_BYTES || fw_size == 0) { + if (fw_size == 0) { fprintf(stderr, "Wrong firmware size"); goto out; } @@ -2906,8 +2906,6 @@ int do_ffu(int nargs, char **argv) fill_switch_cmd(&multi_cmd->cmds[0], EXT_CSD_MODE_CONFIG, EXT_CSD_FFU_MODE); - set_ffu_single_cmd(multi_cmd, ext_csd, fw_size, buf, 0); - /* return device into normal mode */ fill_switch_cmd(&multi_cmd->cmds[3], EXT_CSD_MODE_CONFIG, EXT_CSD_NORMAL_MODE); @@ -2921,14 +2919,30 @@ int do_ffu(int nargs, char **argv) } do_retry: - /* send ioctl with multi-cmd */ - ret = ioctl(dev_fd, MMC_IOC_MULTI_CMD, multi_cmd); + bytes_left = fw_size; + off = 0; + while (bytes_left) { + unsigned int chunk_size = bytes_left < MMC_IOC_MAX_BYTES ? + bytes_left : MMC_IOC_MAX_BYTES; - 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; + /* 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; } /* From patchwork Sun Jun 25 10:38:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Avri Altman X-Patchwork-Id: 13291876 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0E2C2EB64DD for ; Sun, 25 Jun 2023 10:39:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231438AbjFYKjX (ORCPT ); Sun, 25 Jun 2023 06:39:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57638 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231484AbjFYKjW (ORCPT ); Sun, 25 Jun 2023 06:39:22 -0400 Received: from esa6.hgst.iphmx.com (esa6.hgst.iphmx.com [216.71.154.45]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3C5A1E44 for ; Sun, 25 Jun 2023 03:39:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1687689560; x=1719225560; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=cbPr9is1lhDIdyfCo15q74NmPvMaF3gMv7Z2OgyuoBM=; b=AEd7rREx4bZbt4RSv+KbPnjZI/1sx9T7LNc7G+PPYZF74QjQ6Tq3a+uk PhGtrwynCNmuvvdncZLi9pG75jhY7GSzi6ML53+voi/XLE9BDE9C0WsLz p+yXxmGR1cmKAgi2Ww6y2YQ24qhftIAynUv7Og0KwCp9E5GuiLXMVcprY 1mugggQYJJSOVTsmeDT4AKmPxCHXZenNFA/zIQe1zu8+H5nQPMoIyxThD aTMzp6jktG+t6x0pKJu8t/W9M1FcvJDCI4ZV81mIEYUjRSuT61+LoP6+z Af2vJCvJ7LUEdKZzUUHKNNgHW3LXwtcGSrUJ4tDLE02wQnwn0pyS5ds/2 A==; X-IronPort-AV: E=Sophos;i="6.01,157,1684771200"; d="scan'208";a="236798746" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 25 Jun 2023 18:39:20 +0800 IronPort-SDR: bfYaOFTSLknvINKL6fQY9EtNQAkh7F6YeNpuY0FVwJBzYR+cO/O3h968X3Nn+oKpmqW8r1dggX j30A2aLIZzBVsaj9k6MoVW+yaIvzbhk67Hq4rX7rU2bvP5plBkPa0IecCCFH6Cnxt2XJb0prrt UFSNXiXvUqWT0Kb4TBrU7BOswImezoMth2v//mD/Zh1CxSAYB+M2vToRTeynZVqOza8Di2l0Ro R+aV1KILVaP2mz8bOV/8u3ahBNjmbWEUGQeC9fL2tyUA0sTAIaEwkSpJ/l5EhVXXVnfQwEo8MH 72o= Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 25 Jun 2023 02:53:42 -0700 IronPort-SDR: 4vfUHZhQl5+TdbTEg87IteUtrC9PHYOrAI6oCEM8Aglvr9PnPX8eSC+5nr+jf3mcWC/ErPKksB WMB3BBBhXOrq6uaDUuVrRSLvM900feRoZMmM3sULoZXheXYFzxcRGCYGFzY818q4NH2T20WVGi Ztu8IrxL1T4NtbMsK7GBw6y17A3RzuLaAGNdaBfyeO/z/Tv/+8l1RDmZzNwW3OeiSnRe9kAd// llPAJQNIuc4nw+vh+RxpaloePeaeeyCOuGerRBQGIUuuVnnBBhQYb4kwmEHoAQ3CBv+6b7SkY+ Tv4= WDCIronportException: Internal Received: from bxygm33.ad.shared ([10.45.31.229]) by uls-op-cesaip01.wdc.com with ESMTP; 25 Jun 2023 03:39:20 -0700 From: Avri Altman To: Ulf Hansson , linux-mmc@vger.kernel.org Cc: Avri Altman , Lund Austin Subject: [PATCH 6/6] mmc-utils: ffu: Add optional chunk-size argument Date: Sun, 25 Jun 2023 13:38:14 +0300 Message-Id: <20230625103814.105-7-avri.altman@wdc.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230625103814.105-1-avri.altman@wdc.com> References: <20230625103814.105-1-avri.altman@wdc.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org Normally one would like to perform ffu using the largest possible chunk. However, since the ffu-timeout is vendor specific, there are times in which smaller chunks would lead to a more robust ffu process. Allow this via an additional optional argument. Tested-by: Lund Austin Signed-off-by: Avri Altman --- mmc.c | 6 ++++-- mmc_cmds.c | 18 ++++++++++++------ 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/mmc.c b/mmc.c index 795b4e3..bc8f74e 100644 --- a/mmc.c +++ b/mmc.c @@ -228,8 +228,10 @@ static struct Command commands[] = { NULL }, { do_ffu, -2, - "ffu", " \n" - "Run Field Firmware Update with on .\n", + "ffu", " [chunk-bytes]\n" + "Run Field Firmware Update with on .\n" + "[chunk-bytes] is optional and defaults to its max - 512k. " + "should be in decimal bytes and sector aligned.\n", NULL }, { do_erase, -4, diff --git a/mmc_cmds.c b/mmc_cmds.c index a1adbde..10d063d 100644 --- a/mmc_cmds.c +++ b/mmc_cmds.c @@ -2834,11 +2834,9 @@ int do_ffu(int nargs, char **argv) 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; - if (nargs != 3) { - fprintf(stderr, "Usage: ffu \n"); - exit(1); - } + assert (nargs == 3 || nargs == 4); device = argv[2]; dev_fd = open(device, O_RDWR); @@ -2898,6 +2896,14 @@ int do_ffu(int nargs, char **argv) goto out; } + if (nargs == 4) { + default_chunk = strtol(argv[3], NULL, 10); + if (default_chunk > MMC_IOC_MAX_BYTES || default_chunk % 512) { + fprintf(stderr, "Invalid chunk size"); + goto out; + } + } + /* prepare multi_cmd for FFU based on cmd to be used */ multi_cmd->num_of_cmds = 4; @@ -2922,8 +2928,8 @@ do_retry: bytes_left = fw_size; off = 0; while (bytes_left) { - unsigned int chunk_size = bytes_left < MMC_IOC_MAX_BYTES ? - bytes_left : MMC_IOC_MAX_BYTES; + 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);