|
楼主 |
发表于 2013-1-19 16:17
|
显示全部楼层
刷不死的wr703N的u-boot, 是用uip 实现HTTP协议的, 大体看了下代码, 稍微总结如下:
//--- include/config.h, 生成的内容如下
#define CONFIG_AR7240 1
#define CONFIG_MACH_HORNET 1
#define CONFIG_HORNET_1_1_WAR 1
#define NEW_DDR_TAP_CAL 1
#define FLASH_SIZE 4
/* Automatically generated - do not edit */
#include <configs/ap121.h>
#define CONFIG_PID_WR70301 1
#define GPIO_SYS_LED_BIT 27
#define GPIO_SYS_LED_ON 0
#define GPIO_RST_BUTTON_BIT 11
---- include/configs/ap121.h, 相关的配置数据都在此文件!!!!
//#define FLASH_SIZE 4
#if (FLASH_SIZE == 8)
#define CFG_MAX_FLASH_BANKS 1 /* max number of memory banks */
#define CFG_MAX_FLASH_SECT 128 /* max number of sectors on one chip */
#define CFG_FLASH_SECTOR_SIZE (64*1024)
#define CFG_FLASH_SIZE 0x00800000 /* Total flash size */
#elif (FLASH_SIZE == 4)
#define CFG_MAX_FLASH_BANKS 1 /* max number of memory banks */
#define CFG_MAX_FLASH_SECT 64 /* max number of sectors on one chip */
#define CFG_FLASH_SECTOR_SIZE (64*1024)
#define CFG_FLASH_SIZE 0x00400000 /* Total flash size */
#else
/* For 2 MB flash */
# error "not support 2MB flash now"
#define CFG_MAX_FLASH_BANKS 1 /* max number of memory banks */
#define CFG_MAX_FLASH_SECT 32 /* max number of sectors on one chip */
#define CFG_FLASH_SECTOR_SIZE (64*1024)
#define CFG_FLASH_SIZE 0x00200000 /* Total flash size */
#endif
#define CONFIG_IPADDR 192.168.1.1
#define CONFIG_SERVERIP 192.168.1.2
----- net/uip-0.9/fsdata.c, httpd.c, fsdata.c,
#升级时的提示
Flashing...
The system is now trying to flash. If there is a problem, the LEDs will start to blink.
After a successful update the box will reboot
static const char data_index_html[] =
"HTTP/1.0 200 OKn"
"Server: uIP/0.9 (http://dunkels.com/adam/uip/)n"
"Content-type: text/htmln"
"n"
"<html>n"
"t<head>n"
"tt<title>n"
"tttFailsafe UIn"
"tt</title>n"
"t</head>n"
"t<body>n"
"tt<h1>Failsafe UI</h1>n"
"tt<form method="post" enctype="multipart/form-data">n"
"ttt<input type=file name=firmware>n"
"ttt<input type=submit>n"
"tt</form>n"
"t</body>n"
"</html>n";
const struct fsdata_file file_index_html[] =
{{file_404_html, "/index.html", data_index_html, sizeof(data_index_html)}};
-- httpd.c
void httpd_init(void)
{
fs_init();
uip_listen(HTONS(80));
}
upload_data = httpd_upload_data = (unsigned char *)do_http_tmp_address();
printf("received data will be stored at %pn", upload_data);
next = (unsigned char *)strstr((char *)boundary_start, "name="firmware";");
void httpd_appcall(void)
{
//第一包
if(hs->state == HTTP_FIRMWARE) {
next = (unsigned char *)strstr((char *)boundary_start, "name="firmware";");
if(!next)
{
uip_close();
return;
}
next = (unsigned char *)strstr((char *)next, eol2); //rnrn
if(!next)
{
printf("could not find start of datan");
uip_close();
return;
}
next += 4; //此为首包的有效数据
hs->script = 0;
hs->state = HTTP_FIRMWARE;
hs->upload = uip_len - (next - start); //有效数据的长度
hs->upload_total = len - (int)(next - boundary_start);
hs->upload_total -= (strlen(boundary) + 6);
//printf("storing %d bytes at %pn", (int)hs->upload, upload_data);
for(i = 0; i < hs->upload; i++)
upload_data = next; //有效数据赋值
upload_data += (int)hs->upload;
printf("%d / %dn", (int)hs->upload, hs->upload_total);
uip_slen = 0;
return;
}
//后续包
if(hs->state == HTTP_FIRMWARE) {
if(uip_newdata()) {
int i;
hs->count = 0;
uip_appdata[uip_len] = '';
hs->upload += uip_len;
//printf("storing %d bytes at %pn", uip_len, upload_data);
printf("%d / %dn", (int)hs->upload, hs->upload_total);
for(i = 0; i < uip_len; i++)
upload_data = uip_appdata;
upload_data += uip_len;
uip_slen = 0;
if(hs->upload >= hs->upload_total)
{
upload_running = 1;
NetBootFileXferSize = hs->upload_total;
fs_open(file_flash_html.name, &fsfile);
hs->script = 0;
hs->state = HTTP_FILE;
hs->dataptr = fsfile.data;
hs->count = fsfile.len;
}
}
}
} |
|