From patchwork Sun Apr 2 18:26:44 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 746216 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 3vx3c823d1z9s78 for ; Mon, 3 Apr 2017 04:27:03 +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="b+LlhMaI"; dkim-atps=neutral Received: by lists.denx.de (Postfix, from userid 105) id ABE3BC21C5F; Sun, 2 Apr 2017 18:26: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=RCVD_IN_MSPIKE_H2, 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 E1CAFC21C48; Sun, 2 Apr 2017 18:26:53 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id BF5FEC21C48; Sun, 2 Apr 2017 18:26:52 +0000 (UTC) Received: from mail-oi0-f48.google.com (mail-oi0-f48.google.com [209.85.218.48]) by lists.denx.de (Postfix) with ESMTPS id 702D6C21C28 for ; Sun, 2 Apr 2017 18:26:51 +0000 (UTC) Received: by mail-oi0-f48.google.com with SMTP id o67so105263733oib.1 for ; Sun, 02 Apr 2017 11:26:51 -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; bh=tzWrvioiUIKHSDHn7F7pmmVm+5kOUIUdG1MwgdLnrBA=; b=b+LlhMaIEKPnWhYeQvYr3sygyXD16uMgNaVzEpyJUt5uFQSh6O9/BwDJTMBI7tJEci g7Or2rAWeBPc3cS/ZM8VCM71R/TFM3Xazeh8gntLDbfV8C1pwr0MBlNNZgAAdJE6wGBH 5n+Q/oVVl4JPoA34o636R7+jm5SdFRJTflnzRmP0x+SuVBCLNM/1gor7jR4B5YAp98tI QQ7UiDICEVGVdWM2p75eDIW/KsDKtzGNWoop5Q11N1dowQieb/+zmtqzOUbKaiRwpoO8 7vx9s+nI10LCH3Yu76YhzBw1cKNV3b5kMryZV+pI8FyikD965rKX3n7i7YD/hK/Xst4K WI3g== 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; bh=tzWrvioiUIKHSDHn7F7pmmVm+5kOUIUdG1MwgdLnrBA=; b=Xql6xrgbOcDW5oPEzaTw0RLB/tslF1zGwGmMof2Y6bn5QkmU+hF/PLEBONV1m2opTG LELtO7awawAOl4TVQdZ6zWow3O/mla7qvSwzmMGrIywPjgabUP9PterzPmY/WevP9pY+ hLsz6RgoA/1fLgGZ7QRpSgsvgS29+JfWTNJxjDbfuEv/agDqWL1NtfSnT5WFu5anpeM8 O7t2m6E38evlFfYO/ysA8TA1dlemHsj/f+SSae8JXBGt9IOEdHfey66yuaLK2rqx9oMx fWxhDj05fNDTadCD/meC40Cs6YxBMEFj7gwKScpH9/v0wRMuz1NradDH3WPZNqmKXfYX ORQg== X-Gm-Message-State: AFeK/H3vqVzF3oCVLQ6pH5ZFLk3HE/KM4ZuCS1YHtVSxTMXbS73OjBxAADbDTfcVZV5jQWQN X-Received: by 10.202.0.215 with SMTP id 206mr7024619oia.111.1491157609872; Sun, 02 Apr 2017 11:26:49 -0700 (PDT) Received: from kaki.bld.corp.google.com ([100.100.184.96]) by smtp.gmail.com with ESMTPSA id u144sm5673861oie.24.2017.04.02.11.26.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 02 Apr 2017 11:26:49 -0700 (PDT) Received: by kaki.bld.corp.google.com (Postfix, from userid 121222) id 17F6F401B7; Sun, 2 Apr 2017 12:26:47 -0600 (MDT) From: Simon Glass To: U-Boot Mailing List Date: Sun, 2 Apr 2017 12:26:44 -0600 Message-Id: <20170402182644.15239-1-sjg@chromium.org> X-Mailer: git-send-email 2.12.2.564.g063fe858b8-goog Subject: [U-Boot] [PATCH] fdtgrep: Copy with the /aliases node being last 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" With skeleton.dtsi being dropped it is more likely that the /aliases node will be last in the device tree. Update fdtgrep to handle this. Signed-off-by: Simon Glass Tested-by: Masahiro Yamada --- lib/libfdt/fdt_region.c | 40 +++++++++++++++++++++++++++++++++++----- tools/fdtgrep.c | 3 --- 2 files changed, 35 insertions(+), 8 deletions(-) diff --git a/lib/libfdt/fdt_region.c b/lib/libfdt/fdt_region.c index d2ce4c1c53..8b8a547555 100644 --- a/lib/libfdt/fdt_region.c +++ b/lib/libfdt/fdt_region.c @@ -63,6 +63,30 @@ static int region_list_contains_offset(struct fdt_region_state *info, return 0; } +/** + * fdt_add_alias_regions() - Add regions covering the aliases that we want + * + * The /aliases node is not automatically included by fdtgrep unless the + * command-line arguments cause to be included (or not excluded). However + * aliases are special in that we generally want to include those which + * reference a node that fdtgrep includes. + * + * In fact we want to include only aliases for those nodes still included in + * the fdt, and drop the other aliases since they point to nodes that will not + * be present. + * + * This function scans the aliases and adds regions for those which we want + * to keep. + * + * @fdt: Device tree to scan + * @region: List of regions + * @count: Number of regions in the list so far (i.e. starting point for this + * function) + * @max_regions: Maximum number of regions in @region list + * @info: Place to put the region state + * @return number of regions after processing, or -FDT_ERR_NOSPACE if we did + * not have enough room in the regions table for the regions we wanted to add. + */ int fdt_add_alias_regions(const void *fdt, struct fdt_region *region, int count, int max_regions, struct fdt_region_state *info) { @@ -74,11 +98,17 @@ int fdt_add_alias_regions(const void *fdt, struct fdt_region *region, int count, if (node < 0) return -FDT_ERR_NOTFOUND; - /* The aliases node must come before the others */ + /* + * Find the next node so that we know where the /aliases node ends. We + * need special handling if /aliases is the last node. + */ node_end = fdt_next_subnode(fdt, node); - if (node_end <= 0) - return -FDT_ERR_BADLAYOUT; - node_end -= sizeof(fdt32_t); + if (node_end == -FDT_ERR_NOTFOUND) + /* Move back to the FDT_END_NODE tag of '/' */ + node_end = fdt_size_dt_struct(fdt) - sizeof(fdt32_t) * 2; + else if (node_end < 0) /* other error */ + return node_end; + node_end -= sizeof(fdt32_t); /* Move to FDT_END_NODE tag of /aliases */ did_alias_header = 0; info->region = region; @@ -109,7 +139,7 @@ int fdt_add_alias_regions(const void *fdt, struct fdt_region *region, int count, fdt_add_region(info, base + offset, next - offset); } - /* Add the 'end' tag */ + /* Add the FDT_END_NODE tag */ if (did_alias_header) fdt_add_region(info, base + node_end, sizeof(fdt32_t)); diff --git a/tools/fdtgrep.c b/tools/fdtgrep.c index b9078273c9..e373c43e36 100644 --- a/tools/fdtgrep.c +++ b/tools/fdtgrep.c @@ -810,9 +810,6 @@ static int do_fdtgrep(struct display_info *disp, const char *filename) disp->flags); if (count < 0) { report_error("fdt_find_regions", count); - if (count == -FDT_ERR_BADLAYOUT) - fprintf(stderr, - "/aliases node must come before all other nodes\n"); return -1; } if (count <= max_regions)