Browse Source

add control load .bin

balbekova 7 years ago
parent
commit
5712bbd015
3 changed files with 61 additions and 6 deletions
  1. 45 4
      iap/Modules/Ethernet/httpserver.c
  2. 13 2
      modules/startup/stm32_flash.ld
  3. 3 0
      user/main.c

+ 45 - 4
iap/Modules/Ethernet/httpserver.c

@@ -33,6 +33,7 @@ static __IO u8 resetpage=0;
 static uint32_t ContentLengthOffset =0,BrowserFlag=0;
 static __IO uint32_t TotalData=0, checklogin=0;
 static bool fEraseFlash = true;
+static bool hw_validated = false;
 
 static uint8_t reqCounter = 0;
 static uint8_t reqTimer = 0;
@@ -279,10 +280,10 @@ static err_t http_recv(void *arg, struct tcp_pcb *pcb,  struct pbuf *p, err_t er
       /* process POST request for file upload and incoming data packets after POST request*/
       else if ((strncmp(data, "POST /upload.cgi",16) == 0) || (DataFlag >= 1))
       {
-		if (fEraseFlash) {
+		/*if (fEraseFlash) {
 		  FLASH_If_Erase(USER_FLASH_FIRST_PAGE_ADDRESS);
 		  fEraseFlash = false;
-		}
+		}*/
 
         DataOffset = 0;
         
@@ -362,6 +363,9 @@ static err_t http_recv(void *arg, struct tcp_pcb *pcb,  struct pbuf *p, err_t er
              filename[i] = 0x0;
            }
            
+           /* Set HW revision validation marker */
+               hw_validated = false;
+
            if (i==0)
            {
              htmlpage = FileUploadPage;
@@ -389,11 +393,11 @@ static err_t http_recv(void *arg, struct tcp_pcb *pcb,  struct pbuf *p, err_t er
           
            TotalData =0 ;
            /* init flash */
-           FLASH_If_Init();
+         ///  FLASH_If_Init();
            /* erase user flash area */
            //FLASH_If_Erase(USER_FLASH_FIRST_PAGE_ADDRESS);
 
-           FlashWriteAddress = USER_FLASH_FIRST_PAGE_ADDRESS;
+         // / FlashWriteAddress = USER_FLASH_FIRST_PAGE_ADDRESS;
           
            /*indicate start of flash programming */
            PRINT_USART("\n\rState: Programming..\n\r");
@@ -448,6 +452,8 @@ static err_t http_recv(void *arg, struct tcp_pcb *pcb,  struct pbuf *p, err_t er
 
 		   else
 		   {
+			 FLASH_If_Erase(USER_FLASH_FIRST_PAGE_ADDRESS);
+			 fEraseFlash = false;
 		     fs_open("/error.html", &file);
              hs->file = file.data;
              hs->left = file.len;
@@ -469,6 +475,41 @@ static err_t http_recv(void *arg, struct tcp_pcb *pcb,  struct pbuf *p, err_t er
         /* not last data packet */
         else
         {
+        	if ((TotalData >= HW_REV_OFFSET + HW_REV_LEN) && (!hw_validated)) {
+			  char rev[HW_REV_LEN];
+
+			  strncpy(rev, HW_REV, HW_REV_LEN);
+
+			  if (strcmp((char *)(ptr + HW_REV_OFFSET), rev) != 0) {
+
+
+				  DataFlag = 0;
+
+				 fs_open("/error.html", &file);
+				 hs->file = file.data;
+				 hs->left = file.len;
+				 send_data(pcb, hs);
+				 tcp_sent(pcb, http_sent);
+				 htmlpage = UploadErrorPage;
+				// fErrorReset = 1;
+				 pbuf_free(p);
+				 //close_conn(pcb, hs);
+
+				  return ERR_OK;
+			  }
+			  else {
+				  hw_validated = true;
+
+				   // Erase flash
+				   if (fEraseFlash) {
+					  FLASH_If_Erase(USER_FLASH_FIRST_PAGE_ADDRESS);
+					  fEraseFlash = false;
+				   }
+				  // Init flash
+				  FLASH_If_Init();
+				  FlashWriteAddress = USER_FLASH_FIRST_PAGE_ADDRESS;
+			  }
+		  }
           /* write data in flash */
           if(len)
             IAP_HTTP_writedata(ptr,len);

+ 13 - 2
modules/startup/stm32_flash.ld

@@ -46,7 +46,9 @@ MEMORY
   SETTINGS      (rx) : ORIGIN = 0x08004000, LENGTH = 16K
   SETTINGS_SYS  (rx) : ORIGIN = 0x08008000, LENGTH = 16K
   BOOTLOADER    (rx) : ORIGIN = 0x0800C000, LENGTH = 80K
-  FLASH         (rx) : ORIGIN = 0x08020000, LENGTH = 384K
+  VECTOR        (rx) : ORIGIN = 0x08020000, LENGTH = 496
+  HWREV         (rx) : ORIGIN = 0x080201F0, LENGTH = 16
+  FLASH         (rx) : ORIGIN = 0x08020200, LENGTH = 384K - 512
   CRC           (rx) : ORIGIN = 0x0807FFFC, LENGTH = 4
   RAM           (xrw) : ORIGIN = 0x20000000, LENGTH = 128K
   MEMORY_B1     (rx) : ORIGIN = 0x10000000, LENGTH = 64K
@@ -61,7 +63,16 @@ SECTIONS
     . = ALIGN(4);
     KEEP(*(.isr_vector)) /* Startup code */
     . = ALIGN(4);
-  } >FLASH
+  } >VECTOR
+  
+  /* The HWREV section contains hardware revision 
+   * number for binary validation in bootloader */
+  .hw_rev :
+  {
+    . = ALIGN(4);
+    KEEP(*(.hw_rev)) /* Startup code */
+    . = ALIGN(4);
+  } >HWREV
 
   /* The program code and other data goes into FLASH */
   .text :

+ 3 - 0
user/main.c

@@ -2,6 +2,7 @@
 #include "wdg.h"
 #include "FreeRTOS.h"
 #include "task.h"
+#include "common_config.h"
 
 #include "gpio.h"
 
@@ -19,6 +20,8 @@ uint8_t ucHeap[ configTOTAL_HEAP_SIZE ];
 uint8_t ucHeap[ configTOTAL_HEAP_SIZE ] __attribute__ ((section (".mb1text")));
 /* Секция размещения СRC прошивки */
 uint32_t crc __attribute__ ((section (".crc"))) = 0xAABBCCDD;
+/* Секция размещения HW ревизии платы */
+char hw_rev[HW_REV_LEN] __attribute__ ((section (".hw_rev"))) = HW_REV;
 #endif