/* * Write a buffer from memory to flash: * 0. Assumption: Caller has already erased the appropriate sectors. * 1. call page programming for every 256 bytes */ int write_buff(flash_info_t *info, uchar *source, ulong addr, ulong len) { int total = 0, len_this_lp, bytes_this_page; ulong dst; uchar *src; printf ("write addr: %x\n", addr); addr = addr - CFG_FLASH_BASE; while(total < len) { src = source + total; dst = addr + total; bytes_this_page = AR7100_SPI_PAGE_SIZE - (addr % AR7100_SPI_PAGE_SIZE); len_this_lp = ((len - total) > bytes_this_page) ? bytes_this_page : (len - total); ar7100_spi_write_page(dst, src, len_this_lp); total += len_this_lp; } ar7100_spi_done(); return 0; }
/* * Write a buffer from memory to flash: * 0. Assumption: Caller has already erased the appropriate sectors. * 1. call page programming for every 256 bytes */ int write_buff(flash_info_t *info, uchar *source, ulong addr, ulong len) { int total = 0, len_this_lp, bytes_this_page; ulong dst; uchar *src; #if (defined(CONFIG_WNDR3700U_LED) || defined(CONFIG_WNDR3700V1H2_LED) || defined(CONFIG_HW29763654P16P128)) && defined(CFG_NMRP) int n_alive=2,send_alive=0; Nmrp_active_start=get_timer(0); #endif #if (defined(CONFIG_WNDR3700U_LED) || defined(CONFIG_WNDR3700V1H2_LED) || defined(CONFIG_HW29763654P16P128)) && defined(FIRMWARE_RECOVER_FROM_TFTP_SERVER) NetSetTimeout (CFG_HZ/10,Update_LedSet); #endif printf ("write addr: %x\n", addr); addr = addr - CFG_FLASH_BASE; while(total < len) { src = source + total; dst = addr + total; bytes_this_page = AR7100_SPI_PAGE_SIZE - (addr % AR7100_SPI_PAGE_SIZE); len_this_lp = ((len - total) > bytes_this_page) ? bytes_this_page : (len - total); #if (defined(CONFIG_WNDR3700U_LED) || defined(CONFIG_WNDR3700V1H2_LED) || defined(CONFIG_HW29763654P16P128)) && defined(FIRMWARE_RECOVER_FROM_TFTP_SERVER) if (timeHandler && ((get_timer(0) - timeStart) > timeDelta)) { thand_f *x; x = timeHandler; timeHandler = (thand_f *)0; (*x)(); } #endif #if (defined(CONFIG_WNDR3700U_LED) || defined(CONFIG_WNDR3700V1H2_LED) || defined(CONFIG_HW29763654P16P128)) && defined(CFG_NMRP) /* * send Keep Alive Req every 15s, I find the timer is not * accurate if the time is more than 10s, so I record the time * every 5s */ if(NmrpState !=0 && ((get_timer(0) - Nmrp_active_start) > (5* CFG_HZ) ) ) { n_alive++; send_alive=1; Nmrp_active_start=get_timer(0); } if (send_alive && n_alive%3==0) { NmrpState = STATE_KEEP_ALIVE; NmrpSend(); send_alive=0; } #endif ar7100_spi_write_page(dst, src, len_this_lp); total += len_this_lp; } #if defined(CONFIG_WNDR3700U_LED) && defined(FIRMWARE_RECOVER_FROM_TFTP_SERVER) /*write finished , test led on*/ test_led(0); #endif #if (defined(CONFIG_WNDR3700V1H2_LED) || defined(CONFIG_HW29763654P16P128)) && defined(FIRMWARE_RECOVER_FROM_TFTP_SERVER) /*write finished , test led on*/ board_test_led(0); #endif #if (defined(CONFIG_WNDR3700U_LED) || defined(CONFIG_WNDR3700V1H2_LED) || defined(CONFIG_HW29763654P16P128)) && defined(CFG_NMRP) if(NmrpState !=0) NmrpState=STATE_CLOSING; #endif ar7100_spi_done(); return 0; }