From patchwork Sat May 26 06:06:07 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Huth X-Patchwork-Id: 920933 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 40tCLj3k6mz9s16 for ; Sat, 26 May 2018 16:06:53 +1000 (AEST) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 40tCLj20c3zDr10 for ; Sat, 26 May 2018 16:06:53 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=redhat.com X-Original-To: slof@lists.ozlabs.org Delivered-To: slof@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=redhat.com (client-ip=66.187.233.73; helo=mx1.redhat.com; envelope-from=thuth@redhat.com; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=redhat.com Received: from mx1.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 40tCL65V1ZzDqL5 for ; Sat, 26 May 2018 16:06:22 +1000 (AEST) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8318840201C5; Sat, 26 May 2018 06:06:20 +0000 (UTC) Received: from thh440s.redhat.com (ovpn-116-22.ams2.redhat.com [10.36.116.22]) by smtp.corp.redhat.com (Postfix) with ESMTP id 787232023433; Sat, 26 May 2018 06:06:19 +0000 (UTC) From: Thomas Huth To: slof@lists.ozlabs.org Date: Sat, 26 May 2018 08:06:07 +0200 Message-Id: <1527314768-4797-8-git-send-email-thuth@redhat.com> In-Reply-To: <1527314768-4797-1-git-send-email-thuth@redhat.com> References: <1527314768-4797-1-git-send-email-thuth@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Sat, 26 May 2018 06:06:20 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Sat, 26 May 2018 06:06:20 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'thuth@redhat.com' RCPT:'' Subject: [SLOF] [PATCH v3 7/8] slof: Add a helper function to get the contents of a property in C code X-BeenThere: slof@lists.ozlabs.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: "Patches for https://github.com/aik/SLOF" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Greg Kurz MIME-Version: 1.0 Errors-To: slof-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "SLOF" 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 --- 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; +}