[Feature][ZXW-179]merge P52U02 version
Only Configure: No
Affected branch: master
Affected module: unknow
Is it affected on both ZXIC and MTK: only ZXIC
Self-test: Yes
Doc Update: No
Change-Id: I4fa8f86757e71388ae88400914dae8b50cd00338
diff --git a/ap/os/linux/linux-3.4.x/drivers/mtd/mtdadapter.c b/ap/os/linux/linux-3.4.x/drivers/mtd/mtdadapter.c
old mode 100644
new mode 100755
index c7b418a..1cc4218
--- a/ap/os/linux/linux-3.4.x/drivers/mtd/mtdadapter.c
+++ b/ap/os/linux/linux-3.4.x/drivers/mtd/mtdadapter.c
@@ -19,6 +19,7 @@
#include <linux/kernel.h>
#include <linux/mtd/mtd.h>
#include <linux/module.h>
+#include <linux/soc/zte/otp/otp_zx.h>
#define READ_ZLOADER_FLAG_SIZE 0x800
#define WRITE_ZLOADER_FLAG_SIZE 0x3000
@@ -26,6 +27,8 @@
extern struct mtd_info *mtd_fota;
extern int g_zload_read_only_flag;
+extern char *nor_cmdline;
+unsigned char nor_flag = 0;
#ifndef USE_CPPS_KO
extern unsigned int zOss_NvItemRead(unsigned int NvItemID, unsigned char *NvItemData, unsigned int NvItemLen);
@@ -212,23 +215,59 @@
if( buffer == NULL )
return -1;
- if(mtd_read(mtd_fota,0,READ_ZLOADER_FLAG_SIZE,&retlen,buffer))/* BOOTFLAGÔÚnandµÄµÚ20~27×Ö½Ú */
- {
- kfree(buffer);
- return 1;
- }
- memcpy(&value, buffer+2, 1);
- bootflag = value;
-
- if( bootflag == 0x5a)
- {
- bootflag = 1;
- }
+ if(nor_cmdline != NULL)
+ {
+ if (!strcmp(nor_cmdline, "1"))
+ {
+ nor_flag = 1;
+ printk("----------EnhancedSecurity---------\n");
+ }
+ }
+ if(1 == nor_flag)
+ {
+#ifndef CONFIG_SPI_ZXIC_NOR
+
+ if(nor_read(0, 256, buffer))
+ {
+ kfree(buffer);
+ return 1;
+ }
+ memcpy(&value, buffer+2, 1);
+ bootflag = value;
+
+ if( bootflag == 0x5a)
+ {
+ bootflag = 1;
+ }
+ else
+ {
+ bootflag = 0;
+ }
+ kfree(buffer);
+#endif
+ }
else
{
- bootflag = 0;
- }
- kfree(buffer);
+ if(mtd_read(mtd_fota,0,READ_ZLOADER_FLAG_SIZE,&retlen,buffer))/* BOOTFLAGÔÚnandµÄµÚ20~27×Ö½Ú */
+ {
+ kfree(buffer);
+ return 1;
+ }
+ memcpy(&value, buffer+2, 1);
+ bootflag = value;
+
+ if( bootflag == 0x5a)
+ {
+ bootflag = 1;
+ }
+ else
+ {
+ bootflag = 0;
+ }
+ kfree(buffer);
+
+ }
+
return bootflag;
}
@@ -246,38 +285,87 @@
int bootflag = 0;
int retlen = 0;
struct erase_info ei;
-
- unsigned char *buffer = kzalloc(WRITE_ZLOADER_FLAG_SIZE,GFP_KERNEL);
- if( buffer == NULL )
- return -1;
-
- if(mtd_read(mtd_fota,0,WRITE_ZLOADER_FLAG_SIZE,&retlen,buffer))/* BOOTFLAGÔÚnandµÄµÚ20~27×Ö½Ú */
- {
- kfree(buffer);
- return -1;
- }
- if(flag == 0 )
+ if(nor_cmdline != NULL)
{
- bootflag = 0x00;
- memset(&value, bootflag, 1);
+ if (!strcmp(nor_cmdline, "1"))
+ {
+ nor_flag = 1;
+ printk("----------EnhancedSecurity---------\n");
+ }else{
+ printk("----------normal---------\n");
+ }
+ }else{
+ printk("----------nor cmdline is null!---------\n");
}
- else
- {
- bootflag = 0x5a;
- memset(&value, bootflag, 1);
- }
+
+ if(1 == nor_flag)
+ {
+#ifndef CONFIG_SPI_ZXIC_NOR
+
+ unsigned char *buffer = kmalloc(0x10000, GFP_KERNEL);
+
+ if( buffer == NULL )
+ return -1;
- memcpy(buffer+2, &value, 1);
- memset(&ei, 0, sizeof(struct erase_info));
- ei.mtd = mtd_fota;
- ei.addr = 0;
- ei.len = mtd_fota->erasesize;
- g_zload_read_only_flag = 1;
- ret = mtd_erase(mtd_fota, &ei); /*²Á³ýµÚÒ»¿é*/
- ret = mtd_write(mtd_fota,0,WRITE_ZLOADER_FLAG_SIZE,&retlen,buffer);
- g_zload_read_only_flag = 0;
- kfree(buffer);
+ if(nor_read(0,0x10000,buffer))
+ {
+ kfree(buffer);
+ return -1;
+ }
+ if(flag == 0 )
+ {
+ bootflag = 0x00;
+ memset(&value, bootflag, 1);
+ }
+ else
+ {
+ bootflag = 0x5a;
+ memset(&value, bootflag, 1);
+ }
+
+ memcpy(buffer+2, &value, 1);
+
+ ret = nor_erase(0);
+ ret = nor_write(0,0x10000,buffer);
+ kfree(buffer);
+#endif
+ }
+ else
+ {
+ unsigned char *buffer = kzalloc(WRITE_ZLOADER_FLAG_SIZE,GFP_KERNEL);
+
+ if( buffer == NULL )
+ return -1;
+
+ if(mtd_read(mtd_fota,0,WRITE_ZLOADER_FLAG_SIZE,&retlen,buffer))/* BOOTFLAGÔÚnandµÄµÚ20~27×Ö½Ú */
+ {
+ kfree(buffer);
+ return -1;
+ }
+ if(flag == 0 )
+ {
+ bootflag = 0x00;
+ memset(&value, bootflag, 1);
+ }
+ else
+ {
+ bootflag = 0x5a;
+ memset(&value, bootflag, 1);
+ }
+
+ memcpy(buffer+2, &value, 1);
+ memset(&ei, 0, sizeof(struct erase_info));
+ ei.mtd = mtd_fota;
+ ei.addr = 0;
+ ei.len = mtd_fota->erasesize;
+ g_zload_read_only_flag = 1;
+ ret = mtd_erase(mtd_fota, &ei); /*²Á³ýµÚÒ»¿é*/
+ ret = mtd_write(mtd_fota,0,WRITE_ZLOADER_FLAG_SIZE,&retlen,buffer);
+ g_zload_read_only_flag = 0;
+ kfree(buffer);
+
+ }
return 0;