2 * Copyright 1994, 1995, 2000 Neil Russell.
4 * Copyright 2000, 2001 DENX Software Engineering, Wolfgang Denk, wd@denx.de
10 #include <asm/byteorder.h>
13 #include "../httpd/uipopt.h"
14 #include "../httpd/uip.h"
15 #include "../httpd/uip_arp.h"
17 #if !defined(WEBFAILSAFE_UPLOAD_ART_ADDRESS)
18 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 #if !defined(WEBFAILSAFE_UPLOAD_ART_ADDRESS)
50 flash_info_t *info = &flash_info[0];
53 if(upgrade_type == WEBFAILSAFE_UPGRADE_TYPE_UBOOT){
55 printf("\n\n****************************\n* U-BOOT UPGRADING *\n* DO NOT POWER OFF DEVICE! *\n****************************\n\n");
57 "erase 0x%lX +0x%lX; cp.b 0x%lX 0x%lX 0x%lX",
58 WEBFAILSAFE_UPLOAD_UBOOT_ADDRESS,
59 WEBFAILSAFE_UPLOAD_UBOOT_SIZE_IN_BYTES,
60 WEBFAILSAFE_UPLOAD_RAM_ADDRESS,
61 WEBFAILSAFE_UPLOAD_UBOOT_ADDRESS,
62 WEBFAILSAFE_UPLOAD_UBOOT_SIZE_IN_BYTES);
64 } else if(upgrade_type == WEBFAILSAFE_UPGRADE_TYPE_FIRMWARE){
66 printf("\n\n****************************\n* FIRMWARE UPGRADING *\n* DO NOT POWER OFF DEVICE! *\n****************************\n\n");
68 "erase 0x%lX +0x%lX; cp.b 0x%lX 0x%lX 0x%lX",
69 WEBFAILSAFE_UPLOAD_KERNEL_ADDRESS,
71 WEBFAILSAFE_UPLOAD_RAM_ADDRESS,
72 WEBFAILSAFE_UPLOAD_KERNEL_ADDRESS,
75 } else if(upgrade_type == WEBFAILSAFE_UPGRADE_TYPE_ART){
77 // TODO: add option to change ART partition offset,
78 // for those who want to use OFW on router with replaced/bigger FLASH
79 printf("\n\n****************************\n* ART UPGRADING *\n* DO NOT POWER OFF DEVICE! *\n****************************\n\n");
80 #if defined(WEBFAILSAFE_UPLOAD_ART_ADDRESS)
82 "erase 0x%lX +0x%lX; cp.b 0x%lX 0x%lX 0x%lX",
83 WEBFAILSAFE_UPLOAD_ART_ADDRESS,
84 WEBFAILSAFE_UPLOAD_ART_SIZE_IN_BYTES,
85 WEBFAILSAFE_UPLOAD_RAM_ADDRESS,
86 WEBFAILSAFE_UPLOAD_ART_ADDRESS,
87 WEBFAILSAFE_UPLOAD_ART_SIZE_IN_BYTES);
90 "erase 0x%lX +0x%lX; cp.b 0x%lX 0x%lX 0x%lX",
91 WEBFAILSAFE_UPLOAD_UBOOT_ADDRESS + (info->size - WEBFAILSAFE_UPLOAD_ART_SIZE_IN_BYTES),
92 WEBFAILSAFE_UPLOAD_ART_SIZE_IN_BYTES,
93 WEBFAILSAFE_UPLOAD_RAM_ADDRESS,
94 WEBFAILSAFE_UPLOAD_UBOOT_ADDRESS + (info->size - WEBFAILSAFE_UPLOAD_ART_SIZE_IN_BYTES),
95 WEBFAILSAFE_UPLOAD_ART_SIZE_IN_BYTES);
102 printf("Executing: %s\n\n", buf);
103 return(run_command(buf, 0));
108 // info about current progress of failsafe mode
109 int do_http_progress(const int state){
112 /* toggle LED's here */
114 case WEBFAILSAFE_PROGRESS_START:
116 // blink LED fast 10 times
117 for(i = 0; i < 10; ++i){
124 printf("HTTP server is ready!\n\n");
127 case WEBFAILSAFE_PROGRESS_TIMEOUT:
128 //printf("Waiting for request...\n");
131 case WEBFAILSAFE_PROGRESS_UPLOAD_READY:
132 printf("HTTP upload is done! Upgrading...\n");
135 case WEBFAILSAFE_PROGRESS_UPGRADE_READY:
136 printf("HTTP ugrade is done! Rebooting...\n\n");
139 case WEBFAILSAFE_PROGRESS_UPGRADE_FAILED:
140 printf("## Error: HTTP ugrade failed!\n\n");
142 // blink LED fast for 4 sec
143 for(i = 0; i < 80; ++i){