Fix flash write support.

MEMGETINFO can not be issued to an mtdblock device, only an mtd
device. This bothers me in that this code could never have worked,
since adding the MEMGETINFO call Humax has clearly never tested it.
Nonetheless it seems to work in my own testing, so I'm ready to go
with it.

Also (optionally) suppress verbose output.

Change-Id: I1cab453c4986265f4a7a644723c14988fa4cb5a3
diff --git a/libupgrade/hmx_upgrade_flash.c b/libupgrade/hmx_upgrade_flash.c
index 46fa911..2002377 100644
--- a/libupgrade/hmx_upgrade_flash.c
+++ b/libupgrade/hmx_upgrade_flash.c
@@ -61,6 +61,7 @@
 #define TARGET_BOOT_LOADER_MTD	"/dev/mtdblock0"

 

 #define TARGET_NVRAM_MTD	"/dev/mtdblock1"

+#define TARGET_NVRAM_MTDC	"/dev/mtd1"

 

 /* this is for test */

 #define TARGET_KERNEL_MTD	"/dev/mtdblock10"

@@ -82,7 +83,7 @@
 /************************ global variables *************************/

 /*******************************************************************/

 /* Start global variable */

-

+int libupgrade_verbose = 1;

 /* End global variable */

 

 

@@ -94,6 +95,7 @@
 int fd_rootfs = 0;

 int fd_boorloader = 0;

 int fd_nvram = 0;

+int fd_nvram_c = -1;

 

 static unsigned long	s_FlashTotalSize;

 static unsigned long	s_FlashBlockSize;

@@ -127,7 +129,7 @@
 	unsigned long block_size, write_size;

 	unsigned long mov_offset, remain_size;

 

-	printf("[%s] offset %08x, size %d, data = %02x\n",__FUNCTION__, offset, size, data[0] );

+	if (libupgrade_verbose) printf("[%s] offset %08x, size %d, data = %02x\n",__FUNCTION__, offset, size, data[0] );

 

 	/* */

 	if ( fd_nvram == 0 )

@@ -140,7 +142,17 @@
 		}

 	}

 

-	ret = ioctl(fd_nvram, MEMGETINFO,(void *)&info);

+	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);

 	if(ret < 0)

 	{

 		printf("can't get info data! (%d)\n", ret);

@@ -162,7 +174,7 @@
 			write_size = remain_size;

 		}

 

-		printf(" write : offset - 0x%x, size %d\n", mov_offset, write_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)

@@ -192,7 +204,7 @@
 	unsigned long block_size, write_size;

 	unsigned long mov_offset, remain_size;

 

-	printf("[%s] offset %08x, size %d, data = %02x\n",__FUNCTION__, offset, size, data[0] );

+	if (libupgrade_verbose) printf("[%s] offset %08x, size %d, data = %02x\n",__FUNCTION__, offset, size, data[0] );

 

 	/* */

 	if ( fd_nvram == 0 )

diff --git a/libupgrade/hmx_upgrade_nvram.h b/libupgrade/hmx_upgrade_nvram.h
index 242acd6..b9dd3f6 100644
--- a/libupgrade/hmx_upgrade_nvram.h
+++ b/libupgrade/hmx_upgrade_nvram.h
@@ -42,6 +42,7 @@
 /************************ Extern variables *************************/

 /*******************************************************************/

 /* Start Extern variablee */

+extern int libupgrade_verbose;

 

 /* End Extern variable */