diff mbox series

[v3,7/8] slof: Add a helper function to get the contents of a property in C code

Message ID 1527314768-4797-8-git-send-email-thuth@redhat.com
State Accepted
Headers show
Series Support network booting with pxelinux.cfg files | expand

Commit Message

Thomas Huth May 26, 2018, 6:06 a.m. UTC
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@redhat.com>
---
 include/helpers.h |  2 ++
 slof/helpers.c    | 15 +++++++++++++++
 2 files changed, 17 insertions(+)
diff mbox series

Patch

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;
+}