From patchwork Mon Jul 8 20:25:44 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1129326 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=fail (p=none dis=none) header.from=chromium.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="iwcWSkyA"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 45jHNH08Zhz9sPP for ; Tue, 9 Jul 2019 06:38:38 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 48191C21E08; Mon, 8 Jul 2019 20:35:54 +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=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 5025FC21E73; Mon, 8 Jul 2019 20:28:44 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id CFA08C21E49; Mon, 8 Jul 2019 20:27:57 +0000 (UTC) Received: from mail-io1-f66.google.com (mail-io1-f66.google.com [209.85.166.66]) by lists.denx.de (Postfix) with ESMTPS id 145A6C21DD9 for ; Mon, 8 Jul 2019 20:27:54 +0000 (UTC) Received: by mail-io1-f66.google.com with SMTP id k8so38350278iot.1 for ; Mon, 08 Jul 2019 13:27:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=PkKcfou5MLatZeHuInncIZGRzDu8DzxY9EIew+jvEzY=; b=iwcWSkyAhiq57kEmJHlMWPoFLPqPU0Yabobh93hndKMszZY8XccE/tHP6qx2XBVpCk 01IRL45bE70hOn7inrSajyT6YIirDJYHXnffhuRGyQ9UkbY9ptBUKhPgjQgY5EWKqThO w4w+MtMIFi9SpJMarUsJ8EIpUo2WOam7bdIw4= 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:mime-version:content-transfer-encoding; bh=PkKcfou5MLatZeHuInncIZGRzDu8DzxY9EIew+jvEzY=; b=O3q5kk4QqRNkw6iVNV53xiqjLwqsKOibyutEpVPe5Cm89SIEXONoYa6w7yhH4+oXBe e5jSn+HwWKZmQBOzItU5kExLqKBIiDscE3TRG1+oAZ/NLTeZUi6dzQM7io41YyhW2tPX ACNVNZZBE8NpxncAX49IHgVy0qfnbpJYHcg5D/3NPN+wIzhIGjvqv712ZdsltKK96A3r qWleIjGZgsrXE2uOw+hM27zfHiBaHBDQ9Yoe1ja+wnY3538TgLMwzc+z4J2GODfQB0vQ XRa2HaAQeOfI7Qi7+c9DTAVY4EblqNBxuqSgURXy+U9oR+rHNvvG7PTDUFx2jbdDBEVV IGkA== X-Gm-Message-State: APjAAAW/Bb02x2wa+LYAYdEY1pOaQjq5aFp/zzh+xEqUKqwO+Ys9W/Tu JDBUB/07rT5TQtPmULo74boMAvC23+M= X-Google-Smtp-Source: APXvYqx0za/oWGIJwrqXih7yJL80jLGwz2n/LTEdvlyEYrfIlltOTNP3DZH8lw5nTddWM5nStoPwQg== X-Received: by 2002:a05:6602:2413:: with SMTP id s19mr7254361ioa.161.1562617672865; Mon, 08 Jul 2019 13:27:52 -0700 (PDT) Received: from kiwi.bld.corp.google.com ([2620:15c:183:0:8223:87c:a681:66aa]) by smtp.gmail.com with ESMTPSA id v13sm16692359ioq.13.2019.07.08.13.27.52 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Mon, 08 Jul 2019 13:27:52 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Date: Mon, 8 Jul 2019 14:25:44 -0600 Message-Id: <20190708202553.225715-23-sjg@chromium.org> X-Mailer: git-send-email 2.22.0.410.gd8fdbe21b5-goog In-Reply-To: <20190708202553.225715-1-sjg@chromium.org> References: <20190708202553.225715-1-sjg@chromium.org> MIME-Version: 1.0 Cc: Tom Rini Subject: [U-Boot] [PATCH v2 22/31] binman: Support locating an FDT map 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" Add support for locating an image's Fdt map which is used to determine the contents and structure of the image. Signed-off-by: Simon Glass Signed-off-by: Simon Glass --- Changes in v2: - Adjust LocateFdtmap() to return the position of the header - Update commit subject to more accurately describe this patch - Update test to use _DoReadFileRealDtb() helper tools/binman/etype/fdtmap.py | 25 ++++++++++++++++-- tools/binman/ftest.py | 15 +++++++++++ tools/binman/test/128_decode_image.dts | 36 ++++++++++++++++++++++++++ 3 files changed, 74 insertions(+), 2 deletions(-) create mode 100644 tools/binman/test/128_decode_image.dts diff --git a/tools/binman/etype/fdtmap.py b/tools/binman/etype/fdtmap.py index bfd7962be3a..08505264984 100644 --- a/tools/binman/etype/fdtmap.py +++ b/tools/binman/etype/fdtmap.py @@ -15,7 +15,26 @@ from fdt import Fdt import state import tools -FDTMAP_MAGIC = b'_FDTMAP_' +FDTMAP_MAGIC = b'_FDTMAP_' +FDTMAP_HDR_LEN = 16 + +def LocateFdtmap(data): + """Search an image for an fdt map + + Args: + data: Data to search + + Returns: + Position of fdt map in data, or None if not found. Note that the + position returned is of the FDT header, i.e. before the FDT data + """ + hdr_pos = data.find(FDTMAP_MAGIC) + size = len(data) + if hdr_pos: + hdr = data[hdr_pos:hdr_pos + FDTMAP_HDR_LEN] + if len(hdr) == FDTMAP_HDR_LEN: + return hdr_pos + return None class Entry_fdtmap(Entry): """An entry which contains an FDT map @@ -24,7 +43,9 @@ class Entry_fdtmap(Entry): None An FDT map is just a header followed by an FDT containing a list of all the - entries in the image. + entries in the image. The root node corresponds to the image node in the + original FDT, and an image-name property indicates the image name in that + original tree. The header is the string _FDTMAP_ followed by 8 unused bytes. diff --git a/tools/binman/ftest.py b/tools/binman/ftest.py index de459b2b3b6..d800ba1e9d8 100644 --- a/tools/binman/ftest.py +++ b/tools/binman/ftest.py @@ -24,6 +24,7 @@ import command import control import elf import fdt +from etype import fdtmap import fdt_util import fmap_util import test_util @@ -2267,6 +2268,20 @@ class TestFunctional(unittest.TestCase): self.assertEqual(len(data), 0x100 + section_size) self.assertEqual(section_size, 0x400 + dtb_size) + def testFindFdtmap(self): + """Test locating an FDT map in an image""" + self._CheckLz4() + data = self.data = self._DoReadFileRealDtb('128_decode_image.dts') + image = control.images['image'] + entries = image.GetEntries() + entry = entries['fdtmap'] + self.assertEqual(entry.image_pos, fdtmap.LocateFdtmap(data)) + + def testFindFdtmapMissing(self): + """Test failing to locate an FDP map""" + data = self._DoReadFile('005_simple.dts') + self.assertEqual(None, fdtmap.LocateFdtmap(data)) + if __name__ == "__main__": unittest.main() diff --git a/tools/binman/test/128_decode_image.dts b/tools/binman/test/128_decode_image.dts new file mode 100644 index 00000000000..449fccc41df --- /dev/null +++ b/tools/binman/test/128_decode_image.dts @@ -0,0 +1,36 @@ +// SPDX-License-Identifier: GPL-2.0+ + +/dts-v1/; + +/ { + #address-cells = <1>; + #size-cells = <1>; + + binman { + size = <0xc00>; + u-boot { + }; + section { + align = <0x100>; + cbfs { + size = <0x400>; + u-boot { + cbfs-type = "raw"; + }; + u-boot-dtb { + cbfs-type = "raw"; + cbfs-compress = "lzma"; + cbfs-offset = <0x80>; + }; + }; + u-boot-dtb { + compress = "lz4"; + }; + }; + fdtmap { + }; + image-header { + location = "end"; + }; + }; +};