mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 1/4] PBL: fdt: implement fdt_device_get_match_data
@ 2021-04-03  7:02 Ahmad Fatoum
  2021-04-03  7:02 ` [PATCH 2/4] RISC-V: debug_ll: ns16550: split off debug_ll from generic parts Ahmad Fatoum
                   ` (4 more replies)
  0 siblings, 5 replies; 7+ messages in thread
From: Ahmad Fatoum @ 2021-04-03  7:02 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

Currently, the generic DT image can't properly have a PBL console,
because it's only known at runtime what system we are running on.

As we already parse the FDT in the PBL to get the memory regions, we
could extract the board compatible as well and determine which UART to
use. Add a helper to achieve this.

Signed-off-by: Ahmad Fatoum <ahmad@a3f.at>
---
 include/pbl.h |  9 +++++++++
 pbl/fdt.c     | 36 ++++++++++++++++++++++++++++++++++++
 2 files changed, 45 insertions(+)

diff --git a/include/pbl.h b/include/pbl.h
index 194d5e750839..f58daec7351a 100644
--- a/include/pbl.h
+++ b/include/pbl.h
@@ -34,4 +34,13 @@ ssize_t pbl_fat_load(struct pbl_bio *, const char *filename, void *dest, size_t
 
 void fdt_find_mem(const void *fdt, unsigned long *membase, unsigned long *memsize);
 
+struct fdt_device_id {
+	const char *compatible;
+	const void *data;
+};
+
+const void *
+fdt_device_get_match_data(const void *fdt, const char *nodepath,
+			  const struct fdt_device_id ids[]);
+
 #endif /* __PBL_H__ */
diff --git a/pbl/fdt.c b/pbl/fdt.c
index b4a40a514b8b..03260cb61971 100644
--- a/pbl/fdt.c
+++ b/pbl/fdt.c
@@ -68,3 +68,39 @@ err:
 	pr_err("No memory, cannot continue\n");
 	while (1);
 }
+
+const void *fdt_device_get_match_data(const void *fdt, const char *nodepath,
+				      const struct fdt_device_id ids[])
+{
+	int node, length;
+	const char *list, *end;
+	const struct fdt_device_id *id;
+
+	node = fdt_path_offset(fdt, nodepath);
+	if (node < 0)
+		return NULL;
+
+	list = fdt_getprop(fdt, node, "compatible", &length);
+	if (!list)
+		return NULL;
+
+	end = list + length;
+
+	while (list < end) {
+		length = strnlen(list, end - list) + 1;
+
+		/* Abort if the last string isn't properly NUL-terminated. */
+		if (list + length > end)
+			return NULL;
+
+		for (id = ids; id->compatible; id++) {
+			if (strlen(id->compatible) == length &&
+			    !memcmp(list, id->compatible, length))
+				return id->data;
+		}
+
+		list += length;
+	}
+
+	return NULL;
+}
-- 
2.30.0


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2021-04-04 11:35 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-03  7:02 [PATCH 1/4] PBL: fdt: implement fdt_device_get_match_data Ahmad Fatoum
2021-04-03  7:02 ` [PATCH 2/4] RISC-V: debug_ll: ns16550: split off debug_ll from generic parts Ahmad Fatoum
2021-04-03  7:02 ` [PATCH 3/4] RISC-V: board-dt-2nd: add PBL console support for virt Ahmad Fatoum
2021-04-03  7:02 ` [PATCH 4/4] RISC-V: delete unused mach-virt subdirectory Ahmad Fatoum
2021-04-03  9:49 ` [PATCH] fixup! PBL: fdt: implement fdt_device_get_match_data Ahmad Fatoum
2021-04-03 12:00 ` [PATCH 1/4] " Jules Maselbas
2021-04-04 11:22   ` Ahmad Fatoum

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox