From patchwork Sun Feb 9 09:08:00 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Avi Shchislowski X-Patchwork-Id: 3612491 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 C4F44BF418 for ; Sun, 9 Feb 2014 09:08:11 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id CC92A201BB for ; Sun, 9 Feb 2014 09:08:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id BCEC720172 for ; Sun, 9 Feb 2014 09:08:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751768AbaBIJIH (ORCPT ); Sun, 9 Feb 2014 04:08:07 -0500 Received: from co9ehsobe004.messaging.microsoft.com ([207.46.163.27]:59997 "EHLO co9outboundpool.messaging.microsoft.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751379AbaBIJIE convert rfc822-to-8bit (ORCPT ); Sun, 9 Feb 2014 04:08:04 -0500 Received: from mail12-co9-R.bigfish.com (10.236.132.246) by CO9EHSOBE031.bigfish.com (10.236.130.94) with Microsoft SMTP Server id 14.1.225.22; Sun, 9 Feb 2014 09:08:03 +0000 Received: from mail12-co9 (localhost [127.0.0.1]) by mail12-co9-R.bigfish.com (Postfix) with ESMTP id 84613300825; Sun, 9 Feb 2014 09:08:03 +0000 (UTC) X-Forefront-Antispam-Report: CIP:74.221.232.164; KIP:(null); UIP:(null); IPV:NLI; H:sacsmgep12.sandisk.com; RD:none; EFVD:NLI X-SpamScore: 3 X-BigFish: VPS3(z551bizzz1f42h2148h208ch1ee6h1de0h1fdah2073h2146h1202h1e76h2189h1d1ah1d2ah21bch1fc6hz31iz1de098h8275bh1de097h18602eh1cd15fiz2fh109h839h947hd25hf0ah1288h12a5h12a9h12bdh137ah13b6h1441h1504h1537h153bh15d0h162dh1631h1758h18e1h1946h19b5h1ad9h1b0ah1b2fh224fh1fb3h1d0ch1d2eh1d3fh1dc1h1dfeh1dffh1e1dh1fe8h1ff5h2184h2216h2336h2438h2461h2487h24d7h2516h2545h1155h) Received-SPF: pass (mail12-co9: domain of sandisk.com designates 74.221.232.164 as permitted sender) client-ip=74.221.232.164; envelope-from=Avi.Shchislowski@sandisk.com; helo=sacsmgep12.sandisk.com ; .sandisk.com ; Received: from mail12-co9 (localhost.localdomain [127.0.0.1]) by mail12-co9 (MessageSwitch) id 1391936881479625_13589; Sun, 9 Feb 2014 09:08:01 +0000 (UTC) Received: from CO9EHSMHS014.bigfish.com (unknown [10.236.132.241]) by mail12-co9.bigfish.com (Postfix) with ESMTP id 70867200052; Sun, 9 Feb 2014 09:08:01 +0000 (UTC) Received: from sacsmgep12.sandisk.com (74.221.232.164) by CO9EHSMHS014.bigfish.com (10.236.130.24) with Microsoft SMTP Server id 14.16.227.3; Sun, 9 Feb 2014 09:08:01 +0000 X-AuditID: ac1c210f-f79cc6d0000011b4-dc-52f7432689b6 Received: from SACHUBIP02.sdcorp.global.sandisk.com ( [172.28.1.254]) by sacsmgep12.sandisk.com (Symantec Messaging Gateway) with SMTP id 9D.67.04532.62347F25; Sun, 9 Feb 2014 00:58:14 -0800 (PST) Received: from SACMBXIP01.sdcorp.global.sandisk.com ([169.254.1.195]) by SACHUBIP02.sdcorp.global.sandisk.com ([10.181.10.104]) with mapi id 14.02.0342.003; Sun, 9 Feb 2014 01:08:00 -0800 From: Avi Shchislowski To: "'cjb@laptop.org'" , "linux-mmc@vger.kernel.org" CC: Alex Lemberg , Grant Grundler Subject: [RFC PATCH 1/1] mmc-utils: Support-sending-eMMC-5.0-FFU Thread-Topic: [RFC PATCH 1/1] mmc-utils: Support-sending-eMMC-5.0-FFU Thread-Index: Ac8ldk7QG1soTOHdQeOUuV9mELGckQ== Date: Sun, 9 Feb 2014 09:08:00 +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+NgFvrOLMWRmVeSWpSXmKPExsWyRobxn66a8/cgg7+3tCy2v97IZvHqyA8m iyP/+xkdmD1mN1xk8Th0ZS2jx+dNcgHMUVw2Kak5mWWpRfp2CVwZn6dNZS3YZFJxdsNPlgbG SUpdjJwcEgImEq0Tm5ggbDGJC/fWs3UxcnEICRxnlHg6+T0rSEJIYD+jxMHrYSA2m4CpxLrv T8AaRASSJG5dec4IYjMLhEq0t01g72Lk4BAWcJBYfiALxBQRcJXY9sMZolpPYs+D72wgNouA isTB5hssIDavQLTExkP3wWxGoBO+n1rDBDFRXOLWk/lQpwlILNlznhnCFpV4+fgfK8h4CQF5 ieun7SDK9SRuTJ3CBmFrSyxb+JoZYrygxMmZT1gmMIrMQjJ1FpKWWUhaZiFpWcDIsopRrDgx uTg3PbXA0EivODEvJbM4Wy85P3cTIzg6FPl3MG6bYn6IUYCDUYmH12L1tyAh1sSy4srcQ4wS HMxKIryeEt+DhHhTEiurUovy44tKc1KLDzFKc7AoifOmbsv2FxJITyxJzU5NLUgtgskycXBK NTBGHtlvmu7kPfmUVfuSs8+O3+b+9SoxVUD+V/HGuWbhfcscsoU+1RcvkZt47PI6I731F850 bdZqi6r/3s6+80pxceThSiHT+WWV9bvn+J7a8PxVb+wf1oly1w4IL85N7lS8rpmoymEac2rn BBVfZtd5iWbvPk+ynarv7/rEvLR537WFqq+yni1UYinOSDTUYi4qTgQAAn48cYoCAAA= 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=unavailable 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 Avi Shchislowski | Staff Software Engineer, MCS Embedded  | SanDisk | +972.09.763-2666| www.sandisk.com --- 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..a01852d 100644 --- a/mmc.c +++ b/mmc.c @@ -36,9 +36,9 @@ struct Command { if >= 0, number of arguments, if < 0, _minimum_ number of arguments */ char *verb; /* verb */ - char *help; /* help lines; from the 2nd line onward they + char *help; /* help lines; from the 2nd line onward they are automatically indented */ - char *adv_help; /* advanced help message; from the 2nd line + char *adv_help; /* advanced help message; from the 2nd line onward they are automatically indented */ /* the following fields are run-time filled by the program */ @@ -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, + "emmc50 ffu", " \n" + "run eMMC 5.0 Field firmware update.\n.", + NULL + }, { 0, 0, 0, 0 } }; @@ -362,7 +367,7 @@ static int parse_args(int argc, char **argv, matchcmd->verb, matchcmd->nargs); return -2; } - + if (prepare_args( nargs_, args_, prgname, matchcmd )){ fprintf(stderr, "ERROR: not enough memory\\n"); return -20; diff --git a/mmc.h b/mmc.h index 9871d62..3be6db0 100644 --- a/mmc.h +++ b/mmc.h @@ -80,6 +80,14 @@ #define BKOPS_ENABLE (1<<0) /* + * sector size +*/ +#define CARD_BLOCK_SIZE 512 + +#define FFU_DWONLOAD_OP 302 +#define FFU_INSTALL_OP 303 + +/* * EXT_CSD field definitions */ #define EXT_CSD_HPI_SUPP (1<<0) diff --git a/mmc_cmds.c b/mmc_cmds.c index b8afa74..24c4a6b 100644 --- a/mmc_cmds.c +++ b/mmc_cmds.c @@ -1163,3 +1163,112 @@ int do_sanitize(int nargs, char **argv) } +static int ffu_download_image(int fw_fd, int mmc_fd) { + int ret = 0; + struct mmc_ioc_cmd mmc_ioc_cmd; + char data_buff[MMC_IOC_MAX_BYTES]; + int file_size; + int size; + int data_length; + + memset(data_buff, 0, sizeof(data_buff)); + /* get file size */ + file_size = lseek(fw_fd, 0, SEEK_END); + if (file_size < 0) { + ret = -1; + perror("seek file error \n"); + goto exit; + } + + lseek(fw_fd, 0, SEEK_SET); + do { + size = (file_size > MMC_IOC_MAX_BYTES) ? + MMC_IOC_MAX_BYTES : file_size; + /* Read FW data from file */ + data_length = read(fw_fd, data_buff, size); + if (data_length == -1) { + ret = -1; + goto exit; + } + /* prepare and send ioctl */ + memset(&mmc_ioc_cmd, 0, sizeof(mmc_ioc_cmd)); + mmc_ioc_cmd.opcode = FFU_DWONLOAD_OP; + mmc_ioc_cmd.blksz = CARD_BLOCK_SIZE; + mmc_ioc_cmd.blocks = data_length / mmc_ioc_cmd.blksz; + 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, data_buff); + ret = ioctl(mmc_fd, MMC_IOC_CMD, &mmc_ioc_cmd); + if (ret) { + perror("ioctl FW download"); + goto exit; + } + + file_size = file_size - size; + printf("firmware file loading, remaining: %d\n", file_size); + } while (file_size > 0); + +exit: + + return ret; +} + +static int ffu_install(int mmc_fd) +{ + int ret; + struct mmc_ioc_cmd mmc_ioc_cmd; + + memset(&mmc_ioc_cmd, 0, sizeof(mmc_ioc_cmd)); + mmc_ioc_cmd.opcode = FFU_INSTALL_OP; + mmc_ioc_cmd.blksz = CARD_BLOCK_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); + if (ret) + perror("ioctl install"); + + printf("ffu_install ret %d \n", ret); + return ret; +} + +int do_emmc50_ffu(int nargs, char **argv) { + int fd, fw_fd, ret; + char *device; + + CHECK(nargs != 3, "Usage: ffu \n", + exit(1)); + + device = argv[2]; + fd = open(device, O_RDWR); + if (fd < 0) { + perror("open"); + exit(1); + } + + /* open eMMC5.0 firmware image file */ + fw_fd = open(argv[1], O_RDONLY); + if (fw_fd < 0) { + perror("open eMMC5.0 firmware file"); + ret = -1; + goto exit; + } + + ret = ffu_download_image(fw_fd, fd); + if (ret) + goto exit; + + ret = ffu_install(fd); + if (ret) + goto exit; + +exit: + close(fd); + close(fw_fd); + + return ret; +} diff --git a/mmc_cmds.h b/mmc_cmds.h index f06cc10..77a6cb8 100644 --- a/mmc_cmds.h +++ b/mmc_cmds.h @@ -28,3 +28,5 @@ 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); + -- 1.7.5.4