* [PATCH 1/5] memory: return error in barebox_add_memory_bank
2012-10-08 19:46 [PATCH] of patches Sascha Hauer
@ 2012-10-08 19:46 ` Sascha Hauer
2012-10-08 19:46 ` [PATCH 2/5] of: find and register memory during probe Sascha Hauer
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Sascha Hauer @ 2012-10-08 19:46 UTC (permalink / raw)
To: barebox
When a memory bank is already registered, return an error code
instead of throwing a bug. This can happen if a board has registered
a memory bank and the same bank is then probed from the devicetree.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
common/memory.c | 8 +++++---
include/memory.h | 2 +-
2 files changed, 6 insertions(+), 4 deletions(-)
diff --git a/common/memory.c b/common/memory.c
index 7174f14..2674002 100644
--- a/common/memory.c
+++ b/common/memory.c
@@ -113,15 +113,15 @@ void *sbrk(ptrdiff_t increment)
LIST_HEAD(memory_banks);
-void barebox_add_memory_bank(const char *name, resource_size_t start,
+int barebox_add_memory_bank(const char *name, resource_size_t start,
resource_size_t size)
{
struct memory_bank *bank = xzalloc(sizeof(*bank));
struct device_d *dev;
bank->res = request_iomem_region(name, start, start + size - 1);
-
- BUG_ON(!bank->res);
+ if (!bank->res)
+ return -EBUSY;
dev = add_mem_device(name, start, size, IORESOURCE_MEM_WRITEABLE);
@@ -130,6 +130,8 @@ void barebox_add_memory_bank(const char *name, resource_size_t start,
bank->size = size;
list_add_tail(&bank->list, &memory_banks);
+
+ return 0;
}
/*
diff --git a/include/memory.h b/include/memory.h
index 4be4340..165d2dc 100644
--- a/include/memory.h
+++ b/include/memory.h
@@ -18,7 +18,7 @@ struct memory_bank {
extern struct list_head memory_banks;
-void barebox_add_memory_bank(const char *name, resource_size_t start,
+int barebox_add_memory_bank(const char *name, resource_size_t start,
resource_size_t size);
#define for_each_memory_bank(mem) list_for_each_entry(mem, &memory_banks, list)
--
1.7.10.4
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 2/5] of: find and register memory during probe
2012-10-08 19:46 [PATCH] of patches Sascha Hauer
2012-10-08 19:46 ` [PATCH 1/5] memory: return error in barebox_add_memory_bank Sascha Hauer
@ 2012-10-08 19:46 ` Sascha Hauer
2012-10-08 19:46 ` [PATCH 3/5] console/of: evaluate linux,stdout-path property Sascha Hauer
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Sascha Hauer @ 2012-10-08 19:46 UTC (permalink / raw)
To: barebox
This automatically registers the memory nodes in the devicetree.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
drivers/of/base.c | 49 ++++++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 48 insertions(+), 1 deletion(-)
diff --git a/drivers/of/base.c b/drivers/of/base.c
index fd152d6..09785fb 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -23,6 +23,7 @@
#include <libfdt.h>
#include <malloc.h>
#include <init.h>
+#include <memory.h>
#include <linux/ctype.h>
/**
@@ -612,9 +613,51 @@ static struct device_d *add_of_device(struct device_node *node)
}
EXPORT_SYMBOL(add_of_device);
+u64 dt_mem_next_cell(int s, const __be32 **cellp)
+{
+ const __be32 *p = *cellp;
+
+ *cellp = p + s;
+ return of_read_number(p, s);
+}
+
+static int of_add_memory(struct device_node *node)
+{
+ int na, nc;
+ const __be32 *reg, *endp;
+ int len, r = 0;
+ static char str[6];
+
+ of_bus_count_cells(node, &na, &nc);
+
+ reg = of_get_property(node, "reg", &len);
+ if (!reg)
+ return 0;
+
+ endp = reg + (len / sizeof(__be32));
+
+ while ((endp - reg) >= (na + nc)) {
+ u64 base, size;
+
+ base = dt_mem_next_cell(na, ®);
+ size = dt_mem_next_cell(nc, ®);
+
+ if (size == 0)
+ continue;
+
+ sprintf(str, "ram%d", r);
+
+ barebox_add_memory_bank(str, base, size);
+
+ r++;
+ }
+
+ return 0;
+}
+
static int add_of_device_resource(struct device_node *node)
{
- struct property *reg;
+ struct property *reg, *type;
u64 address, size;
struct resource *res;
struct device_d *dev;
@@ -627,6 +670,10 @@ static int add_of_device_resource(struct device_node *node)
list_add_tail(&node->phandles, &phandle_list);
}
+ type = of_find_property(node, "device_type");
+ if (type)
+ return of_add_memory(node);
+
reg = of_find_property(node, "reg");
if (!reg)
return -ENODEV;
--
1.7.10.4
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 3/5] console/of: evaluate linux,stdout-path property
2012-10-08 19:46 [PATCH] of patches Sascha Hauer
2012-10-08 19:46 ` [PATCH 1/5] memory: return error in barebox_add_memory_bank Sascha Hauer
2012-10-08 19:46 ` [PATCH 2/5] of: find and register memory during probe Sascha Hauer
@ 2012-10-08 19:46 ` Sascha Hauer
2012-10-08 19:46 ` [PATCH 4/5] of: Add function to get the model name Sascha Hauer
2012-10-08 19:46 ` [PATCH 5/5] of: Print model name in banner Sascha Hauer
4 siblings, 0 replies; 6+ messages in thread
From: Sascha Hauer @ 2012-10-08 19:46 UTC (permalink / raw)
To: barebox
When a linux,stdout-path property is given in the devicetree
activate the corresponding console.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
common/console.c | 3 +++
drivers/of/base.c | 23 +++++++++++++++++++++++
include/of.h | 6 ++++++
3 files changed, 32 insertions(+)
diff --git a/common/console.c b/common/console.c
index 3dd964c..2766981 100644
--- a/common/console.c
+++ b/common/console.c
@@ -161,6 +161,9 @@ int console_register(struct console_device *newcdev)
}
#endif
+ if (newcdev->dev && of_device_is_stdout_path(newcdev->dev))
+ activate = 1;
+
list_add_tail(&newcdev->list, &console_list);
while (kfifo_getc(console_output_fifo, &ch) == 0)
diff --git a/drivers/of/base.c b/drivers/of/base.c
index 09785fb..3d26343 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -758,11 +758,15 @@ static void __of_probe(struct device_node *node)
__of_probe(n);
}
+struct device_node *of_chosen;
+
int of_probe(void)
{
if(!root_node)
return -ENODEV;
+ of_chosen = of_find_node_by_path("/chosen");
+
__of_probe(root_node);
return 0;
@@ -847,3 +851,22 @@ int of_parse_dtb(struct fdt_header *fdt)
return 0;
}
+
+int of_device_is_stdout_path(struct device_d *dev)
+{
+ struct device_node *dn;
+ const char *name;
+
+ name = of_get_property(of_chosen, "linux,stdout-path", NULL);
+ if (name == NULL)
+ return 0;
+ dn = of_find_node_by_path(name);
+
+ if (!dn)
+ return 0;
+
+ if (dn == dev->device_node)
+ return 1;
+
+ return 0;
+}
diff --git a/include/of.h b/include/of.h
index 7b6a23a..e6342b6 100644
--- a/include/of.h
+++ b/include/of.h
@@ -114,6 +114,7 @@ int of_parse_partitions(const char *cdevname,
struct device_node *of_get_root_node(void);
int of_alias_get_id(struct device_node *np, const char *stem);
+int of_device_is_stdout_path(struct device_d *dev);
#else
static inline int of_parse_partitions(const char *cdevname,
struct device_node *node)
@@ -130,6 +131,11 @@ static inline int of_alias_get_id(struct device_node *np, const char *stem)
{
return -ENOENT;
}
+
+static inline int of_device_is_stdout_path(struct device_d *dev)
+{
+ return 0;
+}
#endif
#endif /* __OF_H */
--
1.7.10.4
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 4/5] of: Add function to get the model name
2012-10-08 19:46 [PATCH] of patches Sascha Hauer
` (2 preceding siblings ...)
2012-10-08 19:46 ` [PATCH 3/5] console/of: evaluate linux,stdout-path property Sascha Hauer
@ 2012-10-08 19:46 ` Sascha Hauer
2012-10-08 19:46 ` [PATCH 5/5] of: Print model name in banner Sascha Hauer
4 siblings, 0 replies; 6+ messages in thread
From: Sascha Hauer @ 2012-10-08 19:46 UTC (permalink / raw)
To: barebox
This is useful for printing it during startup.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
drivers/of/base.c | 37 +++++++++++++++++++++++++++++++++++++
include/of.h | 9 +++++++++
2 files changed, 46 insertions(+)
diff --git a/drivers/of/base.c b/drivers/of/base.c
index 3d26343..5853826 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -490,6 +490,36 @@ struct device_node *of_find_node_by_path(const char *path)
}
EXPORT_SYMBOL(of_find_node_by_path);
+/**
+ * of_property_read_string - Find and read a string from a property
+ * @np: device node from which the property value is to be read.
+ * @propname: name of the property to be searched.
+ * @out_string: pointer to null terminated return string, modified only if
+ * return value is 0.
+ *
+ * Search for a property in a device tree node and retrieve a null
+ * terminated string value (pointer to data, not a copy). Returns 0 on
+ * success, -EINVAL if the property does not exist, -ENODATA if property
+ * does not have a value, and -EILSEQ if the string is not null-terminated
+ * within the length of the property data.
+ *
+ * The out_string pointer is modified only if a valid string can be decoded.
+ */
+int of_property_read_string(struct device_node *np, const char *propname,
+ const char **out_string)
+{
+ struct property *prop = of_find_property(np, propname);
+ if (!prop)
+ return -EINVAL;
+ if (!prop->value)
+ return -ENODATA;
+ if (strnlen(prop->value, prop->length) >= prop->length)
+ return -EILSEQ;
+ *out_string = prop->value;
+ return 0;
+}
+EXPORT_SYMBOL_GPL(of_property_read_string);
+
struct device_node *of_get_root_node(void)
{
return root_node;
@@ -759,6 +789,12 @@ static void __of_probe(struct device_node *node)
}
struct device_node *of_chosen;
+const char *of_model;
+
+const char *of_get_model(void)
+{
+ return of_model;
+}
int of_probe(void)
{
@@ -766,6 +802,7 @@ int of_probe(void)
return -ENODEV;
of_chosen = of_find_node_by_path("/chosen");
+ of_property_read_string(root_node, "model", &of_model);
__of_probe(root_node);
diff --git a/include/of.h b/include/of.h
index e6342b6..58b4590 100644
--- a/include/of.h
+++ b/include/of.h
@@ -108,6 +108,9 @@ void of_print_nodes(struct device_node *node, int indent);
int of_probe(void);
int of_parse_dtb(struct fdt_header *fdt);
+int of_property_read_string(struct device_node *np, const char *propname,
+ const char **out_string);
+
#ifdef CONFIG_OFDEVICE
int of_parse_partitions(const char *cdevname,
struct device_node *node);
@@ -115,6 +118,7 @@ int of_parse_partitions(const char *cdevname,
struct device_node *of_get_root_node(void);
int of_alias_get_id(struct device_node *np, const char *stem);
int of_device_is_stdout_path(struct device_d *dev);
+const char *of_get_model(void);
#else
static inline int of_parse_partitions(const char *cdevname,
struct device_node *node)
@@ -136,6 +140,11 @@ static inline int of_device_is_stdout_path(struct device_d *dev)
{
return 0;
}
+
+static inline const char *of_get_model(void)
+{
+ return NULL;
+}
#endif
#endif /* __OF_H */
--
1.7.10.4
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 5/5] of: Print model name in banner
2012-10-08 19:46 [PATCH] of patches Sascha Hauer
` (3 preceding siblings ...)
2012-10-08 19:46 ` [PATCH 4/5] of: Add function to get the model name Sascha Hauer
@ 2012-10-08 19:46 ` Sascha Hauer
4 siblings, 0 replies; 6+ messages in thread
From: Sascha Hauer @ 2012-10-08 19:46 UTC (permalink / raw)
To: barebox
If we know the model name from the devicetree print this
in the banner instead of the hardcoded board name.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
common/version.c | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/common/version.c b/common/version.c
index a557904..22e111a 100644
--- a/common/version.c
+++ b/common/version.c
@@ -1,6 +1,7 @@
#include <common.h>
#include <generated/compile.h>
#include <generated/utsrelease.h>
+#include <of.h>
const char version_string[] =
"barebox " UTS_RELEASE " " UTS_VERSION "\n";
@@ -8,7 +9,13 @@ EXPORT_SYMBOL(version_string);
void barebox_banner (void)
{
+ const char *board;
+
+ board = of_get_model();
+
+ if (!board)
+ board = CONFIG_BOARDINFO;
+
printf("\n\n%s\n\n", version_string);
- printf("Board: " CONFIG_BOARDINFO "\n");
+ printf("Board: %s\n", board);
}
-
--
1.7.10.4
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 6+ messages in thread