From patchwork Mon Nov 27 07:06:06 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 119657 Delivered-To: patch@linaro.org Received: by 10.140.22.164 with SMTP id 33csp1384496qgn; Sun, 26 Nov 2017 23:06:54 -0800 (PST) X-Google-Smtp-Source: AGs4zMZG7mMB6VxQnVgvxhUse0iVmDWZtiWxp7rxbN9WBjMiCeJX2OVM8WsXmbwo2rvQ6QNt8uCa X-Received: by 10.80.177.250 with SMTP id n55mr52796515edd.30.1511766414166; Sun, 26 Nov 2017 23:06:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1511766414; cv=none; d=google.com; s=arc-20160816; b=vTado5e76dbi352pjzbBuPniSIsNLjiiRGYA+0Lrc82BixJeZPt26JsHIUkBxYTSJN aadO9npPJVnCmXGBCmEM5xN/fQXegysyb3S22Nx4BjNuUKXE+JIuuAUDo6dlERWcV/+u CCfOKTC1folEPrxzDlZu88kO3IpTHB7+hsXlXFjjnSXx7qoqj2Ukk5LErGkUX8qkETCO piGPfdCenPog+zczdlJS0CKwOTGddHpA3FGes36rROEXVSO2Jfbzx7/XYHxkJb+M0Jv+ Gr1TzngZKUkM1sKNNdZ4kFzMLPwqMeEmMf35GgHuYWHyC1/eOctuiD/WW0hW+t1b7tdc nZ2Q== 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:references:in-reply-to:message-id:date :to:from:dkim-signature:dkim-filter:arc-authentication-results; bh=bAaCsWtdjkzaozxqDeQtY+FC3QrpR/R3DZr2rSZAryw=; b=N4l91vqrfntBZj1SHGQyK7sw4ge5aNY1qIoXl5YDNfxYVPsk+eJXjAC4u59/PH6yKf ckfCYXm+sBe3lTQZSSpZWKJpwUEDET2YwsVoCqD/dfpNpvR3ScnqIJcVDURaHH3w9wS6 iF/3CS9BzqO4sCe/r0rZeo6lcSvPpM9X6LPPFo03mNXKH2Tq/sKXraK4EkS2MCdcJVu/ 3WCXl5IE/lhFuPL9KmFjrIVMPVC22C/LQhRbFkxUJ2J0T0QFBptcgbk/6m97l33vHmOl 27HaonQiRCW+jfz9qdml033IwZXLCilj4pVyNfzEjzlrvNLxcI3ePRZik/ZLdGE5S9+b jIzg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@nifty.com header.s=dec2015msa header.b=PcYLeTmo; 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 y45si1859884edc.82.2017.11.26.23.06.53; Sun, 26 Nov 2017 23:06:54 -0800 (PST) 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=PcYLeTmo; 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 6CBBFC21E5A; Mon, 27 Nov 2017 07:06:52 +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_BLOCKED, 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 2F4D1C21DB2; Mon, 27 Nov 2017 07:06:50 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 5F02BC21DB2; Mon, 27 Nov 2017 07:06:48 +0000 (UTC) Received: from conuserg-09.nifty.com (conuserg-09.nifty.com [210.131.2.76]) by lists.denx.de (Postfix) with ESMTPS id A0B4DC21D8C for ; Mon, 27 Nov 2017 07:06:46 +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 vAR76GXu021781; Mon, 27 Nov 2017 16:06:18 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-09.nifty.com vAR76GXu021781 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1511766378; bh=kopUNqhoJ1aK2FK4pgeX2yEw+ZOpURBXfguzI4spS3I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PcYLeTmoglHoURBDDYRBnOr9kh+OBGypeF2DYRGGwZSL5fOqCyDY//BjBKPndiywy rfLmrRN5nMlHq8JTnbL4MDF2X0ptJgCVlJY/mP6+2u7/cH1l7SC7VcqFvlMC4ZM5sQ gQkISN4qYLBHseSSHjWGsaLcMi3+UCSIPTd0i8vid8gHtOLwKr47LY7+rMvWozd1qJ 0a0Fl875LxAUVtfGO8sJc00jxFaaBzBe2SWvJWyKcrU2Wp9wriisKeDAkJK3jzz6FG 8n9z3W7DfMH0LWiye7ETyzdUfgFy4oVPsu/6XF/34vYmazbTMF/Ct0CkNKZLKuz0jh 5akhY66JvwKLA== X-Nifty-SrcIP: [153.142.97.92] From: Masahiro Yamada To: u-boot@lists.denx.de Date: Mon, 27 Nov 2017 16:06:06 +0900 Message-Id: <1511766367-20787-2-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1511766367-20787-1-git-send-email-yamada.masahiro@socionext.com> References: <1511766367-20787-1-git-send-email-yamada.masahiro@socionext.com> Subject: [U-Boot] [PATCH 1/2] libfdt: move fdt_find_regions() to fdt_region.c from fdt_wip.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" All the other fdt_*_region() functions are located in fdt_region.c, while only fdt_find_regions() was added to fdt_wip.c, strangely. Move it to the suitable place. Signed-off-by: Masahiro Yamada Reviewed-by: Simon Glass --- lib/libfdt/fdt_region.c | 129 ++++++++++++++++++++++++++++++++++++++++++++++++ lib/libfdt/fdt_wip.c | 129 ------------------------------------------------ 2 files changed, 129 insertions(+), 129 deletions(-) diff --git a/lib/libfdt/fdt_region.c b/lib/libfdt/fdt_region.c index 63099f1..5bfc4da 100644 --- a/lib/libfdt/fdt_region.c +++ b/lib/libfdt/fdt_region.c @@ -16,6 +16,135 @@ #include "libfdt_internal.h" +#define FDT_MAX_DEPTH 32 + +static int str_in_list(const char *str, char * const list[], int count) +{ + int i; + + for (i = 0; i < count; i++) + if (!strcmp(list[i], str)) + return 1; + + return 0; +} + +int fdt_find_regions(const void *fdt, char * const inc[], int inc_count, + char * const exc_prop[], int exc_prop_count, + struct fdt_region region[], int max_regions, + char *path, int path_len, int add_string_tab) +{ + int stack[FDT_MAX_DEPTH] = { 0 }; + char *end; + int nextoffset = 0; + uint32_t tag; + int count = 0; + int start = -1; + int depth = -1; + int want = 0; + int base = fdt_off_dt_struct(fdt); + + end = path; + *end = '\0'; + do { + const struct fdt_property *prop; + const char *name; + const char *str; + int include = 0; + int stop_at = 0; + int offset; + int len; + + offset = nextoffset; + tag = fdt_next_tag(fdt, offset, &nextoffset); + stop_at = nextoffset; + + switch (tag) { + case FDT_PROP: + include = want >= 2; + stop_at = offset; + prop = fdt_get_property_by_offset(fdt, offset, NULL); + str = fdt_string(fdt, fdt32_to_cpu(prop->nameoff)); + if (str_in_list(str, exc_prop, exc_prop_count)) + include = 0; + break; + + case FDT_NOP: + include = want >= 2; + stop_at = offset; + break; + + case FDT_BEGIN_NODE: + depth++; + if (depth == FDT_MAX_DEPTH) + return -FDT_ERR_BADSTRUCTURE; + name = fdt_get_name(fdt, offset, &len); + if (end - path + 2 + len >= path_len) + return -FDT_ERR_NOSPACE; + if (end != path + 1) + *end++ = '/'; + strcpy(end, name); + end += len; + stack[depth] = want; + if (want == 1) + stop_at = offset; + if (str_in_list(path, inc, inc_count)) + want = 2; + else if (want) + want--; + else + stop_at = offset; + include = want; + break; + + case FDT_END_NODE: + include = want; + want = stack[depth--]; + while (end > path && *--end != '/') + ; + *end = '\0'; + break; + + case FDT_END: + include = 1; + break; + } + + if (include && start == -1) { + /* Should we merge with previous? */ + if (count && count <= max_regions && + offset == region[count - 1].offset + + region[count - 1].size - base) + start = region[--count].offset - base; + else + start = offset; + } + + if (!include && start != -1) { + if (count < max_regions) { + region[count].offset = base + start; + region[count].size = stop_at - start; + } + count++; + start = -1; + } + } while (tag != FDT_END); + + if (nextoffset != fdt_size_dt_struct(fdt)) + return -FDT_ERR_BADLAYOUT; + + /* Add a region for the END tag and the string table */ + if (count < max_regions) { + region[count].offset = base + start; + region[count].size = nextoffset - start; + if (add_string_tab) + region[count].size += fdt_size_dt_strings(fdt); + } + count++; + + return count; +} + /** * fdt_add_region() - Add a new region to our list * @info: State information diff --git a/lib/libfdt/fdt_wip.c b/lib/libfdt/fdt_wip.c index 01adad0..7274c81 100644 --- a/lib/libfdt/fdt_wip.c +++ b/lib/libfdt/fdt_wip.c @@ -96,132 +96,3 @@ int fdt_nop_node(void *fdt, int nodeoffset) endoffset - nodeoffset); return 0; } - -#define FDT_MAX_DEPTH 32 - -static int str_in_list(const char *str, char * const list[], int count) -{ - int i; - - for (i = 0; i < count; i++) - if (!strcmp(list[i], str)) - return 1; - - return 0; -} - -int fdt_find_regions(const void *fdt, char * const inc[], int inc_count, - char * const exc_prop[], int exc_prop_count, - struct fdt_region region[], int max_regions, - char *path, int path_len, int add_string_tab) -{ - int stack[FDT_MAX_DEPTH] = { 0 }; - char *end; - int nextoffset = 0; - uint32_t tag; - int count = 0; - int start = -1; - int depth = -1; - int want = 0; - int base = fdt_off_dt_struct(fdt); - - end = path; - *end = '\0'; - do { - const struct fdt_property *prop; - const char *name; - const char *str; - int include = 0; - int stop_at = 0; - int offset; - int len; - - offset = nextoffset; - tag = fdt_next_tag(fdt, offset, &nextoffset); - stop_at = nextoffset; - - switch (tag) { - case FDT_PROP: - include = want >= 2; - stop_at = offset; - prop = fdt_get_property_by_offset(fdt, offset, NULL); - str = fdt_string(fdt, fdt32_to_cpu(prop->nameoff)); - if (str_in_list(str, exc_prop, exc_prop_count)) - include = 0; - break; - - case FDT_NOP: - include = want >= 2; - stop_at = offset; - break; - - case FDT_BEGIN_NODE: - depth++; - if (depth == FDT_MAX_DEPTH) - return -FDT_ERR_BADSTRUCTURE; - name = fdt_get_name(fdt, offset, &len); - if (end - path + 2 + len >= path_len) - return -FDT_ERR_NOSPACE; - if (end != path + 1) - *end++ = '/'; - strcpy(end, name); - end += len; - stack[depth] = want; - if (want == 1) - stop_at = offset; - if (str_in_list(path, inc, inc_count)) - want = 2; - else if (want) - want--; - else - stop_at = offset; - include = want; - break; - - case FDT_END_NODE: - include = want; - want = stack[depth--]; - while (end > path && *--end != '/') - ; - *end = '\0'; - break; - - case FDT_END: - include = 1; - break; - } - - if (include && start == -1) { - /* Should we merge with previous? */ - if (count && count <= max_regions && - offset == region[count - 1].offset + - region[count - 1].size - base) - start = region[--count].offset - base; - else - start = offset; - } - - if (!include && start != -1) { - if (count < max_regions) { - region[count].offset = base + start; - region[count].size = stop_at - start; - } - count++; - start = -1; - } - } while (tag != FDT_END); - - if (nextoffset != fdt_size_dt_struct(fdt)) - return -FDT_ERR_BADLAYOUT; - - /* Add a region for the END tag and the string table */ - if (count < max_regions) { - region[count].offset = base + start; - region[count].size = nextoffset - start; - if (add_string_tab) - region[count].size += fdt_size_dt_strings(fdt); - } - count++; - - return count; -}