From d4921257c321c9ba7929d34221167f2221b59034 Mon Sep 17 00:00:00 2001 From: Piotr Dymacz Date: Mon, 27 Apr 2015 19:38:23 +0200 Subject: [PATCH] Allow to upload in web failsafe mode U-Boot images which are not multiple of FLASH erase sector size (like Nx64KB). Backup data from FLASH before U-Boot upgrade - that will allow to extend U-Boot image size on all TP-Link devices. --- u-boot/httpd/httpd.c | 6 ++++-- u-boot/net/httpd.c | 33 +++++++++++++++++++++++++++------ 2 files changed, 31 insertions(+), 8 deletions(-) diff --git a/u-boot/httpd/httpd.c b/u-boot/httpd/httpd.c index 3fac374..082a646 100644 --- a/u-boot/httpd/httpd.c +++ b/u-boot/httpd/httpd.c @@ -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 { diff --git a/u-boot/net/httpd.c b/u-boot/net/httpd.c index 1815082..c4b7e4f 100644 --- a/u-boot/net/httpd.c +++ b/u-boot/net/httpd.c @@ -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){ -- 2.25.1