Эх сурвалжийг харах

[Add][Uboot / Modularization][Module_Upgrade]

2022.01.18 / Folus Wen

Actions:
1. Uboot implement mount secondary image block(dts, kernel, rootfs) if last upgrade fail.
2. Module_Upgrade implement upgrade flag mark function when upgrade flash block(dts, kernel, rootfs).

Files:
1. As follow commit history

Image version: D0.00.XX.XXXX.XX
Image checksum: XXXXXXXX

Hardware PWB P/N : XXXXXXX
Hardware Version : XXXXXXX
FolusWen 3 жил өмнө
parent
commit
279d96c1b6

+ 55 - 2
EVSE/Modularization/Module_Upgrade.c

@@ -21,8 +21,11 @@
 #define FAIL                -1
 #define	YES					1
 #define	NO					0
+#define	ON					1
+#define	OFF					0
 #define HEADER_LENGTH		48
 
+
 struct SysConfigAndInfo         *ShmSysConfigAndInfo;
 struct StatusCodeData           *ShmStatusCodeData;
 struct FanModuleData            *ShmFanModuleData;
@@ -122,6 +125,52 @@ int runShellCmd(const char*cmd)
 	return result;
 }
 
+int config_upgrade_flag(unsigned int upgradeFlag, unsigned char isSetFlag)
+{
+	int result = FAIL;
+	int fd;
+	unsigned char envFlash[512*1024];
+	system("rm -f /tmp/envFlash");
+	DEBUG_INFO("Read /dev/mtd2.\n");
+	runShellCmd("nanddump -s 0x0 -l 0x80000 -f /tmp/envFlash /dev/mtd2");
+
+    fd = open("/tmp/envFlash", O_RDWR);
+    if(fd < 0)
+    {
+        DEBUG_ERROR("Open envFlash NG.\n");
+    }
+    else
+    {
+		read(fd,envFlash,ARRAY_SIZE(envFlash));
+		close(fd);
+		system("rm -f /tmp/envFlash");
+
+		envFlash[upgradeFlag] = (isSetFlag?0x00:0xff);
+
+		fd = open("/tmp/envFlash", O_RDWR | O_CREAT | O_EXCL);
+		if(fd < 0)
+		{
+			DEBUG_ERROR("Open envFlash NG.\n");
+		}
+		else
+		{
+			write(fd,envFlash,ARRAY_SIZE(envFlash));
+			close(fd);
+
+			DEBUG_INFO("Erase /dev/mtd2.\n");
+			runShellCmd("flash_erase /dev/mtd2 0 0");
+
+			DEBUG_INFO("Write /dev/mtd2.\n");
+			runShellCmd("nandwrite -p /dev/mtd2 /tmp/envFlash");
+
+			system("rm -f /tmp/envFlash");
+			result = PASS;
+		}
+    }
+
+	return result;
+}
+
 int Upgrade_Flash(unsigned int Type,char *SourcePath,char *ModelName)
 {
     int result = FAIL;
@@ -309,15 +358,15 @@ int Upgrade_Flash(unsigned int Type,char *SourcePath,char *ModelName)
                                 }
                                 else
                                 {
+                                	config_upgrade_flag(UPGRADE_FLAG_DTS, ON);
                                     DEBUG_INFO("Erase /dev/mtd4.\n");
                                     runShellCmd("flash_erase /dev/mtd4 0 0");
-
 									DEBUG_INFO("Write /dev/mtd4.\n");
 									runShellCmd("nandwrite -p /dev/mtd4 /mnt/imgBuffer");
+									config_upgrade_flag(UPGRADE_FLAG_DTS, OFF);
 
 									DEBUG_INFO("Erase /dev/mtd5.\n");
 									runShellCmd("flash_erase /dev/mtd5 0 0");
-
 									DEBUG_INFO("Write /dev/mtd5.\n");
 									runShellCmd("nandwrite -p /dev/mtd5 /mnt/imgBuffer");
 
@@ -346,10 +395,12 @@ int Upgrade_Flash(unsigned int Type,char *SourcePath,char *ModelName)
                                 }
                                 else
                                 {
+                                	config_upgrade_flag(UPGRADE_FLAG_KERNEL, ON);
                                 	DEBUG_INFO("Erase /dev/mtd6.\n");
                                 	runShellCmd("flash_erase /dev/mtd6 0 0");
 									DEBUG_INFO("Write /dev/mtd6.\n");
 									runShellCmd("nandwrite -p /dev/mtd6 /mnt/imgBuffer");
+									config_upgrade_flag(UPGRADE_FLAG_KERNEL, OFF);
 
 									DEBUG_INFO("Erase /dev/mtd7.\n");
 									runShellCmd("flash_erase /dev/mtd7 0 0");
@@ -380,10 +431,12 @@ int Upgrade_Flash(unsigned int Type,char *SourcePath,char *ModelName)
                                 }
                                 else
                                 {
+                                	config_upgrade_flag(UPGRADE_FLAG_ROOTFS, ON);
                                 	DEBUG_INFO("Erase /dev/mtd8.\n");
                                 	runShellCmd("flash_erase /dev/mtd8 0 0");
                                 	DEBUG_INFO("Write /dev/mtd8.\n");
                                 	runShellCmd("nandwrite -p /dev/mtd8 /mnt/imgBuffer");
+                                	config_upgrade_flag(UPGRADE_FLAG_ROOTFS, OFF);
 
                                 	DEBUG_INFO("Erase /dev/mtd9.\n");
                                 	runShellCmd("flash_erase /dev/mtd9 0 0");

+ 6 - 0
EVSE/Modularization/Module_Upgrade.h

@@ -98,6 +98,12 @@ enum Uart_Command
     UART_CMD_UPDATE_FINISH                      = 0xe3,
 };
 
+enum Upgrade_Flag
+{
+	UPGRADE_FLAG_DTS							= 0x7fffd,
+	UPGRADE_FLAG_KERNEL							= 0x7fffe,
+	UPGRADE_FLAG_ROOTFS							= 0x7ffff
+};
 
 int Upgrade_Flash(unsigned int Type,char *SourcePath,char *ModelName);
 int Upgrade_UART(int uartfdOrd,unsigned int Type,unsigned char TargetAddr,char *SourcePath,char *ModelName);

+ 36 - 9
board-support/u-boot-2017.01+gitAUTOINC+340fb36f04-g340fb36f04/common/autoboot.c

@@ -19,27 +19,27 @@ DECLARE_GLOBAL_DATA_PTR;
 
 #if defined(MT29F16G08_BCH16)
 	#if defined(MT41K256M16HA125E_303)
-		#define uboot_version "02.04"
+		#define uboot_version "02.06"
 	#elif defined(MT41K256M16HA125E_400)
-		#define uboot_version "02.03"
+		#define uboot_version "02.05"
 	#else
-		#define uboot_version "02.04"
+		#define uboot_version "02.06"
 	#endif
 #elif defined(MT29F8G08_BCH16)
 	#if defined(MT41K256M16HA125E_303)
-		#define uboot_version "03.04"
+		#define uboot_version "03.06"
 	#elif defined(MT41K256M16HA125E_400)
-		#define uboot_version "03.03"
+		#define uboot_version "03.05"
 	#else
-		#define uboot_version "03.04"
+		#define uboot_version "03.06"
 	#endif
 #else
 	#if defined(MT41K256M16HA125E_303)
-		#define uboot_version "01.04"
+		#define uboot_version "01.06"
 	#elif defined(MT41K256M16HA125E_400)
-		#define uboot_version "01.03"
+		#define uboot_version "01.05"
 	#else
-		#define uboot_version "01.04"
+		#define uboot_version "01.06"
 	#endif
 #endif
 
@@ -397,6 +397,33 @@ void autoboot_command(const char *s)
 	                memcpy(BufTmp+(0x00600000-4),&Chk,4);
                 	run_command_list("nand erase 0x09000000 0x00600000", -1, 0);
         	        run_command_list("nand write 0x80000000 0x09000000 0x00600000", -1, 0);
+
+			// Valid dts, kernel and rootfs upgrade flag
+			char nandbootStr[256];
+			uint32_t addrDts=0x00300000;
+			uint32_t addrKernel=0x00400000;
+			uint32_t addrRootfs=0x03000000;
+
+			memset(BufTmp,0,0x80000);
+			run_command_list("nand read 0x80000000 0x00180000 0x00080000", -1, 0);
+
+			if(*(BufTmp+0x7fffd) != 0xff)
+                        {
+                                addrDts=0x00380000;
+                        }
+
+			if(*(BufTmp+0x7fffe) != 0xff)
+                        {
+                                addrKernel=0x00e00000;
+                        }
+
+			if(*(BufTmp+0x7ffff) != 0xff)
+			{
+				addrRootfs=0x06000000;
+			}
+
+			sprintf(nandbootStr, "setenv nandboot 'nand read 0x80F80000 0x%08X 0x00080000;nand read 0x85200000 0x%08X 0x00A00000;nand read 0x81000000 0x%08X 0x03000000;bootz 0x85200000 - 0x80F80000'", addrDts, addrKernel, addrRootfs);
+			run_command_list(nandbootStr, -1, 0);
 	        }
 
 		run_command_list(s, -1, 0);