diff options
author | Jo-Philipp Wich <jow@openwrt.org> | 2010-07-19 22:20:07 +0000 |
---|---|---|
committer | Jo-Philipp Wich <jow@openwrt.org> | 2010-07-19 22:20:07 +0000 |
commit | f813a693fd5e07c60c042a0b11ae8e15144fc960 (patch) | |
tree | a1dae749b3ad33263d56c889d557fac19235886b /package/nvram | |
parent | c811398d00f0b23a9daef2b5f422785233880f34 (diff) | |
download | mtk-20170518-f813a693fd5e07c60c042a0b11ae8e15144fc960.zip mtk-20170518-f813a693fd5e07c60c042a0b11ae8e15144fc960.tar.gz mtk-20170518-f813a693fd5e07c60c042a0b11ae8e15144fc960.tar.bz2 |
nvram: handle nvram at varying offsets within the eraseblock (fixes Edimax PS-1208mfg with FLSH at offset 0)
SVN-Revision: 22299
Diffstat (limited to 'package/nvram')
-rw-r--r-- | package/nvram/Makefile | 2 | ||||
-rw-r--r-- | package/nvram/src/cli.c | 1 | ||||
-rw-r--r-- | package/nvram/src/nvram.c | 21 | ||||
-rw-r--r-- | package/nvram/src/nvram.h | 4 |
4 files changed, 22 insertions, 6 deletions
diff --git a/package/nvram/Makefile b/package/nvram/Makefile index c47f1c7..7fc9cc8 100644 --- a/package/nvram/Makefile +++ b/package/nvram/Makefile @@ -8,7 +8,7 @@ include $(TOPDIR)/rules.mk PKG_NAME:=nvram -PKG_RELEASE:=7 +PKG_RELEASE:=8 PKG_BUILD_DIR := $(BUILD_DIR)/$(PKG_NAME) diff --git a/package/nvram/src/cli.c b/package/nvram/src/cli.c index 44d4b88..66ef904 100644 --- a/package/nvram/src/cli.c +++ b/package/nvram/src/cli.c @@ -111,6 +111,7 @@ static int do_info(nvram_handle_t *nvram) /* Show info */ printf("Magic: 0x%08X\n", hdr->magic); printf("Length: 0x%08X\n", hdr->len); + printf("Offset: 0x%08X\n", nvram->offset); printf("CRC8: 0x%02X (calculated: 0x%02X)\n", hdr->crc_ver_init & 0xFF, crc); diff --git a/package/nvram/src/nvram.c b/package/nvram/src/nvram.c index 7ab8c81..a0bc006 100644 --- a/package/nvram/src/nvram.c +++ b/package/nvram/src/nvram.c @@ -142,7 +142,7 @@ static int _nvram_rehash(nvram_handle_t *h) /* Get nvram header. */ nvram_header_t * nvram_header(nvram_handle_t *h) { - return (nvram_header_t *) &h->mmap[NVRAM_START(nvram_erase_size)]; + return (nvram_header_t *) &h->mmap[h->offset]; } /* Get the value of an NVRAM variable. */ @@ -337,10 +337,12 @@ int nvram_commit(nvram_handle_t *h) /* Open NVRAM and obtain a handle. */ nvram_handle_t * nvram_open(const char *file, int rdonly) { + int i; int fd; char *mtd = NULL; nvram_handle_t *h; nvram_header_t *header; + int offset = -1; /* If erase size or file are undefined then try to define them */ if( (nvram_erase_size == 0) || (file == NULL) ) @@ -361,15 +363,28 @@ nvram_handle_t * nvram_open(const char *file, int rdonly) if( mmap_area != MAP_FAILED ) { - memset(mmap_area, 0xFF, NVRAM_START(nvram_erase_size)); + for( i = 0; i <= ((nvram_erase_size - NVRAM_SPACE) / sizeof(uint32_t)); i++ ) + { + if( ((uint32_t *)mmap_area)[i] == NVRAM_MAGIC ) + { + offset = i * sizeof(uint32_t); + break; + } + } - if((h = (nvram_handle_t *) malloc(sizeof(nvram_handle_t))) != NULL) + if( offset < 0 ) + { + free(mtd); + return NULL; + } + else if( (h = malloc(sizeof(nvram_handle_t))) != NULL ) { memset(h, 0, sizeof(nvram_handle_t)); h->fd = fd; h->mmap = mmap_area; h->length = nvram_erase_size; + h->offset = offset; header = nvram_header(h); diff --git a/package/nvram/src/nvram.h b/package/nvram/src/nvram.h index e3d6461..c72f67e 100644 --- a/package/nvram/src/nvram.h +++ b/package/nvram/src/nvram.h @@ -46,7 +46,8 @@ struct nvram_tuple { struct nvram_handle { int fd; char *mmap; - unsigned long length; + unsigned int length; + unsigned int offset; struct nvram_tuple *nvram_hash[257]; struct nvram_tuple *nvram_dead; }; @@ -113,7 +114,6 @@ char * nvram_find_staging(void); /* NVRAM constants */ #define NVRAM_SPACE 0x8000 -#define NVRAM_START(x) x - NVRAM_SPACE #define NVRAM_MAGIC 0x48534C46 /* 'FLSH' */ #define NVRAM_VERSION 1 |