FreeCalypso > hg > freecalypso-sw
annotate target-utils/libtiffs/init.c @ 981:0feb3db6f097
fc-olddump written, compiles
author | Mychaela Falconia <falcon@ivan.Harhan.ORG> |
---|---|
date | Thu, 10 Dec 2015 05:16:46 +0000 |
parents | 2900fe603f8a |
children |
rev | line source |
---|---|
100
02ece4d8c755
pirexplore: beginning of FFS support
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1 #include "types.h" |
02ece4d8c755
pirexplore: beginning of FFS support
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
2 #include "struct.h" |
02ece4d8c755
pirexplore: beginning of FFS support
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
3 #include "globals.h" |
02ece4d8c755
pirexplore: beginning of FFS support
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
4 #include "macros.h" |
02ece4d8c755
pirexplore: beginning of FFS support
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
5 |
02ece4d8c755
pirexplore: beginning of FFS support
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
6 static const u8 ffs_sector_signature[6] = {'F', 'f', 's', '#', 0x10, 0x02}; |
02ece4d8c755
pirexplore: beginning of FFS support
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
7 static const u8 blank_flash_line[16] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, |
02ece4d8c755
pirexplore: beginning of FFS support
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
8 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, |
02ece4d8c755
pirexplore: beginning of FFS support
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
9 0xFF, 0xFF, 0xFF, 0xFF}; |
02ece4d8c755
pirexplore: beginning of FFS support
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
10 |
02ece4d8c755
pirexplore: beginning of FFS support
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
11 static |
02ece4d8c755
pirexplore: beginning of FFS support
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
12 find_indexblk() |
02ece4d8c755
pirexplore: beginning of FFS support
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
13 { |
02ece4d8c755
pirexplore: beginning of FFS support
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
14 u32 sector_addr; |
02ece4d8c755
pirexplore: beginning of FFS support
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
15 u8 *sector_ptr; |
02ece4d8c755
pirexplore: beginning of FFS support
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
16 int i; |
02ece4d8c755
pirexplore: beginning of FFS support
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
17 |
02ece4d8c755
pirexplore: beginning of FFS support
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
18 printf("Looking for MPFFS active index block\n"); |
02ece4d8c755
pirexplore: beginning of FFS support
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
19 sector_addr = mpffs_base_addr; |
02ece4d8c755
pirexplore: beginning of FFS support
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
20 for (i = 0; i < mpffs_nsectors; i++) { |
02ece4d8c755
pirexplore: beginning of FFS support
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
21 sector_ptr = (u8 *) sector_addr; |
02ece4d8c755
pirexplore: beginning of FFS support
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
22 if (!bcmp(sector_ptr, ffs_sector_signature, 6) && |
02ece4d8c755
pirexplore: beginning of FFS support
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
23 sector_ptr[8] == 0xAB) { |
02ece4d8c755
pirexplore: beginning of FFS support
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
24 printf("Found at %08X\n", sector_addr); |
02ece4d8c755
pirexplore: beginning of FFS support
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
25 mpffs_active_index = (struct inode *) sector_ptr; |
02ece4d8c755
pirexplore: beginning of FFS support
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
26 return(0); |
02ece4d8c755
pirexplore: beginning of FFS support
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
27 } |
02ece4d8c755
pirexplore: beginning of FFS support
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
28 sector_addr += mpffs_sector_size; |
02ece4d8c755
pirexplore: beginning of FFS support
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
29 } |
02ece4d8c755
pirexplore: beginning of FFS support
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
30 printf("Error: Not found in any of the %d candidate sectors\n", |
02ece4d8c755
pirexplore: beginning of FFS support
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
31 mpffs_nsectors); |
02ece4d8c755
pirexplore: beginning of FFS support
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
32 return(-1); |
02ece4d8c755
pirexplore: beginning of FFS support
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
33 } |
02ece4d8c755
pirexplore: beginning of FFS support
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
34 |
02ece4d8c755
pirexplore: beginning of FFS support
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
35 static |
02ece4d8c755
pirexplore: beginning of FFS support
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
36 find_rootino() |
02ece4d8c755
pirexplore: beginning of FFS support
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
37 { |
02ece4d8c755
pirexplore: beginning of FFS support
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
38 int ino; |
02ece4d8c755
pirexplore: beginning of FFS support
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
39 struct inode *irec; |
02ece4d8c755
pirexplore: beginning of FFS support
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
40 |
02ece4d8c755
pirexplore: beginning of FFS support
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
41 printf("Looking for the root inode\n"); |
02ece4d8c755
pirexplore: beginning of FFS support
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
42 for (ino = 1; ; ino++) { |
02ece4d8c755
pirexplore: beginning of FFS support
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
43 if (ino >= mpffs_sector_size >> 4) { |
02ece4d8c755
pirexplore: beginning of FFS support
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
44 printf("Error: Hit end of sector, no root inode found\n"); |
02ece4d8c755
pirexplore: beginning of FFS support
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
45 return(-1); |
02ece4d8c755
pirexplore: beginning of FFS support
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
46 } |
02ece4d8c755
pirexplore: beginning of FFS support
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
47 irec = mpffs_active_index + ino; |
02ece4d8c755
pirexplore: beginning of FFS support
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
48 if (!bcmp((u8 *) irec, blank_flash_line, 16)) { |
02ece4d8c755
pirexplore: beginning of FFS support
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
49 printf("Error: Hit blank flash, no root inode found\n"); |
02ece4d8c755
pirexplore: beginning of FFS support
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
50 return(-1); |
02ece4d8c755
pirexplore: beginning of FFS support
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
51 } |
02ece4d8c755
pirexplore: beginning of FFS support
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
52 if (irec->type == OBJTYPE_DIR && *inode_to_dataptr(irec) == '/') |
02ece4d8c755
pirexplore: beginning of FFS support
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
53 break; |
02ece4d8c755
pirexplore: beginning of FFS support
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
54 } |
02ece4d8c755
pirexplore: beginning of FFS support
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
55 printf("Found at inode #%x\n", ino); |
02ece4d8c755
pirexplore: beginning of FFS support
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
56 mpffs_root_ino = ino; |
02ece4d8c755
pirexplore: beginning of FFS support
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
57 return(0); |
02ece4d8c755
pirexplore: beginning of FFS support
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
58 } |
02ece4d8c755
pirexplore: beginning of FFS support
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
59 |
02ece4d8c755
pirexplore: beginning of FFS support
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
60 mpffs_init() |
02ece4d8c755
pirexplore: beginning of FFS support
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
61 { |
02ece4d8c755
pirexplore: beginning of FFS support
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
62 int stat; |
02ece4d8c755
pirexplore: beginning of FFS support
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
63 |
02ece4d8c755
pirexplore: beginning of FFS support
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
64 if (mpffs_init_done) |
02ece4d8c755
pirexplore: beginning of FFS support
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
65 return(0); |
02ece4d8c755
pirexplore: beginning of FFS support
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
66 stat = find_indexblk(); |
02ece4d8c755
pirexplore: beginning of FFS support
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
67 if (stat < 0) |
02ece4d8c755
pirexplore: beginning of FFS support
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
68 return(stat); |
02ece4d8c755
pirexplore: beginning of FFS support
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
69 stat = find_rootino(); |
02ece4d8c755
pirexplore: beginning of FFS support
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
70 if (stat < 0) |
02ece4d8c755
pirexplore: beginning of FFS support
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
71 return(stat); |
02ece4d8c755
pirexplore: beginning of FFS support
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
72 mpffs_init_done = 1; |
02ece4d8c755
pirexplore: beginning of FFS support
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
73 return(0); |
02ece4d8c755
pirexplore: beginning of FFS support
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
74 } |