root/ar5315_microredboot/microredboot/boot/src/lib/fis.c

Revision 12370, 2.0 kB (checked in by BrainSlayer, 5 months ago)

support for senao firmware format

Line 
1 /*
2  * fis.c - simple redboot partition parser
3  *
4  * copyright 2009 Sebastian Gottschall / NewMedia-NET GmbH / DD-WRT.COM
5  * licensed under GPL conditions
6  */
7
8 struct fis_image_desc {
9         unsigned char name[16]; // Null terminated name
10         unsigned long flash_base;       // Address within FLASH of image
11         unsigned long mem_base; // Address in memory where it executes
12         unsigned long size;     // Length of image
13         unsigned long entry_point;      // Execution entry point
14         unsigned long data_length;      // Length of actual data
15         unsigned char _pad[256 - (16 + 7 * sizeof(unsigned long))];
16         unsigned long desc_cksum;       // Checksum over image descriptor
17         unsigned long file_cksum;       // Checksum over image data
18 };
19
20 static unsigned int getPartition(char *name)
21 {
22         int count = 0;
23         unsigned char *p =
24             (unsigned char *)(flashbase + flashsize - (sectorsize * 2));
25         struct fis_image_desc *fis = (struct fis_image_desc *)p;
26         while (fis->name[0] != 0xff && count < 10) {
27                 if (!strncmp(fis->name, name, strlen(name)))
28                         return fis->flash_base;
29         }
30         return 0;
31 }
32
33 /*
34  * searches for a directory entry named linux* vmlinux* or kernel and returns its flash address (it also initializes entrypoint and load address)
35  */
36 static unsigned int getLinux(void)
37 {
38         int count = 0;
39         unsigned char *p =
40             (unsigned char *)(flashbase + flashsize - (sectorsize * 2));
41         struct fis_image_desc *fis = (struct fis_image_desc *)p;
42         /* search for fis partiton linux*,vmlinux* or kernel */
43         while (fis->name[0] != 0xff && count < 10) {
44                 if (!strncmp(fis->name, "linux", 5)
45                     || !strncmp(fis->name, "vmlinux", 7)
46                     || !strcmp(fis->name, "kernel")) {
47                         printf
48                             ("found bootable image: [%s] at [0x%08X] EP [0x%08X]\n",
49                              fis->name, fis->flash_base, fis->entry_point);
50                         bootoffset = fis->entry_point;
51                         output_data = (uch *) fis->mem_base;
52                         return fis->flash_base;
53                 }
54                 p += 256;
55                 fis = (struct fis_image_desc *)p;
56                 count++;
57         }
58         puts("no bootable image found, try default location 0xbfc10000\n");
59         bootoffset = 0x80041000;
60         output_data = (uch *) 0x80041000;
61         return 0xbfc10000;      //first available address after bootloader
62 }
Note: See TracBrowser for help on using the browser.