From patchwork Tue Oct 17 01:11:41 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 115997 Delivered-To: patch@linaro.org Received: by 10.140.22.163 with SMTP id 32csp4296484qgn; Mon, 16 Oct 2017 18:13:40 -0700 (PDT) X-Google-Smtp-Source: AOwi7QDaNvLyYux19xeB6D4xGNt8i8Tnb9FgmFxlJNNUWx9txUtz226RjZPQO6dJIgzp2bcfO4ju X-Received: by 10.80.243.145 with SMTP id g17mr15071258edm.42.1508202820027; Mon, 16 Oct 2017 18:13:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1508202820; cv=none; d=google.com; s=arc-20160816; b=rNaI3EgIz5cud5MwKKjN8Jva8ErUijN4H73Wp4gBiGF+GmefBVjwUfVdWe4sVVjuGb j+Z0oVSlg76Q3K+O4PZpKAXMd4fcs4s+MJ6ing61OgQb8x4+PghUnjE48o1Amw21pLWH DkcuFYCU5GZjplG8luvuHWwz1DuXa4Z/9av2EnlMCN6MO67ahTiB/yu6IPd3Ct5T/rJ2 G9sLAONcQvuruHckQJVPoctCnukUJ3pBrB0zL8XRYJqagt6cwRRWDIQMdquWZ/dwJtxz RJa9ysdmmSeeaiDQa5AeAhgbirvqBFdG9CmVAf0leVj49ZQSHG6b4RTBdIBbIVaNcwdA RRMw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:cc:references:in-reply-to:message-id :date:to:from:dkim-signature:dkim-filter:arc-authentication-results; bh=T0t5ScOSAt45/3zK+v3iMixbFw2le8pYkowltr5zNQc=; b=zqhaoTnFO5rkbs4bDmYl2Ws8fhbIRvP+O/kVDL/EGJx6NaG4v26kz3ho1vUn4fJHjM lxU8AWLIr+1xlxuqXPs4TAvBeDni8gW3wWySE4qjvtcDTXJKd48z/LQr63pXtz0DXtgQ 7EtKsaDGW6mEKBhAF72ZuCh7EGMmojy21DIMlfDxyBKvFmeZ/OL+TUZyl+B8yLci2JB7 bveria5r4mR3WJOYBngvUegxV3gp3hw3lL2IXlf9aTA/dl5+IMl/8QyeD7Rkr3R/zdBv 8FX8137CY3c2jblj/ZEfkWTSyTma5R95k3qYgH8r6ttxpsakwDD4LajuXjB1Fle/eGL6 m3mg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@nifty.com header.s=dec2015msa header.b=vRAjKJ5V; spf=pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de Return-Path: Received: from lists.denx.de (dione.denx.de. [81.169.180.215]) by mx.google.com with ESMTP id c15si2184346edf.93.2017.10.16.18.13.39; Mon, 16 Oct 2017 18:13:40 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) client-ip=81.169.180.215; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@nifty.com header.s=dec2015msa header.b=vRAjKJ5V; spf=pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de Received: by lists.denx.de (Postfix, from userid 105) id 8DEFBC21D56; Tue, 17 Oct 2017 01:13:35 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id F0BC9C21C40; Tue, 17 Oct 2017 01:12:33 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 60649C21C40; Tue, 17 Oct 2017 01:12:31 +0000 (UTC) Received: from conuserg-09.nifty.com (conuserg-09.nifty.com [210.131.2.76]) by lists.denx.de (Postfix) with ESMTPS id 22B97C21C41 for ; Tue, 17 Oct 2017 01:12:29 +0000 (UTC) Received: from pug.e01.socionext.com (p14092-ipngnfx01kyoto.kyoto.ocn.ne.jp [153.142.97.92]) (authenticated) by conuserg-09.nifty.com with ESMTP id v9H1Bnl3015917; Tue, 17 Oct 2017 10:11:50 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-09.nifty.com v9H1Bnl3015917 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1508202710; bh=j+ByPXB0k3TTDeOmLZ75M/A2IN4aojtXLjTtTQKsx/c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=vRAjKJ5Vy762XnXIN0Xxh33Avbs4GqIP13r2bMtWjnnUCpdxCPWdG3Vd0tg6sjvca ob/gwHfEi3wnQAXSmNaXsRTNbz1CNtB8/4e4/STU8580O5n7XeIHfmNQVX4qv3TMND e3EGd1JFcLPAjIjnjbiPO2oec7NHG9Z7ecP+5P2o16aZ90u4HQdSQsup+EZXU9iP8B XOTZ8okIYFDa5Kf53ISwuSwAw0JIH2Kg/Asjgjp4r+w7t/Xj7YzXK+/izf7oMIagic PpeAydEz5YmiNmciOuWI3j08gvOBD0VzNhPIBF1aGcaa/rU3Vdos54k59p0+e62/jo yN2THFCe8bcog== X-Nifty-SrcIP: [153.142.97.92] From: Masahiro Yamada To: u-boot@lists.denx.de Date: Tue, 17 Oct 2017 10:11:41 +0900 Message-Id: <1508202703-23165-2-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1508202703-23165-1-git-send-email-yamada.masahiro@socionext.com> References: <1508202703-23165-1-git-send-email-yamada.masahiro@socionext.com> Cc: Tom Rini Subject: [U-Boot] [PATCH 1/3] dtc: libfdt: import fdt_addresses.c and fdt_overlay.c X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" I will move the pylibfdt build script under the scripts/dtc/ in the next commit. We need two more files to build the pylibfdt. We have almost same copies in lib/libfdt, but we are collecting all DTC-derived files into scripts/dtc. Import fdt_addresses.c and fdt_overlay.c from DTC v1.4.5. Signed-off-by: Masahiro Yamada --- scripts/dtc/libfdt/fdt_addresses.c | 96 +++++ scripts/dtc/libfdt/fdt_overlay.c | 861 +++++++++++++++++++++++++++++++++++++ 2 files changed, 957 insertions(+) create mode 100644 scripts/dtc/libfdt/fdt_addresses.c create mode 100644 scripts/dtc/libfdt/fdt_overlay.c diff --git a/scripts/dtc/libfdt/fdt_addresses.c b/scripts/dtc/libfdt/fdt_addresses.c new file mode 100644 index 0000000..eff4dbc --- /dev/null +++ b/scripts/dtc/libfdt/fdt_addresses.c @@ -0,0 +1,96 @@ +/* + * libfdt - Flat Device Tree manipulation + * Copyright (C) 2014 David Gibson + * + * 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 "libfdt_env.h" + +#include +#include + +#include "libfdt_internal.h" + +int fdt_address_cells(const void *fdt, int nodeoffset) +{ + const fdt32_t *ac; + int val; + int len; + + ac = fdt_getprop(fdt, nodeoffset, "#address-cells", &len); + if (!ac) + return 2; + + if (len != sizeof(*ac)) + return -FDT_ERR_BADNCELLS; + + val = fdt32_to_cpu(*ac); + if ((val <= 0) || (val > FDT_MAX_NCELLS)) + return -FDT_ERR_BADNCELLS; + + return val; +} + +int fdt_size_cells(const void *fdt, int nodeoffset) +{ + const fdt32_t *sc; + int val; + int len; + + sc = fdt_getprop(fdt, nodeoffset, "#size-cells", &len); + if (!sc) + return 2; + + if (len != sizeof(*sc)) + return -FDT_ERR_BADNCELLS; + + val = fdt32_to_cpu(*sc); + if ((val < 0) || (val > FDT_MAX_NCELLS)) + return -FDT_ERR_BADNCELLS; + + return val; +} diff --git a/scripts/dtc/libfdt/fdt_overlay.c b/scripts/dtc/libfdt/fdt_overlay.c new file mode 100644 index 0000000..bd81241 --- /dev/null +++ b/scripts/dtc/libfdt/fdt_overlay.c @@ -0,0 +1,861 @@ +#include "libfdt_env.h" + +#include +#include + +#include "libfdt_internal.h" + +/** + * overlay_get_target_phandle - retrieves the target phandle of a fragment + * @fdto: pointer to the device tree overlay blob + * @fragment: node offset of the fragment in the overlay + * + * overlay_get_target_phandle() retrieves the target phandle of an + * overlay fragment when that fragment uses a phandle (target + * property) instead of a path (target-path property). + * + * returns: + * the phandle pointed by the target property + * 0, if the phandle was not found + * -1, if the phandle was malformed + */ +static uint32_t overlay_get_target_phandle(const void *fdto, int fragment) +{ + const fdt32_t *val; + int len; + + val = fdt_getprop(fdto, fragment, "target", &len); + if (!val) + return 0; + + if ((len != sizeof(*val)) || (fdt32_to_cpu(*val) == (uint32_t)-1)) + return (uint32_t)-1; + + return fdt32_to_cpu(*val); +} + +/** + * overlay_get_target - retrieves the offset of a fragment's target + * @fdt: Base device tree blob + * @fdto: Device tree overlay blob + * @fragment: node offset of the fragment in the overlay + * @pathp: pointer which receives the path of the target (or NULL) + * + * overlay_get_target() retrieves the target offset in the base + * device tree of a fragment, no matter how the actual targetting is + * done (through a phandle or a path) + * + * returns: + * the targetted node offset in the base device tree + * Negative error code on error + */ +static int overlay_get_target(const void *fdt, const void *fdto, + int fragment, char const **pathp) +{ + uint32_t phandle; + const char *path = NULL; + int path_len = 0, ret; + + /* Try first to do a phandle based lookup */ + phandle = overlay_get_target_phandle(fdto, fragment); + if (phandle == (uint32_t)-1) + return -FDT_ERR_BADPHANDLE; + + /* no phandle, try path */ + if (!phandle) { + /* And then a path based lookup */ + path = fdt_getprop(fdto, fragment, "target-path", &path_len); + if (path) + ret = fdt_path_offset(fdt, path); + else + ret = path_len; + } else + ret = fdt_node_offset_by_phandle(fdt, phandle); + + /* + * If we haven't found either a target or a + * target-path property in a node that contains a + * __overlay__ subnode (we wouldn't be called + * otherwise), consider it a improperly written + * overlay + */ + if (ret < 0 && path_len == -FDT_ERR_NOTFOUND) + ret = -FDT_ERR_BADOVERLAY; + + /* return on error */ + if (ret < 0) + return ret; + + /* return pointer to path (if available) */ + if (pathp) + *pathp = path ? path : NULL; + + return ret; +} + +/** + * overlay_phandle_add_offset - Increases a phandle by an offset + * @fdt: Base device tree blob + * @node: Device tree overlay blob + * @name: Name of the property to modify (phandle or linux,phandle) + * @delta: offset to apply + * + * overlay_phandle_add_offset() increments a node phandle by a given + * offset. + * + * returns: + * 0 on success. + * Negative error code on error + */ +static int overlay_phandle_add_offset(void *fdt, int node, + const char *name, uint32_t delta) +{ + const fdt32_t *val; + uint32_t adj_val; + int len; + + val = fdt_getprop(fdt, node, name, &len); + if (!val) + return len; + + if (len != sizeof(*val)) + return -FDT_ERR_BADPHANDLE; + + adj_val = fdt32_to_cpu(*val); + if ((adj_val + delta) < adj_val) + return -FDT_ERR_NOPHANDLES; + + adj_val += delta; + if (adj_val == (uint32_t)-1) + return -FDT_ERR_NOPHANDLES; + + return fdt_setprop_inplace_u32(fdt, node, name, adj_val); +} + +/** + * overlay_adjust_node_phandles - Offsets the phandles of a node + * @fdto: Device tree overlay blob + * @node: Offset of the node we want to adjust + * @delta: Offset to shift the phandles of + * + * overlay_adjust_node_phandles() adds a constant to all the phandles + * of a given node. This is mainly use as part of the overlay + * application process, when we want to update all the overlay + * phandles to not conflict with the overlays of the base device tree. + * + * returns: + * 0 on success + * Negative error code on failure + */ +static int overlay_adjust_node_phandles(void *fdto, int node, + uint32_t delta) +{ + int child; + int ret; + + ret = overlay_phandle_add_offset(fdto, node, "phandle", delta); + if (ret && ret != -FDT_ERR_NOTFOUND) + return ret; + + ret = overlay_phandle_add_offset(fdto, node, "linux,phandle", delta); + if (ret && ret != -FDT_ERR_NOTFOUND) + return ret; + + fdt_for_each_subnode(child, fdto, node) { + ret = overlay_adjust_node_phandles(fdto, child, delta); + if (ret) + return ret; + } + + return 0; +} + +/** + * overlay_adjust_local_phandles - Adjust the phandles of a whole overlay + * @fdto: Device tree overlay blob + * @delta: Offset to shift the phandles of + * + * overlay_adjust_local_phandles() adds a constant to all the + * phandles of an overlay. This is mainly use as part of the overlay + * application process, when we want to update all the overlay + * phandles to not conflict with the overlays of the base device tree. + * + * returns: + * 0 on success + * Negative error code on failure + */ +static int overlay_adjust_local_phandles(void *fdto, uint32_t delta) +{ + /* + * Start adjusting the phandles from the overlay root + */ + return overlay_adjust_node_phandles(fdto, 0, delta); +} + +/** + * overlay_update_local_node_references - Adjust the overlay references + * @fdto: Device tree overlay blob + * @tree_node: Node offset of the node to operate on + * @fixup_node: Node offset of the matching local fixups node + * @delta: Offset to shift the phandles of + * + * overlay_update_local_nodes_references() update the phandles + * pointing to a node within the device tree overlay by adding a + * constant delta. + * + * This is mainly used as part of a device tree application process, + * where you want the device tree overlays phandles to not conflict + * with the ones from the base device tree before merging them. + * + * returns: + * 0 on success + * Negative error code on failure + */ +static int overlay_update_local_node_references(void *fdto, + int tree_node, + int fixup_node, + uint32_t delta) +{ + int fixup_prop; + int fixup_child; + int ret; + + fdt_for_each_property_offset(fixup_prop, fdto, fixup_node) { + const fdt32_t *fixup_val; + const char *tree_val; + const char *name; + int fixup_len; + int tree_len; + int i; + + fixup_val = fdt_getprop_by_offset(fdto, fixup_prop, + &name, &fixup_len); + if (!fixup_val) + return fixup_len; + + if (fixup_len % sizeof(uint32_t)) + return -FDT_ERR_BADOVERLAY; + + tree_val = fdt_getprop(fdto, tree_node, name, &tree_len); + if (!tree_val) { + if (tree_len == -FDT_ERR_NOTFOUND) + return -FDT_ERR_BADOVERLAY; + + return tree_len; + } + + for (i = 0; i < (fixup_len / sizeof(uint32_t)); i++) { + fdt32_t adj_val; + uint32_t poffset; + + poffset = fdt32_to_cpu(fixup_val[i]); + + /* + * phandles to fixup can be unaligned. + * + * Use a memcpy for the architectures that do + * not support unaligned accesses. + */ + memcpy(&adj_val, tree_val + poffset, sizeof(adj_val)); + + adj_val = cpu_to_fdt32(fdt32_to_cpu(adj_val) + delta); + + ret = fdt_setprop_inplace_namelen_partial(fdto, + tree_node, + name, + strlen(name), + poffset, + &adj_val, + sizeof(adj_val)); + if (ret == -FDT_ERR_NOSPACE) + return -FDT_ERR_BADOVERLAY; + + if (ret) + return ret; + } + } + + fdt_for_each_subnode(fixup_child, fdto, fixup_node) { + const char *fixup_child_name = fdt_get_name(fdto, fixup_child, + NULL); + int tree_child; + + tree_child = fdt_subnode_offset(fdto, tree_node, + fixup_child_name); + if (tree_child == -FDT_ERR_NOTFOUND) + return -FDT_ERR_BADOVERLAY; + if (tree_child < 0) + return tree_child; + + ret = overlay_update_local_node_references(fdto, + tree_child, + fixup_child, + delta); + if (ret) + return ret; + } + + return 0; +} + +/** + * overlay_update_local_references - Adjust the overlay references + * @fdto: Device tree overlay blob + * @delta: Offset to shift the phandles of + * + * overlay_update_local_references() update all the phandles pointing + * to a node within the device tree overlay by adding a constant + * delta to not conflict with the base overlay. + * + * This is mainly used as part of a device tree application process, + * where you want the device tree overlays phandles to not conflict + * with the ones from the base device tree before merging them. + * + * returns: + * 0 on success + * Negative error code on failure + */ +static int overlay_update_local_references(void *fdto, uint32_t delta) +{ + int fixups; + + fixups = fdt_path_offset(fdto, "/__local_fixups__"); + if (fixups < 0) { + /* There's no local phandles to adjust, bail out */ + if (fixups == -FDT_ERR_NOTFOUND) + return 0; + + return fixups; + } + + /* + * Update our local references from the root of the tree + */ + return overlay_update_local_node_references(fdto, 0, fixups, + delta); +} + +/** + * overlay_fixup_one_phandle - Set an overlay phandle to the base one + * @fdt: Base Device Tree blob + * @fdto: Device tree overlay blob + * @symbols_off: Node offset of the symbols node in the base device tree + * @path: Path to a node holding a phandle in the overlay + * @path_len: number of path characters to consider + * @name: Name of the property holding the phandle reference in the overlay + * @name_len: number of name characters to consider + * @poffset: Offset within the overlay property where the phandle is stored + * @label: Label of the node referenced by the phandle + * + * overlay_fixup_one_phandle() resolves an overlay phandle pointing to + * a node in the base device tree. + * + * This is part of the device tree overlay application process, when + * you want all the phandles in the overlay to point to the actual + * base dt nodes. + * + * returns: + * 0 on success + * Negative error code on failure + */ +static int overlay_fixup_one_phandle(void *fdt, void *fdto, + int symbols_off, + const char *path, uint32_t path_len, + const char *name, uint32_t name_len, + int poffset, const char *label) +{ + const char *symbol_path; + uint32_t phandle; + fdt32_t phandle_prop; + int symbol_off, fixup_off; + int prop_len; + + if (symbols_off < 0) + return symbols_off; + + symbol_path = fdt_getprop(fdt, symbols_off, label, + &prop_len); + if (!symbol_path) + return prop_len; + + symbol_off = fdt_path_offset(fdt, symbol_path); + if (symbol_off < 0) + return symbol_off; + + phandle = fdt_get_phandle(fdt, symbol_off); + if (!phandle) + return -FDT_ERR_NOTFOUND; + + fixup_off = fdt_path_offset_namelen(fdto, path, path_len); + if (fixup_off == -FDT_ERR_NOTFOUND) + return -FDT_ERR_BADOVERLAY; + if (fixup_off < 0) + return fixup_off; + + phandle_prop = cpu_to_fdt32(phandle); + return fdt_setprop_inplace_namelen_partial(fdto, fixup_off, + name, name_len, poffset, + &phandle_prop, + sizeof(phandle_prop)); +}; + +/** + * overlay_fixup_phandle - Set an overlay phandle to the base one + * @fdt: Base Device Tree blob + * @fdto: Device tree overlay blob + * @symbols_off: Node offset of the symbols node in the base device tree + * @property: Property offset in the overlay holding the list of fixups + * + * overlay_fixup_phandle() resolves all the overlay phandles pointed + * to in a __fixups__ property, and updates them to match the phandles + * in use in the base device tree. + * + * This is part of the device tree overlay application process, when + * you want all the phandles in the overlay to point to the actual + * base dt nodes. + * + * returns: + * 0 on success + * Negative error code on failure + */ +static int overlay_fixup_phandle(void *fdt, void *fdto, int symbols_off, + int property) +{ + const char *value; + const char *label; + int len; + + value = fdt_getprop_by_offset(fdto, property, + &label, &len); + if (!value) { + if (len == -FDT_ERR_NOTFOUND) + return -FDT_ERR_INTERNAL; + + return len; + } + + do { + const char *path, *name, *fixup_end; + const char *fixup_str = value; + uint32_t path_len, name_len; + uint32_t fixup_len; + char *sep, *endptr; + int poffset, ret; + + fixup_end = memchr(value, '\0', len); + if (!fixup_end) + return -FDT_ERR_BADOVERLAY; + fixup_len = fixup_end - fixup_str; + + len -= fixup_len + 1; + value += fixup_len + 1; + + path = fixup_str; + sep = memchr(fixup_str, ':', fixup_len); + if (!sep || *sep != ':') + return -FDT_ERR_BADOVERLAY; + + path_len = sep - path; + if (path_len == (fixup_len - 1)) + return -FDT_ERR_BADOVERLAY; + + fixup_len -= path_len + 1; + name = sep + 1; + sep = memchr(name, ':', fixup_len); + if (!sep || *sep != ':') + return -FDT_ERR_BADOVERLAY; + + name_len = sep - name; + if (!name_len) + return -FDT_ERR_BADOVERLAY; + + poffset = strtoul(sep + 1, &endptr, 10); + if ((*endptr != '\0') || (endptr <= (sep + 1))) + return -FDT_ERR_BADOVERLAY; + + ret = overlay_fixup_one_phandle(fdt, fdto, symbols_off, + path, path_len, name, name_len, + poffset, label); + if (ret) + return ret; + } while (len > 0); + + return 0; +} + +/** + * overlay_fixup_phandles - Resolve the overlay phandles to the base + * device tree + * @fdt: Base Device Tree blob + * @fdto: Device tree overlay blob + * + * overlay_fixup_phandles() resolves all the overlay phandles pointing + * to nodes in the base device tree. + * + * This is one of the steps of the device tree overlay application + * process, when you want all the phandles in the overlay to point to + * the actual base dt nodes. + * + * returns: + * 0 on success + * Negative error code on failure + */ +static int overlay_fixup_phandles(void *fdt, void *fdto) +{ + int fixups_off, symbols_off; + int property; + + /* We can have overlays without any fixups */ + fixups_off = fdt_path_offset(fdto, "/__fixups__"); + if (fixups_off == -FDT_ERR_NOTFOUND) + return 0; /* nothing to do */ + if (fixups_off < 0) + return fixups_off; + + /* And base DTs without symbols */ + symbols_off = fdt_path_offset(fdt, "/__symbols__"); + if ((symbols_off < 0 && (symbols_off != -FDT_ERR_NOTFOUND))) + return symbols_off; + + fdt_for_each_property_offset(property, fdto, fixups_off) { + int ret; + + ret = overlay_fixup_phandle(fdt, fdto, symbols_off, property); + if (ret) + return ret; + } + + return 0; +} + +/** + * overlay_apply_node - Merges a node into the base device tree + * @fdt: Base Device Tree blob + * @target: Node offset in the base device tree to apply the fragment to + * @fdto: Device tree overlay blob + * @node: Node offset in the overlay holding the changes to merge + * + * overlay_apply_node() merges a node into a target base device tree + * node pointed. + * + * This is part of the final step in the device tree overlay + * application process, when all the phandles have been adjusted and + * resolved and you just have to merge overlay into the base device + * tree. + * + * returns: + * 0 on success + * Negative error code on failure + */ +static int overlay_apply_node(void *fdt, int target, + void *fdto, int node) +{ + int property; + int subnode; + + fdt_for_each_property_offset(property, fdto, node) { + const char *name; + const void *prop; + int prop_len; + int ret; + + prop = fdt_getprop_by_offset(fdto, property, &name, + &prop_len); + if (prop_len == -FDT_ERR_NOTFOUND) + return -FDT_ERR_INTERNAL; + if (prop_len < 0) + return prop_len; + + ret = fdt_setprop(fdt, target, name, prop, prop_len); + if (ret) + return ret; + } + + fdt_for_each_subnode(subnode, fdto, node) { + const char *name = fdt_get_name(fdto, subnode, NULL); + int nnode; + int ret; + + nnode = fdt_add_subnode(fdt, target, name); + if (nnode == -FDT_ERR_EXISTS) { + nnode = fdt_subnode_offset(fdt, target, name); + if (nnode == -FDT_ERR_NOTFOUND) + return -FDT_ERR_INTERNAL; + } + + if (nnode < 0) + return nnode; + + ret = overlay_apply_node(fdt, nnode, fdto, subnode); + if (ret) + return ret; + } + + return 0; +} + +/** + * overlay_merge - Merge an overlay into its base device tree + * @fdt: Base Device Tree blob + * @fdto: Device tree overlay blob + * + * overlay_merge() merges an overlay into its base device tree. + * + * This is the next to last step in the device tree overlay application + * process, when all the phandles have been adjusted and resolved and + * you just have to merge overlay into the base device tree. + * + * returns: + * 0 on success + * Negative error code on failure + */ +static int overlay_merge(void *fdt, void *fdto) +{ + int fragment; + + fdt_for_each_subnode(fragment, fdto, 0) { + int overlay; + int target; + int ret; + + /* + * Each fragments will have an __overlay__ node. If + * they don't, it's not supposed to be merged + */ + overlay = fdt_subnode_offset(fdto, fragment, "__overlay__"); + if (overlay == -FDT_ERR_NOTFOUND) + continue; + + if (overlay < 0) + return overlay; + + target = overlay_get_target(fdt, fdto, fragment, NULL); + if (target < 0) + return target; + + ret = overlay_apply_node(fdt, target, fdto, overlay); + if (ret) + return ret; + } + + return 0; +} + +static int get_path_len(const void *fdt, int nodeoffset) +{ + int len = 0, namelen; + const char *name; + + FDT_CHECK_HEADER(fdt); + + for (;;) { + name = fdt_get_name(fdt, nodeoffset, &namelen); + if (!name) + return namelen; + + /* root? we're done */ + if (namelen == 0) + break; + + nodeoffset = fdt_parent_offset(fdt, nodeoffset); + if (nodeoffset < 0) + return nodeoffset; + len += namelen + 1; + } + + /* in case of root pretend it's "/" */ + if (len == 0) + len++; + return len; +} + +/** + * overlay_symbol_update - Update the symbols of base tree after a merge + * @fdt: Base Device Tree blob + * @fdto: Device tree overlay blob + * + * overlay_symbol_update() updates the symbols of the base tree with the + * symbols of the applied overlay + * + * This is the last step in the device tree overlay application + * process, allowing the reference of overlay symbols by subsequent + * overlay operations. + * + * returns: + * 0 on success + * Negative error code on failure + */ +static int overlay_symbol_update(void *fdt, void *fdto) +{ + int root_sym, ov_sym, prop, path_len, fragment, target; + int len, frag_name_len, ret, rel_path_len; + const char *s, *e; + const char *path; + const char *name; + const char *frag_name; + const char *rel_path; + const char *target_path; + char *buf; + void *p; + + ov_sym = fdt_subnode_offset(fdto, 0, "__symbols__"); + + /* if no overlay symbols exist no problem */ + if (ov_sym < 0) + return 0; + + root_sym = fdt_subnode_offset(fdt, 0, "__symbols__"); + + /* it no root symbols exist we should create them */ + if (root_sym == -FDT_ERR_NOTFOUND) + root_sym = fdt_add_subnode(fdt, 0, "__symbols__"); + + /* any error is fatal now */ + if (root_sym < 0) + return root_sym; + + /* iterate over each overlay symbol */ + fdt_for_each_property_offset(prop, fdto, ov_sym) { + path = fdt_getprop_by_offset(fdto, prop, &name, &path_len); + if (!path) + return path_len; + + /* verify it's a string property (terminated by a single \0) */ + if (path_len < 1 || memchr(path, '\0', path_len) != &path[path_len - 1]) + return -FDT_ERR_BADVALUE; + + /* keep end marker to avoid strlen() */ + e = path + path_len; + + /* format: //__overlay__/ */ + + if (*path != '/') + return -FDT_ERR_BADVALUE; + + /* get fragment name first */ + s = strchr(path + 1, '/'); + if (!s) + return -FDT_ERR_BADOVERLAY; + + frag_name = path + 1; + frag_name_len = s - path - 1; + + /* verify format; safe since "s" lies in \0 terminated prop */ + len = sizeof("/__overlay__/") - 1; + if ((e - s) < len || memcmp(s, "/__overlay__/", len)) + return -FDT_ERR_BADOVERLAY; + + rel_path = s + len; + rel_path_len = e - rel_path; + + /* find the fragment index in which the symbol lies */ + ret = fdt_subnode_offset_namelen(fdto, 0, frag_name, + frag_name_len); + /* not found? */ + if (ret < 0) + return -FDT_ERR_BADOVERLAY; + fragment = ret; + + /* an __overlay__ subnode must exist */ + ret = fdt_subnode_offset(fdto, fragment, "__overlay__"); + if (ret < 0) + return -FDT_ERR_BADOVERLAY; + + /* get the target of the fragment */ + ret = overlay_get_target(fdt, fdto, fragment, &target_path); + if (ret < 0) + return ret; + target = ret; + + /* if we have a target path use */ + if (!target_path) { + ret = get_path_len(fdt, target); + if (ret < 0) + return ret; + len = ret; + } else { + len = strlen(target_path); + } + + ret = fdt_setprop_placeholder(fdt, root_sym, name, + len + (len > 1) + rel_path_len + 1, &p); + if (ret < 0) + return ret; + + if (!target_path) { + /* again in case setprop_placeholder changed it */ + ret = overlay_get_target(fdt, fdto, fragment, &target_path); + if (ret < 0) + return ret; + target = ret; + } + + buf = p; + if (len > 1) { /* target is not root */ + if (!target_path) { + ret = fdt_get_path(fdt, target, buf, len + 1); + if (ret < 0) + return ret; + } else + memcpy(buf, target_path, len + 1); + + } else + len--; + + buf[len] = '/'; + memcpy(buf + len + 1, rel_path, rel_path_len); + buf[len + 1 + rel_path_len] = '\0'; + } + + return 0; +} + +int fdt_overlay_apply(void *fdt, void *fdto) +{ + uint32_t delta = fdt_get_max_phandle(fdt); + int ret; + + FDT_CHECK_HEADER(fdt); + FDT_CHECK_HEADER(fdto); + + ret = overlay_adjust_local_phandles(fdto, delta); + if (ret) + goto err; + + ret = overlay_update_local_references(fdto, delta); + if (ret) + goto err; + + ret = overlay_fixup_phandles(fdt, fdto); + if (ret) + goto err; + + ret = overlay_merge(fdt, fdto); + if (ret) + goto err; + + ret = overlay_symbol_update(fdt, fdto); + if (ret) + goto err; + + /* + * The overlay has been damaged, erase its magic. + */ + fdt_set_magic(fdto, ~0); + + return 0; + +err: + /* + * The overlay might have been damaged, erase its magic. + */ + fdt_set_magic(fdto, ~0); + + /* + * The base device tree might have been damaged, erase its + * magic. + */ + fdt_set_magic(fdt, ~0); + + return ret; +} From patchwork Tue Oct 17 01:11:42 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 115996 Delivered-To: patch@linaro.org Received: by 10.140.22.163 with SMTP id 32csp4295833qgn; Mon, 16 Oct 2017 18:12:38 -0700 (PDT) X-Google-Smtp-Source: AOwi7QCQHcuj2RzUWHrT5FLegqz9JL2fwXX86sUmGUe6dVfNTNycU+yqeu5xAkoCrocHh1UdvS7r X-Received: by 10.80.137.6 with SMTP id e6mr15094458ede.32.1508202758233; Mon, 16 Oct 2017 18:12:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1508202758; cv=none; d=google.com; s=arc-20160816; b=YcdRAsrECv7o6hUXSrLQan0wkyTZ4WwX48xYXKG/0JSHHnhO1rTMsLHKLypyw4F20p Dm/s31A3uFHZNRrm4hqsMrHcopFsg6dH1v5HVKr0OOI5Ks1Y13TKyiUgwbo40tFHpawl MknmqHMTuEQfk6ZPaSTOBYYFWtPHPGds0lQqO63QTxay5ejX4rX1hAxGJ6mNS7o/bM8+ hkDQp/7kIuhlDL9iduTi1CxC+qNhVYNo2U+iPYcVGQaAlgBXpJBjF6pl0Z+Rt9l4H3NS 3K8yWj7fHIo5JIXM+o2jPv5gYb7agh7RzjB+CtWlvS5JAVUiE8tivgLwylLwDmw+nXRX MQ7w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:cc:references:in-reply-to:message-id :date:to:from:dkim-signature:dkim-filter:arc-authentication-results; bh=Aq/UNJTKdc7c6b6YE7YUksdke/PxIKzQ9OPhp15Qyew=; b=nBtmumkCcz07GLHfB5kBsg2KWcb0C7cgu0FfjGFqctit9qwID5/gF6xP46PdhPOF3f 94DhqfdboZdStbLPwROLoWc8UGWvVe4s+iYebiAm6RWSjpQjOvgWSaMaznub79NcYqqx puvDiExfTsHvEY+rghs5CqZ3Xw4pP9jWDIoPWAFTDuK2AzWSBqWb68pFcKC9UMZvYL11 UW97gOolOHNKboFssvlHJ+79ubIecE7PP7pT9NKekmZz6z9EXLXhA6tt3oyJLHTWct1i Ui83yn3aB2P9urjtSPPBLmxiZso6gjbZsL4NtItXRkR6XYnHK9EeUbqFpCozCMt7V9dO mh7g== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@nifty.com header.s=dec2015msa header.b=lL1eOo8c; spf=pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de Return-Path: Received: from lists.denx.de (dione.denx.de. [81.169.180.215]) by mx.google.com with ESMTP id c60si6320190edd.191.2017.10.16.18.12.37; Mon, 16 Oct 2017 18:12:38 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) client-ip=81.169.180.215; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@nifty.com header.s=dec2015msa header.b=lL1eOo8c; spf=pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de Received: by lists.denx.de (Postfix, from userid 105) id C8FA3C21D6A; Tue, 17 Oct 2017 01:12:36 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 2EEDEC21C41; Tue, 17 Oct 2017 01:12:33 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 2F4A8C21C59; Tue, 17 Oct 2017 01:12:31 +0000 (UTC) Received: from conuserg-09.nifty.com (conuserg-09.nifty.com [210.131.2.76]) by lists.denx.de (Postfix) with ESMTPS id 0A252C21C40 for ; Tue, 17 Oct 2017 01:12:29 +0000 (UTC) Received: from pug.e01.socionext.com (p14092-ipngnfx01kyoto.kyoto.ocn.ne.jp [153.142.97.92]) (authenticated) by conuserg-09.nifty.com with ESMTP id v9H1Bnl4015917; Tue, 17 Oct 2017 10:11:51 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-09.nifty.com v9H1Bnl4015917 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1508202711; bh=zLaTgaDTmK3rQIdi5LK7KxaA4X2stOBD6mJX0M0/4YU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lL1eOo8cHPqpTkk5xDWZBMyBL5jtIaCQBdHcFkhJ5HY3MEAGsqTgOljFFoQbCJfmd yL466/a4XJ25iF3dEQiATF32jyGj0kQXGxLk12fqoaGD1ID8J7Z/SzEKH8IquLuKUf IXWtXmgaDz71zVSHHv+rUcUp+Vs7RgOdbo+PpA6MHyld86lt4Udce+mS1nGSYBd0Rz YBfzudfSfpxto7Vc4ZpfbLyvULiyE5J+clIvAr5Jk6i39dYHBJdBaH8tm+UTNu9dkO mJyIi+h2N5mH8NyN0mONM14fJAFJQiMEW9CJsD4TrKVj3hZwEQI34Z9VHdAn75cb0E KMdxWB+QMWiJA== X-Nifty-SrcIP: [153.142.97.92] From: Masahiro Yamada To: u-boot@lists.denx.de Date: Tue, 17 Oct 2017 10:11:42 +0900 Message-Id: <1508202703-23165-3-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1508202703-23165-1-git-send-email-yamada.masahiro@socionext.com> References: <1508202703-23165-1-git-send-email-yamada.masahiro@socionext.com> Cc: Tom Rini Subject: [U-Boot] [PATCH 2/3] pylibfdt: move pylibfdt to scripts/dtc/pylibfdt and refactor makefile X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" The pylibfdt is used by dtoc (and, indirectly by binman), but there is no reason why it must be generated in the tools/ directory. Recently, U-Boot switched over to the bundled DTC, and the directory structure under scripts/dtc/ now mirrors the upstream DTC project. So, scripts/dtc/pylibfdt is the best location. I also rewrote the Makefile in a cleaner Kbuild style. The scripts from the upstream have been moved as follows: lib/libfdt/pylibfdt/setup.py -> scripts/dtc/pylibfdt/setup.py lib/libfdt/pylibfdt/libfdt.i -> scripts/dtc/pylibfdt/libfdt.i_shipped The .i_shipped is coped to .i during building because the .i must be located in the objtree when we build it out of tree. Signed-off-by: Masahiro Yamada --- Makefile | 2 +- scripts/Makefile.spl | 4 +-- scripts/dtc/Makefile | 3 +++ scripts/dtc/pylibfdt/.gitignore | 4 +++ scripts/dtc/pylibfdt/Makefile | 30 ++++++++++++++++++++++ .../dtc/pylibfdt/libfdt.i_shipped | 0 {lib/libfdt => scripts/dtc}/pylibfdt/setup.py | 0 tools/.gitignore | 4 --- tools/Makefile | 30 ---------------------- tools/binman/binman.py | 2 +- 10 files changed, 41 insertions(+), 38 deletions(-) create mode 100644 scripts/dtc/pylibfdt/.gitignore create mode 100644 scripts/dtc/pylibfdt/Makefile rename lib/libfdt/pylibfdt/libfdt.i => scripts/dtc/pylibfdt/libfdt.i_shipped (100%) rename {lib/libfdt => scripts/dtc}/pylibfdt/setup.py (100%) diff --git a/Makefile b/Makefile index 888486b..0044503 100644 --- a/Makefile +++ b/Makefile @@ -1380,7 +1380,7 @@ $(timestamp_h): $(srctree)/Makefile FORCE $(call filechk,timestamp.h) checkbinman: tools - @if ! ( echo 'import libfdt' | ( PYTHONPATH=tools $(PYTHON) )); then \ + @if ! ( echo 'import libfdt' | ( PYTHONPATH=scripts/dtc/pylibfdt $(PYTHON) )); then \ echo >&2; \ echo >&2 '*** binman needs the Python libfdt library.'; \ echo >&2 '*** Either install it on your system, or try:'; \ diff --git a/scripts/Makefile.spl b/scripts/Makefile.spl index 49b27ac..065bb25 100644 --- a/scripts/Makefile.spl +++ b/scripts/Makefile.spl @@ -257,7 +257,7 @@ quiet_cmd_fdtgrep = FDTGREP $@ $(obj)/$(SPL_BIN).dtb: dts/dt.dtb $(objtree)/tools/fdtgrep FORCE $(call if_changed,fdtgrep) -pythonpath = PYTHONPATH=tools +pythonpath = PYTHONPATH=scripts/dtc/pylibfdt quiet_cmd_dtocc = DTOC C $@ cmd_dtocc = $(pythonpath) $(srctree)/tools/dtoc/dtoc -d $(obj)/$(SPL_BIN).dtb -o $@ platdata @@ -381,7 +381,7 @@ ifneq ($(cmd_files),) endif checkdtoc: tools - @if ! ( echo 'import libfdt' | ( PYTHONPATH=tools $(PYTHON) )); then \ + @if ! ( echo 'import libfdt' | ( PYTHONPATH=scripts/dtc/pylibfdt $(PYTHON) )); then \ echo '*** dtoc needs the Python libfdt library. Either '; \ echo '*** install it on your system, or try:'; \ echo '***'; \ diff --git a/scripts/dtc/Makefile b/scripts/dtc/Makefile index 2a48022..f4a16ed 100644 --- a/scripts/dtc/Makefile +++ b/scripts/dtc/Makefile @@ -29,3 +29,6 @@ $(obj)/dtc-lexer.lex.o: $(obj)/dtc-parser.tab.h # generated files need to be cleaned explicitly clean-files := dtc-lexer.lex.c dtc-parser.tab.c dtc-parser.tab.h + +# Added for U-Boot +subdir-y += pylibfdt diff --git a/scripts/dtc/pylibfdt/.gitignore b/scripts/dtc/pylibfdt/.gitignore new file mode 100644 index 0000000..033f23d --- /dev/null +++ b/scripts/dtc/pylibfdt/.gitignore @@ -0,0 +1,4 @@ +/_libfdt.so +/libfdt.py +/libfdt.pyc +/libfdt_wrap.c diff --git a/scripts/dtc/pylibfdt/Makefile b/scripts/dtc/pylibfdt/Makefile new file mode 100644 index 0000000..01d5e0f --- /dev/null +++ b/scripts/dtc/pylibfdt/Makefile @@ -0,0 +1,30 @@ +# Unfortunately setup.py below cannot handle srctree being ".." which it often +# is. It fails with an error like: +# Fatal error: can't create build/temp.linux-x86_64-2.7/../lib/libfdt/fdt.o: +# No such file or directory +# To fix this, use an absolute path. +LIBFDT_srcdir = $(abspath $(srctree)/$(src)/../libfdt) + +include $(LIBFDT_srcdir)/Makefile.libfdt + +# Unfortunately setup.py (or actually the Python distutil implementation) puts +# files into the same directory as the .i file. We cannot touch the source +# directory, so we "ship" .i file into the objtree. +PYLIBFDT_srcs = $(addprefix $(LIBFDT_srcdir)/,$(LIBFDT_SRCS)) \ + $(obj)/libfdt.i + +quiet_cmd_pymod = PYMOD $@ + cmd_pymod = unset CC; unset CROSS_COMPILE; unset CFLAGS;\ + LDFLAGS="$(HOSTLDFLAGS)" \ + VERSION="u-boot-$(UBOOTVERSION)" \ + CPPFLAGS="$(HOSTCFLAGS) -I$(LIBFDT_srcdir)" OBJDIR=$(obj) \ + SOURCES="$(PYLIBFDT_srcs)" \ + SWIG_OPTS="-I$(LIBFDT_srcdir) -I$(LIBFDT_srcdir)/.." \ + $(PYTHON) $< --quiet build_ext --inplace + +$(obj)/_libfdt.so: $(src)/setup.py $(PYLIBFDT_srcs) FORCE + $(call if_changed,pymod) + +always += _libfdt.so + +clean-files += libfdt.i _libfdt.so libfdt.py libfdt_wrap.c diff --git a/lib/libfdt/pylibfdt/libfdt.i b/scripts/dtc/pylibfdt/libfdt.i_shipped similarity index 100% rename from lib/libfdt/pylibfdt/libfdt.i rename to scripts/dtc/pylibfdt/libfdt.i_shipped diff --git a/lib/libfdt/pylibfdt/setup.py b/scripts/dtc/pylibfdt/setup.py similarity index 100% rename from lib/libfdt/pylibfdt/setup.py rename to scripts/dtc/pylibfdt/setup.py diff --git a/tools/.gitignore b/tools/.gitignore index 5293d44..6a487d2 100644 --- a/tools/.gitignore +++ b/tools/.gitignore @@ -1,4 +1,3 @@ -/_libfdt.so /atmel_pmecc_params /bin2header /bmp_logo @@ -17,9 +16,6 @@ /img2srec /kwboot /lib/ -/libfdt.py -/libfdt.pyc -/libfdt_wrap.c /mips-relocs /mkenvimage /mkexynosspl diff --git a/tools/Makefile b/tools/Makefile index c164774..38090a9 100644 --- a/tools/Makefile +++ b/tools/Makefile @@ -64,15 +64,6 @@ LIBFDT_CSRCS := fdt.c fdt_ro.c fdt_wip.c fdt_sw.c fdt_rw.c fdt_strerror.c \ fdt_empty_tree.c fdt_addresses.c fdt_overlay.c \ fdt_region.c -# Unfortunately setup.py below cannot handle srctree being ".." which it often -# is. It fails with an error like: -# Fatal error: can't create build/temp.linux-x86_64-2.7/../lib/libfdt/fdt.o: -# No such file or directory -# To fix this, use an absolute path. -libfdt_tree := $(shell readlink -f $(srctree)/lib/libfdt) - -LIBFDT_SRCS := $(addprefix $(libfdt_tree)/, $(LIBFDT_CSRCS)) -LIBFDT_SWIG := $(addprefix $(libfdt_tree)/, pylibfdt/libfdt.i) LIBFDT_OBJS := $(addprefix lib/libfdt/, $(patsubst %.c, %.o, $(LIBFDT_CSRCS))) RSA_OBJS-$(CONFIG_FIT_SIGNATURE) := $(addprefix lib/rsa/, \ @@ -124,23 +115,6 @@ mkimage-objs := $(dumpimage-mkimage-objs) mkimage.o fit_info-objs := $(dumpimage-mkimage-objs) fit_info.o fit_check_sign-objs := $(dumpimage-mkimage-objs) fit_check_sign.o -# Unfortunately setup.py (or actually the Python distutil implementation) -# puts files into the same directory as the .i file. We cannot touch the source -# directory, so we copy the .i file into the tools/ build subdirectory before -# calling setup. This directory is safe to write to. This ensures that we get -# all three files in $(obj)/tools: _libfdt.so, libfdt.py and libfdt_wrap.c -# The latter is a temporary file which we could actually remove. -tools/_libfdt.so: $(LIBFDT_SRCS) $(LIBFDT_SWIG) - $(Q)cp $(LIBFDT_SWIG) tools/. - $(Q)unset CC; \ - unset CROSS_COMPILE; \ - LDFLAGS="$(HOSTLDFLAGS)" CFLAGS= VERSION="u-boot-$(UBOOTVERSION)" \ - CPPFLAGS="$(_hostc_flags)" OBJDIR=tools \ - SOURCES="$(LIBFDT_SRCS) tools/libfdt.i" \ - SWIG_OPTS="-I$(srctree)/lib/libfdt -I$(srctree)/lib" \ - $(PYTHON) $(libfdt_tree)/pylibfdt/setup.py --quiet build_ext \ - --build-lib tools - ifneq ($(CONFIG_MX23)$(CONFIG_MX28),) # Add CONFIG_MXS into host CFLAGS, so we can check whether or not register # the mxsimage support within tools/mxsimage.c . @@ -232,10 +206,6 @@ clean-dirs := lib common always := $(hostprogs-y) -# Build a libfdt Python module if swig is available -# Use 'sudo apt-get install swig libpython-dev' to enable this -always += $(if $(shell which swig 2> /dev/null),_libfdt.so) - # Generated LCD/video logo LOGO_H = $(objtree)/include/bmp_logo.h LOGO_DATA_H = $(objtree)/include/bmp_logo_data.h diff --git a/tools/binman/binman.py b/tools/binman/binman.py index 09dc36a..e75a59d 100755 --- a/tools/binman/binman.py +++ b/tools/binman/binman.py @@ -21,7 +21,7 @@ for dirname in ['../patman', '../dtoc', '..']: sys.path.insert(0, os.path.join(our_path, dirname)) # Bring in the libfdt module -sys.path.insert(0, 'tools') +sys.path.insert(0, 'scripts/dtc/pylibfdt') # Also allow entry-type modules to be brought in from the etype directory. sys.path.insert(0, os.path.join(our_path, 'etype')) From patchwork Tue Oct 17 01:11:43 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 115999 Delivered-To: patch@linaro.org Received: by 10.140.22.163 with SMTP id 32csp4299158qgn; Mon, 16 Oct 2017 18:17:52 -0700 (PDT) X-Google-Smtp-Source: AOwi7QBapYqG9RzgMb62BKHp0/1nEMAmnk7br8AY6CJCRYPVYM9lSMv4wNZRuG4NEP0EdkPiWWJs X-Received: by 10.80.178.36 with SMTP id o33mr15345644edd.116.1508203072313; Mon, 16 Oct 2017 18:17:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1508203072; cv=none; d=google.com; s=arc-20160816; b=sc9bUL7IxczK43onW9aVwT8sqEZcF/HUQqsTH6wqBflq6NXZqfCZiRdDT3nQp4+7/F ruLQzwjAT6zLpYWtRwLAmwOXwnx4a9xXKjZXNJvBrmGp5Gh9Fcjs3kVR76zBlr1SVBDU ZLki2Mp0nyfhONqIKn/LY9ELQewyI7IVuBCnE6PFgMlxqMCukykxDn3bW5UnwSEZWHHC 3SCRTJ4LAwKTzEo6bROtQj6tFQAdd0Ix6QhUnIhPUMjypjU4rERZt3IfuoGsk027o2Of bU3JdFjXxkq05o6Aagdh5fdtwdmSvdbpVDS8okpVsURE3EjYS2KRE6RSgWIIHjsWVmUx JjuA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:cc:references:in-reply-to:message-id :date:to:from:dkim-signature:dkim-filter:arc-authentication-results; bh=6BzbSpOzAjsAXRRJu9IKLwDA7cjLFUTGXIIvbxsDhg4=; b=uK/sIKDTKQf+oxzlwTvCQR6wqi9Ks92TnNOCPRuv80HpVr55jPyMfQ0CdjPxos6Vr3 OK9d5STcP90BJyxbF5ihd+K3yBVBCzgc8nus475llaZlB1uTgMaZQzqrP9GeBuAZax5d ++fq6zQJM9qvNAsHe7PkSlpsn+Bmjt6bgmIuXH9LzojwbKA9TlOfEZgEc40+sM+2skWT bJS/BhHawLa5YPSJlchC5WfQfv8Xp5KpxP+3Rn64SOSLTKYG59Uu+J3dt/wS1ODtFl12 brG/Vg+50l+WPCT8niLG8+MGiYkZLq4C+f7ZGX9/5ISvDjkjAaFvYfuPrRBBxNiu4mnf 1H6w== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@nifty.com header.s=dec2015msa header.b=m3duwW29; spf=pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de Return-Path: Received: from lists.denx.de (dione.denx.de. [81.169.180.215]) by mx.google.com with ESMTP id c35si1867273ede.367.2017.10.16.18.17.52; Mon, 16 Oct 2017 18:17:52 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) client-ip=81.169.180.215; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@nifty.com header.s=dec2015msa header.b=m3duwW29; spf=pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de Received: by lists.denx.de (Postfix, from userid 105) id EA6B8C21C40; Tue, 17 Oct 2017 01:16:56 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id D78D8C21D95; Tue, 17 Oct 2017 01:13:11 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 76507C21C71; Tue, 17 Oct 2017 01:13:08 +0000 (UTC) Received: from conuserg-09.nifty.com (conuserg-09.nifty.com [210.131.2.76]) by lists.denx.de (Postfix) with ESMTPS id BC93AC21D80 for ; Tue, 17 Oct 2017 01:12:51 +0000 (UTC) Received: from pug.e01.socionext.com (p14092-ipngnfx01kyoto.kyoto.ocn.ne.jp [153.142.97.92]) (authenticated) by conuserg-09.nifty.com with ESMTP id v9H1Bnl5015917; Tue, 17 Oct 2017 10:11:51 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-09.nifty.com v9H1Bnl5015917 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1508202711; bh=SIGn3mrEEnRTV5Soly5Dt5bQLtLb42GZpiCox5faB9c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=m3duwW29S9x5/cLcP9DLa+gubqC6VGweTacn7j28VFS1p/3vjnab8ljinNOE230wl jbhQSaG6MeKkimGVfsWujbjxNFpedXMnCIcOY4IgZqTAtqm5DTBhqvYPc7t+Qzx3uh CF1Isn5ARucjo2E5zW/6+vJDBujLPocru3MMfOYOqqYkl6rBauSqHbDNKdQDguHOl7 SNk/W1ZLOy3nYzo61hI1jzznRygeQ7/vdz1WOXcLTKfx1ba7DdGWhbJdrBSU0b6by5 lWuVPFjhWSAtqb4J6fdSY/3758aUa3QhD+HLIP4v2zAz2/+rk+VH2rOsNCs6ypYTmW Xrnr6lw/Kt7nw== X-Nifty-SrcIP: [153.142.97.92] From: Masahiro Yamada To: u-boot@lists.denx.de Date: Tue, 17 Oct 2017 10:11:43 +0900 Message-Id: <1508202703-23165-4-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1508202703-23165-1-git-send-email-yamada.masahiro@socionext.com> References: <1508202703-23165-1-git-send-email-yamada.masahiro@socionext.com> Cc: Tom Rini Subject: [U-Boot] [PATCH 3/3] pylibfdt: compile pylibfdt only when dtoc/binman is necessary X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" Currently, pylibfdt is always compiled if swig is installed on your machine. It is really annoying because most of targets (excepts x86, sunxi, rockchip) do not use dtoc or binman. "checkbinman" and "checkdtoc" are wrong. It is odd that the final build stage checks if we have built necessary tools. If your platform depends on dtoc/binman, you must be able to build pylibfdt. If swig is not installed, it should fail immediately. I added PYLIBFDT, DTOC, BINMAN entries to Kconfig. They should be property select:ed by platforms that need them. Kbuild will descend into scripts/dtc/pylibfdt/ only when CONFIG_PYLIBFDT is enabled. Signed-off-by: Masahiro Yamada --- Makefile | 17 ++--------------- arch/arm/Kconfig | 1 + arch/x86/Kconfig | 1 + dts/Kconfig | 13 +++++++++++++ scripts/Makefile.spl | 15 ++------------- scripts/dtc/Makefile | 2 +- 6 files changed, 20 insertions(+), 29 deletions(-) diff --git a/Makefile b/Makefile index 0044503..627a639 100644 --- a/Makefile +++ b/Makefile @@ -1135,7 +1135,7 @@ cmd_ldr = $(LD) $(LDFLAGS_$(@F)) \ u-boot.rom: u-boot-x86-16bit.bin u-boot.bin \ $(if $(CONFIG_SPL_X86_16BIT_INIT),spl/u-boot-spl.bin) \ - $(if $(CONFIG_HAVE_REFCODE),refcode.bin) checkbinman FORCE + $(if $(CONFIG_HAVE_REFCODE),refcode.bin) FORCE $(call if_changed,binman) OBJCOPYFLAGS_u-boot-x86-16bit.bin := -O binary -j .start16 -j .resetvec @@ -1144,8 +1144,7 @@ u-boot-x86-16bit.bin: u-boot FORCE endif ifneq ($(CONFIG_ARCH_SUNXI),) -u-boot-sunxi-with-spl.bin: spl/sunxi-spl.bin u-boot.img u-boot.dtb \ - checkbinman FORCE +u-boot-sunxi-with-spl.bin: spl/sunxi-spl.bin u-boot.img u-boot.dtb FORCE $(call if_changed,binman) endif @@ -1379,18 +1378,6 @@ $(version_h): include/config/uboot.release FORCE $(timestamp_h): $(srctree)/Makefile FORCE $(call filechk,timestamp.h) -checkbinman: tools - @if ! ( echo 'import libfdt' | ( PYTHONPATH=scripts/dtc/pylibfdt $(PYTHON) )); then \ - echo >&2; \ - echo >&2 '*** binman needs the Python libfdt library.'; \ - echo >&2 '*** Either install it on your system, or try:'; \ - echo >&2 '***'; \ - echo >&2 '*** sudo apt-get install swig libpython-dev'; \ - echo >&2 '***'; \ - echo >&2 '*** to have U-Boot build its own version.'; \ - false; \ - fi - # --------------------------------------------------------------------------- quiet_cmd_cpp_lds = LDS $@ cmd_cpp_lds = $(CPP) -Wp,-MD,$(depfile) $(cpp_flags) $(LDPPFLAGS) \ diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig index 64e0ee4..d69141a 100644 --- a/arch/arm/Kconfig +++ b/arch/arm/Kconfig @@ -682,6 +682,7 @@ config ARCH_SOCFPGA config ARCH_SUNXI bool "Support sunxi (Allwinner) SoCs" + select BINMAN select CMD_GPIO select CMD_MMC if MMC select CMD_USB if DISTRO_DEFAULTS diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig index 38a6187..9d12a98 100644 --- a/arch/x86/Kconfig +++ b/arch/x86/Kconfig @@ -152,6 +152,7 @@ config SMM_TSEG_SIZE config X86_RESET_VECTOR bool default n + select BINMAN # The following options control where the 16-bit and 32-bit init lies # If SPL is enabled then it normally holds this init code, and U-Boot proper diff --git a/dts/Kconfig b/dts/Kconfig index daa757d..0cef225 100644 --- a/dts/Kconfig +++ b/dts/Kconfig @@ -8,6 +8,17 @@ config SUPPORT_OF_CONTROL config DTC bool +config PYLIBFDT + bool + +config DTOC + bool + select PYLIBFDT + +config BINMAN + bool + select DTOC + menu "Device Tree Control" depends on SUPPORT_OF_CONTROL @@ -231,6 +242,7 @@ config OF_SPL_REMOVE_PROPS config SPL_OF_PLATDATA bool "Generate platform data for use in SPL" depends on SPL_OF_CONTROL + select DTOC help For very constrained SPL environments the overhead of decoding device tree nodes and converting their contents into platform data @@ -252,6 +264,7 @@ config SPL_OF_PLATDATA config TPL_OF_PLATDATA bool "Generate platform data for use in TPL" depends on TPL_OF_CONTROL + select DTOC help For very constrained SPL environments the overhead of decoding device tree nodes and converting their contents into platform data diff --git a/scripts/Makefile.spl b/scripts/Makefile.spl index 065bb25..ca04476 100644 --- a/scripts/Makefile.spl +++ b/scripts/Makefile.spl @@ -276,10 +276,10 @@ PHONY += dts_dir dts_dir: $(shell [ -d $(obj)/dts ] || mkdir -p $(obj)/dts) -include/generated/dt-structs-gen.h: $(obj)/$(SPL_BIN).dtb dts_dir checkdtoc +include/generated/dt-structs-gen.h: $(obj)/$(SPL_BIN).dtb dts_dir FORCE $(call if_changed,dtoch) -$(obj)/dts/dt-platdata.c: $(obj)/$(SPL_BIN).dtb dts_dir checkdtoc +$(obj)/dts/dt-platdata.c: $(obj)/$(SPL_BIN).dtb dts_dir FORCE $(call if_changed,dtocc) ifdef CONFIG_SAMSUNG @@ -380,17 +380,6 @@ ifneq ($(cmd_files),) include $(cmd_files) endif -checkdtoc: tools - @if ! ( echo 'import libfdt' | ( PYTHONPATH=scripts/dtc/pylibfdt $(PYTHON) )); then \ - echo '*** dtoc needs the Python libfdt library. Either '; \ - echo '*** install it on your system, or try:'; \ - echo '***'; \ - echo '*** sudo apt-get install swig libpython-dev'; \ - echo '***'; \ - echo '*** to have U-Boot build its own version.'; \ - false; \ - fi - PHONY += FORCE FORCE: diff --git a/scripts/dtc/Makefile b/scripts/dtc/Makefile index f4a16ed..90ef2db 100644 --- a/scripts/dtc/Makefile +++ b/scripts/dtc/Makefile @@ -31,4 +31,4 @@ $(obj)/dtc-lexer.lex.o: $(obj)/dtc-parser.tab.h clean-files := dtc-lexer.lex.c dtc-parser.tab.c dtc-parser.tab.h # Added for U-Boot -subdir-y += pylibfdt +subdir-$(CONFIG_PYLIBFDT) += pylibfdt