aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/dtc/data.c
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/dtc/data.c')
-rw-r--r--scripts/dtc/data.c124
1 files changed, 36 insertions, 88 deletions
diff --git a/scripts/dtc/data.c b/scripts/dtc/data.c
index fe555e819bf8..4a40c5b92474 100644
--- a/scripts/dtc/data.c
+++ b/scripts/dtc/data.c
@@ -68,40 +68,6 @@ struct data data_copy_mem(const char *mem, int len)
68 return d; 68 return d;
69} 69}
70 70
71static char get_oct_char(const char *s, int *i)
72{
73 char x[4];
74 char *endx;
75 long val;
76
77 x[3] = '\0';
78 strncpy(x, s + *i, 3);
79
80 val = strtol(x, &endx, 8);
81
82 assert(endx > x);
83
84 (*i) += endx - x;
85 return val;
86}
87
88static char get_hex_char(const char *s, int *i)
89{
90 char x[3];
91 char *endx;
92 long val;
93
94 x[2] = '\0';
95 strncpy(x, s + *i, 2);
96
97 val = strtol(x, &endx, 16);
98 if (!(endx > x))
99 die("\\x used with no following hex digits\n");
100
101 (*i) += endx - x;
102 return val;
103}
104
105struct data data_copy_escape_string(const char *s, int len) 71struct data data_copy_escape_string(const char *s, int len)
106{ 72{
107 int i = 0; 73 int i = 0;
@@ -114,53 +80,10 @@ struct data data_copy_escape_string(const char *s, int len)
114 while (i < len) { 80 while (i < len) {
115 char c = s[i++]; 81 char c = s[i++];
116 82
117 if (c != '\\') { 83 if (c == '\\')
118 q[d.len++] = c; 84 c = get_escape_char(s, &i);
119 continue; 85
120 } 86 q[d.len++] = c;
121
122 c = s[i++];
123 assert(c);
124 switch (c) {
125 case 'a':
126 q[d.len++] = '\a';
127 break;
128 case 'b':
129 q[d.len++] = '\b';
130 break;
131 case 't':
132 q[d.len++] = '\t';
133 break;
134 case 'n':
135 q[d.len++] = '\n';
136 break;
137 case 'v':
138 q[d.len++] = '\v';
139 break;
140 case 'f':
141 q[d.len++] = '\f';
142 break;
143 case 'r':
144 q[d.len++] = '\r';
145 break;
146 case '0':
147 case '1':
148 case '2':
149 case '3':
150 case '4':
151 case '5':
152 case '6':
153 case '7':
154 i--; /* need to re-read the first digit as
155 * part of the octal value */
156 q[d.len++] = get_oct_char(s, &i);
157 break;
158 case 'x':
159 q[d.len++] = get_hex_char(s, &i);
160 break;
161 default:
162 q[d.len++] = c;
163 }
164 } 87 }
165 88
166 q[d.len++] = '\0'; 89 q[d.len++] = '\0';
@@ -245,11 +168,33 @@ struct data data_merge(struct data d1, struct data d2)
245 return d; 168 return d;
246} 169}
247 170
248struct data data_append_cell(struct data d, cell_t word) 171struct data data_append_integer(struct data d, uint64_t value, int bits)
249{ 172{
250 cell_t beword = cpu_to_fdt32(word); 173 uint8_t value_8;
251 174 uint16_t value_16;
252 return data_append_data(d, &beword, sizeof(beword)); 175 uint32_t value_32;
176 uint64_t value_64;
177
178 switch (bits) {
179 case 8:
180 value_8 = value;
181 return data_append_data(d, &value_8, 1);
182
183 case 16:
184 value_16 = cpu_to_fdt16(value);
185 return data_append_data(d, &value_16, 2);
186
187 case 32:
188 value_32 = cpu_to_fdt32(value);
189 return data_append_data(d, &value_32, 4);
190
191 case 64:
192 value_64 = cpu_to_fdt64(value);
193 return data_append_data(d, &value_64, 8);
194
195 default:
196 die("Invalid literal size (%d)\n", bits);
197 }
253} 198}
254 199
255struct data data_append_re(struct data d, const struct fdt_reserve_entry *re) 200struct data data_append_re(struct data d, const struct fdt_reserve_entry *re)
@@ -262,11 +207,14 @@ struct data data_append_re(struct data d, const struct fdt_reserve_entry *re)
262 return data_append_data(d, &bere, sizeof(bere)); 207 return data_append_data(d, &bere, sizeof(bere));
263} 208}
264 209
265struct data data_append_addr(struct data d, uint64_t addr) 210struct data data_append_cell(struct data d, cell_t word)
266{ 211{
267 uint64_t beaddr = cpu_to_fdt64(addr); 212 return data_append_integer(d, word, sizeof(word) * 8);
213}
268 214
269 return data_append_data(d, &beaddr, sizeof(beaddr)); 215struct data data_append_addr(struct data d, uint64_t addr)
216{
217 return data_append_integer(d, addr, sizeof(addr) * 8);
270} 218}
271 219
272struct data data_append_byte(struct data d, uint8_t byte) 220struct data data_append_byte(struct data d, uint8_t byte)