diff options
author | Simon Glass <sjg@chromium.org> | 2014-07-30 03:59:03 -0600 |
---|---|---|
committer | Tom Rini <trini@ti.com> | 2014-08-09 11:17:04 -0400 |
commit | 0596d35d80f5090440bd9a2a2beaacb268ff59c0 (patch) | |
tree | ae3d87ad5ca521d3f9f2f714fb9c0afe68e4c905 /lib/libfdt/fdt_sw.c | |
parent | 5bf58ccc8ebd5270f64a20c4c54c98a96acbd7ed (diff) | |
download | u-boot-0596d35d80f5090440bd9a2a2beaacb268ff59c0.tar.gz |
fdt: Sync up with libfdt
This brings in changes up to commit f9e91a48 in the libfdt repo.
Mostly this is whitespace/minor changes. But there are a few new
features:
- fdt_size_cells() and fdt_address_cells()
- fdt_resize()
Signed-off-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'lib/libfdt/fdt_sw.c')
-rw-r--r-- | lib/libfdt/fdt_sw.c | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/lib/libfdt/fdt_sw.c b/lib/libfdt/fdt_sw.c index 580b57024f..320a914991 100644 --- a/lib/libfdt/fdt_sw.c +++ b/lib/libfdt/fdt_sw.c @@ -62,6 +62,38 @@ int fdt_create(void *buf, int bufsize) return 0; } +int fdt_resize(void *fdt, void *buf, int bufsize) +{ + size_t headsize, tailsize; + char *oldtail, *newtail; + + FDT_SW_CHECK_HEADER(fdt); + + headsize = fdt_off_dt_struct(fdt); + tailsize = fdt_size_dt_strings(fdt); + + if ((headsize + tailsize) > bufsize) + return -FDT_ERR_NOSPACE; + + oldtail = (char *)fdt + fdt_totalsize(fdt) - tailsize; + newtail = (char *)buf + bufsize - tailsize; + + /* Two cases to avoid clobbering data if the old and new + * buffers partially overlap */ + if (buf <= fdt) { + memmove(buf, fdt, headsize); + memmove(newtail, oldtail, tailsize); + } else { + memmove(newtail, oldtail, tailsize); + memmove(buf, fdt, headsize); + } + + fdt_set_off_dt_strings(buf, bufsize); + fdt_set_totalsize(buf, bufsize); + + return 0; +} + int fdt_add_reservemap_entry(void *fdt, uint64_t addr, uint64_t size) { struct fdt_reserve_entry *re; |