From patchwork Sat Jul 20 18:23:55 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1134447 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="gQ+q6sZH"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 45rcBM5gRhz9s4Y for ; Sun, 21 Jul 2019 04:40:27 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 79C55C21E12; Sat, 20 Jul 2019 18:34:18 +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 2BF76C21ECC; Sat, 20 Jul 2019 18:26:21 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 254F4C21E0B; Sat, 20 Jul 2019 18:25:26 +0000 (UTC) Received: from mail-io1-f49.google.com (mail-io1-f49.google.com [209.85.166.49]) by lists.denx.de (Postfix) with ESMTPS id D9C6CC21C38 for ; Sat, 20 Jul 2019 18:25:19 +0000 (UTC) Received: by mail-io1-f49.google.com with SMTP id k8so65315057iot.1 for ; Sat, 20 Jul 2019 11:25:19 -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=x0As1i8unOheIB67FyhwN9Qkth9U0NpyrSmwPiqSg9Q=; b=gQ+q6sZHsm48xOp36/OXbg/26KamVf/bWi4Aa+g9dMyhVRC6MV9/oZmAp+FX274Pul KPdMLL1TqV6Gf2+ISq/58JT2+7sglcDLa9QN8H02mHUdCeVJTjtVpwFHQqiMjexQvm3Y rU2TwcSrXO5zD3Yw1jwwc1eivr8PComw+PQbQ= 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=x0As1i8unOheIB67FyhwN9Qkth9U0NpyrSmwPiqSg9Q=; b=Q3VCn//fJ4Lc2b8C0M6T185X1pU6DWaGq6oQxHDpIEIVS2hXofJ8fg/6XN4/pXW81h gHJlHEBOdsHpsb9zB/SQvIZJ3U/JGhxpIDqbkM6E0zQ5xGFa+B3FpBTgpOBgvhGZfgXb 7SYMNNRSuL9ZJmKC5P/lL4vDYeaNHXxzch9mTbwrbQ0Jef8TjQVlUI0aBbiiM5ELpPKS K1iQRkP4NLRgmMq3oVJ9lqICirpW78ZR0gYXqXVpsqEKiRV+tAKFCc7ZlKccuQJSW66w rFUuxANaqoVztEcjdPFAtvyAwZc3Xa7rzctQR8wv3mdHanaLbYphZcjHYj8KgaNicyIX YYbQ== X-Gm-Message-State: APjAAAVpZFZ5X03UtHp/z75FFrJJ6WXddnZ450RqAzKrxDPMgQ/yUT2O QcrkTAV89KsI+sNMAl39k7TdVZCs7zE= X-Google-Smtp-Source: APXvYqxLgY209NUQitArjJCPzJUMVbyIH4CdsRsPJPlsvpzx805WH+0HB0xSVJTofshmGNzTyA+cTw== X-Received: by 2002:a6b:f910:: with SMTP id j16mr27814687iog.256.1563647118638; Sat, 20 Jul 2019 11:25:18 -0700 (PDT) Received: from kiwi.bld.corp.google.com ([2620:15c:183:0:8223:87c:a681:66aa]) by smtp.gmail.com with ESMTPSA id z17sm49778933iol.73.2019.07.20.11.25.18 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Sat, 20 Jul 2019 11:25:18 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Date: Sat, 20 Jul 2019 12:23:55 -0600 Message-Id: <20190720182416.183626-34-sjg@chromium.org> X-Mailer: git-send-email 2.22.0.657.g960e92d24f-goog In-Reply-To: <20190720182416.183626-1-sjg@chromium.org> References: <20190720182416.183626-1-sjg@chromium.org> MIME-Version: 1.0 Subject: [U-Boot] [PATCH 33/53] binman: Add more tests for image header position 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" The positioning does not currently work correctly if at the end of an image with no fixed size. Also if the header is in the middle of an image it can cause a gap in the image since the header position is normally at the image end, so entries after it are placed after the end of the image. Fix these problems and add more tests to cover these cases. Signed-off-by: Simon Glass Signed-off-by: Simon Glass --- tools/binman/entry.py | 15 +++++++++++ tools/binman/etype/image_header.py | 16 ++++++++++-- tools/binman/etype/section.py | 9 +++++++ tools/binman/ftest.py | 25 +++++++++++++++++++ tools/binman/test/135_fdtmap_hdr_middle.dts | 16 ++++++++++++ tools/binman/test/136_fdtmap_hdr_startbad.dts | 16 ++++++++++++ tools/binman/test/137_fdtmap_hdr_endbad.dts | 16 ++++++++++++ tools/binman/test/138_fdtmap_hdr_nosize.dts | 16 ++++++++++++ 8 files changed, 127 insertions(+), 2 deletions(-) create mode 100644 tools/binman/test/135_fdtmap_hdr_middle.dts create mode 100644 tools/binman/test/136_fdtmap_hdr_startbad.dts create mode 100644 tools/binman/test/137_fdtmap_hdr_endbad.dts create mode 100644 tools/binman/test/138_fdtmap_hdr_nosize.dts diff --git a/tools/binman/entry.py b/tools/binman/entry.py index 74e280849c4..8dacc61f5a1 100644 --- a/tools/binman/entry.py +++ b/tools/binman/entry.py @@ -745,3 +745,18 @@ features to produce new behaviours. ok = self.ProcessContentsUpdate(data) self.Detail('WriteData: size=%x, ok=%s' % (len(data), ok)) return ok + + def GetSiblingOrder(self): + """Get the relative order of an entry amoung its siblings + + Returns: + 'start' if this entry is first among siblings, 'end' if last, + otherwise None + """ + entries = list(self.section.GetEntries().values()) + if entries: + if self == entries[0]: + return 'start' + elif self == entries[-1]: + return 'end' + return 'middle' diff --git a/tools/binman/etype/image_header.py b/tools/binman/etype/image_header.py index 8f9c5aa5d9e..4b69eda1a22 100644 --- a/tools/binman/etype/image_header.py +++ b/tools/binman/etype/image_header.py @@ -86,8 +86,20 @@ class Entry_image_header(Entry): if self.location not in ['start', 'end']: self.Raise("Invalid location '%s', expected 'start' or 'end'" % self.location) - image_size = self.section.GetImageSize() or 0 - self.offset = (0 if self.location != 'end' else image_size - 8) + order = self.GetSiblingOrder() + if self.location != order and not self.section.GetSort(): + self.Raise("Invalid sibling order '%s' for image-header: Must be at '%s' to match location" % + (order, self.location)) + if self.location != 'end': + offset = 0 + else: + image_size = self.section.GetImageSize() + if image_size is None: + # We don't know the image, but this must be the last entry, + # so we can assume it goes + offset = offset + else: + offset = image_size - IMAGE_HEADER_LEN return Entry.Pack(self, offset) def ProcessContents(self): diff --git a/tools/binman/etype/section.py b/tools/binman/etype/section.py index 0fb81419cea..3ce013d5029 100644 --- a/tools/binman/etype/section.py +++ b/tools/binman/etype/section.py @@ -479,3 +479,12 @@ class Entry_section(Entry): if not self.section: return self return self.section.GetImage() + + def GetSort(self): + """Check if the entries in this section will be sorted + + Returns: + True if to be sorted, False if entries will be left in the order + they appear in the device tree + """ + return self._sort diff --git a/tools/binman/ftest.py b/tools/binman/ftest.py index b67e8a15086..bc751893edb 100644 --- a/tools/binman/ftest.py +++ b/tools/binman/ftest.py @@ -2886,6 +2886,31 @@ class TestFunctional(unittest.TestCase): else: start += dtb._fdt_obj.totalsize() + def testFdtmapHeaderMiddle(self): + """Test an FDT map in the middle of an image when it should be at end""" + with self.assertRaises(ValueError) as e: + self._DoReadFileRealDtb('135_fdtmap_hdr_middle.dts') + self.assertIn("Invalid sibling order 'middle' for image-header: Must be at 'end' to match location", + str(e.exception)) + + def testFdtmapHeaderStartBad(self): + """Test an FDT map in middle of an image when it should be at start""" + with self.assertRaises(ValueError) as e: + self._DoReadFileRealDtb('136_fdtmap_hdr_startbad.dts') + self.assertIn("Invalid sibling order 'end' for image-header: Must be at 'start' to match location", + str(e.exception)) + + def testFdtmapHeaderEndBad(self): + """Test an FDT map at the start of an image when it should be at end""" + with self.assertRaises(ValueError) as e: + self._DoReadFileRealDtb('137_fdtmap_hdr_endbad.dts') + self.assertIn("Invalid sibling order 'start' for image-header: Must be at 'end' to match location", + str(e.exception)) + + def testFdtmapHeaderNoSize(self): + """Test an image header at the end of an image with undefined size""" + self._DoReadFileRealDtb('138_fdtmap_hdr_nosize.dts') + if __name__ == "__main__": unittest.main() diff --git a/tools/binman/test/135_fdtmap_hdr_middle.dts b/tools/binman/test/135_fdtmap_hdr_middle.dts new file mode 100644 index 00000000000..d6211da8ae3 --- /dev/null +++ b/tools/binman/test/135_fdtmap_hdr_middle.dts @@ -0,0 +1,16 @@ +/dts-v1/; + +/ { + #address-cells = <1>; + #size-cells = <1>; + + binman { + u-boot { + }; + image-header { + location = "end"; + }; + fdtmap { + }; + }; +}; diff --git a/tools/binman/test/136_fdtmap_hdr_startbad.dts b/tools/binman/test/136_fdtmap_hdr_startbad.dts new file mode 100644 index 00000000000..ec5f4bc7e3a --- /dev/null +++ b/tools/binman/test/136_fdtmap_hdr_startbad.dts @@ -0,0 +1,16 @@ +/dts-v1/; + +/ { + #address-cells = <1>; + #size-cells = <1>; + + binman { + u-boot { + }; + fdtmap { + }; + image-header { + location = "start"; + }; + }; +}; diff --git a/tools/binman/test/137_fdtmap_hdr_endbad.dts b/tools/binman/test/137_fdtmap_hdr_endbad.dts new file mode 100644 index 00000000000..ebacd71eb23 --- /dev/null +++ b/tools/binman/test/137_fdtmap_hdr_endbad.dts @@ -0,0 +1,16 @@ +/dts-v1/; + +/ { + #address-cells = <1>; + #size-cells = <1>; + + binman { + image-header { + location = "end"; + }; + u-boot { + }; + fdtmap { + }; + }; +}; diff --git a/tools/binman/test/138_fdtmap_hdr_nosize.dts b/tools/binman/test/138_fdtmap_hdr_nosize.dts new file mode 100644 index 00000000000..c362f8fdffb --- /dev/null +++ b/tools/binman/test/138_fdtmap_hdr_nosize.dts @@ -0,0 +1,16 @@ +/dts-v1/; + +/ { + #address-cells = <1>; + #size-cells = <1>; + + binman { + u-boot { + }; + fdtmap { + }; + image-header { + location = "end"; + }; + }; +};