mirror of
https://github.com/dgibson/dtc.git
synced 2025-10-13 16:27:39 -04:00
libfdt: Handle v16 and re-ordered trees for r/w
Currently all the read/write functions in libfdt require that the given tree be v17, and further, that the tree has the memory reservation block, structure block and strings block stored in that physical order. This patch eases these constraints, by making fdt_open_int() reorder the blocks, and/or convert the tree to v17, so that it will then be ready for the other read-write functions. It also extends fdt_pack() to actually remove any gaps between blocks that might be present. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
This commit is contained in:
parent
4a5df5c026
commit
a041dcdc48
7 changed files with 130 additions and 32 deletions
|
@ -220,3 +220,21 @@ void save_blob(const char *filename, void *fdt)
|
|||
offset += ret;
|
||||
}
|
||||
}
|
||||
|
||||
void *open_blob_rw(void *blob)
|
||||
{
|
||||
int err;
|
||||
void *buf = blob;
|
||||
|
||||
err = fdt_open_into(blob, buf, fdt_totalsize(blob));
|
||||
if (err == -FDT_ERR_NOSPACE) {
|
||||
/* Ran out of space converting to v17 */
|
||||
int newsize = fdt_totalsize(blob) + 8;
|
||||
|
||||
buf = xmalloc(newsize);
|
||||
err = fdt_open_into(blob, buf, newsize);
|
||||
}
|
||||
if (err)
|
||||
FAIL("fdt_open_into(): %s", fdt_strerror(err));
|
||||
return buf;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue