unvram: make it work on bcm47xx, also look for /dev/mtdblockX
authorJo-Philipp Wich <jow@openwrt.org>
Sun, 26 Apr 2009 20:42:36 +0000 (20:42 +0000)
committerJo-Philipp Wich <jow@openwrt.org>
Sun, 26 Apr 2009 20:42:36 +0000 (20:42 +0000)
SVN-Revision: 15429

package/unvram/Makefile
package/unvram/src/nvram.c
package/unvram/src/nvram.h

index 5529bdf06846ea8693fe5cc7fb7726da26ed0fbf..2fab89a63414062200f9ea88a53f842edc743067 100644 (file)
@@ -8,7 +8,7 @@
 include $(TOPDIR)/rules.mk
 
 PKG_NAME:=unvram
-PKG_RELEASE:=1
+PKG_RELEASE:=2
 
 PKG_BUILD_DIR := $(BUILD_DIR)/$(PKG_NAME)
 
index 4dfe0a95977057642f2678b37359127024bb819f..a5f1d43508984c25d2171b00c571997ea3635da2 100644 (file)
@@ -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;
+                                               }
+                                       }
                                }
                        }
                }
index 09650239ec84457ce2a5f7120c3ee3a8bfe97b8c..b718928c0e57d0d11265fb3e2c1c2766acfa3fb9 100644 (file)
@@ -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"