summaryrefslogtreecommitdiff
path: root/tools/env/fw_env.c
diff options
context:
space:
mode:
authorLubomir Rintel <lkundrak@v3.sk>2013-02-10 01:02:36 +0000
committerTom Rini <trini@ti.com>2013-03-11 17:05:04 -0400
commitf1932b78505aa52fc29e5862ed8588a6f1bbe3ec (patch)
treea75378bbb248e35b49f15f2d0d8a46d3b2ffb304 /tools/env/fw_env.c
parentc8b5f556c069fcb82e0c5289189dc31f4d5d62f1 (diff)
downloadu-boot-imx-f1932b78505aa52fc29e5862ed8588a6f1bbe3ec.zip
u-boot-imx-f1932b78505aa52fc29e5862ed8588a6f1bbe3ec.tar.gz
u-boot-imx-f1932b78505aa52fc29e5862ed8588a6f1bbe3ec.tar.bz2
env: Allow accessing non-mtd devices
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 <lkundrak@v3.sk>
Diffstat (limited to 'tools/env/fw_env.c')
-rw-r--r--tools/env/fw_env.c34
1 files changed, 24 insertions, 10 deletions
diff --git a/tools/env/fw_env.c b/tools/env/fw_env.c
index 37b60b80..bf30234 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,33 @@ 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");
+ fprintf(stderr, "Cannot stat the file %s\n",
+ DEVNAME(dev_current));
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) {
+ fprintf(stderr, "Cannot get MTD information for %s\n",
+ DEVNAME(dev_current));
+ return -1;
+ }
+ if (mtdinfo.type != MTD_NORFLASH &&
+ mtdinfo.type != MTD_NANDFLASH &&
+ mtdinfo.type != MTD_DATAFLASH) {
+ fprintf (stderr, "Unsupported flash type %u on %s\n",
+ mtdinfo.type, DEVNAME(dev_current));
+ return -1;
+ }
+ } else {
+ memset(&mtdinfo, 0, sizeof(mtdinfo));
+ mtdinfo.type = MTD_ABSENT;
}
DEVTYPE(dev_current) = mtdinfo.type;