| 1 |
/* |
|---|
| 2 |
firmware upgrade code for senao webflash images |
|---|
| 3 |
*/ |
|---|
| 4 |
|
|---|
| 5 |
#include <redboot.h> |
|---|
| 6 |
#include <cyg/io/flash.h> |
|---|
| 7 |
#include <fis.h> |
|---|
| 8 |
#include <flash_config.h> |
|---|
| 9 |
#include "fwupgrade.h" |
|---|
| 10 |
|
|---|
| 11 |
/* some variables from flash.c */ |
|---|
| 12 |
extern void *flash_start, *flash_end; |
|---|
| 13 |
extern int flash_block_size, flash_num_blocks; |
|---|
| 14 |
#ifdef CYGOPT_REDBOOT_FIS |
|---|
| 15 |
extern void *fis_work_block; |
|---|
| 16 |
extern void *fis_addr; |
|---|
| 17 |
extern int fisdir_size; // Size of FIS directory. |
|---|
| 18 |
#endif |
|---|
| 19 |
//extern void _show_invalid_flash_address(CYG_ADDRESS flash_addr, int stat); |
|---|
| 20 |
extern void fis_update_directory(void); |
|---|
| 21 |
|
|---|
| 22 |
//#define TRACE diag_printf("DBG: %s:%d\n", __FUNCTION__, __LINE__) |
|---|
| 23 |
|
|---|
| 24 |
#define TRACE |
|---|
| 25 |
|
|---|
| 26 |
|
|---|
| 27 |
extern void fis_init(int argc, char *argv[], int force); |
|---|
| 28 |
|
|---|
| 29 |
int fw_check_image_senao(unsigned char *addr, unsigned long maxlen, |
|---|
| 30 |
int do_flash) |
|---|
| 31 |
{ |
|---|
| 32 |
unsigned char *base = (unsigned char *)addr+10; |
|---|
| 33 |
if (strncmp(addr,"AP51-3660",9)) { |
|---|
| 34 |
diag_printf("SENAO_FW: bad header\n"); |
|---|
| 35 |
return -1; |
|---|
| 36 |
} |
|---|
| 37 |
|
|---|
| 38 |
if (do_flash) { |
|---|
| 39 |
char *arg[] = { "fis", "init" }; |
|---|
| 40 |
fis_init(2, arg, 1); |
|---|
| 41 |
void *err_addr; |
|---|
| 42 |
flash_read(fis_addr, fis_work_block, fisdir_size, |
|---|
| 43 |
(void **)&err_addr); |
|---|
| 44 |
struct fis_image_desc *img = NULL; |
|---|
| 45 |
int i, stat; |
|---|
| 46 |
img = fis_lookup("RedBoot", &i); |
|---|
| 47 |
if (i != 0) { |
|---|
| 48 |
diag_printf |
|---|
| 49 |
("SENAO_FW: RedBoot partition is not the first partition\n"); |
|---|
| 50 |
return -1; |
|---|
| 51 |
} |
|---|
| 52 |
unsigned int flash_addr = img->flash_base + img->size; |
|---|
| 53 |
if ((stat = |
|---|
| 54 |
flash_erase((void *)flash_addr, maxlen, |
|---|
| 55 |
(void **)&err_addr)) != 0) { |
|---|
| 56 |
diag_printf("SENAO_FW: Can't erase region at %p: %s\n", |
|---|
| 57 |
err_addr, flash_errmsg(stat)); |
|---|
| 58 |
return -1; |
|---|
| 59 |
} |
|---|
| 60 |
if ((stat = |
|---|
| 61 |
flash_program((void *)flash_addr, |
|---|
| 62 |
(void *)(base), |
|---|
| 63 |
maxlen, (void **)&err_addr)) != 0) { |
|---|
| 64 |
diag_printf |
|---|
| 65 |
("SENAO_FW: Can't program region at %p: %s\n", |
|---|
| 66 |
err_addr, flash_errmsg(stat)); |
|---|
| 67 |
return -1; |
|---|
| 68 |
} |
|---|
| 69 |
img = (struct fis_image_desc *)fis_work_block; |
|---|
| 70 |
for (i = 0; i < fisdir_size / sizeof(*img); i++, img++) { |
|---|
| 71 |
if (img->name[0] == (unsigned char)0xFF) { |
|---|
| 72 |
break; |
|---|
| 73 |
} |
|---|
| 74 |
} |
|---|
| 75 |
|
|---|
| 76 |
unsigned int filesyssize = 0x3f0000; |
|---|
| 77 |
unsigned int linuxsize = 0xa0000; |
|---|
| 78 |
unsigned int cfgsize = 0x20000; |
|---|
| 79 |
if (maxlen==3670026) // detect 4M images (EAP3660 etc.) |
|---|
| 80 |
{ |
|---|
| 81 |
filesyssize = 0x2f0000; |
|---|
| 82 |
} |
|---|
| 83 |
strcpy(img->name, "rootfs"); |
|---|
| 84 |
img->flash_base = flash_addr; |
|---|
| 85 |
img->mem_base = 0x80041000; |
|---|
| 86 |
img->entry_point = 0; |
|---|
| 87 |
img->size = filesyssize; |
|---|
| 88 |
img->data_length = filesyssize; |
|---|
| 89 |
img++; |
|---|
| 90 |
strcpy(img->name, "vmlinux.bin.l7"); |
|---|
| 91 |
img->flash_base = flash_addr+filesyssize; |
|---|
| 92 |
img->mem_base = 0x80041000; |
|---|
| 93 |
img->entry_point = 0x80041798; |
|---|
| 94 |
img->size = linuxsize; |
|---|
| 95 |
img->data_length = linuxsize; |
|---|
| 96 |
img++; |
|---|
| 97 |
strcpy(img->name, "cfg"); |
|---|
| 98 |
img->flash_base = flash_addr+filesyssize+linuxsize; |
|---|
| 99 |
img->mem_base = 0x80041000; |
|---|
| 100 |
img->entry_point = 0; |
|---|
| 101 |
img->size = cfgsize; |
|---|
| 102 |
img->data_length = cfgsize; |
|---|
| 103 |
|
|---|
| 104 |
fis_update_directory(); |
|---|
| 105 |
diag_printf("SENAO_FW: flashing done\n"); |
|---|
| 106 |
} |
|---|
| 107 |
return 0; |
|---|
| 108 |
} |
|---|