2 * Copyright 1994, 1995, 2000 Neil Russell.
4 * Copyright 2000, 2001 DENX Software Engineering, Wolfgang Denk, wd@denx.de
10 #include <asm/byteorder.h>
12 #if defined(CONFIG_CMD_HTTPD)
15 #include "../httpd/uipopt.h"
16 #include "../httpd/uip.h"
17 #include "../httpd/uip_arp.h"
19 extern flash_info_t flash_info[];
21 static int arptimer = 0;
23 void HttpdHandler(void){
26 for(i = 0; i < UIP_CONNS; i++){
42 void HttpdStart(void){
47 int do_http_upgrade(const ulong size, const int upgrade_type){
48 char buf[96]; // erase 0xXXXXXXXX +0xXXXXXXXX; cp.b 0xXXXXXXXX 0xXXXXXXXX 0xXXXXXXXX (68 signs)
49 flash_info_t *info = &flash_info[0];
50 unsigned int backup_size = 0;
52 if(upgrade_type == WEBFAILSAFE_UPGRADE_TYPE_UBOOT){
54 while(size > backup_size){
55 backup_size += info->sector_size;
58 // Backup data from FLASH just before U-Boot image upgrade
59 // if uploaded image size is not a multiple of FLASH erase sector size (by default 64 KB)
60 if(size % info->sector_size != 0){
61 printf("Backup: copying %d bytes of data from FLASH at address 0x%X to RAM at address 0x%X...\n",
63 CFG_FLASH_BASE + size,
64 CONFIG_LOADADDR + size);
67 "cp.b 0x%lX 0x%lX 0x%lX",
68 CFG_FLASH_BASE + size,
69 CONFIG_LOADADDR + size,
72 if(!run_command(buf, 0)){
73 printf_err("couldn't backup FLASH data before U-Boot image upgrade!\n");
78 printf("\n\n****************************\n* U-BOOT UPGRADING *\n* DO NOT POWER OFF DEVICE! *\n****************************\n\n");
80 "erase 0x%lX +0x%lX; cp.b 0x%lX 0x%lX 0x%lX",
87 } else if(upgrade_type == WEBFAILSAFE_UPGRADE_TYPE_FIRMWARE){
89 printf("\n\n****************************\n* FIRMWARE UPGRADING *\n* DO NOT POWER OFF DEVICE! *\n****************************\n\n");
91 "erase 0x%lX +0x%lX; cp.b 0x%lX 0x%lX 0x%lX",
92 WEBFAILSAFE_UPLOAD_KERNEL_ADDRESS,
95 WEBFAILSAFE_UPLOAD_KERNEL_ADDRESS,
98 } else if(upgrade_type == WEBFAILSAFE_UPGRADE_TYPE_ART){
100 // TODO: add option to change ART partition offset,
101 // for those who want to use OFW on router with replaced/bigger FLASH
102 printf("\n\n****************************\n* ART UPGRADING *\n* DO NOT POWER OFF DEVICE! *\n****************************\n\n");
103 #if defined(WEBFAILSAFE_UPLOAD_ART_ADDRESS)
105 "erase 0x%lX +0x%lX; cp.b 0x%lX 0x%lX 0x%lX",
106 WEBFAILSAFE_UPLOAD_ART_ADDRESS,
107 WEBFAILSAFE_UPLOAD_ART_SIZE_IN_BYTES,
109 WEBFAILSAFE_UPLOAD_ART_ADDRESS,
110 WEBFAILSAFE_UPLOAD_ART_SIZE_IN_BYTES);
113 "erase 0x%lX +0x%lX; cp.b 0x%lX 0x%lX 0x%lX",
114 CFG_FLASH_BASE + (info->size - WEBFAILSAFE_UPLOAD_ART_SIZE_IN_BYTES),
115 WEBFAILSAFE_UPLOAD_ART_SIZE_IN_BYTES,
117 CFG_FLASH_BASE + (info->size - WEBFAILSAFE_UPLOAD_ART_SIZE_IN_BYTES),
118 WEBFAILSAFE_UPLOAD_ART_SIZE_IN_BYTES);
125 printf("Executing: %s\n\n", buf);
126 return(run_command(buf, 0));
131 // info about current progress of failsafe mode
132 int do_http_progress(const int state){
135 /* toggle LED's here */
137 case WEBFAILSAFE_PROGRESS_START:
139 // blink LED fast 10 times
140 for(i = 0; i < 10; ++i){
147 printf("HTTP server is ready!\n\n");
150 case WEBFAILSAFE_PROGRESS_TIMEOUT:
151 //printf("Waiting for request...\n");
154 case WEBFAILSAFE_PROGRESS_UPLOAD_READY:
155 printf("HTTP upload is done! Upgrading...\n");
158 case WEBFAILSAFE_PROGRESS_UPGRADE_READY:
159 printf("HTTP ugrade is done! Rebooting...\n\n");
162 case WEBFAILSAFE_PROGRESS_UPGRADE_FAILED:
163 printf_err("HTTP ugrade failed!\n\n");
165 // blink LED fast for 4 sec
166 for(i = 0; i < 80; ++i){
181 #endif /* CONFIG_CMD_HTTPD */