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>
This commit is contained in:
parent
c8b5f556c0
commit
f1932b7850
34
tools/env/fw_env.c
vendored
34
tools/env/fw_env.c
vendored
@ -836,9 +836,9 @@ static int flash_write_buf (int dev, int fd, void *buf, size_t count,
|
|||||||
|
|
||||||
erase.start = blockstart;
|
erase.start = blockstart;
|
||||||
ioctl (fd, MEMUNLOCK, &erase);
|
ioctl (fd, MEMUNLOCK, &erase);
|
||||||
|
/* These do not need an explicit erase cycle */
|
||||||
/* Dataflash does not need an explicit erase cycle */
|
if (mtd_type != MTD_ABSENT &&
|
||||||
if (mtd_type != MTD_DATAFLASH)
|
mtd_type != MTD_DATAFLASH)
|
||||||
if (ioctl (fd, MEMERASE, &erase) != 0) {
|
if (ioctl (fd, MEMERASE, &erase) != 0) {
|
||||||
fprintf (stderr, "MTD erase error on %s: %s\n",
|
fprintf (stderr, "MTD erase error on %s: %s\n",
|
||||||
DEVNAME (dev),
|
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)
|
static int flash_read (int fd)
|
||||||
{
|
{
|
||||||
struct mtd_info_user mtdinfo;
|
struct mtd_info_user mtdinfo;
|
||||||
|
struct stat st;
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
rc = ioctl (fd, MEMGETINFO, &mtdinfo);
|
rc = fstat(fd, &st);
|
||||||
if (rc < 0) {
|
if (rc < 0) {
|
||||||
perror ("Cannot get MTD information");
|
fprintf(stderr, "Cannot stat the file %s\n",
|
||||||
|
DEVNAME(dev_current));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mtdinfo.type != MTD_NORFLASH &&
|
if (S_ISCHR(st.st_mode)) {
|
||||||
mtdinfo.type != MTD_NANDFLASH &&
|
rc = ioctl(fd, MEMGETINFO, &mtdinfo);
|
||||||
mtdinfo.type != MTD_DATAFLASH) {
|
if (rc < 0) {
|
||||||
fprintf (stderr, "Unsupported flash type %u\n", mtdinfo.type);
|
fprintf(stderr, "Cannot get MTD information for %s\n",
|
||||||
return -1;
|
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;
|
DEVTYPE(dev_current) = mtdinfo.type;
|
||||||
|
3
tools/env/fw_env.config
vendored
3
tools/env/fw_env.config
vendored
@ -17,3 +17,6 @@
|
|||||||
|
|
||||||
# NAND example
|
# NAND example
|
||||||
#/dev/mtd0 0x4000 0x4000 0x20000 2
|
#/dev/mtd0 0x4000 0x4000 0x20000 2
|
||||||
|
|
||||||
|
# Block device example
|
||||||
|
#/dev/mmcblk0 0xc0000 0x20000
|
||||||
|
Loading…
Reference in New Issue
Block a user