From patchwork Thu Aug 16 20:34:13 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sam Protsenko X-Patchwork-Id: 144450 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp2514696ljj; Thu, 16 Aug 2018 13:35:14 -0700 (PDT) X-Google-Smtp-Source: AA+uWPw5ai0DZn+mooXQGVfntr/oWrvIqtWSjo6bHCk7AHt+9JqhBJaFySW4BG/rYQyvnZrJwYDx X-Received: by 2002:a50:a2a6:: with SMTP id 35-v6mr39376035edm.276.1534451714917; Thu, 16 Aug 2018 13:35:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1534451714; cv=none; d=google.com; s=arc-20160816; b=kqRp0yk0yDYsW9sYShyDZlRbOXjNBQqbHWDLWQ1aTkwZEQ7TleT+wWmupiTsuKKosQ MlApy5LHn4FMcNDCUR5erKQgXW0q3J86RTHHb07u5hiaiDQ67PzS8I6DDR+I21AXo9ls yXl6poCKDlqRdHd3lCYdfKOfvCsRU2qWwXoQfbblCP1IAp914j09lG2rprMJooMPdJik CD+1lQSyfsZrLPd8IbXM2IwFA5L2WJ+U5Ze6b885PFTvL33J72nzqBxboqEZiIBLjoCU wzuYeqN8fnhc4OIgbAWxN0F5t93M94tHI9uf7hA0N3jHv4OuGudPW75TRZCky3THj/Wk FDEg== 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:cc:references:in-reply-to:message-id :date:to:from:dkim-signature:arc-authentication-results; bh=2skXKYmOk3cOXpyEx68VgpxpLuNGwsg0cDTZ3jdf2fk=; b=iqr3vqXQDHRtPdAYfcVCpM+fEkthiza1l2joJ7CLvGr2lP9doHMcfvzlzN8OpcDk4a jLBz+KwWiFq4tUMvRvjLfbdlYkXcKwu6jEsAnqFoVwSvpvfHxYw7Y0TgVCWEbglu4UAU J8vLloOxXv/tvvQwI+KKtHmpMYCnaeJz4ubJXvaHKTvJa1E2zl9H3bZRsJqMHet1EPpL 6/F3fu5GueEji391BXDaDVfzloulC52xCJlIHysfanTnJA5PkJYUDsciTYZ8jPKXbEWz UoeBolb8rT98VTvAS+aV/tAj/Yu7I8uneCmbJSophXDmVJMvBie627LPo+ZqP/5SyPKI Zm2A== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=TdH81NcD; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.denx.de (dione.denx.de. [81.169.180.215]) by mx.google.com with ESMTP id g15-v6si1569520eds.222.2018.08.16.13.35.14; Thu, 16 Aug 2018 13:35:14 -0700 (PDT) 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=@linaro.org header.s=google header.b=TdH81NcD; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: by lists.denx.de (Postfix, from userid 105) id 84C2CC21E2B; Thu, 16 Aug 2018 20:34:45 +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 ADBCAC21DF3; Thu, 16 Aug 2018 20:34:19 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 7199EC21C57; Thu, 16 Aug 2018 20:34:17 +0000 (UTC) Received: from mail-lj1-f195.google.com (mail-lj1-f195.google.com [209.85.208.195]) by lists.denx.de (Postfix) with ESMTPS id 10F88C21C38 for ; Thu, 16 Aug 2018 20:34:17 +0000 (UTC) Received: by mail-lj1-f195.google.com with SMTP id u7-v6so4706571lji.3 for ; Thu, 16 Aug 2018 13:34:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=DDj1n+5+WElJh1nzJXtI2QbWkeOxJC6P8+wDN581Qbk=; b=TdH81NcDu3zHBn9nleL0qym+1aPW+JK7e5AtT6D4AuK7Vg5jdyliMZDLq1CASNxF0W GFSH/2zGQ5QoQTVLC9xVhhkr9HGKiy1q8ZTh580EsgSdfF1c+Vu1PlB8g6SYSTIm9IUX dq9eP48W45tENBeI8CE5iEICw3yWi7uI9rikI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=DDj1n+5+WElJh1nzJXtI2QbWkeOxJC6P8+wDN581Qbk=; b=Ehp85FE7OupqeDhuLWJAOX+iHCU1vVb9TKxFNFaaFxtkcLs5xf0g0C7//rYtACptdV YFnGcvcR6tk8AKVAe2zYVm2ruHP4YDn29sQnu+/mcgT93z7QDfDex6viMwi4yW/pdJIJ rL6dfx9JU2xHqRiaHPrAIjB0FmdU7F7KXLhycbNiSbrK0Lf1aLz2vzGzROPWnNLYNQ3e XXrZCW/SIuk13I7Zx6sFKfEHfEfvfuu2NMUQGyCJkSFvVpsVPxHCDqNQdaFyFkTzWVlA /UzIHVkfbqyHkt3OA0Q6tKa9x/YuITBCMCqLTVrNQnKBYY71E2WpPb8olaPGqmp0KIl3 0kUA== X-Gm-Message-State: AOUpUlEoH3Fs9HYPfPhWfXRPZrvo7FirZQiPdnFEkkt4K506MyCI951F 0/R6ec7nmz3Pr+69JJ5RQeXUgjbV62I= X-Received: by 2002:a2e:2f19:: with SMTP id v25-v6mr18227788ljv.113.1534451656230; Thu, 16 Aug 2018 13:34:16 -0700 (PDT) Received: from localhost ([195.238.92.132]) by smtp.gmail.com with ESMTPSA id 66-v6sm39668ljz.8.2018.08.16.13.34.15 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 16 Aug 2018 13:34:15 -0700 (PDT) From: Sam Protsenko To: u-boot@lists.denx.de Date: Thu, 16 Aug 2018 23:34:13 +0300 Message-Id: <20180816203413.1598-2-semen.protsenko@linaro.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180816203413.1598-1-semen.protsenko@linaro.org> References: <20180816203413.1598-1-semen.protsenko@linaro.org> Cc: Tom Rini , Sandeep Patil , Praneeth Bajjuri , Alistair Strachan Subject: [U-Boot] [PATCH v4 2/2] cmd: Add dtimg command 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" dtimg command allows user to work with Android DTB/DTBO image format. Such as, getting the address of desired DTB/DTBO file, printing the dump of the image in U-Boot shell, etc. This command is needed to provide Android boot with new Android DT image format further. Signed-off-by: Sam Protsenko Reviewed-by: Tom Rini --- Changes in v4: - rebased - fixed SPDX tags - use obj-$(CONFIG_CMD_DTIMG) instead #ifdef cmd/Kconfig | 8 +++ cmd/Makefile | 1 + cmd/dtimg.c | 141 ++++++++++++++++++++++++++++++++++++++++++++++++ common/Makefile | 2 + 4 files changed, 152 insertions(+) create mode 100644 cmd/dtimg.c diff --git a/cmd/Kconfig b/cmd/Kconfig index bd90946667..b9215abae3 100644 --- a/cmd/Kconfig +++ b/cmd/Kconfig @@ -254,6 +254,14 @@ config CMD_BOOTMENU help Add an ANSI terminal boot menu command. +config CMD_DTIMG + bool "dtimg" + help + Android DTB/DTBO image manipulation commands. Read dtb/dtbo files from + image into RAM, dump image structure information, etc. Those dtb/dtbo + files should be merged in one dtb further, which needs to be passed to + the kernel, as part of a boot process. + config CMD_ELF bool "bootelf, bootvx" default y diff --git a/cmd/Makefile b/cmd/Makefile index 12d2118f1d..b1206fca85 100644 --- a/cmd/Makefile +++ b/cmd/Makefile @@ -43,6 +43,7 @@ ifdef CONFIG_POST obj-$(CONFIG_CMD_DIAG) += diag.o endif obj-$(CONFIG_CMD_DISPLAY) += display.o +obj-$(CONFIG_CMD_DTIMG) += dtimg.o obj-$(CONFIG_CMD_ECHO) += echo.o obj-$(CONFIG_ENV_IS_IN_EEPROM) += eeprom.o obj-$(CONFIG_CMD_EEPROM) += eeprom.o diff --git a/cmd/dtimg.c b/cmd/dtimg.c new file mode 100644 index 0000000000..65c8d101b9 --- /dev/null +++ b/cmd/dtimg.c @@ -0,0 +1,141 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * (C) Copyright 2018 Linaro Ltd. + * Sam Protsenko + */ + +#include +#include + +enum cmd_dtimg_info { + CMD_DTIMG_START = 0, + CMD_DTIMG_SIZE, +}; + +static int do_dtimg_dump(cmd_tbl_t *cmdtp, int flag, int argc, + char * const argv[]) +{ + char *endp; + ulong hdr_addr; + + if (argc != 2) + return CMD_RET_USAGE; + + hdr_addr = simple_strtoul(argv[1], &endp, 16); + if (*endp != '\0') { + printf("Error: Wrong image address\n"); + return CMD_RET_FAILURE; + } + + if (!android_dt_check_header(hdr_addr)) { + printf("Error: DT image header is incorrect\n"); + return CMD_RET_FAILURE; + } + + android_dt_print_contents(hdr_addr); + + return CMD_RET_SUCCESS; +} + +static int dtimg_get_fdt(int argc, char * const argv[], enum cmd_dtimg_info cmd) +{ + ulong hdr_addr; + u32 index; + char *endp; + ulong fdt_addr; + u32 fdt_size; + char buf[65]; + + if (argc != 4) + return CMD_RET_USAGE; + + hdr_addr = simple_strtoul(argv[1], &endp, 16); + if (*endp != '\0') { + printf("Error: Wrong image address\n"); + 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') { + printf("Error: Wrong index\n"); + return CMD_RET_FAILURE; + } + + if (!android_dt_get_fdt_by_index(hdr_addr, index, &fdt_addr, &fdt_size)) + return CMD_RET_FAILURE; + + switch (cmd) { + case CMD_DTIMG_START: + snprintf(buf, sizeof(buf), "%lx", fdt_addr); + break; + case CMD_DTIMG_SIZE: + snprintf(buf, sizeof(buf), "%x", fdt_size); + break; + default: + printf("Error: Unknown cmd_dtimg_info value: %d\n", cmd); + return CMD_RET_FAILURE; + } + + env_set(argv[3], buf); + + return CMD_RET_SUCCESS; +} + +static int do_dtimg_start(cmd_tbl_t *cmdtp, int flag, int argc, + char * const argv[]) +{ + return dtimg_get_fdt(argc, argv, CMD_DTIMG_START); +} + +static int do_dtimg_size(cmd_tbl_t *cmdtp, int flag, int argc, + char * const argv[]) +{ + return dtimg_get_fdt(argc, argv, CMD_DTIMG_SIZE); +} + +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, "", ""), +}; + +static int do_dtimg(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) +{ + cmd_tbl_t *cp; + + cp = find_cmd_tbl(argv[1], cmd_dtimg_sub, ARRAY_SIZE(cmd_dtimg_sub)); + + /* Strip off leading 'dtimg' command argument */ + argc--; + argv++; + + if (!cp || argc > cp->maxargs) + return CMD_RET_USAGE; + if (flag == CMD_FLAG_REPEAT && !cp->repeatable) + return CMD_RET_SUCCESS; + + return cp->cmd(cmdtp, flag, argc, argv); +} + +U_BOOT_CMD( + dtimg, CONFIG_SYS_MAXARGS, 0, do_dtimg, + "manipulate dtb/dtbo Android image", + "dump \n" + " - parse specified image and print its structure info\n" + " : image address in RAM, in hex\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" + " - 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" + " : name of variable where to store size of FDT" +); diff --git a/common/Makefile b/common/Makefile index 7100541ece..7473b85011 100644 --- a/common/Makefile +++ b/common/Makefile @@ -108,6 +108,8 @@ obj-$(CONFIG_IO_TRACE) += iotrace.o obj-y += memsize.o obj-y += stdio.o +obj-$(CONFIG_CMD_DTIMG) += image-android-dt.o + ifdef CONFIG_CMD_EEPROM_LAYOUT obj-y += eeprom/eeprom_field.o eeprom/eeprom_layout.o endif