Skip to contentSkip to conversation

sandbox: only access of_add_memory_bank if it's defined

PATCH Applied Holger Schurig 3 participants 8 messages Jun 26, 2014 – Jun 27, 2014 Device tree

lore
Share & tools
lore
#0 lore raw

PATCH 2/4 sandbox: only access of_add_memory_bank if it's defined

... and it's defined only when CONFIG_OFTREE_MEM_GENERIC is on.

---
 drivers/of/base.c |    6 ++++++
 1 file changed, 6 insertions(+)
drivers/of/base.c +6 -0
index c440a69..818d76e 100644
@@ -1697,6 +1697,7 @@ int of_set_property(struct device_node *np, const char *name, const void *val, i
 	return 0;
 }
 
+#ifdef CONFIG_OFTREE_MEM_GENERIC
 int of_add_memory(struct device_node *node, bool dump)
 {
 	const char *device_type;
@@ -1720,6 +1721,7 @@ int of_add_memory(struct device_node *node, bool dump)
 
 	return 0;
 }
+#endif
 
 static struct device_node *of_chosen;
 static const char *of_model;
@@ -1739,7 +1741,9 @@ const struct of_device_id of_default_bus_match_table[] = {
 
 int of_probe(void)
 {
+#ifdef CONFIG_OFTREE_MEM_GENERIC
 	struct device_node *memory;
+#endif
 
 	if(!root_node)
 		return -ENODEV;
@@ -1750,9 +1754,11 @@ int of_probe(void)
 	if (of_model)
 		barebox_set_model(of_model);
 
+#ifdef CONFIG_OFTREE_MEM_GENERIC
 	memory = of_find_node_by_path("/memory");
 	if (memory)
 		of_add_memory(memory, false);
+#endif
 
 	of_platform_populate(root_node, of_default_bus_match_table, NULL);
 	of_clk_init(root_node, NULL);
Signature · 7 lines
1.7.10.4


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#1 lore raw

Hi Holger,

can you please check if this is also a solution for this?

include/of.h +7 -0
index e6993fd..76845e7 100644
@@ -227,7 +227,14 @@ int of_parse_partitions(struct cdev *cdev, struct device_node *node);
 int of_device_is_stdout_path(struct device_d *dev);
 const char *of_get_model(void);
 void *of_flatten_dtb(struct device_node *node);
+#ifdef CONFIG_OFTREE_MEM_GENERIC
 int of_add_memory(struct device_node *node, bool dump);
+#else
+static inline int of_add_memory(struct device_node *node, bool dump)
+{
+       return -EINVAL;
+}
+#endif
 void of_add_memory_bank(struct device_node *node, bool dump, int r,
                u64 base, u64 size);
 struct device_d *of_find_device_by_node_path(const char *path);

If this works for you then this is missing. Maybe there are some other related function which depends on CONFIG_OFTREE_MEM_GENERIC, I didn't check it.

I think this would be a better solution, if it works...

- Alex

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox

#2 lore raw
Quoted 9 lines · Alexander Aring

Hi Holger,

can you please check if this is also a solution for this?

include/of.h +0 -0
index e6993fd..76845e7 100644

include/of.h int of_parse_partitions(struct cdev *cdev, struct device_node *node); · line 235

Quoted 9 lines
include/of.h +5 -0
@@ -227,7 +227,14 @@ int of_parse_partitions(struct cdev *cdev, struct device_node *node);
 int of_device_is_stdout_path(struct device_d *dev);
 const char *of_get_model(void);
 void *of_flatten_dtb(struct device_node *node);
+#ifdef CONFIG_OFTREE_MEM_GENERIC
 int of_add_memory(struct device_node *node, bool dump);
+#else
+static inline int of_add_memory(struct device_node *node, bool dump)
+{
+       return -EINVAL;

mhh, the errno of these function if it's not defined should be changed to -EOPNOTSUPP.

- Alex

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox

#4 lore raw
Quoted 5 lines · Holger Schurig

Your patch alone isn't all that's needed, the definition must still be uncommented. Otherwise we'll get:

drivers/of/base.c:1700:5: error: redefinition of 'of_add_memory' include/of.h:233:50: note: previous definition of 'of_add_memory' was here

Yep you are right. Sorry :-)

Another solution would be to move the implementation for mem_generic in a seperate file which depends on CONFIG_OFTREE_MEM_GENERIC. This would work, but I don't know if we really need that to solve that, I think not.

- Alex

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox

#5 lore raw
In reply to Alexander Aring
Quoted 16 lines · Alexander Aring

Hi Holger,

can you please check if this is also a solution for this?

include/of.h +1 -0
index e6993fd..76845e7 100644
@@ -227,7 +227,14 @@ int of_parse_partitions(struct cdev *cdev, struct device_node *node);
 int of_device_is_stdout_path(struct device_d *dev);
 const char *of_get_model(void);
 void *of_flatten_dtb(struct device_node *node);
+#ifdef CONFIG_OFTREE_MEM_GENERIC

include/of.h int of_parse_partitions(struct cdev *cdev, struct device_node *node); · line 240

Quoted 10 lines
include/of.h +6 -0
 int of_add_memory(struct device_node *node, bool dump);
+#else
+static inline int of_add_memory(struct device_node *node, bool dump)
+{
+       return -EINVAL;
+}
+#endif
 void of_add_memory_bank(struct device_node *node, bool dump, int r,
                u64 base, u64 size);
 struct device_d *of_find_device_by_node_path(const char *path);

Okay the implementation "#ifdef CONFIG_OFTREE_MEM_GENERIC" for function of_add_memory, need to be there.

Other option would be to put this function in a separete file which depends on CONFIG_OFTREE_MEM_GENERIC and do in the header file the above solution one. Don't know if this is better. Then you could drop the #ifdef CONFIG_OFTREE_MEM_GENERIC from the implementation.

- Alex

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox

#6 lore raw
In reply to Holger Schurig
Quoted 20 lines · Holger Schurig

... and it's defined only when CONFIG_OFTREE_MEM_GENERIC is on.

---
 drivers/of/base.c |    6 ++++++
 1 file changed, 6 insertions(+)
drivers/of/base.c +1 -0
index c440a69..818d76e 100644
@@ -1697,6 +1697,7 @@ int of_set_property(struct device_node *np, const char *name, const void *val, i
 	return 0;
 }
 
+#ifdef CONFIG_OFTREE_MEM_GENERIC
 int of_add_memory(struct device_node *node, bool dump)
 {
 	const char *device_type;

drivers/of/base.c int of_add_memory(struct device_node *node, bool dump) · line 1724

Quoted 4 lines
drivers/of/base.c +1 -0
@@ -1720,6 +1721,7 @@ int of_add_memory(struct device_node *node, bool dump)
 
 	return 0;
 }
+#endif

This will break MIPS support. MIPS has it's own implementation of of_add_memory_bank (see ./arch/mips/boot/dtb.c), so in MIPS case the Kconfig options means "I have my own version of of_add_memory_bank"

I currently don't know a good way out of this situation.

Sascha

Signature · 9 lines
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#7 lore raw
Quoted 22 lines · Sascha Hauer
Quoted 21 lines · Holger Schurig

... and it's defined only when CONFIG_OFTREE_MEM_GENERIC is on.

---
 drivers/of/base.c |    6 ++++++
 1 file changed, 6 insertions(+)
drivers/of/base.c +1 -0
index c440a69..818d76e 100644
@@ -1697,6 +1697,7 @@ int of_set_property(struct device_node *np, const char *name, const void *val, i
 	return 0;
 }
 
+#ifdef CONFIG_OFTREE_MEM_GENERIC
 int of_add_memory(struct device_node *node, bool dump)
 {
 	const char *device_type;
@@ -1720,6 +1721,7 @@ int of_add_memory(struct device_node *node, bool dump)
 
Quoted 8 lines

drivers/of/base.c int of_add_memory(struct device_node *node, bool dump) · line 1724

Quoted 3 lines
drivers/of/base.c +1 -0
 	return 0;
 }
+#endif

This will break MIPS support. MIPS has it's own implementation of of_add_memory_bank (see ./arch/mips/boot/dtb.c), so in MIPS case the Kconfig options means "I have my own version of of_add_memory_bank"

Then maybe, move this implementation to "drivers/of/mem_generic.c". This function doesn't use any static function of this file (What I see, currently).

Then make a own header with dummy implementation:

#ifdef CONFIG_OFTREE_MEM_GENERIC
int of_add_memory(struct device_node *node, bool dump) {
...
}
#else
int of_add_memory(struct device_node *node, bool dump)

{
	return -EOPNOTSUPP;
}

#endif

The file drivers/of/mem_generic.c depends on PPC || ARM, so let the buildsystem do the rest.

- Alex

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox