From patchwork Wed Nov 14 15:17:28 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heiko Schocher X-Patchwork-Id: 997788 X-Patchwork-Delegate: sjg@chromium.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=denx.de Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 42w7Qy0ksFz9s9m for ; Thu, 15 Nov 2018 02:17:42 +1100 (AEDT) Received: by lists.denx.de (Postfix, from userid 105) id 3341BC224BB; Wed, 14 Nov 2018 15:17:36 +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_H3, RCVD_IN_MSPIKE_WL 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 3441AC2209D; Wed, 14 Nov 2018 15:17:34 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 98D85C2209D; Wed, 14 Nov 2018 15:17:32 +0000 (UTC) Received: from mail-out.m-online.net (mail-out.m-online.net [212.18.0.9]) by lists.denx.de (Postfix) with ESMTPS id 483F0C2206B for ; Wed, 14 Nov 2018 15:17:32 +0000 (UTC) Received: from frontend01.mail.m-online.net (unknown [192.168.8.182]) by mail-out.m-online.net (Postfix) with ESMTP id 42w7Qh0WDNz1qymj; Wed, 14 Nov 2018 16:17:32 +0100 (CET) Received: from localhost (dynscan1.mnet-online.de [192.168.6.70]) by mail.m-online.net (Postfix) with ESMTP id 42w7Qg6w3Dz1qrp4; Wed, 14 Nov 2018 16:17:31 +0100 (CET) X-Virus-Scanned: amavisd-new at mnet-online.de Received: from mail.mnet-online.de ([192.168.8.182]) by localhost (dynscan1.mail.m-online.net [192.168.6.70]) (amavisd-new, port 10024) with ESMTP id mEqnGukdjJFi; Wed, 14 Nov 2018 16:17:29 +0100 (CET) X-Auth-Info: POyz3PiFNmSMqiwYHX4Lg21tHvVxUVEqPIO/WwdYMkM= Received: from [192.168.1.106] (87.97.17.174.pool.invitel.hu [87.97.17.174]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.mnet-online.de (Postfix) with ESMTPSA; Wed, 14 Nov 2018 16:17:29 +0100 (CET) To: "u-boot@lists.denx.de" From: Heiko Schocher Message-ID: <36acf385-c925-c907-ffb8-8ec4ba8f15be@denx.de> Date: Wed, 14 Nov 2018 16:17:28 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.5.2 MIME-Version: 1.0 Content-Language: en-US Subject: [U-Boot] [PATCH v2] cmd, fdt: add subcommand "get" to fdt header 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: , Reply-To: hs@denx.de Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" store fdt header member with name in U-Boot Environment variable with name . for example to get the total length of the fdt and store it in filesize, call: fdt header get filesize totalsize For membernames look into fdt header definition at scripts/dtc/libfdt/libfdt.h Signed-off-by: Heiko Schocher --- Changes in v2: - add obviously missing "static const char *" cmd/fdt.c | 40 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/cmd/fdt.c b/cmd/fdt.c index 8a19a3fdbf..501aa7c887 100644 --- a/cmd/fdt.c +++ b/cmd/fdt.c @@ -73,6 +73,40 @@ static int fdt_value_env_set(const void *nodep, int len, const char *var) return 0; } +static const char * const fdt_member_table[] = { + "magic", + "totalsize", + "off_dt_struct", + "off_dt_strings", + "off_mem_rsvmap", + "version", + "last_comp_version", + "boot_cpuid_phys", + "size_dt_strings", + "size_dt_struct", +}; + +static int fdt_get_header_value(int argc, char * const argv[]) +{ + fdt32_t *fdtp = (fdt32_t *)working_fdt; + ulong val; + int i; + + if (argv[2][0] != 'g') + return CMD_RET_FAILURE; + + for (i = 0; i < ARRAY_SIZE(fdt_member_table); i++) { + if (strcmp(fdt_member_table[i], argv[4]) == 0) { + val = fdt32_to_cpu(*fdtp); + env_set_hex(argv[3], val); + return CMD_RET_SUCCESS; + } + fdtp++; + } + + return CMD_RET_FAILURE; +} + /* * Flattened Device Tree command, see the help for parameter definitions. */ @@ -491,6 +525,9 @@ static int do_fdt(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) * Display header info */ } else if (argv[1][0] == 'h') { + if (argc == 5) + return fdt_get_header_value(argc, argv); + u32 version = fdt_version(working_fdt); printf("magic:\t\t\t0x%x\n", fdt_magic(working_fdt)); printf("totalsize:\t\t0x%x (%d)\n", fdt_totalsize(working_fdt), @@ -1090,7 +1127,8 @@ static char fdt_help_text[] = "fdt set [] - Set [to ]\n" "fdt mknode - Create a new node after \n" "fdt rm [] - Delete the node or \n" - "fdt header - Display header info\n" + "fdt header [get ] - Display header info\n" + " get - get header member and store it in \n" "fdt bootcpu - Set boot cpuid\n" "fdt memory - Add/Update memory node\n" "fdt rsvmem print - Show current mem reserves\n"