diff options
author | Thomas Huth <thuth@redhat.com> | 2018-05-26 08:06:07 +0200 |
---|---|---|
committer | Alexey Kardashevskiy <aik@ozlabs.ru> | 2018-05-29 19:07:25 +1000 |
commit | 5092c97eda8900070bc0be084526c89de5eed3a8 (patch) | |
tree | 212c072f844723fb3013a4468da64ba4be829f71 | |
parent | 9976594366a3e0da456e4688ac93d802dad56c71 (diff) | |
download | SLOF-5092c97eda8900070bc0be084526c89de5eed3a8.zip SLOF-5092c97eda8900070bc0be084526c89de5eed3a8.tar.gz SLOF-5092c97eda8900070bc0be084526c89de5eed3a8.tar.bz2 |
slof: Add a helper function to get the contents of a property in C code
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>
Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
-rw-r--r-- | include/helpers.h | 2 | ||||
-rw-r--r-- | slof/helpers.c | 15 |
2 files changed, 17 insertions, 0 deletions
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; +} |