From patchwork Wed Jun 6 14:06:54 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sam Protsenko X-Patchwork-Id: 137832 Delivered-To: patch@linaro.org Received: by 2002:a2e:970d:0:0:0:0:0 with SMTP id r13-v6csp848823lji; Wed, 6 Jun 2018 07:08:12 -0700 (PDT) X-Google-Smtp-Source: ADUXVKIgXEqGCWNHkhQ5JDMY68F2/jaK596NM1g7IYmT6RpfZwVqZSsI+NuMVcv0lD8aEWZGMfHb X-Received: by 2002:a50:ed92:: with SMTP id h18-v6mr3859260edr.117.1528294091980; Wed, 06 Jun 2018 07:08:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528294091; cv=none; d=google.com; s=arc-20160816; b=JUqRoXm9NpCLKfx2g9va/Aa2rsE4XRveoFJVEc8bhvshBUEuH00+p/ROJv+Gxhxk1w tdu0O2Ya78TQoSBTw//C0Nkr+WMeFckprGJy5jaCHc+H/hsBhgFv27MoYyk6xzjdlmXT NQn1HwWF0EHTIrojAkoCBULN+bBZY2wWPmf4rdGPdgn31g5jAY8Mh6ZbWRFyaF6kq37x 3qbp76QAn3Ibcu1+YMlPW1InVpkj0+anmmV07kzkaVsKwoT54o+3j+siaZEHpcfkQPaQ 3gwBWdxmE0jkWOxwTD7dpiZsEyZrQmHAadwctxyWG3YH6vswpNASGdeTWWggkVJwAH50 5IOQ== 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=ws0KK+OEouR7QCX41EWPxEOgRKNbsX4xqBV4kiN6ppM=; b=jOneu62DITFCI2mdgy7xKXxBL1AZoaSejQb4DlVeNFuA+VAwNF8k7CmA/6miwvY0kf f4Zp4JA017+7unKVL11ewe1UgXuLe/Xn7jBDP289HEFSisb13Jnf3sYGy9p90XZgUMcG rJLphpXZegobobhDvfg6itO0/k2z8fdOKi6yTq66uoNBR/n7tdPyKP1kf3tx1vbCuh/I MT/Il9nyJAWw6pRrJ/iRJ3ytbPzKM52fTy0++xSm+KW87h3UMM2XR+uAvqO2JSjn0HEA YJfmm7IGc5IqFvDGllQDChBdHivz4n/1iuZi5K0oR3RmuDHfSikkki3gahIIPxQYvsNB sSug== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=edcVpqEO; 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 i91-v6si2396760edd.228.2018.06.06.07.08.11; Wed, 06 Jun 2018 07:08:11 -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=edcVpqEO; 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 731E5C22028; Wed, 6 Jun 2018 14:07:41 +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, 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 BBF5BC21FFE; Wed, 6 Jun 2018 14:07:15 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id A5B66C22026; Wed, 6 Jun 2018 14:06:59 +0000 (UTC) Received: from mail-lf0-f65.google.com (mail-lf0-f65.google.com [209.85.215.65]) by lists.denx.de (Postfix) with ESMTPS id 1F8A6C22028 for ; Wed, 6 Jun 2018 14:06:59 +0000 (UTC) Received: by mail-lf0-f65.google.com with SMTP id 36-v6so9311036lfr.11 for ; Wed, 06 Jun 2018 07:06:59 -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=i+ynwlPdUNsr1cUd4oORQjpH8AyObXc24l+o0vCN9rQ=; b=edcVpqEOdVU4Rz866v4rd8BJA+APnOLib9BITvfethfrNlBtjvEwfHOVtgabWuLYNI lZeot44ouws3heJpO9lQBNRm40u7Sqd9mctD+FZ1m7RQo8M0IoeS2b58q8sjqjHPtq6l lKf2QCCufhNuHr7nYegFmhXU53wzmbcAedia8= 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=i+ynwlPdUNsr1cUd4oORQjpH8AyObXc24l+o0vCN9rQ=; b=D+82l2r8XU8z0mIT8/MOHEq0yC3H7a3ziZcn5yEv25MVCnT3S4XCLQNH54E7UWeNQc lChapO3W/Xjq3BTQ1aV8fNwbnq25H4kgRgXdk2SDAxvoZUTs9wDcfPlc5GGUKbSvCxei 1rbYpTyLw71SuIkXJRhqzahvnQlK9Crk2ie37Num7A7Hn5meIDanQPmXIJm847N6qAuH vjhFwchSf5LOHvb3nXxwwv3P+4eCVge1z3ySW0zTXMkPI/VnjUnfD6XPYDYMf2FYsESh se5cMXNsYBmGIaoZSrvQpfOiUMDAfWNMInwPqQQIUDZp3DAEhmaIhJvMHS9CPI+HmFLT 12Mw== X-Gm-Message-State: APt69E1wn0Q/2/djRRgwvgVml76kOoxasTi4VUJMxaq+DaMC0FRh7pKo LQYAAK8uOHE5sQ5yKT4Gx2lgRoAQm0k= X-Received: by 2002:a2e:6a07:: with SMTP id f7-v6mr2181919ljc.109.1528294018178; Wed, 06 Jun 2018 07:06:58 -0700 (PDT) Received: from localhost ([195.238.92.132]) by smtp.gmail.com with ESMTPSA id y206-v6sm220886lfc.60.2018.06.06.07.06.57 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 06 Jun 2018 07:06:57 -0700 (PDT) From: Sam Protsenko To: u-boot@lists.denx.de Date: Wed, 6 Jun 2018 17:06:54 +0300 Message-Id: <20180606140654.17994-2-semen.protsenko@linaro.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180606140654.17994-1-semen.protsenko@linaro.org> References: <20180606140654.17994-1-semen.protsenko@linaro.org> Cc: Praneeth Bajjuri , Tom Rini Subject: [U-Boot] [PATCH v3 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 --- cmd/Kconfig | 8 +++ cmd/Makefile | 1 + cmd/dtimg.c | 142 ++++++++++++++++++++++++++++++++++++++++++++++++ common/Makefile | 4 ++ 4 files changed, 155 insertions(+) create mode 100644 cmd/dtimg.c diff --git a/cmd/Kconfig b/cmd/Kconfig index e283cb9a8a..5a4244dbac 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 e0088df33b..32c3e52491 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..5295a341ad --- /dev/null +++ b/cmd/dtimg.c @@ -0,0 +1,142 @@ +/* + * (C) Copyright 2018 Linaro Ltd. + * Sam Protsenko + * + * SPDX-License-Identifier: GPL-2.0+ + */ + +#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 b3da72ebb2..80bcc07bd0 100644 --- a/common/Makefile +++ b/common/Makefile @@ -108,6 +108,10 @@ obj-$(CONFIG_IO_TRACE) += iotrace.o obj-y += memsize.o obj-y += stdio.o +ifdef CONFIG_CMD_DTIMG +obj-y += image-android-dt.o +endif + ifdef CONFIG_CMD_EEPROM_LAYOUT obj-y += eeprom/eeprom_field.o eeprom/eeprom_layout.o endif