comparison target-utils/libtiffs/init.c @ 224:2900fe603f8a

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