[SLOF] [PATCH v2 10/11] slof: Add a helper function to get the contents of a property in C code

Thomas Huth thuth at redhat.com
Sat May 19 01:45:39 AEST 2018


We will need to retrieve the UUID of the VM in the libnet code, so we
need a function to get the contents from a device tree property.

Signed-off-by: Thomas Huth <thuth at redhat.com>
---
 include/helpers.h |  2 ++
 slof/helpers.c    | 15 +++++++++++++++
 2 files changed, 17 insertions(+)

diff --git a/include/helpers.h b/include/helpers.h
index 9dfe3ae..5834bce 100644
--- a/include/helpers.h
+++ b/include/helpers.h
@@ -40,6 +40,8 @@ extern void SLOF_set_chosen_int(const char *s, long val);
 extern void SLOF_set_chosen_bytes(const char *s, const char *addr, size_t size);
 extern void SLOF_encode_bootp_response(void *addr, size_t size);
 extern void SLOF_encode_dhcp_response(void *addr, size_t size);
+extern int SLOF_get_property(const char *node, const char *propname,
+                             char **addr, int *len);
 
 #define offset_of(type, member) ((long) &((type *)0)->member)
 #define container_of(ptr, type, member) ({                      \
diff --git a/slof/helpers.c b/slof/helpers.c
index bd0742e..dfb0c13 100644
--- a/slof/helpers.c
+++ b/slof/helpers.c
@@ -209,3 +209,18 @@ void SLOF_encode_dhcp_response(void *addr, size_t size)
 {
 	SLOF_set_chosen_bytes("dhcp-response", addr, size);
 }
+
+int SLOF_get_property(const char *node, const char *propname,
+                      char **addr, int *len)
+{
+	forth_push((unsigned long)propname);
+	forth_push(strlen(propname));
+	forth_push((unsigned long)node);
+	forth_push(strlen(node));
+	forth_eval("find-node get-property");
+	if (forth_pop())
+		return -1;
+	*len = forth_pop();
+	*addr = (char *)forth_pop();
+	return 0;
+}
-- 
1.8.3.1



More information about the SLOF mailing list