From patchwork Fri Feb 8 08:08:58 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lubomir Rintel X-Patchwork-Id: 219068 X-Patchwork-Delegate: trini@ti.com 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 035892C0086 for ; Fri, 8 Feb 2013 19:43:33 +1100 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 9D8D14A0A9; Fri, 8 Feb 2013 09:43:30 +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 SD2IcnXuIJhH; Fri, 8 Feb 2013 09:43:30 +0100 (CET) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 7E8584A0AA; Fri, 8 Feb 2013 09:43:28 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 8BDE74A0A9 for ; Fri, 8 Feb 2013 09:09:12 +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 MXHPbsPgNq8h for ; Fri, 8 Feb 2013 09:09:10 +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 32AD84A0A2 for ; Fri, 8 Feb 2013 09:09:08 +0100 (CET) Received: from localhost (localhost.localdomain [127.0.0.1]) by norkia.v3.sk (Postfix) with ESMTP id 901EA12A0AE; Fri, 8 Feb 2013 09:09:05 +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 CjYKaEy2Gdcn; Fri, 8 Feb 2013 09:09:02 +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 8D18C12A098; Fri, 8 Feb 2013 09:09:02 +0100 (CET) From: Lubomir Rintel To: Wolfgang Denk Date: Fri, 8 Feb 2013 09:08:58 +0100 Message-Id: <1360310938-1731-1-git-send-email-lkundrak@v3.sk> X-Mailer: git-send-email 1.7.1 In-Reply-To: <20130207165819.700DE200565@gemini.denx.de> References: <20130207165819.700DE200565@gemini.denx.de> X-Mailman-Approved-At: Fri, 08 Feb 2013 09:43:26 +0100 Cc: u-boot@lists.denx.de, Lubomir Rintel Subject: [U-Boot] [PATCH v3] 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 --- Changes for v2: - Coding Style cleanup - Clarified an error message Changes for v3: - Used MTD_ABSENT macro to represent non-MTD devices - Cleaned up places when zero was used instead of MTD_ABSENT tools/env/fw_env.c | 32 ++++++++++++++++++++++---------- tools/env/fw_env.config | 3 +++ 2 files changed, 25 insertions(+), 10 deletions(-) diff --git a/tools/env/fw_env.c b/tools/env/fw_env.c index 37b60b8..94a790d 100644 --- a/tools/env/fw_env.c +++ b/tools/env/fw_env.c @@ -836,9 +836,9 @@ static int flash_write_buf (int dev, int fd, void *buf, size_t count, erase.start = blockstart; ioctl (fd, MEMUNLOCK, &erase); - - /* Dataflash does not need an explicit erase cycle */ - if (mtd_type != MTD_DATAFLASH) + /* These do not need an explicit erase cycle */ + if (mtd_type != MTD_ABSENT && + mtd_type != MTD_DATAFLASH) if (ioctl (fd, MEMERASE, &erase) != 0) { fprintf (stderr, "MTD erase error on %s: %s\n", DEVNAME (dev), @@ -949,19 +949,31 @@ 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 (mtdinfo.type != MTD_NORFLASH && - mtdinfo.type != MTD_NANDFLASH && - mtdinfo.type != MTD_DATAFLASH) { - fprintf (stderr, "Unsupported flash type %u\n", mtdinfo.type); - return -1; + if (S_ISCHR(st.st_mode)) { + rc = ioctl(fd, MEMGETINFO, &mtdinfo); + if (rc < 0) { + perror("Cannot get MTD information"); + return -1; + } + if (mtdinfo.type != MTD_NORFLASH && + mtdinfo.type != MTD_NANDFLASH && + mtdinfo.type != MTD_DATAFLASH) { + fprintf(stderr, "Unsupported flash type %u\n", + mtdinfo.type); + return -1; + } + } else { + memset(&mtdinfo, 0, sizeof(mtdinfo)); + mtdinfo.type = MTD_ABSENT; } DEVTYPE(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