Index: /ar5315_microredboot/microredboot/CHANGELOG =================================================================== --- /ar5315_microredboot/microredboot/CHANGELOG (revision 12368) +++ /ar5315_microredboot/microredboot/CHANGELOG (revision 12370) @@ -1,3 +1,5 @@ 24.6.09 + * added config erase method for senao,ubiquiti and wiligear configs + * added Senao firmware format (EOC2610,EAP3660,ECB3500,EOC5610,EOC1650) * added wiligear firmware format for tftp recovery (the whole code is rewritten to be readable and small) 23.6.09 Index: /ar5315_microredboot/microredboot/ecos/packages/redboot/current/cdl/redboot.cdl =================================================================== --- /ar5315_microredboot/microredboot/ecos/packages/redboot/current/cdl/redboot.cdl (revision 12368) +++ /ar5315_microredboot/microredboot/ecos/packages/redboot/current/cdl/redboot.cdl (revision 12370) @@ -340,5 +340,5 @@ flavor bool default_value 1 - compile -library=libextras.a net/tftp_server.c net/fwupgrade.c net/fwupgrade_ubnt.c net/fwupgrade_wili.c + compile -library=libextras.a net/tftp_server.c net/fwupgrade.c net/fwupgrade_ubnt.c net/fwupgrade_wili.c net/fwupgrade_senao.c description " This option enables the use of the TFTP server" 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 12368) +++ /ar5315_microredboot/microredboot/ecos/packages/redboot/current/src/net/tftp_server.c (revision 12370) @@ -156,4 +156,15 @@ /* 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); @@ -257,4 +268,5 @@ int isubnt = 0; int iswili = 0; + int issenao = 0; isddwrt = fw_check_image_ddwrt((char *)BASE_ADDR, ptr - BASE_ADDR, 0) == 0; @@ -271,5 +283,11 @@ 0) == 0; - if (isddwrt || isubnt || iswili) /* third parameter 0 - do not write to flash */ + 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 */ tftpd_send(ACK, block, src_route, src_port); // crc ok else { @@ -296,4 +314,10 @@ ("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); } 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 12370) +++ /ar5315_microredboot/microredboot/ecos/packages/redboot/current/src/net/fwupgrade_senao.c (revision 12370) @@ -0,0 +1,108 @@ +/* +firmware upgrade code for senao webflash images +*/ + +#include +#include +#include +#include +#include "fwupgrade.h" + +/* some variables from flash.c */ +extern void *flash_start, *flash_end; +extern int flash_block_size, flash_num_blocks; +#ifdef CYGOPT_REDBOOT_FIS +extern void *fis_work_block; +extern void *fis_addr; +extern int fisdir_size; // Size of FIS directory. +#endif +//extern void _show_invalid_flash_address(CYG_ADDRESS flash_addr, int stat); +extern void fis_update_directory(void); + +//#define TRACE diag_printf("DBG: %s:%d\n", __FUNCTION__, __LINE__) + +#define TRACE + + +extern void fis_init(int argc, char *argv[], int force); + +int fw_check_image_senao(unsigned char *addr, unsigned long maxlen, + int do_flash) +{ + unsigned char *base = (unsigned char *)addr+10; + if (strncmp(addr,"AP51-3660",9)) { + diag_printf("SENAO_FW: bad header\n"); + return -1; + } + + if (do_flash) { + char *arg[] = { "fis", "init" }; + fis_init(2, arg, 1); + void *err_addr; + flash_read(fis_addr, fis_work_block, fisdir_size, + (void **)&err_addr); + struct fis_image_desc *img = NULL; + 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 = + flash_erase((void *)flash_addr, maxlen, + (void **)&err_addr)) != 0) { + diag_printf("SENAO_FW: Can't erase region at %p: %s\n", + err_addr, flash_errmsg(stat)); + return -1; + } + if ((stat = + flash_program((void *)flash_addr, + (void *)(base), + maxlen, (void **)&err_addr)) != 0) { + diag_printf + ("SENAO_FW: Can't program region at %p: %s\n", + err_addr, flash_errmsg(stat)); + return -1; + } + img = (struct fis_image_desc *)fis_work_block; + for (i = 0; i < fisdir_size / sizeof(*img); i++, img++) { + if (img->name[0] == (unsigned char)0xFF) { + break; + } + } + + unsigned int filesyssize = 0x3f0000; + unsigned int linuxsize = 0xa0000; + unsigned int cfgsize = 0x20000; + if (maxlen==3670026) // detect 4M images (EAP3660 etc.) + { + filesyssize = 0x2f0000; + } + strcpy(img->name, "rootfs"); + img->flash_base = flash_addr; + img->mem_base = 0x80041000; + img->entry_point = 0; + img->size = filesyssize; + img->data_length = filesyssize; + img++; + strcpy(img->name, "vmlinux.bin.l7"); + img->flash_base = flash_addr+filesyssize; + img->mem_base = 0x80041000; + img->entry_point = 0x80041798; + img->size = linuxsize; + img->data_length = linuxsize; + img++; + strcpy(img->name, "cfg"); + img->flash_base = flash_addr+filesyssize+linuxsize; + img->mem_base = 0x80041000; + img->entry_point = 0; + img->size = cfgsize; + img->data_length = cfgsize; + + fis_update_directory(); + diag_printf("SENAO_FW: flashing done\n"); + } + return 0; +} Index: /ar5315_microredboot/microredboot/ecos/packages/redboot/current/src/net/fwupgrade_senao.h =================================================================== --- /ar5315_microredboot/microredboot/ecos/packages/redboot/current/src/net/fwupgrade_senao.h (revision 12370) +++ /ar5315_microredboot/microredboot/ecos/packages/redboot/current/src/net/fwupgrade_senao.h (revision 12370) @@ -0,0 +1,18 @@ + +#ifndef __senao_fw__ +#define __senao_fw__ + +/* do header, partition and final signature check */ +extern int fw_check_image_senao(unsigned char *addr, unsigned long maxlen, + int do_flash); + +#define MAX_IMAGE_SIZE 0x7E0000 /* 4mb - 64k */ + +#define MAX_PART_SIZE 0x800000 /* 3mb - valid only for ar531x */ + +/* these variables will be initialized in do_tftpd() */ +CYG_ADDRWORD BASE_ADDR; +CYG_ADDRWORD FW_TEMP_BASE; +/***********************************************************************************/ + +#endif /* __wilibox_fw__ */ Index: /ar5315_microredboot/microredboot/ecos/packages/redboot/current/src/net/fwupgrade.h =================================================================== --- /ar5315_microredboot/microredboot/ecos/packages/redboot/current/src/net/fwupgrade.h (revision 12368) +++ /ar5315_microredboot/microredboot/ecos/packages/redboot/current/src/net/fwupgrade.h (revision 12370) @@ -9,4 +9,6 @@ int do_flash); extern int fw_check_image_wili(unsigned char *addr, unsigned long maxlen, + int do_flash); +extern int fw_check_image_senao(unsigned char *addr, unsigned long maxlen, int do_flash); Index: /ar5315_microredboot/microredboot/boot/src/lib/fis.c =================================================================== --- /ar5315_microredboot/microredboot/boot/src/lib/fis.c (revision 12346) +++ /ar5315_microredboot/microredboot/boot/src/lib/fis.c (revision 12370) @@ -17,4 +17,17 @@ unsigned long file_cksum; // Checksum over image data }; + +static unsigned int getPartition(char *name) +{ + int count = 0; + unsigned char *p = + (unsigned char *)(flashbase + flashsize - (sectorsize * 2)); + struct fis_image_desc *fis = (struct fis_image_desc *)p; + while (fis->name[0] != 0xff && count < 10) { + if (!strncmp(fis->name, name, strlen(name))) + return fis->flash_base; + } + return 0; +} /* Index: /ar5315_microredboot/microredboot/boot/src/lib/LzmaDecode.c =================================================================== --- /ar5315_microredboot/microredboot/boot/src/lib/LzmaDecode.c (revision 12346) +++ /ar5315_microredboot/microredboot/boot/src/lib/LzmaDecode.c (revision 12370) @@ -168,5 +168,6 @@ #ifdef _LZMA_LOC_OPT CProb *prob = probs + mi; - RC_GET_BIT2(prob, mi,;, symbol |= (1 << i)) + RC_GET_BIT2(prob, mi,; + , symbol |= (1 << i)) #else int bit = RangeDecoderBitDecode(probs + mi, rd); Index: /ar5315_microredboot/microredboot/boot/src/arch/ar2315.c =================================================================== --- /ar5315_microredboot/microredboot/boot/src/arch/ar2315.c (revision 12346) +++ /ar5315_microredboot/microredboot/boot/src/arch/ar2315.c (revision 12370) @@ -283,4 +283,6 @@ } +static unsigned int getPartition(char *name); + /* erases nvram partition on the detected location or simply returns if no nvram was detected */ @@ -291,4 +293,7 @@ struct opcodes *ptr_opcode; __u32 temp, reg; + if (!nvramdetect) { + nvramdetect = getPartition("cfg"); + } if (!nvramdetect) { puts("nvram can and will not erased, since nvram was not detected on this device (maybe dd-wrt isnt installed)!\n"); Index: /ar5315_microredboot/microredboot/boot/src/arch/ar5312.c =================================================================== --- /ar5315_microredboot/microredboot/boot/src/arch/ar5312.c (revision 12346) +++ /ar5315_microredboot/microredboot/boot/src/arch/ar5312.c (revision 12370) @@ -208,4 +208,5 @@ /* erases nvram partition on the detected location or simply returns if no nvram was detected */ +static unsigned int getPartition(char *name); static int flash_erase_nvram(unsigned int flashsize, unsigned int blocksize) @@ -213,4 +214,7 @@ int i, ticks; unsigned short val; + if (!nvramdetect) { + nvramdetect = getPartition("cfg"); + } if (!nvramdetect) { puts("nvram can and will not erased, since nvram was not detected on this device (maybe dd-wrt isnt installed)!\n");