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:
David Gibson 2007-11-01 11:37:31 +11:00 committed by Jon Loeliger
parent 4a5df5c026
commit a041dcdc48
7 changed files with 130 additions and 32 deletions

View file

@ -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;
}