David Gibson | fc14dad | 2005-06-08 17:18:34 +1000 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright David Gibson <dwg@au1.ibm.com>, IBM Corporation. 2005. |
| 3 | * |
David Gibson | 63dc9c7 | 2007-09-18 11:44:04 +1000 | [diff] [blame] | 4 | * |
David Gibson | fc14dad | 2005-06-08 17:18:34 +1000 | [diff] [blame] | 5 | * This program is free software; you can redistribute it and/or |
| 6 | * modify it under the terms of the GNU General Public License as |
| 7 | * published by the Free Software Foundation; either version 2 of the |
| 8 | * License, or (at your option) any later version. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 | * General Public License for more details. |
David Gibson | 63dc9c7 | 2007-09-18 11:44:04 +1000 | [diff] [blame] | 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program; if not, write to the Free Software |
| 17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 |
| 18 | * USA |
David Gibson | fc14dad | 2005-06-08 17:18:34 +1000 | [diff] [blame] | 19 | */ |
| 20 | |
| 21 | #include "dtc.h" |
David Gibson | a742aad | 2008-05-16 13:22:09 +1000 | [diff] [blame] | 22 | #include "srcpos.h" |
David Gibson | fc14dad | 2005-06-08 17:18:34 +1000 | [diff] [blame] | 23 | |
| 24 | #define FTF_FULLPATH 0x1 |
| 25 | #define FTF_VARALIGN 0x2 |
| 26 | #define FTF_NAMEPROPS 0x4 |
| 27 | #define FTF_BOOTCPUID 0x8 |
| 28 | #define FTF_STRTABSIZE 0x10 |
David Gibson | 46c88df | 2007-03-14 11:02:40 +1100 | [diff] [blame] | 29 | #define FTF_STRUCTSIZE 0x20 |
Milton Miller | ce24322 | 2007-06-09 23:21:31 -0500 | [diff] [blame] | 30 | #define FTF_NOPS 0x40 |
David Gibson | fc14dad | 2005-06-08 17:18:34 +1000 | [diff] [blame] | 31 | |
David Gibson | 230f253 | 2005-08-29 12:48:02 +1000 | [diff] [blame] | 32 | static struct version_info { |
David Gibson | fc14dad | 2005-06-08 17:18:34 +1000 | [diff] [blame] | 33 | int version; |
| 34 | int last_comp_version; |
| 35 | int hdr_size; |
| 36 | int flags; |
| 37 | } version_table[] = { |
David Gibson | fb7c7ac | 2007-09-26 13:11:05 +1000 | [diff] [blame] | 38 | {1, 1, FDT_V1_SIZE, |
David Gibson | fc14dad | 2005-06-08 17:18:34 +1000 | [diff] [blame] | 39 | FTF_FULLPATH|FTF_VARALIGN|FTF_NAMEPROPS}, |
David Gibson | fb7c7ac | 2007-09-26 13:11:05 +1000 | [diff] [blame] | 40 | {2, 1, FDT_V2_SIZE, |
David Gibson | fc14dad | 2005-06-08 17:18:34 +1000 | [diff] [blame] | 41 | FTF_FULLPATH|FTF_VARALIGN|FTF_NAMEPROPS|FTF_BOOTCPUID}, |
David Gibson | fb7c7ac | 2007-09-26 13:11:05 +1000 | [diff] [blame] | 42 | {3, 1, FDT_V3_SIZE, |
David Gibson | fc14dad | 2005-06-08 17:18:34 +1000 | [diff] [blame] | 43 | FTF_FULLPATH|FTF_VARALIGN|FTF_NAMEPROPS|FTF_BOOTCPUID|FTF_STRTABSIZE}, |
David Gibson | fb7c7ac | 2007-09-26 13:11:05 +1000 | [diff] [blame] | 44 | {16, 16, FDT_V3_SIZE, |
Milton Miller | ce24322 | 2007-06-09 23:21:31 -0500 | [diff] [blame] | 45 | FTF_BOOTCPUID|FTF_STRTABSIZE|FTF_NOPS}, |
David Gibson | fb7c7ac | 2007-09-26 13:11:05 +1000 | [diff] [blame] | 46 | {17, 16, FDT_V17_SIZE, |
Milton Miller | ce24322 | 2007-06-09 23:21:31 -0500 | [diff] [blame] | 47 | FTF_BOOTCPUID|FTF_STRTABSIZE|FTF_STRUCTSIZE|FTF_NOPS}, |
David Gibson | fc14dad | 2005-06-08 17:18:34 +1000 | [diff] [blame] | 48 | }; |
| 49 | |
| 50 | struct emitter { |
| 51 | void (*cell)(void *, cell_t); |
| 52 | void (*string)(void *, char *, int); |
| 53 | void (*align)(void *, int); |
| 54 | void (*data)(void *, struct data); |
David Gibson | 92cb9a2 | 2007-12-04 14:26:15 +1100 | [diff] [blame] | 55 | void (*beginnode)(void *, const char *); |
| 56 | void (*endnode)(void *, const char *); |
| 57 | void (*property)(void *, const char *); |
David Gibson | fc14dad | 2005-06-08 17:18:34 +1000 | [diff] [blame] | 58 | }; |
| 59 | |
| 60 | static void bin_emit_cell(void *e, cell_t val) |
| 61 | { |
| 62 | struct data *dtbuf = e; |
| 63 | |
| 64 | *dtbuf = data_append_cell(*dtbuf, val); |
| 65 | } |
| 66 | |
| 67 | static void bin_emit_string(void *e, char *str, int len) |
| 68 | { |
| 69 | struct data *dtbuf = e; |
| 70 | |
| 71 | if (len == 0) |
| 72 | len = strlen(str); |
| 73 | |
| 74 | *dtbuf = data_append_data(*dtbuf, str, len); |
| 75 | *dtbuf = data_append_byte(*dtbuf, '\0'); |
| 76 | } |
| 77 | |
| 78 | static void bin_emit_align(void *e, int a) |
| 79 | { |
| 80 | struct data *dtbuf = e; |
| 81 | |
| 82 | *dtbuf = data_append_align(*dtbuf, a); |
| 83 | } |
| 84 | |
| 85 | static void bin_emit_data(void *e, struct data d) |
| 86 | { |
| 87 | struct data *dtbuf = e; |
| 88 | |
| 89 | *dtbuf = data_append_data(*dtbuf, d.val, d.len); |
| 90 | } |
| 91 | |
David Gibson | 92cb9a2 | 2007-12-04 14:26:15 +1100 | [diff] [blame] | 92 | static void bin_emit_beginnode(void *e, const char *label) |
David Gibson | fc14dad | 2005-06-08 17:18:34 +1000 | [diff] [blame] | 93 | { |
David Gibson | fb7c7ac | 2007-09-26 13:11:05 +1000 | [diff] [blame] | 94 | bin_emit_cell(e, FDT_BEGIN_NODE); |
David Gibson | fc14dad | 2005-06-08 17:18:34 +1000 | [diff] [blame] | 95 | } |
| 96 | |
David Gibson | 92cb9a2 | 2007-12-04 14:26:15 +1100 | [diff] [blame] | 97 | static void bin_emit_endnode(void *e, const char *label) |
David Gibson | fc14dad | 2005-06-08 17:18:34 +1000 | [diff] [blame] | 98 | { |
David Gibson | fb7c7ac | 2007-09-26 13:11:05 +1000 | [diff] [blame] | 99 | bin_emit_cell(e, FDT_END_NODE); |
David Gibson | fc14dad | 2005-06-08 17:18:34 +1000 | [diff] [blame] | 100 | } |
| 101 | |
David Gibson | 92cb9a2 | 2007-12-04 14:26:15 +1100 | [diff] [blame] | 102 | static void bin_emit_property(void *e, const char *label) |
David Gibson | fc14dad | 2005-06-08 17:18:34 +1000 | [diff] [blame] | 103 | { |
David Gibson | fb7c7ac | 2007-09-26 13:11:05 +1000 | [diff] [blame] | 104 | bin_emit_cell(e, FDT_PROP); |
David Gibson | fc14dad | 2005-06-08 17:18:34 +1000 | [diff] [blame] | 105 | } |
| 106 | |
David Gibson | 230f253 | 2005-08-29 12:48:02 +1000 | [diff] [blame] | 107 | static struct emitter bin_emitter = { |
David Gibson | fc14dad | 2005-06-08 17:18:34 +1000 | [diff] [blame] | 108 | .cell = bin_emit_cell, |
| 109 | .string = bin_emit_string, |
| 110 | .align = bin_emit_align, |
| 111 | .data = bin_emit_data, |
| 112 | .beginnode = bin_emit_beginnode, |
| 113 | .endnode = bin_emit_endnode, |
David Gibson | 63dc9c7 | 2007-09-18 11:44:04 +1000 | [diff] [blame] | 114 | .property = bin_emit_property, |
David Gibson | fc14dad | 2005-06-08 17:18:34 +1000 | [diff] [blame] | 115 | }; |
| 116 | |
David Gibson | 92cb9a2 | 2007-12-04 14:26:15 +1100 | [diff] [blame] | 117 | static void emit_label(FILE *f, const char *prefix, const char *label) |
David Gibson | 4102d84 | 2005-06-16 14:36:37 +1000 | [diff] [blame] | 118 | { |
| 119 | fprintf(f, "\t.globl\t%s_%s\n", prefix, label); |
| 120 | fprintf(f, "%s_%s:\n", prefix, label); |
| 121 | fprintf(f, "_%s_%s:\n", prefix, label); |
| 122 | } |
| 123 | |
David Gibson | 92cb9a2 | 2007-12-04 14:26:15 +1100 | [diff] [blame] | 124 | static void emit_offset_label(FILE *f, const char *label, int offset) |
Milton Miller | 6a99b13 | 2007-07-07 01:18:51 -0500 | [diff] [blame] | 125 | { |
| 126 | fprintf(f, "\t.globl\t%s\n", label); |
| 127 | fprintf(f, "%s\t= . + %d\n", label, offset); |
| 128 | } |
| 129 | |
David Gibson | fc14dad | 2005-06-08 17:18:34 +1000 | [diff] [blame] | 130 | static void asm_emit_cell(void *e, cell_t val) |
| 131 | { |
| 132 | FILE *f = e; |
| 133 | |
Mark A. Greer | 7a9f663 | 2006-03-15 18:59:24 -0700 | [diff] [blame] | 134 | fprintf(f, "\t.long\t0x%x\n", val); |
David Gibson | fc14dad | 2005-06-08 17:18:34 +1000 | [diff] [blame] | 135 | } |
| 136 | |
| 137 | static void asm_emit_string(void *e, char *str, int len) |
| 138 | { |
| 139 | FILE *f = e; |
Jon Loeliger | 2d50f8f | 2007-10-18 09:46:52 -0500 | [diff] [blame] | 140 | char c = 0; |
David Gibson | fc14dad | 2005-06-08 17:18:34 +1000 | [diff] [blame] | 141 | |
| 142 | if (len != 0) { |
| 143 | /* XXX: ewww */ |
| 144 | c = str[len]; |
| 145 | str[len] = '\0'; |
| 146 | } |
David Gibson | 63dc9c7 | 2007-09-18 11:44:04 +1000 | [diff] [blame] | 147 | |
David Gibson | fc14dad | 2005-06-08 17:18:34 +1000 | [diff] [blame] | 148 | fprintf(f, "\t.string\t\"%s\"\n", str); |
| 149 | |
| 150 | if (len != 0) { |
| 151 | str[len] = c; |
| 152 | } |
| 153 | } |
| 154 | |
| 155 | static void asm_emit_align(void *e, int a) |
| 156 | { |
| 157 | FILE *f = e; |
| 158 | |
| 159 | fprintf(f, "\t.balign\t%d\n", a); |
| 160 | } |
| 161 | |
| 162 | static void asm_emit_data(void *e, struct data d) |
| 163 | { |
| 164 | FILE *f = e; |
| 165 | int off = 0; |
David Gibson | 5ac97df | 2008-02-28 20:58:28 +1100 | [diff] [blame] | 166 | struct marker *m = d.markers; |
Milton Miller | 6a99b13 | 2007-07-07 01:18:51 -0500 | [diff] [blame] | 167 | |
David Gibson | 5ac97df | 2008-02-28 20:58:28 +1100 | [diff] [blame] | 168 | for_each_marker_of_type(m, LABEL) |
| 169 | emit_offset_label(f, m->ref, m->offset); |
David Gibson | fc14dad | 2005-06-08 17:18:34 +1000 | [diff] [blame] | 170 | |
David Gibson | 5335901 | 2008-06-25 13:53:07 +1000 | [diff] [blame^] | 171 | while ((d.len - off) >= sizeof(uint32_t)) { |
David Gibson | fc14dad | 2005-06-08 17:18:34 +1000 | [diff] [blame] | 172 | fprintf(f, "\t.long\t0x%x\n", |
David Gibson | 5335901 | 2008-06-25 13:53:07 +1000 | [diff] [blame^] | 173 | be32_to_cpu(*((uint32_t *)(d.val+off)))); |
| 174 | off += sizeof(uint32_t); |
David Gibson | fc14dad | 2005-06-08 17:18:34 +1000 | [diff] [blame] | 175 | } |
| 176 | |
David Gibson | 5335901 | 2008-06-25 13:53:07 +1000 | [diff] [blame^] | 177 | if ((d.len - off) >= sizeof(uint16_t)) { |
David Gibson | 63dc9c7 | 2007-09-18 11:44:04 +1000 | [diff] [blame] | 178 | fprintf(f, "\t.short\t0x%hx\n", |
David Gibson | 5335901 | 2008-06-25 13:53:07 +1000 | [diff] [blame^] | 179 | be16_to_cpu(*((uint16_t *)(d.val+off)))); |
| 180 | off += sizeof(uint16_t); |
David Gibson | fc14dad | 2005-06-08 17:18:34 +1000 | [diff] [blame] | 181 | } |
| 182 | |
| 183 | if ((d.len - off) >= 1) { |
| 184 | fprintf(f, "\t.byte\t0x%hhx\n", d.val[off]); |
| 185 | off += 1; |
| 186 | } |
| 187 | |
| 188 | assert(off == d.len); |
| 189 | } |
| 190 | |
David Gibson | 92cb9a2 | 2007-12-04 14:26:15 +1100 | [diff] [blame] | 191 | static void asm_emit_beginnode(void *e, const char *label) |
David Gibson | fc14dad | 2005-06-08 17:18:34 +1000 | [diff] [blame] | 192 | { |
| 193 | FILE *f = e; |
| 194 | |
David Gibson | 4102d84 | 2005-06-16 14:36:37 +1000 | [diff] [blame] | 195 | if (label) { |
| 196 | fprintf(f, "\t.globl\t%s\n", label); |
| 197 | fprintf(f, "%s:\n", label); |
| 198 | } |
David Gibson | fb7c7ac | 2007-09-26 13:11:05 +1000 | [diff] [blame] | 199 | fprintf(f, "\t.long\tFDT_BEGIN_NODE\n"); |
David Gibson | fc14dad | 2005-06-08 17:18:34 +1000 | [diff] [blame] | 200 | } |
| 201 | |
David Gibson | 92cb9a2 | 2007-12-04 14:26:15 +1100 | [diff] [blame] | 202 | static void asm_emit_endnode(void *e, const char *label) |
David Gibson | fc14dad | 2005-06-08 17:18:34 +1000 | [diff] [blame] | 203 | { |
| 204 | FILE *f = e; |
| 205 | |
David Gibson | fb7c7ac | 2007-09-26 13:11:05 +1000 | [diff] [blame] | 206 | fprintf(f, "\t.long\tFDT_END_NODE\n"); |
David Gibson | 4102d84 | 2005-06-16 14:36:37 +1000 | [diff] [blame] | 207 | if (label) { |
| 208 | fprintf(f, "\t.globl\t%s_end\n", label); |
| 209 | fprintf(f, "%s_end:\n", label); |
| 210 | } |
David Gibson | fc14dad | 2005-06-08 17:18:34 +1000 | [diff] [blame] | 211 | } |
| 212 | |
David Gibson | 92cb9a2 | 2007-12-04 14:26:15 +1100 | [diff] [blame] | 213 | static void asm_emit_property(void *e, const char *label) |
David Gibson | fc14dad | 2005-06-08 17:18:34 +1000 | [diff] [blame] | 214 | { |
| 215 | FILE *f = e; |
| 216 | |
David Gibson | 4102d84 | 2005-06-16 14:36:37 +1000 | [diff] [blame] | 217 | if (label) { |
| 218 | fprintf(f, "\t.globl\t%s\n", label); |
| 219 | fprintf(f, "%s:\n", label); |
| 220 | } |
David Gibson | fb7c7ac | 2007-09-26 13:11:05 +1000 | [diff] [blame] | 221 | fprintf(f, "\t.long\tFDT_PROP\n"); |
David Gibson | fc14dad | 2005-06-08 17:18:34 +1000 | [diff] [blame] | 222 | } |
| 223 | |
David Gibson | 230f253 | 2005-08-29 12:48:02 +1000 | [diff] [blame] | 224 | static struct emitter asm_emitter = { |
David Gibson | fc14dad | 2005-06-08 17:18:34 +1000 | [diff] [blame] | 225 | .cell = asm_emit_cell, |
| 226 | .string = asm_emit_string, |
| 227 | .align = asm_emit_align, |
| 228 | .data = asm_emit_data, |
| 229 | .beginnode = asm_emit_beginnode, |
| 230 | .endnode = asm_emit_endnode, |
David Gibson | 63dc9c7 | 2007-09-18 11:44:04 +1000 | [diff] [blame] | 231 | .property = asm_emit_property, |
David Gibson | fc14dad | 2005-06-08 17:18:34 +1000 | [diff] [blame] | 232 | }; |
| 233 | |
David Gibson | 92cb9a2 | 2007-12-04 14:26:15 +1100 | [diff] [blame] | 234 | static int stringtable_insert(struct data *d, const char *str) |
David Gibson | fc14dad | 2005-06-08 17:18:34 +1000 | [diff] [blame] | 235 | { |
| 236 | int i; |
| 237 | |
| 238 | /* FIXME: do this more efficiently? */ |
| 239 | |
| 240 | for (i = 0; i < d->len; i++) { |
| 241 | if (streq(str, d->val + i)) |
| 242 | return i; |
| 243 | } |
| 244 | |
| 245 | *d = data_append_data(*d, str, strlen(str)+1); |
David Gibson | a6c6957 | 2005-07-11 17:09:42 +1000 | [diff] [blame] | 246 | return i; |
David Gibson | fc14dad | 2005-06-08 17:18:34 +1000 | [diff] [blame] | 247 | } |
| 248 | |
| 249 | static void flatten_tree(struct node *tree, struct emitter *emit, |
| 250 | void *etarget, struct data *strbuf, |
| 251 | struct version_info *vi) |
| 252 | { |
| 253 | struct property *prop; |
| 254 | struct node *child; |
| 255 | int seen_name_prop = 0; |
| 256 | |
David Gibson | 4102d84 | 2005-06-16 14:36:37 +1000 | [diff] [blame] | 257 | emit->beginnode(etarget, tree->label); |
David Gibson | fc14dad | 2005-06-08 17:18:34 +1000 | [diff] [blame] | 258 | |
| 259 | if (vi->flags & FTF_FULLPATH) |
| 260 | emit->string(etarget, tree->fullpath, 0); |
| 261 | else |
| 262 | emit->string(etarget, tree->name, 0); |
| 263 | |
| 264 | emit->align(etarget, sizeof(cell_t)); |
| 265 | |
| 266 | for_each_property(tree, prop) { |
| 267 | int nameoff; |
| 268 | |
| 269 | if (streq(prop->name, "name")) |
| 270 | seen_name_prop = 1; |
| 271 | |
| 272 | nameoff = stringtable_insert(strbuf, prop->name); |
| 273 | |
David Gibson | 4102d84 | 2005-06-16 14:36:37 +1000 | [diff] [blame] | 274 | emit->property(etarget, prop->label); |
David Gibson | fc14dad | 2005-06-08 17:18:34 +1000 | [diff] [blame] | 275 | emit->cell(etarget, prop->val.len); |
| 276 | emit->cell(etarget, nameoff); |
| 277 | |
| 278 | if ((vi->flags & FTF_VARALIGN) && (prop->val.len >= 8)) |
| 279 | emit->align(etarget, 8); |
| 280 | |
| 281 | emit->data(etarget, prop->val); |
| 282 | emit->align(etarget, sizeof(cell_t)); |
| 283 | } |
| 284 | |
| 285 | if ((vi->flags & FTF_NAMEPROPS) && !seen_name_prop) { |
David Gibson | 4102d84 | 2005-06-16 14:36:37 +1000 | [diff] [blame] | 286 | emit->property(etarget, NULL); |
David Gibson | fc14dad | 2005-06-08 17:18:34 +1000 | [diff] [blame] | 287 | emit->cell(etarget, tree->basenamelen+1); |
| 288 | emit->cell(etarget, stringtable_insert(strbuf, "name")); |
| 289 | |
| 290 | if ((vi->flags & FTF_VARALIGN) && ((tree->basenamelen+1) >= 8)) |
| 291 | emit->align(etarget, 8); |
| 292 | |
| 293 | emit->string(etarget, tree->name, tree->basenamelen); |
David Gibson | 4191613 | 2005-08-25 15:39:09 +1000 | [diff] [blame] | 294 | emit->align(etarget, sizeof(cell_t)); |
David Gibson | fc14dad | 2005-06-08 17:18:34 +1000 | [diff] [blame] | 295 | } |
| 296 | |
| 297 | for_each_child(tree, child) { |
| 298 | flatten_tree(child, emit, etarget, strbuf, vi); |
| 299 | } |
| 300 | |
David Gibson | 4102d84 | 2005-06-16 14:36:37 +1000 | [diff] [blame] | 301 | emit->endnode(etarget, tree->label); |
David Gibson | fc14dad | 2005-06-08 17:18:34 +1000 | [diff] [blame] | 302 | } |
| 303 | |
David Gibson | f040d95 | 2005-10-24 18:18:38 +1000 | [diff] [blame] | 304 | static struct data flatten_reserve_list(struct reserve_info *reservelist, |
| 305 | struct version_info *vi) |
| 306 | { |
| 307 | struct reserve_info *re; |
| 308 | struct data d = empty_data; |
David Gibson | fb7c7ac | 2007-09-26 13:11:05 +1000 | [diff] [blame] | 309 | static struct fdt_reserve_entry null_re = {0,0}; |
Jerry Van Baren | 4384b23 | 2007-04-04 22:04:33 -0400 | [diff] [blame] | 310 | int j; |
David Gibson | f040d95 | 2005-10-24 18:18:38 +1000 | [diff] [blame] | 311 | |
| 312 | for (re = reservelist; re; re = re->next) { |
| 313 | d = data_append_re(d, &re->re); |
| 314 | } |
Jerry Van Baren | 4384b23 | 2007-04-04 22:04:33 -0400 | [diff] [blame] | 315 | /* |
| 316 | * Add additional reserved slots if the user asked for them. |
| 317 | */ |
| 318 | for (j = 0; j < reservenum; j++) { |
| 319 | d = data_append_re(d, &null_re); |
| 320 | } |
Jerry Van Baren | 86c01ee | 2007-04-18 21:59:51 -0400 | [diff] [blame] | 321 | |
David Gibson | f040d95 | 2005-10-24 18:18:38 +1000 | [diff] [blame] | 322 | return d; |
| 323 | } |
Jerry Van Baren | 86c01ee | 2007-04-18 21:59:51 -0400 | [diff] [blame] | 324 | |
David Gibson | fb7c7ac | 2007-09-26 13:11:05 +1000 | [diff] [blame] | 325 | static void make_fdt_header(struct fdt_header *fdt, |
| 326 | struct version_info *vi, |
| 327 | int reservesize, int dtsize, int strsize, |
| 328 | int boot_cpuid_phys) |
David Gibson | fc14dad | 2005-06-08 17:18:34 +1000 | [diff] [blame] | 329 | { |
David Gibson | 47f23de | 2005-07-11 17:19:26 +1000 | [diff] [blame] | 330 | int reserve_off; |
David Gibson | f040d95 | 2005-10-24 18:18:38 +1000 | [diff] [blame] | 331 | |
David Gibson | fb7c7ac | 2007-09-26 13:11:05 +1000 | [diff] [blame] | 332 | reservesize += sizeof(struct fdt_reserve_entry); |
David Gibson | fc14dad | 2005-06-08 17:18:34 +1000 | [diff] [blame] | 333 | |
David Gibson | fb7c7ac | 2007-09-26 13:11:05 +1000 | [diff] [blame] | 334 | memset(fdt, 0xff, sizeof(*fdt)); |
David Gibson | fc14dad | 2005-06-08 17:18:34 +1000 | [diff] [blame] | 335 | |
David Gibson | fb7c7ac | 2007-09-26 13:11:05 +1000 | [diff] [blame] | 336 | fdt->magic = cpu_to_be32(FDT_MAGIC); |
| 337 | fdt->version = cpu_to_be32(vi->version); |
| 338 | fdt->last_comp_version = cpu_to_be32(vi->last_comp_version); |
David Gibson | fc14dad | 2005-06-08 17:18:34 +1000 | [diff] [blame] | 339 | |
David Gibson | 47f23de | 2005-07-11 17:19:26 +1000 | [diff] [blame] | 340 | /* Reserve map should be doubleword aligned */ |
| 341 | reserve_off = ALIGN(vi->hdr_size, 8); |
| 342 | |
David Gibson | fb7c7ac | 2007-09-26 13:11:05 +1000 | [diff] [blame] | 343 | fdt->off_mem_rsvmap = cpu_to_be32(reserve_off); |
| 344 | fdt->off_dt_struct = cpu_to_be32(reserve_off + reservesize); |
| 345 | fdt->off_dt_strings = cpu_to_be32(reserve_off + reservesize |
David Gibson | fc14dad | 2005-06-08 17:18:34 +1000 | [diff] [blame] | 346 | + dtsize); |
David Gibson | fb7c7ac | 2007-09-26 13:11:05 +1000 | [diff] [blame] | 347 | fdt->totalsize = cpu_to_be32(reserve_off + reservesize + dtsize + strsize); |
Jerry Van Baren | 4384b23 | 2007-04-04 22:04:33 -0400 | [diff] [blame] | 348 | |
David Gibson | fc14dad | 2005-06-08 17:18:34 +1000 | [diff] [blame] | 349 | if (vi->flags & FTF_BOOTCPUID) |
David Gibson | fb7c7ac | 2007-09-26 13:11:05 +1000 | [diff] [blame] | 350 | fdt->boot_cpuid_phys = cpu_to_be32(boot_cpuid_phys); |
David Gibson | fc14dad | 2005-06-08 17:18:34 +1000 | [diff] [blame] | 351 | if (vi->flags & FTF_STRTABSIZE) |
David Gibson | fb7c7ac | 2007-09-26 13:11:05 +1000 | [diff] [blame] | 352 | fdt->size_dt_strings = cpu_to_be32(strsize); |
David Gibson | 46c88df | 2007-03-14 11:02:40 +1100 | [diff] [blame] | 353 | if (vi->flags & FTF_STRUCTSIZE) |
David Gibson | fb7c7ac | 2007-09-26 13:11:05 +1000 | [diff] [blame] | 354 | fdt->size_dt_struct = cpu_to_be32(dtsize); |
David Gibson | fc14dad | 2005-06-08 17:18:34 +1000 | [diff] [blame] | 355 | } |
| 356 | |
David Gibson | 548767f | 2008-05-16 13:22:57 +1000 | [diff] [blame] | 357 | void dt_to_blob(FILE *f, struct boot_info *bi, int version) |
David Gibson | fc14dad | 2005-06-08 17:18:34 +1000 | [diff] [blame] | 358 | { |
| 359 | struct version_info *vi = NULL; |
| 360 | int i; |
Jerry Van Baren | 86c01ee | 2007-04-18 21:59:51 -0400 | [diff] [blame] | 361 | struct data blob = empty_data; |
| 362 | struct data reservebuf = empty_data; |
| 363 | struct data dtbuf = empty_data; |
| 364 | struct data strbuf = empty_data; |
David Gibson | fb7c7ac | 2007-09-26 13:11:05 +1000 | [diff] [blame] | 365 | struct fdt_header fdt; |
Kumar Gala | 2b7dc8d | 2007-11-28 10:21:12 -0600 | [diff] [blame] | 366 | int padlen = 0; |
David Gibson | fc14dad | 2005-06-08 17:18:34 +1000 | [diff] [blame] | 367 | |
| 368 | for (i = 0; i < ARRAY_SIZE(version_table); i++) { |
| 369 | if (version_table[i].version == version) |
| 370 | vi = &version_table[i]; |
| 371 | } |
| 372 | if (!vi) |
| 373 | die("Unknown device tree blob version %d\n", version); |
| 374 | |
David Gibson | f0517db | 2005-07-15 17:14:24 +1000 | [diff] [blame] | 375 | flatten_tree(bi->dt, &bin_emitter, &dtbuf, &strbuf, vi); |
David Gibson | fb7c7ac | 2007-09-26 13:11:05 +1000 | [diff] [blame] | 376 | bin_emit_cell(&dtbuf, FDT_END); |
David Gibson | fc14dad | 2005-06-08 17:18:34 +1000 | [diff] [blame] | 377 | |
David Gibson | f040d95 | 2005-10-24 18:18:38 +1000 | [diff] [blame] | 378 | reservebuf = flatten_reserve_list(bi->reservelist, vi); |
| 379 | |
David Gibson | f0517db | 2005-07-15 17:14:24 +1000 | [diff] [blame] | 380 | /* Make header */ |
David Gibson | fb7c7ac | 2007-09-26 13:11:05 +1000 | [diff] [blame] | 381 | make_fdt_header(&fdt, vi, reservebuf.len, dtbuf.len, strbuf.len, |
David Gibson | 548767f | 2008-05-16 13:22:57 +1000 | [diff] [blame] | 382 | bi->boot_cpuid_phys); |
David Gibson | fc14dad | 2005-06-08 17:18:34 +1000 | [diff] [blame] | 383 | |
Jerry Van Baren | 86c01ee | 2007-04-18 21:59:51 -0400 | [diff] [blame] | 384 | /* |
Jerry Van Baren | 7ea144f | 2007-04-19 22:22:35 -0400 | [diff] [blame] | 385 | * If the user asked for more space than is used, adjust the totalsize. |
| 386 | */ |
Kumar Gala | 2b7dc8d | 2007-11-28 10:21:12 -0600 | [diff] [blame] | 387 | if (minsize > 0) { |
| 388 | padlen = minsize - be32_to_cpu(fdt.totalsize); |
| 389 | if ((padlen < 0) && (quiet < 1)) |
Jerry Van Baren | 7ea144f | 2007-04-19 22:22:35 -0400 | [diff] [blame] | 390 | fprintf(stderr, |
| 391 | "Warning: blob size %d >= minimum size %d\n", |
David Gibson | fb7c7ac | 2007-09-26 13:11:05 +1000 | [diff] [blame] | 392 | be32_to_cpu(fdt.totalsize), minsize); |
Jerry Van Baren | 7ea144f | 2007-04-19 22:22:35 -0400 | [diff] [blame] | 393 | } |
| 394 | |
Kumar Gala | 2b7dc8d | 2007-11-28 10:21:12 -0600 | [diff] [blame] | 395 | if (padsize > 0) |
| 396 | padlen = padsize; |
| 397 | |
Kumar Gala | 80c72a8 | 2007-12-04 17:36:08 -0600 | [diff] [blame] | 398 | if (padlen > 0) { |
| 399 | int tsize = be32_to_cpu(fdt.totalsize); |
| 400 | tsize += padlen; |
| 401 | fdt.totalsize = cpu_to_be32(tsize); |
| 402 | } |
| 403 | |
Jerry Van Baren | 7ea144f | 2007-04-19 22:22:35 -0400 | [diff] [blame] | 404 | /* |
Jerry Van Baren | 86c01ee | 2007-04-18 21:59:51 -0400 | [diff] [blame] | 405 | * Assemble the blob: start with the header, add with alignment |
| 406 | * the reserve buffer, add the reserve map terminating zeroes, |
| 407 | * the device tree itself, and finally the strings. |
| 408 | */ |
David Gibson | a266e5c | 2008-02-28 20:55:37 +1100 | [diff] [blame] | 409 | blob = data_append_data(blob, &fdt, vi->hdr_size); |
Jerry Van Baren | 86c01ee | 2007-04-18 21:59:51 -0400 | [diff] [blame] | 410 | blob = data_append_align(blob, 8); |
| 411 | blob = data_merge(blob, reservebuf); |
David Gibson | fb7c7ac | 2007-09-26 13:11:05 +1000 | [diff] [blame] | 412 | blob = data_append_zeroes(blob, sizeof(struct fdt_reserve_entry)); |
Jerry Van Baren | 86c01ee | 2007-04-18 21:59:51 -0400 | [diff] [blame] | 413 | blob = data_merge(blob, dtbuf); |
| 414 | blob = data_merge(blob, strbuf); |
David Gibson | 47f23de | 2005-07-11 17:19:26 +1000 | [diff] [blame] | 415 | |
David Gibson | f0517db | 2005-07-15 17:14:24 +1000 | [diff] [blame] | 416 | /* |
Jerry Van Baren | 86c01ee | 2007-04-18 21:59:51 -0400 | [diff] [blame] | 417 | * If the user asked for more space than is used, pad out the blob. |
David Gibson | f0517db | 2005-07-15 17:14:24 +1000 | [diff] [blame] | 418 | */ |
Kumar Gala | 80c72a8 | 2007-12-04 17:36:08 -0600 | [diff] [blame] | 419 | if (padlen > 0) |
Jerry Van Baren | 7ea144f | 2007-04-19 22:22:35 -0400 | [diff] [blame] | 420 | blob = data_append_zeroes(blob, padlen); |
Jerry Van Baren | 86c01ee | 2007-04-18 21:59:51 -0400 | [diff] [blame] | 421 | |
| 422 | fwrite(blob.val, blob.len, 1, f); |
David Gibson | fc14dad | 2005-06-08 17:18:34 +1000 | [diff] [blame] | 423 | |
| 424 | if (ferror(f)) |
| 425 | die("Error writing device tree blob: %s\n", strerror(errno)); |
| 426 | |
Jerry Van Baren | 86c01ee | 2007-04-18 21:59:51 -0400 | [diff] [blame] | 427 | /* |
| 428 | * data_merge() frees the right-hand element so only the blob |
| 429 | * remains to be freed. |
| 430 | */ |
| 431 | data_free(blob); |
David Gibson | fc14dad | 2005-06-08 17:18:34 +1000 | [diff] [blame] | 432 | } |
| 433 | |
David Gibson | 230f253 | 2005-08-29 12:48:02 +1000 | [diff] [blame] | 434 | static void dump_stringtable_asm(FILE *f, struct data strbuf) |
David Gibson | fc14dad | 2005-06-08 17:18:34 +1000 | [diff] [blame] | 435 | { |
David Gibson | 92cb9a2 | 2007-12-04 14:26:15 +1100 | [diff] [blame] | 436 | const char *p; |
David Gibson | fc14dad | 2005-06-08 17:18:34 +1000 | [diff] [blame] | 437 | int len; |
| 438 | |
| 439 | p = strbuf.val; |
| 440 | |
| 441 | while (p < (strbuf.val + strbuf.len)) { |
| 442 | len = strlen(p); |
| 443 | fprintf(f, "\t.string \"%s\"\n", p); |
| 444 | p += len+1; |
| 445 | } |
| 446 | } |
| 447 | |
David Gibson | 548767f | 2008-05-16 13:22:57 +1000 | [diff] [blame] | 448 | void dt_to_asm(FILE *f, struct boot_info *bi, int version) |
David Gibson | fc14dad | 2005-06-08 17:18:34 +1000 | [diff] [blame] | 449 | { |
| 450 | struct version_info *vi = NULL; |
| 451 | int i; |
| 452 | struct data strbuf = empty_data; |
David Gibson | f040d95 | 2005-10-24 18:18:38 +1000 | [diff] [blame] | 453 | struct reserve_info *re; |
David Gibson | 92cb9a2 | 2007-12-04 14:26:15 +1100 | [diff] [blame] | 454 | const char *symprefix = "dt"; |
David Gibson | fc14dad | 2005-06-08 17:18:34 +1000 | [diff] [blame] | 455 | |
| 456 | for (i = 0; i < ARRAY_SIZE(version_table); i++) { |
| 457 | if (version_table[i].version == version) |
| 458 | vi = &version_table[i]; |
| 459 | } |
| 460 | if (!vi) |
| 461 | die("Unknown device tree blob version %d\n", version); |
| 462 | |
| 463 | fprintf(f, "/* autogenerated by dtc, do not edit */\n\n"); |
David Gibson | fb7c7ac | 2007-09-26 13:11:05 +1000 | [diff] [blame] | 464 | fprintf(f, "#define FDT_MAGIC 0x%x\n", FDT_MAGIC); |
| 465 | fprintf(f, "#define FDT_BEGIN_NODE 0x%x\n", FDT_BEGIN_NODE); |
| 466 | fprintf(f, "#define FDT_END_NODE 0x%x\n", FDT_END_NODE); |
| 467 | fprintf(f, "#define FDT_PROP 0x%x\n", FDT_PROP); |
| 468 | fprintf(f, "#define FDT_END 0x%x\n", FDT_END); |
David Gibson | fc14dad | 2005-06-08 17:18:34 +1000 | [diff] [blame] | 469 | fprintf(f, "\n"); |
| 470 | |
| 471 | emit_label(f, symprefix, "blob_start"); |
| 472 | emit_label(f, symprefix, "header"); |
David Gibson | fb7c7ac | 2007-09-26 13:11:05 +1000 | [diff] [blame] | 473 | fprintf(f, "\t.long\tFDT_MAGIC\t\t\t\t/* magic */\n"); |
Milton Miller | 7f45666 | 2007-07-07 01:18:53 -0500 | [diff] [blame] | 474 | fprintf(f, "\t.long\t_%s_blob_abs_end - _%s_blob_start\t/* totalsize */\n", |
David Gibson | fc14dad | 2005-06-08 17:18:34 +1000 | [diff] [blame] | 475 | symprefix, symprefix); |
Milton Miller | 7f45666 | 2007-07-07 01:18:53 -0500 | [diff] [blame] | 476 | fprintf(f, "\t.long\t_%s_struct_start - _%s_blob_start\t/* off_dt_struct */\n", |
David Gibson | fc14dad | 2005-06-08 17:18:34 +1000 | [diff] [blame] | 477 | symprefix, symprefix); |
Milton Miller | 7f45666 | 2007-07-07 01:18:53 -0500 | [diff] [blame] | 478 | fprintf(f, "\t.long\t_%s_strings_start - _%s_blob_start\t/* off_dt_strings */\n", |
David Gibson | fc14dad | 2005-06-08 17:18:34 +1000 | [diff] [blame] | 479 | symprefix, symprefix); |
Milton Miller | 7f45666 | 2007-07-07 01:18:53 -0500 | [diff] [blame] | 480 | fprintf(f, "\t.long\t_%s_reserve_map - _%s_blob_start\t/* off_dt_strings */\n", |
David Gibson | fc14dad | 2005-06-08 17:18:34 +1000 | [diff] [blame] | 481 | symprefix, symprefix); |
Milton Miller | 7f45666 | 2007-07-07 01:18:53 -0500 | [diff] [blame] | 482 | fprintf(f, "\t.long\t%d\t\t\t\t\t/* version */\n", vi->version); |
| 483 | fprintf(f, "\t.long\t%d\t\t\t\t\t/* last_comp_version */\n", |
David Gibson | fc14dad | 2005-06-08 17:18:34 +1000 | [diff] [blame] | 484 | vi->last_comp_version); |
| 485 | |
| 486 | if (vi->flags & FTF_BOOTCPUID) |
Milton Miller | 7f45666 | 2007-07-07 01:18:53 -0500 | [diff] [blame] | 487 | fprintf(f, "\t.long\t%i\t\t\t\t\t/* boot_cpuid_phys */\n", |
David Gibson | 548767f | 2008-05-16 13:22:57 +1000 | [diff] [blame] | 488 | bi->boot_cpuid_phys); |
David Gibson | fc14dad | 2005-06-08 17:18:34 +1000 | [diff] [blame] | 489 | |
| 490 | if (vi->flags & FTF_STRTABSIZE) |
| 491 | fprintf(f, "\t.long\t_%s_strings_end - _%s_strings_start\t/* size_dt_strings */\n", |
| 492 | symprefix, symprefix); |
| 493 | |
Milton Miller | 81fda8a | 2007-07-07 01:18:47 -0500 | [diff] [blame] | 494 | if (vi->flags & FTF_STRUCTSIZE) |
| 495 | fprintf(f, "\t.long\t_%s_struct_end - _%s_struct_start\t/* size_dt_struct */\n", |
| 496 | symprefix, symprefix); |
| 497 | |
David Gibson | f0517db | 2005-07-15 17:14:24 +1000 | [diff] [blame] | 498 | /* |
| 499 | * Reserve map entries. |
| 500 | * Align the reserve map to a doubleword boundary. |
| 501 | * Each entry is an (address, size) pair of u64 values. |
David Gibson | f0517db | 2005-07-15 17:14:24 +1000 | [diff] [blame] | 502 | * Always supply a zero-sized temination entry. |
| 503 | */ |
David Gibson | 47f23de | 2005-07-11 17:19:26 +1000 | [diff] [blame] | 504 | asm_emit_align(f, 8); |
David Gibson | fc14dad | 2005-06-08 17:18:34 +1000 | [diff] [blame] | 505 | emit_label(f, symprefix, "reserve_map"); |
David Gibson | f0517db | 2005-07-15 17:14:24 +1000 | [diff] [blame] | 506 | |
David Gibson | f040d95 | 2005-10-24 18:18:38 +1000 | [diff] [blame] | 507 | fprintf(f, "/* Memory reserve map from source file */\n"); |
Jon Loeliger | 05ae3d8 | 2006-04-19 11:58:45 -0500 | [diff] [blame] | 508 | |
| 509 | /* |
| 510 | * Use .long on high and low halfs of u64s to avoid .quad |
| 511 | * as it appears .quad isn't available in some assemblers. |
| 512 | */ |
David Gibson | f040d95 | 2005-10-24 18:18:38 +1000 | [diff] [blame] | 513 | for (re = bi->reservelist; re; re = re->next) { |
Milton Miller | d429033 | 2007-07-07 01:18:49 -0500 | [diff] [blame] | 514 | if (re->label) { |
| 515 | fprintf(f, "\t.globl\t%s\n", re->label); |
| 516 | fprintf(f, "%s:\n", re->label); |
| 517 | } |
Milton Miller | 445d55d | 2007-07-07 01:18:54 -0500 | [diff] [blame] | 518 | fprintf(f, "\t.long\t0x%08x, 0x%08x\n", |
Jon Loeliger | 05ae3d8 | 2006-04-19 11:58:45 -0500 | [diff] [blame] | 519 | (unsigned int)(re->re.address >> 32), |
| 520 | (unsigned int)(re->re.address & 0xffffffff)); |
Milton Miller | 445d55d | 2007-07-07 01:18:54 -0500 | [diff] [blame] | 521 | fprintf(f, "\t.long\t0x%08x, 0x%08x\n", |
Jon Loeliger | 05ae3d8 | 2006-04-19 11:58:45 -0500 | [diff] [blame] | 522 | (unsigned int)(re->re.size >> 32), |
| 523 | (unsigned int)(re->re.size & 0xffffffff)); |
David Gibson | fc14dad | 2005-06-08 17:18:34 +1000 | [diff] [blame] | 524 | } |
Jerry Van Baren | ca25e54 | 2007-04-17 18:14:41 -0400 | [diff] [blame] | 525 | for (i = 0; i < reservenum; i++) { |
| 526 | fprintf(f, "\t.long\t0, 0\n\t.long\t0, 0\n"); |
| 527 | } |
David Gibson | fc14dad | 2005-06-08 17:18:34 +1000 | [diff] [blame] | 528 | |
Jon Loeliger | 05ae3d8 | 2006-04-19 11:58:45 -0500 | [diff] [blame] | 529 | fprintf(f, "\t.long\t0, 0\n\t.long\t0, 0\n"); |
David Gibson | f0517db | 2005-07-15 17:14:24 +1000 | [diff] [blame] | 530 | |
David Gibson | fc14dad | 2005-06-08 17:18:34 +1000 | [diff] [blame] | 531 | emit_label(f, symprefix, "struct_start"); |
David Gibson | f0517db | 2005-07-15 17:14:24 +1000 | [diff] [blame] | 532 | flatten_tree(bi->dt, &asm_emitter, f, &strbuf, vi); |
David Gibson | fb7c7ac | 2007-09-26 13:11:05 +1000 | [diff] [blame] | 533 | fprintf(f, "\t.long\tFDT_END\n"); |
David Gibson | fc14dad | 2005-06-08 17:18:34 +1000 | [diff] [blame] | 534 | emit_label(f, symprefix, "struct_end"); |
| 535 | |
| 536 | emit_label(f, symprefix, "strings_start"); |
| 537 | dump_stringtable_asm(f, strbuf); |
| 538 | emit_label(f, symprefix, "strings_end"); |
| 539 | |
| 540 | emit_label(f, symprefix, "blob_end"); |
| 541 | |
Jerry Van Baren | 86c01ee | 2007-04-18 21:59:51 -0400 | [diff] [blame] | 542 | /* |
| 543 | * If the user asked for more space than is used, pad it out. |
| 544 | */ |
| 545 | if (minsize > 0) { |
| 546 | fprintf(f, "\t.space\t%d - (_%s_blob_end - _%s_blob_start), 0\n", |
| 547 | minsize, symprefix, symprefix); |
| 548 | } |
Kumar Gala | 2b7dc8d | 2007-11-28 10:21:12 -0600 | [diff] [blame] | 549 | if (padsize > 0) { |
| 550 | fprintf(f, "\t.space\t%d, 0\n", padsize); |
| 551 | } |
Jerry Van Baren | 86c01ee | 2007-04-18 21:59:51 -0400 | [diff] [blame] | 552 | emit_label(f, symprefix, "blob_abs_end"); |
| 553 | |
David Gibson | fc14dad | 2005-06-08 17:18:34 +1000 | [diff] [blame] | 554 | data_free(strbuf); |
| 555 | } |
| 556 | |
| 557 | struct inbuf { |
| 558 | char *base, *limit, *ptr; |
| 559 | }; |
| 560 | |
| 561 | static void inbuf_init(struct inbuf *inb, void *base, void *limit) |
| 562 | { |
| 563 | inb->base = base; |
| 564 | inb->limit = limit; |
| 565 | inb->ptr = inb->base; |
| 566 | } |
| 567 | |
| 568 | static void flat_read_chunk(struct inbuf *inb, void *p, int len) |
| 569 | { |
| 570 | if ((inb->ptr + len) > inb->limit) |
| 571 | die("Premature end of data parsing flat device tree\n"); |
| 572 | |
| 573 | memcpy(p, inb->ptr, len); |
| 574 | |
| 575 | inb->ptr += len; |
| 576 | } |
| 577 | |
David Gibson | 5335901 | 2008-06-25 13:53:07 +1000 | [diff] [blame^] | 578 | static uint32_t flat_read_word(struct inbuf *inb) |
David Gibson | fc14dad | 2005-06-08 17:18:34 +1000 | [diff] [blame] | 579 | { |
David Gibson | 5335901 | 2008-06-25 13:53:07 +1000 | [diff] [blame^] | 580 | uint32_t val; |
David Gibson | fc14dad | 2005-06-08 17:18:34 +1000 | [diff] [blame] | 581 | |
| 582 | assert(((inb->ptr - inb->base) % sizeof(val)) == 0); |
| 583 | |
| 584 | flat_read_chunk(inb, &val, sizeof(val)); |
| 585 | |
| 586 | return be32_to_cpu(val); |
| 587 | } |
| 588 | |
| 589 | static void flat_realign(struct inbuf *inb, int align) |
| 590 | { |
| 591 | int off = inb->ptr - inb->base; |
| 592 | |
| 593 | inb->ptr = inb->base + ALIGN(off, align); |
| 594 | if (inb->ptr > inb->limit) |
| 595 | die("Premature end of data parsing flat device tree\n"); |
| 596 | } |
| 597 | |
| 598 | static char *flat_read_string(struct inbuf *inb) |
| 599 | { |
| 600 | int len = 0; |
David Gibson | 92cb9a2 | 2007-12-04 14:26:15 +1100 | [diff] [blame] | 601 | const char *p = inb->ptr; |
David Gibson | fc14dad | 2005-06-08 17:18:34 +1000 | [diff] [blame] | 602 | char *str; |
| 603 | |
| 604 | do { |
| 605 | if (p >= inb->limit) |
| 606 | die("Premature end of data parsing flat device tree\n"); |
| 607 | len++; |
| 608 | } while ((*p++) != '\0'); |
| 609 | |
| 610 | str = strdup(inb->ptr); |
| 611 | |
| 612 | inb->ptr += len; |
| 613 | |
David Gibson | 5335901 | 2008-06-25 13:53:07 +1000 | [diff] [blame^] | 614 | flat_realign(inb, sizeof(uint32_t)); |
David Gibson | fc14dad | 2005-06-08 17:18:34 +1000 | [diff] [blame] | 615 | |
| 616 | return str; |
| 617 | } |
| 618 | |
| 619 | static struct data flat_read_data(struct inbuf *inb, int len) |
| 620 | { |
| 621 | struct data d = empty_data; |
| 622 | |
| 623 | if (len == 0) |
| 624 | return empty_data; |
| 625 | |
| 626 | d = data_grow_for(d, len); |
| 627 | d.len = len; |
| 628 | |
| 629 | flat_read_chunk(inb, d.val, len); |
| 630 | |
David Gibson | 5335901 | 2008-06-25 13:53:07 +1000 | [diff] [blame^] | 631 | flat_realign(inb, sizeof(uint32_t)); |
David Gibson | fc14dad | 2005-06-08 17:18:34 +1000 | [diff] [blame] | 632 | |
| 633 | return d; |
| 634 | } |
| 635 | |
| 636 | static char *flat_read_stringtable(struct inbuf *inb, int offset) |
| 637 | { |
David Gibson | 92cb9a2 | 2007-12-04 14:26:15 +1100 | [diff] [blame] | 638 | const char *p; |
David Gibson | fc14dad | 2005-06-08 17:18:34 +1000 | [diff] [blame] | 639 | |
| 640 | p = inb->base + offset; |
| 641 | while (1) { |
David Gibson | 4ddf7c0 | 2005-08-19 16:11:11 +1000 | [diff] [blame] | 642 | if (p >= inb->limit || p < inb->base) |
David Gibson | 7ee3ffd | 2005-07-11 16:45:57 +1000 | [diff] [blame] | 643 | die("String offset %d overruns string table\n", |
| 644 | offset); |
David Gibson | fc14dad | 2005-06-08 17:18:34 +1000 | [diff] [blame] | 645 | |
| 646 | if (*p == '\0') |
| 647 | break; |
| 648 | |
| 649 | p++; |
| 650 | } |
| 651 | |
| 652 | return strdup(inb->base + offset); |
| 653 | } |
| 654 | |
David Gibson | 230f253 | 2005-08-29 12:48:02 +1000 | [diff] [blame] | 655 | static struct property *flat_read_property(struct inbuf *dtbuf, |
| 656 | struct inbuf *strbuf, int flags) |
David Gibson | fc14dad | 2005-06-08 17:18:34 +1000 | [diff] [blame] | 657 | { |
David Gibson | 5335901 | 2008-06-25 13:53:07 +1000 | [diff] [blame^] | 658 | uint32_t proplen, stroff; |
David Gibson | fc14dad | 2005-06-08 17:18:34 +1000 | [diff] [blame] | 659 | char *name; |
| 660 | struct data val; |
| 661 | |
| 662 | proplen = flat_read_word(dtbuf); |
| 663 | stroff = flat_read_word(dtbuf); |
| 664 | |
| 665 | name = flat_read_stringtable(strbuf, stroff); |
| 666 | |
| 667 | if ((flags & FTF_VARALIGN) && (proplen >= 8)) |
| 668 | flat_realign(dtbuf, 8); |
| 669 | |
| 670 | val = flat_read_data(dtbuf, proplen); |
| 671 | |
David Gibson | 4102d84 | 2005-06-16 14:36:37 +1000 | [diff] [blame] | 672 | return build_property(name, val, NULL); |
David Gibson | fc14dad | 2005-06-08 17:18:34 +1000 | [diff] [blame] | 673 | } |
| 674 | |
David Gibson | f0517db | 2005-07-15 17:14:24 +1000 | [diff] [blame] | 675 | |
David Gibson | f040d95 | 2005-10-24 18:18:38 +1000 | [diff] [blame] | 676 | static struct reserve_info *flat_read_mem_reserve(struct inbuf *inb) |
David Gibson | f0517db | 2005-07-15 17:14:24 +1000 | [diff] [blame] | 677 | { |
David Gibson | f040d95 | 2005-10-24 18:18:38 +1000 | [diff] [blame] | 678 | struct reserve_info *reservelist = NULL; |
| 679 | struct reserve_info *new; |
David Gibson | 92cb9a2 | 2007-12-04 14:26:15 +1100 | [diff] [blame] | 680 | const char *p; |
David Gibson | fb7c7ac | 2007-09-26 13:11:05 +1000 | [diff] [blame] | 681 | struct fdt_reserve_entry re; |
David Gibson | f0517db | 2005-07-15 17:14:24 +1000 | [diff] [blame] | 682 | |
| 683 | /* |
| 684 | * Each entry is a pair of u64 (addr, size) values for 4 cell_t's. |
| 685 | * List terminates at an entry with size equal to zero. |
| 686 | * |
| 687 | * First pass, count entries. |
| 688 | */ |
| 689 | p = inb->ptr; |
David Gibson | 6c0f367 | 2005-08-29 13:36:15 +1000 | [diff] [blame] | 690 | while (1) { |
| 691 | flat_read_chunk(inb, &re, sizeof(re)); |
Michael Neuling | 332c536 | 2006-07-07 23:28:10 +1000 | [diff] [blame] | 692 | re.address = be64_to_cpu(re.address); |
| 693 | re.size = be64_to_cpu(re.size); |
David Gibson | 6c0f367 | 2005-08-29 13:36:15 +1000 | [diff] [blame] | 694 | if (re.size == 0) |
| 695 | break; |
David Gibson | f0517db | 2005-07-15 17:14:24 +1000 | [diff] [blame] | 696 | |
David Gibson | f040d95 | 2005-10-24 18:18:38 +1000 | [diff] [blame] | 697 | new = build_reserve_entry(re.address, re.size, NULL); |
| 698 | reservelist = add_reserve_entry(reservelist, new); |
David Gibson | 6c0f367 | 2005-08-29 13:36:15 +1000 | [diff] [blame] | 699 | } |
David Gibson | f0517db | 2005-07-15 17:14:24 +1000 | [diff] [blame] | 700 | |
David Gibson | f040d95 | 2005-10-24 18:18:38 +1000 | [diff] [blame] | 701 | return reservelist; |
David Gibson | f0517db | 2005-07-15 17:14:24 +1000 | [diff] [blame] | 702 | } |
| 703 | |
| 704 | |
David Gibson | 92cb9a2 | 2007-12-04 14:26:15 +1100 | [diff] [blame] | 705 | static char *nodename_from_path(const char *ppath, const char *cpath) |
David Gibson | fc14dad | 2005-06-08 17:18:34 +1000 | [diff] [blame] | 706 | { |
David Gibson | fc14dad | 2005-06-08 17:18:34 +1000 | [diff] [blame] | 707 | int plen; |
| 708 | |
David Gibson | b2de518 | 2008-02-29 16:51:28 +1100 | [diff] [blame] | 709 | plen = strlen(ppath); |
David Gibson | fc14dad | 2005-06-08 17:18:34 +1000 | [diff] [blame] | 710 | |
David Gibson | b2de518 | 2008-02-29 16:51:28 +1100 | [diff] [blame] | 711 | if (!strneq(ppath, cpath, plen)) |
| 712 | die("Path \"%s\" is not valid as a child of \"%s\"\n", |
| 713 | cpath, ppath); |
David Gibson | fc14dad | 2005-06-08 17:18:34 +1000 | [diff] [blame] | 714 | |
David Gibson | b2de518 | 2008-02-29 16:51:28 +1100 | [diff] [blame] | 715 | /* root node is a special case */ |
| 716 | if (!streq(ppath, "/")) |
| 717 | plen++; |
David Gibson | fc14dad | 2005-06-08 17:18:34 +1000 | [diff] [blame] | 718 | |
David Gibson | b2de518 | 2008-02-29 16:51:28 +1100 | [diff] [blame] | 719 | return strdup(cpath + plen); |
David Gibson | fc14dad | 2005-06-08 17:18:34 +1000 | [diff] [blame] | 720 | } |
| 721 | |
| 722 | static struct node *unflatten_tree(struct inbuf *dtbuf, |
| 723 | struct inbuf *strbuf, |
David Gibson | b2de518 | 2008-02-29 16:51:28 +1100 | [diff] [blame] | 724 | const char *parent_flatname, int flags) |
David Gibson | fc14dad | 2005-06-08 17:18:34 +1000 | [diff] [blame] | 725 | { |
| 726 | struct node *node; |
David Gibson | b2de518 | 2008-02-29 16:51:28 +1100 | [diff] [blame] | 727 | char *flatname; |
David Gibson | 5335901 | 2008-06-25 13:53:07 +1000 | [diff] [blame^] | 728 | uint32_t val; |
David Gibson | fc14dad | 2005-06-08 17:18:34 +1000 | [diff] [blame] | 729 | |
| 730 | node = build_node(NULL, NULL); |
| 731 | |
David Gibson | b2de518 | 2008-02-29 16:51:28 +1100 | [diff] [blame] | 732 | flatname = flat_read_string(dtbuf); |
David Gibson | fc14dad | 2005-06-08 17:18:34 +1000 | [diff] [blame] | 733 | |
David Gibson | b2de518 | 2008-02-29 16:51:28 +1100 | [diff] [blame] | 734 | if (flags & FTF_FULLPATH) |
| 735 | node->name = nodename_from_path(parent_flatname, flatname); |
| 736 | else |
| 737 | node->name = flatname; |
David Gibson | fc14dad | 2005-06-08 17:18:34 +1000 | [diff] [blame] | 738 | |
| 739 | do { |
| 740 | struct property *prop; |
| 741 | struct node *child; |
| 742 | |
| 743 | val = flat_read_word(dtbuf); |
| 744 | switch (val) { |
David Gibson | fb7c7ac | 2007-09-26 13:11:05 +1000 | [diff] [blame] | 745 | case FDT_PROP: |
David Gibson | 592ea58 | 2007-09-04 10:43:03 +1000 | [diff] [blame] | 746 | if (node->children) |
| 747 | fprintf(stderr, "Warning: Flat tree input has " |
| 748 | "subnodes preceding a property.\n"); |
David Gibson | fc14dad | 2005-06-08 17:18:34 +1000 | [diff] [blame] | 749 | prop = flat_read_property(dtbuf, strbuf, flags); |
| 750 | add_property(node, prop); |
| 751 | break; |
| 752 | |
David Gibson | fb7c7ac | 2007-09-26 13:11:05 +1000 | [diff] [blame] | 753 | case FDT_BEGIN_NODE: |
David Gibson | b2de518 | 2008-02-29 16:51:28 +1100 | [diff] [blame] | 754 | child = unflatten_tree(dtbuf,strbuf, flatname, flags); |
David Gibson | fc14dad | 2005-06-08 17:18:34 +1000 | [diff] [blame] | 755 | add_child(node, child); |
| 756 | break; |
| 757 | |
David Gibson | fb7c7ac | 2007-09-26 13:11:05 +1000 | [diff] [blame] | 758 | case FDT_END_NODE: |
David Gibson | fc14dad | 2005-06-08 17:18:34 +1000 | [diff] [blame] | 759 | break; |
| 760 | |
David Gibson | fb7c7ac | 2007-09-26 13:11:05 +1000 | [diff] [blame] | 761 | case FDT_END: |
| 762 | die("Premature FDT_END in device tree blob\n"); |
David Gibson | fc14dad | 2005-06-08 17:18:34 +1000 | [diff] [blame] | 763 | break; |
| 764 | |
David Gibson | fb7c7ac | 2007-09-26 13:11:05 +1000 | [diff] [blame] | 765 | case FDT_NOP: |
David Gibson | 0738774 | 2007-06-26 11:30:47 +1000 | [diff] [blame] | 766 | if (!(flags & FTF_NOPS)) |
| 767 | fprintf(stderr, "Warning: NOP tag found in flat tree" |
| 768 | " version <16\n"); |
Milton Miller | ce24322 | 2007-06-09 23:21:31 -0500 | [diff] [blame] | 769 | |
David Gibson | 0738774 | 2007-06-26 11:30:47 +1000 | [diff] [blame] | 770 | /* Ignore */ |
Milton Miller | ce24322 | 2007-06-09 23:21:31 -0500 | [diff] [blame] | 771 | break; |
| 772 | |
David Gibson | fc14dad | 2005-06-08 17:18:34 +1000 | [diff] [blame] | 773 | default: |
| 774 | die("Invalid opcode word %08x in device tree blob\n", |
| 775 | val); |
| 776 | } |
David Gibson | fb7c7ac | 2007-09-26 13:11:05 +1000 | [diff] [blame] | 777 | } while (val != FDT_END_NODE); |
David Gibson | fc14dad | 2005-06-08 17:18:34 +1000 | [diff] [blame] | 778 | |
| 779 | return node; |
| 780 | } |
| 781 | |
David Gibson | f0517db | 2005-07-15 17:14:24 +1000 | [diff] [blame] | 782 | |
David Gibson | a742aad | 2008-05-16 13:22:09 +1000 | [diff] [blame] | 783 | struct boot_info *dt_from_blob(const char *fname) |
David Gibson | fc14dad | 2005-06-08 17:18:34 +1000 | [diff] [blame] | 784 | { |
David Gibson | a742aad | 2008-05-16 13:22:09 +1000 | [diff] [blame] | 785 | struct dtc_file *dtcf; |
David Gibson | 5335901 | 2008-06-25 13:53:07 +1000 | [diff] [blame^] | 786 | uint32_t magic, totalsize, version, size_dt, boot_cpuid_phys; |
| 787 | uint32_t off_dt, off_str, off_mem_rsvmap; |
David Gibson | fc14dad | 2005-06-08 17:18:34 +1000 | [diff] [blame] | 788 | int rc; |
| 789 | char *blob; |
David Gibson | fb7c7ac | 2007-09-26 13:11:05 +1000 | [diff] [blame] | 790 | struct fdt_header *fdt; |
David Gibson | fc14dad | 2005-06-08 17:18:34 +1000 | [diff] [blame] | 791 | char *p; |
| 792 | struct inbuf dtbuf, strbuf; |
David Gibson | f0517db | 2005-07-15 17:14:24 +1000 | [diff] [blame] | 793 | struct inbuf memresvbuf; |
David Gibson | fc14dad | 2005-06-08 17:18:34 +1000 | [diff] [blame] | 794 | int sizeleft; |
David Gibson | f040d95 | 2005-10-24 18:18:38 +1000 | [diff] [blame] | 795 | struct reserve_info *reservelist; |
David Gibson | fc14dad | 2005-06-08 17:18:34 +1000 | [diff] [blame] | 796 | struct node *tree; |
David Gibson | 5335901 | 2008-06-25 13:53:07 +1000 | [diff] [blame^] | 797 | uint32_t val; |
David Gibson | fc14dad | 2005-06-08 17:18:34 +1000 | [diff] [blame] | 798 | int flags = 0; |
| 799 | |
David Gibson | a742aad | 2008-05-16 13:22:09 +1000 | [diff] [blame] | 800 | dtcf = dtc_open_file(fname, NULL); |
| 801 | |
| 802 | rc = fread(&magic, sizeof(magic), 1, dtcf->file); |
| 803 | if (ferror(dtcf->file)) |
David Gibson | fc14dad | 2005-06-08 17:18:34 +1000 | [diff] [blame] | 804 | die("Error reading DT blob magic number: %s\n", |
| 805 | strerror(errno)); |
| 806 | if (rc < 1) { |
David Gibson | a742aad | 2008-05-16 13:22:09 +1000 | [diff] [blame] | 807 | if (feof(dtcf->file)) |
David Gibson | fc14dad | 2005-06-08 17:18:34 +1000 | [diff] [blame] | 808 | die("EOF reading DT blob magic number\n"); |
| 809 | else |
| 810 | die("Mysterious short read reading magic number\n"); |
| 811 | } |
| 812 | |
| 813 | magic = be32_to_cpu(magic); |
David Gibson | fb7c7ac | 2007-09-26 13:11:05 +1000 | [diff] [blame] | 814 | if (magic != FDT_MAGIC) |
David Gibson | fc14dad | 2005-06-08 17:18:34 +1000 | [diff] [blame] | 815 | die("Blob has incorrect magic number\n"); |
| 816 | |
David Gibson | a742aad | 2008-05-16 13:22:09 +1000 | [diff] [blame] | 817 | rc = fread(&totalsize, sizeof(totalsize), 1, dtcf->file); |
| 818 | if (ferror(dtcf->file)) |
David Gibson | fc14dad | 2005-06-08 17:18:34 +1000 | [diff] [blame] | 819 | die("Error reading DT blob size: %s\n", strerror(errno)); |
| 820 | if (rc < 1) { |
David Gibson | a742aad | 2008-05-16 13:22:09 +1000 | [diff] [blame] | 821 | if (feof(dtcf->file)) |
David Gibson | fc14dad | 2005-06-08 17:18:34 +1000 | [diff] [blame] | 822 | die("EOF reading DT blob size\n"); |
| 823 | else |
| 824 | die("Mysterious short read reading blob size\n"); |
| 825 | } |
| 826 | |
| 827 | totalsize = be32_to_cpu(totalsize); |
David Gibson | fb7c7ac | 2007-09-26 13:11:05 +1000 | [diff] [blame] | 828 | if (totalsize < FDT_V1_SIZE) |
David Gibson | fc14dad | 2005-06-08 17:18:34 +1000 | [diff] [blame] | 829 | die("DT blob size (%d) is too small\n", totalsize); |
| 830 | |
| 831 | blob = xmalloc(totalsize); |
| 832 | |
David Gibson | fb7c7ac | 2007-09-26 13:11:05 +1000 | [diff] [blame] | 833 | fdt = (struct fdt_header *)blob; |
| 834 | fdt->magic = cpu_to_be32(magic); |
| 835 | fdt->totalsize = cpu_to_be32(totalsize); |
David Gibson | fc14dad | 2005-06-08 17:18:34 +1000 | [diff] [blame] | 836 | |
| 837 | sizeleft = totalsize - sizeof(magic) - sizeof(totalsize); |
| 838 | p = blob + sizeof(magic) + sizeof(totalsize); |
| 839 | |
| 840 | while (sizeleft) { |
David Gibson | a742aad | 2008-05-16 13:22:09 +1000 | [diff] [blame] | 841 | if (feof(dtcf->file)) |
David Gibson | fc14dad | 2005-06-08 17:18:34 +1000 | [diff] [blame] | 842 | die("EOF before reading %d bytes of DT blob\n", |
| 843 | totalsize); |
| 844 | |
David Gibson | a742aad | 2008-05-16 13:22:09 +1000 | [diff] [blame] | 845 | rc = fread(p, 1, sizeleft, dtcf->file); |
| 846 | if (ferror(dtcf->file)) |
David Gibson | fc14dad | 2005-06-08 17:18:34 +1000 | [diff] [blame] | 847 | die("Error reading DT blob: %s\n", |
| 848 | strerror(errno)); |
| 849 | |
| 850 | sizeleft -= rc; |
| 851 | p += rc; |
| 852 | } |
| 853 | |
David Gibson | fb7c7ac | 2007-09-26 13:11:05 +1000 | [diff] [blame] | 854 | off_dt = be32_to_cpu(fdt->off_dt_struct); |
| 855 | off_str = be32_to_cpu(fdt->off_dt_strings); |
| 856 | off_mem_rsvmap = be32_to_cpu(fdt->off_mem_rsvmap); |
| 857 | version = be32_to_cpu(fdt->version); |
David Gibson | 548767f | 2008-05-16 13:22:57 +1000 | [diff] [blame] | 858 | boot_cpuid_phys = be32_to_cpu(fdt->boot_cpuid_phys); |
David Gibson | fc14dad | 2005-06-08 17:18:34 +1000 | [diff] [blame] | 859 | |
David Gibson | f0517db | 2005-07-15 17:14:24 +1000 | [diff] [blame] | 860 | if (off_mem_rsvmap >= totalsize) |
| 861 | die("Mem Reserve structure offset exceeds total size\n"); |
| 862 | |
David Gibson | fc14dad | 2005-06-08 17:18:34 +1000 | [diff] [blame] | 863 | if (off_dt >= totalsize) |
| 864 | die("DT structure offset exceeds total size\n"); |
| 865 | |
| 866 | if (off_str > totalsize) |
| 867 | die("String table offset exceeds total size\n"); |
| 868 | |
David Gibson | fc14dad | 2005-06-08 17:18:34 +1000 | [diff] [blame] | 869 | if (version >= 3) { |
David Gibson | 5335901 | 2008-06-25 13:53:07 +1000 | [diff] [blame^] | 870 | uint32_t size_str = be32_to_cpu(fdt->size_dt_strings); |
David Gibson | fc14dad | 2005-06-08 17:18:34 +1000 | [diff] [blame] | 871 | if (off_str+size_str > totalsize) |
| 872 | die("String table extends past total size\n"); |
David Gibson | a266e5c | 2008-02-28 20:55:37 +1100 | [diff] [blame] | 873 | inbuf_init(&strbuf, blob + off_str, blob + off_str + size_str); |
| 874 | } else { |
| 875 | inbuf_init(&strbuf, blob + off_str, blob + totalsize); |
David Gibson | fc14dad | 2005-06-08 17:18:34 +1000 | [diff] [blame] | 876 | } |
David Gibson | 46c88df | 2007-03-14 11:02:40 +1100 | [diff] [blame] | 877 | |
| 878 | if (version >= 17) { |
David Gibson | fb7c7ac | 2007-09-26 13:11:05 +1000 | [diff] [blame] | 879 | size_dt = be32_to_cpu(fdt->size_dt_struct); |
David Gibson | 46c88df | 2007-03-14 11:02:40 +1100 | [diff] [blame] | 880 | if (off_dt+size_dt > totalsize) |
| 881 | die("Structure block extends past total size\n"); |
| 882 | } |
David Gibson | 63dc9c7 | 2007-09-18 11:44:04 +1000 | [diff] [blame] | 883 | |
David Gibson | 46c88df | 2007-03-14 11:02:40 +1100 | [diff] [blame] | 884 | if (version < 16) { |
David Gibson | fc14dad | 2005-06-08 17:18:34 +1000 | [diff] [blame] | 885 | flags |= FTF_FULLPATH | FTF_NAMEPROPS | FTF_VARALIGN; |
Milton Miller | ce24322 | 2007-06-09 23:21:31 -0500 | [diff] [blame] | 886 | } else { |
| 887 | flags |= FTF_NOPS; |
David Gibson | fc14dad | 2005-06-08 17:18:34 +1000 | [diff] [blame] | 888 | } |
| 889 | |
David Gibson | f0517db | 2005-07-15 17:14:24 +1000 | [diff] [blame] | 890 | inbuf_init(&memresvbuf, |
| 891 | blob + off_mem_rsvmap, blob + totalsize); |
David Gibson | fc14dad | 2005-06-08 17:18:34 +1000 | [diff] [blame] | 892 | inbuf_init(&dtbuf, blob + off_dt, blob + totalsize); |
David Gibson | fc14dad | 2005-06-08 17:18:34 +1000 | [diff] [blame] | 893 | |
David Gibson | f040d95 | 2005-10-24 18:18:38 +1000 | [diff] [blame] | 894 | reservelist = flat_read_mem_reserve(&memresvbuf); |
David Gibson | f0517db | 2005-07-15 17:14:24 +1000 | [diff] [blame] | 895 | |
David Gibson | fc14dad | 2005-06-08 17:18:34 +1000 | [diff] [blame] | 896 | val = flat_read_word(&dtbuf); |
| 897 | |
David Gibson | fb7c7ac | 2007-09-26 13:11:05 +1000 | [diff] [blame] | 898 | if (val != FDT_BEGIN_NODE) |
| 899 | die("Device tree blob doesn't begin with FDT_BEGIN_NODE (begins with 0x%08x)\n", val); |
David Gibson | fc14dad | 2005-06-08 17:18:34 +1000 | [diff] [blame] | 900 | |
| 901 | tree = unflatten_tree(&dtbuf, &strbuf, "", flags); |
| 902 | |
| 903 | val = flat_read_word(&dtbuf); |
David Gibson | fb7c7ac | 2007-09-26 13:11:05 +1000 | [diff] [blame] | 904 | if (val != FDT_END) |
| 905 | die("Device tree blob doesn't end with FDT_END\n"); |
David Gibson | fc14dad | 2005-06-08 17:18:34 +1000 | [diff] [blame] | 906 | |
| 907 | free(blob); |
| 908 | |
David Gibson | a742aad | 2008-05-16 13:22:09 +1000 | [diff] [blame] | 909 | dtc_close_file(dtcf); |
| 910 | |
David Gibson | 548767f | 2008-05-16 13:22:57 +1000 | [diff] [blame] | 911 | return build_boot_info(reservelist, tree, boot_cpuid_phys); |
David Gibson | fc14dad | 2005-06-08 17:18:34 +1000 | [diff] [blame] | 912 | } |