From patchwork Thu Apr 21 05:43:17 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 66302 Delivered-To: patch@linaro.org Received: by 10.140.93.198 with SMTP id d64csp2857133qge; Wed, 20 Apr 2016 23:11:55 -0700 (PDT) X-Received: by 10.28.41.70 with SMTP id p67mr25227214wmp.70.1461219114480; Wed, 20 Apr 2016 23:11:54 -0700 (PDT) Return-Path: Received: from theia.denx.de (theia.denx.de. [85.214.87.163]) by mx.google.com with ESMTP id b203si1753978wme.30.2016.04.20.23.11.54; Wed, 20 Apr 2016 23:11:54 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 85.214.87.163 as permitted sender) client-ip=85.214.87.163; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@nifty.com; spf=pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 85.214.87.163 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 16450B3BC6; Thu, 21 Apr 2016 07:54:33 +0200 (CEST) Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id wJrRfiJqFvfQ; Thu, 21 Apr 2016 07:54:32 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 88D7BA7A23; Thu, 21 Apr 2016 07:51:04 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 4492FA785F for ; Thu, 21 Apr 2016 07:44:18 +0200 (CEST) Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id BlVJxK81Kwdy for ; Thu, 21 Apr 2016 07:44:18 +0200 (CEST) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from conuserg-07.nifty.com (conuserg-07.nifty.com [210.131.2.74]) by theia.denx.de (Postfix) with ESMTPS id 0396AA785B for ; Thu, 21 Apr 2016 07:42:41 +0200 (CEST) Received: from beagle.diag.org (p14092-ipngnfx01kyoto.kyoto.ocn.ne.jp [153.142.97.92]) (authenticated) by conuserg-07.nifty.com with ESMTP id u3L5gQcK010871; Thu, 21 Apr 2016 14:42:34 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-07.nifty.com u3L5gQcK010871 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1461217354; bh=/wVlNWuzjbrwi7oqw+hqrTvAFMzwvIfj/CDQtT/LSE8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Et8KUYsDv7GzUVUEz//GGc/t6atYS5okyHrQEha4tq8rE7p3ECNoiXLbVrzbLL3LK dV6ELnTlHkTj5dU67PGZNFKmW3kJmn5QjDiSCYnC2Rq+zrt4mjDYcCcAWcvG9POoHt GbvW7zT3Mpkov3/qRklNCz+HAPVxeIomlEprIgU4WFcHZXleC28+hSjaaxBmsvsRHR XY6/xU3c5DhFRQp6UF4YUZn4+wnXDjaWXRdaw1EBXh5LsiGxHp5VGkkvMdMmNtLaea MQ9qClgFnyRtGrLUCOd3yL9NWp2OilFq/mNLDl2oU37QTV+b7pfEvsyTnBJez28DCc iHKS2/lbKe98Q== X-Nifty-SrcIP: [153.142.97.92] From: Masahiro Yamada To: u-boot@lists.denx.de Date: Thu, 21 Apr 2016 14:43:17 +0900 Message-Id: <1461217402-25430-9-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1461217402-25430-1-git-send-email-yamada.masahiro@socionext.com> References: <1461217402-25430-1-git-send-email-yamada.masahiro@socionext.com> Subject: [U-Boot] [PATCH v4 08/13] ARM: uniphier: rework uniphier_set_fdt_file() X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.15 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 current table look-up for the DTB file name turned out bothersome in terms of maintainability; I ended up adding a new entry every time a new board is supported. There is a common pattern between the DT compatible string and the corresponding file name; drop the vendor prefix "socionext," and prefix it with "uniphier-" and suffix it with ".dtb". Signed-off-by: Masahiro Yamada --- Changes in v4: - Newly added Changes in v3: None Changes in v2: None arch/arm/mach-uniphier/board_late_init.c | 62 ++++++++++++++++---------------- 1 file changed, 31 insertions(+), 31 deletions(-) -- 1.9.1 _______________________________________________ U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot diff --git a/arch/arm/mach-uniphier/board_late_init.c b/arch/arm/mach-uniphier/board_late_init.c index 591b972..845f047 100644 --- a/arch/arm/mach-uniphier/board_late_init.c +++ b/arch/arm/mach-uniphier/board_late_init.c @@ -28,38 +28,37 @@ static void nand_denali_wp_disable(void) #endif } -struct uniphier_fdt_file { - const char *compatible; - const char *file_name; -}; - -static const struct uniphier_fdt_file uniphier_fdt_files[] = { - { "socionext,ph1-ld4-ref", "uniphier-ph1-ld4-ref.dtb", }, - { "socionext,ph1-ld6b-ref", "uniphier-ph1-ld6b-ref.dtb", }, - { "socionext,ph1-ld10-ref", "uniphier-ph1-ld10-ref.dtb", }, - { "socionext,ph1-pro4-ace", "uniphier-ph1-pro4-ace.dtb", }, - { "socionext,ph1-pro4-ref", "uniphier-ph1-pro4-ref.dtb", }, - { "socionext,ph1-pro4-sanji", "uniphier-ph1-pro4-sanji.dtb", }, - { "socionext,ph1-pro5-4kbox", "uniphier-ph1-pro5-4kbox.dtb", }, - { "socionext,ph1-sld3-ref", "uniphier-ph1-sld3-ref.dtb", }, - { "socionext,ph1-sld8-ref", "uniphier-ph1-sld8-ref.dtb", }, - { "socionext,proxstream2-gentil", "uniphier-proxstream2-gentil.dtb", }, - { "socionext,proxstream2-vodka", "uniphier-proxstream2-vodka.dtb", }, -}; - -static void uniphier_set_fdt_file(void) +#define VENDOR_PREFIX "socionext," +#define DTB_FILE_PREFIX "uniphier-" + +static int uniphier_set_fdt_file(void) { DECLARE_GLOBAL_DATA_PTR; - int i; - - /* lookup DTB file name based on the compatible string */ - for (i = 0; i < ARRAY_SIZE(uniphier_fdt_files); i++) { - if (!fdt_node_check_compatible(gd->fdt_blob, 0, - uniphier_fdt_files[i].compatible)) { - setenv("fdt_file", uniphier_fdt_files[i].file_name); - return; - } - } + const char *compat; + char dtb_name[256]; + int buf_len = 256; + int ret; + + ret = fdt_get_string(gd->fdt_blob, 0, "compatible", &compat); + if (ret) + return -EINVAL; + + if (strncmp(compat, VENDOR_PREFIX, strlen(VENDOR_PREFIX))) + return -EINVAL; + + compat += strlen(VENDOR_PREFIX); + + strncat(dtb_name, DTB_FILE_PREFIX, buf_len); + buf_len -= strlen(DTB_FILE_PREFIX); + + strncat(dtb_name, compat, buf_len); + buf_len -= strlen(compat); + + strncat(dtb_name, ".dtb", buf_len); + + setenv("fdt_file", dtb_name); + + return 0; } int board_late_init(void) @@ -89,7 +88,8 @@ int board_late_init(void) break; } - uniphier_set_fdt_file(); + if (uniphier_set_fdt_file()) + printf("fdt_file environment was not set correctly\n"); return 0; }