Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1514610
  • 博文数量: 129
  • 博客积分: 1449
  • 博客等级: 上尉
  • 技术积分: 3048
  • 用 户 组: 普通用户
  • 注册时间: 2012-07-24 18:36
文章分类

全部博文(129)

文章存档

2015年(3)

2014年(20)

2013年(65)

2012年(41)

分类: C/C++

2013-01-18 11:24:31


在上面基础上的修改

make 后的显示:
cp /home/xxg/wr703n-uboot-with-web-failsafe-read-only/u-boot/tuboot.bin /home/xxg/wr703n-uboot-with-web-failsafe-read-only/bin./tools/mkimage -A mips -T firmware -C lzma \
-a 0x80010000 \
-e 0x80010000 \
-n 'u-boot image' -d u-boot.bin.lzma u-boot.lzimg
Image Name:   u-boot image
Created:      Fri Jan 18 09:28:16 2013
Image Type:   MIPS Linux Firmware (lzma compressed)
Data Size:    39446 Bytes = 38.52 kB = 0.04 MB
Load Address: 0x80010000
Entry Point:  0x80010000
cat bootstrap.bin > tuboot.bin
cat u-boot.lzimg >> tuboot.bin
make[1]: Leaving directory `/home/xxg/wr703n-uboot-with-web-failsafe-read-only/u-boot'
cp /home/xxg/wr703n-uboot-with-web-failsafe-read-only/u-boot/tuboot.bin /home/xxg/wr703n-uboot-with-web-failsafe-read-only/bin
tuboot.bin size: 54462




--- u-boot分析, 主要目录: common(common.h中有文件声明), include(config/ap121.h), net, board(ar7240/ap121)



//--- 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 
#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, 相关的配置数据都在此文件!!!!
/*-----------------------------------------------------------------------
 * FLASH and environment organization
 *-----------------------------------------------------------------------
 */

//#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_CMD_HTTPD 1
#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 OK\n"
"Server: uIP/0.9 ()\n"
"Content-type: text/html\n"
"\n"
"\n"
"\t\n"
"\t\t\n"
"\t\t\tFailsafe UI\n"
"\t\t\n"
"\t\n"
"\t\n"
"\t\t

Failsafe UI

\n" "\t\t
\n" "\t\t\t\n" "\t\t\t\n" "\t\t
\n" "\t \n" "\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 %p\n", 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); //\r\n\r\n if(!next) { printf("could not find start of data\n"); 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 %p\n", (int)hs->upload, upload_data); for(i = 0; i < hs->upload; i++) upload_data[i] = next[i]; //有效数据赋值 upload_data += (int)hs->upload; printf("%d / %d\n", (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] = '\0'; hs->upload += uip_len; //printf("storing %d bytes at %p\n", uip_len, upload_data); printf("%d / %d\n", (int)hs->upload, hs->upload_total); for(i = 0; i < uip_len; i++) upload_data[i] = uip_appdata[i]; 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; } } } } ---- net目录下 -- httpd.c void HttpdStart (void) { uip_init(); httpd_init(); } unsigned long do_http_tmp_address(void) { char *s = getenv ("ram_addr"); if (s) { ulong tmp = simple_strtoul (s, NULL, 16); return tmp; } return 0 /*0x80a00000*/; } int do_http_progress(const int state) { /* toggle LED's here */ switch(state) { case HTTP_PROGRESS_START: ar7240_all_led_on(); break; case HTTP_PROGRESS_UPLOAD_READY: ar7240_all_led_off(); udelay(1000 * 500); ar7240_all_led_on(); break; case HTTP_PROGRESS_UGRADE_FAILED: puts("http ugrade failed\n"); break; } return 0; } int do_http_upgrade(const unsigned char *data, const ulong size) { char buf[128]; if(getenv ("ram_addr") == NULL) return -1; if(getenv ("kernel_addr") == NULL) return -1; /* write the image to the flash, 执行命令 刷FW erase 0x9f020000 +0x7c0000 cp.b 0x80000000 0x9f020000 0x7c0000 */ sprintf(buf, "era ${kernel_addr} +0x%lx; cp.b ${ram_addr} ${kernel_addr} 0x%lx", size, size); // return run_command(buf, 0); //代码中调用cmd } -- net.c int NetLoopHttpd(void) { HttpdStart(); do_http_progress(HTTP_PROGRESS_START); https_running = 1; for (;;) { unsigned long long t1; WATCHDOG_RESET(); if(eth_rx() > 0) { HttpdHandler(); } else { t1 = get_ticks(); if(t1 - tout > 1000) { do_http_progress(HTTP_PROGRESS_TIMEOUT); tout = t1; } } do_http_progress(HTTP_PROGRESS_UPLOAD_READY); //http升级 if(do_http_upgrade(&httpd_upload_data[0], NetBootFileXferSize) >= 0) { do_http_progress(HTTP_PROGRESS_UGRADE_READY); udelay(1000 * 10); ar7240_all_led_off(); do_reset (0,0,0,0); return 0; } break; } } ---- board/ar7240/ap121 目录下, ap121.c, flash.c #define MY_WRITE(y, z) ((*((volatile u32*)(y))) = z) #define MY_READ(y) (*((volatile u32*)(y))) #define SETBITVAL(val, pos, bit) \ do { \ ulong bitval = (bit) ? 0x1 : 0x0; \ (val) = ((val) & ~(0x1 << (pos))) | ( (bitval) << (pos)); \ } while (0) void ar7240_all_led_on(void) { ulong gpio; int index; gpio = MY_READ(0xb8040008); #ifdef CONFIG_PID_WR70301 SETBITVAL(gpio, GPIO_SYS_LED_BIT, GPIO_SYS_LED_ON); //LED ON SETBITVAL(gpio, GPIO_SYS_LED_BIT, !GPIO_SYS_LED_ON); //LED OFF #endif MY_WRITE(0xb8040008, gpio); } int ar7240_is_rst_button_pushed(void) { if(ar7240_reg_rd(AR7240_GPIO_IN) & (1 << GPIO_RST_BUTTON_BIT)) return 1; else return 0; } //sets up flash_info and returns size of FLASH (bytes) unsigned long flash_get_geom (flash_info_t *flash_info) { int i; //#define FLASH_M25P64 0x00F2, \include\flash.h flash_info->flash_id = FLASH_M25P64; //#define CFG_FLASH_SIZE ((uint)(8 * 1024 * 1024)) /* max 8Mbyte */, \board\fads\fads.h, flash_info->size = CFG_FLASH_SIZE; /* bytes */ flash_info->sector_count = flash_info->size/CFG_FLASH_SECTOR_SIZE; for (i = 0; i < flash_info->sector_count; i++) { flash_info->start[i] = CFG_FLASH_BASE + (i * CFG_FLASH_SECTOR_SIZE); flash_info->protect[i] = 0; } printf ("flash size %d, sector count = %d\n", flash_info->size, flash_info->sector_count); return (flash_info->size); } ---- board/ar7240/common目录下, -- ar7240_flash.c: 通过SPI 读写Flash unsigned long flash_init(void) { read_id(); return (flash_get_geom(&flash_info[0])); } int flash_erase(flash_info_t *info, int s_first, int s_last) { int i, sector_size = info->size / info->sector_count; for (i = s_first; i <= s_last; i++) { ar7240_spi_sector_erase(i * sector_size); } ar7240_spi_done(); return 0; } -- main.c void main_loop (void) { # ifdef CONFIG_CMD_HTTPD if (ar7240_is_rst_button_pushed()) { printf("You push the button,starting httpd to update firmware ...\n"); NetLoopHttpd(); } # endif } int run_command (const char *cmd, int flag) { }

                                   
阅读(6103) | 评论(0) | 转发(6) |
给主人留下些什么吧!~~