From patchwork Tue Apr 28 14:32:38 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 47748 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-la0-f71.google.com (mail-la0-f71.google.com [209.85.215.71]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 497C92121F for ; Wed, 29 Apr 2015 18:09:18 +0000 (UTC) Received: by layy10 with SMTP id y10sf8905974lay.0 for ; Wed, 29 Apr 2015 11:09: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:mime-version:cc:subject:precedence:list-id :list-unsubscribe:list-post:list-help:list-subscribe:content-type :content-transfer-encoding:sender:errors-to:x-original-sender :x-original-authentication-results:mailing-list:list-archive; bh=0fdnWs/vQYQ+IeKmtYaLU5IPecq9EPfZTLX15SjyIDM=; b=SSIMy/sBd3gL2QBZI2K+5ffF2p9HGagq10wNUSdK+GgoESsJUQVKrP4aeowKSpJweK bY9BXATUt+Iyu6M+qlupNf/LOywFzwo4PBchdhbSugm2qzv7f426PWvW6y+FkshgS3Id P56+yZg8GEytX/CHn5MWoZtKtINy/tW/A1yvAkGEgAOwIIFLfwSB3ovIlou7LM0mKlEQ 00Z/KVLCKGXrkeTtz/dYnFahFkir6sYVAY1s3/qcQT/Qkv3HSSGrp5n8wfAIrF8R3wXO bASAl84sYjEgAEesaIyOdTg/LTNRomHHAQXkBWLPtwttPj2v7kAxwTRAHhyd3vwOoZvz NuWA== X-Gm-Message-State: ALoCoQlYr4qltosFeQ9CWZR6HU8W3kbaD5OaIeIcgKFBsXd7Mg6nYSYkL2Vg2mJ7WTMyfAe2ujC4 X-Received: by 10.180.106.10 with SMTP id gq10mr13793642wib.0.1430330957046; Wed, 29 Apr 2015 11:09:17 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.10.208 with SMTP id k16ls283379lab.42.gmail; Wed, 29 Apr 2015 11:09:16 -0700 (PDT) X-Received: by 10.152.121.6 with SMTP id lg6mr310610lab.42.1430330956905; Wed, 29 Apr 2015 11:09:16 -0700 (PDT) Received: from mail-lb0-f174.google.com (mail-lb0-f174.google.com. [209.85.217.174]) by mx.google.com with ESMTPS id u5si19899241lal.85.2015.04.29.11.09.16 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 29 Apr 2015 11:09:16 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.174 as permitted sender) client-ip=209.85.217.174; Received: by lbcga7 with SMTP id ga7so26599411lbc.1 for ; Wed, 29 Apr 2015 11:09:16 -0700 (PDT) X-Received: by 10.152.36.161 with SMTP id r1mr288262laj.88.1430330956730; Wed, 29 Apr 2015 11:09: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.67.65 with SMTP id l1csp2663184lbt; Wed, 29 Apr 2015 11:09:15 -0700 (PDT) X-Received: by 10.42.187.65 with SMTP id cv1mr5113410icb.87.1430330954666; Wed, 29 Apr 2015 11:09:14 -0700 (PDT) Received: from lists.xen.org (lists.xen.org. [50.57.142.19]) by mx.google.com with ESMTPS id n65si21920798ioi.107.2015.04.29.11.09.14 (version=TLSv1 cipher=RC4-SHA bits=128/128); Wed, 29 Apr 2015 11:09:14 -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 1Yn6oF-00014G-21; Tue, 28 Apr 2015 14:48:27 +0000 Received: from mail6.bemta14.messagelabs.com ([193.109.254.103]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1Yn6oD-00013V-38 for xen-devel@lists.xenproject.org; Tue, 28 Apr 2015 14:48:25 +0000 Received: from [193.109.254.147] by server-3.bemta-14.messagelabs.com id 4F/E6-23827-8BD9F355; Tue, 28 Apr 2015 14:48:24 +0000 X-Env-Sender: julien.grall@citrix.com X-Msg-Ref: server-3.tower-27.messagelabs.com!1430232499!12833102!3 X-Originating-IP: [66.165.176.89] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogNjYuMTY1LjE3Ni44OSA9PiAyMDMwMDc=\n, received_headers: No Received headers X-StarScan-Received: X-StarScan-Version: 6.13.14; banners=-,-,- X-VirusChecked: Checked Received: (qmail 10695 invoked from network); 28 Apr 2015 14:48:23 -0000 Received: from smtp.citrix.com (HELO SMTP.CITRIX.COM) (66.165.176.89) by server-3.tower-27.messagelabs.com with RC4-SHA encrypted SMTP; 28 Apr 2015 14:48:23 -0000 X-IronPort-AV: E=Sophos;i="5.11,664,1422921600"; d="scan'208";a="257352095" From: Julien Grall To: Date: Tue, 28 Apr 2015 15:32:38 +0100 Message-ID: <1430231563-25648-15-git-send-email-julien.grall@citrix.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1430231563-25648-1-git-send-email-julien.grall@citrix.com> References: <1430231563-25648-1-git-send-email-julien.grall@citrix.com> MIME-Version: 1.0 X-DLP: MIA2 Cc: Wei Liu , ian.campbell@citrix.com, tim@xen.org, Julien Grall , Ian Jackson , stefano.stabellini@citrix.com Subject: [Xen-devel] [PATCH v6 14/19] 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: , 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: patch@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.217.174 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: From: Julien Grall 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 Signed-off-by: Ian Jackson Acked-by: Ian Campbell Cc: Wei Liu --- tools/configure needs to be regenerate as this patch is modifying tools/configure.ac Changes in v6: - Add Ian's Ack Changes in v5: - Add Ian's Signed-off-by for the license part and update the license - Rename libxl_fdt to libxl_libfdt_compat.c Changes in v4: - Patch added --- tools/config.h.in | 6 +++ tools/configure.ac | 5 +++ tools/libxl/Makefile | 2 +- tools/libxl/libxl_libfdt_compat.c | 92 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 104 insertions(+), 1 deletion(-) create mode 100644 tools/libxl/libxl_libfdt_compat.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..2afb146 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_libfdt_compat.o ifeq ($(CONFIG_NetBSD),y) LIBXL_OBJS-y += libxl_netbsd.o diff --git a/tools/libxl/libxl_libfdt_compat.c b/tools/libxl/libxl_libfdt_compat.c new file mode 100644 index 0000000..d0519f9 --- /dev/null +++ b/tools/libxl/libxl_libfdt_compat.c @@ -0,0 +1,92 @@ +/* + * Copyright (C) 2006 David Gibson, IBM Corporation. + * + * This file is part of libxl, and was originally taken from libfdt. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published + * by the Free Software Foundation; version 2.1 only. with the special + * exception on linking described in file LICENSE. + * + * This program 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 Lesser General Public License for more details. + * + * Additionally, this particular file is dual licensed. That is, + * alternatively, at your option: + * + * 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. + * + * Note that this applies only to this file, and other files with a + * similar notice. Also, note that when the same code is distributed + * along with the rest of libxl, you must comply with the terms of the + * LGPLv2.1 for the whole of libxl including this file. + * + * The intent is to permit, in particular, upstream libfdt to + * incorporate improvements to this file within upstream libfdt. At + * the time of writing, upstream libfdt is dual licensed: 2-clause BSD + * (as above) and GPLv2-or-later. The 2-clause BSD licence is + * compatible with both GPLv2-or-later and LGPLv2.1-only; this permits + * copying in both directions, and the optional licence upgrade to a + * copyleft licence by libdft upstream or the Xen Project, + * respectively. + */ + +#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