Skip to content
This repository has been archived by the owner on Oct 13, 2022. It is now read-only.

Commit

Permalink
Allow to upload in web failsafe mode U-Boot images which are not mult…
Browse files Browse the repository at this point in the history
…iple 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.
  • Loading branch information
pepe2k committed Apr 27, 2015
1 parent 056fbad commit d492125
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 8 deletions.
6 changes: 4 additions & 2 deletions u-boot/httpd/httpd.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
33 changes: 27 additions & 6 deletions u-boot/net/httpd.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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){

Expand Down

0 comments on commit d492125

Please sign in to comment.