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

Revision 12376, 2.8 kB (checked in by BrainSlayer, 5 months ago)

merge partition code

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                 if (i != 0) {
52                         diag_printf
53                             ("SENAO_FW: RedBoot partition is not the first partition\n");
54                         return -1;
55                 }
56                 unsigned int flash_addr = img->flash_base + img->size;
57                 if ((stat =
58                      flash_erase((void *)flash_addr, maxlen,
59                                  (void **)&err_addr)) != 0) {
60                         diag_printf("SENAO_FW: Can't erase region at %p: %s\n",
61                                     err_addr, flash_errmsg(stat));
62                         return -1;
63                 }
64                 if ((stat =
65                      flash_program((void *)flash_addr,
66                                    (void *)(base),
67                                    maxlen, (void **)&err_addr)) != 0) {
68                         diag_printf
69                             ("SENAO_FW: Can't program region at %p: %s\n",
70                              err_addr, flash_errmsg(stat));
71                         return -1;
72                 }
73                 img = (struct fis_image_desc *)fis_work_block;
74                 for (i = 0; i < fisdir_size / sizeof(*img); i++, img++) {
75                         if (img->name[0] == (unsigned char)0xFF) {
76                                 break;
77                         }
78                 }
79
80                 unsigned int filesyssize = 0x3f0000;
81                 unsigned int linuxsize = 0xa0000;
82                 unsigned int cfgsize = 0x20000;
83                 unsigned int exec = 0x80041798;
84                 if (maxlen == (3670026 - 10))   // detect 4M images (EAP3660 etc.)
85                 {
86                         filesyssize = 0x2f0000;
87                         exec = 0x80170040;      //weired entrypoint
88                 }
89                 addPartition("rootfs", flash_addr, 0x80041000, 0, filesyssize,
90                              filesyssize);
91                 addPartition("vmlinux.bin.l7", flash_addr + filesyssize,
92                              0x80041000, exec, linuxsize, linuxsize);
93                 addPartition("cfg", flash_addr + filesyssize + linuxsize,
94                              0x80041000, 0, cfgsize, cfgsize);
95                 fis_update_directory();
96                 diag_printf("SENAO_FW: flashing done\n");
97         }
98         return 0;
99 }
Note: See TracBrowser for help on using the browser.