[Feature][ZXW-311] add lynq nv config support & merge changes for sihai

Only Configure :No
Affected branch: master
Affected module: uboot/ap
Is it affected on both ZXIC and MTK:only ZXIC
Self-test: Yes
Doc Update: No

Change-Id: Ie02a4c5daad09441e82b92c9746d5aff0a603692
diff --git a/ap/app/Script/scripts/nat.sh b/ap/app/Script/scripts/nat.sh
old mode 100644
new mode 100755
index 1c9b82e..db36140
--- a/ap/app/Script/scripts/nat.sh
+++ b/ap/app/Script/scripts/nat.sh
@@ -6,6 +6,7 @@
 #
 
 path_sh=`nv get path_sh`
+rndis_ip_map=`cat /sys/class/lynq_nv_cfg/cdev_lynq_nv_cfg/rndis_ip_map`
 . $path_sh/global.sh
 echo "Info: nat.sh start " >> $test_log
 
@@ -18,7 +19,9 @@
 iptables -P FORWARD ACCEPT
 
 #clear nat
-iptables -t nat -F
+if [ "$rndis_ip_map" != "1" ];then
+	iptables -t nat -F
+fi
 iptables -t nat -X $ZTE_FORWARD_CHAIN
 iptables -t nat -X $ZTE_DMZ_CHAIN
 iptables -t nat -X $ZTE_MAPPING_CHAIN
@@ -29,6 +32,12 @@
 iptables -t nat -N $ZTE_DMZ_CHAIN
 iptables -t nat -N $ZTE_MAPPING_CHAIN
 
+if [ "$rndis_ip_map" == "1" ];then
+	iptables -t nat -D PREROUTING -j $ZTE_FORWARD_CHAIN
+	iptables -t nat -D PREROUTING -j $ZTE_DMZ_CHAIN
+	iptables -t nat -D PREROUTING -j $ZTE_MAPPING_CHAIN
+fi
+
 iptables -t nat -I PREROUTING 1 -j $ZTE_FORWARD_CHAIN
 iptables -t nat -I PREROUTING 1 -j $ZTE_DMZ_CHAIN
 iptables -t nat -I PREROUTING 1 -j $ZTE_MAPPING_CHAIN
diff --git a/ap/app/zte_comm/zte_mainctrl/netdev_proc.c b/ap/app/zte_comm/zte_mainctrl/netdev_proc.c
index a24b64c..367298f 100755
--- a/ap/app/zte_comm/zte_mainctrl/netdev_proc.c
+++ b/ap/app/zte_comm/zte_mainctrl/netdev_proc.c
@@ -871,16 +871,24 @@
 		{
 			char nat_enable[4] = {0};
 			
+			int rndis_ip_map = !system("cat /sys/class/lynq_nv_cfg/cdev_lynq_nv_cfg/rndis_ip_map | grep 1");
 			system_cmd_ex("iptables -P INPUT ACCEPT");
 			system_cmd_ex("iptables -P OUTPUT ACCEPT");
 			system_cmd_ex("iptables -P FORWARD ACCEPT");
-			system_cmd_ex("iptables -t nat -F");
+			if (rndis_ip_map == 0)
+				system_cmd_ex("iptables -t nat -F");
 			system_cmd_ex("iptables -t nat -X port_forward");
 			system_cmd_ex("iptables -t nat -X DMZ");
 			system_cmd_ex("iptables -t nat -X port_mapping");
 			system_cmd_ex("iptables -t nat -N port_forward");
 			system_cmd_ex("iptables -t nat -N DMZ");
 			system_cmd_ex("iptables -t nat -N port_mapping");
+			if (rndis_ip_map == 1)
+			{
+				system_cmd_ex("iptables -t nat -D PREROUTING -j port_forward");
+				system_cmd_ex("iptables -t nat -D PREROUTING -j DMZ");
+				system_cmd_ex("iptables -t nat -D PREROUTING -j port_mapping");
+			}
 			system_cmd_ex("iptables -t nat -I PREROUTING 1 -j port_forward");
 			system_cmd_ex("iptables -t nat -I PREROUTING 1 -j DMZ");
 			system_cmd_ex("iptables -t nat -I PREROUTING 1 -j port_mapping");
diff --git a/ap/app/zte_mdl/zte_mdl.c b/ap/app/zte_mdl/zte_mdl.c
index 38bb203..b883b2a 100755
--- a/ap/app/zte_mdl/zte_mdl.c
+++ b/ap/app/zte_mdl/zte_mdl.c
@@ -93,8 +93,13 @@
 }
 void wlan_entry(char *arg)
 {
-#if (defined _USE_VEHICLE_DC_REF)&&(defined _USE_VEHICLE_DC_REF_MMC0) //jb.qi add for wifi config on 20240301
-	wlan_main(0,NULL);
+#if (defined _USE_VEHICLE_DC_REF) //jb.qi add for wifi config on 20240301
+	if (system("cat /sys/class/lynq_nv_cfg/cdev_lynq_nv_cfg/wifi_enable | grep 1") == 0) {
+		wlan_main(0,NULL);
+	}
+	else{
+		printf("not need to start wifi\n");
+	}
 #endif
 	return;
 }
diff --git a/ap/os/linux/linux-3.4.x/arch/arm/mach-zx297520v3/Makefile b/ap/os/linux/linux-3.4.x/arch/arm/mach-zx297520v3/Makefile
index 1d079c1..89aebac 100755
--- a/ap/os/linux/linux-3.4.x/arch/arm/mach-zx297520v3/Makefile
+++ b/ap/os/linux/linux-3.4.x/arch/arm/mach-zx297520v3/Makefile
@@ -10,7 +10,7 @@
 
 # CPU-specific support
 obj-$(CONFIG_ARCH_ZX297520V3)	+= io.o  irq.o board-zx297520v3.o spinlock.o pcu.o \
-                               		gpio.o debug.o reset.o pwr_ctrl.o 
+                               		gpio.o debug.o reset.o pwr_ctrl.o lynq_ap_nv_cfg.o
 obj-$(CONFIG_ARCH_ZX297520V3_EVB) += zx297520v3-evb-devices.o
 obj-$(CONFIG_ARCH_ZX297520V3_MDL) += zx297520v3-mdl-devices.o
 obj-$(CONFIG_ARCH_ZX297520V3_WATCH) += zx297520v3-watch-devices.o
diff --git a/ap/os/linux/linux-3.4.x/arch/arm/mach-zx297520v3/board-zx297520v3.c b/ap/os/linux/linux-3.4.x/arch/arm/mach-zx297520v3/board-zx297520v3.c
index 929e125..2601f6e 100755
--- a/ap/os/linux/linux-3.4.x/arch/arm/mach-zx297520v3/board-zx297520v3.c
+++ b/ap/os/linux/linux-3.4.x/arch/arm/mach-zx297520v3/board-zx297520v3.c
@@ -669,6 +669,9 @@
 	pwr_buck3v3_on(POWER_WIFI);
 	printk("buck3v3 on, wifi power up.\n");
 #endif
+	//youchen@2024-06-20 add for lynq nv config begin
+	modify_zx29_device_table();
+	//youchen@2024-06-20 add for lynq nv config end
 	platform_add_devices(zx29_device_table, zx29_device_table_num);
 
 #if (defined CONFIG_SPI_ZX29) || (defined CONFIG_SPI_GPIO)
diff --git a/ap/os/linux/linux-3.4.x/arch/arm/mach-zx297520v3/include/mach/board.h b/ap/os/linux/linux-3.4.x/arch/arm/mach-zx297520v3/include/mach/board.h
index 060569c..d6b6a32 100644
--- a/ap/os/linux/linux-3.4.x/arch/arm/mach-zx297520v3/include/mach/board.h
+++ b/ap/os/linux/linux-3.4.x/arch/arm/mach-zx297520v3/include/mach/board.h
@@ -75,6 +75,9 @@
 
 extern struct platform_device *zx29_device_table[];
 extern unsigned int zx29_device_table_num;
+//youchen@2024-06-20 add for lynq nv config begin
+extern void modify_zx29_device_table();
+//youchen@2024-06-20 add for lynq nv config end
 
 void __init zx29_map_io(void);
 void __init zx29_clock_init(void);
diff --git a/ap/os/linux/linux-3.4.x/arch/arm/mach-zx297520v3/include/mach/iomap.h b/ap/os/linux/linux-3.4.x/arch/arm/mach-zx297520v3/include/mach/iomap.h
index c721782..fe908c7 100755
--- a/ap/os/linux/linux-3.4.x/arch/arm/mach-zx297520v3/include/mach/iomap.h
+++ b/ap/os/linux/linux-3.4.x/arch/arm/mach-zx297520v3/include/mach/iomap.h
@@ -247,7 +247,12 @@
 

 #define SECURE_PUK_BASE						(POWERON_TYPE_BASE + 0xc)/*secure pub key 256byte*/

 #define WDT_IRAM_BASE						(SECURE_PUK_BASE + 0x100)/*wdt iram flag 36byte*/

-#define MMC_CFG_BASE						(WDT_IRAM_BASE+0x34)/*mmc flag 4Byte*/

+//youchen@2024-06-20 add for lynq nv config begin
+//#define MMC_CFG_BASE						(WDT_IRAM_BASE+0x34)/*mmc flag 4Byte*/

+#define MMC_LYNQ_NV_CFG_ADDR				(WDT_IRAM_BASE+0x34)/*mmc flag 1024Byte*/

+#define MMC_LYNQ_NV_CFG_SIZE				(0x100UL)
+//youchen@2024-06-20 add for lynq nv config end
+//
 /**************************************************************************************

  *                        iram: tsc

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

diff --git a/ap/os/linux/linux-3.4.x/arch/arm/mach-zx297520v3/lynq_ap_nv_cfg.c b/ap/os/linux/linux-3.4.x/arch/arm/mach-zx297520v3/lynq_ap_nv_cfg.c
new file mode 100755
index 0000000..7fae817
--- /dev/null
+++ b/ap/os/linux/linux-3.4.x/arch/arm/mach-zx297520v3/lynq_ap_nv_cfg.c
@@ -0,0 +1,232 @@
+#include <linux/module.h>

+#include <linux/kernel.h>

+#include <linux/types.h>

+#include <linux/init.h>

+#include <linux/slab.h>

+#include <linux/device.h>

+#include <lynq/lynq_ap_nv_cfg.h>

+#include <linux/crc16.h>

+#include <mach/iomap.h>

+#include <linux/cdev.h>

+//#include <asm-generic/iomap.h>

+#include "lynq_default_nv_cfg.h"

+

+static struct nv_cfg_info * g_nv_cfg_info = NULL;

+

+static struct nv_cfg_info * get_valid_nv_cfg(unsigned char * buff, unsigned int len)

+{

+    int content_len, pos, crc;

+    unsigned char * p_cfg_body = NULL;

+    struct lynq_nv_cfg_header *p_tail;

+    struct version_info * p_versions;

+    struct lynq_nv_cfg * p_nv_cfg = (struct lynq_nv_cfg *)buff;

+    if (p_nv_cfg == NULL)

+        return NULL;

+    if (p_nv_cfg->head.magic_flag != 0xaa55 || p_nv_cfg->head.valid_flag != 1 ||

+            len < (p_nv_cfg->head.content_len + sizeof(struct lynq_nv_cfg_header)*2))

+    {

+        printk("got bad header\n");

+        return NULL;

+    }

+    content_len = (char*)&p_nv_cfg->tail - (char*)&p_nv_cfg->head - sizeof(struct lynq_nv_cfg_header);

+    //actual content len less than default request len, maybe a lower version protocol, ignore

+    if (content_len > p_nv_cfg->head.content_len || content_len != sizeof(lynq_nv_cfg_bitmap))

+    {

+        printk("got bad content len\n");

+        return NULL;

+    }

+    else if ( content_len == p_nv_cfg->head.content_len)

+    {

+        if (p_nv_cfg->tail.magic_flag != 0x55aa || p_nv_cfg->tail.valid_flag != 1

+                || p_nv_cfg->tail.content_len != p_nv_cfg->head.content_len)

+        {

+            printk("got bad tail %d\n", __LINE__);

+            return NULL;

+        }

+        p_cfg_body = (unsigned char*)kzalloc(p_nv_cfg->head.content_len, GFP_KERNEL);

+        memcpy(p_cfg_body, &p_nv_cfg->content, p_nv_cfg->head.content_len);

+        p_versions = p_nv_cfg->versions;

+    }

+    else // maybe a newer protocol, need backward compatible

+    {

+        p_cfg_body = (unsigned char*)&p_nv_cfg->content;

+        p_tail = (struct lynq_nv_cfg_header *)(p_cfg_body+p_nv_cfg->head.content_len);

+        if (p_tail->magic_flag != 0x55aa || p_tail->valid_flag != 1

+                || p_tail->content_len != p_nv_cfg->head.content_len)

+        {

+            printk("got bad tail %d\n", __LINE__);

+            return NULL;

+        }

+        p_versions = (struct version_info *)(p_cfg_body+p_nv_cfg->head.content_len + sizeof (struct lynq_nv_cfg_header));

+        p_cfg_body = (unsigned char*)kzalloc(p_nv_cfg->head.content_len, GFP_KERNEL);

+        memcpy(p_cfg_body, &p_nv_cfg->content, p_nv_cfg->head.content_len);

+    }

+

+    while(p_versions->soft_ver != 0 && p_versions->crc != 0)

+    {

+        if (p_versions->soft_ver != lynq_default_soft_version)

+        {

+            p_versions++;

+            continue;

+        }

+

+        //

+        for(pos = 0; pos < content_len; pos ++)

+        {

+            p_cfg_body[pos] &= lynq_nv_cfg_bitmap[pos];

+        }

+

+        crc = crc16(0, p_cfg_body, content_len);

+        printk("crc is %d\n", crc);

+

+        if (crc != p_versions->crc)

+        {

+            printk("got bad crc\n");

+            break;

+        }

+

+        return (struct nv_cfg_info *)p_cfg_body;

+    }

+

+    printk("no valid protocal version found\n");

+

+    if (p_cfg_body != NULL)

+    {

+        kfree(p_cfg_body);

+    }

+    return NULL;

+}

+

+static int read_from_uboot_memory(unsigned char * buff)

+{

+    int len, total_read_cnt, min_read_cnt, zero_cnt, ret;

+    int * curr_pos;

+    struct lynq_nv_cfg_header * head = (struct lynq_nv_cfg_header *)buff;

+    curr_pos = (int*)buff;

+    *curr_pos = ioread32(MMC_LYNQ_NV_CFG_ADDR);

+    printk("read data is %08x\n", *curr_pos);

+    curr_pos++;

+    if (head->magic_flag != 0xaa55 || head->valid_flag != 1

+            || head->content_len > (MMC_LYNQ_NV_CFG_SIZE - sizeof(struct lynq_nv_cfg_header)*2))

+    {

+        printk("got bad header len %d\n",head->content_len);

+        printk("magic %04x-need %04x\n", head->magic_flag, 0xaa55);

+        return 0;

+    }

+    min_read_cnt = head->content_len + sizeof(struct lynq_nv_cfg_header) + sizeof (struct version_info) + sizeof(int);

+    if (min_read_cnt > MMC_LYNQ_NV_CFG_SIZE)

+    {

+        total_read_cnt = MMC_LYNQ_NV_CFG_SIZE;

+        min_read_cnt = MMC_LYNQ_NV_CFG_SIZE;

+    }

+

+    total_read_cnt = total_read_cnt / sizeof (int);

+    min_read_cnt = min_read_cnt / sizeof (int);

+

+    len = 1;

+    zero_cnt = 0;

+    while(len < total_read_cnt && zero_cnt < 4)

+    {

+        ret = ioread32(MMC_LYNQ_NV_CFG_ADDR + len * sizeof(int));

+        printk("read data %08x\n", ret);

+        *curr_pos++ = ret;

+        if (ret != 0) {

+            zero_cnt = 0;

+        }

+        else{

+            zero_cnt ++;

+        }

+        len ++;

+    }

+

+    return len * sizeof(int);

+}

+

+struct nv_cfg_info *get_ap_nv_cfg_info()

+{

+

+    int len;

+    unsigned char * buff;

+    struct nv_cfg_info * ret;

+    printk("enter get_ap_nv_cfg_info\n");

+    if (g_nv_cfg_info != NULL)

+        return g_nv_cfg_info;

+

+    printk("[%s] start init!\n", __func__);

+

+    ret = NULL;

+    buff = kzalloc(MMC_LYNQ_NV_CFG_SIZE, GFP_KERNEL);

+    printk("enter read_from_uboot_memory\n");

+    len = read_from_uboot_memory(buff);

+    if (len > 0)

+    {

+        printk("enter check cfg from uboot\n");

+        ret = get_valid_nv_cfg(buff, len);

+    }

+    // read default in head file

+    if (ret == NULL)

+    {

+        printk("enter check lynq_default_nv_cfg_value\n");

+        ret = get_valid_nv_cfg(lynq_default_nv_cfg_value, sizeof (lynq_default_nv_cfg_value));

+    }

+

+    // use local default values

+    if (ret == NULL){

+        printk("enter use local default values\n");

+        ret = (struct nv_cfg_info *)kzalloc(sizeof (struct nv_cfg_info), GFP_KERNEL);

+        memset(ret, 0, sizeof(struct nv_cfg_info));

+        ret->mmc0_enable = 1;

+        ret->mmc1_enable = 1;

+    }

+

+    g_nv_cfg_info = ret;

+

+    return ret;

+}

+

+#define DECLARE_NV_CFG_ATTR(name) \

+static ssize_t name##_show(struct device *dev, struct device_attribute *attr, char *buf) \

+{ \

+    return sprintf(buf, "%d", get_##name()); \

+}\

+\

+static DEVICE_ATTR(name, 0664, name##_show, NULL); \

+

+

+DECLARE_NV_CFG_ATTR(wifi_enable)

+DECLARE_NV_CFG_ATTR(rndis_ip_map)

+/*

+static struct attribute * lynq_nv_cfg_attrs[] = {

+    &dev_attr_wifi_enable.attr,

+    NULL,

+};

+

+static const struct attribute_group lynq_nv_cfg_attr_grp = {

+    .attrs = lynq_nv_cfg_attrs,

+};

+*/

+static struct class * lynq_nv_cfg_class;

+static struct class_device * lynq_nv_cfg_device;

+static int __init lynq_nv_cfg_init(void)

+{

+    printk("[%s] start init!\n", __func__);

+    lynq_nv_cfg_class =  class_create(THIS_MODULE, "lynq_nv_cfg");

+    if (lynq_nv_cfg_class == NULL)

+        return -1;

+    lynq_nv_cfg_device = device_create(lynq_nv_cfg_class, NULL, MKDEV(1,0), NULL, "cdev_lynq_nv_cfg");

+    if (lynq_nv_cfg_device == NULL)

+        return -1;

+    //sysfs_create_group(&lynq_nv_cfg_device->kobj, &lynq_nv_cfg_attr_grp);

+    device_create_file(lynq_nv_cfg_device, &dev_attr_wifi_enable);

+    device_create_file(lynq_nv_cfg_device, &dev_attr_rndis_ip_map);

+    return 0;

+}

+

+static void __exit lynq_nv_cfg_exit(void)

+{

+    printk("[%s] start exit!\n", __func__);

+    //platform_driver_unregister(&lynq_nv_cfg_device);

+}

+

+module_init(lynq_nv_cfg_init);

+module_exit(lynq_nv_cfg_exit);

diff --git a/ap/os/linux/linux-3.4.x/arch/arm/mach-zx297520v3/lynq_default_nv_cfg.h b/ap/os/linux/linux-3.4.x/arch/arm/mach-zx297520v3/lynq_default_nv_cfg.h
new file mode 100755
index 0000000..85ebb80
--- /dev/null
+++ b/ap/os/linux/linux-3.4.x/arch/arm/mach-zx297520v3/lynq_default_nv_cfg.h
@@ -0,0 +1,18 @@
+#ifndef LYNQ_DEFAULT_NV_CFG_H

+#define LYNQ_DEFAULT_NV_CFG_H

+

+static const char lynq_default_nv_cfg_value1[] = {

+    '\x55', '\xaa', '\x0b', '\x00', '\xff', '\xff', '\xff', '\xff', '\x00', '\xaa', '\x55', '\x0b', '\x00', '\x05', '\x10', '\x0c', '\x03'

+};

+

+static const char lynq_default_nv_cfg_value[] = {

+    '\x55', '\xaa', '\x09', '\x00', '\xc0', '\x80', '\x80', '\x00', '\xaa', '\x55', '\x09', '\x00', '\x05', '\x10', '\x0c', '\x03'

+};

+

+static const char lynq_nv_cfg_bitmap[] = {

+    '\xC0', '\x80', '\x80', '\x80'

+};

+

+static int lynq_default_soft_version = 1;

+

+#endif // LYNQ_DEFAULT_NV_CFG_H

diff --git a/ap/os/linux/linux-3.4.x/arch/arm/mach-zx297520v3/pwr_ctrl.c b/ap/os/linux/linux-3.4.x/arch/arm/mach-zx297520v3/pwr_ctrl.c
index e5ec161..0ba80af 100755
--- a/ap/os/linux/linux-3.4.x/arch/arm/mach-zx297520v3/pwr_ctrl.c
+++ b/ap/os/linux/linux-3.4.x/arch/arm/mach-zx297520v3/pwr_ctrl.c
@@ -29,6 +29,10 @@
 //++yuwei 20160719
 #include <mach/gpio_cfg.h>
 //++
+//youchen@2024-06-20 add for lynq nv config begin
+#include <lynq/lynq_ap_nv_cfg.h>
+//youchen@2024-06-20 add for lynq nv config end
+
 
 static unsigned int pwr_buck3v3_init_flag	= 0;
 static unsigned int pwr_buck3v3_status  		= 0;
@@ -287,7 +291,7 @@
 	   }
 
 	   // zw.wang The WiFi-related control pins gpio132 and gpio91 are still affected after the uboot removes mmc0 on 20240531 on start
-	   if ((ioread32(MMC_CFG_BASE) & (1 << 0)))
+	   if (get_mmc0_enable() == 1)
 	   {
 		   gpio_direction_output(ZX29_GPIO_132, 1);
 		   gpio_direction_output(ZX29_GPIO_91, 1);
diff --git a/ap/os/linux/linux-3.4.x/arch/arm/mach-zx297520v3/zx297520v3-mdl-devices.c b/ap/os/linux/linux-3.4.x/arch/arm/mach-zx297520v3/zx297520v3-mdl-devices.c
index 485d8f2..74cba0d 100755
--- a/ap/os/linux/linux-3.4.x/arch/arm/mach-zx297520v3/zx297520v3-mdl-devices.c
+++ b/ap/os/linux/linux-3.4.x/arch/arm/mach-zx297520v3/zx297520v3-mdl-devices.c
@@ -64,6 +64,9 @@
 #endif
 #include <mach/gpio_cfg.h>
 
+//youchen@2024-06-20 add for lynq nv config begin
+#include <lynq/lynq_ap_nv_cfg.h>
+//youchen@2024-06-20 add for lynq nv config end
 
 struct zx29_uart_platdata  zx29_uart0_platdata= {
 		.uart_use = 1,
@@ -1149,7 +1152,7 @@
 #endif
 
 #ifdef CONFIG_MMC_ZX29
-#if (defined _USE_VEHICLE_DC_REF)&&(defined _USE_VEHICLE_DC_REF_MMC0) //jb.qi add for wifi config on 20240221
+#if (defined _USE_VEHICLE_DC_REF) //jb.qi add for wifi config on 20240221
     &zx29_sdmmc0_device,
 #endif
     &zx29_sdmmc1_device,
@@ -1232,6 +1235,37 @@
 
 unsigned int zx29_device_table_num=ARRAY_SIZE(zx29_device_table);
 
+//youchen@2024-06-20 add for lynq nv config begin
+void modify_zx29_device_table()
+{
+#if (defined _USE_VEHICLE_DC_REF) 
+	int i, last;
+
+	last = 0;
+	for( i=0; i<zx29_device_table_num;i++ )
+	{
+		if (zx29_device_table[i] == &zx29_sdmmc0_device && get_mmc0_enable() == 0)
+		{
+			continue;
+		}
+		else if (zx29_device_table[i] == &zx29_sdmmc1_device && get_mmc1_enable() == 0)
+		{
+			continue;
+		}
+		else if (i != last)
+		{
+			zx29_device_table[last++] = zx29_device_table[i];
+		}
+		else
+		{
+			last++;
+		}
+	}
+	zx29_device_table_num -= (i - last);
+#endif
+}
+//youchen@2024-06-20 add for lynq nv config end
+
 #if (defined CONFIG_SPI_ZX29) || (defined CONFIG_SPI_GPIO)
 struct zx29_lcd_platform_data lead_lcd_platform = {
 	.spi_dcx_gpio = PIN_SPI_DCX,
diff --git a/ap/os/linux/linux-3.4.x/drivers/mmc/host/zx29_mmc-pltfm.c b/ap/os/linux/linux-3.4.x/drivers/mmc/host/zx29_mmc-pltfm.c
index 0cf0d7f..1100d88 100755
--- a/ap/os/linux/linux-3.4.x/drivers/mmc/host/zx29_mmc-pltfm.c
+++ b/ap/os/linux/linux-3.4.x/drivers/mmc/host/zx29_mmc-pltfm.c
@@ -44,6 +44,11 @@
 static struct dw_mci *dw_mci_host_ptr[2];
 volatile u8 mmc0_data1_flag = 0xff;
 //zw.wang The sdio0 pin is configured in gpio mode before and after wifi uninstallation on 20240521 on end
+
+//youchen@2024-06-20 add for lynq nv config begin
+#include <lynq/lynq_ap_nv_cfg.h>
+//youchen@2024-06-20 add for lynq nv config end
+
 static void dw_mci_rockchip_prepare_command(struct dw_mci *host, u32 *cmdr)
 {
 	*cmdr |= SDMMC_CMD_USE_HOLD_REG;
@@ -551,7 +556,8 @@
 #endif
 
 #ifdef _USE_VEHICLE_DC
-	if(ioread32(MMC_CFG_BASE)&(1<<pdev->id)){
+	//youchen@2024-06-20 add for lynq nv config
+	if((0 == pdev->id && get_mmc0_enable() == 1) || (1 == pdev->id && get_mmc1_enable() == 1)){
 		return dw_mci_pltfm_register(pdev, drv_data);
 	}else
 	{
diff --git a/ap/os/linux/linux-3.4.x/drivers/net/wireless/aic8800d80l/wifi_dev_aic88.c b/ap/os/linux/linux-3.4.x/drivers/net/wireless/aic8800d80l/wifi_dev_aic88.c
index a020bbc..18b3a9c 100755
--- a/ap/os/linux/linux-3.4.x/drivers/net/wireless/aic8800d80l/wifi_dev_aic88.c
+++ b/ap/os/linux/linux-3.4.x/drivers/net/wireless/aic8800d80l/wifi_dev_aic88.c
@@ -6,7 +6,7 @@
 #include <asm/uaccess.h>
 #include <linux/slab.h>
 //zw.wang The WiFi-related control pins gpio132 and gpio91 are still affected after the uboot removes mmc0 on 20240531 on start
-#include <mach/iomap.h>
+#include <lynq/lynq_ap_nv_cfg.h>
 //zw.wang The WiFi-related control pins gpio132 and gpio91 are still affected after the uboot removes mmc0 on 20240531 on end
 
 #define WIFI_IOCTL_STOP   0x0
@@ -51,7 +51,7 @@
 	int ret = 0;
 	void __user *argp = (void __user *) arg;
 	//zw.wang The WiFi-related control pins gpio132 and gpio91 are still affected after the uboot removes mmc0 on 20240531 on start
-	if(!(ioread32(MMC_CFG_BASE)&(1<<0)))
+	if(!get_mmc0_enable() || !get_wifi_enable())
         return -ENODEV;
 	//zw.wang The WiFi-related control pins gpio132 and gpio91 are still affected after the uboot removes mmc0 on 20240531 on end
 	switch (cmd) {
diff --git a/ap/os/linux/linux-3.4.x/drivers/usb/gadget/u_ether.c b/ap/os/linux/linux-3.4.x/drivers/usb/gadget/u_ether.c
index 5f9d709..16cf5dc 100755
--- a/ap/os/linux/linux-3.4.x/drivers/usb/gadget/u_ether.c
+++ b/ap/os/linux/linux-3.4.x/drivers/usb/gadget/u_ether.c
@@ -26,6 +26,10 @@
 #include "multi_packet.h"
 #include <mach/highspeed_debug.h>
 #include <linux/nvro_comm.h>
+//youchen@2024-06-20 add for lynq nv config begin
+#include <lynq/lynq_ap_nv_cfg.h>
+//youchen@2024-06-20 add for lynq nv config end
+
 /*
  * This component encapsulates the Ethernet link glue needed to provide
  * one (!) network link through the USB gadget stack, normally "usb0".
@@ -1007,6 +1011,13 @@
 	{0x34,0x4b,0x50,0x00,0x00,0x0a},
 	{0x34,0x4b,0x50,0x00,0x00,0x0b},
 	{0x34,0x4b,0x50,0x00,0x00,0x0c}};
+//youchen@2024-06-20 add for lynq nv config begin
+static u8 eth_addrs2[ETH_MAX_NUM][ETH_ALEN] = {
+	{0x3a,0x4b,0x50,0x00,0x00,0x00},
+	{0x34,0x4b,0x50,0x00,0x00,0x0a},
+	{0x34,0x4b,0x50,0x00,0x00,0x0b},
+	{0x34,0x4b,0x50,0x00,0x00,0x0c}};
+//youchen@2024-06-20 add for lynq nv config end
 #define NVUSB_MAC_LEN 6
 
 
@@ -1323,7 +1334,17 @@
     {
     	random_ether_addr(net->dev_addr);
 	usb_printk("random_ether_addr ok\n");
-	host_addr = &eth_addrs[num][0];
+	//youchen@2024-06-20 add for lynq nv config begin
+	if (get_rndis_mac_convert() == 1)
+	{
+		host_addr = &eth_addrs2[num][0];
+		printk("rndis_mac_convert finish\n");
+	}
+	else
+	{
+		host_addr = &eth_addrs[num][0];
+	}
+	//youchen@2024-06-20 add for lynq nv config end
 	memcpy(dev->host_mac, host_addr, ETH_ALEN);
 
 	if (ethaddr)
diff --git a/ap/os/linux/linux-3.4.x/include/lynq/lynq_ap_nv_cfg.h b/ap/os/linux/linux-3.4.x/include/lynq/lynq_ap_nv_cfg.h
new file mode 100755
index 0000000..e13fb05
--- /dev/null
+++ b/ap/os/linux/linux-3.4.x/include/lynq/lynq_ap_nv_cfg.h
@@ -0,0 +1,61 @@
+#ifndef LYNQ_AP_NV_CFG_H

+#define LYNQ_AP_NV_CFG_H

+

+#pragma pack(1)

+struct lynq_nv_cfg_header

+{

+    unsigned short magic_flag;

+    unsigned short valid_flag:1;

+    unsigned short content_len:15;

+};

+struct nv_cfg_info{

+    unsigned char reserved_0:6;

+    unsigned char mmc1_enable:1;

+    unsigned char mmc0_enable:1;

+    unsigned char reserved_1:7;

+    unsigned char wifi_enable:1;

+    unsigned char reserved_2:7;

+    unsigned char rndis_mac_convert:1;

+    unsigned char reserved_3:7;

+    unsigned char rndis_ip_map:1;

+};

+

+struct version_info{

+    unsigned short soft_ver:12;

+    unsigned short hard_ver:4;

+    unsigned short crc;

+};

+

+struct lynq_nv_cfg

+{

+    struct lynq_nv_cfg_header head;

+    struct nv_cfg_info content;

+    struct lynq_nv_cfg_header tail;

+    struct version_info versions[0];

+};

+

+#pragma pack()

+

+extern struct nv_cfg_info *get_ap_nv_cfg_info();

+

+static inline int get_mmc0_enable() {

+    return get_ap_nv_cfg_info()->mmc0_enable;

+}

+

+static inline int get_mmc1_enable() {

+    return get_ap_nv_cfg_info()->mmc1_enable;

+}

+

+static inline int get_wifi_enable() {

+    return get_ap_nv_cfg_info()->wifi_enable;

+}

+

+static inline int get_rndis_mac_convert() {

+    return get_ap_nv_cfg_info()->rndis_mac_convert;

+}

+

+static inline int get_rndis_ip_map() {

+    return get_ap_nv_cfg_info()->rndis_ip_map;

+}

+

+#endif // LYNQ_AP_NV_CFG_H