From mboxrd@z Thu Jan 1 00:00:00 1970 From: Andrew Jones Subject: [PATCH kvm-unit-tests 02/15] devicetree: introduce dt_get_initrd Date: Fri, 13 Jan 2017 19:15:20 +0100 Message-ID: <20170113181533.15145-3-drjones@redhat.com> References: <20170113181533.15145-1-drjones@redhat.com> Cc: rkrcmar@redhat.com, pbonzini@redhat.com, lvivier@redhat.com, thuth@redhat.com To: kvm@vger.kernel.org Return-path: Received: from mx1.redhat.com ([209.132.183.28]:36900 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751104AbdAMSPx (ORCPT ); Fri, 13 Jan 2017 13:15:53 -0500 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 185483E9 for ; Fri, 13 Jan 2017 18:15:40 +0000 (UTC) In-Reply-To: <20170113181533.15145-1-drjones@redhat.com> Sender: kvm-owner@vger.kernel.org List-ID: Allow DT users to find the initrd if one is passed on the QEMU command line. Signed-off-by: Andrew Jones --- lib/devicetree.h | 10 ++++++++++ lib/devicetree.c | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/lib/devicetree.h b/lib/devicetree.h index 9a4d910b6450..93c7ebc63bd8 100644 --- a/lib/devicetree.h +++ b/lib/devicetree.h @@ -220,6 +220,16 @@ extern int dt_get_bootargs(const char **bootargs); extern int dt_get_default_console_node(void); /* + * dt_get_initrd gets the physical address of the initrd and its + * size from /chosen + * returns + * - zero on success + * - a negative FDT_ERR_* value on failure, and @initrd will be + * set to NULL and @size set to zero + */ +extern int dt_get_initrd(const char **initrd, u32 *size); + +/* * dt_get_memory_params gets the memory parameters from the /memory node(s) * storing each memory region ("address size" tuple) in consecutive entries * of @regs, up to @nr_regs diff --git a/lib/devicetree.c b/lib/devicetree.c index 509649b917cf..2b89178a109b 100644 --- a/lib/devicetree.c +++ b/lib/devicetree.c @@ -282,6 +282,40 @@ int dt_get_default_console_node(void) return fdt_path_offset(fdt, prop->data); } +int dt_get_initrd(const char **initrd, u32 *size) +{ + const struct fdt_property *prop; + const char *start, *end; + int node, len; + u32 *data; + + *initrd = NULL; + *size = 0; + + node = fdt_path_offset(fdt, "/chosen"); + if (node < 0) + return node; + + prop = fdt_get_property(fdt, node, "linux,initrd-start", &len); + if (!prop) + return len; + data = (u32 *)prop->data; + start = (const char *)(unsigned long)fdt32_to_cpu(*data); + + prop = fdt_get_property(fdt, node, "linux,initrd-end", &len); + if (!prop) { + assert(len != -FDT_ERR_NOTFOUND); + return len; + } + data = (u32 *)prop->data; + end = (const char *)(unsigned long)fdt32_to_cpu(*data); + + *initrd = start; + *size = (unsigned long)end - (unsigned long)start; + + return 0; +} + int dt_init(const void *fdt_ptr) { int ret; -- 2.9.3