From patchwork Wed Jun 6 14:06:53 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sam Protsenko X-Patchwork-Id: 137831 Delivered-To: patch@linaro.org Received: by 2002:a2e:970d:0:0:0:0:0 with SMTP id r13-v6csp847787lji; Wed, 6 Jun 2018 07:07:21 -0700 (PDT) X-Google-Smtp-Source: ADUXVKLxLhTqnHD+Vbio70ogYBvu5QTIFW22W5OoAMfkRHw7zuAYzMuYx2rqyWhDi9VGMpH+6MUb X-Received: by 2002:a50:aca4:: with SMTP id x33-v6mr3907179edc.270.1528294041559; Wed, 06 Jun 2018 07:07:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528294041; cv=none; d=google.com; s=arc-20160816; b=WToPsbBHswDPrbHoCSNN1sAlRjhN5DZ/JzU8zSA4tCHA5+K0/4bq2i+OF6ByclVuy0 bPg88ASJhpzFWcqXwCceukOhPr9ng3IUYrrbdk235+rWeGkCjmuIDd/aPkHMB2dgnny5 wjTnZp+iAdrX6m7wbAeW+tnYeS4+OO0+S9efIg0fbXKSZPXLf7xoQfQiNooxcSnoDXV/ gzKyO1raAizIw1aTvocrc3Hq63X6hHSWh+viQDkFS32Jb8ZWpDK2RBYMRMR3irA4tEC/ bp8mGGoYgPf9yzV55spw2+caPE/UjAKlurP03one+QrM0MelAKrSwajJw5DiTBAEGOvU gT9g== 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:message-id:date:to:from :dkim-signature:arc-authentication-results; bh=UpoDDqfoJyYIDSkSt7oV1tkvJkoqmIeTK+jYdms9V1Y=; b=D7izQ6DLhU3+Q0AwKe+TSBH23GWQf4gbvvee/3lq0K89cTed8D98084h4qRhQVTlwp 01rdLXSJWPNVbpscz5FzElYXDULtjYJNmgzPJOIBbRi2IgmQy5gf/uUuSFzut/Ksttnm x6ql3fNTvXTAu6b2gZR2yBvr/KIiyHS0bk9gzWxDqkJDC/0D0Qu9WHn+4wraEZiUQDE4 g0kCTGzzoRWq1/sjhuVK/pvCPDfPWZKbA6ggeko3SwBhs/yoJNpCRXNJ1v+KE9JuTrCM W6WzBR8eVxS0LLJ8zih2kB/3/YksCg5H2b+xYe0A1dm9XgZwq2veDRVSkRDRFO3vv4Uq 2teQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=kmnjkEfl; 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 a13-v6si3705026edm.339.2018.06.06.07.07.19; Wed, 06 Jun 2018 07:07:21 -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=kmnjkEfl; 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 26888C2202D; Wed, 6 Jun 2018 14:07:16 +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 6B7BBC21FDA; Wed, 6 Jun 2018 14:07:14 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 4DBC5C22026; Wed, 6 Jun 2018 14:06:57 +0000 (UTC) Received: from mail-lf0-f67.google.com (mail-lf0-f67.google.com [209.85.215.67]) by lists.denx.de (Postfix) with ESMTPS id 74022C22007 for ; Wed, 6 Jun 2018 14:06:57 +0000 (UTC) Received: by mail-lf0-f67.google.com with SMTP id j13-v6so9308739lfb.13 for ; Wed, 06 Jun 2018 07:06:57 -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; bh=p1cO/UWA/qkL07AffdDCVAZpDCKr5LeW6rPU6xLP2gU=; b=kmnjkEfllzeu7oImr8K5IHT4KA2xZCeW4uIIywarFKK1N7adojAD05v69tggk4zsMq tOFa0QGDLg6M8x5483sbMJKpKHBWsP23bMn45fTndc7PZKpTdvPS8tTcSDgVpeT1Ctbc 7RZkX119kZ9Yn87KEhtdZonUQ5ZyAv57qnLEc= 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; bh=p1cO/UWA/qkL07AffdDCVAZpDCKr5LeW6rPU6xLP2gU=; b=DiYo5JSx0toQBHkReWzbyaOkPpqpcgv8Iyw0YViC0LIZN2pA2Vk6C4sk0h0GJUIFG9 GxpXvzVAvYeil2C3Kpe2BRLOSJrgEF1pK/GJjZgK07eezD7/vXGwGqHWbC0Sfq2SOkRs Sn9O5xlFqJxmh0MRRzT7KkFw5h+9wIOfyTYgfO1tbO0L1FoTY8fRkHbqHN7WHH9trQPj tRE131vT8gb6Bb1nTslX0FRvLyu0IqDbRWlejr9/3hnXDeUeJ7gFpvu/okwWrApXRNh1 p8FAbIyKLOJM4geE3nrKQatGrKoXUHGsnO11Gm9QbNOiuqm11pmRWMJCzggrt6a7y5eH xWDQ== X-Gm-Message-State: APt69E0G2Nj2lDEPP46yHFJTawZOQYO4YojCP92Hvyoh8y+ETWTPFD9Z 45B1IyCMd22dI5XwHkEq6eVw0d/SwgI= X-Received: by 2002:a2e:3c0e:: with SMTP id j14-v6mr2383274lja.149.1528294016500; Wed, 06 Jun 2018 07:06:56 -0700 (PDT) Received: from localhost ([195.238.92.132]) by smtp.gmail.com with ESMTPSA id a18-v6sm5140275ljf.17.2018.06.06.07.06.55 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 06 Jun 2018 07:06:55 -0700 (PDT) From: Sam Protsenko To: u-boot@lists.denx.de Date: Wed, 6 Jun 2018 17:06:53 +0300 Message-Id: <20180606140654.17994-1-semen.protsenko@linaro.org> X-Mailer: git-send-email 2.17.0 Cc: Praneeth Bajjuri , Tom Rini Subject: [U-Boot] [PATCH v3 1/2] common: Add support for Android DT image 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" Android documentation recommends new image format for storing DTB/DTBO files: [1]. To support that format, this patch adds helper functions for Android DTB/DTBO format. In image-android-dt.* files you can find helper functions to work with Android DT image format, such us routines for: - printing the dump of image structure - getting the address and size of desired dtb/dtbo file This patch uses dt_table.h file, that was added in 643cefa4d848 ("Import Android's dt_table.h for DT image format") by Alex Deymo. [1] https://source.android.com/devices/architecture/dto/partitions Signed-off-by: Sam Protsenko --- Changes in v3: - dropped include/dt_image.h (was sent in another patch by Alex Deymo) - rebased on top of last master common/image-android-dt.c | 157 +++++++++++++++++++++++++++++++++++++ include/image-android-dt.h | 21 +++++ 2 files changed, 178 insertions(+) create mode 100644 common/image-android-dt.c create mode 100644 include/image-android-dt.h diff --git a/common/image-android-dt.c b/common/image-android-dt.c new file mode 100644 index 0000000000..9b7683faab --- /dev/null +++ b/common/image-android-dt.c @@ -0,0 +1,157 @@ +/* + * (C) Copyright 2018 Linaro Ltd. + * Sam Protsenko + * + * SPDX-License-Identifier: GPL-2.0+ + */ + +#include +#include +#include +#include +#include + +/** + * Check if image header is correct. + * + * @param hdr_addr Start address of DT image + * @return true if header is correct or false if header is incorrect + */ +bool android_dt_check_header(ulong hdr_addr) +{ + const struct dt_table_header *hdr; + u32 magic; + + hdr = map_sysmem(hdr_addr, sizeof(*hdr)); + magic = fdt32_to_cpu(hdr->magic); + unmap_sysmem(hdr); + + return magic == DT_TABLE_MAGIC; +} + +/** + * Get the address of FDT (dtb or dtbo) in memory by its index in image. + * + * @param hdr_addr Start address of DT image + * @param index Index of desired FDT in image (starting from 0) + * @param[out] addr If not NULL, will contain address to specified FDT + * @param[out] size If not NULL, will contain size of specified FDT + * + * @return true on success or false on error + */ +bool android_dt_get_fdt_by_index(ulong hdr_addr, u32 index, 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; + + hdr = map_sysmem(hdr_addr, sizeof(*hdr)); + entry_count = fdt32_to_cpu(hdr->dt_entry_count); + entries_offset = fdt32_to_cpu(hdr->dt_entries_offset); + entry_size = fdt32_to_cpu(hdr->dt_entry_size); + unmap_sysmem(hdr); + + if (index > entry_count) { + printf("Error: index > dt_entry_count (%u > %u)\n", index, + entry_count); + return false; + } + + e_addr = hdr_addr + entries_offset + index * entry_size; + e = map_sysmem(e_addr, sizeof(*e)); + dt_offset = fdt32_to_cpu(e->dt_offset); + dt_size = fdt32_to_cpu(e->dt_size); + unmap_sysmem(e); + + if (addr) + *addr = hdr_addr + dt_offset; + if (size) + *size = dt_size; + + return true; +} + +#if !defined(CONFIG_SPL_BUILD) +static void android_dt_print_fdt_info(const struct fdt_header *fdt) +{ + u32 fdt_size; + int root_node_off; + const char *compatible = NULL; + + fdt_size = fdt_totalsize(fdt); + root_node_off = fdt_path_offset(fdt, "/"); + if (root_node_off < 0) { + printf("Error: Root node not found\n"); + } else { + compatible = fdt_getprop(fdt, root_node_off, "compatible", + NULL); + } + + printf(" (FDT)size = %d\n", fdt_size); + printf(" (FDT)compatible = %s\n", + compatible ? compatible : "(unknown)"); +} + +/** + * Print information about DT image structure. + * + * @param hdr_addr Start address of DT image + */ +void android_dt_print_contents(ulong hdr_addr) +{ + const struct dt_table_header *hdr; + u32 entry_count, entries_offset, entry_size; + u32 i; + + hdr = map_sysmem(hdr_addr, sizeof(*hdr)); + entry_count = fdt32_to_cpu(hdr->dt_entry_count); + entries_offset = fdt32_to_cpu(hdr->dt_entries_offset); + entry_size = fdt32_to_cpu(hdr->dt_entry_size); + + /* Print image header info */ + printf("dt_table_header:\n"); + printf(" magic = %08x\n", fdt32_to_cpu(hdr->magic)); + printf(" total_size = %d\n", fdt32_to_cpu(hdr->total_size)); + printf(" header_size = %d\n", fdt32_to_cpu(hdr->header_size)); + printf(" dt_entry_size = %d\n", entry_size); + printf(" dt_entry_count = %d\n", entry_count); + printf(" dt_entries_offset = %d\n", entries_offset); + printf(" page_size = %d\n", fdt32_to_cpu(hdr->page_size)); + printf(" reserved[0] = %08x\n", fdt32_to_cpu(hdr->reserved[0])); + + unmap_sysmem(hdr); + + /* Print image entries info */ + for (i = 0; i < entry_count; ++i) { + const ulong e_addr = hdr_addr + entries_offset + i * entry_size; + const struct dt_table_entry *e; + const struct fdt_header *fdt; + u32 dt_offset, dt_size; + u32 j; + + e = map_sysmem(e_addr, sizeof(*e)); + dt_offset = fdt32_to_cpu(e->dt_offset); + dt_size = fdt32_to_cpu(e->dt_size); + + printf("dt_table_entry[%d]:\n", i); + printf(" dt_size = %d\n", dt_size); + printf(" dt_offset = %d\n", dt_offset); + printf(" id = %08x\n", fdt32_to_cpu(e->id)); + printf(" rev = %08x\n", fdt32_to_cpu(e->rev)); + for (j = 0; j < 4; ++j) { + printf(" custom[%d] = %08x\n", j, + fdt32_to_cpu(e->custom[j])); + } + + unmap_sysmem(e); + + /* Print FDT info for this entry */ + fdt = map_sysmem(hdr_addr + dt_offset, sizeof(*fdt)); + android_dt_print_fdt_info(fdt); + unmap_sysmem(fdt); + } +} +#endif diff --git a/include/image-android-dt.h b/include/image-android-dt.h new file mode 100644 index 0000000000..08b810d461 --- /dev/null +++ b/include/image-android-dt.h @@ -0,0 +1,21 @@ +/* + * (C) Copyright 2018 Linaro Ltd. + * Sam Protsenko + * + * SPDX-License-Identifier: GPL-2.0+ + */ + +#ifndef IMAGE_ANDROID_DT_H +#define IMAGE_ANDROID_DT_H + +#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); + +#if !defined(CONFIG_SPL_BUILD) +void android_dt_print_contents(ulong hdr_addr); +#endif + +#endif /* IMAGE_ANDROID_DT_H */ 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