From patchwork Wed Apr 9 19:53:08 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Avi Shchislowski X-Patchwork-Id: 3957571 Return-Path: X-Original-To: patchwork-linux-mmc@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 48250BFF02 for ; Wed, 9 Apr 2014 19:53:20 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 41283205CA for ; Wed, 9 Apr 2014 19:53:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 1AA19201BC for ; Wed, 9 Apr 2014 19:53:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934375AbaDITxQ (ORCPT ); Wed, 9 Apr 2014 15:53:16 -0400 Received: from ch1ehsobe003.messaging.microsoft.com ([216.32.181.183]:37727 "EHLO ch1outboundpool.messaging.microsoft.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933481AbaDITxO convert rfc822-to-8bit (ORCPT ); Wed, 9 Apr 2014 15:53:14 -0400 Received: from mail209-ch1-R.bigfish.com (10.43.68.253) by CH1EHSOBE013.bigfish.com (10.43.70.63) with Microsoft SMTP Server id 14.1.225.22; Wed, 9 Apr 2014 19:52:52 +0000 Received: from mail209-ch1 (localhost [127.0.0.1]) by mail209-ch1-R.bigfish.com (Postfix) with ESMTP id 674833600E4; Wed, 9 Apr 2014 19:52:52 +0000 (UTC) X-Forefront-Antispam-Report: CIP:74.221.232.162; KIP:(null); UIP:(null); IPV:NLI; H:sacsmgep11.sandisk.com; RD:none; EFVD:NLI X-SpamScore: 2 X-BigFish: VPS2(z551bizzz1f42h2148h1ee6h1de0h1fdah2073h2146h1202h1e76h2189h1d1ah1d2ah21bch1fc6h208chz31iz1de098h8275bh1de097hz2fh109h839h944hd25hf0ah1220h1288h12a5h12a9h12bdh137ah13b6h1441h1504h1537h153bh15d0h162dh1631h1758h18e1h1946h19b5h1ad9h1b0ah1b2fh224fh1fb3h1d0ch1d2eh1d3fh1dc1h1dfeh1dffh1e1dh1fe8h1ff5h2184h2216h2336h2438h2461h2487h24d7h2516h2545h255eh25cch25f6h2605h262fh268bh26d3h1155h) Received-SPF: pass (mail209-ch1: domain of sandisk.com designates 74.221.232.162 as permitted sender) client-ip=74.221.232.162; envelope-from=Avi.Shchislowski@sandisk.com; helo=sacsmgep11.sandisk.com ; .sandisk.com ; Received: from mail209-ch1 (localhost.localdomain [127.0.0.1]) by mail209-ch1 (MessageSwitch) id 1397073170399332_7116; Wed, 9 Apr 2014 19:52:50 +0000 (UTC) Received: from CH1EHSMHS012.bigfish.com (snatpool2.int.messaging.microsoft.com [10.43.68.239]) by mail209-ch1.bigfish.com (Postfix) with ESMTP id 595DB420257; Wed, 9 Apr 2014 19:52:50 +0000 (UTC) Received: from sacsmgep11.sandisk.com (74.221.232.162) by CH1EHSMHS012.bigfish.com (10.43.70.12) with Microsoft SMTP Server id 14.16.227.3; Wed, 9 Apr 2014 19:52:48 +0000 X-AuditID: ac1c210e-f79eb6d000000dd0-4b-5345a4ce1b91 Received: from SACHUBIP02.sdcorp.global.sandisk.com ( [172.28.1.254]) by sacsmgep11.sandisk.com (Symantec Messaging Gateway) with SMTP id D2.9A.03536.EC4A5435; Wed, 9 Apr 2014 12:51:42 -0700 (PDT) Received: from SACMBXIP01.sdcorp.global.sandisk.com ([169.254.1.168]) by SACHUBIP02.sdcorp.global.sandisk.com ([10.181.10.104]) with mapi id 14.03.0174.001; Wed, 9 Apr 2014 12:53:08 -0700 From: Avi Shchislowski To: "'linux-mmc@vger.kernel.org'" , "'cjb@laptop.org'" CC: 'Grant Grundler' , Alex Lemberg Subject: [RFC PATCH 1/1 v2] mmc-utils: Support-sending-eMMC-5.0-FFU Thread-Topic: [RFC PATCH 1/1 v2] mmc-utils: Support-sending-eMMC-5.0-FFU Thread-Index: Ac9ULPnyL4odDEahTryVZhiNZMunwg== Date: Wed, 9 Apr 2014 19:53:08 +0000 Message-ID: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [172.28.1.254] MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrJLMWRmVeSWpSXmKPExsWyRobxn+65Ja7BBudfWFhsf72RzeLVkR9M Fkf+9zM6MHvMbrjI4nHoylpGj8+b5AKYo7hsUlJzMstSi/TtErgyPt/5ylZwVKVizt2dLA2M 12W7GDk5JARMJJbO7mWHsMUkLtxbz9bFyMUhJHCcUWLW2yZGCGc/o0Tjyn2sIFVsAqYS674/ Yepi5OAQEUiROPLLFCTMLBAusX3VM3aQsLCAs8TFWQogYREBD4kvN+8zQdh6EpeXLgWzWQRU JB6ta2YDsXkFoiVOvlkFNp0R6Ibvp9YwQYwUl7j1ZD4TxG0CEkv2nGeGsEUlXj7+xwphK0h8 XvGPDaJeR2LB7k9QtrbEsoWvmSHmC0qcnPmEZQKjyCwkY2chaZmFpGUWkpYFjCyrGMWKE5OL c9NTCwwN9YoT81Iyi7P1kvNzNzGCI0SRbwfjvinmhxgFOBiVeHhPmLkEC7EmlhVX5h5ilOBg VhLhnTjHNViINyWxsiq1KD++qDQntfgQozQHi5I4b+q2bH8hgfTEktTs1NSC1CKYLBMHp1QD 43xm62gxs3Mbem9U6N7Pi9LwmXSy6U7ih5Y4+5P7X/NIOu/fu7XsiVv0ifddR44usLOIDt48 r8c6etWkAyyXZxi32tl5RWzcG+LKkOBb+0RSI2Mud6f/0ymCrlstxGT3tBRt8XWZxmDhrVX/ WTVT9AtTPuMngRvn/h2pXnqhOu+mRED9DTFuJZbijERDLeai4kQAzQyLPIwCAAA= X-OriginatorOrg: sandisk.com X-FOPE-CONNECTOR: Id%0$Dn%*$RO%0$TLS%0$FQDN%$TlsDn% Sender: linux-mmc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org X-Spam-Status: No, score=-7.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The mmc-utils was modified to invoke eMMC5.0 Field Firmware Update (FFU) process in mmc driver New command was add: "do_emmc50_ffu". This patch depends on patch mmc: Support-FFU-for-eMMC-v5.0 Committed by Avi Shchislowski FFU will be done in two steps. Two new IOCTL codes will be sent to the driver in order to operate FFU code: 1. FFU_DWONLOAD_OP (sent in ffu_download_image() function) 2. FFU_INSTALL_OP (sent in ffu_install() function) Signed-off-by: Avi Shchislowski Signed-off-by: Alex Lemberg the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/mmc.c b/mmc.c index 926e92f..ee23cd3 100644 --- a/mmc.c +++ b/mmc.c @@ -110,6 +110,11 @@ static struct Command commands[] = { "Send Sanitize command to the .\nThis will delete the unmapped memory region of the device.", NULL }, + { do_emmc50_ffu, -2, + "ffu", " \n" + "run eMMC 5.0 Field firmware update.\n.", + NULL + }, { 0, 0, 0, 0 } }; diff --git a/mmc.h b/mmc.h index 9871d62..b338e1d 100644 --- a/mmc.h +++ b/mmc.h @@ -64,6 +64,7 @@ #define EXT_CSD_ENH_START_ADDR_2 138 #define EXT_CSD_ENH_START_ADDR_1 137 #define EXT_CSD_ENH_START_ADDR_0 136 +#define EXT_CSD_REV 192 #define EXT_CSD_NATIVE_SECTOR_SIZE 63 /* R */ #define EXT_CSD_USE_NATIVE_SECTOR 62 /* R/W */ #define EXT_CSD_DATA_SECTOR_SIZE 61 /* R */ @@ -79,6 +80,9 @@ */ #define BKOPS_ENABLE (1<<0) +#define MMC_FFU_DOWNLOAD_OP 302 +#define MMC_FFU_INSTALL_OP 303 + /* * EXT_CSD field definitions */ diff --git a/mmc_cmds.c b/mmc_cmds.c index b8afa74..71a2ce3 100644 --- a/mmc_cmds.c +++ b/mmc_cmds.c @@ -1142,7 +1142,7 @@ int do_sanitize(int nargs, char **argv) char *device; CHECK(nargs != 2, "Usage: mmc sanitize \n", - exit(1)); + exit(1)); device = argv[1]; @@ -1163,3 +1163,94 @@ int do_sanitize(int nargs, char **argv) } +static int ffu_download_image(char *fname, int mmc_fd, int blk_size) { + int ret = 0; + struct mmc_ioc_cmd mmc_ioc_cmd; + char firmware_name[512]; + + memset(firmware_name, 0, sizeof(firmware_name)); + memcpy(firmware_name, fname, strlen(fname)); + + /* prepare and send ioctl */ + memset(&mmc_ioc_cmd, 0, sizeof(mmc_ioc_cmd)); + mmc_ioc_cmd.opcode = MMC_FFU_DOWNLOAD_OP; + mmc_ioc_cmd.blksz = blk_size; + mmc_ioc_cmd.blocks = 1; + mmc_ioc_cmd.arg = 0; + mmc_ioc_cmd.flags = MMC_RSP_SPI_R1 | MMC_RSP_R1 | MMC_CMD_ADTC; + mmc_ioc_cmd.write_flag = 1; + mmc_ioc_cmd_set_data(mmc_ioc_cmd, firmware_name); + ret = ioctl(mmc_fd, MMC_IOC_CMD, &mmc_ioc_cmd); + if (ret) { + fprintf(stderr, "ioctl FW download error%d\n", ret); + return ret; + } + + return ret; +} + +static int ffu_install(int mmc_fd, int blk_size) { + int ret; + struct mmc_ioc_cmd mmc_ioc_cmd; + + memset(&mmc_ioc_cmd, 0, sizeof(mmc_ioc_cmd)); + mmc_ioc_cmd.opcode = MMC_FFU_INSTALL_OP; + mmc_ioc_cmd.blksz = blk_size; + mmc_ioc_cmd.blocks = 0; + mmc_ioc_cmd.arg = 0; + mmc_ioc_cmd.flags = MMC_RSP_SPI_R1 | MMC_RSP_R1 | MMC_CMD_ADTC; + mmc_ioc_cmd.write_flag = 0; + ret = ioctl(mmc_fd, MMC_IOC_CMD, &mmc_ioc_cmd); + + return ret; +} + +int do_emmc50_ffu (int nargs, char **argv) { + int fd, ret; + char *device; + char *path; + __u8 ext_csd[512]; + int blk_size; + + CHECK(nargs != 3, "Usage: ffu \n", + exit(1)); + + device = argv[2]; + fd = open(device, O_RDWR); + if (fd < 0) { + perror("open"); + exit(1); + } + + ret = read_extcsd(fd, ext_csd); + if (ret) { + fprintf(stderr, "Could not read EXT_CSD from %s\n", device); + exit(1); + } + + if (ext_csd[EXT_CSD_REV] < 7) { + fprintf(stderr, "FFU is not supported on device %s\n", device); + exit(1); + } + + blk_size = (ext_csd[EXT_CSD_DATA_SECTOR_SIZE] == 0) ? 512 : 4096; + path = argv[1]; + ret = ffu_download_image(path, fd, blk_size); + if (ret) { + fprintf(stderr, "FFU failed %d\n", ret); + exit(1); + } + + ret = ffu_install(fd, blk_size); + if (ret) { + fprintf(stderr, "FFU failed %d\n", ret); + exit(1); + } + + close(fd); + fprintf(stderr, "FFU finished with status %d \n", ret); + return ret; +} diff --git a/mmc_cmds.h b/mmc_cmds.h index f06cc10..3ff3440 100644 --- a/mmc_cmds.h +++ b/mmc_cmds.h @@ -28,3 +28,4 @@ int do_sanitize(int nargs, char **argv); int do_status_get(int nargs, char **argv); int do_enh_area_set(int nargs, char **argv); int do_write_reliability_set(int nargs, char **argv); +int do_emmc50_ffu(int nargs, char **argv); -- To unsubscribe from this list: send the line "unsubscribe linux-mmc" in