From patchwork Wed Feb 6 23:05:23 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lubomir Rintel X-Patchwork-Id: 218794 X-Patchwork-Delegate: wd@denx.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id C17982C02EF for ; Thu, 7 Feb 2013 10:09:55 +1100 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id F2D364A0B5; Thu, 7 Feb 2013 00:09:46 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 0kd1U34plE89; Thu, 7 Feb 2013 00:09:46 +0100 (CET) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id E2F134A0F6; Thu, 7 Feb 2013 00:09:34 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 17A474A0B7 for ; Thu, 7 Feb 2013 00:05:33 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 2DG3yoN-7PaY for ; Thu, 7 Feb 2013 00:05:31 +0100 (CET) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from norkia.v3.sk (norkia.v3.sk [91.210.183.14]) by theia.denx.de (Postfix) with ESMTPS id BA5FA4A0B5 for ; Thu, 7 Feb 2013 00:05:30 +0100 (CET) Received: from localhost (localhost.localdomain [127.0.0.1]) by norkia.v3.sk (Postfix) with ESMTP id 638DA12A0AE; Thu, 7 Feb 2013 00:05:29 +0100 (CET) X-Virus-Scanned: amavisd-new at v3.sk Received: from norkia.v3.sk ([127.0.0.1]) by localhost (norkia.v3.sk [127.0.0.1]) (amavisd-new, port 10024) with SMTP id EBoTGS1JULUf; Thu, 7 Feb 2013 00:05:27 +0100 (CET) Received: from localhost.localdomain (ip-94-113-108-27.net.upcbroadband.cz [94.113.108.27]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) (Authenticated sender: lkundrak@v3.sk) by norkia.v3.sk (Postfix) with ESMTP id CB98D12A098; Thu, 7 Feb 2013 00:05:26 +0100 (CET) From: Lubomir Rintel To: Wolfgang Denk Date: Thu, 7 Feb 2013 00:05:23 +0100 Message-Id: <1360191923-4688-1-git-send-email-lkundrak@v3.sk> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1360191866.3594.10.camel@unicorn> References: <1360191866.3594.10.camel@unicorn> X-Mailman-Approved-At: Thu, 07 Feb 2013 00:09:30 +0100 Cc: u-boot@lists.denx.de, Lubomir Rintel Subject: [U-Boot] [PATCH] env: Allow accessing non-mtd devices X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.11 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: u-boot-bounces@lists.denx.de Errors-To: u-boot-bounces@lists.denx.de In certain cases, memory device is present as flat file or block device (via mmc or mtdblock layer). Do not attempt MTD operations against it. Signed-off-by: Lubomir Rintel --- tools/env/fw_env.c | 20 ++++++++++++++++---- tools/env/fw_env.config | 3 +++ 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/tools/env/fw_env.c b/tools/env/fw_env.c index 37b60b8..72d77a9 100644 --- a/tools/env/fw_env.c +++ b/tools/env/fw_env.c @@ -838,7 +838,7 @@ static int flash_write_buf (int dev, int fd, void *buf, size_t count, ioctl (fd, MEMUNLOCK, &erase); /* Dataflash does not need an explicit erase cycle */ - if (mtd_type != MTD_DATAFLASH) + if (mtd_type && mtd_type != MTD_DATAFLASH) if (ioctl (fd, MEMERASE, &erase) != 0) { fprintf (stderr, "MTD erase error on %s: %s\n", DEVNAME (dev), @@ -949,17 +949,29 @@ static int flash_write (int fd_current, int fd_target, int dev_target) static int flash_read (int fd) { struct mtd_info_user mtdinfo; + struct stat st; int rc; - rc = ioctl (fd, MEMGETINFO, &mtdinfo); + rc = fstat(fd, &st); if (rc < 0) { - perror ("Cannot get MTD information"); + perror("Cannot access the device file"); return -1; } + if (S_ISCHR(st.st_mode)) { + rc = ioctl(fd, MEMGETINFO, &mtdinfo); + if (rc < 0) { + perror("Cannot get MTD information"); + return -1; + } + } else { + memset(&mtdinfo, 0, sizeof(mtdinfo)); + } + if (mtdinfo.type != MTD_NORFLASH && mtdinfo.type != MTD_NANDFLASH && - mtdinfo.type != MTD_DATAFLASH) { + mtdinfo.type != MTD_DATAFLASH && + mtdinfo.type) { fprintf (stderr, "Unsupported flash type %u\n", mtdinfo.type); return -1; } diff --git a/tools/env/fw_env.config b/tools/env/fw_env.config index 8e21d5a..c086512 100644 --- a/tools/env/fw_env.config +++ b/tools/env/fw_env.config @@ -17,3 +17,6 @@ # NAND example #/dev/mtd0 0x4000 0x4000 0x20000 2 + +# Block device example +#/dev/mmcblk0 0xc0000 0x20000