Small fixes in new web pages
[oweals/u-boot_mod.git] / u-boot / net / httpd.c
1 /*
2  *      Copyright 1994, 1995, 2000 Neil Russell.
3  *      (See License)
4  *      Copyright 2000, 2001 DENX Software Engineering, Wolfgang Denk, wd@denx.de
5  */
6
7 #include <common.h>
8 #include <command.h>
9 #include <net.h>
10 #include <asm/byteorder.h>
11 #include "httpd.h"
12
13 #include "../httpd/uipopt.h"
14 #include "../httpd/uip.h"
15 #include "../httpd/uip_arp.h"
16
17 #if !defined(WEBFAILSAFE_UPLOAD_ART_ADDRESS)
18 extern flash_info_t flash_info[];
19 #endif
20
21 static int arptimer = 0;
22
23 void HttpdHandler(void){
24         int i;
25
26         for(i = 0; i < UIP_CONNS; i++){
27                 uip_periodic(i);
28
29                 if(uip_len > 0){
30                         uip_arp_out();
31                         NetSendHttpd();
32                 }
33         }
34
35         if(++arptimer == 20){
36                 uip_arp_timer();
37                 arptimer = 0;
38         }
39 }
40
41 // start http daemon
42 void HttpdStart(void){
43         uip_init();
44         httpd_init();
45 }
46
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];
51 #endif
52
53         if(upgrade_type == WEBFAILSAFE_UPGRADE_TYPE_UBOOT){
54
55                 printf("\n\n****************************\n*     U-BOOT UPGRADING     *\n* DO NOT POWER OFF DEVICE! *\n****************************\n\n");
56                 sprintf(buf,
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);
63
64         } else if(upgrade_type == WEBFAILSAFE_UPGRADE_TYPE_FIRMWARE){
65
66                 printf("\n\n****************************\n*    FIRMWARE UPGRADING    *\n* DO NOT POWER OFF DEVICE! *\n****************************\n\n");
67                 sprintf(buf,
68                                 "erase 0x%lX +0x%lX; cp.b 0x%lX 0x%lX 0x%lX",
69                                 WEBFAILSAFE_UPLOAD_KERNEL_ADDRESS,
70                                 size,
71                                 WEBFAILSAFE_UPLOAD_RAM_ADDRESS,
72                                 WEBFAILSAFE_UPLOAD_KERNEL_ADDRESS,
73                                 size);
74
75         } else if(upgrade_type == WEBFAILSAFE_UPGRADE_TYPE_ART){
76
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)
81                 sprintf(buf,
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);
88 #else
89                 sprintf(buf,
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);
96 #endif
97
98         } else {
99                 return(-1);
100         }
101
102         printf("Executing: %s\n\n", buf);
103         return(run_command(buf, 0));
104
105         return(-1);
106 }
107
108 // info about current progress of failsafe mode
109 int do_http_progress(const int state){
110         unsigned char i = 0;
111
112         /* toggle LED's here */
113         switch(state){
114                 case WEBFAILSAFE_PROGRESS_START:
115
116                         // blink LED fast 10 times
117                         for(i = 0; i < 10; ++i){
118                                 all_led_on();
119                                 milisecdelay(25);
120                                 all_led_off();
121                                 milisecdelay(25);
122                         }
123
124                         printf("HTTP server is ready!\n\n");
125                         break;
126
127                 case WEBFAILSAFE_PROGRESS_TIMEOUT:
128                         //printf("Waiting for request...\n");
129                         break;
130
131                 case WEBFAILSAFE_PROGRESS_UPLOAD_READY:
132                         printf("HTTP upload is done! Upgrading...\n");
133                         break;
134
135                 case WEBFAILSAFE_PROGRESS_UPGRADE_READY:
136                         printf("HTTP ugrade is done! Rebooting...\n\n");
137                         break;
138
139                 case WEBFAILSAFE_PROGRESS_UPGRADE_FAILED:
140                         printf("## Error: HTTP ugrade failed!\n\n");
141
142                         // blink LED fast for 4 sec
143                         for(i = 0; i < 80; ++i){
144                                 all_led_on();
145                                 milisecdelay(25);
146                                 all_led_off();
147                                 milisecdelay(25);
148                         }
149
150                         // wait 1 sec
151                         milisecdelay(1000);
152
153                         break;
154         }
155
156         return(0);
157 }