aboutsummaryrefslogtreecommitdiffstats
path: root/package
diff options
context:
space:
mode:
authorRafał Miłecki <zajec5@gmail.com>2015-04-24 14:28:57 +0000
committerRafał Miłecki <zajec5@gmail.com>2015-04-24 14:28:57 +0000
commit388ae4d9d1202fd137952a5dbb8bcc5cf3c86397 (patch)
tree43081b2603be7246530b51c2aee9522ba0626fa7 /package
parent31f0f77e556d5de457196185dc73540af1daa758 (diff)
downloadupstream-388ae4d9d1202fd137952a5dbb8bcc5cf3c86397.tar.gz
upstream-388ae4d9d1202fd137952a5dbb8bcc5cf3c86397.tar.bz2
upstream-388ae4d9d1202fd137952a5dbb8bcc5cf3c86397.zip
nvram: fix regression in finding NVRAM beginning
The loop was giving up too early as it never expected NVRAM smaller than 0x10000. Signed-off-by: Rafał Miłecki <zajec5@gmail.com> git-svn-id: svn://svn.openwrt.org/openwrt/trunk@45578 3c298f89-4303-0410-b956-a3cf2f4a3e73
Diffstat (limited to 'package')
-rw-r--r--package/utils/nvram/src/nvram.c7
-rw-r--r--package/utils/nvram/src/nvram.h1
2 files changed, 7 insertions, 1 deletions
diff --git a/package/utils/nvram/src/nvram.c b/package/utils/nvram/src/nvram.c
index 0e1c726837..c4bcb1d4a6 100644
--- a/package/utils/nvram/src/nvram.c
+++ b/package/utils/nvram/src/nvram.c
@@ -364,7 +364,12 @@ nvram_handle_t * nvram_open(const char *file, int rdonly)
if( mmap_area != MAP_FAILED )
{
- for( i = 0; i <= ((nvram_part_size - NVRAM_SPACE) / sizeof(uint32_t)); i++ )
+ /*
+ * Start looking for NVRAM_MAGIC at beginning of MTD
+ * partition. Stop if there is less than NVRAM_MIN_SPACE
+ * to check, that was the lowest used size.
+ */
+ for( i = 0; i <= ((nvram_part_size - NVRAM_MIN_SPACE) / sizeof(uint32_t)); i++ )
{
if( ((uint32_t *)mmap_area)[i] == NVRAM_MAGIC )
{
diff --git a/package/utils/nvram/src/nvram.h b/package/utils/nvram/src/nvram.h
index cd37650860..215d816327 100644
--- a/package/utils/nvram/src/nvram.h
+++ b/package/utils/nvram/src/nvram.h
@@ -113,6 +113,7 @@ char * nvram_find_staging(void);
#define NVRAM_ROUNDUP(x, y) ((((x)+((y)-1))/(y))*(y))
/* NVRAM constants */
+#define NVRAM_MIN_SPACE 0x8000
#define NVRAM_SPACE 0x10000
#define NVRAM_MAGIC 0x48534C46 /* 'FLSH' */
#define NVRAM_VERSION 1