root/ar5315_microredboot/microredboot/ecos/packages/redboot/current/src/net/fwupgrade_senao.c

Revision 12385, 2.7 kB (checked in by BrainSlayer, 5 months ago)

lates image and source changes

Line 
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 extern void addPartition(char *name, unsigned int flashbase,
27                          unsigned int memaddr, unsigned int entryaddr,
28                          unsigned int partsize, unsigned int datasize);
29
30 extern void fis_init(int argc, char *argv[], int force);
31
32 int fw_check_image_senao(unsigned char *addr, unsigned long maxlen,
33                          int do_flash)
34 {
35         unsigned char *base = (unsigned char *)addr + 10;
36         if (strncmp(addr, "AP51-3660", 9)) {
37                 diag_printf("SENAO_FW: bad header\n");
38                 return -1;
39         }
40
41         if (do_flash) {
42                 maxlen -= 10;
43                 char *arg[] = { "fis", "init" };
44                 fis_init(2, arg, 1);
45                 void *err_addr;
46                 flash_read(fis_addr, fis_work_block, fisdir_size,
47                            (void **)&err_addr);
48                 struct fis_image_desc *img = NULL;
49                 int i, stat;
50                 img = fis_lookup("RedBoot", &i);
51                 unsigned int flash_addr = img->flash_base + img->size;
52                 if ((stat =
53                      flash_erase((void *)flash_addr, maxlen,
54                                  (void **)&err_addr)) != 0) {
55                         diag_printf("SENAO_FW: Can't erase region at %p: %s\n",
56                                     err_addr, flash_errmsg(stat));
57                         return -1;
58                 }
59                 if ((stat =
60                      flash_program((void *)flash_addr,
61                                    (void *)(base),
62                                    maxlen, (void **)&err_addr)) != 0) {
63                         diag_printf
64                             ("SENAO_FW: Can't program region at %p: %s\n",
65                              err_addr, flash_errmsg(stat));
66                         return -1;
67                 }
68                 img = (struct fis_image_desc *)fis_work_block;
69                 for (i = 0; i < fisdir_size / sizeof(*img); i++, img++) {
70                         if (img->name[0] == (unsigned char)0xFF) {
71                                 break;
72                         }
73                 }
74
75                 unsigned int filesyssize = 0x3f0000;
76                 unsigned int linuxsize = 0xa0000;
77                 unsigned int cfgsize = 0x20000;
78                 unsigned int exec = 0x80041798;
79                 if (maxlen == (3670026 - 10))   // detect 4M images (EAP3660 etc.)
80                 {
81                         filesyssize = 0x2f0000;
82                         exec = 0x80170040;      //weired entrypoint
83                 }
84                 addPartition("rootfs", flash_addr, 0x80041000, 0, filesyssize,
85                              filesyssize);
86                 addPartition("vmlinux.bin.l7", flash_addr + filesyssize,
87                              0x80041000, exec, linuxsize, linuxsize);
88                 addPartition("cfg", flash_addr + filesyssize + linuxsize,
89                              0x80041000, 0, cfgsize, cfgsize);
90                 fis_update_directory();
91                 diag_printf("SENAO_FW: flashing done\n");
92         }
93         return 0;
94 }
Note: See TracBrowser for help on using the browser.