From patchwork Tue Jan 31 00:02:56 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Boyd X-Patchwork-Id: 92919 Delivered-To: patch@linaro.org Received: by 10.140.20.99 with SMTP id 90csp1691716qgi; Mon, 30 Jan 2017 16:04:10 -0800 (PST) X-Received: by 10.84.218.71 with SMTP id f7mr35133787plm.59.1485821050534; Mon, 30 Jan 2017 16:04:10 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c85si14149002pfk.224.2017.01.30.16.04.09; Mon, 30 Jan 2017 16:04:10 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932139AbdAaAEI (ORCPT + 25 others); Mon, 30 Jan 2017 19:04:08 -0500 Received: from mail-pf0-f174.google.com ([209.85.192.174]:35684 "EHLO mail-pf0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753609AbdAaAEC (ORCPT ); Mon, 30 Jan 2017 19:04:02 -0500 Received: by mail-pf0-f174.google.com with SMTP id f144so95454737pfa.2 for ; Mon, 30 Jan 2017 16:03:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=a54kGSGkX/JNXTnjX7QWNVkCS43S5/KEk1WdRN9OVU0=; b=DaR6gVzfpgE922iDZ01DyBIOHOKhLpQjnwfcS5IzLh+qpVY7IT6i9Bvm5RKjgtFDrJ VCKBLfJQeXEDyUY3MqOG6eNA5TEurI/JOH6Jdlr2unRezpDQDj6q06vhUyKg9y1cSeF/ sbhhWeLdR6pqPn2rqEPE2lODkeUHYu8HbqBJs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=a54kGSGkX/JNXTnjX7QWNVkCS43S5/KEk1WdRN9OVU0=; b=LnA10gffUbi5Rv7STPc4kjdJCsWEed+ur2dxEK1a0EHRUmaX8toWLZkLemL1o30i/8 QTZB8w60lsmDkQNgco4tMXuSu9DvpxPHmMdS9HIg5U4ivJ5/Si+CBN8CBySP36o9EGtJ d8EjWWOZICUj5ZvTSHNJT7AjfXk9KM0SgKbUFzmPT6/01tRIiP6ayvE8O8AFvxZAq9ay YFkOBM9cs/5x2fplx4jSsJCyPxXg+ImXV9Fn2Fp/2Zz0S6cRWwBxvagzvMBZoN9YQFki yRGkWw6X/3BfP7+AvCwnAgohAP89K97R/TbFqjAau2kCnehALTuk52ANxhM9s1K32PiY vtwg== X-Gm-Message-State: AIkVDXLbp6WPb9cWVmkvFd+nUqMQDIEj3CETywHKe2nZ8OOkFuRveVp7RcR0q/OdwYamnbBm X-Received: by 10.98.13.18 with SMTP id v18mr26196072pfi.62.1485820982917; Mon, 30 Jan 2017 16:03:02 -0800 (PST) Received: from localhost.localdomain (i-global254.qualcomm.com. [199.106.103.254]) by smtp.gmail.com with ESMTPSA id e189sm35301942pfg.64.2017.01.30.16.03.01 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 30 Jan 2017 16:03:02 -0800 (PST) From: Stephen Boyd To: David Gibson Cc: devicetree-compiler@vger.kernel.org, Frank Rowand , Pantelis Antoniou , Rob Herring , Mark Brown , Grant Likely , Mark Rutland , mporter@konsulko.com, Koen Kooi , Guenter Roeck , marex@denx.de, Wolfram Sang , devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-i2c@vger.kernel.org Subject: [RFC/PATCH 1/4] Start moving overlay handling from parser into dtc core Date: Mon, 30 Jan 2017 16:02:56 -0800 Message-Id: <20170131000259.28576-2-stephen.boyd@linaro.org> X-Mailer: git-send-email 2.10.0.297.gf6727b0 In-Reply-To: <20170131000259.28576-1-stephen.boyd@linaro.org> References: <20170131000259.28576-1-stephen.boyd@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: David Gibson To make includes more useful, dtc for some time has allowed "overlays" in dts files, defining the tree in several chunks which are merged together. Recent Linux kernels make use of dynamic DT overlays which have similar mechanics, but are implemented at DT load time with specially formatted dtbs. In order to provide better support for these dynamic overlays in dtc, we want to explicitly manipulate overlays, rather than just fold them together during the parse phase. This patch is a first step towards this. Signed-off-by: David Gibson [stephen.boyd@linaro.org: Have resolve_overlays() loop with a cursor] Signed-off-by: Stephen Boyd --- dtc-parser.y | 63 +++++++++++++++++++++++++++++------------------------------- dtc.c | 13 +++++++++++++ dtc.h | 18 +++++++++++++++-- flattree.c | 2 +- fstree.c | 2 +- livetree.c | 40 ++++++++++++++++++++++++++++++++++++-- 6 files changed, 99 insertions(+), 39 deletions(-) -- 2.10.0.297.gf6727b0 diff --git a/dtc-parser.y b/dtc-parser.y index ca3f5003427c..3d2ce372c286 100644 --- a/dtc-parser.y +++ b/dtc-parser.y @@ -51,6 +51,8 @@ extern bool treesource_error; struct property *proplist; struct node *node; struct node *nodelist; + struct overlay *overlay; + struct overlay *overlaylist; struct reserve_info *re; uint64_t integer; unsigned int flags; @@ -83,11 +85,14 @@ extern bool treesource_error; %type propdef %type proplist -%type devicetree %type nodedef %type subnode %type subnodes +%type basetree +%type overlay +%type overlays + %type integer_prim %type integer_unary %type integer_mul @@ -106,9 +111,9 @@ extern bool treesource_error; %% sourcefile: - headers memreserves devicetree + headers memreserves basetree overlays { - parser_output = build_dt_info($1, $2, $3, + parser_output = build_dt_info($1, $2, $3, $4, guess_boot_cpuid($3)); } ; @@ -157,48 +162,40 @@ memreserve: } ; -devicetree: +basetree: '/' nodedef { $$ = name_node($2, ""); } - | devicetree '/' nodedef + ; + +overlay: basetree { - $$ = merge_nodes($1, $3); + $$ = build_overlay("/", $1); } - - | devicetree DT_LABEL DT_REF nodedef + | DT_REF nodedef { - struct node *target = get_node_by_ref($1, $3); - - if (target) { - add_label(&target->labels, $2); - merge_nodes(target, $4); - } else - ERROR(&@3, "Label or path %s not found", $3); - $$ = $1; + $$ = build_overlay($1, $2); } - | devicetree DT_REF nodedef + | DT_DEL_NODE DT_REF ';' { - struct node *target = get_node_by_ref($1, $2); - - if (target) - merge_nodes(target, $3); - else - ERROR(&@2, "Label or path %s not found", $2); - $$ = $1; + $$ = build_overlay($2, NULL); } - | devicetree DT_DEL_NODE DT_REF ';' + | DT_LABEL overlay { - struct node *target = get_node_by_ref($1, $3); - - if (target) - delete_node(target); - else - ERROR(&@3, "Label or path %s not found", $3); - + add_label(&$2->dt->labels, $1); + $$ = $2; + } + ; - $$ = $1; +overlays: + /* empty */ + { + $$ = NULL; + } + | overlay overlays + { + $$ = chain_overlay($1, $2); } ; diff --git a/dtc.c b/dtc.c index a4edf4c7aebf..91e4c18b891e 100644 --- a/dtc.c +++ b/dtc.c @@ -58,6 +58,16 @@ static void fill_fullpaths(struct node *tree, const char *prefix) fill_fullpaths(child, tree->fullpath); } +static void resolve_overlays(struct dt_info *dti) +{ + struct overlay *o = dti->overlays; + + while (o) { + apply_overlay(dti->dt, o); + o = o->next; + } +} + /* Usage related data. */ #define FDT_VERSION(version) _FDT_VERSION(version) #define _FDT_VERSION(version) #version @@ -317,7 +327,10 @@ int main(int argc, char *argv[]) if (cmdline_boot_cpuid != -1) dti->boot_cpuid_phys = cmdline_boot_cpuid; + resolve_overlays(dti); + fill_fullpaths(dti->dt, ""); + process_checks(force, dti); /* on a plugin, generate by default */ diff --git a/dtc.h b/dtc.h index c6f125c68ba8..c4eb6421eabf 100644 --- a/dtc.h +++ b/dtc.h @@ -164,6 +164,12 @@ struct node { struct label *labels; }; +struct overlay { + char *target; + struct node *dt; + struct overlay *next; +}; + #define for_each_label_withdel(l0, l) \ for ((l) = (l0); (l); (l) = (l)->next) @@ -208,6 +214,10 @@ void delete_node(struct node *node); void append_to_property(struct node *node, char *name, const void *data, int len); +struct overlay *build_overlay(char *target, struct node *dt); +struct overlay *chain_overlay(struct overlay *first, struct overlay *list); +void apply_overlay(struct node *base, struct overlay *overlay); + const char *get_unitname(struct node *node); struct property *get_property(struct node *node, const char *propname); cell_t propval_cell(struct property *prop); @@ -245,7 +255,9 @@ struct dt_info { unsigned int dtsflags; struct reserve_info *reservelist; uint32_t boot_cpuid_phys; - struct node *dt; /* the device tree */ + + struct node *dt; + struct overlay *overlays; }; /* DTS version flags definitions */ @@ -254,7 +266,9 @@ struct dt_info { struct dt_info *build_dt_info(unsigned int dtsflags, struct reserve_info *reservelist, - struct node *tree, uint32_t boot_cpuid_phys); + struct node *basetree, + struct overlay *overlays, + uint32_t boot_cpuid_phys); void sort_tree(struct dt_info *dti); void generate_label_tree(struct dt_info *dti, char *name, bool allocph); void generate_fixups_tree(struct dt_info *dti, char *name); diff --git a/flattree.c b/flattree.c index ebac548b3fa8..13e4a4a46b6b 100644 --- a/flattree.c +++ b/flattree.c @@ -942,5 +942,5 @@ struct dt_info *dt_from_blob(const char *fname) fclose(f); - return build_dt_info(DTSF_V1, reservelist, tree, boot_cpuid_phys); + return build_dt_info(DTSF_V1, reservelist, tree, NULL, boot_cpuid_phys); } diff --git a/fstree.c b/fstree.c index ae7d06c3c492..08ee93d26157 100644 --- a/fstree.c +++ b/fstree.c @@ -86,5 +86,5 @@ struct dt_info *dt_from_fs(const char *dirname) tree = read_fstree(dirname); tree = name_node(tree, ""); - return build_dt_info(DTSF_V1, NULL, tree, guess_boot_cpuid(tree)); + return build_dt_info(DTSF_V1, NULL, tree, NULL, guess_boot_cpuid(tree)); } diff --git a/livetree.c b/livetree.c index afa2f67b142a..dd51223d1e61 100644 --- a/livetree.c +++ b/livetree.c @@ -313,6 +313,39 @@ void append_to_property(struct node *node, } } +struct overlay *build_overlay(char *target, struct node *dt) +{ + struct overlay *new = xmalloc(sizeof(*new)); + + new->target = target; + new->dt = dt; + new->next = NULL; + return new; +} + +struct overlay *chain_overlay(struct overlay *first, struct overlay *list) +{ + assert(first->next == NULL); + + first->next = list; + return first; +} + +void apply_overlay(struct node *base, struct overlay *overlay) +{ + struct node *target = get_node_by_ref(base, overlay->target); + + if (!target) + die("Couldn't find label or path %s for overlay\n", + overlay->target); + + if (!overlay->dt) + /* Deletion */ + delete_node(target); + else + merge_nodes(target, overlay->dt); +} + struct reserve_info *build_reserve_entry(uint64_t address, uint64_t size) { struct reserve_info *new = xmalloc(sizeof(*new)); @@ -354,15 +387,18 @@ struct reserve_info *add_reserve_entry(struct reserve_info *list, struct dt_info *build_dt_info(unsigned int dtsflags, struct reserve_info *reservelist, - struct node *tree, uint32_t boot_cpuid_phys) + struct node *basetree, + struct overlay *overlays, + uint32_t boot_cpuid_phys) { struct dt_info *dti; dti = xmalloc(sizeof(*dti)); dti->dtsflags = dtsflags; dti->reservelist = reservelist; - dti->dt = tree; dti->boot_cpuid_phys = boot_cpuid_phys; + dti->dt = basetree; + dti->overlays = overlays; return dti; }