From patchwork Sat Jun 23 23:07:00 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Graf X-Patchwork-Id: 166789 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 381E7B6F9D for ; Sun, 24 Jun 2012 09:12:53 +1000 (EST) Received: from localhost ([::1]:35115 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SiZVb-0006Xc-1u for incoming@patchwork.ozlabs.org; Sat, 23 Jun 2012 19:12:51 -0400 Received: from eggs.gnu.org ([208.118.235.92]:38242) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SiZRC-000854-3g for qemu-devel@nongnu.org; Sat, 23 Jun 2012 19:08:31 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SiZR3-0002OK-ES for qemu-devel@nongnu.org; Sat, 23 Jun 2012 19:08:17 -0400 Received: from cantor2.suse.de ([195.135.220.15]:34887 helo=mx2.suse.de) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SiZR3-0002NZ-4l; Sat, 23 Jun 2012 19:08:09 -0400 Received: from relay1.suse.de (unknown [195.135.220.254]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx2.suse.de (Postfix) with ESMTP id D0A47A3CEE; Sun, 24 Jun 2012 01:08:07 +0200 (CEST) From: Alexander Graf To: qemu-devel qemu-devel Date: Sun, 24 Jun 2012 01:07:00 +0200 Message-Id: <1340492856-21126-37-git-send-email-agraf@suse.de> X-Mailer: git-send-email 1.6.0.2 In-Reply-To: <1340492856-21126-1-git-send-email-agraf@suse.de> References: <1340492856-21126-1-git-send-email-agraf@suse.de> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4-2.6 X-Received-From: 195.135.220.15 Cc: Blue Swirl , qemu-ppc Mailing List , Aurelien Jarno Subject: [Qemu-devel] [PATCH 36/72] dt: add helper for empty dt creation X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org We want to get rid of the concept of loading an external device tree and instead generate our own. However, to do this we need to also create a device tree template programatically. This patch adds a helper to create an empty device tree in memory. Signed-off-by: Alexander Graf Reviewed-by: Peter Crosthwaite --- device_tree.c | 37 +++++++++++++++++++++++++++++++++++++ device_tree.h | 1 + 2 files changed, 38 insertions(+), 0 deletions(-) diff --git a/device_tree.c b/device_tree.c index 2f127b7..d037896 100644 --- a/device_tree.c +++ b/device_tree.c @@ -25,6 +25,43 @@ #include +#define FDT_MAX_SIZE 0x10000 + +void *create_device_tree(int *sizep) +{ + void *fdt; + int ret; + + *sizep = FDT_MAX_SIZE; + fdt = g_malloc0(FDT_MAX_SIZE); + ret = fdt_create(fdt, FDT_MAX_SIZE); + if (ret < 0) { + goto fail; + } + ret = fdt_begin_node(fdt, ""); + if (ret < 0) { + goto fail; + } + ret = fdt_end_node(fdt); + if (ret < 0) { + goto fail; + } + ret = fdt_finish(fdt); + if (ret < 0) { + goto fail; + } + ret = fdt_open_into(fdt, fdt, *sizep); + if (ret) { + fprintf(stderr, "Unable to copy device tree in memory\n"); + exit(1); + } + + return fdt; +fail: + fprintf(stderr, "%s Couldn't create dt: %s\n", __func__, fdt_strerror(ret)); + exit(1); +} + void *load_device_tree(const char *filename_path, int *sizep) { int dt_size; diff --git a/device_tree.h b/device_tree.h index 36fc9db..5f76f40 100644 --- a/device_tree.h +++ b/device_tree.h @@ -14,6 +14,7 @@ #ifndef __DEVICE_TREE_H__ #define __DEVICE_TREE_H__ +void *create_device_tree(int *sizep); void *load_device_tree(const char *filename_path, int *sizep); int qemu_devtree_setprop(void *fdt, const char *node_path,