Remove hardcoded mtdblock number and simplify the code.
With this change, we depend on a boot script setting up /dev/mtd/hnvram as a
symlink to the right mtd block device, but now it'll work even if the hnvram
isn't always partition mtdblock1.
Also simplify the code: it was doing a bunch of unnecessary junk to write to
the flash, when it can just simply write to the flash.
Change-Id: Ie7bf0b6b9be5cdbe065ae9965bd0df8a3ade17df
diff --git a/libupgrade/hmx_upgrade_flash.c b/libupgrade/hmx_upgrade_flash.c
index 32db792..6153d01 100644
--- a/libupgrade/hmx_upgrade_flash.c
+++ b/libupgrade/hmx_upgrade_flash.c
@@ -82,8 +82,7 @@
/*******************************************************************/
/* Start #define */
/* this is for test */
-#define TARGET_NVRAM_MTD "/dev/mtdblock1"
-#define TARGET_NVRAM_MTDC "/dev/mtd1"
+#define TARGET_NVRAM_MTD "/dev/mtd/hnvram"
/* End #define */
/*******************************************************************/
@@ -105,8 +104,7 @@
/************************ static variables *************************/
/*******************************************************************/
/* Start static variable */
-int fd_nvram = 0;
-int fd_nvram_c = -1;
+int fd_nvram = -1;
static unsigned long s_FlashTotalSize;
static unsigned long s_FlashBlockSize;
@@ -120,67 +118,28 @@
unsigned int size )
{
int ret;
- struct mtd_info_user info;
- unsigned long block_size, write_size;
- unsigned long mov_offset, remain_size;
if (libupgrade_verbose) printf("[%s] offset %08x, size %d, data = %02x\n",
__FUNCTION__, offset, size, data[0] );
- /* */
- if ( fd_nvram == 0 ) {
+ if ( fd_nvram < 0 ) {
fd_nvram = open(TARGET_NVRAM_MTD, (O_RDWR | O_SYNC) );
if( fd_nvram < 0 ) {
- printf( "Failed to open!\n" );
+ perror(TARGET_NVRAM_MTD);
return -1;
}
}
- if ( fd_nvram_c < 0 ) {
- fd_nvram_c = open(TARGET_NVRAM_MTDC, (O_RDWR | O_SYNC) );
- if( fd_nvram_c < 0 ) {
- printf( "Failed to open!\n" );
- return -1;
- }
- }
-
- ret = ioctl(fd_nvram_c, MEMGETINFO,(void *)&info);
+ ret = lseek(fd_nvram, offset, SEEK_SET);
if(ret < 0) {
- printf("can't get info data! (%d)\n", ret);
+ perror("lseek");
return -1;
}
- remain_size = size;
- mov_offset = offset;
-
- while(remain_size > 0) {
- /* offsetÀÌ block ³Ñ¾î¼¸é ¾ÈµÈ´Ù.. */
- write_size = info.erasesize;
- write_size -= ((mov_offset + info.erasesize)%info.erasesize);
-
- /* ¸¶Áö¸·Àº ³ª¸ÓÁö ¸¸Å.. */
- if( remain_size < write_size) {
- write_size = remain_size;
- }
-
- if (libupgrade_verbose) {
- printf(" write : offset - 0x%x, size %d\n", mov_offset, write_size);
- }
-
- ret = lseek(fd_nvram, mov_offset, SEEK_SET);
- if(ret < 0) {
- printf("can't seek position! (%d)\n", ret);
- return -1;
- }
-
- ret = write(fd_nvram, data+(mov_offset-offset), write_size);
- if(ret < 0) {
- printf("can't write data! (%d)\n", ret);
- return -1;
- }
-
- mov_offset += write_size;
- remain_size -= write_size;
+ ret = write(fd_nvram, data, size);
+ if(ret < 0) {
+ perror("write");
+ return -1;
}
return 0;
@@ -190,7 +149,6 @@
unsigned int size )
{
int ret;
- struct mtd_info_user info;
unsigned long block_size, write_size;
unsigned long mov_offset, remain_size;
@@ -198,10 +156,10 @@
__FUNCTION__, offset, size, data[0] );
/* */
- if ( fd_nvram == 0 ) {
+ if ( fd_nvram < 0 ) {
fd_nvram = open(TARGET_NVRAM_MTD, (O_RDWR | O_SYNC) );
if( fd_nvram < 0 ) {
- printf( "Failed to open!\n" );
+ perror(TARGET_NVRAM_MTD);
return -1;
}
}
@@ -209,13 +167,13 @@
ret = lseek(fd_nvram, offset, SEEK_SET);
if(ret < 0) {
- printf("can't seek position! (%d)\n", ret);
+ perror(lseek);
return -1;
}
ret = read(fd_nvram, data, size);
if(ret < 0) {
- printf("can't read data! (%d)\n", ret);
+ perror("read");
return ret;
}