diff options
author | Jo-Philipp Wich <jow@openwrt.org> | 2009-04-26 20:42:36 +0000 |
---|---|---|
committer | Jo-Philipp Wich <jow@openwrt.org> | 2009-04-26 20:42:36 +0000 |
commit | 0f3ccb8868dc2b815c92bfa8b33d7211374268fb (patch) | |
tree | cbf4449ac1fc6cf37223a660f24065fdf7d06815 /package | |
parent | 2d9c80b60fe413115b3aa30f752684830c321e43 (diff) | |
download | upstream-0f3ccb8868dc2b815c92bfa8b33d7211374268fb.tar.gz upstream-0f3ccb8868dc2b815c92bfa8b33d7211374268fb.tar.bz2 upstream-0f3ccb8868dc2b815c92bfa8b33d7211374268fb.zip |
unvram: make it work on bcm47xx, also look for /dev/mtdblockX
SVN-Revision: 15429
Diffstat (limited to 'package')
-rw-r--r-- | package/unvram/Makefile | 2 | ||||
-rw-r--r-- | package/unvram/src/nvram.c | 29 | ||||
-rw-r--r-- | package/unvram/src/nvram.h | 2 |
3 files changed, 25 insertions, 8 deletions
diff --git a/package/unvram/Makefile b/package/unvram/Makefile index 5529bdf068..2fab89a634 100644 --- a/package/unvram/Makefile +++ b/package/unvram/Makefile @@ -8,7 +8,7 @@ include $(TOPDIR)/rules.mk PKG_NAME:=unvram -PKG_RELEASE:=1 +PKG_RELEASE:=2 PKG_BUILD_DIR := $(BUILD_DIR)/$(PKG_NAME) diff --git a/package/unvram/src/nvram.c b/package/unvram/src/nvram.c index 4dfe0a9597..a5f1d43508 100644 --- a/package/unvram/src/nvram.c +++ b/package/unvram/src/nvram.c @@ -409,6 +409,7 @@ const char * nvram_find_mtd(void) int i, esz; char dev[PATH_MAX]; char *path = NULL; + struct stat s; // "/dev/mtdblock/" + ( 0 < x < 99 ) + \0 = 19 if( (path = (char *) malloc(19)) == NULL ) @@ -416,12 +417,30 @@ const char * nvram_find_mtd(void) if ((fp = fopen("/proc/mtd", "r"))) { while (fgets(dev, sizeof(dev), fp)) { - if (strstr(dev, "nvram") && sscanf(dev, "mtd%d: %08x", &i, &esz)) { - if( (path = (char *) malloc(19)) != NULL ) + if (strstr(dev, "nvram") && sscanf(dev, "mtd%d: %08x", &i, &esz)) + { + nvram_erase_size = esz; + + sprintf(dev, "/dev/mtdblock/%d", i); + if( stat(dev, &s) > -1 && (s.st_mode & S_IFBLK) ) + { + if( (path = (char *) malloc(strlen(dev)+1)) != NULL ) + { + strncpy(path, dev, strlen(dev)+1); + break; + } + } + else { - nvram_erase_size = esz; - snprintf(path, 19, "/dev/mtdblock/%d", i); - break; + sprintf(dev, "/dev/mtdblock%d", i); + if( stat(dev, &s) > -1 && (s.st_mode & S_IFBLK) ) + { + if( (path = (char *) malloc(strlen(dev)+1)) != NULL ) + { + strncpy(path, dev, strlen(dev)+1); + break; + } + } } } } diff --git a/package/unvram/src/nvram.h b/package/unvram/src/nvram.h index 09650239ec..b718928c0e 100644 --- a/package/unvram/src/nvram.h +++ b/package/unvram/src/nvram.h @@ -24,8 +24,6 @@ #include <errno.h> #include <sys/mman.h> #include <sys/stat.h> -#include <sys/ioctl.h> -#include <arpa/inet.h> #include <linux/limits.h> #include "sdinitvals.h" |