From 82e26e0d6883673bdedbcdb0ddd4bc967ce6ce70 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Tue, 26 Sep 2023 08:14:16 -0600 Subject: spl: Use CONFIG_SPL... instead of CONFIG_..._SPL_... We like to put the SPL first so it is clear that it relates to SPL. Rename various malloc-related options which have crept in, to stick to this convention. Signed-off-by: Simon Glass Reviewed-by: Marcel Ziswiler Reviewed-by: Martyn Welch Reviewed-by: Svyatoslav Ryhel --- include/configs/socfpga_common.h | 2 +- include/configs/socfpga_soc64_common.h | 2 +- include/system-constants.h | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) (limited to 'include') diff --git a/include/configs/socfpga_common.h b/include/configs/socfpga_common.h index 0c96c9c24fe..4838bfd4f13 100644 --- a/include/configs/socfpga_common.h +++ b/include/configs/socfpga_common.h @@ -18,7 +18,7 @@ #define CFG_SYS_INIT_RAM_ADDR 0xFFE00000 /* SPL memory allocation configuration, this is for FAT implementation */ #define CFG_SYS_INIT_RAM_SIZE (SOCFPGA_PHYS_OCRAM_SIZE - \ - CONFIG_SYS_SPL_MALLOC_SIZE) + CONFIG_SPL_SYS_MALLOC_SIZE) #endif /* diff --git a/include/configs/socfpga_soc64_common.h b/include/configs/socfpga_soc64_common.h index 66ecb168a0a..820372c28b3 100644 --- a/include/configs/socfpga_soc64_common.h +++ b/include/configs/socfpga_soc64_common.h @@ -112,7 +112,7 @@ unsigned int cm_get_l4_sys_free_clk_hz(void); * SDRAM * 0x0000_0000 ...... Start of SDRAM_1 * unused / empty space for image loading - * Size 64MB ...... MALLOC (size CONFIG_SYS_SPL_MALLOC_SIZE) + * Size 64MB ...... MALLOC (size CONFIG_SPL_SYS_MALLOC_SIZE) * Size 1MB ...... BSS (size CONFIG_SPL_BSS_MAX_SIZE) * 0x8000_0000 ...... End of SDRAM_1 (assume 2GB) * diff --git a/include/system-constants.h b/include/system-constants.h index 0d6b71b35a0..f0a191be590 100644 --- a/include/system-constants.h +++ b/include/system-constants.h @@ -22,10 +22,10 @@ /* * Typically, we have the SPL malloc pool at the end of the BSS area. */ -#ifdef CONFIG_HAS_CUSTOM_SPL_MALLOC_START -#define SYS_SPL_MALLOC_START CONFIG_CUSTOM_SYS_SPL_MALLOC_ADDR +#ifdef CONFIG_SPL_HAS_CUSTOM_MALLOC_START +#define SPL_SYS_MALLOC_START CONFIG_SPL_CUSTOM_SYS_MALLOC_ADDR #else -#define SYS_SPL_MALLOC_START (CONFIG_SPL_BSS_START_ADDR + \ +#define SPL_SYS_MALLOC_START (CONFIG_SPL_BSS_START_ADDR + \ CONFIG_SPL_BSS_MAX_SIZE) #endif -- cgit v1.2.3 From 52779874dac3f096f9f7893f0b3603aeff4c646b Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Tue, 26 Sep 2023 08:14:18 -0600 Subject: spl: Avoid #ifdef with CONFIG_SPL_SYS_MALLOC Use IF_ENABLED_INT() to avoid needing to use the preprocessor. Signed-off-by: Simon Glass --- include/system-constants.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'include') diff --git a/include/system-constants.h b/include/system-constants.h index f0a191be590..dca6a86b01f 100644 --- a/include/system-constants.h +++ b/include/system-constants.h @@ -24,9 +24,14 @@ */ #ifdef CONFIG_SPL_HAS_CUSTOM_MALLOC_START #define SPL_SYS_MALLOC_START CONFIG_SPL_CUSTOM_SYS_MALLOC_ADDR -#else +#elif defined(CONFIG_SPL_BSS_START_ADDR) #define SPL_SYS_MALLOC_START (CONFIG_SPL_BSS_START_ADDR + \ CONFIG_SPL_BSS_MAX_SIZE) +#else +/* feature not enabled: this value avoids compiler errors but is not used */ +#define SPL_SYS_MALLOC_START 0 #endif +#define SPL_SYS_MALLOC_SIZE \ + IF_ENABLED_INT(CONFIG_SPL_SYS_MALLOC, CONFIG_SPL_SYS_MALLOC_SIZE) #endif -- cgit v1.2.3 From 6371c47999ea78d00cf98028ced210bea8337711 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Tue, 26 Sep 2023 08:14:20 -0600 Subject: spl: Drop #ifdefs for BOARD_INIT and watchdog Avoid using the preprocessor for these checks. Signed-off-by: Simon Glass --- include/spl.h | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/spl.h b/include/spl.h index 0fedddd00ef..ab06e32ebd9 100644 --- a/include/spl.h +++ b/include/spl.h @@ -707,9 +707,13 @@ int spl_early_init(void); */ int spl_init(void); -#ifdef CONFIG_SPL_BOARD_INIT +/* + * spl_board_init() - Do board-specific init in SPL + * + * If xPL_BOARD_INIT is enabled, this is called from board_init_r() before + * jumping to the next phase. + */ void spl_board_init(void); -#endif /** * spl_was_boot_source() - check if U-Boot booted from SPL -- cgit v1.2.3 From e0be6eaf581d06af788509e588129c4dbae967d2 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Tue, 26 Sep 2023 08:14:21 -0600 Subject: spl: Avoid #ifdef with CONFIG_SPL_PAYLOAD_ARGS_ADDR Move the condition to the header file to improve readability. Signed-off-by: Simon Glass --- include/system-constants.h | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'include') diff --git a/include/system-constants.h b/include/system-constants.h index dca6a86b01f..59371568d1e 100644 --- a/include/system-constants.h +++ b/include/system-constants.h @@ -34,4 +34,11 @@ #define SPL_SYS_MALLOC_SIZE \ IF_ENABLED_INT(CONFIG_SPL_SYS_MALLOC, CONFIG_SPL_SYS_MALLOC_SIZE) +/* deal with an optional value */ +#ifdef CONFIG_SPL_OS_BOOT +#define SPL_PAYLOAD_ARGS_ADDR CONFIG_SPL_PAYLOAD_ARGS_ADDR +#else +#define SPL_PAYLOAD_ARGS_ADDR 0 +#endif + #endif -- cgit v1.2.3 From f817e08ff290c51f6471345d7bc11507cde8ffbc Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Tue, 26 Sep 2023 08:14:22 -0600 Subject: spl: Drop the switch() statement for OS selection This code is pretty ugly, with many #ifdefs There are quite a lot of IH_OS_U_BOOT values so the compiler struggles to create a jump table here. Also, most of the options are normally disabled. Change it to an else...if construct instead. Add an accessor for the spl_image field behind an #ifdef to avoid needing #ifdef in the C code. Signed-off-by: Simon Glass --- include/spl.h | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'include') diff --git a/include/spl.h b/include/spl.h index ab06e32ebd9..6c6ca07dbcc 100644 --- a/include/spl.h +++ b/include/spl.h @@ -263,6 +263,15 @@ struct spl_image_info { #endif }; +static inline void *spl_image_fdt_addr(struct spl_image_info *info) +{ +#if CONFIG_IS_ENABLED(LOAD_FIT) || CONFIG_IS_ENABLED(LOAD_FIT_FULL) + return info->fdt_addr; +#else + return 0; +#endif +} + /** * Information required to load data from a device * -- cgit v1.2.3 From 3d6d50751469fbadec3e34fbb6d06f21746619dd Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Tue, 26 Sep 2023 08:14:27 -0600 Subject: spl: Use SYS_MALLOC_F instead of SYS_MALLOC_F_LEN Use the new SPL/TPL/VPL_SYS_MALLOC_F symbols to determine whether the malloc pool exists. Signed-off-by: Simon Glass Reviewed-by: Sean Anderson --- include/asm-generic/global_data.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include') diff --git a/include/asm-generic/global_data.h b/include/asm-generic/global_data.h index c6d63b3657c..f8fc87f1e46 100644 --- a/include/asm-generic/global_data.h +++ b/include/asm-generic/global_data.h @@ -307,7 +307,7 @@ struct global_data { #if CONFIG_IS_ENABLED(CMD_BDINFO_EXTRA) unsigned long malloc_start; #endif -#if CONFIG_VAL(SYS_MALLOC_F_LEN) +#if CONFIG_IS_ENABLED(SYS_MALLOC_F) /** * @malloc_base: base address of early malloc() */ -- cgit v1.2.3 From 2003a83cc8b3937cda09e712c75f50f579eed3fa Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Tue, 26 Sep 2023 08:14:31 -0600 Subject: spl: Avoid an #ifdef when printing gd->malloc_ptr Use an accessor in the header file to avoid this. Signed-off-by: Simon Glass --- include/asm-generic/global_data.h | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'include') diff --git a/include/asm-generic/global_data.h b/include/asm-generic/global_data.h index f8fc87f1e46..937fb12516c 100644 --- a/include/asm-generic/global_data.h +++ b/include/asm-generic/global_data.h @@ -588,6 +588,12 @@ static_assert(sizeof(struct global_data) == GD_SIZE); #define gd_set_pci_ram_top(val) #endif +#if CONFIG_VAL(SYS_MALLOC_F_LEN) +#define gd_malloc_ptr() gd->malloc_ptr +#else +#define gd_malloc_ptr() 0L +#endif + /** * enum gd_flags - global data flags * -- cgit v1.2.3 From 17ba50106efe04ca5249ce33a8ef8374b584ee8d Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Tue, 26 Sep 2023 08:14:32 -0600 Subject: spl: Remove #ifdefs with BOOTSTAGE This feature has some helpers in its header file so that its functions resolve to nothing when the feature is disabled. Add a few more and use these to simplify the code. With this there are no more #ifdefs in board_init_r() Signed-off-by: Simon Glass --- include/bootstage.h | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'include') diff --git a/include/bootstage.h b/include/bootstage.h index 685939ccffc..f9376c320c9 100644 --- a/include/bootstage.h +++ b/include/bootstage.h @@ -244,6 +244,8 @@ void show_boot_progress(int val); #ifdef ENABLE_BOOTSTAGE +#include + /* This is the full bootstage implementation */ /** @@ -452,6 +454,26 @@ static inline int bootstage_init(bool first) #endif /* ENABLE_BOOTSTAGE */ +/* helpers for SPL */ +int _bootstage_stash_default(void); +int _bootstage_unstash_default(void); + +static inline int bootstage_stash_default(void) +{ + if (CONFIG_IS_ENABLED(BOOTSTAGE) && IS_ENABLED(CONFIG_BOOTSTAGE_STASH)) + return _bootstage_stash_default(); + + return 0; +} + +static inline int bootstage_unstash_default(void) +{ + if (CONFIG_IS_ENABLED(BOOTSTAGE) && IS_ENABLED(CONFIG_BOOTSTAGE_STASH)) + return _bootstage_unstash_default(); + + return 0; +} + /* Helper macro for adding a bootstage to a line of code */ #define BOOTSTAGE_MARKER() \ bootstage_mark_code(__FILE__, __func__, __LINE__) -- cgit v1.2.3 From 035ab46e3930c8142cae881e08923043632faa51 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Tue, 26 Sep 2023 08:14:34 -0600 Subject: spl: Move the full FIT code to spl_fit.c For some reason this code was put in the main spl.c file. Move it out to the FIT implementation where it belongs. Signed-off-by: Simon Glass --- include/spl.h | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'include') diff --git a/include/spl.h b/include/spl.h index 6c6ca07dbcc..59c508280bc 100644 --- a/include/spl.h +++ b/include/spl.h @@ -910,4 +910,15 @@ struct legacy_img_hdr *spl_get_load_buffer(ssize_t offset, size_t size); void board_boot_order(u32 *spl_boot_list); void spl_save_restore_data(void); + +/** + * spl_load_fit_image() - Fully parse and a FIT image in SPL + * + * @spl_image: SPL Image data to fill in + * @header: Pointer to FIT image + * Return 0 if OK, -ve on error + */ +int spl_load_fit_image(struct spl_image_info *spl_image, + const struct legacy_img_hdr *header); + #endif -- cgit v1.2.3 From 247970978d3de3e46537550e83137df586d9dee9 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Tue, 26 Sep 2023 08:14:37 -0600 Subject: dm: core: Reverse the argument order in ofnode_copy_props() Follow the order used by memcpy() as it may be less confusing. Signed-off-by: Simon Glass --- include/dm/ofnode.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'include') diff --git a/include/dm/ofnode.h b/include/dm/ofnode.h index 06c969c61fe..32917f66155 100644 --- a/include/dm/ofnode.h +++ b/include/dm/ofnode.h @@ -1598,7 +1598,7 @@ int ofnode_add_subnode(ofnode parent, const char *name, ofnode *nodep); /** * ofnode_copy_props() - copy all properties from one node to another * - * Makes a copy of all properties from the source note in the destination node. + * Makes a copy of all properties from the source node to the destination node. * Existing properties in the destination node remain unchanged, except that * any with the same name are overwritten, including changing the size of the * property. @@ -1606,9 +1606,9 @@ int ofnode_add_subnode(ofnode parent, const char *name, ofnode *nodep); * For livetree, properties are copied / allocated, so the source tree does not * need to be present afterwards. * + * @dst: Destination node to write properties to * @src: Source node to read properties from - * @dst: Destination node to write properties too */ -int ofnode_copy_props(ofnode src, ofnode dst); +int ofnode_copy_props(ofnode dst, ofnode src); #endif -- cgit v1.2.3 From e0c3c21d8ba1a0abbb7effee6c5a952f3e65a03d Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Tue, 26 Sep 2023 08:14:40 -0600 Subject: dm: core: Add a function to create an empty tree Provide a function to create a new, empty tree. Signed-off-by: Simon Glass --- include/dm/ofnode.h | 9 +++++++++ include/of_live.h | 8 ++++++++ 2 files changed, 17 insertions(+) (limited to 'include') diff --git a/include/dm/ofnode.h b/include/dm/ofnode.h index 32917f66155..0b96ab34ede 100644 --- a/include/dm/ofnode.h +++ b/include/dm/ofnode.h @@ -127,6 +127,15 @@ static inline ofnode noffset_to_ofnode(ofnode other_node, int of_offset) #endif /* OFNODE_MULTI_TREE */ +/** + * oftree_new() - Create a new, empty tree + * + * @treep: Returns a pointer to the tree, on success + * Returns: 0 on success, -ENOMEM if out of memory, -E2BIG if !OF_LIVE and + * there are too many (flattrees) already + */ +int oftree_new(oftree *treep); + /** * ofnode_to_np() - convert an ofnode to a live DT node pointer * diff --git a/include/of_live.h b/include/of_live.h index 05e86ac06b1..81cb9bd13e2 100644 --- a/include/of_live.h +++ b/include/of_live.h @@ -46,4 +46,12 @@ int unflatten_device_tree(const void *blob, struct device_node **mynodes); */ void of_live_free(struct device_node *root); +/** + * of_live_create_empty() - Create a new, empty tree + * + * @rootp: Returns the root node of the created tree + * Return: 0 if OK, -ENOMEM if out of memory + */ +int of_live_create_empty(struct device_node **rootp); + #endif -- cgit v1.2.3 From c15862ffdd5f7797338808cf7645786109bcddc3 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Tue, 26 Sep 2023 08:14:41 -0600 Subject: dm: core: Add a way to copy a node Add a function to copy a node to another place under a new name. This is useful at least for testing, since copying a test node with existing properties is easier than writing the code to generate it all afresh. Signed-off-by: Simon Glass --- include/dm/ofnode.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'include') diff --git a/include/dm/ofnode.h b/include/dm/ofnode.h index 0b96ab34ede..7eb04accd62 100644 --- a/include/dm/ofnode.h +++ b/include/dm/ofnode.h @@ -1620,4 +1620,19 @@ int ofnode_add_subnode(ofnode parent, const char *name, ofnode *nodep); */ int ofnode_copy_props(ofnode dst, ofnode src); +/** + * ofnode_copy_node() - Copy a node to another place + * + * If a node with this name already exists in dst_parent, this returns an + * .error + * + * @dst_parent: Parent of the newly copied node + * @name: Name to give the new node + * @src: Source node to copy + * @nodep: Returns the new node, or the existing node if there is one + * Return: 0 if OK, -EEXIST if dst_parent already has a node with this parent + */ +int ofnode_copy_node(ofnode dst_parent, const char *name, ofnode src, + ofnode *nodep); + #endif -- cgit v1.2.3 From 67fb2159fb3438359fa0fc3f8cb491ffe8d57c0f Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Tue, 26 Sep 2023 08:14:42 -0600 Subject: dm: core: Add a way to delete a node Add a function to delete a node in an existing tree. Signed-off-by: Simon Glass --- include/dm/of_access.h | 18 ++++++++++++++++++ include/dm/ofnode.h | 13 +++++++++++++ 2 files changed, 31 insertions(+) (limited to 'include') diff --git a/include/dm/of_access.h b/include/dm/of_access.h index 9361d0a87bf..de740d44674 100644 --- a/include/dm/of_access.h +++ b/include/dm/of_access.h @@ -597,4 +597,22 @@ int of_write_prop(struct device_node *np, const char *propname, int len, int of_add_subnode(struct device_node *node, const char *name, int len, struct device_node **subnodep); +/** + * of_remove_property() - Remove a property from a node + * + * @np: Node to remove from + * @prop: Pointer to property to remove + * Return 0 if OK, -ENODEV if the property could not be found in the node + */ +int of_remove_property(struct device_node *np, struct property *prop); + +/** + * of_remove_node() - Remove a node from the tree + * + * @to_remove: Node to remove + * Return: 0 if OK, -EPERM if it is the root node (wWhich cannot be removed), + * -ENOENT if the tree is broken (to_remove is not a child of its parent) + */ +int of_remove_node(struct device_node *to_remove); + #endif diff --git a/include/dm/ofnode.h b/include/dm/ofnode.h index 7eb04accd62..f1ee02cd837 100644 --- a/include/dm/ofnode.h +++ b/include/dm/ofnode.h @@ -1635,4 +1635,17 @@ int ofnode_copy_props(ofnode dst, ofnode src); int ofnode_copy_node(ofnode dst_parent, const char *name, ofnode src, ofnode *nodep); +/** + * ofnode_delete() - Delete a node + * + * Delete a node from the tree + * + * @nodep: Pointer to node to delete (set to ofnode_null() on success) + * Return: 0 if OK, -ENOENT if the node does not exist, -EPERM if it is the root + * node (wWhich cannot be removed), -EFAULT if the tree is broken (to_remove is + * not a child of its parent), + * + */ +int ofnode_delete(ofnode *nodep); + #endif -- cgit v1.2.3 From 62b1db33778611a3023d1e3a98e869b495edc9ca Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Tue, 26 Sep 2023 08:14:43 -0600 Subject: dm: core: Add a way to convert a devicetree to a dtb Add a way to flatten a devicetree into binary form. For livetree this involves generating the devicetree using fdt_property() and other calls. For flattree it simply involves providing the buffer containing the tree. Signed-off-by: Simon Glass --- include/dm/ofnode.h | 13 +++++++++++++ include/of_live.h | 10 ++++++++++ 2 files changed, 23 insertions(+) (limited to 'include') diff --git a/include/dm/ofnode.h b/include/dm/ofnode.h index f1ee02cd837..a8605fb718b 100644 --- a/include/dm/ofnode.h +++ b/include/dm/ofnode.h @@ -17,6 +17,7 @@ /* Enable checks to protect against invalid calls */ #undef OF_CHECKS +struct abuf; struct resource; #include @@ -136,6 +137,18 @@ static inline ofnode noffset_to_ofnode(ofnode other_node, int of_offset) */ int oftree_new(oftree *treep); +/** + * oftree_to_fdt() - Convert an oftree to a flat FDT + * + * @tree: tree to flatten (if livetree) or copy (if not) + * @buf: Returns inited buffer containing the newly created flat tree. Note + * that for flat tree the buffer is not allocated. In either case the caller + * must call abut_uninit() to free any memory used by @buf + * Return: 0 on success, -ENOMEM if out of memory, other -ve value for any other + * error + */ +int oftree_to_fdt(oftree tree, struct abuf *buf); + /** * ofnode_to_np() - convert an ofnode to a live DT node pointer * diff --git a/include/of_live.h b/include/of_live.h index 81cb9bd13e2..67bd5f02c74 100644 --- a/include/of_live.h +++ b/include/of_live.h @@ -9,6 +9,7 @@ #ifndef _OF_LIVE_H #define _OF_LIVE_H +struct abuf; struct device_node; /** @@ -54,4 +55,13 @@ void of_live_free(struct device_node *root); */ int of_live_create_empty(struct device_node **rootp); +/** + * of_live_flatten() - Create an FDT from a hierarchical tree + * + * @root: Root node of tree to convert + * @buf: Buffer to return the tree (inited by this function) + * Return: 0 if OK, -ENOMEM if out of memory + */ +int of_live_flatten(const struct device_node *root, struct abuf *buf); + #endif -- cgit v1.2.3 From d9216c8683fced4cbf6d437b4357c9368bf1bf86 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Tue, 26 Sep 2023 08:14:44 -0600 Subject: dm: core: Support writing a boolean Add functions to write a boolean property. This involves deleting it if the value is false. Add a new ofnode_has_property() as well. Add a comment about the behaviour of of_read_property() when the property value is empty. Signed-off-by: Simon Glass --- include/dm/ofnode.h | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) (limited to 'include') diff --git a/include/dm/ofnode.h b/include/dm/ofnode.h index a8605fb718b..ebea29d32af 100644 --- a/include/dm/ofnode.h +++ b/include/dm/ofnode.h @@ -1037,10 +1037,19 @@ int ofnode_decode_panel_timing(ofnode node, * @node: node to read * @propname: property to read * @lenp: place to put length on success - * Return: pointer to property, or NULL if not found + * Return: pointer to property value, or NULL if not found or empty */ const void *ofnode_get_property(ofnode node, const char *propname, int *lenp); +/** + * ofnode_has_property() - check if a node has a named property + * + * @node: node to read + * @propname: property to read + * Return: true if the property exists in the node, false if not + */ +bool ofnode_has_property(ofnode node, const char *propname); + /** * ofnode_first_property()- get the reference of the first property * @@ -1452,6 +1461,27 @@ int ofnode_write_string(ofnode node, const char *propname, const char *value); */ int ofnode_write_u32(ofnode node, const char *propname, u32 value); +/** + * ofnode_write_bool() - Set a boolean property of an ofnode + * + * This either adds or deleted a property with a zero-length value + * + * @node: The node for whose string property should be set + * @propname: The name of the string property to set + * @value: The new value of the boolean property + * Return: 0 if successful, -ve on error + */ +int ofnode_write_bool(ofnode node, const char *propname, bool value); + +/** + * ofnode_delete_prop() - Delete a property + * + * @node: Node containing the property to delete + * @propname: Name of property to delete + * Return: 0 if successful, -ve on error + */ +int ofnode_delete_prop(ofnode node, const char *propname); + /** * ofnode_set_enabled() - Enable or disable a device tree node given by its * ofnode -- cgit v1.2.3 From 7071c82bdc55ed5d7955d8e1682b7c80af5659b5 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Tue, 26 Sep 2023 08:14:45 -0600 Subject: dm: core: Support writing a 64-bit value Add support for writing a single 64-bit value into a property. Repurpose the existing tests to handle this case too. Signed-off-by: Simon Glass --- include/dm/ofnode.h | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'include') diff --git a/include/dm/ofnode.h b/include/dm/ofnode.h index ebea29d32af..ef1437cc556 100644 --- a/include/dm/ofnode.h +++ b/include/dm/ofnode.h @@ -1461,6 +1461,16 @@ int ofnode_write_string(ofnode node, const char *propname, const char *value); */ int ofnode_write_u32(ofnode node, const char *propname, u32 value); +/** + * ofnode_write_u64() - Set an integer property of an ofnode + * + * @node: The node for whose string property should be set + * @propname: The name of the string property to set + * @value: The new value of the 64-bit integer property + * Return: 0 if successful, -ve on error + */ +int ofnode_write_u64(ofnode node, const char *propname, u64 value); + /** * ofnode_write_bool() - Set a boolean property of an ofnode * -- cgit v1.2.3 From 3d6531803e1cdc4c6976dae3c92220daba57f148 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Tue, 26 Sep 2023 08:14:51 -0600 Subject: bloblist: Support initing from multiple places Typically the bloblist is set up after the devicetree is present. This makes sense because bloblist may use malloc() to allocate the space it needs. However sometimes the devicetree itself may be present in the bloblist. In that case it is at a known location in memory so we can init the bloblist very early, before devicetree. Add a flag to indicate whether the bloblist has been inited. Add a function to init it only if needed. Use that in the init sequence. Signed-off-by: Simon Glass --- include/asm-generic/global_data.h | 4 ++++ include/bloblist.h | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+) (limited to 'include') diff --git a/include/asm-generic/global_data.h b/include/asm-generic/global_data.h index 937fb12516c..e8c6412e3f8 100644 --- a/include/asm-generic/global_data.h +++ b/include/asm-generic/global_data.h @@ -693,6 +693,10 @@ enum gd_flags { * the memory used to holds its tables has been mapped out. */ GD_FLG_DM_DEAD = 0x400000, + /** + * @GD_FLG_BLOBLIST_READY: bloblist is ready for use + */ + GD_FLG_BLOBLIST_READY = 0x800000, }; #endif /* __ASSEMBLY__ */ diff --git a/include/bloblist.h b/include/bloblist.h index 7ea72c6bd46..080cc46a126 100644 --- a/include/bloblist.h +++ b/include/bloblist.h @@ -413,8 +413,26 @@ void bloblist_reloc(void *to, uint to_size, void *from, uint from_size); * standard passage. The size is detected automatically so CONFIG_BLOBLIST_SIZE * can be 0. * + * Sets GD_FLG_BLOBLIST_READY in global_data flags on success + * * Return: 0 if OK, -ve on error */ int bloblist_init(void); +#if CONFIG_IS_ENABLED(BLOBLIST) +/** + * bloblist_maybe_init() - Init the bloblist system if not already done + * + * Calls bloblist_init() if the GD_FLG_BLOBLIST_READY flag is not et + * + * Return: 0 if OK, -ve on error + */ +int bloblist_maybe_init(void); +#else +static inline int bloblist_maybe_init(void) +{ + return 0; +} +#endif /* BLOBLIST */ + #endif /* __BLOBLIST_H */ -- cgit v1.2.3 From be5951461c23111b343348401defd1d05227a75e Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Wed, 27 Sep 2023 08:22:37 -0600 Subject: command: Include a required header in command.h This uses ARRAY_SIZE() but does not include the header file which declares it. Fix this, so that command.h can be included without common.h Signed-off-by: Simon Glass Reviewed-by: Mattijs Korpershoek --- include/command.h | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'include') diff --git a/include/command.h b/include/command.h index ae7bb4a30b0..34ea989b39b 100644 --- a/include/command.h +++ b/include/command.h @@ -25,6 +25,10 @@ #endif #ifndef __ASSEMBLY__ + +/* For ARRAY_SIZE() */ +#include + /* * Monitor Command Table */ -- cgit v1.2.3 From 9031ba824209166444d5abea2064c23015883705 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Tue, 26 Sep 2023 08:14:55 -0600 Subject: spl: Add C-based runtime detection of SPL The spl_phase() function indicates whether U-Boot is in SPL and before or after relocation. But sometimes it is useful to check for SPL with zero code-size impact. Since spl_phase() checks the global_data flags, it does add a few bytes. Add a new spl_in_proper() function to check if U-Boot proper is running, regardless of the relocation status. Signed-off-by: Simon Glass --- include/spl.h | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'include') diff --git a/include/spl.h b/include/spl.h index 59c508280bc..a222db9c559 100644 --- a/include/spl.h +++ b/include/spl.h @@ -132,6 +132,16 @@ static inline enum u_boot_phase spl_phase(void) #endif } +/* returns true if in U-Boot proper, false if in SPL */ +static inline bool spl_in_proper(void) +{ +#ifdef CONFIG_SPL_BUILD + return false; +#endif + + return true; +} + /** * spl_prev_phase() - Figure out the previous U-Boot phase * -- cgit v1.2.3 From 61fc132051740e0378a5e71f3db6cb1581e970fe Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Tue, 26 Sep 2023 08:14:57 -0600 Subject: dm: core: Tweak device_is_on_pci_bus() for code size This function cannot return true if PCI is not enabled, since no PCI devices will have been bound. Add a check for this to reduce code size where it is used. Signed-off-by: Simon Glass --- include/dm/device.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'include') diff --git a/include/dm/device.h b/include/dm/device.h index e54cb6bca41..add67f9ec06 100644 --- a/include/dm/device.h +++ b/include/dm/device.h @@ -1005,7 +1005,8 @@ int dev_enable_by_path(const char *path); */ static inline bool device_is_on_pci_bus(const struct udevice *dev) { - return dev->parent && device_get_uclass_id(dev->parent) == UCLASS_PCI; + return CONFIG_IS_ENABLED(PCI) && dev->parent && + device_get_uclass_id(dev->parent) == UCLASS_PCI; } /** -- cgit v1.2.3 From f69d3d6d10b15872a279aeb10b7c522627aff6c2 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Tue, 26 Sep 2023 08:14:58 -0600 Subject: pci: serial: Support reading PCI-register size with base The PCI helpers read only the base address for a PCI region. In some cases the size is needed as well, e.g. to pass along to a driver which needs to know the size of its register area. Update the functions to allow the size to be returned. For serial, record the information and provided it with the serial_info() call. A limitation still exists in that the size is not available when OF_LIVE is enabled, so take account of that in the tests. Signed-off-by: Simon Glass --- include/dm/fdtaddr.h | 3 ++- include/dm/ofnode.h | 4 +++- include/dm/read.h | 8 +++++--- include/ns16550.h | 4 +++- include/serial.h | 2 ++ 5 files changed, 15 insertions(+), 6 deletions(-) (limited to 'include') diff --git a/include/dm/fdtaddr.h b/include/dm/fdtaddr.h index dcdc19137cc..6d2fa8f1044 100644 --- a/include/dm/fdtaddr.h +++ b/include/dm/fdtaddr.h @@ -168,8 +168,9 @@ fdt_addr_t devfdt_get_addr_size_name(const struct udevice *dev, * devfdt_get_addr_pci() - Read an address and handle PCI address translation * * @dev: Device to read from + * @sizep: If non-NULL, returns size of address space * Return: address or FDT_ADDR_T_NONE if not found */ -fdt_addr_t devfdt_get_addr_pci(const struct udevice *dev); +fdt_addr_t devfdt_get_addr_pci(const struct udevice *dev, fdt_size_t *sizep); #endif diff --git a/include/dm/ofnode.h b/include/dm/ofnode.h index ef1437cc556..19e97a90327 100644 --- a/include/dm/ofnode.h +++ b/include/dm/ofnode.h @@ -1153,13 +1153,15 @@ const uint8_t *ofnode_read_u8_array_ptr(ofnode node, const char *propname, * @type: pci address type (FDT_PCI_SPACE_xxx) * @propname: name of property to find * @addr: returns pci address in the form of fdt_pci_addr + * @size: if non-null, returns register-space size * Return: * 0 if ok, -ENOENT if the property did not exist, -EINVAL if the * format of the property was invalid, -ENXIO if the requested * address type was not found */ int ofnode_read_pci_addr(ofnode node, enum fdt_pci_space type, - const char *propname, struct fdt_pci_addr *addr); + const char *propname, struct fdt_pci_addr *addr, + fdt_size_t *size); /** * ofnode_read_pci_vendev() - look up PCI vendor and device id diff --git a/include/dm/read.h b/include/dm/read.h index c2615f72f40..3c2eea6f0c4 100644 --- a/include/dm/read.h +++ b/include/dm/read.h @@ -346,9 +346,10 @@ void *dev_read_addr_ptr(const struct udevice *dev); * fdtdec_get_addr() and friends. * * @dev: Device to read from + * @sizep: If non-NULL, returns size of address space found * Return: address or FDT_ADDR_T_NONE if not found */ -fdt_addr_t dev_read_addr_pci(const struct udevice *dev); +fdt_addr_t dev_read_addr_pci(const struct udevice *dev, fdt_size_t *sizep); /** * dev_remap_addr() - Get the reg property of a device as a @@ -996,9 +997,10 @@ static inline void *dev_read_addr_ptr(const struct udevice *dev) return devfdt_get_addr_ptr(dev); } -static inline fdt_addr_t dev_read_addr_pci(const struct udevice *dev) +static inline fdt_addr_t dev_read_addr_pci(const struct udevice *dev, + fdt_size_t *sizep) { - return devfdt_get_addr_pci(dev); + return devfdt_get_addr_pci(dev, sizep); } static inline void *dev_remap_addr(const struct udevice *dev) diff --git a/include/ns16550.h b/include/ns16550.h index e7e68663d03..7f481300083 100644 --- a/include/ns16550.h +++ b/include/ns16550.h @@ -58,6 +58,7 @@ enum ns16550_flags { * struct ns16550_plat - information about a NS16550 port * * @base: Base register address + * @size: Size of register area in bytes * @reg_width: IO accesses size of registers (in bytes, 1 or 4) * @reg_shift: Shift size of registers (0=byte, 1=16bit, 2=32bit...) * @reg_offset: Offset to start of registers (normally 0) @@ -67,7 +68,8 @@ enum ns16550_flags { * @bdf: PCI slot/function (pci_dev_t) */ struct ns16550_plat { - unsigned long base; + ulong base; + ulong size; int reg_width; int reg_shift; int reg_offset; diff --git a/include/serial.h b/include/serial.h index 42bdf3759c0..205889d28be 100644 --- a/include/serial.h +++ b/include/serial.h @@ -137,6 +137,7 @@ enum adr_space_type { * @type: type of the UART chip * @addr_space: address space to access the registers * @addr: physical address of the registers + * @size: size of the register area in bytes * @reg_width: size (in bytes) of the IO accesses to the registers * @reg_offset: offset to apply to the @addr from the start of the registers * @reg_shift: quantity to shift the register offsets by @@ -147,6 +148,7 @@ struct serial_device_info { enum serial_chip_type type; enum adr_space_type addr_space; ulong addr; + ulong size; u8 reg_width; u8 reg_offset; u8 reg_shift; -- cgit v1.2.3