From patchwork Thu Mar 19 19:29:54 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 46116 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-we0-f200.google.com (mail-we0-f200.google.com [74.125.82.200]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id CD55721515 for ; Thu, 19 Mar 2015 19:33:17 +0000 (UTC) Received: by wesq59 with SMTP id q59sf14147537wes.1 for ; Thu, 19 Mar 2015 12:33:17 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:date:message-id:in-reply-to :references:cc:subject:precedence:list-id:list-unsubscribe:list-post :list-help:list-subscribe:mime-version:content-type :content-transfer-encoding:sender:errors-to:x-original-sender :x-original-authentication-results:mailing-list:list-archive; bh=YPtIAXch/S0AJiFD+4Wmzzg6rKkN23j+FVrmB8dZnBo=; b=GpZcxfCp081rljx4g20G+xdeibdjxcuXMwGN3aEykeyyVWTR/Dn0TA4EeF+1ao3oFZ wIpZH/M0Vd1m4wpbBpJcnsNHtxA/ccdDz6JBEmMzMIjKiAClXYz7PBtaPSftv9jyrxAw E3R0FxN/nUZeq8t+eLmo4yde1D4Js4Uq12dyWlcSkNodbk6q5yXLgamuiAy7G35yOImJ LcvZ3d5ZU3g7Y77OFhnAw/UJU/aMpwfaJLK5StmgO2Q/wsTwc1wXdL4y2SBtqWGmSE4p cAfHB/eqOAA/ijUv+0onwL9srywLxPuDL5scIke4MgpjH29UM1i50YgAHMhXRR4arq+U KdfA== X-Gm-Message-State: ALoCoQkIkF0Bmsr9qjA3QNVhPcIDku0re4qLyvMmJMQorCNNAJa6zeEQGwvupi2XEpDNah89+LeH X-Received: by 10.112.35.135 with SMTP id h7mr12220696lbj.23.1426793597115; Thu, 19 Mar 2015 12:33:17 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.43.48 with SMTP id t16ls323874lal.55.gmail; Thu, 19 Mar 2015 12:33:16 -0700 (PDT) X-Received: by 10.152.7.212 with SMTP id l20mr58694110laa.68.1426793596841; Thu, 19 Mar 2015 12:33:16 -0700 (PDT) Received: from mail-la0-f42.google.com (mail-la0-f42.google.com. [209.85.215.42]) by mx.google.com with ESMTPS id qy3si1637610lbc.117.2015.03.19.12.33.16 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 19 Mar 2015 12:33:16 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.42 as permitted sender) client-ip=209.85.215.42; Received: by labjg1 with SMTP id jg1so70631203lab.2 for ; Thu, 19 Mar 2015 12:33:16 -0700 (PDT) X-Received: by 10.112.162.167 with SMTP id yb7mr68450396lbb.76.1426793596746; Thu, 19 Mar 2015 12:33:16 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.35.133 with SMTP id h5csp598010lbj; Thu, 19 Mar 2015 12:33:15 -0700 (PDT) X-Received: by 10.55.54.71 with SMTP id d68mr156792294qka.42.1426793570133; Thu, 19 Mar 2015 12:32:50 -0700 (PDT) Received: from lists.xen.org (lists.xen.org. [50.57.142.19]) by mx.google.com with ESMTPS id i90si2165552qge.83.2015.03.19.12.32.49 (version=TLSv1 cipher=RC4-SHA bits=128/128); Thu, 19 Mar 2015 12:32:50 -0700 (PDT) Received-SPF: none (google.com: xen-devel-bounces@lists.xen.org does not designate permitted sender hosts) client-ip=50.57.142.19; Received: from localhost ([127.0.0.1] helo=lists.xen.org) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1YYgA8-0005La-C5; Thu, 19 Mar 2015 19:31:24 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1YYgA5-0005Dy-Kr for xen-devel@lists.xenproject.org; Thu, 19 Mar 2015 19:31:21 +0000 Received: from [85.158.139.211] by server-7.bemta-5.messagelabs.com id AF/E4-30396-8042B055; Thu, 19 Mar 2015 19:31:20 +0000 X-Env-Sender: julien.grall@linaro.org X-Msg-Ref: server-3.tower-206.messagelabs.com!1426793479!4386479!1 X-Originating-IP: [74.125.82.49] X-SpamReason: No, hits=0.0 required=7.0 tests=UPPERCASE_25_50 X-StarScan-Received: X-StarScan-Version: 6.13.4; banners=-,-,- X-VirusChecked: Checked Received: (qmail 5357 invoked from network); 19 Mar 2015 19:31:19 -0000 Received: from mail-wg0-f49.google.com (HELO mail-wg0-f49.google.com) (74.125.82.49) by server-3.tower-206.messagelabs.com with RC4-SHA encrypted SMTP; 19 Mar 2015 19:31:19 -0000 Received: by wgra20 with SMTP id a20so71296104wgr.3 for ; Thu, 19 Mar 2015 12:31:19 -0700 (PDT) X-Received: by 10.180.104.66 with SMTP id gc2mr18975623wib.34.1426793479722; Thu, 19 Mar 2015 12:31:19 -0700 (PDT) Received: from chilopoda.uk.xensource.com. ([185.25.64.249]) by mx.google.com with ESMTPSA id hl8sm3203005wjb.38.2015.03.19.12.31.18 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 19 Mar 2015 12:31:18 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xenproject.org Date: Thu, 19 Mar 2015 19:29:54 +0000 Message-Id: <1426793399-6283-29-git-send-email-julien.grall@linaro.org> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1426793399-6283-1-git-send-email-julien.grall@linaro.org> References: <1426793399-6283-1-git-send-email-julien.grall@linaro.org> Cc: Wei Liu , ian.campbell@citrix.com, tim@xen.org, Julien Grall , Ian Jackson , stefano.stabellini@citrix.com Subject: [Xen-devel] [PATCH v4 28/33] tools/libxl: Check if fdt_{first, next}_subnode are present in libfdt X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: List-Unsubscribe: , List-Post: , List-Help: , List-Subscribe: , MIME-Version: 1.0 Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: julien.grall@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.42 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Archive: The functions fdt_{fisrt,next}_subnode may not be available because: * It has been introduced in 2013 => Doesn't work on Wheezy * The prototype exists but the functions are not exposed. Don't ask why... The later has been fixed recently in the dtc repo [1] When the functions are not available, implement our own in order to use them in a following patch. [1] git://git.kernel.org/pub/scm/utils/dtc/dtc.git commit a4b093f7366fdb429ca1781144d3985fa50d0fbb Signed-off-by: Julien Grall Cc: Ian Jackson Cc: Wei Liu --- Changes in v4: - Patch added --- tools/config.h.in | 6 ++++ tools/configure.ac | 5 +++ tools/libxl/Makefile | 2 +- tools/libxl/libxl_fdt.c | 84 +++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 96 insertions(+), 1 deletion(-) create mode 100644 tools/libxl/libxl_fdt.c diff --git a/tools/config.h.in b/tools/config.h.in index 2a0ae48..06f8b6c 100644 --- a/tools/config.h.in +++ b/tools/config.h.in @@ -3,6 +3,12 @@ /* Blktap2 enabled */ #undef HAVE_BLKTAP2 +/* Define to 1 if you have the `fdt_first_subnode' function. */ +#undef HAVE_FDT_FIRST_SUBNODE + +/* Define to 1 if you have the `fdt_next_subnode' function. */ +#undef HAVE_FDT_NEXT_SUBNODE + /* Define to 1 if you have the header file. */ #undef HAVE_INTTYPES_H diff --git a/tools/configure.ac b/tools/configure.ac index d31c2f3..cc13336 100644 --- a/tools/configure.ac +++ b/tools/configure.ac @@ -355,6 +355,11 @@ AC_SUBST(libiconv) case "$host_cpu" in arm*|aarch64) AC_CHECK_LIB([fdt], [fdt_create], [], [AC_MSG_ERROR([Could not find libfdt])]) + +# The functions fdt_{first,next}_subnode may not be available because: +# * It has been introduced in 2013 => Doesn't work on Wheezy +# * The prototype exists but the functions are not exposed. Don't ask why... +AC_CHECK_FUNCS([fdt_first_subnode fdt_next_subnode]) esac # Checks for header files. diff --git a/tools/libxl/Makefile b/tools/libxl/Makefile index 1b16598..d74aee1 100644 --- a/tools/libxl/Makefile +++ b/tools/libxl/Makefile @@ -59,7 +59,7 @@ endif LIBXL_OBJS-y += libxl_remus_device.o libxl_remus_disk_drbd.o LIBXL_OBJS-$(CONFIG_X86) += libxl_cpuid.o libxl_x86.o libxl_psr.o -LIBXL_OBJS-$(CONFIG_ARM) += libxl_nocpuid.o libxl_arm.o +LIBXL_OBJS-$(CONFIG_ARM) += libxl_nocpuid.o libxl_arm.o libxl_fdt.o ifeq ($(CONFIG_NetBSD),y) LIBXL_OBJS-y += libxl_netbsd.o diff --git a/tools/libxl/libxl_fdt.c b/tools/libxl/libxl_fdt.c new file mode 100644 index 0000000..f88e9f1 --- /dev/null +++ b/tools/libxl/libxl_fdt.c @@ -0,0 +1,84 @@ +/* + * libfdt - Flat Device Tree manipulation + * Copyright (C) 2006 David Gibson, IBM Corporation. + * + * libfdt is dual licensed: you can use it either under the terms of + * the GPL, or the BSD license, at your option. + * + * a) This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this library; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, + * MA 02110-1301 USA + * + * Alternatively, + * + * b) Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * 1. Redistributions of source code must retain the above + * copyright notice, this list of conditions and the following + * disclaimer. + * 2. Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND + * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include + +#ifndef HAVE_FDT_FIRST_SUBNODE +int fdt_first_subnode(const void *fdt, int offset) +{ + int depth = 0; + + offset = fdt_next_node(fdt, offset, &depth); + if (offset < 0 || depth != 1) + return -FDT_ERR_NOTFOUND; + + return offset; +} +#endif + +#ifndef HAVE_FDT_NEXT_SUBNODE +int fdt_next_subnode(const void *fdt, int offset) +{ + int depth = 1; + + /* + * With respect to the parent, the depth of the next subnode will be + * the same as the last. + */ + do { + offset = fdt_next_node(fdt, offset, &depth); + if (offset < 0 || depth < 1) + return -FDT_ERR_NOTFOUND; + } while (depth > 1); + + return offset; +} +#endif