From patchwork Fri May 19 02:08:53 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 764332 X-Patchwork-Delegate: sjg@chromium.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 3wTWts3pWdz9s4s for ; Fri, 19 May 2017 12:18:29 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.b="oFDGQSxT"; dkim-atps=neutral Received: by lists.denx.de (Postfix, from userid 105) id 29BCFC2224A; Fri, 19 May 2017 02:18:24 +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=RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, 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 9EAD8C220D7; Fri, 19 May 2017 02:10:47 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 8F165C21FF4; Fri, 19 May 2017 02:10:18 +0000 (UTC) Received: from mail-oi0-f50.google.com (mail-oi0-f50.google.com [209.85.218.50]) by lists.denx.de (Postfix) with ESMTPS id 36D06C21FCA for ; Fri, 19 May 2017 02:10:18 +0000 (UTC) Received: by mail-oi0-f50.google.com with SMTP id b204so76686308oii.1 for ; Thu, 18 May 2017 19:10:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=FqE6vZ7K6fngh2Wc8eXZB+lTsS65M0BYwby3ATIq22U=; b=oFDGQSxT/He40nibXBDbmEeoM7+5Fdo6rE00kDCMMHQ+VdhN+NlQc8ztDVU0ht2tKR n4BQQWf6/1clDoSe6wKaBElEjFCXJ9uMlp6GC7/PnGIZBuwyrNVA1IX6/9sGVgQCrrLw dsr9eW85R66gR7N/cEIVTpIBFiQB7Ul9Mcn5YSOjgrHIrkk017/XaT+FtyANGzjpcz+v vE/ABcyIkQxZQ7a53uumTAiDlqWlTQddBl73Urnx0wKN94dh+hJ48MCrRGiUOA5PcfOM hpArYu3MAvWUQzqTpqEhB2Mf0UQmKnpDM9gRvsF1WBMYuAhXOp4u1i4GwccAk2MAZ7mf gwKw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=FqE6vZ7K6fngh2Wc8eXZB+lTsS65M0BYwby3ATIq22U=; b=Lk9JlPAGinQCYeP4auys+MhQVBUckzVAtVy82nEOD6SzerJoOaylmbSqkGFl5LxPIX lXeUFnOQO/vwaZbOcpUA/UA3j0uU7hbqVPotf+hCrbCaxGNWo3KHEzJ1LcBmh9Jj728Y sLWr2OWPmm4W/dcJ65mpgZfEOHW+861nP42NJ6DI02DjmH7sNAbXREnqCyeC+9L7xg43 kGd9M9boV014VWK/dhyehC5tEuQ2XCl4jFCigCJC5n19qzUYUXxcRrYvSu9LOQqZuBhl 3wD7L8vSK79shVtPppmbtizERixwb9eiIOxoYeHZ8WTMOJkoOh9CNGcC+KZW7TPHpa+2 VSXA== X-Gm-Message-State: AODbwcDGLQAVJUvufk2+Dav8u9rRxd2vgeaCQiSLQ6Np+0ztUxg+VRV0 92L98XNXYlBPTzQ+ X-Received: by 10.157.73.145 with SMTP id g17mr3705615otf.22.1495159816889; Thu, 18 May 2017 19:10:16 -0700 (PDT) Received: from kaki.bld.corp.google.com ([100.100.184.96]) by smtp.gmail.com with ESMTPSA id j184sm3459955oif.20.2017.05.18.19.10.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 18 May 2017 19:10:16 -0700 (PDT) Received: by kaki.bld.corp.google.com (Postfix, from userid 121222) id ACC8840550; Thu, 18 May 2017 20:10:15 -0600 (MDT) From: Simon Glass To: U-Boot Mailing List Date: Thu, 18 May 2017 20:08:53 -0600 Message-Id: <20170519021002.1098-4-sjg@chromium.org> X-Mailer: git-send-email 2.13.0.303.g4ebf302169-goog In-Reply-To: <20170519021002.1098-1-sjg@chromium.org> References: <20170519021002.1098-1-sjg@chromium.org> Cc: Tom Rini , Stephen Warren Subject: [U-Boot] [PATCH v3 03/72] dm: core: Add livetree definitions 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" Add a Kconfig option to enable a live device tree, built at run time from the flat tree. Also add structure definitions and a root node. Signed-off-by: Simon Glass Signed-off-by: Simon Glass --- Changes in v3: None Changes in v2: None dts/Kconfig | 11 ++++ include/asm-generic/global_data.h | 3 ++ include/dm/of.h | 106 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 120 insertions(+) create mode 100644 include/dm/of.h diff --git a/dts/Kconfig b/dts/Kconfig index 9a0622154a..b3009af03f 100644 --- a/dts/Kconfig +++ b/dts/Kconfig @@ -32,6 +32,17 @@ config SPL_OF_CONTROL which is not enough to support device tree. Enable this option to allow such boards to be supported by U-Boot SPL. +config OF_LIVE + bool "Enable use of a live tree" + depends on OF_CONTROL + help + Normally U-Boot uses a flat device tree which saves space and + avoids the need to unpack the tree before use. However a flat + tree does not support modifcation from within U-Boot since it + can invalidate driver-model device tree offsets. This option + enables a live tree which is available after relocation, + and can be adjusted as needed. + choice prompt "Provider of DTB for DT control" depends on OF_CONTROL diff --git a/include/asm-generic/global_data.h b/include/asm-generic/global_data.h index 51838b5ead..e6f905110e 100644 --- a/include/asm-generic/global_data.h +++ b/include/asm-generic/global_data.h @@ -72,6 +72,9 @@ typedef struct global_data { const void *fdt_blob; /* Our device tree, NULL if none */ void *new_fdt; /* Relocated FDT */ unsigned long fdt_size; /* Space reserved for relocated FDT */ +#ifdef CONFIG_OF_LIVE + struct device_node *of_root; +#endif struct jt_funcs *jt; /* jump table */ char env_buf[32]; /* buffer for getenv() before reloc. */ #ifdef CONFIG_TRACE diff --git a/include/dm/of.h b/include/dm/of.h new file mode 100644 index 0000000000..6b5afab1c1 --- /dev/null +++ b/include/dm/of.h @@ -0,0 +1,106 @@ +/* + * Copyright (c) 2017 Google, Inc + * Written by Simon Glass + * + * SPDX-License-Identifier: GPL-2.0+ + */ + +#ifndef _DM_OF_H +#define _DM_OF_H + +#include +#include + +/* integer value within a device tree property which references another node */ +typedef u32 phandle; + +/** + * struct property: Device tree property + * + * @name: Property name + * @length: Length of property in bytes + * @value: Pointer to property value + * @next: Pointer to next property, or NULL if none + */ +struct property { + char *name; + int length; + void *value; + struct property *next; +}; + +/** + * struct device_node: Device tree node + * + * @name: Node name + * @type: Node type (value of device_type property) or "" if none + * @phandle: Phandle value of this none, or 0 if none + * @full_name: Full path to node, e.g. "/bus@1/spi@1100" + * @properties: Pointer to head of list of properties, or NULL if none + * @parent: Pointer to parent node, or NULL if this is the root node + * @child: Pointer to head of child node list, or NULL if no children + * @sibling: Pointer to the next sibling node, or NULL if this is the last + */ +struct device_node { + const char *name; + const char *type; + phandle phandle; + const char *full_name; + + struct property *properties; + struct device_node *parent; + struct device_node *child; + struct device_node *sibling; +}; + +#define OF_MAX_PHANDLE_ARGS 16 + +/** + * struct of_phandle_args - structure to hold phandle and arguments + * + * This is used when decoding a phandle in a device tree property. Typically + * these look like this: + * + * wibble { + * phandle = <5>; + * }; + * + * ... + * some-prop = <&wibble 1 2 3> + * + * Here &node is the phandle of the node 'wibble', i.e. 5. There are three + * arguments: 1, 2, 3. + * + * So when decoding the phandle in some-prop, np will point to wibble, + * args_count will be 3 and the three arguments will be in args. + * + * @np: Node that the phandle refers to + * @args_count: Number of arguments + * @args: Argument values + */ +struct of_phandle_args { + struct device_node *np; + int args_count; + uint32_t args[OF_MAX_PHANDLE_ARGS]; +}; + +DECLARE_GLOBAL_DATA_PTR; + +/** + * of_live_active() - check if livetree is active + * + * @returns true if livetree is active, false it not + */ +#ifdef CONFIG_OF_LIVE +static inline bool of_live_active(void) +{ + return gd->of_root != NULL; +} +#else +static inline bool of_live_active(void) +{ + return false; +} +#endif + +#endif