From patchwork Thu Apr 10 18:10:02 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Avi Shchislowski X-Patchwork-Id: 3964041 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 33243BFF02 for ; Thu, 10 Apr 2014 18:10:13 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 374902081D for ; Thu, 10 Apr 2014 18:10:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 3736820809 for ; Thu, 10 Apr 2014 18:10:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753333AbaDJSKJ (ORCPT ); Thu, 10 Apr 2014 14:10:09 -0400 Received: from am1ehsobe005.messaging.microsoft.com ([213.199.154.208]:41438 "EHLO am1outboundpool.messaging.microsoft.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753323AbaDJSKH convert rfc822-to-8bit (ORCPT ); Thu, 10 Apr 2014 14:10:07 -0400 Received: from mail64-am1-R.bigfish.com (10.3.201.252) by AM1EHSOBE003.bigfish.com (10.3.204.23) with Microsoft SMTP Server id 14.1.225.22; Thu, 10 Apr 2014 18:09:42 +0000 Received: from mail64-am1 (localhost [127.0.0.1]) by mail64-am1-R.bigfish.com (Postfix) with ESMTP id EFE154002D4; Thu, 10 Apr 2014 18:09:41 +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 (mail64-am1: 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 mail64-am1 (localhost.localdomain [127.0.0.1]) by mail64-am1 (MessageSwitch) id 1397153380733481_10070; Thu, 10 Apr 2014 18:09:40 +0000 (UTC) Received: from AM1EHSMHS010.bigfish.com (unknown [10.3.201.233]) by mail64-am1.bigfish.com (Postfix) with ESMTP id A5629460050; Thu, 10 Apr 2014 18:09:40 +0000 (UTC) Received: from sacsmgep11.sandisk.com (74.221.232.162) by AM1EHSMHS010.bigfish.com (10.3.207.110) with Microsoft SMTP Server id 14.16.227.3; Thu, 10 Apr 2014 18:09:40 +0000 X-AuditID: ac1c210e-f79eb6d000000dd0-ad-5346de143d80 Received: from SACHUBIP02.sdcorp.global.sandisk.com ( [172.28.1.254]) by sacsmgep11.sandisk.com (Symantec Messaging Gateway) with SMTP id 95.C2.03536.41ED6435; Thu, 10 Apr 2014 11:08:20 -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; Thu, 10 Apr 2014 11:10:02 -0700 From: Avi Shchislowski To: "'linux-mmc@vger.kernel.org'" , "'cjb@laptop.org'" CC: 'Grant Grundler' , Alex Lemberg Subject: [RFC PATCH 1/1 v3] mmc-utils: Support-sending-eMMC-5.0-FFU Thread-Topic: [RFC PATCH 1/1 v3] mmc-utils: Support-sending-eMMC-5.0-FFU Thread-Index: Ac9U6BV03RFvLaUGQqC81tAYlXcD/A== Date: Thu, 10 Apr 2014 18:10:02 +0000 Message-ID: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.181.8.64] MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrJLMWRmVeSWpSXmKPExsWyRobxn67IPbdgg+lbNSy2v97IZvHqyA8m iyP/+xkdmD1mN1xk8Th0ZS2jx+dNcgHMUVw2Kak5mWWpRfp2CVwZJ27PYS74oVzRM+UqUwPj TNkuRk4OCQETif+flrBC2GISF+6tZ+ti5OIQEjjOKNF8ehMrhHOAUeL16x5GkCo2AVOJdd+f MHUxcnCICKRIHPllChJmFgiX2L7qGTuILSzgLPHj9SU2EFtEwEOiq/shK4StJ7F+4zGwMSwC qhJtx9cwgdi8AtESR141sIDYjEBHfD8FEWcWEJe49WQ+E8RxAhJL9pxnhrBFJV4+/scKcoKE gLzE9dN2EOU6Egt2f2KDsLUlli18zQwxXlDi5MwnLBMYRWYhmToLScssJC2zkLQsYGRZxShW nJhcnJueWmBoqFecmJeSWZytl5yfu4kRHCGKfDsY900xP8QowMGoxMN74JJbsBBrYllxZe4h RgkOZiURXsvbQCHelMTKqtSi/Pii0pzU4kOM0hwsSuK8qduy/YUE0hNLUrNTUwtSi2CyTByc Ug2Mtte4P0U3usea7TsdaST+fNskn4tKM74dklAouiHQxPe+7tPX5W+/c7qt6Dgexb93zTOr E2fVvqqudbPzmvitOk7k5JTCat9a5Ukuf7LW8366fPmzN6epUMLPvf/rExYf8FDVUNx88sBs 9i0cvnyTFqQXn5hgNDdD9/jUuqzjSkXiTgL/grcYKrEUZyQaajEXFScCADordN6MAgAA 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.5 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 Firmware Update (FFU) 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 --- To unsubscribe from this list: send the line "unsubscribe linux-mmc" in 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);