From patchwork Fri Nov 29 19:29:16 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eugeniu Rosca X-Patchwork-Id: 1202576 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) 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=de.adit-jv.com Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 47Pl365vcbz9sPJ for ; Sat, 30 Nov 2019 06:30:26 +1100 (AEDT) Received: by lists.denx.de (Postfix, from userid 105) id 53643C21DED; Fri, 29 Nov 2019 19:30:20 +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=none 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 D0C6BC21DFD; Fri, 29 Nov 2019 19:30:19 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 20953C22066; Fri, 29 Nov 2019 19:30:15 +0000 (UTC) Received: from smtp1.de.adit-jv.com (smtp1.de.adit-jv.com [93.241.18.167]) by lists.denx.de (Postfix) with ESMTPS id E9124C22113 for ; Fri, 29 Nov 2019 19:30:14 +0000 (UTC) Received: from localhost (smtp1.de.adit-jv.com [127.0.0.1]) by smtp1.de.adit-jv.com (Postfix) with ESMTP id CDCBA3C0579; Fri, 29 Nov 2019 20:30:14 +0100 (CET) Received: from smtp1.de.adit-jv.com ([127.0.0.1]) by localhost (smtp1.de.adit-jv.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 5B0MT1TKXKAf; Fri, 29 Nov 2019 20:30:08 +0100 (CET) Received: from HI2EXCH01.adit-jv.com (hi2exch01.adit-jv.com [10.72.92.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by smtp1.de.adit-jv.com (Postfix) with ESMTPS id E6A723C00BE; Fri, 29 Nov 2019 20:30:08 +0100 (CET) Received: from vmlxhi-102.adit-jv.com (10.72.93.184) by HI2EXCH01.adit-jv.com (10.72.92.24) with Microsoft SMTP Server (TLS) id 14.3.468.0; Fri, 29 Nov 2019 20:30:08 +0100 From: Eugeniu Rosca To: , Tom Rini , Simon Glass , Sam Protsenko , Igor Opaniuk Date: Fri, 29 Nov 2019 20:29:16 +0100 Message-ID: <20191129192919.27715-2-erosca@de.adit-jv.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191129192919.27715-1-erosca@de.adit-jv.com> References: <20191129192919.27715-1-erosca@de.adit-jv.com> MIME-Version: 1.0 X-Originating-IP: [10.72.93.184] Cc: Roman Stratiienko , Eugeniu Rosca , Eugeniu Rosca Subject: [U-Boot] [PATCH 1/4] cmd: dtimg: Report invalid index argument 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: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" Being user-friendly is paramount to make any product likeable and easy to use. Hence, instead of [1], print [2]. [1] dtimg start 0x48000000 not-a-number myvar Error: Wrong index [2] dtimg start 0x48000000 not-a-number myvar Error: Wrong index 'not-a-number' Signed-off-by: Eugeniu Rosca Reviewed-by: Sam Protsenko --- cmd/dtimg.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/dtimg.c b/cmd/dtimg.c index 6c5d53cc6808..2317c859953d 100644 --- a/cmd/dtimg.c +++ b/cmd/dtimg.c @@ -63,7 +63,7 @@ static int dtimg_get_fdt(int argc, char * const argv[], enum cmd_dtimg_info cmd) index = simple_strtoul(argv[2], &endp, 0); if (*endp != '\0') { - printf("Error: Wrong index\n"); + printf("Error: Wrong index '%s'\n", argv[2]); return CMD_RET_FAILURE; } From patchwork Fri Nov 29 19:29:17 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eugeniu Rosca X-Patchwork-Id: 1202577 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) 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=de.adit-jv.com Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 47Pl3b1hSqz9sPJ for ; Sat, 30 Nov 2019 06:30:51 +1100 (AEDT) Received: by lists.denx.de (Postfix, from userid 105) id CD4B2C21FEF; Fri, 29 Nov 2019 19:30:48 +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=none 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 497AEC2209C; Fri, 29 Nov 2019 19:30:46 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 4A08DC220FA; Fri, 29 Nov 2019 19:30:35 +0000 (UTC) Received: from smtp1.de.adit-jv.com (smtp1.de.adit-jv.com [93.241.18.167]) by lists.denx.de (Postfix) with ESMTPS id BE08DC22117 for ; Fri, 29 Nov 2019 19:30:35 +0000 (UTC) Received: from localhost (smtp1.de.adit-jv.com [127.0.0.1]) by smtp1.de.adit-jv.com (Postfix) with ESMTP id A31D03C0579; Fri, 29 Nov 2019 20:30:35 +0100 (CET) Received: from smtp1.de.adit-jv.com ([127.0.0.1]) by localhost (smtp1.de.adit-jv.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id QRO0y4pzSijL; Fri, 29 Nov 2019 20:30:30 +0100 (CET) Received: from HI2EXCH01.adit-jv.com (hi2exch01.adit-jv.com [10.72.92.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by smtp1.de.adit-jv.com (Postfix) with ESMTPS id BEA323C00BE; Fri, 29 Nov 2019 20:30:30 +0100 (CET) Received: from vmlxhi-102.adit-jv.com (10.72.93.184) by HI2EXCH01.adit-jv.com (10.72.92.24) with Microsoft SMTP Server (TLS) id 14.3.468.0; Fri, 29 Nov 2019 20:30:30 +0100 From: Eugeniu Rosca To: , Tom Rini , Simon Glass , Sam Protsenko , Igor Opaniuk Date: Fri, 29 Nov 2019 20:29:17 +0100 Message-ID: <20191129192919.27715-3-erosca@de.adit-jv.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191129192919.27715-1-erosca@de.adit-jv.com> References: <20191129192919.27715-1-erosca@de.adit-jv.com> MIME-Version: 1.0 X-Originating-IP: [10.72.93.184] Cc: Roman Stratiienko , Eugeniu Rosca , Eugeniu Rosca Subject: [U-Boot] [PATCH 2/4] cmd: dtimg: Merge duplicated prints 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: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" Getting DTB/DTBO header address happens twice (in do_dtimg_dump and in dtimg_get_fdt) with duplicating below error messages: - Error: Wrong image address - Error: DT image header is incorrect Reduce the duplication and improve the error message by appending the faulty address value: - Error: Wrong image address '0x48000000z' Signed-off-by: Eugeniu Rosca Reviewed-by: Sam Protsenko --- cmd/dtimg.c | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/cmd/dtimg.c b/cmd/dtimg.c index 2317c859953d..5989081b0c14 100644 --- a/cmd/dtimg.c +++ b/cmd/dtimg.c @@ -13,18 +13,13 @@ enum cmd_dtimg_info { CMD_DTIMG_SIZE, }; -static int do_dtimg_dump(cmd_tbl_t *cmdtp, int flag, int argc, - char * const argv[]) +static int dtimg_get_argv_addr(char * const str, ulong *hdr_addrp) { char *endp; - ulong hdr_addr; + ulong hdr_addr = simple_strtoul(str, &endp, 16); - if (argc != 2) - return CMD_RET_USAGE; - - hdr_addr = simple_strtoul(argv[1], &endp, 16); if (*endp != '\0') { - printf("Error: Wrong image address\n"); + printf("Error: Wrong image address '%s'\n", str); return CMD_RET_FAILURE; } @@ -32,6 +27,21 @@ static int do_dtimg_dump(cmd_tbl_t *cmdtp, int flag, int argc, printf("Error: DT image header is incorrect\n"); return CMD_RET_FAILURE; } + *hdr_addrp = hdr_addr; + + return CMD_RET_SUCCESS; +} + +static int do_dtimg_dump(cmd_tbl_t *cmdtp, int flag, int argc, + char * const argv[]) +{ + ulong hdr_addr; + + if (argc != 2) + return CMD_RET_USAGE; + + if (dtimg_get_argv_addr(argv[1], &hdr_addr) != CMD_RET_SUCCESS) + return CMD_RET_FAILURE; android_dt_print_contents(hdr_addr); @@ -50,16 +60,8 @@ static int dtimg_get_fdt(int argc, char * const argv[], enum cmd_dtimg_info cmd) if (argc != 4) return CMD_RET_USAGE; - hdr_addr = simple_strtoul(argv[1], &endp, 16); - if (*endp != '\0') { - printf("Error: Wrong image address\n"); + if (dtimg_get_argv_addr(argv[1], &hdr_addr) != CMD_RET_SUCCESS) return CMD_RET_FAILURE; - } - - if (!android_dt_check_header(hdr_addr)) { - printf("Error: DT image header is incorrect\n"); - return CMD_RET_FAILURE; - } index = simple_strtoul(argv[2], &endp, 0); if (*endp != '\0') { From patchwork Fri Nov 29 19:29:18 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eugeniu Rosca X-Patchwork-Id: 1202579 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) 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=de.adit-jv.com Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 47Pl4966MRz9sPJ for ; Sat, 30 Nov 2019 06:31:21 +1100 (AEDT) Received: by lists.denx.de (Postfix, from userid 105) id 784C6C21DED; Fri, 29 Nov 2019 19:31:19 +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=none 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 CC2DCC22091; Fri, 29 Nov 2019 19:31:17 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id EF130C220D6; Fri, 29 Nov 2019 19:30:57 +0000 (UTC) Received: from smtp1.de.adit-jv.com (smtp1.de.adit-jv.com [93.241.18.167]) by lists.denx.de (Postfix) with ESMTPS id EA477C2209C for ; Fri, 29 Nov 2019 19:30:56 +0000 (UTC) Received: from localhost (smtp1.de.adit-jv.com [127.0.0.1]) by smtp1.de.adit-jv.com (Postfix) with ESMTP id CF8963C0579; Fri, 29 Nov 2019 20:30:56 +0100 (CET) Received: from smtp1.de.adit-jv.com ([127.0.0.1]) by localhost (smtp1.de.adit-jv.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id JmF2QDR7Dn0N; Fri, 29 Nov 2019 20:30:52 +0100 (CET) Received: from HI2EXCH01.adit-jv.com (hi2exch01.adit-jv.com [10.72.92.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by smtp1.de.adit-jv.com (Postfix) with ESMTPS id 001423C00BE; Fri, 29 Nov 2019 20:30:52 +0100 (CET) Received: from vmlxhi-102.adit-jv.com (10.72.93.184) by HI2EXCH01.adit-jv.com (10.72.92.24) with Microsoft SMTP Server (TLS) id 14.3.468.0; Fri, 29 Nov 2019 20:30:51 +0100 From: Eugeniu Rosca To: , Tom Rini , Simon Glass , Sam Protsenko , Igor Opaniuk Date: Fri, 29 Nov 2019 20:29:18 +0100 Message-ID: <20191129192919.27715-4-erosca@de.adit-jv.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191129192919.27715-1-erosca@de.adit-jv.com> References: <20191129192919.27715-1-erosca@de.adit-jv.com> MIME-Version: 1.0 X-Originating-IP: [10.72.93.184] Cc: Roman Stratiienko , Eugeniu Rosca , Eugeniu Rosca Subject: [U-Boot] [PATCH 3/4] cmd: dtimg: Make an optional argument 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: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" Unlike dtimg, U-Boot commands like part [1], fstype [2] and uuid [3] accept an _optional_ parameter, which means that they will output the result to console whenever is skipped. This is extremely useful during development. Allow "dtimg" to behave in a similar fashion [4]. In addition: - replace env_set() by env_set_hex() - track and report the failures of env_set_hex() - amend command's help/usage text [1] => part start mmc 0 1 800 => part start mmc 0 1 myvar; print myvar myvar=800 [2] => fstype mmc 0:1 ext4 => fstype mmc 0:1 myvar; print myvar myvar=ext4 [3] => uuid b3909b50-55df-4173-b83c-b05343d2d5d2 => uuid myvar; print myvar myvar=4c04b15f-d0c1-4f98-9aca-ab62a66be864 [4] => dtimg start 0x48000000 0 0x480000e0 => dtimg start 0x48000000 0 myvar; print myvar myvar=480000e0 Signed-off-by: Eugeniu Rosca Reviewed-by: Sam Protsenko --- cmd/dtimg.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/cmd/dtimg.c b/cmd/dtimg.c index 5989081b0c14..5348a4ad46e8 100644 --- a/cmd/dtimg.c +++ b/cmd/dtimg.c @@ -55,9 +55,10 @@ static int dtimg_get_fdt(int argc, char * const argv[], enum cmd_dtimg_info cmd) char *endp; ulong fdt_addr; u32 fdt_size; - char buf[65]; + ulong envval; + int ret; - if (argc != 4) + if (argc < 3) return CMD_RET_USAGE; if (dtimg_get_argv_addr(argv[1], &hdr_addr) != CMD_RET_SUCCESS) @@ -74,17 +75,24 @@ static int dtimg_get_fdt(int argc, char * const argv[], enum cmd_dtimg_info cmd) switch (cmd) { case CMD_DTIMG_START: - snprintf(buf, sizeof(buf), "%lx", fdt_addr); + envval = fdt_addr; break; case CMD_DTIMG_SIZE: - snprintf(buf, sizeof(buf), "%x", fdt_size); + envval = fdt_size; break; default: printf("Error: Unknown cmd_dtimg_info value: %d\n", cmd); return CMD_RET_FAILURE; } - env_set(argv[3], buf); + if (argv[3]) { + ret = env_set_hex(argv[3], envval); + if (ret) + printf("Error(%d) env-setting '%s=0x%lx'\n", + ret, argv[3], envval); + } else { + printf("0x%lx\n", envval); + } return CMD_RET_SUCCESS; } @@ -131,12 +139,12 @@ U_BOOT_CMD( "dump \n" " - parse specified image and print its structure info\n" " : image address in RAM, in hex\n" - "dtimg start \n" + "dtimg start []\n" " - get address (hex) of FDT in the image, by index\n" " : image address in RAM, in hex\n" " : index of desired FDT in the image\n" " : name of variable where to store address of FDT\n" - "dtimg size \n" + "dtimg size []\n" " - get size (hex, bytes) of FDT in the image, by index\n" " : image address in RAM, in hex\n" " : index of desired FDT in the image\n" From patchwork Fri Nov 29 19:29:19 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eugeniu Rosca X-Patchwork-Id: 1202580 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) 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=de.adit-jv.com Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 47Pl526wxBz9sPJ for ; Sat, 30 Nov 2019 06:32:06 +1100 (AEDT) Received: by lists.denx.de (Postfix, from userid 105) id A9AEDC2202C; Fri, 29 Nov 2019 19:31:48 +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=none 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 7AD7BC22105; Fri, 29 Nov 2019 19:31:45 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id E3B82C2210B; Fri, 29 Nov 2019 19:31:26 +0000 (UTC) Received: from smtp1.de.adit-jv.com (smtp1.de.adit-jv.com [93.241.18.167]) by lists.denx.de (Postfix) with ESMTPS id 7EE15C21F7A for ; Fri, 29 Nov 2019 19:31:23 +0000 (UTC) Received: from localhost (smtp1.de.adit-jv.com [127.0.0.1]) by smtp1.de.adit-jv.com (Postfix) with ESMTP id 63FF63C0579; Fri, 29 Nov 2019 20:31:23 +0100 (CET) Received: from smtp1.de.adit-jv.com ([127.0.0.1]) by localhost (smtp1.de.adit-jv.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id O6fYkSImPWfo; Fri, 29 Nov 2019 20:31:17 +0100 (CET) Received: from HI2EXCH01.adit-jv.com (hi2exch01.adit-jv.com [10.72.92.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by smtp1.de.adit-jv.com (Postfix) with ESMTPS id C8C6E3C00BE; Fri, 29 Nov 2019 20:31:17 +0100 (CET) Received: from vmlxhi-102.adit-jv.com (10.72.93.184) by HI2EXCH01.adit-jv.com (10.72.92.24) with Microsoft SMTP Server (TLS) id 14.3.468.0; Fri, 29 Nov 2019 20:31:17 +0100 From: Eugeniu Rosca To: , Tom Rini , Simon Glass , Sam Protsenko , Igor Opaniuk Date: Fri, 29 Nov 2019 20:29:19 +0100 Message-ID: <20191129192919.27715-5-erosca@de.adit-jv.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191129192919.27715-1-erosca@de.adit-jv.com> References: <20191129192919.27715-1-erosca@de.adit-jv.com> MIME-Version: 1.0 X-Originating-IP: [10.72.93.184] Cc: Roman Stratiienko , Eugeniu Rosca , Eugeniu Rosca Subject: [U-Boot] [PATCH 4/4] cmd: dtimg: Get start and size based on --id and --rev 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: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" Currently, it is only possible to get the ${index}'s entry of a DTB/DTBO image [*]. The "dtimg" command is agnostic on the "id" and "rev" fields and is unable to take them as input for a more fine-grained DTB/DTBO search/retrieval. This is a major limitation, as users would like [**] to employ the "id"/"rev" fields to e.g. differentiate between DTBs/DTBOs associated to multiple HW revisions or several platforms. Given a sample DTBO image [***], the new options work like below: => dtimg start 0x48000000 0 --id invalid Error: Bad value '--id=invalid' => dtimg start 0x48000000 0 --id 0x100 Error: No #0 entry having id=0x100 && rev=0x0 => dtimg start 0x48000000 0 --id 00779000 0x480006ac => dtimg start 0x48000000 1 --id 00779000 0x48000b46 => dtimg start 0x48000000 2 --id 00779000 Error: No #2 entry having id=0x779000 && rev=0x0 => dtimg start 0x48000000 99 --id 00779000 Error: index >= dt_entry_count (99 >= 6) => dtimg start 0x48000000 0 0x480000e0 => dtimg start 0x48000000 1 0x480000e0 => dtimg start 0x48000000 2 0x480004d0 => dtimg start 0x48000000 3 0x480005be => dtimg start 0x48000000 4 0x480006ac => dtimg start 0x48000000 5 0x48000b46 => dtimg start 0x48000000 6 Error: index >= dt_entry_count (6 >= 6) => dtimg size 0x48000000 0 --id 00779000 0x49a => dtimg size 0x48000000 1 --id 00779000 0x248 [*] https://source.android.com/devices/architecture/dto/partitions [**] https://patchwork.ozlabs.org/patch/958594/#2302310 [***] Sample/dummy DTBO image: => dtimg dump 0x48000000 dt_table_header: magic = d7b7ab1e total_size = 3470 header_size = 32 dt_entry_size = 32 dt_entry_count = 6 dt_entries_offset = 32 page_size = 4096 version = 0 dt_table_entry[0]: dt_size = 1008 dt_offset = 224 id = 0b779530 rev = 00000000 custom[0] = 00000000 custom[1] = 00000000 custom[2] = 00000000 custom[3] = 00000000 (FDT)size = 1008 (FDT)compatible = (unknown) dt_table_entry[1]: dt_size = 1008 dt_offset = 224 id = 0b779520 rev = 00000000 custom[0] = 00000000 custom[1] = 00000000 custom[2] = 00000000 custom[3] = 00000000 (FDT)size = 1008 (FDT)compatible = (unknown) dt_table_entry[2]: dt_size = 238 dt_offset = 1232 id = 0b779530 rev = 00000000 custom[0] = 00000000 custom[1] = 00000000 custom[2] = 00000000 custom[3] = 00000000 (FDT)size = 238 (FDT)compatible = (unknown) dt_table_entry[3]: dt_size = 238 dt_offset = 1470 id = 0b779520 rev = 00000000 custom[0] = 00000000 custom[1] = 00000000 custom[2] = 00000000 custom[3] = 00000000 (FDT)size = 238 (FDT)compatible = (unknown) dt_table_entry[4]: dt_size = 1178 dt_offset = 1708 id = 00779000 rev = 00000000 custom[0] = 00000000 custom[1] = 00000000 custom[2] = 00000000 custom[3] = 00000000 (FDT)size = 1178 (FDT)compatible = (unknown) dt_table_entry[5]: dt_size = 584 dt_offset = 2886 id = 00779000 rev = 00000000 custom[0] = 00000000 custom[1] = 00000000 custom[2] = 00000000 custom[3] = 00000000 (FDT)size = 584 (FDT)compatible = (unknown) Signed-off-by: Eugeniu Rosca --- cmd/dtimg.c | 81 +++++++++++++++++++++++++++++++++++--- common/image-android-dt.c | 64 ++++++++++++++++++++++++++++-- include/image-android-dt.h | 5 ++- 3 files changed, 138 insertions(+), 12 deletions(-) diff --git a/cmd/dtimg.c b/cmd/dtimg.c index 5348a4ad46e8..10e909ce551b 100644 --- a/cmd/dtimg.c +++ b/cmd/dtimg.c @@ -7,6 +7,7 @@ #include #include #include +#include enum cmd_dtimg_info { CMD_DTIMG_START = 0, @@ -48,6 +49,61 @@ static int do_dtimg_dump(cmd_tbl_t *cmdtp, int flag, int argc, return CMD_RET_SUCCESS; } +static int dtimg_get_opthex(int *argcp, char * const *argvp[], u32 *valp) +{ + char *endp; + u32 val; + + if (!argcp || !argvp || !valp) + return CMD_RET_FAILURE; + + if (*argcp < 2) { + printf("Error: Option '%s' expects an argument\n", (*argvp)[0]); + return CMD_RET_FAILURE; + } + + val = simple_strtoul((*argvp)[1], &endp, 16); + if (*endp != '\0') { + printf("Error: Bad value '%s=%s'\n", (*argvp)[0], (*argvp)[1]); + return CMD_RET_FAILURE; + } + + *valp = val; + (*argcp)--; + (*argvp)++; + + return CMD_RET_SUCCESS; +} + +static int dtimg_get_opt(int argc, char * const argv[], + struct dt_table_entry *ep, char **envstrp) +{ + if (!ep || argc < 0 || !argv || !envstrp) + return CMD_RET_FAILURE; + + for (; argc > 0; argc--, argv++) { + int ret; + + if (!strcmp(argv[0], "--id")) { + ret = dtimg_get_opthex(&argc, &argv, &ep->id); + if (ret != CMD_RET_SUCCESS) + return ret; + } else if (!strcmp(argv[0], "--rev")) { + ret = dtimg_get_opthex(&argc, &argv, &ep->rev); + if (ret != CMD_RET_SUCCESS) + return ret; + } else if (argc == 1 && argv[0][0] != '-' && + !isdigit(argv[0][0])) { + *envstrp = argv[0]; + } else { + printf("Error: Option '%s' not supported\n", argv[0]); + return CMD_RET_FAILURE; + } + } + + return CMD_RET_SUCCESS; +} + static int dtimg_get_fdt(int argc, char * const argv[], enum cmd_dtimg_info cmd) { ulong hdr_addr; @@ -55,6 +111,8 @@ static int dtimg_get_fdt(int argc, char * const argv[], enum cmd_dtimg_info cmd) char *endp; ulong fdt_addr; u32 fdt_size; + struct dt_table_entry entry = { 0 }; + char *envstr = NULL; ulong envval; int ret; @@ -70,7 +128,18 @@ static int dtimg_get_fdt(int argc, char * const argv[], enum cmd_dtimg_info cmd) return CMD_RET_FAILURE; } - if (!android_dt_get_fdt_by_index(hdr_addr, index, &fdt_addr, &fdt_size)) + /* + * Consume all processed mandatory arguments. + * Prepare for parsing the optional ones. + */ + argc -= 3; + argv += 3; + + ret = dtimg_get_opt(argc, argv, &entry, &envstr); + if (ret != CMD_RET_SUCCESS) + return ret; + + if (!android_dt_get_fdt(hdr_addr, index, &entry, &fdt_addr, &fdt_size)) return CMD_RET_FAILURE; switch (cmd) { @@ -85,11 +154,11 @@ static int dtimg_get_fdt(int argc, char * const argv[], enum cmd_dtimg_info cmd) return CMD_RET_FAILURE; } - if (argv[3]) { - ret = env_set_hex(argv[3], envval); + if (envstr) { + ret = env_set_hex(envstr, envval); if (ret) printf("Error(%d) env-setting '%s=0x%lx'\n", - ret, argv[3], envval); + ret, envstr, envval); } else { printf("0x%lx\n", envval); } @@ -111,8 +180,8 @@ static int do_dtimg_size(cmd_tbl_t *cmdtp, int flag, int argc, static cmd_tbl_t cmd_dtimg_sub[] = { U_BOOT_CMD_MKENT(dump, 2, 0, do_dtimg_dump, "", ""), - U_BOOT_CMD_MKENT(start, 4, 0, do_dtimg_start, "", ""), - U_BOOT_CMD_MKENT(size, 4, 0, do_dtimg_size, "", ""), + U_BOOT_CMD_MKENT(start, 8, 0, do_dtimg_start, "", ""), + U_BOOT_CMD_MKENT(size, 8, 0, do_dtimg_size, "", ""), }; static int do_dtimg(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) diff --git a/common/image-android-dt.c b/common/image-android-dt.c index a2d52df4a2a9..91e6b4eca23a 100644 --- a/common/image-android-dt.c +++ b/common/image-android-dt.c @@ -5,7 +5,6 @@ */ #include -#include #include #include #include @@ -38,14 +37,15 @@ bool android_dt_check_header(ulong hdr_addr) * * @return true on success or false on error */ -bool android_dt_get_fdt_by_index(ulong hdr_addr, u32 index, ulong *addr, - u32 *size) +bool android_dt_get_fdt(ulong hdr_addr, u32 index, + struct dt_table_entry *ep, ulong *addr, u32 *size) { const struct dt_table_header *hdr; const struct dt_table_entry *e; u32 entry_count, entries_offset, entry_size; ulong e_addr; - u32 dt_offset, dt_size; + u32 dt_offset, dt_size, dt_id, dt_rev; + int i, cnt; hdr = map_sysmem(hdr_addr, sizeof(*hdr)); entry_count = fdt32_to_cpu(hdr->dt_entry_count); @@ -59,6 +59,62 @@ bool android_dt_get_fdt_by_index(ulong hdr_addr, u32 index, ulong *addr, return false; } + /* + * In case of a NULL dt_table_entry _or_ if both its 'id' and 'rev' + * fields are empty/zero, return the ${index}'th DTB/DTBO entry + */ + if (!ep || (!ep->id && !ep->rev)) + goto found; + + /* + * - In case of non-zero value received in both 'id' and 'rev' fields, + * return the ${cnt}'th DTB/DTBO entry matching both fields + * - In case of non-zero value received in 'id' and zero in 'rev', + * return the ${cnt}'th DTB/DTBO entry matching the 'id' field only + * - In case of non-zero value received in 'rev' and zero in 'id', + * return the ${cnt}'th DTB/DTBO entry matching the 'rev' field only + * In any of the above cases: 0 <= ${cnt} <= ${index} < entry_count + */ + for (i = 0, cnt = -1; i < entry_count; i++) { + e_addr = hdr_addr + entries_offset + i * entry_size; + e = map_sysmem(e_addr, sizeof(*e)); + dt_id = fdt32_to_cpu(e->id); + dt_rev = fdt32_to_cpu(e->rev); + unmap_sysmem(e); + + if (ep->id && ep->rev) { + if (ep->id == dt_id && ep->rev == dt_rev) { + cnt++; + if (cnt == index) { + index = i; + goto found; + } + } + } else if (ep->id) { + if (ep->id == dt_id) { + cnt++; + if (cnt == index) { + index = i; + goto found; + } + } + } else if (ep->rev) { + if (ep->rev == dt_rev) { + cnt++; + if (cnt == index) { + index = i; + goto found; + } + } + } + } + + printf("Error: No #%d entry having id=0x%x && rev=0x%x\n", + index, ep->id, ep->rev); + + return false; + +found: e_addr = hdr_addr + entries_offset + index * entry_size; e = map_sysmem(e_addr, sizeof(*e)); dt_offset = fdt32_to_cpu(e->dt_offset); diff --git a/include/image-android-dt.h b/include/image-android-dt.h index 9a3aa8fa30fb..15f6115eedf0 100644 --- a/include/image-android-dt.h +++ b/include/image-android-dt.h @@ -8,10 +8,11 @@ #define IMAGE_ANDROID_DT_H #include +#include bool android_dt_check_header(ulong hdr_addr); -bool android_dt_get_fdt_by_index(ulong hdr_addr, u32 index, ulong *addr, - u32 *size); +bool android_dt_get_fdt(ulong hdr_addr, u32 index, + struct dt_table_entry *ep, ulong *addr, u32 *size); #if !defined(CONFIG_SPL_BUILD) void android_dt_print_contents(ulong hdr_addr);