From patchwork Mon Jul 8 20:25:41 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1129339 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="eYjUGrCr"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 45jHTb46yTz9s00 for ; Tue, 9 Jul 2019 06:43:15 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 342B5C21E57; Mon, 8 Jul 2019 20:35: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=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 A7CEFC21DFA; Mon, 8 Jul 2019 20:28:43 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 6C91FC21E7E; Mon, 8 Jul 2019 20:27:55 +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 F1029C21DB5 for ; Mon, 8 Jul 2019 20:27:51 +0000 (UTC) Received: by mail-io1-f66.google.com with SMTP id g20so17158144ioc.12 for ; Mon, 08 Jul 2019 13:27:51 -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=Rsu822KKfI7hrrvoNlD878tdYpJHJ9CvFRjEeovy1xs=; b=eYjUGrCrkZTqJWlO+xe4FCAiTH0qABAaOP3FvdFK5bKmk3ISVTtfFTEC/+L4wetwH1 m/UqekO+qxfQgKg+eSo+qS3Ag41Pd9FlWsm8yfxZjsjx9lrhdeYN/N8REGMikmFKgZim 4q/xLwzeHieUqe2iMJ+bE7gHq4QKfyqUWoQ/s= 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=Rsu822KKfI7hrrvoNlD878tdYpJHJ9CvFRjEeovy1xs=; b=AFnppBSPG4hshnM5z47eUmoIYgUDPOS+TiZZ2FyFSkuqAzRhJikn8c7Whr85MWahKt mccBHuEdhQHtRVYFPE7Ds7tUN3WFwWGWgwiMul5+i7OYZEBT5TxVEHcwGAFrQqJPdM5K q+y+fVso9n6tJS4uhlI5me6791b2hZ9nRJrI9n4DmwuU5nyVxpu1L+cJBPRc2mi1AYVm T5LxhD+qjWftOQ+WEHfKQpjm6uo0iMJDC3Zl3uR5peDFjWRqXLVMEXKFxjqP8e/0L4hb RY7KysKPa0Re2l+7kff/S7LaX5nJm77OjDOKd1l8POGnHkk9LYb3uPc5o5tSJ40qn9QR 5vng== X-Gm-Message-State: APjAAAUb1KUnyPYANiUz3nuwyCLfsKgsj7ke5YSXf67s5CwdXimsp3+N v0kekLIT+ttvzPTOIaT2MocClONYQms= X-Google-Smtp-Source: APXvYqzOpMXF9IC/dEkiZk6XPVfiaNiqe1dPJV59X6oN6Hedw9GwIJh1ir+NaTUq4/jC7zzG+TQBUA== X-Received: by 2002:a5d:8451:: with SMTP id w17mr22324944ior.226.1562617670695; Mon, 08 Jul 2019 13:27:50 -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.50 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Mon, 08 Jul 2019 13:27:50 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Date: Mon, 8 Jul 2019 14:25:41 -0600 Message-Id: <20190708202553.225715-20-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 19/31] binman: Support FDT update for CBFS 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" It is useful to add the CBFS file information (offset, size, etc.) into the FDT so that the layout is complete. Add support for this. Signed-off-by: Simon Glass Signed-off-by: Simon Glass --- Changes in v2: None tools/binman/etype/cbfs.py | 49 +++++++++++++++++++++++++-- tools/binman/ftest.py | 25 ++++++++++++++ tools/binman/test/125_cbfs_update.dts | 21 ++++++++++++ 3 files changed, 92 insertions(+), 3 deletions(-) create mode 100644 tools/binman/test/125_cbfs_update.dts diff --git a/tools/binman/etype/cbfs.py b/tools/binman/etype/cbfs.py index 49baa6a4f63..a46bb98a033 100644 --- a/tools/binman/etype/cbfs.py +++ b/tools/binman/etype/cbfs.py @@ -11,6 +11,7 @@ import cbfs_util from cbfs_util import CbfsWriter from entry import Entry import fdt_util +import state class Entry_cbfs(Entry): """Entry containing a Coreboot Filesystem (CBFS) @@ -181,11 +182,17 @@ class Entry_cbfs(Entry): if not entry.ObtainContents(): return False data = entry.GetData() + cfile = None if entry._type == 'raw': - cbfs.add_file_raw(entry._cbfs_name, data, entry._cbfs_offset, - entry._cbfs_compress) + cfile = cbfs.add_file_raw(entry._cbfs_name, data, + entry._cbfs_offset, + entry._cbfs_compress) elif entry._type == 'stage': - cbfs.add_file_stage(entry._cbfs_name, data, entry._cbfs_offset) + cfile = cbfs.add_file_stage(entry._cbfs_name, data, + entry._cbfs_offset) + if cfile: + entry._cbfs_file = cfile + entry.size = cfile.data_len data = cbfs.get_data() self.SetContents(data) return True @@ -203,3 +210,39 @@ class Entry_cbfs(Entry): self.Raise("Invalid compression in '%s': '%s'" % (node.name, compress)) self._cbfs_entries[entry._cbfs_name] = entry + + def SetImagePos(self, image_pos): + """Override this function to set all the entry properties from CBFS + + We can only do this once image_pos is known + + Args: + image_pos: Position of this entry in the image + """ + Entry.SetImagePos(self, image_pos) + + # Now update the entries with info from the CBFS entries + for entry in self._cbfs_entries.values(): + cfile = entry._cbfs_file + entry.size = cfile.data_len + entry.offset = cfile.calced_cbfs_offset + entry.image_pos = self.image_pos + entry.offset + if entry._cbfs_compress: + entry.uncomp_size = cfile.memlen + + def AddMissingProperties(self): + Entry.AddMissingProperties(self) + for entry in self._cbfs_entries.values(): + entry.AddMissingProperties() + if entry._cbfs_compress: + state.AddZeroProp(entry._node, 'uncomp-size') + + def SetCalculatedProperties(self): + """Set the value of device-tree properties calculated by binman""" + Entry.SetCalculatedProperties(self) + for entry in self._cbfs_entries.values(): + state.SetInt(entry._node, 'offset', entry.offset) + state.SetInt(entry._node, 'size', entry.size) + state.SetInt(entry._node, 'image-pos', entry.image_pos) + if entry.uncomp_size is not None: + state.SetInt(entry._node, 'uncomp-size', entry.uncomp_size) diff --git a/tools/binman/ftest.py b/tools/binman/ftest.py index 89e732fca31..999d8884aca 100644 --- a/tools/binman/ftest.py +++ b/tools/binman/ftest.py @@ -2160,6 +2160,31 @@ class TestFunctional(unittest.TestCase): } self.assertEqual(expected, props) + def testCbfsUpdateFdt(self): + """Test that we can update the device tree with CBFS offset/size info""" + self._CheckLz4() + data, _, _, out_dtb_fname = self._DoReadFileDtb('125_cbfs_update.dts', + update_dtb=True) + dtb = fdt.Fdt(out_dtb_fname) + dtb.Scan() + props = self._GetPropTree(dtb, ['offset', 'size', 'image-pos', + 'uncomp-size']) + del props['cbfs/u-boot:size'] + self.assertEqual({ + 'offset': 0, + 'size': len(data), + 'image-pos': 0, + 'cbfs:offset': 0, + 'cbfs:size': len(data), + 'cbfs:image-pos': 0, + 'cbfs/u-boot:offset': 0x38, + 'cbfs/u-boot:uncomp-size': len(U_BOOT_DATA), + 'cbfs/u-boot:image-pos': 0x38, + 'cbfs/u-boot-dtb:offset': 0xb8, + 'cbfs/u-boot-dtb:size': len(U_BOOT_DATA), + 'cbfs/u-boot-dtb:image-pos': 0xb8, + }, props) + if __name__ == "__main__": unittest.main() diff --git a/tools/binman/test/125_cbfs_update.dts b/tools/binman/test/125_cbfs_update.dts new file mode 100644 index 00000000000..6d2e8a0b8ff --- /dev/null +++ b/tools/binman/test/125_cbfs_update.dts @@ -0,0 +1,21 @@ +// SPDX-License-Identifier: GPL-2.0+ + +/dts-v1/; + +/ { + #address-cells = <1>; + #size-cells = <1>; + + binman { + cbfs { + size = <0x100>; + u-boot { + cbfs-type = "raw"; + cbfs-compress = "lz4"; + }; + u-boot-dtb { + cbfs-type = "raw"; + }; + }; + }; +};