Index: /ar5315_microredboot/microredboot/CHANGELOG =================================================================== --- /ar5315_microredboot/microredboot/CHANGELOG (revision 12381) +++ /ar5315_microredboot/microredboot/CHANGELOG (revision 12385) @@ -1,2 +1,6 @@ +26.6.09 + * move clock initialization to ensure udelay function + * removed http protocol to save space. i believe the embedded tftp client is enough and the tftp server for recovery makes recovery and flashing pretty easy + * simplified the firmware format handling code, for easy integration of new formats. reduces codesize too 25.6.09 * fix bootcode for LSDK based devices Index: /ar5315_microredboot/microredboot/ecos/packages/redboot/current/cdl/redboot.cdl =================================================================== --- /ar5315_microredboot/microredboot/ecos/packages/redboot/current/cdl/redboot.cdl (revision 12370) +++ /ar5315_microredboot/microredboot/ecos/packages/redboot/current/cdl/redboot.cdl (revision 12385) @@ -357,5 +357,5 @@ display "Support HTTP for download" flavor bool - default_value 1 + default_value 0 compile -library=libextras.a net/http_client.c description " Index: /ar5315_microredboot/microredboot/ecos/packages/redboot/current/src/net/tftp_server.c =================================================================== --- /ar5315_microredboot/microredboot/ecos/packages/redboot/current/src/net/tftp_server.c (revision 12376) +++ /ar5315_microredboot/microredboot/ecos/packages/redboot/current/src/net/tftp_server.c (revision 12385) @@ -93,6 +93,20 @@ extern int page_gpio; -static void pagesetup(void) -{ +struct firmware_formats { + char *name; + int (*fw_check_image) (unsigned char *, unsigned long, int); +}; + +static const struct firmware_formats fw_formats[] = { + {.name = "DD-WRT",.fw_check_image = fw_check_image_ddwrt}, + {.name = "UBIQUITI",.fw_check_image = fw_check_image_ubnt}, + {.name = "WILIGEAR",.fw_check_image = fw_check_image_wili}, + {.name = "SENAO",.fw_check_image = fw_check_image_senao}, +}; + +static void do_flash_update(unsigned long base_addr, unsigned long len, + int index) +{ + int rc; #if defined(CYGPKG_HAL_MIPS_AR2316) #if FISTYPE == 1 @@ -115,9 +129,6 @@ #endif #endif - -} - -static void flashresult(int rc) -{ + /* do_flash = 1, write to flash */ + rc = fw_formats[index].fw_check_image((char *)base_addr, len, 1); if (rc) diag_printf("Flash update failed!\n"); @@ -125,49 +136,6 @@ diag_printf("Flash update complete.\n"); /* clean da memory */ + memset((unsigned char *)base_addr, 0, len); do_reset(0, NULL); - -} - -void do_flash_update_ddwrt(unsigned long base_addr, unsigned long len) -{ - int rc; - pagesetup(); - /* do_flash = 1, write to flash */ - rc = fw_check_image_ddwrt((char *)base_addr, len, 1); - memset((unsigned char *)base_addr, 0, len); - flashresult(rc); -} - -void do_flash_update_ubnt(unsigned long base_addr, unsigned long len) -{ - int rc; - pagesetup(); - /* do_flash = 1, write to flash */ - rc = fw_check_image_ubnt((char *)base_addr, len, 1); - - memset((unsigned char *)base_addr, 0, len); - flashresult(rc); -} - -void do_flash_update_wili(unsigned long base_addr, unsigned long len) -{ - int rc; - pagesetup(); - /* do_flash = 1, write to flash */ - rc = fw_check_image_wili((char *)base_addr, len, 1); - - memset((unsigned char *)base_addr, 0, len); - flashresult(rc); -} - -void do_flash_update_senao(unsigned long base_addr, unsigned long len) -{ - int rc; - pagesetup(); - /* do_flash = 1, write to flash */ - rc = fw_check_image_senao((char *)base_addr, len, 1); - - memset((unsigned char *)base_addr, 0, len); - flashresult(rc); } @@ -265,29 +233,21 @@ diag_printf("Checking uploaded file...\n"); - int isddwrt = 0; - int isubnt = 0; - int iswili = 0; - int issenao = 0; - isddwrt = fw_check_image_ddwrt((char *)BASE_ADDR, - ptr - BASE_ADDR, 0) == 0; - if (!isddwrt) - isubnt = - fw_check_image_ubnt((char *)BASE_ADDR, - ptr - BASE_ADDR, - 0) == 0; - - if (!isubnt && !isddwrt) - iswili = - fw_check_image_wili((char *)BASE_ADDR, - ptr - BASE_ADDR, - 0) == 0; - - if (!isubnt && !isddwrt && !iswili) - issenao = - fw_check_image_senao((char *)BASE_ADDR, - ptr - BASE_ADDR, - 0) == 0; - - if (isddwrt || isubnt || iswili || issenao) /* third parameter 0 - do not write to flash */ + int detect = 0; + int i; + for (i = 0; + i < + sizeof(fw_formats) / + sizeof(struct firmware_formats); i++) { + int v = + fw_formats[i]. + fw_check_image((char *)BASE_ADDR, + ptr - BASE_ADDR, 0) == 0; + if (v) { + detect = i; + break; + } + } + + if (detect) /* third parameter 0 - do not write to flash */ tftpd_send(ACK, block, src_route, src_port); // crc ok else { @@ -299,26 +259,7 @@ // write to flash #if 1 - if (isddwrt) { - diag_printf - ("DD-WRT firmware format detected\n"); - do_flash_update_ddwrt(BASE_ADDR, - ptr - BASE_ADDR); - } - if (isubnt) { - diag_printf("UBNT firmware format detected\n"); - do_flash_update_ubnt(BASE_ADDR, - ptr - BASE_ADDR); - } - if (iswili) { - diag_printf - ("WILIGEAR firmware format detected\n"); - do_flash_update_wili(BASE_ADDR, - ptr - BASE_ADDR); - } - if (issenao) { - diag_printf("SENAO firmware format detected\n"); - do_flash_update_senao(BASE_ADDR, - ptr - BASE_ADDR); - } + diag_printf("%s: firmware format detected\n", + fw_formats[detect].name); + do_flash_update(BASE_ADDR, ptr - BASE_ADDR, detect); #else diag_printf("Not writing to flash.\n"); Index: /ar5315_microredboot/microredboot/ecos/packages/redboot/current/src/net/fwupgrade_wili.c =================================================================== --- /ar5315_microredboot/microredboot/ecos/packages/redboot/current/src/net/fwupgrade_wili.c (revision 12368) +++ /ar5315_microredboot/microredboot/ecos/packages/redboot/current/src/net/fwupgrade_wili.c (revision 12385) @@ -223,10 +223,4 @@ flash_read(fis_addr, fis_work_block, fisdir_size, (void **)&err_addr); - struct fis_image_desc *img = fis_lookup("RedBoot", &i); - if (i != 0) { - diag_printf - ("WILI_FW: RedBoot partition is not the first partition\n"); - return -1; - } for (i = 0; i < fw.part_count; ++i) { fw_part_t *fwp = &fw.parts[i]; @@ -240,5 +234,6 @@ int stat; int index; - img = fis_lookup(fwp->header->name, &index); + struct fis_image_desc *img = + fis_lookup(fwp->header->name, &index); if (!img) { diag_printf Index: /ar5315_microredboot/microredboot/ecos/packages/redboot/current/src/net/fwupgrade_senao.c =================================================================== --- /ar5315_microredboot/microredboot/ecos/packages/redboot/current/src/net/fwupgrade_senao.c (revision 12376) +++ /ar5315_microredboot/microredboot/ecos/packages/redboot/current/src/net/fwupgrade_senao.c (revision 12385) @@ -49,9 +49,4 @@ int i, stat; img = fis_lookup("RedBoot", &i); - if (i != 0) { - diag_printf - ("SENAO_FW: RedBoot partition is not the first partition\n"); - return -1; - } unsigned int flash_addr = img->flash_base + img->size; if ((stat = Index: /ar5315_microredboot/microredboot/ecos/packages/redboot/current/src/net/tftp_client.c =================================================================== --- /ar5315_microredboot/microredboot/ecos/packages/redboot/current/src/net/tftp_client.c (revision 12376) +++ /ar5315_microredboot/microredboot/ecos/packages/redboot/current/src/net/tftp_client.c (revision 12385) @@ -223,7 +223,5 @@ if (ntohs(hdr->th_opcode) == DATA) { if (ntohs(hdr->th_block) == - (cyg_uint16) ((tftp_stream. - last_good_block + - 1) & 0xFFFF)) { + (cyg_uint16) ((tftp_stream.last_good_block + 1) & 0xFFFF)) { // Consume this data data_len -= 4; /* Sizeof TFTP header */ Index: /ar5315_microredboot/microredboot/ecos/packages/redboot/current/src/net/fwupgrade_ubnt.c =================================================================== --- /ar5315_microredboot/microredboot/ecos/packages/redboot/current/src/net/fwupgrade_ubnt.c (revision 12376) +++ /ar5315_microredboot/microredboot/ecos/packages/redboot/current/src/net/fwupgrade_ubnt.c (revision 12385) @@ -132,10 +132,4 @@ flash_read(fis_addr, fis_work_block, fisdir_size, (void **)&err_addr); - struct fis_image_desc *img = fis_lookup("RedBoot", &i); - if (i != 0) { - diag_printf - ("UBNT_FW: RedBoot partition is not the first partition\n"); - return -1; - } for (i = 0; i < fw.part_count; ++i) { fw_part_t *fwp = &fw.parts[i]; @@ -185,6 +179,7 @@ ntohl(fwp->header->data_size)); } - addPartition("cfg", (flash_end + 1) - (flash_block_size * 3), 0, - 0, 0x10000, 0x10000); + addPartition("cfg", + ((unsigned int)flash_end + 1) - + (flash_block_size * 3), 0, 0, 0x10000, 0x10000); fis_update_directory(); Index: /ar5315_microredboot/microredboot/ecos/packages/redboot/current/src/net/fwupgrade.c =================================================================== --- /ar5315_microredboot/microredboot/ecos/packages/redboot/current/src/net/fwupgrade.c (revision 12376) +++ /ar5315_microredboot/microredboot/ecos/packages/redboot/current/src/net/fwupgrade.c (revision 12385) @@ -121,9 +121,4 @@ int i, stat; img = fis_lookup("RedBoot", &i); - if (i != 0) { - diag_printf - ("DD-WRT_FW: RedBoot partition is not the first partition\n"); - return -1; - } unsigned int flash_addr = img->flash_base + img->size; diag_printf("DD-WRT_FW: flash base is 0x%08X\n", flash_addr); Index: /ar5315_microredboot/microredboot/README =================================================================== --- /ar5315_microredboot/microredboot/README (revision 12306) +++ /ar5315_microredboot/microredboot/README (revision 12385) @@ -9,4 +9,7 @@ if the button is pushed, the redboot will be started and can be used like known from the past. if the reset button is pushed longer than 5 seconds, the dd-wrt nvram config will be resetted +if you keep it pushed a little bit longer, redboot will start a recovery tftp which accepts external firmware uploads. +supported are DD-WRT webflash,Ubiquiti,Wiligear and Senao images +simply send it with tftp -i 192.168.1.1 put newfirmware.bin to the device (ip might be different, depending from the device) Index: /ar5315_microredboot/microredboot/boot/src/misc_lzma.c =================================================================== --- /ar5315_microredboot/microredboot/boot/src/misc_lzma.c (revision 12382) +++ /ar5315_microredboot/microredboot/boot/src/misc_lzma.c (revision 12385) @@ -269,5 +269,5 @@ pb->argv[0] = pcmd; pb->argv[1] = ++pcmd; - pcmd[0] = 0; //terminate, no commandline + pcmd[0] = 0; //terminate, no user commandline void (*tt) (int a, char **b, void *c); @@ -285,4 +285,6 @@ disable_watchdog(); arch_decomp_setup(); + /* initialize clock */ + HAL_CLOCK_INITIALIZE(RTC_PERIOD); printf("MicroRedBoot v1.3, (c) 2009 DD-WRT.COM (%s)\n", __DATE__); printf("CPU Clock: %dMhz\n", cpu_frequency() / 1000000); @@ -321,6 +323,4 @@ puts("Booting Linux\n"); resettrigger = 1; - /* initialize clock */ - HAL_CLOCK_INITIALIZE(RTC_PERIOD); /* important, enable ethernet bus, if the following lines are not initialized linux will not be able to use the ethernet mac, taken from redboot source */