Browse Source

add authority check while update ddrinit bin file

yanhong.wang 3 years ago
parent
commit
5aea32f898
3 changed files with 99 additions and 6 deletions
  1. 93 0
      boot/bootmain.c
  2. 1 1
      common/sys.h
  3. 5 5
      uart/uart.c

+ 93 - 0
boot/bootmain.c

@@ -232,6 +232,96 @@ static int updata_flash_code(struct spi_flash* spi_flash,unsigned int updata_num
     return ret;
 }
 
+static int prog_2ndboot(struct spi_flash *flash, int mode)
+{
+    updata_flash_code(flash, 0, mode);
+    return 0;
+}
+
+static int prog_ddrinit(struct spi_flash *flash, int mode)
+{
+    updata_flash_code(flash, 1, mode);
+    return 0;
+}
+
+static int prog_uboot(struct spi_flash *flash, int mode)
+{
+    updata_flash_code(flash, 2, mode);
+    return 0;
+}
+
+typedef struct
+{
+    const char *text;
+    int (*prog_op)(struct spi_flash *, int);
+} prog_menu_t;
+
+static int prog_menu(struct spi_flash *flash, int mode, const prog_menu_t *menu, int count)
+{
+    int i, sel;
+    char buff[32]={0};
+    char *str = NULL, *str_end = NULL;
+    const char *ROOT_MENU_KEY = "root@s5t";
+    
+    while (1) {
+        printk("\n");
+        for (i = 0; i < count; i++) {
+            printk("%d:%s\n", i, menu[i].text);
+        }
+        printk("%d:quit\n", count);
+        printk("select the function: ");
+        serial_gets(buff);
+        str = buff;
+        while (*str == '\n' || *str == ' ') {
+            //skip white
+            str++;
+        }
+
+        if (strcmp(str, ROOT_MENU_KEY) == 0) {
+            //request root menu
+            return 1;
+        }
+        sel = (int)strtol(str, &str_end, 10);
+        if (str == str_end || sel < 0 || sel > count) {
+            //invalid sel
+            continue;
+        }
+        if (sel == count) {
+            //quit
+            printk("\nquit\n");
+            return 0;
+        }
+        if (menu[sel].prog_op) {
+            menu[sel].prog_op(flash, mode);
+        }
+    }
+    return 0;
+}
+
+static void prog_flash(void)
+{
+    prog_menu_t user_menu[] = {
+        { "update uboot",           prog_uboot   },
+    };
+    prog_menu_t root_menu[] = {
+        { "update second boot",     prog_2ndboot },
+        { "update ddr init boot",   prog_ddrinit },
+        { "update uboot",           prog_uboot   },
+    };
+    struct spi_flash *flash = NULL;
+    unsigned char mode = 1;// or 4
+
+    cadence_qspi_init(0, mode);
+    flash = spi_flash_probe(0, 0, 31250000, 0, (u32)SPI_DATAMODE_8);
+
+    printk("\n***************************************************\n");
+    printk("*************** FLASH PROGRAMMING *****************\n");
+    printk("***************************************************\n");
+    if (prog_menu(flash, mode, &user_menu, sizeof(user_menu)/sizeof(user_menu[0]))) {
+        prog_menu(flash, mode, &root_menu, ARRAY_SIZE(root_menu));
+    }
+}
+
 void boot_from_chiplink(void)
 {
 	int bootdelay = 3;
@@ -264,6 +354,8 @@ void boot_from_chiplink(void)
 	
 	if(1 == abort)
 	{
+		prog_flash();
+#if 0
 		cadence_qspi_init(0, mode);
 		spi_flash = spi_flash_probe(0, 0, 31250000, 0, (u32)SPI_DATAMODE_8);
 		
@@ -303,6 +395,7 @@ again:
 			printk("updata success\r\n");
 
 		goto again;
+#endif
 	}
 }
 

+ 1 - 1
common/sys.h

@@ -107,7 +107,7 @@
 #define FLASH_DDRINIT_START_ADDR        0x10000
 #define FLASH_DDRINIT_SIZE_LIMIT        (192*1024)
 #define FLASH_UBOOT_START_ADDR          0x40000
-#define FLASH_UBOOT_SIZE_LIMIT          (896*1024)
+#define FLASH_UBOOT_SIZE_LIMIT          (3*1024*1024)
 
 #define DEFAULT_UBOOT_LOAD_ADDR  DEFAULT_UBOOT_ADDR
 #define DEFAULT_SECONDBOOT_LOAD_ADDR	0x180a8000 /*32k*/

+ 5 - 5
uart/uart.c

@@ -177,15 +177,15 @@ int serial_getc()
 
 void serial_gets(char *pstr)
 {
-	unsigned char c;
-	unsigned char *pstrorg;
+	char c;
+	char *pstrorg;
 	
-	pstrorg = (unsigned char *) pstr;
+	pstrorg = (char *) pstr;
 
-	while ((c = serial_getc()) != '\r')
+	while ((c = (char)serial_getc()) != '\r')
 	{
 		if (c == '\b'){
-			if ((int) *pstrorg < (int) *pstr){
+			if (pstrorg < pstr){
 				rlSendString("\b \b");
 				pstr--;
 			}