From c20ee0ed070953600b54b16c8b48725348abead5 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Tue, 29 Aug 2017 14:15:50 -0600 Subject: dtoc: Add support for 32 or 64-bit addresses When using 32-bit addresses dtoc works correctly. For 64-bit addresses it does not since it ignores the #address-cells and #size-cells properties. Update the tool to use fdt64_t as the element type for reg properties when either the address or size is larger than one cell. Use the correct value so that C code can obtain the information from the device tree easily. Alos create a new type, fdt_val_t, which is defined to either fdt32_t or fdt64_t depending on the word size of the machine. This type corresponds to fdt_addr_t and fdt_size_t. Unfortunately we cannot just use those types since they are defined to phys_addr_t and phys_size_t which use 'unsigned long' in the 32-bit case, rather than 'unsigned int'. Add tests for the four combinations of address and size values (32/32, 64/64, 32/64, 64/32). Also update existing uses for rk3399 and rk3368 which now need to use the new fdt_val_t type. Signed-off-by: Simon Glass Suggested-by: Heiko Stuebner Reported-by: Kever Yang Reviewed-by: Philipp Tomsich Tested-by: Kever Yang --- include/fdtdec.h | 2 ++ include/regmap.h | 2 +- include/syscon.h | 6 +++++- 3 files changed, 8 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/fdtdec.h b/include/fdtdec.h index 4a0947c626..1ba02be8e1 100644 --- a/include/fdtdec.h +++ b/include/fdtdec.h @@ -27,10 +27,12 @@ typedef phys_size_t fdt_size_t; #define FDT_ADDR_T_NONE (-1ULL) #define fdt_addr_to_cpu(reg) be64_to_cpu(reg) #define fdt_size_to_cpu(reg) be64_to_cpu(reg) +typedef fdt64_t fdt_val_t; #else #define FDT_ADDR_T_NONE (-1U) #define fdt_addr_to_cpu(reg) be32_to_cpu(reg) #define fdt_size_to_cpu(reg) be32_to_cpu(reg) +typedef fdt32_t fdt_val_t; #endif /* Information obtained about memory from the FDT */ diff --git a/include/regmap.h b/include/regmap.h index 1eed94e47a..493a5d8eff 100644 --- a/include/regmap.h +++ b/include/regmap.h @@ -69,7 +69,7 @@ int regmap_init_mem(struct udevice *dev, struct regmap **mapp); * @count: Number of pairs (e.g. 1 if the regmap has a single entry) * @mapp: Returns allocated map */ -int regmap_init_mem_platdata(struct udevice *dev, u32 *reg, int count, +int regmap_init_mem_platdata(struct udevice *dev, fdt_val_t *reg, int count, struct regmap **mapp); /** diff --git a/include/syscon.h b/include/syscon.h index 34842aa470..5d52b1cc3c 100644 --- a/include/syscon.h +++ b/include/syscon.h @@ -8,6 +8,8 @@ #ifndef __SYSCON_H #define __SYSCON_H +#include + /** * struct syscon_uc_info - Information stored by the syscon UCLASS_UCLASS * @@ -28,9 +30,11 @@ struct syscon_ops { * We don't support 64-bit machines. If they are so resource-contrained that * they need to use OF_PLATDATA, something is horribly wrong with the * education of our hardware engineers. + * + * Update: 64-bit is now supported and we have an education crisis. */ struct syscon_base_platdata { - u32 reg[2]; + fdt_val_t reg[2]; }; #endif -- cgit From 0d15463c0537806f70ea2359e32e4deb8c4766c2 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Tue, 29 Aug 2017 14:15:56 -0600 Subject: dtoc: Rename the phandle struct Rather than naming the phandle struct according to the number of cells it uses (e.g. struct phandle_2_cell) name it according to the number of arguments it has (e.g. struct phandle_1_arg). This is a more intuitive naming. Signed-off-by: Simon Glass Tested-by: Kever Yang --- include/clk.h | 4 ++-- include/dt-structs.h | 7 ++++++- 2 files changed, 8 insertions(+), 3 deletions(-) (limited to 'include') diff --git a/include/clk.h b/include/clk.h index c5988f78a8..e7ce3e8576 100644 --- a/include/clk.h +++ b/include/clk.h @@ -61,9 +61,9 @@ struct clk { }; #if CONFIG_IS_ENABLED(OF_CONTROL) && CONFIG_IS_ENABLED(CLK) -struct phandle_2_cell; +struct phandle_1_arg; int clk_get_by_index_platdata(struct udevice *dev, int index, - struct phandle_2_cell *cells, struct clk *clk); + struct phandle_1_arg *cells, struct clk *clk); /** * clock_get_by_index - Get/request a clock by integer index. diff --git a/include/dt-structs.h b/include/dt-structs.h index 0732c442ff..2ed997115a 100644 --- a/include/dt-structs.h +++ b/include/dt-structs.h @@ -9,7 +9,12 @@ /* These structures may only be used in SPL */ #if CONFIG_IS_ENABLED(OF_PLATDATA) -struct phandle_2_cell { +struct phandle_0_arg { + const void *node; + int id[0]; +}; + +struct phandle_1_arg { const void *node; int id; }; -- cgit From bc79617fdfeb4afabb94774885447dd64d7bea6c Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Tue, 29 Aug 2017 14:15:58 -0600 Subject: dtoc: Put phandle args in an array We want to support more than one phandle argument. It makes sense to use an array for this rather than discrete struct members. Adjust the code to support this. Rename the member to 'arg' instead of 'id'. Signed-off-by: Simon Glass Tested-by: Kever Yang --- include/dt-structs.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/dt-structs.h b/include/dt-structs.h index 2ed997115a..9ab4e2524d 100644 --- a/include/dt-structs.h +++ b/include/dt-structs.h @@ -11,12 +11,12 @@ #if CONFIG_IS_ENABLED(OF_PLATDATA) struct phandle_0_arg { const void *node; - int id[0]; + int arg[0]; }; struct phandle_1_arg { const void *node; - int id; + int arg[1]; }; #include #endif -- cgit From 634eba4be060af3bcba51cba2d57d217df897f31 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Tue, 29 Aug 2017 14:15:59 -0600 Subject: dtoc: Support properties containing multiple phandle values At present dtoc has a very simplistic view of phandles. It assumes that a property has only a single phandle with a single argument (i.e. two cells per property). This is not true in many cases. Enhance the implementation to scan all phandles in a property and to use the correct number of arguments (which can be 0, 1, 2 or more) when generating the C code. For the struct definitions, use a struct which can hold the maximum number of arguments used by the property. Signed-off-by: Simon Glass Tested-by: Kever Yang --- include/dt-structs.h | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'include') diff --git a/include/dt-structs.h b/include/dt-structs.h index 9ab4e2524d..76979e73e1 100644 --- a/include/dt-structs.h +++ b/include/dt-structs.h @@ -18,6 +18,11 @@ struct phandle_1_arg { const void *node; int arg[1]; }; + +struct phandle_2_arg { + const void *node; + int arg[2]; +}; #include #endif -- cgit From b145b45b0ce26028d9ad6ea8277c052c3c87ea56 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Tue, 29 Aug 2017 14:16:00 -0600 Subject: dtoc: Rename the auto-generated dt-structs.h file The filename of the auto-generated file is the same as the file that includes it. Even though the form is in the generated/ subdirectory, this could be confused. Rename the generated file to something that makes it clear it is auto-generated. Signed-off-by: Simon Glass Tested-by: Kever Yang --- include/dt-structs.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include') diff --git a/include/dt-structs.h b/include/dt-structs.h index 76979e73e1..c0f56951b5 100644 --- a/include/dt-structs.h +++ b/include/dt-structs.h @@ -23,7 +23,7 @@ struct phandle_2_arg { const void *node; int arg[2]; }; -#include +#include #endif #endif -- cgit From fc7c31891c40dd1aac2e71e9d1546727ca2b3556 Mon Sep 17 00:00:00 2001 From: Pantelis Antoniou Date: Mon, 4 Sep 2017 23:12:11 +0300 Subject: fdt: Introduce helper method fdt_overlay_apply_verbose() Introduce fdt_overlay_apply_verbose, a method that applies an overlay but in the case of an error produces a helpful message. In addition if a base tree is found to be missing the __symbols__ node the message will point out that the probable reason is that the base tree was miscompiled without the -@ option. Signed-off-by: Pantelis Antoniou Acked-by: Simon Glass --- include/fdt_support.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'include') diff --git a/include/fdt_support.h b/include/fdt_support.h index 5ef78cce6e..2bca4d7889 100644 --- a/include/fdt_support.h +++ b/include/fdt_support.h @@ -264,6 +264,8 @@ int arch_fixup_memory_node(void *blob); int fdt_setup_simplefb_node(void *fdt, int node, u64 base_address, u32 width, u32 height, u32 stride, const char *format); +int fdt_overlay_apply_verbose(void *fdt, void *fdto); + #endif /* ifdef CONFIG_OF_LIBFDT */ #ifdef USE_HOSTCC -- cgit From 169043d826e6b0db3c67a60acbedfc72c43aae5d Mon Sep 17 00:00:00 2001 From: Pantelis Antoniou Date: Mon, 4 Sep 2017 23:12:16 +0300 Subject: fit: Introduce methods for applying overlays on fit-load Introduce an overlay based method for constructing a base DT blob to pass to the kernel. It is based on a specific method now to get the FDT from a FIT image named boot_get_fdt_fit(). Signed-off-by: Pantelis Antoniou Acked-by: Simon Glass --- include/image.h | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'include') diff --git a/include/image.h b/include/image.h index 339f79c6dc..af98ed9f25 100644 --- a/include/image.h +++ b/include/image.h @@ -593,6 +593,31 @@ int boot_get_loadable(int argc, char * const argv[], bootm_headers_t *images, int boot_get_setup_fit(bootm_headers_t *images, uint8_t arch, ulong *setup_start, ulong *setup_len); +/** + * boot_get_fdt_fit() - load a DTB from a FIT file (applying overlays) + * + * This deals with all aspects of loading an DTB from a FIT. + * The correct base image based on configuration will be selected, and + * then any overlays specified will be applied (as present in fit_uname_configp). + * + * @param images Boot images structure + * @param addr Address of FIT in memory + * @param fit_unamep On entry this is the requested image name + * (e.g. "kernel@1") or NULL to use the default. On exit + * points to the selected image name + * @param fit_uname_configp On entry this is the requested configuration + * name (e.g. "conf@1") or NULL to use the default. On + * exit points to the selected configuration name. + * @param arch Expected architecture (IH_ARCH_...) + * @param datap Returns address of loaded image + * @param lenp Returns length of loaded image + * + * @return node offset of base image, or -ve error code on error + */ +int boot_get_fdt_fit(bootm_headers_t *images, ulong addr, + const char **fit_unamep, const char **fit_uname_configp, + int arch, ulong *datap, ulong *lenp); + /** * fit_image_load() - load an image from a FIT * -- cgit