Allow to upload in web failsafe mode U-Boot images which are not multiple of FLASH...
authorPiotr Dymacz <pepe2k@gmail.com>
Mon, 27 Apr 2015 17:38:23 +0000 (19:38 +0200)
committerPiotr Dymacz <pepe2k@gmail.com>
Mon, 27 Apr 2015 17:38:23 +0000 (19:38 +0200)
u-boot/httpd/httpd.c
u-boot/net/httpd.c

index 3fac3745fa079f637cd7da9dedf967c5b7041464..082a646b8f3cd156d8dcd9e9a51dadf768e0ae15 100644 (file)
@@ -193,9 +193,9 @@ static int httpd_findandstore_firstchunk(void){
                                // has correct size (for every type of upgrade)
 
                                // U-Boot
-                               if((webfailsafe_upgrade_type == WEBFAILSAFE_UPGRADE_TYPE_UBOOT) && (hs->upload_total != WEBFAILSAFE_UPLOAD_UBOOT_SIZE_IN_BYTES)){
+                               if((webfailsafe_upgrade_type == WEBFAILSAFE_UPGRADE_TYPE_UBOOT) && (hs->upload_total > WEBFAILSAFE_UPLOAD_UBOOT_SIZE_IN_BYTES)){
 
-                                       printf("## Error: wrong file size, should be: %d bytes!\n", WEBFAILSAFE_UPLOAD_UBOOT_SIZE_IN_BYTES);
+                                       printf("## Error: file too big!\n");
                                        webfailsafe_upload_failed = 1;
 
                                // ART
@@ -466,6 +466,8 @@ void httpd_appcall(void){
                                                printf("Data will be downloaded at 0x%X in RAM\n", WEBFAILSAFE_UPLOAD_RAM_ADDRESS);
                                        }
 
+                                       memset((void *)webfailsafe_data_pointer, 0xFF, WEBFAILSAFE_UPLOAD_UBOOT_SIZE_IN_BYTES);
+
                                        if(httpd_findandstore_firstchunk()){
                                                data_start_found = 1;
                                        } else {
index 18150826195d799a7447139634f6e47704fe79c1..c4b7e4f74350b31d5786b6e4209191f47bbbc9ad 100644 (file)
@@ -14,9 +14,7 @@
 #include "../httpd/uip.h"
 #include "../httpd/uip_arp.h"
 
-#if !defined(WEBFAILSAFE_UPLOAD_ART_ADDRESS)
 extern flash_info_t flash_info[];
-#endif
 
 static int arptimer = 0;
 
@@ -46,20 +44,43 @@ void HttpdStart(void){
 
 int do_http_upgrade(const ulong size, const int upgrade_type){
        char buf[96];   // erase 0xXXXXXXXX +0xXXXXXXXX; cp.b 0xXXXXXXXX 0xXXXXXXXX 0xXXXXXXXX (68 signs)
-#if !defined(WEBFAILSAFE_UPLOAD_ART_ADDRESS)
        flash_info_t *info = &flash_info[0];
-#endif
+       unsigned int backup_size = 0;
 
        if(upgrade_type == WEBFAILSAFE_UPGRADE_TYPE_UBOOT){
 
+               while(size > backup_size){
+                       backup_size += info->sector_size;
+               }
+
+               // Backup data from FLASH just before U-Boot image upgrade
+               // if uploaded image size is not a multiple of FLASH erase sector size (by default 64 KB)
+               if(size % info->sector_size != 0){
+                       printf("Backup: copying %d bytes of data from FLASH at address 0x%X to RAM at address 0x%X...\n",
+                                       backup_size - size,
+                                       WEBFAILSAFE_UPLOAD_UBOOT_ADDRESS + size,
+                                       WEBFAILSAFE_UPLOAD_RAM_ADDRESS + size);
+
+                       sprintf(buf,
+                                       "cp.b 0x%lX 0x%lX 0x%lX",
+                                       WEBFAILSAFE_UPLOAD_UBOOT_ADDRESS + size,
+                                       WEBFAILSAFE_UPLOAD_RAM_ADDRESS + size,
+                                       backup_size - size);
+
+                       if(!run_command(buf, 0)){
+                               printf("## Error: couldn't backup FLASH data before U-Boot image upgrade!\n");
+                               return(-1);
+                       }
+               }
+
                printf("\n\n****************************\n*     U-BOOT UPGRADING     *\n* DO NOT POWER OFF DEVICE! *\n****************************\n\n");
                sprintf(buf,
                                "erase 0x%lX +0x%lX; cp.b 0x%lX 0x%lX 0x%lX",
                                WEBFAILSAFE_UPLOAD_UBOOT_ADDRESS,
-                               WEBFAILSAFE_UPLOAD_UBOOT_SIZE_IN_BYTES,
+                               backup_size,
                                WEBFAILSAFE_UPLOAD_RAM_ADDRESS,
                                WEBFAILSAFE_UPLOAD_UBOOT_ADDRESS,
-                               WEBFAILSAFE_UPLOAD_UBOOT_SIZE_IN_BYTES);
+                               backup_size);
 
        } else if(upgrade_type == WEBFAILSAFE_UPGRADE_TYPE_FIRMWARE){