aboutsummaryrefslogtreecommitdiffstats
path: root/arch/powerpc/boot/dtc-src/data.c
diff options
context:
space:
mode:
authorDavid Gibson <david@gibson.dropbear.id.au>2008-08-06 22:24:17 -0400
committerPaul Mackerras <paulus@samba.org>2008-08-20 02:34:58 -0400
commited95d7450dcbfeb45ffc9d39b1747aee82b49a51 (patch)
treefaca7d89e2907e1407161f967477ed2ae21d46bb /arch/powerpc/boot/dtc-src/data.c
parent0ec27c049d80535f77901654a310b090106b046c (diff)
powerpc: Update in-kernel dtc and libfdt to version 1.2.0
Some time ago, a copies of the upstream dtc and libfdt sources were included in the kernel tree to avoid having these as external dependencies for building the kernel. Since then development on the upstream dtc and libfdt has continued. This updates the in-kernel versions to match the recently released upstream dtc version 1.2.0. This includes a number of bugfixes, many cleanups and a few new features. Signed-off-by: David Gibson <david@gibson.dropbear.id.au> Signed-off-by: Paul Mackerras <paulus@samba.org>
Diffstat (limited to 'arch/powerpc/boot/dtc-src/data.c')
-rw-r--r--arch/powerpc/boot/dtc-src/data.c62
1 files changed, 31 insertions, 31 deletions
diff --git a/arch/powerpc/boot/dtc-src/data.c b/arch/powerpc/boot/dtc-src/data.c
index a94718c731a9..dd2e3d39d4c1 100644
--- a/arch/powerpc/boot/dtc-src/data.c
+++ b/arch/powerpc/boot/dtc-src/data.c
@@ -32,8 +32,6 @@ void data_free(struct data d)
32 m = nm; 32 m = nm;
33 } 33 }
34 34
35 assert(!d.val || d.asize);
36
37 if (d.val) 35 if (d.val)
38 free(d.val); 36 free(d.val);
39} 37}
@@ -43,9 +41,6 @@ struct data data_grow_for(struct data d, int xlen)
43 struct data nd; 41 struct data nd;
44 int newsize; 42 int newsize;
45 43
46 /* we must start with an allocated datum */
47 assert(!d.val || d.asize);
48
49 if (xlen == 0) 44 if (xlen == 0)
50 return d; 45 return d;
51 46
@@ -56,11 +51,8 @@ struct data data_grow_for(struct data d, int xlen)
56 while ((d.len + xlen) > newsize) 51 while ((d.len + xlen) > newsize)
57 newsize *= 2; 52 newsize *= 2;
58 53
59 nd.asize = newsize;
60 nd.val = xrealloc(d.val, newsize); 54 nd.val = xrealloc(d.val, newsize);
61 55
62 assert(nd.asize >= (d.len + xlen));
63
64 return nd; 56 return nd;
65} 57}
66 58
@@ -83,16 +75,11 @@ static char get_oct_char(const char *s, int *i)
83 long val; 75 long val;
84 76
85 x[3] = '\0'; 77 x[3] = '\0';
86 x[0] = s[(*i)]; 78 strncpy(x, s + *i, 3);
87 if (x[0]) {
88 x[1] = s[(*i)+1];
89 if (x[1])
90 x[2] = s[(*i)+2];
91 }
92 79
93 val = strtol(x, &endx, 8); 80 val = strtol(x, &endx, 8);
94 if ((endx - x) == 0) 81
95 fprintf(stderr, "Empty \\nnn escape\n"); 82 assert(endx > x);
96 83
97 (*i) += endx - x; 84 (*i) += endx - x;
98 return val; 85 return val;
@@ -105,13 +92,11 @@ static char get_hex_char(const char *s, int *i)
105 long val; 92 long val;
106 93
107 x[2] = '\0'; 94 x[2] = '\0';
108 x[0] = s[(*i)]; 95 strncpy(x, s + *i, 2);
109 if (x[0])
110 x[1] = s[(*i)+1];
111 96
112 val = strtol(x, &endx, 16); 97 val = strtol(x, &endx, 16);
113 if ((endx - x) == 0) 98 if (!(endx > x))
114 fprintf(stderr, "Empty \\x escape\n"); 99 die("\\x used with no following hex digits\n");
115 100
116 (*i) += endx - x; 101 (*i) += endx - x;
117 return val; 102 return val;
@@ -182,14 +167,29 @@ struct data data_copy_escape_string(const char *s, int len)
182 return d; 167 return d;
183} 168}
184 169
185struct data data_copy_file(FILE *f, size_t len) 170struct data data_copy_file(FILE *f, size_t maxlen)
186{ 171{
187 struct data d; 172 struct data d = empty_data;
188 173
189 d = data_grow_for(empty_data, len); 174 while (!feof(f) && (d.len < maxlen)) {
175 size_t chunksize, ret;
190 176
191 d.len = len; 177 if (maxlen == -1)
192 fread(d.val, len, 1, f); 178 chunksize = 4096;
179 else
180 chunksize = maxlen - d.len;
181
182 d = data_grow_for(d, chunksize);
183 ret = fread(d.val + d.len, 1, chunksize, f);
184
185 if (ferror(f))
186 die("Error reading file into data: %s", strerror(errno));
187
188 if (d.len + ret < d.len)
189 die("Overflow reading file into data\n");
190
191 d.len += ret;
192 }
193 193
194 return d; 194 return d;
195} 195}
@@ -247,7 +247,7 @@ struct data data_merge(struct data d1, struct data d2)
247 247
248struct data data_append_cell(struct data d, cell_t word) 248struct data data_append_cell(struct data d, cell_t word)
249{ 249{
250 cell_t beword = cpu_to_be32(word); 250 cell_t beword = cpu_to_fdt32(word);
251 251
252 return data_append_data(d, &beword, sizeof(beword)); 252 return data_append_data(d, &beword, sizeof(beword));
253} 253}
@@ -256,15 +256,15 @@ struct data data_append_re(struct data d, const struct fdt_reserve_entry *re)
256{ 256{
257 struct fdt_reserve_entry bere; 257 struct fdt_reserve_entry bere;
258 258
259 bere.address = cpu_to_be64(re->address); 259 bere.address = cpu_to_fdt64(re->address);
260 bere.size = cpu_to_be64(re->size); 260 bere.size = cpu_to_fdt64(re->size);
261 261
262 return data_append_data(d, &bere, sizeof(bere)); 262 return data_append_data(d, &bere, sizeof(bere));
263} 263}
264 264
265struct data data_append_addr(struct data d, u64 addr) 265struct data data_append_addr(struct data d, uint64_t addr)
266{ 266{
267 u64 beaddr = cpu_to_be64(addr); 267 uint64_t beaddr = cpu_to_fdt64(addr);
268 268
269 return data_append_data(d, &beaddr, sizeof(beaddr)); 269 return data_append_data(d, &beaddr, sizeof(beaddr));
270} 270}