Simon Glass | a5e1a58 | 2019-10-27 09:47:42 -0600 | [diff] [blame] | 1 | // SPDX-License-Identifier: (GPL-2.0-or-later OR BSD-2-Clause) |
Tom Rini | bd39173 | 2017-09-23 12:52:44 -0400 | [diff] [blame] | 2 | /* |
| 3 | * libfdt - Flat Device Tree manipulation |
| 4 | * Copyright (C) 2006 David Gibson, IBM Corporation. |
Tom Rini | bd39173 | 2017-09-23 12:52:44 -0400 | [diff] [blame] | 5 | */ |
| 6 | #include "libfdt_env.h" |
| 7 | |
| 8 | #include <fdt.h> |
| 9 | #include <libfdt.h> |
| 10 | |
| 11 | #include "libfdt_internal.h" |
| 12 | |
Simon Glass | a5e1a58 | 2019-10-27 09:47:42 -0600 | [diff] [blame] | 13 | static int fdt_sw_probe_(void *fdt) |
| 14 | { |
| 15 | if (fdt_chk_basic()) { |
| 16 | if (fdt_magic(fdt) == FDT_MAGIC) |
| 17 | return -FDT_ERR_BADSTATE; |
| 18 | else if (fdt_magic(fdt) != FDT_SW_MAGIC) |
| 19 | return -FDT_ERR_BADMAGIC; |
| 20 | } |
| 21 | |
| 22 | return 0; |
| 23 | } |
| 24 | |
| 25 | #define FDT_SW_PROBE(fdt) \ |
| 26 | { \ |
| 27 | int err; \ |
| 28 | if (fdt_chk_basic() && (err = fdt_sw_probe_(fdt)) != 0) \ |
| 29 | return err; \ |
| 30 | } |
| 31 | |
| 32 | /* 'memrsv' state: Initial state after fdt_create() |
| 33 | * |
| 34 | * Allowed functions: |
| 35 | * fdt_add_reservmap_entry() |
| 36 | * fdt_finish_reservemap() [moves to 'struct' state] |
| 37 | */ |
| 38 | static int fdt_sw_probe_memrsv_(void *fdt) |
| 39 | { |
| 40 | int err = fdt_sw_probe_(fdt); |
| 41 | if (err) |
| 42 | return err; |
| 43 | |
| 44 | if (fdt_chk_extra() && fdt_off_dt_strings(fdt) != 0) |
| 45 | return -FDT_ERR_BADSTATE; |
| 46 | return 0; |
| 47 | } |
| 48 | |
| 49 | #define FDT_SW_PROBE_MEMRSV(fdt) \ |
| 50 | { \ |
| 51 | int err; \ |
| 52 | if (fdt_chk_extra() && (err = fdt_sw_probe_memrsv_(fdt)) != 0) \ |
| 53 | return err; \ |
| 54 | } |
| 55 | |
| 56 | /* 'struct' state: Enter this state after fdt_finish_reservemap() |
| 57 | * |
| 58 | * Allowed functions: |
| 59 | * fdt_begin_node() |
| 60 | * fdt_end_node() |
| 61 | * fdt_property*() |
| 62 | * fdt_finish() [moves to 'complete' state] |
| 63 | */ |
| 64 | static int fdt_sw_probe_struct_(void *fdt) |
Tom Rini | bd39173 | 2017-09-23 12:52:44 -0400 | [diff] [blame] | 65 | { |
Simon Glass | a5e1a58 | 2019-10-27 09:47:42 -0600 | [diff] [blame] | 66 | int err; |
| 67 | |
| 68 | if (!fdt_chk_extra()) |
| 69 | return 0; |
| 70 | err = fdt_sw_probe_(fdt); |
| 71 | if (err) |
| 72 | return err; |
| 73 | |
| 74 | if (fdt_off_dt_strings(fdt) != fdt_totalsize(fdt)) |
| 75 | return -FDT_ERR_BADSTATE; |
Tom Rini | bd39173 | 2017-09-23 12:52:44 -0400 | [diff] [blame] | 76 | return 0; |
| 77 | } |
| 78 | |
Simon Glass | a5e1a58 | 2019-10-27 09:47:42 -0600 | [diff] [blame] | 79 | #define FDT_SW_PROBE_STRUCT(fdt) \ |
Tom Rini | bd39173 | 2017-09-23 12:52:44 -0400 | [diff] [blame] | 80 | { \ |
| 81 | int err; \ |
Simon Glass | a5e1a58 | 2019-10-27 09:47:42 -0600 | [diff] [blame] | 82 | if (fdt_chk_extra() && (err = fdt_sw_probe_struct_(fdt)) != 0) \ |
Tom Rini | bd39173 | 2017-09-23 12:52:44 -0400 | [diff] [blame] | 83 | return err; \ |
| 84 | } |
| 85 | |
Simon Glass | a5e1a58 | 2019-10-27 09:47:42 -0600 | [diff] [blame] | 86 | static inline uint32_t sw_flags(void *fdt) |
| 87 | { |
| 88 | /* assert: (fdt_magic(fdt) == FDT_SW_MAGIC) */ |
| 89 | return fdt_last_comp_version(fdt); |
| 90 | } |
| 91 | |
| 92 | /* 'complete' state: Enter this state after fdt_finish() |
| 93 | * |
| 94 | * Allowed functions: none |
| 95 | */ |
| 96 | |
Rob Herring | cd5f70d | 2018-05-19 14:13:53 +0200 | [diff] [blame] | 97 | static void *fdt_grab_space_(void *fdt, size_t len) |
Tom Rini | bd39173 | 2017-09-23 12:52:44 -0400 | [diff] [blame] | 98 | { |
| 99 | int offset = fdt_size_dt_struct(fdt); |
| 100 | int spaceleft; |
| 101 | |
| 102 | spaceleft = fdt_totalsize(fdt) - fdt_off_dt_struct(fdt) |
| 103 | - fdt_size_dt_strings(fdt); |
| 104 | |
| 105 | if ((offset + len < offset) || (offset + len > spaceleft)) |
| 106 | return NULL; |
| 107 | |
| 108 | fdt_set_size_dt_struct(fdt, offset + len); |
Rob Herring | cd5f70d | 2018-05-19 14:13:53 +0200 | [diff] [blame] | 109 | return fdt_offset_ptr_w_(fdt, offset); |
Tom Rini | bd39173 | 2017-09-23 12:52:44 -0400 | [diff] [blame] | 110 | } |
| 111 | |
Simon Glass | a5e1a58 | 2019-10-27 09:47:42 -0600 | [diff] [blame] | 112 | int fdt_create_with_flags(void *buf, int bufsize, uint32_t flags) |
Tom Rini | bd39173 | 2017-09-23 12:52:44 -0400 | [diff] [blame] | 113 | { |
Simon Glass | a5e1a58 | 2019-10-27 09:47:42 -0600 | [diff] [blame] | 114 | const size_t hdrsize = FDT_ALIGN(sizeof(struct fdt_header), |
| 115 | sizeof(struct fdt_reserve_entry)); |
Tom Rini | bd39173 | 2017-09-23 12:52:44 -0400 | [diff] [blame] | 116 | void *fdt = buf; |
| 117 | |
Simon Glass | a5e1a58 | 2019-10-27 09:47:42 -0600 | [diff] [blame] | 118 | if (bufsize < hdrsize) |
Tom Rini | bd39173 | 2017-09-23 12:52:44 -0400 | [diff] [blame] | 119 | return -FDT_ERR_NOSPACE; |
| 120 | |
Simon Glass | a5e1a58 | 2019-10-27 09:47:42 -0600 | [diff] [blame] | 121 | if (flags & ~FDT_CREATE_FLAGS_ALL) |
| 122 | return -FDT_ERR_BADFLAGS; |
| 123 | |
Tom Rini | bd39173 | 2017-09-23 12:52:44 -0400 | [diff] [blame] | 124 | memset(buf, 0, bufsize); |
| 125 | |
Simon Glass | a5e1a58 | 2019-10-27 09:47:42 -0600 | [diff] [blame] | 126 | /* |
| 127 | * magic and last_comp_version keep intermediate state during the fdt |
| 128 | * creation process, which is replaced with the proper FDT format by |
| 129 | * fdt_finish(). |
| 130 | * |
| 131 | * flags should be accessed with sw_flags(). |
| 132 | */ |
Tom Rini | bd39173 | 2017-09-23 12:52:44 -0400 | [diff] [blame] | 133 | fdt_set_magic(fdt, FDT_SW_MAGIC); |
| 134 | fdt_set_version(fdt, FDT_LAST_SUPPORTED_VERSION); |
Simon Glass | a5e1a58 | 2019-10-27 09:47:42 -0600 | [diff] [blame] | 135 | fdt_set_last_comp_version(fdt, flags); |
| 136 | |
Tom Rini | bd39173 | 2017-09-23 12:52:44 -0400 | [diff] [blame] | 137 | fdt_set_totalsize(fdt, bufsize); |
| 138 | |
Simon Glass | a5e1a58 | 2019-10-27 09:47:42 -0600 | [diff] [blame] | 139 | fdt_set_off_mem_rsvmap(fdt, hdrsize); |
Tom Rini | bd39173 | 2017-09-23 12:52:44 -0400 | [diff] [blame] | 140 | fdt_set_off_dt_struct(fdt, fdt_off_mem_rsvmap(fdt)); |
Simon Glass | a5e1a58 | 2019-10-27 09:47:42 -0600 | [diff] [blame] | 141 | fdt_set_off_dt_strings(fdt, 0); |
Tom Rini | bd39173 | 2017-09-23 12:52:44 -0400 | [diff] [blame] | 142 | |
| 143 | return 0; |
| 144 | } |
| 145 | |
Simon Glass | a5e1a58 | 2019-10-27 09:47:42 -0600 | [diff] [blame] | 146 | int fdt_create(void *buf, int bufsize) |
| 147 | { |
| 148 | return fdt_create_with_flags(buf, bufsize, 0); |
| 149 | } |
| 150 | |
Tom Rini | bd39173 | 2017-09-23 12:52:44 -0400 | [diff] [blame] | 151 | int fdt_resize(void *fdt, void *buf, int bufsize) |
| 152 | { |
| 153 | size_t headsize, tailsize; |
| 154 | char *oldtail, *newtail; |
| 155 | |
Simon Glass | a5e1a58 | 2019-10-27 09:47:42 -0600 | [diff] [blame] | 156 | FDT_SW_PROBE(fdt); |
Tom Rini | bd39173 | 2017-09-23 12:52:44 -0400 | [diff] [blame] | 157 | |
Simon Glass | 14ec68c | 2019-07-20 12:23:59 -0600 | [diff] [blame] | 158 | headsize = fdt_off_dt_struct(fdt) + fdt_size_dt_struct(fdt); |
Tom Rini | bd39173 | 2017-09-23 12:52:44 -0400 | [diff] [blame] | 159 | tailsize = fdt_size_dt_strings(fdt); |
| 160 | |
Simon Glass | a5e1a58 | 2019-10-27 09:47:42 -0600 | [diff] [blame] | 161 | if (fdt_chk_extra() && (headsize + tailsize) > fdt_totalsize(fdt)) |
| 162 | return -FDT_ERR_INTERNAL; |
| 163 | |
Tom Rini | bd39173 | 2017-09-23 12:52:44 -0400 | [diff] [blame] | 164 | if ((headsize + tailsize) > bufsize) |
| 165 | return -FDT_ERR_NOSPACE; |
| 166 | |
| 167 | oldtail = (char *)fdt + fdt_totalsize(fdt) - tailsize; |
| 168 | newtail = (char *)buf + bufsize - tailsize; |
| 169 | |
| 170 | /* Two cases to avoid clobbering data if the old and new |
| 171 | * buffers partially overlap */ |
| 172 | if (buf <= fdt) { |
| 173 | memmove(buf, fdt, headsize); |
| 174 | memmove(newtail, oldtail, tailsize); |
| 175 | } else { |
| 176 | memmove(newtail, oldtail, tailsize); |
| 177 | memmove(buf, fdt, headsize); |
| 178 | } |
| 179 | |
Tom Rini | bd39173 | 2017-09-23 12:52:44 -0400 | [diff] [blame] | 180 | fdt_set_totalsize(buf, bufsize); |
Simon Glass | a5e1a58 | 2019-10-27 09:47:42 -0600 | [diff] [blame] | 181 | if (fdt_off_dt_strings(buf)) |
| 182 | fdt_set_off_dt_strings(buf, bufsize); |
Tom Rini | bd39173 | 2017-09-23 12:52:44 -0400 | [diff] [blame] | 183 | |
| 184 | return 0; |
| 185 | } |
| 186 | |
| 187 | int fdt_add_reservemap_entry(void *fdt, uint64_t addr, uint64_t size) |
| 188 | { |
| 189 | struct fdt_reserve_entry *re; |
| 190 | int offset; |
| 191 | |
Simon Glass | a5e1a58 | 2019-10-27 09:47:42 -0600 | [diff] [blame] | 192 | FDT_SW_PROBE_MEMRSV(fdt); |
Tom Rini | bd39173 | 2017-09-23 12:52:44 -0400 | [diff] [blame] | 193 | |
| 194 | offset = fdt_off_dt_struct(fdt); |
| 195 | if ((offset + sizeof(*re)) > fdt_totalsize(fdt)) |
| 196 | return -FDT_ERR_NOSPACE; |
| 197 | |
| 198 | re = (struct fdt_reserve_entry *)((char *)fdt + offset); |
| 199 | re->address = cpu_to_fdt64(addr); |
| 200 | re->size = cpu_to_fdt64(size); |
| 201 | |
| 202 | fdt_set_off_dt_struct(fdt, offset + sizeof(*re)); |
| 203 | |
| 204 | return 0; |
| 205 | } |
| 206 | |
| 207 | int fdt_finish_reservemap(void *fdt) |
| 208 | { |
Simon Glass | a5e1a58 | 2019-10-27 09:47:42 -0600 | [diff] [blame] | 209 | int err = fdt_add_reservemap_entry(fdt, 0, 0); |
| 210 | |
| 211 | if (err) |
| 212 | return err; |
| 213 | |
| 214 | fdt_set_off_dt_strings(fdt, fdt_totalsize(fdt)); |
| 215 | return 0; |
Tom Rini | bd39173 | 2017-09-23 12:52:44 -0400 | [diff] [blame] | 216 | } |
| 217 | |
| 218 | int fdt_begin_node(void *fdt, const char *name) |
| 219 | { |
| 220 | struct fdt_node_header *nh; |
Simon Glass | a5e1a58 | 2019-10-27 09:47:42 -0600 | [diff] [blame] | 221 | int namelen; |
Tom Rini | bd39173 | 2017-09-23 12:52:44 -0400 | [diff] [blame] | 222 | |
Simon Glass | a5e1a58 | 2019-10-27 09:47:42 -0600 | [diff] [blame] | 223 | FDT_SW_PROBE_STRUCT(fdt); |
Tom Rini | bd39173 | 2017-09-23 12:52:44 -0400 | [diff] [blame] | 224 | |
Simon Glass | a5e1a58 | 2019-10-27 09:47:42 -0600 | [diff] [blame] | 225 | namelen = strlen(name) + 1; |
Rob Herring | cd5f70d | 2018-05-19 14:13:53 +0200 | [diff] [blame] | 226 | nh = fdt_grab_space_(fdt, sizeof(*nh) + FDT_TAGALIGN(namelen)); |
Tom Rini | bd39173 | 2017-09-23 12:52:44 -0400 | [diff] [blame] | 227 | if (! nh) |
| 228 | return -FDT_ERR_NOSPACE; |
| 229 | |
| 230 | nh->tag = cpu_to_fdt32(FDT_BEGIN_NODE); |
| 231 | memcpy(nh->name, name, namelen); |
| 232 | return 0; |
| 233 | } |
| 234 | |
| 235 | int fdt_end_node(void *fdt) |
| 236 | { |
| 237 | fdt32_t *en; |
| 238 | |
Simon Glass | a5e1a58 | 2019-10-27 09:47:42 -0600 | [diff] [blame] | 239 | FDT_SW_PROBE_STRUCT(fdt); |
Tom Rini | bd39173 | 2017-09-23 12:52:44 -0400 | [diff] [blame] | 240 | |
Rob Herring | cd5f70d | 2018-05-19 14:13:53 +0200 | [diff] [blame] | 241 | en = fdt_grab_space_(fdt, FDT_TAGSIZE); |
Tom Rini | bd39173 | 2017-09-23 12:52:44 -0400 | [diff] [blame] | 242 | if (! en) |
| 243 | return -FDT_ERR_NOSPACE; |
| 244 | |
| 245 | *en = cpu_to_fdt32(FDT_END_NODE); |
| 246 | return 0; |
| 247 | } |
| 248 | |
Simon Glass | a5e1a58 | 2019-10-27 09:47:42 -0600 | [diff] [blame] | 249 | static int fdt_add_string_(void *fdt, const char *s) |
Tom Rini | bd39173 | 2017-09-23 12:52:44 -0400 | [diff] [blame] | 250 | { |
| 251 | char *strtab = (char *)fdt + fdt_totalsize(fdt); |
Tom Rini | bd39173 | 2017-09-23 12:52:44 -0400 | [diff] [blame] | 252 | int strtabsize = fdt_size_dt_strings(fdt); |
| 253 | int len = strlen(s) + 1; |
| 254 | int struct_top, offset; |
| 255 | |
Tom Rini | bd39173 | 2017-09-23 12:52:44 -0400 | [diff] [blame] | 256 | offset = -strtabsize - len; |
| 257 | struct_top = fdt_off_dt_struct(fdt) + fdt_size_dt_struct(fdt); |
| 258 | if (fdt_totalsize(fdt) + offset < struct_top) |
| 259 | return 0; /* no more room :( */ |
| 260 | |
| 261 | memcpy(strtab + offset, s, len); |
| 262 | fdt_set_size_dt_strings(fdt, strtabsize + len); |
| 263 | return offset; |
| 264 | } |
| 265 | |
Simon Glass | a5e1a58 | 2019-10-27 09:47:42 -0600 | [diff] [blame] | 266 | /* Must only be used to roll back in case of error */ |
| 267 | static void fdt_del_last_string_(void *fdt, const char *s) |
| 268 | { |
| 269 | int strtabsize = fdt_size_dt_strings(fdt); |
| 270 | int len = strlen(s) + 1; |
| 271 | |
| 272 | fdt_set_size_dt_strings(fdt, strtabsize - len); |
| 273 | } |
| 274 | |
| 275 | static int fdt_find_add_string_(void *fdt, const char *s, int *allocated) |
| 276 | { |
| 277 | char *strtab = (char *)fdt + fdt_totalsize(fdt); |
| 278 | int strtabsize = fdt_size_dt_strings(fdt); |
| 279 | const char *p; |
| 280 | |
| 281 | *allocated = 0; |
| 282 | |
| 283 | p = fdt_find_string_(strtab - strtabsize, strtabsize, s); |
| 284 | if (p) |
| 285 | return p - strtab; |
| 286 | |
| 287 | *allocated = 1; |
| 288 | |
| 289 | return fdt_add_string_(fdt, s); |
| 290 | } |
| 291 | |
Tom Rini | 0eb096d | 2017-09-23 17:31:59 -0400 | [diff] [blame] | 292 | int fdt_property_placeholder(void *fdt, const char *name, int len, void **valp) |
Tom Rini | bd39173 | 2017-09-23 12:52:44 -0400 | [diff] [blame] | 293 | { |
| 294 | struct fdt_property *prop; |
| 295 | int nameoff; |
Simon Glass | a5e1a58 | 2019-10-27 09:47:42 -0600 | [diff] [blame] | 296 | int allocated; |
Tom Rini | bd39173 | 2017-09-23 12:52:44 -0400 | [diff] [blame] | 297 | |
Simon Glass | a5e1a58 | 2019-10-27 09:47:42 -0600 | [diff] [blame] | 298 | FDT_SW_PROBE_STRUCT(fdt); |
Tom Rini | bd39173 | 2017-09-23 12:52:44 -0400 | [diff] [blame] | 299 | |
Simon Glass | a5e1a58 | 2019-10-27 09:47:42 -0600 | [diff] [blame] | 300 | /* String de-duplication can be slow, _NO_NAME_DEDUP skips it */ |
| 301 | if (sw_flags(fdt) & FDT_CREATE_FLAG_NO_NAME_DEDUP) { |
| 302 | allocated = 1; |
| 303 | nameoff = fdt_add_string_(fdt, name); |
| 304 | } else { |
| 305 | nameoff = fdt_find_add_string_(fdt, name, &allocated); |
| 306 | } |
Tom Rini | bd39173 | 2017-09-23 12:52:44 -0400 | [diff] [blame] | 307 | if (nameoff == 0) |
| 308 | return -FDT_ERR_NOSPACE; |
| 309 | |
Rob Herring | cd5f70d | 2018-05-19 14:13:53 +0200 | [diff] [blame] | 310 | prop = fdt_grab_space_(fdt, sizeof(*prop) + FDT_TAGALIGN(len)); |
Simon Glass | a5e1a58 | 2019-10-27 09:47:42 -0600 | [diff] [blame] | 311 | if (! prop) { |
| 312 | if (allocated) |
| 313 | fdt_del_last_string_(fdt, name); |
Tom Rini | bd39173 | 2017-09-23 12:52:44 -0400 | [diff] [blame] | 314 | return -FDT_ERR_NOSPACE; |
Simon Glass | a5e1a58 | 2019-10-27 09:47:42 -0600 | [diff] [blame] | 315 | } |
Tom Rini | bd39173 | 2017-09-23 12:52:44 -0400 | [diff] [blame] | 316 | |
| 317 | prop->tag = cpu_to_fdt32(FDT_PROP); |
| 318 | prop->nameoff = cpu_to_fdt32(nameoff); |
| 319 | prop->len = cpu_to_fdt32(len); |
Tom Rini | 0eb096d | 2017-09-23 17:31:59 -0400 | [diff] [blame] | 320 | *valp = prop->data; |
| 321 | return 0; |
| 322 | } |
| 323 | |
| 324 | int fdt_property(void *fdt, const char *name, const void *val, int len) |
| 325 | { |
| 326 | void *ptr; |
| 327 | int ret; |
| 328 | |
| 329 | ret = fdt_property_placeholder(fdt, name, len, &ptr); |
| 330 | if (ret) |
| 331 | return ret; |
| 332 | memcpy(ptr, val, len); |
Tom Rini | bd39173 | 2017-09-23 12:52:44 -0400 | [diff] [blame] | 333 | return 0; |
| 334 | } |
| 335 | |
| 336 | int fdt_finish(void *fdt) |
| 337 | { |
| 338 | char *p = (char *)fdt; |
| 339 | fdt32_t *end; |
| 340 | int oldstroffset, newstroffset; |
| 341 | uint32_t tag; |
| 342 | int offset, nextoffset; |
| 343 | |
Simon Glass | a5e1a58 | 2019-10-27 09:47:42 -0600 | [diff] [blame] | 344 | FDT_SW_PROBE_STRUCT(fdt); |
Tom Rini | bd39173 | 2017-09-23 12:52:44 -0400 | [diff] [blame] | 345 | |
| 346 | /* Add terminator */ |
Rob Herring | cd5f70d | 2018-05-19 14:13:53 +0200 | [diff] [blame] | 347 | end = fdt_grab_space_(fdt, sizeof(*end)); |
Tom Rini | bd39173 | 2017-09-23 12:52:44 -0400 | [diff] [blame] | 348 | if (! end) |
| 349 | return -FDT_ERR_NOSPACE; |
| 350 | *end = cpu_to_fdt32(FDT_END); |
| 351 | |
| 352 | /* Relocate the string table */ |
| 353 | oldstroffset = fdt_totalsize(fdt) - fdt_size_dt_strings(fdt); |
| 354 | newstroffset = fdt_off_dt_struct(fdt) + fdt_size_dt_struct(fdt); |
| 355 | memmove(p + newstroffset, p + oldstroffset, fdt_size_dt_strings(fdt)); |
| 356 | fdt_set_off_dt_strings(fdt, newstroffset); |
| 357 | |
| 358 | /* Walk the structure, correcting string offsets */ |
| 359 | offset = 0; |
| 360 | while ((tag = fdt_next_tag(fdt, offset, &nextoffset)) != FDT_END) { |
| 361 | if (tag == FDT_PROP) { |
| 362 | struct fdt_property *prop = |
Rob Herring | cd5f70d | 2018-05-19 14:13:53 +0200 | [diff] [blame] | 363 | fdt_offset_ptr_w_(fdt, offset); |
Tom Rini | bd39173 | 2017-09-23 12:52:44 -0400 | [diff] [blame] | 364 | int nameoff; |
| 365 | |
| 366 | nameoff = fdt32_to_cpu(prop->nameoff); |
| 367 | nameoff += fdt_size_dt_strings(fdt); |
| 368 | prop->nameoff = cpu_to_fdt32(nameoff); |
| 369 | } |
| 370 | offset = nextoffset; |
| 371 | } |
| 372 | if (nextoffset < 0) |
| 373 | return nextoffset; |
| 374 | |
| 375 | /* Finally, adjust the header */ |
| 376 | fdt_set_totalsize(fdt, newstroffset + fdt_size_dt_strings(fdt)); |
Simon Glass | a5e1a58 | 2019-10-27 09:47:42 -0600 | [diff] [blame] | 377 | |
| 378 | /* And fix up fields that were keeping intermediate state. */ |
| 379 | fdt_set_last_comp_version(fdt, FDT_FIRST_SUPPORTED_VERSION); |
Tom Rini | bd39173 | 2017-09-23 12:52:44 -0400 | [diff] [blame] | 380 | fdt_set_magic(fdt, FDT_MAGIC); |
Simon Glass | a5e1a58 | 2019-10-27 09:47:42 -0600 | [diff] [blame] | 381 | |
Tom Rini | bd39173 | 2017-09-23 12:52:44 -0400 | [diff] [blame] | 382 | return 0; |
| 383 | } |