fdt: Rename fdt_resize() to fdt_shrink_to_minimum()
PATCH 1/2 fdt: Rename fdt_resize() to fdt_shrink_to_minimum()
Since libfdt now has an fdt_resize() function, we need to rename the U-Boot one.
---
common/cmd_fdt.c | 2 +- common/fdt_support.c | 2 +- common/image-fdt.c | 2 +- include/fdt_support.h | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-)
common/cmd_fdt.c +1 -1
@@ -621,7 +621,7 @@ static int do_fdt(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) }/* resize the fdt */ else if (strncmp (argv[1 ],"re" ,2 ) ==0 ) { -fdt_resize (working_fdt); +fdt_shrink_to_minimum (working_fdt); }else {/* Unrecognized command */
common/fdt_support.c +1 -1
@@ -508,7 +508,7 @@ void fdt_fixup_ethernet(void *fdt) }/* Resize the fdt to its actual size + a bit of padding */ -int fdt_resize (void *blob) +int fdt_shrink_to_minimum (void *blob) {int i;uint64_t addr, size;
common/image-fdt.c +1 -1
@@ -476,7 +476,7 @@ int image_setup_libfdt(bootm_headers_t *images, void *blob,lmb_free (lmb, (phys_addr_t )(u32 )(uintptr_t )blob, (phys_size_t )fdt_totalsize (blob)); - ret =fdt_resize (blob); + ret =fdt_shrink_to_minimum (blob);if (ret <0 )return ret; of_size = ret;
include/fdt_support.h +1 -1
@@ -76,7 +76,7 @@ void ft_cpu_setup(void *blob, bd_t *bd);void ft_pci_setup (void *blob,bd_t *bd);void set_working_fdt_addr (void *addr); -int fdt_resize (void *blob); +int fdt_shrink_to_minimum (void *blob);int fdt_increase_size (void *fdt,int add_len);int fdt_fixup_nor_flash_size (void *blob);
Signature · 1 line
2.0.0.526.g5318336
PATCH 2/2 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()
---
include/libfdt.h | 73 +++++++++++++++++++++++++++++++++++++++++--- lib/libfdt/Makefile | 3 +- lib/libfdt/fdt_addresses.c | 55 +++++++++++++++++++++++++++++++++ lib/libfdt/fdt_rw.c | 6 ++-- lib/libfdt/fdt_sw.c | 32 +++++++++++++++++++ lib/libfdt/libfdt_internal.h | 6 ++-- 6 files changed, 163 insertions(+), 12 deletions(-) create mode 100644 lib/libfdt/fdt_addresses.c
include/libfdt.h +68 -5
@@ -116,7 +116,12 @@* Should never be returned, if it is, it indicates a bug in * libfdt itself. */ -#define FDT_ERR_MAX 13 +/* Errors in device tree content */ +#define FDT_ERR_BADNCELLS 14 +/* FDT_ERR_BADNCELLS: Device tree has a #address-cells, #size-cells +* or similar property with a bad format or value */ + +#define FDT_ERR_MAX 14/**********************************************************************/ /* Low-level functions (you probably don't need these) */
@@ -596,9 +601,9 @@ const char *fdt_get_alias_namelen(const void *fdt, const char *name, int namelen);/** -* fdt_get_alias - retrieve the path referenced by a given alias +* fdt_get_alias - retreive the path referenced by a given alias * @fdt: pointer to the device tree blob -* @name: name of the alias to look up +* @name: name of the alias th look up * * fdt_get_alias() retrieves the value of a given alias. That is, the * value of the property named 'name' in the node /aliases.
@@ -731,7 +736,7 @@ int fdt_parent_offset(const void *fdt, int nodeoffset);* offset = fdt_node_offset_by_prop_value(fdt, -1, propname, * propval, proplen); * while (offset != -FDT_ERR_NOTFOUND) { -* ... other code here ... +* // other code here * offset = fdt_node_offset_by_prop_value(fdt, offset, propname, * propval, proplen); * }
@@ -816,7 +821,7 @@ int fdt_node_check_compatible(const void *fdt, int nodeoffset,* idiom can be used: * offset = fdt_node_offset_by_compatible(fdt, -1, compatible); * while (offset != -FDT_ERR_NOTFOUND) { -* ... other code here ... +* // other code here * offset = fdt_node_offset_by_compatible(fdt, offset, compatible); * } *
@@ -853,6 +858,63 @@ int fdt_node_offset_by_compatible(const void *fdt, int startoffset,int fdt_stringlist_contains (const char *strlist,int listlen,const char *str);/**********************************************************************/ +/* Read-only functions (addressing related) */ +/**********************************************************************/ + +/** +* FDT_MAX_NCELLS - maximum value for #address-cells and #size-cells +* +* This is the maximum value for #address-cells, #size-cells and +* similar properties that will be processed by libfdt. IEE1275 +* requires that OF implementations handle values up to 4. +* Implementations may support larger values, but in practice higher +* values aren't used. +*/ +#define FDT_MAX_NCELLS 4 + +/** +* fdt_address_cells - retrieve address size for a bus represented in the tree +* @fdt: pointer to the device tree blob +* @nodeoffset: offset of the node to find the address size for +* +* When the node has a valid #address-cells property, returns its value. +* +* returns: +* 0 <= n < FDT_MAX_NCELLS, on success +* 2, if the node has no #address-cells property +* -FDT_ERR_BADNCELLS, if the node has a badly formatted or invalid +* #address-cells property +* -FDT_ERR_BADMAGIC, +* -FDT_ERR_BADVERSION, +* -FDT_ERR_BADSTATE, +* -FDT_ERR_BADSTRUCTURE, +* -FDT_ERR_TRUNCATED, standard meanings +*/ +int fdt_address_cells (const void *fdt,int nodeoffset); + +/** +* fdt_size_cells - retrieve address range size for a bus represented in the +* tree +* @fdt: pointer to the device tree blob +* @nodeoffset: offset of the node to find the address range size for +* +* When the node has a valid #size-cells property, returns its value. +* +* returns: +* 0 <= n < FDT_MAX_NCELLS, on success +* 2, if the node has no #address-cells property +* -FDT_ERR_BADNCELLS, if the node has a badly formatted or invalid +* #size-cells property +* -FDT_ERR_BADMAGIC, +* -FDT_ERR_BADVERSION, +* -FDT_ERR_BADSTATE, +* -FDT_ERR_BADSTRUCTURE, +* -FDT_ERR_TRUNCATED, standard meanings +*/ +int fdt_size_cells (const void *fdt,int nodeoffset); + + +/**********************************************************************/ /* Write-in-place functions */ /**********************************************************************/
@@ -1023,6 +1085,7 @@ int fdt_nop_node(void *fdt, int nodeoffset);/**********************************************************************/ int fdt_create (void *buf,int bufsize); +int fdt_resize (void *fdt,void *buf,int bufsize);int fdt_add_reservemap_entry (void *fdt,uint64_t addr,uint64_t size);int fdt_finish_reservemap (void *fdt);int fdt_begin_node (void *fdt,const char *name);
lib/libfdt/Makefile +2 -1
@@ -5,7 +5,8 @@ # SPDX-License-Identifier: GPL-2.0+ # -COBJS-libfdt += fdt.o fdt_ro.o fdt_rw.o fdt_strerror.o fdt_sw.o fdt_wip.o fdt_empty_tree.o +COBJS-libfdt += fdt.o fdt_ro.o fdt_rw.o fdt_strerror.o fdt_sw.o fdt_wip.o \ + fdt_empty_tree.o fdt_addresses.o obj-$(CONFIG_OF_LIBFDT) += $(COBJS-libfdt) obj-$(CONFIG_FIT) += $(COBJS-libfdt)
lib/libfdt/fdt_addresses.c new file +55 -0
55 lines not on this page · raw message
lib/libfdt/fdt_rw.c +3 -3
@@ -43,9 +43,9 @@ static int _fdt_rw_check_header(void *fdt)#define FDT_RW_CHECK_HEADER (fdt) \ { \ - int err; \ - if ((err = _fdt_rw_check_header(fdt)) != 0) \ - return err; \ + int __err; \ + if ((__err = _fdt_rw_check_header(fdt)) != 0) \ + return __err; \ }static inline int _fdt_data_size (void *fdt)
lib/libfdt/fdt_sw.c +32 -0
@@ -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;
lib/libfdt/libfdt_internal.h +3 -3
@@ -12,9 +12,9 @@#define FDT_CHECK_HEADER (fdt) \ { \ - int err; \ - if ((err = fdt_check_header(fdt)) != 0) \ - return err; \ + int __err; \ + if ((__err = fdt_check_header(fdt)) != 0) \ + return __err; \ }int _fdt_check_node_offset (const void *fdt,int offset);
Signature · 1 line
2.0.0.526.g5318336
PATCH 2/2 fdt: Sync up with libfdt
Quoted 8 lines · Simon Glass
This brings in changes up to commit
f9e91a48in the libfdt repo. Mostly this is whitespace/minor changes. But there are a few new features:-
fdt_size_cells()andfdt_address_cells()
-fdt_resize()Signed-off-by Simon Glass <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 836 bytes Desc: Digital signature URL: <http://lists.denx.de/pipermail/u-boot/attachments/20140810/a9495b75/attachment.pgp>
PATCH 1/2 fdt: Rename fdt_resize() to fdt_shrink_to_minimum()
In reply to Simon GlassQuoted 4 lines · Simon Glass
Since libfdt now has an
fdt_resize()function, we need to rename the U-Boot one.Signed-off-by Simon Glass <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 836 bytes Desc: Digital signature URL: <http://lists.denx.de/pipermail/u-boot/attachments/20140810/c4f9e1ff/attachment.pgp>