comparison chipsetsw/drivers/drv_app/ffs/board/tdata.c @ 0:509db1a7b7b8

initial import: leo2moko-r1
author Space Falcon <falcon@ivan.Harhan.ORG>
date Mon, 01 Jun 2015 03:24:05 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:509db1a7b7b8
1 /******************************************************************************
2 * Flash File System (ffs)
3 * Idea, design and coding by Mads Meisner-Jensen, mmj@ti.com
4 *
5 * ffs test data
6 *
7 * $Id: tdata.c 1.9 Tue, 14 Oct 2003 12:50:00 +0200 tsj $
8 *
9 ******************************************************************************/
10
11 #ifndef TARGET
12 #include "ffs.cfg"
13 #endif
14
15 #if (TARGET == 1)
16 #include "chipset.cfg"
17 #endif
18
19 #include "ffs/ffs.h"
20 #include "ffs/board/drv.h"
21 #include "ffs/board/tdata.h"
22
23 #if (TARGET == 0)
24 #ifdef WIN32
25 #include "windows.h"
26 #else //WIN32
27 #include "sys/mman.h"
28 #include "unistd.h"
29 #endif //WIN32
30
31 #include <string.h>
32 #include <stdlib.h>
33 #include "stdio.h"
34 #include "sys/types.h"
35 #include "sys/stat.h"
36 #include "fcntl.h"
37 #endif //TARGET == 0
38
39 /******************************************************************************
40 * Globals
41 ******************************************************************************/
42
43 // Buffer for tdata 'HUGE'. In target it point to the flash device, on the
44 // PC a buffer is allocated and filled with data from a c code file.
45 char *tdata_buf;
46
47 int sdata[TEST_DATA_NUM];
48
49 // Initialize test data.
50 int test_tdata_init(void)
51 {
52 int i, error, tdatasize, fsize = 60 * 1024; // Check the file size or?
53
54 #ifdef WIN32
55 DWORD nbytesread;
56 OFSTRUCT lpReOpenBuff;
57 HANDLE fd;
58 char *fname = "../core.c"; // file to use as test data
59 #else
60 char *fname = "core.c";
61 int fd;
62 #endif
63 // Set the size to the maximum image size
64 tdatasize = 8 * 1024 * 1024;
65
66 // Open file NOTEME change to readonly
67 #if (TARGET == 0)
68 #ifdef WIN32
69 fd = OpenFile(fname, &lpReOpenBuff, OF_READ);
70 #else
71 fd = open(fname, O_RDONLY, S_IRWXU|S_IRWXG|S_IRWXO);
72 #endif //WIN32
73 if (fd == -1) {
74 perror("Failed to open flash image"); exit(1);
75 }
76
77 if ((tdata_buf = (char*) malloc(tdatasize)) == 0)
78 return EFFS_MEMORY;
79
80 #ifdef WIN32
81 error = ReadFile(fd, tdata_buf, fsize, &nbytesread, 0);
82 #else
83 error = read(fd, tdata_buf, fsize);
84 #endif
85 if (error < 0) {
86 perror("Failed to read file"); exit(1);
87 }
88
89 #ifdef WIN32
90 error = CloseHandle(fd);
91 #else
92 error = close(fd);
93 #endif
94 if (error < 0) {
95 perror("Failed to close file"); exit(1);
96 }
97
98 // Fill the rest of tdata_buf
99 for (i = 1; i < tdatasize/fsize; i++)
100 memcpy(&tdata_buf[i], &tdata_buf[0], fsize);
101 #endif
102
103 #if (TARGET == 0)
104 // Init tdata
105 tdata[TDATA_HUGE] = tdata_buf;
106 #else
107 #if (CHIPSET == 12) // Calypso+. Do not read from the secure rom
108 tdata[TDATA_HUGE] = (char *) 0x4000000;
109 #else
110 tdata[TDATA_HUGE] = (char *) 0x1;
111 #endif
112 #endif //TARGET == 0
113
114 for (i = 0; i < TEST_DATA_NUM; i++)
115 sdata[i] = strlen(tdata[i]);
116
117 return EFFS_OK;
118 }
119
120 char *tdata[TEST_DATA_NUM] =
121 {
122 // 0
123 "yo",
124
125 // 1
126 "NineBytes",
127
128 // 2
129 "EighteenCharacters",
130
131 // 3
132 "The quick brown fox jumped over the little lazy rabbit then it turned "
133 "around and ate the little stupid bunny."
134 "The brown fox ate too much and became sick.",
135
136 // 4
137 "Foo bar fum fi fo, look high, look low, where it is, i don't know",
138
139 // 5
140 "55555",
141
142 // 6
143 "Two Canadian guys, Mike and Rob were on the roof, laying tile,"
144 "when a sudden gust of wind came and knocked down their ladder."
145 "'I have an idea,' said Mike. 'We'll throw you down, and then"
146 "you can pick up the ladder.'"
147 "What, do you think I'm stupid? I have an idea. I'll shine my"
148 "flashlight, and you can climb down on the beam of light."
149 "What, do you think I'm stupid? You'll just turn off the"
150 "flashlight when I'm halfway there.''",
151
152 // 7
153 "7777777",
154
155 // 8
156 "88888888",
157
158 // 9
159 "999999999",
160
161 // 10
162 "dummy"
163 };
164
165
166