From patchwork Wed Jan 30 23:46:24 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lubomir Rintel X-Patchwork-Id: 217089 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 A7D8D2C0296 for ; Thu, 31 Jan 2013 16:24:47 +1100 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id C6BFF4A0F1; Thu, 31 Jan 2013 06:23:21 +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 UPSSwfU4JF7h; Thu, 31 Jan 2013 06:23:21 +0100 (CET) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id D97CC4A13A; Thu, 31 Jan 2013 06:23:06 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 752514A109 for ; Thu, 31 Jan 2013 01:17:19 +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 whLxq8JEgKgR for ; Thu, 31 Jan 2013 01:17:18 +0100 (CET) X-Greylist: delayed 1840 seconds by postgrey-1.27 at theia; Thu, 31 Jan 2013 01:17:16 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 95B3B4A107 for ; Thu, 31 Jan 2013 01:17:16 +0100 (CET) Received: from localhost (localhost.localdomain [127.0.0.1]) by norkia.v3.sk (Postfix) with ESMTP id 51A9B12A0E3; Thu, 31 Jan 2013 00:46:33 +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 7jWiys4lxN31; Thu, 31 Jan 2013 00:46:30 +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 497B912A0E1; Thu, 31 Jan 2013 00:46:30 +0100 (CET) From: Lubomir Rintel To: Wolfgang Denk Date: Thu, 31 Jan 2013 00:46:24 +0100 Message-Id: <1359589584-19846-1-git-send-email-lkundrak@v3.sk> X-Mailer: git-send-email 1.7.1 X-Mailman-Approved-At: Thu, 31 Jan 2013 06:23:03 +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. --- tools/env/fw_env.c | 21 ++++++++++++++++----- tools/env/fw_env.config | 3 +++ 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/tools/env/fw_env.c b/tools/env/fw_env.c index 37b60b8..0d8052d 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,23 +949,34 @@ 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 MTD device"); 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; } DEVTYPE(dev_current) = mtdinfo.type; - rc = flash_read_buf(dev_current, fd, environment.image, CUR_ENVSIZE, DEVOFFSET (dev_current), mtdinfo.type); 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