From patchwork Wed Jun 6 00:46:37 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 925667 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" (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.b="So4H5zh3"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 410qlV16Ngz9s02 for ; Wed, 6 Jun 2018 10:47:50 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id D176FC21E90; Wed, 6 Jun 2018 00:47:42 +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_DNSWL_BLOCKED, RCVD_IN_MSPIKE_H2, 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 5C8C1C21F8A; Wed, 6 Jun 2018 00:47:23 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 9887CC21E88; Wed, 6 Jun 2018 00:47:21 +0000 (UTC) Received: from mail-io0-f196.google.com (mail-io0-f196.google.com [209.85.223.196]) by lists.denx.de (Postfix) with ESMTPS id A79FDC21F1A for ; Wed, 6 Jun 2018 00:47:15 +0000 (UTC) Received: by mail-io0-f196.google.com with SMTP id u4-v6so5654525iof.2 for ; Tue, 05 Jun 2018 17:47:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=AoLwckmbFbsyUYwpde0Oj6WQqHXC4a6F3N9RU8UIfP8=; b=So4H5zh3X66Oc8ewFprPbdauRQqZE5gcso7/3I4w3AHHnT7EPsJKY636jS1d8HjaRA gEQEInuXjbQsS4lxIH98mprbWUWhayCSMuYvqsyHiZrabq4VOuVtQvrHjVWSubjSlw/C O5A8KkEste0Zq5qEX+eJk9hFV7YHlw+c/L5EjK9T5XWRugEdDmpuc7mrXbdDn34Mf92l ivWbv3sp9byN058wnzdqOJxo1q2y2mh2TdFy7prCYhVUIJOyHrpyvdgu+sKRcTeSLw1v aLtN+df47Hvx6Rgs2QhvEiFPh+EwB2wyNldsZh0lEmCGZKafJjG7nZkh++NznC2QoWK5 Ut3Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=AoLwckmbFbsyUYwpde0Oj6WQqHXC4a6F3N9RU8UIfP8=; b=mTljaisH1oTbOKLP6QL1qyek4WfUvwRz/sBC+wVA7LrrYN/MuPC4v5wnN2sHxJIEGn UqmjD51iYAiTa7ZQmzT4Lam/H6K9Yk5DqRhpkwd6I5JfWEU0SX99+7s/ZiC2Hgnhs9WP FBEZ3HGoRis1XiHJdWUfdzl/t4VxsvPl1y3Mczad88oRkTXcaZEm0jzXDfl1YzgP2cS+ 9/SJxh88ejWorJHMW2igO9V8zpqUaDcGaokzmTA7BHX+ZeOh4fnBstwBpXfzqKZpLE+f tMZ8muFAR9v5bfu+gIQCOSZwNXtkW6XOkLmvkNqZ+mSung1GYik3viGZ7O3n4+Sa0S+e RXNQ== X-Gm-Message-State: APt69E3CAQgv1aR+GXV570g8F6wo4E/iWSamjSRVdl9dtT+dbA8xb8Y9 ifyvwGe08EMxO/UQQOnw6p3AZA== X-Google-Smtp-Source: ADUXVKKFKX0c3NVsLqOqB2DULJ9Cw0vo1jrzCjRSs/inWd05jEjzzQ5qTGszy71SECzH2IGlLZlB2g== X-Received: by 2002:a6b:e89:: with SMTP id 131-v6mr870695ioo.69.1528246034093; Tue, 05 Jun 2018 17:47:14 -0700 (PDT) Received: from kiwi.bld.corp.google.com ([2620:15c:183:0:8223:87c:a681:66aa]) by smtp.gmail.com with ESMTPSA id i143-v6sm1157574iti.18.2018.06.05.17.47.11 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 05 Jun 2018 17:47:11 -0700 (PDT) Received: by kiwi.bld.corp.google.com (Postfix, from userid 121222) id 0E3C91409F9; Tue, 5 Jun 2018 18:47:11 -0600 (MDT) From: Simon Glass To: U-Boot Mailing List Date: Tue, 5 Jun 2018 18:46:37 -0600 Message-Id: <20180606004705.79641-2-sjg@chromium.org> X-Mailer: git-send-email 2.17.1.1185.g55be947832-goog In-Reply-To: <20180606004705.79641-1-sjg@chromium.org> References: <20180606004705.79641-1-sjg@chromium.org> Cc: Tom Rini Subject: [U-Boot] [PATCH 01/29] binman: Switch to 'python-coverage' 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" From: Tom Rini The most portable way to get access to coverage is to invoke it as 'python-coverage'. Cc: Simon Glass Signed-off-by: Tom Rini Signed-off-by: Simon Glass --- tools/binman/README | 3 +-- tools/binman/binman.py | 4 ++-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/tools/binman/README b/tools/binman/README index 22f21bc5b44..f74e39242f6 100644 --- a/tools/binman/README +++ b/tools/binman/README @@ -583,8 +583,7 @@ implementations target 100% test coverage. Run 'binman -T' to check this. To enable Python test coverage on Debian-type distributions (e.g. Ubuntu): - $ sudo apt-get install python-pip python-pytest - $ sudo pip install coverage + $ sudo apt-get install python-coverage python-pytest Advanced Features / Technical docs diff --git a/tools/binman/binman.py b/tools/binman/binman.py index 31b045337d2..f3044ca2124 100755 --- a/tools/binman/binman.py +++ b/tools/binman/binman.py @@ -81,11 +81,11 @@ def RunTests(debug, args): def RunTestCoverage(): """Run the tests and check that we get 100% coverage""" # This uses the build output from sandbox_spl to get _libfdt.so - cmd = ('PYTHONPATH=$PYTHONPATH:%s/sandbox_spl/tools coverage run ' + cmd = ('PYTHONPATH=$PYTHONPATH:%s/sandbox_spl/tools python-coverage run ' '--include "tools/binman/*.py" --omit "*test*,*binman.py" ' 'tools/binman/binman.py -t' % options.build_dir) os.system(cmd) - stdout = command.Output('coverage', 'report') + stdout = command.Output('python-coverage', 'report') lines = stdout.splitlines() test_set= set([os.path.basename(line.split()[0]) From patchwork Wed Jun 6 00:46:38 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 925669 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" (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.b="tGsltdAY"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 410qnk29phz9s02 for ; Wed, 6 Jun 2018 10:49:46 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id ED9EFC22004; Wed, 6 Jun 2018 00:48: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=RCVD_IN_DNSWL_BLOCKED, 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 18024C21F9F; Wed, 6 Jun 2018 00:47:33 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id C99C4C21FB3; Wed, 6 Jun 2018 00:47:22 +0000 (UTC) Received: from mail-it0-f66.google.com (mail-it0-f66.google.com [209.85.214.66]) by lists.denx.de (Postfix) with ESMTPS id DD487C21F67 for ; Wed, 6 Jun 2018 00:47:16 +0000 (UTC) Received: by mail-it0-f66.google.com with SMTP id v83-v6so5838453itc.3 for ; Tue, 05 Jun 2018 17:47:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=YJzoB5tKWiSu4e/2bONHfbQelCMxFLKj6RgOQX6YYVQ=; b=tGsltdAYLJ2nVpr6O8fvkYeKPmPRJfS2oMyoP4LMpLlf+U9WnzN/SmN9rKcscQtSRJ kQfuaWW/onSPakQgDGHTwe7BbvVNQIDzinP3VxsxCRNG1w5i1ZZvc7fkM2pBymMG95Af iIs1UUhKfEn/xRvU3WDgvXIXCv/Oc/lUz/IK7cDD4JJZOl8sGLbRWtIpgvOFD5ZhaEj4 Izm2PDDemSeGsTuH9Z9XRmAvqnfrmmvHfNWg7YuNZmbRsMAGmY7Oog/mMoqupeckCj43 QRtDiHzPofjEw79eTuIurDQV7FepMkktr9sWO2IqJHJ85mtydFPiwCj9MdwzDWlubF7W Tq8Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=YJzoB5tKWiSu4e/2bONHfbQelCMxFLKj6RgOQX6YYVQ=; b=E+va20ZthsXP5L/SaY3j4fr1cn1iEofRu7HuXurrhZ6kRW+qx7rxYG0DaOhtdglIPK /Gnay1ZaY68pwnbjru9v4CXqm3E/Ks4Boz+ybtLYvuLS40/2DcwQHSvI7ByOPkPmaO9j Gd1KPJ5uJ6WJguLzzR+d5ldnZ/lG8O2TrswuaS5gr8ZVtVN17zA5IyWNeFSNFGP5Vm34 63Al48op2NZArlUe6qrLUJwLC6FIJ7WSeDjUO0UL7gWDfhgu1St6upxwtIGKznkehgAa edtdUpL074/EJVt7cFC4padAbppJW1VKhQoz1YkiseGVovHuzu3PnfGMSdyIYLFUewo3 Sa8Q== X-Gm-Message-State: APt69E0jsdKAhG1sJ1P4FgD6/nV5j0gSSNb+7TPXeWEZYxVwL6DlCmxl DrZa2SHRp72KMkSeNV2LpnyDWw== X-Google-Smtp-Source: ADUXVKJ/IMMnap+02Au6o8qci88B737snkiUYJvm1h7s2LGPc5Nf/zE2J0PYIJbfWZ8d3e5UP/7IJA== X-Received: by 2002:a24:19ca:: with SMTP id b193-v6mr466614itb.135.1528246035140; Tue, 05 Jun 2018 17:47:15 -0700 (PDT) Received: from kiwi.bld.corp.google.com ([100.67.80.24]) by smtp.gmail.com with ESMTPSA id p20-v6sm126697itf.4.2018.06.05.17.47.13 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 05 Jun 2018 17:47:14 -0700 (PDT) Received: by kiwi.bld.corp.google.com (Postfix, from userid 121222) id C4BDB140700; Tue, 5 Jun 2018 18:47:12 -0600 (MDT) From: Simon Glass To: U-Boot Mailing List Date: Tue, 5 Jun 2018 18:46:38 -0600 Message-Id: <20180606004705.79641-3-sjg@chromium.org> X-Mailer: git-send-email 2.17.1.1185.g55be947832-goog In-Reply-To: <20180606004705.79641-1-sjg@chromium.org> References: <20180606004705.79641-1-sjg@chromium.org> Cc: Tom Rini Subject: [U-Boot] [PATCH 02/29] binman: Make the operation of Entry__testing explicit 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" This fake entry is used for testing. At present it only has one behaviour which is to return an invalid set of entry positions, to cause an error. The fake entry will need to be used for other things too. Allow the test .dts file to specify the behaviour of the fake entry, so we can control its behaviour easily. While we are here, drop the ReadContents() method, since this only applies to subclasses of Entry_blob, which Entry__testing is not. Signed-off-by: Simon Glass --- tools/binman/etype/_testing.py | 14 ++++++++++---- tools/binman/test/41_unknown_pos_size.dts | 1 + 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/tools/binman/etype/_testing.py b/tools/binman/etype/_testing.py index c376dd5c9ca..0b1eaefc3ce 100644 --- a/tools/binman/etype/_testing.py +++ b/tools/binman/etype/_testing.py @@ -10,16 +10,22 @@ import fdt_util import tools class Entry__testing(Entry): + """A fake entry used for testing + + Properties: + return_invalid_entry: Return an invalid entry from GetPositions() + """ def __init__(self, section, etype, node): Entry.__init__(self, section, etype, node) + self.return_invalid_entry = fdt_util.GetBool(self._node, + 'return-invalid-entry') def ObtainContents(self): self.data = 'a' self.contents_size = len(self.data) return True - def ReadContents(self): - return True - def GetPositions(self): - return {'invalid-entry': [1, 2]} + if self.return_invalid_entry : + return {'invalid-entry': [1, 2]} + return {} diff --git a/tools/binman/test/41_unknown_pos_size.dts b/tools/binman/test/41_unknown_pos_size.dts index a8e7d8aa227..94fe821c470 100644 --- a/tools/binman/test/41_unknown_pos_size.dts +++ b/tools/binman/test/41_unknown_pos_size.dts @@ -6,6 +6,7 @@ binman { _testing { + return-invalid-entry; }; }; }; From patchwork Wed Jun 6 00:46:39 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 925668 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" (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.b="hTwRJeE4"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 410qn71y2Gz9s08 for ; Wed, 6 Jun 2018 10:49:15 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id DE223C21F8A; Wed, 6 Jun 2018 00:47:59 +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_DNSWL_BLOCKED, 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 43D13C21F99; Wed, 6 Jun 2018 00:47:28 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 6E362C21F2A; Wed, 6 Jun 2018 00:47:23 +0000 (UTC) Received: from mail-it0-f49.google.com (mail-it0-f49.google.com [209.85.214.49]) by lists.denx.de (Postfix) with ESMTPS id C80ACC21F94 for ; Wed, 6 Jun 2018 00:47:18 +0000 (UTC) Received: by mail-it0-f49.google.com with SMTP id p185-v6so5836198itp.4 for ; Tue, 05 Jun 2018 17:47:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=tnWyKs8x25T1ieOYar1FUQpHTXcNakAG75nlM0Si9ag=; b=hTwRJeE4XxlnE25OBR4RuAkuujIfXpkrZ6OIGHEqhHUUvQJMrSYQaDXha0Uc9t+qnV uWZyDDxzHCTj0gM+HET7SpcYSpNbl3rQ26ugPb22B8Af2y+nqIvrDjjPZ9gErRuw5Pxx 8Z12V2AKj5bhhszinRbNpqG0SN4DGlI3dajIMHwrgiXfqXQKJRJLY0K8dngjK4Zqpm6Z Js5R1XGSixV+uY71RwJVfBEfQ5zqERvAEILw6FMQ5HhzJlmzKPzqrjplaa2IypLkJ1FE U+PqRpol2Vw1yHRuiLXDR6KJY3GsNVWH65jFO+fvYNQYa6K8PLkZo4hll6VvmbGmzVCL wDYw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=tnWyKs8x25T1ieOYar1FUQpHTXcNakAG75nlM0Si9ag=; b=EFVC2yOn2i9MQlpzcLOBxeGflV32yBKgMG5FExjmp/KKKbLMohj3NeKXjqCh8OYwhN xg/Jgof6zJ5410CsISMbAqH2tkELZf6OIr7M+ll/FatvWZxAVvlHxE932CxM+CgBqsHH 1Zj0U3UgFIVYpT6ot1EAfUGLYOeiprbGLHtXgn3OPdO5tguXV7Q0kkXsgknImp0eFTW9 5szbwTHkAEDl2m+bE7oRHbN2x4ltBeEGp5/0jb0zphS8SUkOsTJNK0Dyf+Rp9fNfTTNs k1ykMsWKJbNeHcPgG3DlKwOadI2+CHIhS9EC9Mej+T7DmXeWS1WV+gNYw+xbUSw7F0U/ wEzA== X-Gm-Message-State: APt69E2SIGzG8aTj+zeV9jUtX0FrY4BNTONMcV+0OzmvKt9UixaWyb27 M70ViH3MLqlcCvB99v4KDag5aZRSYQI= X-Google-Smtp-Source: ADUXVKIvFGIvfVw2NlVoAzRHWC+y3JOx9gwaYlqzhSvAJrQo5gdskG+xLUYwyL7w4Y6AuwZn3kK73w== X-Received: by 2002:a24:1249:: with SMTP id 70-v6mr503486itp.82.1528246037160; Tue, 05 Jun 2018 17:47:17 -0700 (PDT) Received: from kiwi.bld.corp.google.com ([2620:15c:183:0:8223:87c:a681:66aa]) by smtp.gmail.com with ESMTPSA id v144-v6sm1267503itc.31.2018.06.05.17.47.15 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 05 Jun 2018 17:47:15 -0700 (PDT) Received: by kiwi.bld.corp.google.com (Postfix, from userid 121222) id 1EC4F1409F9; Tue, 5 Jun 2018 18:47:15 -0600 (MDT) From: Simon Glass To: U-Boot Mailing List Date: Tue, 5 Jun 2018 18:46:39 -0600 Message-Id: <20180606004705.79641-4-sjg@chromium.org> X-Mailer: git-send-email 2.17.1.1185.g55be947832-goog In-Reply-To: <20180606004705.79641-1-sjg@chromium.org> References: <20180606004705.79641-1-sjg@chromium.org> Cc: Tom Rini Subject: [U-Boot] [PATCH 03/29] binman: Tidy up variables in _RunMicrocodeTest() 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" At present we call the three entries first, second and third. Rename them to reflect their contents instead, for clarity. Signed-off-by: Simon Glass --- tools/binman/ftest.py | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/tools/binman/ftest.py b/tools/binman/ftest.py index eb8a0793cbe..80eadeffab8 100644 --- a/tools/binman/ftest.py +++ b/tools/binman/ftest.py @@ -689,29 +689,40 @@ class TestFunctional(unittest.TestCase): self.assertEqual(X86_START16_DATA, data[:len(X86_START16_DATA)]) def _RunMicrocodeTest(self, dts_fname, nodtb_data): + """Handle running a test for insertion of microcode + + Args: + dts_fname: Name of test .dts file + nodtb_data: Data that we expect in the first section + + Returns: + Tuple: + Contents of first region (U-Boot or SPL) + Position and size components of microcode pointer, as inserted + in the above (two 4-byte words) + """ data = self._DoReadFile(dts_fname, True) # Now check the device tree has no microcode - second = data[len(nodtb_data):] + dtb_with_ucode = data[len(nodtb_data):] + fdt_len = self.GetFdtLen(dtb_with_ucode) + ucode_content = dtb_with_ucode[fdt_len:] + ucode_pos = len(nodtb_data) + fdt_len fname = tools.GetOutputFilename('test.dtb') with open(fname, 'wb') as fd: - fd.write(second) + fd.write(dtb_with_ucode) dtb = fdt.FdtScan(fname) ucode = dtb.GetNode('/microcode') self.assertTrue(ucode) for node in ucode.subnodes: self.assertFalse(node.props.get('data')) - fdt_len = self.GetFdtLen(second) - third = second[fdt_len:] - # Check that the microcode appears immediately after the Fdt # This matches the concatenation of the data properties in # the /microcode/update@xxx nodes in 34_x86_ucode.dts. ucode_data = struct.pack('>4L', 0x12345678, 0x12345679, 0xabcd0000, 0x78235609) - self.assertEqual(ucode_data, third[:len(ucode_data)]) - ucode_pos = len(nodtb_data) + fdt_len + self.assertEqual(ucode_data, ucode_content[:len(ucode_data)]) # Check that the microcode pointer was inserted. It should match the # expected position and size From patchwork Wed Jun 6 00:46:40 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 925671 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" (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.b="POeJjQqC"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 410qrg4CF5z9s02 for ; Wed, 6 Jun 2018 10:52:19 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 3DEA3C21FCE; Wed, 6 Jun 2018 00:48:37 +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_DNSWL_BLOCKED, RCVD_IN_MSPIKE_H2, 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 EFA35C21F84; Wed, 6 Jun 2018 00:47:42 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 48BD1C21F6E; Wed, 6 Jun 2018 00:47:26 +0000 (UTC) Received: from mail-io0-f177.google.com (mail-io0-f177.google.com [209.85.223.177]) by lists.denx.de (Postfix) with ESMTPS id 7AE82C21EF0 for ; Wed, 6 Jun 2018 00:47:21 +0000 (UTC) Received: by mail-io0-f177.google.com with SMTP id t6-v6so5634108iob.10 for ; Tue, 05 Jun 2018 17:47:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=VFAZYc0jDX6xUnMb+r6O8Yok+UP8lT2I+cFJDCnmcY4=; b=POeJjQqC5jMRyvSEUD/zTgJw3dc50Kpc+zDJlvAaxdYK3T8K7JrsNc3sIRU4yZpsut jXAEi8zVqn4PB0lxpCcGKC4yfNTS9h3qrMxvPQLqR9w8N5y9mRUEyHN80yo/ZzjOzfDd MbWq65WL3SYQx0KxgAYEhEqDQ2am2ZsX9rjAfhbzq+oWaLflBuQ3kuNJmqEUoWQB0ZDu o7Q4jbiRV3U19PC7M4FIO6bNueHEBYuhrtKLc4/s6aZ2R5AFzULKOGFaZQCyiRdJ2ADj +dGQb6aNyHmWUf9+/0tvWZZ3pAn0N9oZk/mra5kyc2Ia9sD/LOxlY84aZrOdMBeLQa2m TkZA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=VFAZYc0jDX6xUnMb+r6O8Yok+UP8lT2I+cFJDCnmcY4=; b=kYxlql2Hq/nX0oAtkptrIXuXVagTIeMTPptHrf74sQYxinVcTDZlOy3MNaSnrjB2T+ zMFMMoVaL1NJrP21c2hc1dgu3bfRk8JwDx+mTVtsFYCPhh4ZZHrSjCg9c6Ukp6/9zEH8 CAL18x+wPqZoFPudDeHinbG1+Ze2u5DxQ4sug9VdhHSqX/9jFTOhUtang+t/cw1+NIkE xavrvh0K2buER3nXUjC2EIA+w6I6nWlyW31NJUR73ZVZlr5Z9JF1mSmSP46vD339BouB zHDS5A0BNvh+6pHMMNP23IVGR0lGIybOCxOND71FdPFUjhLYwKSlqpeiynI+N7XstvX9 TYNQ== X-Gm-Message-State: APt69E2FXWmlyL29RRCuhgjZklTtorUiut9Tfzq7aDcOgx0jiJwdCRJA iaLKzcXdcaW37RaUlpff1+nu3g== X-Google-Smtp-Source: ADUXVKJFzm7Vvi2QJFfCof0wctOuTPbRpZ/DYPkKVhxAfZhuvf5qIqFsomNxV9GJu05JKxSRzbZVtg== X-Received: by 2002:a6b:a510:: with SMTP id o16-v6mr788481ioe.271.1528246039732; Tue, 05 Jun 2018 17:47:19 -0700 (PDT) Received: from kiwi.bld.corp.google.com ([100.67.80.24]) by smtp.gmail.com with ESMTPSA id u8-v6sm6085287iol.6.2018.06.05.17.47.17 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 05 Jun 2018 17:47:17 -0700 (PDT) Received: by kiwi.bld.corp.google.com (Postfix, from userid 121222) id 226D8140700; Tue, 5 Jun 2018 18:47:17 -0600 (MDT) From: Simon Glass To: U-Boot Mailing List Date: Tue, 5 Jun 2018 18:46:40 -0600 Message-Id: <20180606004705.79641-5-sjg@chromium.org> X-Mailer: git-send-email 2.17.1.1185.g55be947832-goog In-Reply-To: <20180606004705.79641-1-sjg@chromium.org> References: <20180606004705.79641-1-sjg@chromium.org> Cc: Tom Rini Subject: [U-Boot] [PATCH 04/29] binman: Correct operation of ObtainContents() 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" This method is supposed to return the contents of an entry. However at present there is no check that it actually does. Also some implementations do not return 'True' to indicate success, as required. Add a check for things working as expected, and correct the implementations. This requires some additional test cases to cover things which were missed originally. Add these at the same time. Signed-off-by: Simon Glass --- tools/binman/bsection.py | 4 ++ tools/binman/etype/_testing.py | 5 ++ tools/binman/etype/section.py | 2 +- tools/binman/etype/u_boot_spl_bss_pad.py | 1 + tools/binman/etype/u_boot_ucode.py | 9 ++- tools/binman/ftest.py | 57 +++++++++++++++---- tools/binman/test/57_unknown_contents.dts | 14 +++++ .../test/58_x86_ucode_spl_needs_retry.dts | 36 ++++++++++++ 8 files changed, 114 insertions(+), 14 deletions(-) create mode 100644 tools/binman/test/57_unknown_contents.dts create mode 100644 tools/binman/test/58_x86_ucode_spl_needs_retry.dts diff --git a/tools/binman/bsection.py b/tools/binman/bsection.py index 3f30f6e4fe7..06a6711350a 100644 --- a/tools/binman/bsection.py +++ b/tools/binman/bsection.py @@ -162,6 +162,10 @@ class Section(object): todo = next_todo if not todo: break + if todo: + self._Raise('Internal error: Could not complete processing of ' + 'contents: remaining %s' % todo) + return True def _SetEntryPosSize(self, name, pos, size): """Set the position and size of an entry diff --git a/tools/binman/etype/_testing.py b/tools/binman/etype/_testing.py index 0b1eaefc3ce..c075c3ff0d9 100644 --- a/tools/binman/etype/_testing.py +++ b/tools/binman/etype/_testing.py @@ -9,6 +9,7 @@ from entry import Entry import fdt_util import tools + class Entry__testing(Entry): """A fake entry used for testing @@ -19,8 +20,12 @@ class Entry__testing(Entry): Entry.__init__(self, section, etype, node) self.return_invalid_entry = fdt_util.GetBool(self._node, 'return-invalid-entry') + self.return_unknown_contents = fdt_util.GetBool(self._node, + 'return-unknown-contents') def ObtainContents(self): + if self.return_unknown_contents: + return False self.data = 'a' self.contents_size = len(self.data) return True diff --git a/tools/binman/etype/section.py b/tools/binman/etype/section.py index 139fcad51af..36b31a849f8 100644 --- a/tools/binman/etype/section.py +++ b/tools/binman/etype/section.py @@ -18,7 +18,7 @@ class Entry_section(Entry): self._section = bsection.Section(node.name, node) def ObtainContents(self): - self._section.GetEntryContents() + return self._section.GetEntryContents() def GetData(self): return self._section.GetData() diff --git a/tools/binman/etype/u_boot_spl_bss_pad.py b/tools/binman/etype/u_boot_spl_bss_pad.py index 3d2dea2e0d8..6c397957e30 100644 --- a/tools/binman/etype/u_boot_spl_bss_pad.py +++ b/tools/binman/etype/u_boot_spl_bss_pad.py @@ -24,3 +24,4 @@ class Entry_u_boot_spl_bss_pad(Entry_blob): self.Raise('Expected __bss_size symbol in spl/u-boot-spl') self.data = chr(0) * bss_size self.contents_size = bss_size + return True diff --git a/tools/binman/etype/u_boot_ucode.py b/tools/binman/etype/u_boot_ucode.py index 3a0cff7c3a3..8cae7deed3c 100644 --- a/tools/binman/etype/u_boot_ucode.py +++ b/tools/binman/etype/u_boot_ucode.py @@ -64,9 +64,14 @@ class Entry_u_boot_ucode(Entry_blob): self.data = '' return True - # Get the microcode from the device tree entry + # Get the microcode from the device tree entry. If it is not available + # yet, return False so we will be called later. If the section simply + # doesn't exist, then we may as well return True, since we are going to + # get an error anyway. fdt_entry = self.section.FindEntryType('u-boot-dtb-with-ucode') - if not fdt_entry or not fdt_entry.ucode_data: + if not fdt_entry: + return True + if not fdt_entry.ucode_data: return False if not fdt_entry.collate: diff --git a/tools/binman/ftest.py b/tools/binman/ftest.py index 80eadeffab8..ca9d158eef3 100644 --- a/tools/binman/ftest.py +++ b/tools/binman/ftest.py @@ -688,12 +688,14 @@ class TestFunctional(unittest.TestCase): data = self._DoReadFile('33_x86-start16.dts') self.assertEqual(X86_START16_DATA, data[:len(X86_START16_DATA)]) - def _RunMicrocodeTest(self, dts_fname, nodtb_data): + def _RunMicrocodeTest(self, dts_fname, nodtb_data, ucode_second=False): """Handle running a test for insertion of microcode Args: dts_fname: Name of test .dts file nodtb_data: Data that we expect in the first section + ucode_second: True if the microsecond entry is second instead of + third Returns: Tuple: @@ -704,10 +706,16 @@ class TestFunctional(unittest.TestCase): data = self._DoReadFile(dts_fname, True) # Now check the device tree has no microcode - dtb_with_ucode = data[len(nodtb_data):] - fdt_len = self.GetFdtLen(dtb_with_ucode) - ucode_content = dtb_with_ucode[fdt_len:] - ucode_pos = len(nodtb_data) + fdt_len + if ucode_second: + ucode_content = data[len(nodtb_data):] + ucode_pos = len(nodtb_data) + dtb_with_ucode = ucode_content[16:] + fdt_len = self.GetFdtLen(dtb_with_ucode) + else: + dtb_with_ucode = data[len(nodtb_data):] + fdt_len = self.GetFdtLen(dtb_with_ucode) + ucode_content = dtb_with_ucode[fdt_len:] + ucode_pos = len(nodtb_data) + fdt_len fname = tools.GetOutputFilename('test.dtb') with open(fname, 'wb') as fd: fd.write(dtb_with_ucode) @@ -728,8 +736,8 @@ class TestFunctional(unittest.TestCase): # expected position and size pos_and_size = struct.pack('<2L', 0xfffffe00 + ucode_pos, len(ucode_data)) - first = data[:len(nodtb_data)] - return first, pos_and_size + u_boot = data[:len(nodtb_data)] + return u_boot, pos_and_size def testPackUbootMicrocode(self): """Test that x86 microcode can be handled correctly @@ -892,23 +900,42 @@ class TestFunctional(unittest.TestCase): data = self._DoReadFile('48_x86-start16-spl.dts') self.assertEqual(X86_START16_SPL_DATA, data[:len(X86_START16_SPL_DATA)]) - def testPackUbootSplMicrocode(self): - """Test that x86 microcode can be handled correctly in SPL + def _PackUbootSplMicrocode(self, dts, ucode_second=False): + """Helper function for microcode tests We expect to see the following in the image, in order: u-boot-spl-nodtb.bin with a microcode pointer inserted at the correct place u-boot.dtb with the microcode removed the microcode + + Args: + dts: Device tree file to use for test + ucode_second: True if the microsecond entry is second instead of + third """ # ELF file with a '_dt_ucode_base_size' symbol with open(self.TestFile('u_boot_ucode_ptr')) as fd: TestFunctional._MakeInputFile('spl/u-boot-spl', fd.read()) - first, pos_and_size = self._RunMicrocodeTest('49_x86_ucode_spl.dts', - U_BOOT_SPL_NODTB_DATA) + first, pos_and_size = self._RunMicrocodeTest(dts, U_BOOT_SPL_NODTB_DATA, + ucode_second=ucode_second) self.assertEqual('splnodtb with microc' + pos_and_size + 'ter somewhere in here', first) + def testPackUbootSplMicrocode(self): + """Test that x86 microcode can be handled correctly in SPL""" + self._PackUbootSplMicrocode('49_x86_ucode_spl.dts') + + def testPackUbootSplMicrocodeReorder(self): + """Test that order doesn't matter for microcode entries + + This is the same as testPackUbootSplMicrocode but when we process the + u-boot-ucode entry we have not yet seen the u-boot-dtb-with-ucode + entry, so we reply on binman to try later. + """ + self._PackUbootSplMicrocode('58_x86_ucode_spl_needs_retry.dts', + ucode_second=True) + def testPackMrc(self): """Test that an image with an MRC binary can be created""" data = self._DoReadFile('50_intel_mrc.dts') @@ -971,5 +998,13 @@ class TestFunctional(unittest.TestCase): 00000000 00000004 rw-u-boot ''', map_data) + def testUnknownContents(self): + """Test that obtaining the contents works as expected""" + with self.assertRaises(ValueError) as e: + self._DoReadFile('57_unknown_contents.dts', True) + self.assertIn("Section '/binman': Internal error: Could not complete " + "processing of contents: remaining [<_testing.Entry__testing ", + str(e.exception)) + if __name__ == "__main__": unittest.main() diff --git a/tools/binman/test/57_unknown_contents.dts b/tools/binman/test/57_unknown_contents.dts new file mode 100644 index 00000000000..6ea98d7cab6 --- /dev/null +++ b/tools/binman/test/57_unknown_contents.dts @@ -0,0 +1,14 @@ +// SPDX-License-Identifier: GPL-2.0+ + +/dts-v1/; + +/ { + #address-cells = <1>; + #size-cells = <1>; + + binman { + _testing { + return-unknown-contents; + }; + }; +}; diff --git a/tools/binman/test/58_x86_ucode_spl_needs_retry.dts b/tools/binman/test/58_x86_ucode_spl_needs_retry.dts new file mode 100644 index 00000000000..e2cb80cf6e2 --- /dev/null +++ b/tools/binman/test/58_x86_ucode_spl_needs_retry.dts @@ -0,0 +1,36 @@ +// SPDX-License-Identifier: GPL-2.0+ + +/dts-v1/; + +/ { + #address-cells = <1>; + #size-cells = <1>; + + binman { + sort-by-pos; + end-at-4gb; + size = <0x200>; + u-boot-spl-with-ucode-ptr { + }; + + /* + * Microcode goes before the DTB which contains it, so binman + * will need to obtain the contents of the next section before + * obtaining the contents of this one. + */ + u-boot-ucode { + }; + + u-boot-dtb-with-ucode { + }; + }; + + microcode { + update@0 { + data = <0x12345678 0x12345679>; + }; + update@1 { + data = <0xabcd0000 0x78235609>; + }; + }; +}; From patchwork Wed Jun 6 00:46:41 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 925670 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" (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.b="gSx88HlF"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 410qqL30scz9s02 for ; Wed, 6 Jun 2018 10:51:10 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 1D0C7C2200D; Wed, 6 Jun 2018 00:50:24 +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_DNSWL_BLOCKED, 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 1BC47C21F9D; Wed, 6 Jun 2018 00:48:02 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 5E817C21FCB; Wed, 6 Jun 2018 00:47:32 +0000 (UTC) Received: from mail-io0-f181.google.com (mail-io0-f181.google.com [209.85.223.181]) by lists.denx.de (Postfix) with ESMTPS id 796DDC21F9F for ; Wed, 6 Jun 2018 00:47:27 +0000 (UTC) Received: by mail-io0-f181.google.com with SMTP id e15-v6so5663910iog.1 for ; Tue, 05 Jun 2018 17:47:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=PWcNQPQJqhPhHLGYH6abQ5A0rF2m4Vg2kVnnWMuTvp4=; b=gSx88HlFkrWO3F4akC/EBwIgxPW1JJlfR+SmGr1XUYmt09y20F8L6EBt0Y3uuC0DRw vifseY9tQYDqo8YnGSxUitaxIJTF3bT2X3zHI3uO1n8mkEwO3do2TUqwJXzPUtlT38YO Nhu5l/gYF4rLj+I8q0JxmcGNRo45zBeit+wkOgls5kzGbez0GG7GJRP7B2AR15S2RabK 551zb1yriqF0+nT6QEpxCESZWr7pAP18rUQ/Bqxu7B6SSIKtrsB8JlzKuAf6F+UTPnDk ajt8TrjXv7cB/FaFZSb94Bt4p2ZJU5AE3udXUD0eJ5k8Zowlb10JSbAEv78TGtW/43vs xDeQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=PWcNQPQJqhPhHLGYH6abQ5A0rF2m4Vg2kVnnWMuTvp4=; b=nupYj10cW+M3aaRP+9Lb9rhDANucpfSvENwQG3H2viXOt+k8XY/U68HvWji2yneJ1u HiCBJsFgEFJ9Wi9JbAdwrl4IOgpkBAuzaiqexeVYNE9gF6XwoPqe5X9Pdnpci3jv/46H EObL0ipoEXN8qsdzTjEpZthpNqerkcaXPssDPlssafXNrYR2LT4wiyXngfarxXdS9bdm yZNwOfmhQ5ZsfvqkYZL+VVcCBH2KNZurAavSCos1LjMO9IQEnyyIPSXuN8MB3HPdIvHS CHIUmr5H5R/JkbqAsVE50vkgC6I33AZo2vjprRiuhCYEkCcfrOaWmbrNYqxRQBSBFPzZ ZcoA== X-Gm-Message-State: APt69E2fpsJJQO0Sy0z5Rhx0+WMF9fYAJ+21JQ7Vw471AF2vqA9uS9io eYMcrBLSPAk5ijNIpo/SmfsvXdQBl/k= X-Google-Smtp-Source: ADUXVKInnmLkMOsrCwcrIC4x8wWL+SxKiMj100xMRhPKmd8RUq54cv+/hxgApVechellSME0Tdfgtw== X-Received: by 2002:a6b:4a19:: with SMTP id w25-v6mr848627iob.25.1528246045950; Tue, 05 Jun 2018 17:47:25 -0700 (PDT) Received: from kiwi.bld.corp.google.com ([100.67.80.24]) by smtp.gmail.com with ESMTPSA id o140-v6sm5820752ioo.22.2018.06.05.17.47.24 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 05 Jun 2018 17:47:24 -0700 (PDT) Received: by kiwi.bld.corp.google.com (Postfix, from userid 121222) id 93453140700; Tue, 5 Jun 2018 18:47:24 -0600 (MDT) From: Simon Glass To: U-Boot Mailing List Date: Tue, 5 Jun 2018 18:46:41 -0600 Message-Id: <20180606004705.79641-6-sjg@chromium.org> X-Mailer: git-send-email 2.17.1.1185.g55be947832-goog In-Reply-To: <20180606004705.79641-1-sjg@chromium.org> References: <20180606004705.79641-1-sjg@chromium.org> Cc: Tom Rini Subject: [U-Boot] [PATCH 05/29] binman: Tidy up execution of tests 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" Move all the test execution into the same mechanism so that we can request a particular test (from any suite) by passing it as an argument to 'binman -t'. Signed-off-by: Simon Glass --- tools/binman/binman.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/tools/binman/binman.py b/tools/binman/binman.py index f3044ca2124..9bdf2237528 100755 --- a/tools/binman/binman.py +++ b/tools/binman/binman.py @@ -54,14 +54,12 @@ def RunTests(debug, args): # Run the entry tests first ,since these need to be the first to import the # 'entry' module. - suite = unittest.TestLoader().loadTestsFromTestCase(entry_test.TestEntry) - suite.run(result) test_name = args and args[0] or None - for module in (ftest.TestFunctional, fdt_test.TestFdt, elf_test.TestElf, - image_test.TestImage): + for module in (entry_test.TestEntry, ftest.TestFunctional, fdt_test.TestFdt, + elf_test.TestElf, image_test.TestImage): if test_name: try: - suite = unittest.TestLoader().loadTestsFromName(args[0], module) + suite = unittest.TestLoader().loadTestsFromName(test_name, module) except AttributeError: continue else: From patchwork Wed Jun 6 00:46:42 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 925674 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" (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.b="V++HS1NZ"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 410qsS0Jnkz9s08 for ; Wed, 6 Jun 2018 10:53:00 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id A6C9FC21FE2; Wed, 6 Jun 2018 00:49:05 +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_DNSWL_BLOCKED, 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 36259C21F1A; Wed, 6 Jun 2018 00:47:53 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 0F1A7C21EBA; Wed, 6 Jun 2018 00:47:38 +0000 (UTC) Received: from mail-it0-f51.google.com (mail-it0-f51.google.com [209.85.214.51]) by lists.denx.de (Postfix) with ESMTPS id 895EDC21E56 for ; Wed, 6 Jun 2018 00:47:30 +0000 (UTC) Received: by mail-it0-f51.google.com with SMTP id 76-v6so5903296itx.4 for ; Tue, 05 Jun 2018 17:47:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=AdGonzVhoLi2YySzxlhu8mNHt89wI9K476Dd6xu++1Y=; b=V++HS1NZxmcb/c2fA806hsR663vkzXzqoJNZOPZ1d3DnIeESKsl3dkgkfq8gemo8DN ZA2AkE71OIvLKQcNK18TRiJWSpQfk71j2hLETR84REBAudSU2qS76UQ1H45K3dmaodAp Tce1i5Si/bG9K3TxAUq2UE9flLxFKQOutFF0Z/qnnq/brT+/533xX34eYjv+5zYAdzNR GnFuhcE6CW9u114FmMSnTF4QXxVBph7Tfz9Ahpq+tUcz95AncZ06IRB2tBB/clTiX2dR jTVxQKRVos7he1Ae5Oxj85+CS+NJAbn2U/sNdAHc9zffwx19AsvBerwNL5EDXgPrnj2M SLlg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=AdGonzVhoLi2YySzxlhu8mNHt89wI9K476Dd6xu++1Y=; b=N90UumUfaslkuQBBFvyqNp3X7z36ShrNhlUfoK8sOLQ4HcO66Kf11jgG/n3ehTuviC xLkeft1Ccikadi292Vxag48H6/T3ud8dqWTi6JjGlD3Uq/XH0Lzmt89jaV73oc2kliG6 c3sPLtkzS7ATxlHunxwyV/DB3MzPCf2DjwV0EqnzgDbz+xjLyG7uhMd4k8FD4e8alOoj NCZ/y3oR7thWjIpZXRHmjn12fMJ+FtuMtn5iGCUyiQvjwq5hDk18v+ilN7bRZnmBXH0e bfgk8NSCJ91kM0qYSHeFvC6XqKiFjEFp40rzdhKZVoXfyb0MjcXP4Q10IMEvVyDYuf/R 9aWw== X-Gm-Message-State: APt69E3lEaBFlyP+QNAM8tJu1bqzeHrYSA2S5/jEEyKEUrPuSFYKnUqQ awbo5EvaWouXDi5FZsTEWDvepQ== X-Google-Smtp-Source: ADUXVKKRzZXKW14B7jIVrV62a4FYwipKfEvRUMibQmJf7qC2wGiN5iROgE0zGO4kxtP9PuIZjaFoGA== X-Received: by 2002:a24:4001:: with SMTP id n1-v6mr472567ita.8.1528246049029; Tue, 05 Jun 2018 17:47:29 -0700 (PDT) Received: from kiwi.bld.corp.google.com ([100.67.80.24]) by smtp.gmail.com with ESMTPSA id f201-v6sm1728003itc.44.2018.06.05.17.47.27 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 05 Jun 2018 17:47:28 -0700 (PDT) Received: by kiwi.bld.corp.google.com (Postfix, from userid 121222) id 17376140700; Tue, 5 Jun 2018 18:47:27 -0600 (MDT) From: Simon Glass To: U-Boot Mailing List Date: Tue, 5 Jun 2018 18:46:42 -0600 Message-Id: <20180606004705.79641-7-sjg@chromium.org> X-Mailer: git-send-email 2.17.1.1185.g55be947832-goog In-Reply-To: <20180606004705.79641-1-sjg@chromium.org> References: <20180606004705.79641-1-sjg@chromium.org> Cc: Tom Rini Subject: [U-Boot] [PATCH 06/29] binman: Tidy up setting of entry contents 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" At present the contents of an entry are set in subclasses simply by assigning to the data and content_size properties. Add some methods to do this, so that we have more control. In particular, add a method to set the contents without changing its size, so we can validate that case. Add a test case for trying to change the size when this is not allowed. Signed-off-by: Simon Glass --- tools/binman/entry.py | 28 +++++++++++++++++++++ tools/binman/etype/_testing.py | 8 ++++++ tools/binman/etype/blob.py | 3 +-- tools/binman/etype/u_boot_spl_bss_pad.py | 3 +-- tools/binman/etype/u_boot_with_ucode_ptr.py | 4 +-- tools/binman/ftest.py | 8 ++++++ tools/binman/test/59_change_size.dts | 14 +++++++++++ 7 files changed, 62 insertions(+), 6 deletions(-) create mode 100644 tools/binman/test/59_change_size.dts diff --git a/tools/binman/entry.py b/tools/binman/entry.py index e4d688c91f9..303c992e375 100644 --- a/tools/binman/entry.py +++ b/tools/binman/entry.py @@ -55,6 +55,7 @@ class Entry(object): self.name = node and (name_prefix + node.name) or 'none' self.pos = None self.size = None + self.data = '' self.contents_size = 0 self.align = None self.align_size = None @@ -138,6 +139,33 @@ class Entry(object): if prefix: self.name = prefix + self.name + def SetContents(self, data): + """Set the contents of an entry + + This sets both the data and content_size properties + + Args: + data: Data to set to the contents (string) + """ + self.data = data + self.contents_size = len(self.data) + + def ProcessContentsUpdate(self, data): + """Update the contens of an entry, after the size is fixed + + This checks that the new data is the same size as the old. + + Args: + data: Data to set to the contents (string) + + Raises: + ValueError if the new data size is not the same as the old + """ + if len(data) != self.contents_size: + self.Raise('Cannot update entry size from %d to %d' % + (len(data), self.contents_size)) + self.SetContents(data) + def ObtainContents(self): """Figure out the contents of an entry. diff --git a/tools/binman/etype/_testing.py b/tools/binman/etype/_testing.py index c075c3ff0d9..04bdc6c532b 100644 --- a/tools/binman/etype/_testing.py +++ b/tools/binman/etype/_testing.py @@ -22,6 +22,8 @@ class Entry__testing(Entry): 'return-invalid-entry') self.return_unknown_contents = fdt_util.GetBool(self._node, 'return-unknown-contents') + self.bad_update_contents = fdt_util.GetBool(self._node, + 'bad-update-contents') def ObtainContents(self): if self.return_unknown_contents: @@ -34,3 +36,9 @@ class Entry__testing(Entry): if self.return_invalid_entry : return {'invalid-entry': [1, 2]} return {} + + def ProcessContents(self): + if self.bad_update_contents: + # Request to update the conents with something larger, to cause a + # failure. + self.ProcessContentsUpdate('aa') diff --git a/tools/binman/etype/blob.py b/tools/binman/etype/blob.py index 16b1e5f64d9..28e6651a935 100644 --- a/tools/binman/etype/blob.py +++ b/tools/binman/etype/blob.py @@ -28,8 +28,7 @@ class Entry_blob(Entry): # new Entry method which can read in chunks. Then we could copy # the data in chunks and avoid reading it all at once. For now # this seems like an unnecessary complication. - self.data = fd.read() - self.contents_size = len(self.data) + self.SetContents(fd.read()) return True def GetDefaultFilename(self): diff --git a/tools/binman/etype/u_boot_spl_bss_pad.py b/tools/binman/etype/u_boot_spl_bss_pad.py index 6c397957e30..65f631d3c5e 100644 --- a/tools/binman/etype/u_boot_spl_bss_pad.py +++ b/tools/binman/etype/u_boot_spl_bss_pad.py @@ -22,6 +22,5 @@ class Entry_u_boot_spl_bss_pad(Entry_blob): bss_size = elf.GetSymbolAddress(fname, '__bss_size') if not bss_size: self.Raise('Expected __bss_size symbol in spl/u-boot-spl') - self.data = chr(0) * bss_size - self.contents_size = bss_size + self.SetContents(chr(0) * bss_size) return True diff --git a/tools/binman/etype/u_boot_with_ucode_ptr.py b/tools/binman/etype/u_boot_with_ucode_ptr.py index 41c2ded2fe8..86945f33184 100644 --- a/tools/binman/etype/u_boot_with_ucode_ptr.py +++ b/tools/binman/etype/u_boot_with_ucode_ptr.py @@ -81,5 +81,5 @@ class Entry_u_boot_with_ucode_ptr(Entry_blob): # Write the microcode position and size into the entry pos_and_size = struct.pack('<2L', pos, size) self.target_pos -= self.pos - self.data = (self.data[:self.target_pos] + pos_and_size + - self.data[self.target_pos + 8:]) + self.ProcessContentsUpdate(self.data[:self.target_pos] + pos_and_size + + self.data[self.target_pos + 8:]) diff --git a/tools/binman/ftest.py b/tools/binman/ftest.py index ca9d158eef3..af3b4dc3e56 100644 --- a/tools/binman/ftest.py +++ b/tools/binman/ftest.py @@ -1006,5 +1006,13 @@ class TestFunctional(unittest.TestCase): "processing of contents: remaining [<_testing.Entry__testing ", str(e.exception)) + def testBadChangeSize(self): + """Test that trying to change the size of an entry fails""" + with self.assertRaises(ValueError) as e: + self._DoReadFile('59_change_size.dts', True) + self.assertIn("Node '/binman/_testing': Cannot update entry size from " + '2 to 1', str(e.exception)) + + if __name__ == "__main__": unittest.main() diff --git a/tools/binman/test/59_change_size.dts b/tools/binman/test/59_change_size.dts new file mode 100644 index 00000000000..1a69026a64c --- /dev/null +++ b/tools/binman/test/59_change_size.dts @@ -0,0 +1,14 @@ +// SPDX-License-Identifier: GPL-2.0+ + +/dts-v1/; + +/ { + #address-cells = <1>; + #size-cells = <1>; + + binman { + _testing { + bad-update-contents; + }; + }; +}; From patchwork Wed Jun 6 00:46:43 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 925672 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" (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.b="nlNUj7yL"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 410qrs0sqbz9s02 for ; Wed, 6 Jun 2018 10:52:29 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id AFAB6C21F00; Wed, 6 Jun 2018 00:49:34 +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_DNSWL_BLOCKED, 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 2F976C21F8E; Wed, 6 Jun 2018 00:47:59 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 0D278C21EF0; Wed, 6 Jun 2018 00:47:41 +0000 (UTC) Received: from mail-it0-f66.google.com (mail-it0-f66.google.com [209.85.214.66]) by lists.denx.de (Postfix) with ESMTPS id 1CF17C21FB3 for ; Wed, 6 Jun 2018 00:47:35 +0000 (UTC) Received: by mail-it0-f66.google.com with SMTP id p185-v6so5836789itp.4 for ; Tue, 05 Jun 2018 17:47:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=VgFoQFc7ikW6NYOy6jdqAqBGhQWNez9HidloRWYEIg0=; b=nlNUj7yLtImu5N2Y7Hk3qfcfqRUpCytebImEs2EJIlpFQ30YO69DlHD9nA0h+hMHBG DsHG2AJUp3/pscdQ2gVYgA/e5UtCmbdz5uvk6NomTuWPFmktPHQ2WP00GlmZ1jpzuFl9 7WYQlJXcpQdSGp0u2+9k2BBvury2uZkPk/gA+XUoqY9ubU1GruwzsB1ZSjmmbZRdhGFT es+V4L4/9I4/OvLdFzwv0uAx5xMxaKVZVwtI0MeRI01zmUnVXKMjkbv04XdO/c17yD1G u+1CbTqKKBc5pYRhtTNBSmaeoaDvFIvpVNnymJQLFnzV7HtDbjtlNbNIwQRgxz3GamQQ keBg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=VgFoQFc7ikW6NYOy6jdqAqBGhQWNez9HidloRWYEIg0=; b=rrz9XUcEOUl2RKtm6UQC9isAjE5plmDR4auExqM6g7DpZbYZI4YJkaQjCyHTWPjaux sLUfK5cvrZr5bv7h/KUR0MtbTOx80orL0mCAPi7XAkn6VEav6lldRBGysOL/B2VgdCp2 xYawiZwnqa8Vf4/d6A7+Fj/qtKTS6R3vAi+WLC+7c8YGq4nZMI2OaDH/ihYbONLPJvh2 ChMseAQuOiT4tijbd2h31FBNFZmFpKOF2uN94wVCwyZ71i712l31ezTOyWCetwLyhcnE 1dd7kSH2s2IQtJIVxBeagrC9QhqKcjmPm8hhlaz+LQdJdDUY4pyEuokpw+Tq5Eo/1B1e XWuA== X-Gm-Message-State: APt69E15qNoCVqof2nQuI22+nBg9m30urNS80dYpUkEEh8uplYoFejHC 1YY85Z47uPpQC9EGm5jzApNy+Q== X-Google-Smtp-Source: ADUXVKJCVw/u1O2UcpMsKwRb+2y06Q/dfKUMH7dOCAuBHleMeqxnLgatoDc+E1XfMikEpqFsIPQDLw== X-Received: by 2002:a24:3644:: with SMTP id l65-v6mr518849itl.78.1528246053201; Tue, 05 Jun 2018 17:47:33 -0700 (PDT) Received: from kiwi.bld.corp.google.com ([100.67.80.24]) by smtp.gmail.com with ESMTPSA id a17-v6sm4652412iod.20.2018.06.05.17.47.32 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 05 Jun 2018 17:47:32 -0700 (PDT) Received: by kiwi.bld.corp.google.com (Postfix, from userid 121222) id 25EC7140700; Tue, 5 Jun 2018 18:47:32 -0600 (MDT) From: Simon Glass To: U-Boot Mailing List Date: Tue, 5 Jun 2018 18:46:43 -0600 Message-Id: <20180606004705.79641-8-sjg@chromium.org> X-Mailer: git-send-email 2.17.1.1185.g55be947832-goog In-Reply-To: <20180606004705.79641-1-sjg@chromium.org> References: <20180606004705.79641-1-sjg@chromium.org> Cc: Tom Rini , Devicetree Compiler Subject: [U-Boot] [PATCH 07/29] libfdt: Bring in proposed pylibfdt changes 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" This provides various patches sent to the devicetree-compiler mailing list to enhance the Python bindings. A final version of this patch may be created once upstreaming is complete, but if it takes too long, this can act as a placeholder. New pylibfdt features: - Support for most remaining, relevant libfdt functions - Support for sequential-write functions Changes are applied to existing U-Boot tools as needed. Signed-off-by: Simon Glass --- scripts/dtc/libfdt/libfdt.h | 3 + scripts/dtc/pylibfdt/libfdt.i_shipped | 705 +++++++++++++++++++++++--- tools/dtoc/dtoc.py | 20 +- tools/dtoc/fdt.py | 3 +- tools/dtoc/test_dtoc.py | 3 +- 5 files changed, 663 insertions(+), 71 deletions(-) diff --git a/scripts/dtc/libfdt/libfdt.h b/scripts/dtc/libfdt/libfdt.h index 7f83023ee10..c30aaaeac64 100644 --- a/scripts/dtc/libfdt/libfdt.h +++ b/scripts/dtc/libfdt/libfdt.h @@ -1310,10 +1310,13 @@ static inline int fdt_property_u64(void *fdt, const char *name, uint64_t val) fdt64_t tmp = cpu_to_fdt64(val); return fdt_property(fdt, name, &tmp, sizeof(tmp)); } + +#ifndef SWIG /* Not available in Python */ static inline int fdt_property_cell(void *fdt, const char *name, uint32_t val) { return fdt_property_u32(fdt, name, val); } +#endif /** * fdt_property_placeholder - add a new property and return a ptr to its value diff --git a/scripts/dtc/pylibfdt/libfdt.i_shipped b/scripts/dtc/pylibfdt/libfdt.i_shipped index 2c1c987c1d1..6774b93b2cb 100644 --- a/scripts/dtc/pylibfdt/libfdt.i_shipped +++ b/scripts/dtc/pylibfdt/libfdt.i_shipped @@ -12,6 +12,17 @@ %{ #define SWIG_FILE_WITH_INIT #include "libfdt.h" + +/* + * We rename this function here to avoid problems with swig, since we also have + * a struct called fdt_property. That struct causes swig to create a class in + * libfdt.py called fdt_property(), which confuses things. + */ +static int _fdt_property(void *fdt, const char *name, const char *val, int len) +{ + return fdt_property(fdt, name, val, len); +} + %} %pythoncode %{ @@ -108,6 +119,7 @@ def check_err_null(val, quiet=()): raise FdtException(val) return val + class Fdt: """Device tree class, supporting all operations @@ -129,6 +141,163 @@ class Fdt: self._fdt = bytearray(data) check_err(fdt_check_header(self._fdt)); + def as_bytearray(self): + """Get the device tree contents as a bytearray + + This can be passed directly to libfdt functions that access a + const void * for the device tree. + + Returns: + bytearray containing the device tree + """ + return bytearray(self._fdt) + + def next_node(self, nodeoffset, depth, quiet=()): + """Find the next subnode + + Args: + nodeoffset: Node offset of previous node + depth: On input, the depth of the node at nodeoffset. On output, the + depth of the returned node + quiet: Errors to ignore (empty to raise on all errors) + + Returns: + The offset of the next node, if any + + Raises: + FdtException if no more nodes found or other error occurs + """ + return check_err(fdt_next_node(self._fdt, nodeoffset, depth), quiet) + + def first_subnode(self, nodeoffset, quiet=()): + """Find the first subnode of a parent node + + Args: + nodeoffset: Node offset of parent node + quiet: Errors to ignore (empty to raise on all errors) + + Returns: + The offset of the first subnode, if any + + Raises: + FdtException if no subnodes found or other error occurs + """ + return check_err(fdt_first_subnode(self._fdt, nodeoffset), quiet) + + def next_subnode(self, nodeoffset, quiet=()): + """Find the next subnode + + Args: + nodeoffset: Node offset of previous subnode + quiet: Errors to ignore (empty to raise on all errors) + + Returns: + The offset of the next subnode, if any + + Raises: + FdtException if no more subnodes found or other error occurs + """ + return check_err(fdt_next_subnode(self._fdt, nodeoffset), quiet) + + def magic(self): + """Return the magic word from the header + + Returns: + Magic word + """ + return fdt_magic(self._fdt) & 0xffffffff + + def totalsize(self): + """Return the total size of the device tree + + Returns: + Total tree size in bytes + """ + return check_err(fdt_totalsize(self._fdt)) + + def off_dt_struct(self): + """Return the start of the device-tree struct area + + Returns: + Start offset of struct area + """ + return check_err(fdt_off_dt_struct(self._fdt)) + + def off_dt_strings(self): + """Return the start of the device-tree string area + + Returns: + Start offset of string area + """ + return check_err(fdt_off_dt_strings(self._fdt)) + + def off_mem_rsvmap(self): + """Return the start of the memory reserve map + + Returns: + Start offset of memory reserve map + """ + return check_err(fdt_off_mem_rsvmap(self._fdt)) + + def version(self): + """Return the version of the device tree + + Returns: + Version number of the device tree + """ + return check_err(fdt_version(self._fdt)) + + def last_comp_version(self): + """Return the last compatible version of the device tree + + Returns: + Last compatible version number of the device tree + """ + return check_err(fdt_last_comp_version(self._fdt)) + + def boot_cpuid_phys(self): + """Return the physical boot CPU ID + + Returns: + Physical boot CPU ID + """ + return check_err(fdt_boot_cpuid_phys(self._fdt)) + + def size_dt_strings(self): + """Return the start of the device-tree string area + + Returns: + Start offset of string area + """ + return check_err(fdt_size_dt_strings(self._fdt)) + + def size_dt_struct(self): + """Return the start of the device-tree struct area + + Returns: + Start offset of struct area + """ + return check_err(fdt_size_dt_struct(self._fdt)) + + def num_mem_rsv(self, quiet=()): + """Return the number of memory reserve-map records + + Returns: + Number of memory reserve-map records + """ + return check_err(fdt_num_mem_rsv(self._fdt), quiet) + + def get_mem_rsv(self, index, quiet=()): + """Return the indexed memory reserve-map record + + Args: + index: Record to return (0=first) + + Returns: + Number of memory reserve-map records + """ + return check_err(fdt_get_mem_rsv(self._fdt, index), quiet) + def subnode_offset(self, parentoffset, name, quiet=()): """Get the offset of a named subnode @@ -161,6 +330,20 @@ class Fdt: """ return check_err(fdt_path_offset(self._fdt, path), quiet) + def get_name(self, nodeoffset): + """Get the name of a node + + Args: + nodeoffset: Offset of node to check + + Returns: + Node name + + Raises: + FdtException on error (e.g. nodeoffset is invalid) + """ + return check_err_null(fdt_get_name(self._fdt, nodeoffset))[0] + def first_property_offset(self, nodeoffset, quiet=()): """Get the offset of the first property in a node offset @@ -195,20 +378,6 @@ class Fdt: return check_err(fdt_next_property_offset(self._fdt, prop_offset), quiet) - def get_name(self, nodeoffset): - """Get the name of a node - - Args: - nodeoffset: Offset of node to check - - Returns: - Node name - - Raises: - FdtException on error (e.g. nodeoffset is invalid) - """ - return check_err_null(fdt_get_name(self._fdt, nodeoffset))[0] - def get_property_by_offset(self, prop_offset, quiet=()): """Obtains a property that can be examined @@ -229,51 +398,38 @@ class Fdt: return pdata return Property(pdata[0], pdata[1]) - def first_subnode(self, nodeoffset, quiet=()): - """Find the first subnode of a parent node + @staticmethod + def create_empty_tree(size, quiet=()): + """Create an empty device tree ready for use Args: - nodeoffset: Node offset of parent node - quiet: Errors to ignore (empty to raise on all errors) + size: Size of device tree in bytes Returns: - The offset of the first subnode, if any - - Raises: - FdtException if no subnode found or other error occurs + Fdt object containing the device tree """ - return check_err(fdt_first_subnode(self._fdt, nodeoffset), quiet) - - def next_subnode(self, nodeoffset, quiet=()): - """Find the next subnode + data = bytearray(size) + err = check_err(fdt_create_empty_tree(data, size), quiet) + if err: + return err + return Fdt(data) - Args: - nodeoffset: Node offset of previous subnode - quiet: Errors to ignore (empty to raise on all errors) + def open_into(self, size, quiet=()): + """Move the device tree into a larger or smaller space - Returns: - The offset of the next subnode, if any + This creates a new device tree of size @size and moves the existing + device tree contents over to that. It can be used to create more space + in a device tree. - Raises: - FdtException if no more subnode found or other error occurs - """ - return check_err(fdt_next_subnode(self._fdt, nodeoffset), quiet) - - def totalsize(self): - """Return the total size of the device tree - - Returns: - Total tree size in bytes - """ - return check_err(fdt_totalsize(self._fdt)) - - def off_dt_struct(self): - """Return the start of the device tree struct area - - Returns: - Start offset of struct area + Args: + size: Required new size of device tree in bytes """ - return check_err(fdt_off_dt_struct(self._fdt)) + fdt = bytearray(size) + fdt[:len(self._fdt)] = self._fdt + err = check_err(fdt_open_into(self._fdt, fdt, size), quiet) + if err: + return err + self._fdt = fdt def pack(self, quiet=()): """Pack the device tree to remove unused space @@ -288,20 +444,28 @@ class Fdt: """ return check_err(fdt_pack(self._fdt), quiet) - def delprop(self, nodeoffset, prop_name): - """Delete a property from a node + def getprop(self, nodeoffset, prop_name, quiet=()): + """Get a property from a node Args: - nodeoffset: Node offset containing property to delete - prop_name: Name of property to delete + nodeoffset: Node offset containing property to get + prop_name: Name of property to get + quiet: Errors to ignore (empty to raise on all errors) + + Returns: + Value of property as a string, or -ve error number Raises: - FdtError if the property does not exist, or another error occurs + FdtError if any error occurs (e.g. the property is not found) """ - return check_err(fdt_delprop(self._fdt, nodeoffset, prop_name)) + pdata = check_err_null(fdt_getprop(self._fdt, nodeoffset, prop_name), + quiet) + if isinstance(pdata, (int)): + return pdata + return str(pdata[0]) - def getprop(self, nodeoffset, prop_name, quiet=()): - """Get a property from a node + def getprop_obj(self, nodeoffset, prop_name, quiet=()): + """Get a property from a node as a Property object Args: nodeoffset: Node offset containing property to get @@ -309,7 +473,7 @@ class Fdt: quiet: Errors to ignore (empty to raise on all errors) Returns: - Value of property as a bytearray, or -ve error number + Property object, or None if not found Raises: FdtError if any error occurs (e.g. the property is not found) @@ -317,8 +481,8 @@ class Fdt: pdata = check_err_null(fdt_getprop(self._fdt, nodeoffset, prop_name), quiet) if isinstance(pdata, (int)): - return pdata - return bytearray(pdata[0]) + return None + return Property(prop_name, bytearray(pdata[0])) def get_phandle(self, nodeoffset): """Get the phandle of a node @@ -347,6 +511,108 @@ class Fdt: """ return check_err(fdt_parent_offset(self._fdt, nodeoffset), quiet) + def set_name(self, nodeoffset, name, quiet=()): + """Set the name of a node + + Args: + nodeoffset: Node offset of node to update + name: New node name + + Returns: + Error code, or 0 if OK + + Raises: + FdtException if no parent found or other error occurs + """ + return check_err(fdt_set_name(self._fdt, nodeoffset, name), quiet) + + def setprop(self, nodeoffset, prop_name, val, quiet=()): + """Set the value of a property + + Args: + nodeoffset: Node offset containing the property to create/update + prop_name: Name of property + val: Value to write (string or bytearray) + quiet: Errors to ignore (empty to raise on all errors) + + Returns: + Error code, or 0 if OK + + Raises: + FdtException if no parent found or other error occurs + """ + return check_err(fdt_setprop(self._fdt, nodeoffset, prop_name, val, + len(val)), quiet) + + def setprop_u32(self, nodeoffset, prop_name, val, quiet=()): + """Set the value of a property + + Args: + nodeoffset: Node offset containing the property to create/update + prop_name: Name of property + val: Value to write (integer) + quiet: Errors to ignore (empty to raise on all errors) + + Returns: + Error code, or 0 if OK + + Raises: + FdtException if no parent found or other error occurs + """ + return check_err(fdt_setprop_u32(self._fdt, nodeoffset, prop_name, val), + quiet) + + def setprop_u64(self, nodeoffset, prop_name, val, quiet=()): + """Set the value of a property + + Args: + nodeoffset: Node offset containing the property to create/update + prop_name: Name of property + val: Value to write (integer) + quiet: Errors to ignore (empty to raise on all errors) + + Returns: + Error code, or 0 if OK + + Raises: + FdtException if no parent found or other error occurs + """ + return check_err(fdt_setprop_u64(self._fdt, nodeoffset, prop_name, val), + quiet) + + def setprop_str(self, nodeoffset, prop_name, val, quiet=()): + """Set the string value of a property + + The property is set to the string, with a nul terminator added + + Args: + nodeoffset: Node offset containing the property to create/update + prop_name: Name of property + val: Value to write (string without nul terminator) + quiet: Errors to ignore (empty to raise on all errors) + + Returns: + Error code, or 0 if OK + + Raises: + FdtException if no parent found or other error occurs + """ + val += '\0' + return check_err(fdt_setprop(self._fdt, nodeoffset, prop_name, + val, len(val)), quiet) + + def delprop(self, nodeoffset, prop_name): + """Delete a property from a node + + Args: + nodeoffset: Node offset containing property to delete + prop_name: Name of property to delete + + Raises: + FdtError if the property does not exist, or another error occurs + """ + return check_err(fdt_delprop(self._fdt, nodeoffset, prop_name)) + def node_offset_by_phandle(self, phandle, quiet=()): """Get the offset of a node with the given phandle @@ -362,7 +628,8 @@ class Fdt: """ return check_err(fdt_node_offset_by_phandle(self._fdt, phandle), quiet) -class Property: + +class Property(bytearray): """Holds a device tree property name and value. This holds a copy of a property taken from the device tree. It does not @@ -371,11 +638,274 @@ class Property: Properties: name: Property name - value: Proper value as a bytearray + value: Property value as a bytearray """ def __init__(self, name, value): + bytearray.__init__(self, value) self.name = name - self.value = value + + def as_cell(self, fmt): + return struct.unpack('>' + fmt, self)[0] + + def as_uint32(self): + return self.as_cell('L') + + def as_int32(self): + return self.as_cell('l') + + def as_uint64(self): + return self.as_cell('Q') + + def as_int64(self): + return self.as_cell('q') + + def as_str(self): + return self[:-1] + + +class FdtSw(object): + """Software interface to create a device tree from scratch + + The methods in this class work by adding to an existing 'partial' device + tree buffer of a fixed size created by instantiating this class. When the + tree is complete, call finish() to complete the device tree so that it can + be used. + + Similarly with nodes, a new node is started with begin_node() and finished + with end_node(). + + The context manager functions can be used to make this a bit easier: + + # First create the device tree with a node and property: + with FdtSw(small_size) as sw: + with sw.AddNode('node'): + sw.property_u32('reg', 2) + fdt = sw.AsFdt() + + # Now we can use it as a real device tree + fdt.setprop_u32(0, 'reg', 3) + """ + def __init__(self, size, quiet=()): + fdtrw = bytearray(size) + err = check_err(fdt_create(fdtrw, size)) + if err: + return err + self._fdtrw = fdtrw + + def __enter__(self): + """Contact manager to use to create a device tree via software""" + return self + + def __exit__(self, type, value, traceback): + check_err(fdt_finish(self._fdtrw)) + + def AsFdt(self): + """Convert a FdtSw into an Fdt so it can be accessed as normal + + Note that finish() must be called before this function will work. If + you are using the context manager (see 'with' code in the FdtSw class + comment) then this will happen automatically. + + Returns: + Fdt object allowing access to the newly created device tree + """ + return Fdt(self._fdtrw) + + def resize(self, size, quiet=()): + """Resize the buffer to accommodate a larger tree + + Args: + size: New size of tree + quiet: Errors to ignore (empty to raise on all errors) + + Raises: + FdtException if no node found or other error occurs + """ + fdt = bytearray(size) + fdt[:len(self._fdtrw)] = self._fdtrw + err = check_err(fdt_resize(self._fdtrw, fdt, size), quiet) + if err: + return err + self._fdtrw = fdt + + def add_reservemap_entry(self, addr, size, quiet=()): + """Add a new memory reserve map entry + + Once finished adding, you must call finish_reservemap(). + + Args: + addr: 64-bit start address + size: 64-bit size + quiet: Errors to ignore (empty to raise on all errors) + + Raises: + FdtException if no node found or other error occurs + """ + return check_err(fdt_add_reservemap_entry(self._fdtrw, addr, size), + quiet) + + def finish_reservemap(self, quiet=()): + """Indicate that there are no more reserve map entries to add + + Args: + quiet: Errors to ignore (empty to raise on all errors) + + Raises: + FdtException if no node found or other error occurs + """ + return check_err(fdt_finish_reservemap(self._fdtrw), quiet) + + def begin_node(self, name, quiet=()): + """Begin a new node + + Use this before adding properties to the node. Then call end_node() to + finish it. You can also use the context manager as shown in the FdtSw + class comment. + + Args: + name: Name of node to begin + quiet: Errors to ignore (empty to raise on all errors) + + Raises: + FdtException if no node found or other error occurs + """ + return check_err(fdt_begin_node(self._fdtrw, name), quiet) + + def property_string(self, name, string, quiet=()): + """Add a property with a string value + + The string will be nul-terminated when written to the device tree + + Args: + name: Name of property to add + string: String value of property + quiet: Errors to ignore (empty to raise on all errors) + + Raises: + FdtException if no node found or other error occurs + """ + return check_err(fdt_property_string(self._fdtrw, name, string), quiet) + + def property_u32(self, name, val, quiet=()): + """Add a property with a 32-bit value + + Write a single-cell value to the device tree + + Args: + name: Name of property to add + val: Value of property + quiet: Errors to ignore (empty to raise on all errors) + + Raises: + FdtException if no node found or other error occurs + """ + return check_err(fdt_property_u32(self._fdtrw, name, val), quiet) + + def property_u64(self, name, val, quiet=()): + """Add a property with a 64-bit value + + Write a double-cell value to the device tree in big-endian format + + Args: + name: Name of property to add + val: Value of property + quiet: Errors to ignore (empty to raise on all errors) + + Raises: + FdtException if no node found or other error occurs + """ + return check_err(fdt_property_u64(self._fdtrw, name, val), quiet) + + def property_cell(self, name, val, quiet=()): + """Add a property with a single-cell value + + Write a single-cell value to the device tree + + Args: + name: Name of property to add + val: Value of property + quiet: Errors to ignore (empty to raise on all errors) + + Raises: + FdtException if no node found or other error occurs + """ + return check_err(fdt_property_cell(self._fdtrw, name, val), quiet) + + def property(self, name, val, quiet=()): + """Add a property + + Write a new property with the given value to the device tree. The value + is taken as is and is not nul-terminated + + Args: + name: Name of property to add + val: Value of property + quiet: Errors to ignore (empty to raise on all errors) + + Raises: + FdtException if no node found or other error occurs + """ + return check_err(_fdt_property(self._fdtrw, name, val, len(val)), quiet) + + def end_node(self, quiet=()): + """End a node + + Use this after adding properties to a node to close it off. You can also + use the context manager as shown in the FdtSw class comment. + + Args: + quiet: Errors to ignore (empty to raise on all errors) + + Raises: + FdtException if no node found or other error occurs + """ + return check_err(fdt_end_node(self._fdtrw), quiet) + + def finish(self, quiet=()): + """Finish writing the device tree + + This closes off the device tree ready for use + + Args: + quiet: Errors to ignore (empty to raise on all errors) + + Raises: + FdtException if no node found or other error occurs + """ + return check_err(fdt_finish(self._fdtrw), quiet) + + def AddNode(self, name): + """Create a new context for adding a node + + When used in a 'with' clause this starts a new node and finishes it + afterward. + + Args: + name: Name of node to add + """ + return NodeAdder(self._fdtrw, name) + + +class NodeAdder(): + """Class to provide a node context + + This allows you to add nodes in a more natural way: + + with fdtsw.AddNode('name'): + fdtsw.property_string('test', 'value') + + The node is automatically completed with a call to end_node() when the + context exits. + """ + def __init__(self, fdt, name): + self._fdt = fdt + self._name = name + + def __enter__(self): + check_err(fdt_begin_node(self._fdt, self._name)) + + def __exit__(self, type, value, traceback): + check_err(fdt_end_node(self._fdt)) %} %rename(fdt_property) fdt_property_func; @@ -408,6 +938,7 @@ typedef int fdt32_t; fdt = fdt; /* avoid unused variable warning */ } +/* typemap used for fdt_get_property_by_offset() */ %typemap(out) (struct fdt_property *) { PyObject *buff; @@ -430,6 +961,44 @@ typedef int fdt32_t; $result = Py_BuildValue("s#", $1, *arg4); } +/* typemap used for fdt_setprop() */ +%typemap(in) (const void *val) { + $1 = PyString_AsString($input); /* char *str */ +} + +/* typemap used for fdt_add_reservemap_entry() */ +%typemap(in) uint64_t { + $1 = PyLong_AsUnsignedLong($input); +} + +/* typemaps used for fdt_next_node() */ +%typemap(in, numinputs=1) int *depth (int depth) { + depth = (int) PyInt_AsLong($input); + $1 = &depth; +} + +%typemap(argout) int *depth { + PyObject *val = Py_BuildValue("i", *arg$argnum); + resultobj = SWIG_Python_AppendOutput(resultobj, val); +} + +%apply int *depth { int *depth }; + +/* typemaps for fdt_get_mem_rsv */ +%typemap(in, numinputs=0) uint64_t * (uint64_t temp) { + $1 = &temp; +} + +%typemap(argout) uint64_t * { + PyObject *val = PyLong_FromUnsignedLong(*arg$argnum); + if (!result) { + if (PyTuple_GET_SIZE(resultobj) == 0) + resultobj = val; + else + resultobj = SWIG_Python_AppendOutput(resultobj, val); + } +} + /* We have both struct fdt_property and a function fdt_property() */ %warnfilter(302) fdt_property; @@ -444,5 +1013,13 @@ int fdt_last_comp_version(const void *fdt); int fdt_boot_cpuid_phys(const void *fdt); int fdt_size_dt_strings(const void *fdt); int fdt_size_dt_struct(const void *fdt); +int fdt_property_string(void *fdt, const char *name, const char *val); +int fdt_property_cell(void *fdt, const char *name, uint32_t val); + +/* + * This function has a stub since the name fdt_property is used for both a + * function and a struct, which confuses SWIG. + */ +int _fdt_property(void *fdt, const char *name, const char *val, int len); %include <../libfdt/libfdt.h> diff --git a/tools/dtoc/dtoc.py b/tools/dtoc/dtoc.py index 008c0f4d693..c891b063800 100755 --- a/tools/dtoc/dtoc.py +++ b/tools/dtoc/dtoc.py @@ -36,14 +36,26 @@ sys.path.append(os.path.join(our_path, '../patman')) import dtb_platdata -def run_tests(): - """Run all the test we have for dtoc""" +def run_tests(args): + """Run all the test we have for dtoc + + Args: + args: List of positional args provided to binman. This can hold a test + name to execute (as in 'binman -t testSections', for example) + """ import test_dtoc result = unittest.TestResult() sys.argv = [sys.argv[0]] + test_name = args and args[0] or None for module in (test_dtoc.TestDtoc,): - suite = unittest.TestLoader().loadTestsFromTestCase(module) + if test_name: + try: + suite = unittest.TestLoader().loadTestsFromName(test_name, module) + except AttributeError: + continue + else: + suite = unittest.TestLoader().loadTestsFromTestCase(module) suite.run(result) print result @@ -68,7 +80,7 @@ parser.add_option('-t', '--test', action='store_true', dest='test', # Run our meagre tests if options.test: - run_tests() + run_tests(args) else: dtb_platdata.run_steps(args, options.dtb_file, options.include_disabled, diff --git a/tools/dtoc/fdt.py b/tools/dtoc/fdt.py index 7fab0cd8e90..d08b0b53e61 100644 --- a/tools/dtoc/fdt.py +++ b/tools/dtoc/fdt.py @@ -234,7 +234,6 @@ class Node: be updated. """ if self._offset != my_offset: - #print '%s: %d -> %d\n' % (self.path, self._offset, my_offset) self._offset = my_offset offset = libfdt.fdt_first_subnode(self._fdt.GetFdt(), self._offset) for subnode in self.subnodes: @@ -359,7 +358,7 @@ class Fdt: poffset = libfdt.fdt_first_property_offset(self._fdt, node._offset) while poffset >= 0: p = self._fdt_obj.get_property_by_offset(poffset) - prop = Prop(node, poffset, p.name, p.value) + prop = Prop(node, poffset, p.name, p) props_dict[prop.name] = prop poffset = libfdt.fdt_next_property_offset(self._fdt, poffset) diff --git a/tools/dtoc/test_dtoc.py b/tools/dtoc/test_dtoc.py index 99f4e1a13a4..e475a7eb14e 100644 --- a/tools/dtoc/test_dtoc.py +++ b/tools/dtoc/test_dtoc.py @@ -4,7 +4,8 @@ """Tests for the dtb_platdata module -This includes unit tests for some functions and functional tests for +This includes unit tests for some functions and functional tests for the dtoc +tool. """ import collections From patchwork Wed Jun 6 00:46:44 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 925676 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" (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.b="IqlIfAOS"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 410qtd62qHz9s08 for ; Wed, 6 Jun 2018 10:54:01 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 83F34C21F27; Wed, 6 Jun 2018 00:50:40 +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_DNSWL_BLOCKED, 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 E703DC21FB9; Wed, 6 Jun 2018 00:48:08 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id B15DDC21FCB; Wed, 6 Jun 2018 00:47:42 +0000 (UTC) Received: from mail-it0-f67.google.com (mail-it0-f67.google.com [209.85.214.67]) by lists.denx.de (Postfix) with ESMTPS id C4AB9C21FB5 for ; Wed, 6 Jun 2018 00:47:37 +0000 (UTC) Received: by mail-it0-f67.google.com with SMTP id l6-v6so5844330iti.2 for ; Tue, 05 Jun 2018 17:47:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=qxP5jQxheKZw6YyJApdTSgBZu38rsfMyjr3vBbgzvH4=; b=IqlIfAOS+nsgF02Db+5g3IbT7HnqW8J3nk2GzOIgesLnxaC72qbfzQegGUTkFOJr0i VnF1XkK2HQ4bbSWrDuyNLhxpb4gfhWKnByhsZW3ZO12zh9TKYMxh2Zqn4RXH74UGS8ez gUfGIiii7PrL+N78E44a7KXXo8+jyAfX2uMQV8XHkaXv+IiYBdFKdulAv9DipziQj3NW M8Rwbp8TFxDmFbXpRp6ZRunO4X5N7IZK9ffwrMnxJBiKrPXvKW2Ncj+T7RGXISwThsho rS+dJOqZ2D8TE0qCKOQ2zqFhd4vgrUVe9I/Z05nyttDlRe+3F/GGkpcp1HsiV8y9U93M HzuA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=qxP5jQxheKZw6YyJApdTSgBZu38rsfMyjr3vBbgzvH4=; b=jRpdqCsFeq/0yUHlSOmA1dI5sFpRcLZlmesGE6xaeLCT+NzBmTx8fAJYHrix64o5zR 55otVMsNCUXogwXNQABMM4MEdqIxbGyq9JiIRZaf1hJS1WmFTZsAOxqWqfVpGCO5LtL3 bQSKOqzfwlTQ7L+j6nIJ1QO6QkStZY9OB3ajfzkpyog+U2AkvIE4bgfWFG7MxR+w5VFG DIXNTF1umtV10ZqhNpWjJtt8LpgJK6BK70hzWahSXzviNqCPrsNl9w7MnpmNOxAzbMYt Trm+BIn+xM+mJCCIJammbP2dVku4fh5s4fP2FLvQDvzNxyio0hzB+wMZA/C+b0ea7Duf NNrw== X-Gm-Message-State: APt69E0gEToRPsxOe9GD+6Y5FxOK0D5M752Q0L7Wfznx0yOll03LZ/JR GPbkADulS8prlz0Hdl7D3yduNg== X-Google-Smtp-Source: ADUXVKJYwG5rULJZ47jUAnqFNh1nuSpzEMTTE1NTHhitxu0fAuYOJ5+FbE7aHnsxzg4CbbGcv8LckA== X-Received: by 2002:a24:4d8d:: with SMTP id l135-v6mr436147itb.121.1528246056249; Tue, 05 Jun 2018 17:47:36 -0700 (PDT) Received: from kiwi.bld.corp.google.com ([2620:15c:183:0:8223:87c:a681:66aa]) by smtp.gmail.com with ESMTPSA id u3-v6sm4266223ioc.67.2018.06.05.17.47.35 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 05 Jun 2018 17:47:35 -0700 (PDT) Received: by kiwi.bld.corp.google.com (Postfix, from userid 121222) id 11B1D140700; Tue, 5 Jun 2018 18:47:35 -0600 (MDT) From: Simon Glass To: U-Boot Mailing List Date: Tue, 5 Jun 2018 18:46:44 -0600 Message-Id: <20180606004705.79641-9-sjg@chromium.org> X-Mailer: git-send-email 2.17.1.1185.g55be947832-goog In-Reply-To: <20180606004705.79641-1-sjg@chromium.org> References: <20180606004705.79641-1-sjg@chromium.org> Cc: Tom Rini , Devicetree Compiler Subject: [U-Boot] [PATCH 08/29] libfdt: Fix the Python pack() function 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" This currently fails to reduce the device-tree bytearray size. Fix this. This stands in for a pending upstream change. Signed-off-by: Simon Glass --- scripts/dtc/pylibfdt/libfdt.i_shipped | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/scripts/dtc/pylibfdt/libfdt.i_shipped b/scripts/dtc/pylibfdt/libfdt.i_shipped index 6774b93b2cb..5b38e63b267 100644 --- a/scripts/dtc/pylibfdt/libfdt.i_shipped +++ b/scripts/dtc/pylibfdt/libfdt.i_shipped @@ -442,7 +442,11 @@ class Fdt: Raises: FdtException if any error occurs """ - return check_err(fdt_pack(self._fdt), quiet) + err = check_err(fdt_pack(self._fdt), quiet) + if err: + return err + del self._fdt[self.totalsize():] + return err def getprop(self, nodeoffset, prop_name, quiet=()): """Get a property from a node From patchwork Wed Jun 6 00:46:45 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 925695 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" (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.b="m++xtR9Y"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 410r5C718hz9s02 for ; Wed, 6 Jun 2018 11:03:11 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id A032CC21F52; Wed, 6 Jun 2018 00:53:33 +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_DNSWL_BLOCKED, 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 84A94C21FAF; Wed, 6 Jun 2018 00:49:12 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 03C04C21FB7; Wed, 6 Jun 2018 00:47:48 +0000 (UTC) Received: from mail-it0-f67.google.com (mail-it0-f67.google.com [209.85.214.67]) by lists.denx.de (Postfix) with ESMTPS id B0686C21EBA for ; Wed, 6 Jun 2018 00:47:44 +0000 (UTC) Received: by mail-it0-f67.google.com with SMTP id m194-v6so5906684itg.2 for ; Tue, 05 Jun 2018 17:47:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=aALAV9XM8HHo1KwBxCouU3Br60dD9oKA8YHOXvZi4Y8=; b=m++xtR9Yukdcrl/qJqthXOpjkRg3GvcgTjsoe9YjkwCOA7P0XvH5+xyMD8pr73G1An KtpiJ+n+S6AQETAB5Pk30VzpQQySpDffyvWZDZmB6TIUdb7HY5PzjW2sE13e3+FY0Gj2 ClsXIjACGCePW6FVaDJ7wscMJCXxy3A7fZzn/bWrGwT/2GJM2PJBZDtU7Mzp1rX6LHrD HwKLQ5j/KZaGCPzPExFI8iCPf1mB4nc0xFFIbbMR6l5bCT2OrFUeljWdfUIZKjGWhBIr lHewbwI3ywwEuqSPLCks7Pu3AS/HKgJHNzIDYOFOlxuGnsod7E+vlNkyLr6eRkMpqpMT iEhA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=aALAV9XM8HHo1KwBxCouU3Br60dD9oKA8YHOXvZi4Y8=; b=bmlCKG0t7YgbyIgVC0+UmX0zk24M2jZ7PTynHZydfquQB0EmVbs+4J7bPRflqkYaD1 e067l+6R0sJZ5EluQvxF53G5Hc/L/Ue94oDQLvv3JQo6Ut3i4LTt4eL2fSvDd1rHEPuN +LWGJ3BDbF5OZYaDGxAe+AY4x1u4SY9YvlcCZDyxJPUMS0fSgo6ktqcxtuUKroQ8yRlL Kp6T4Yr5VsfkGkP2jjnQYXafUDAUFCIwGkSwuJkKLqRwBmGasiEn2bXcMFCkvV4njsKn IMDQ/Oo9ssyenYzohsbKTwTOWT3ZuI4/c+HtscBXA5K5xN6PX9ZCnHDjGII2gRHvhmnI 8NGg== X-Gm-Message-State: APt69E2Kkn/v/JStpLHlL/WQGNCFrEEC3TT1yT60Fueo3wCC1tiIzTO4 0XDWU1Q0T7D6e3lyQK0XbUDMv4gUUQo= X-Google-Smtp-Source: ADUXVKKeuDeXI/m9D9Twcceqe4eKbImwaQMlIUIdGsuKgRvrbFzJxrm02E7vzIodocBLBxOzExJ4Rg== X-Received: by 2002:a24:730a:: with SMTP id y10-v6mr466307itb.137.1528246063128; Tue, 05 Jun 2018 17:47:43 -0700 (PDT) Received: from kiwi.bld.corp.google.com ([100.67.80.24]) by smtp.gmail.com with ESMTPSA id y204-v6sm10159107ioy.88.2018.06.05.17.47.42 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 05 Jun 2018 17:47:42 -0700 (PDT) Received: by kiwi.bld.corp.google.com (Postfix, from userid 121222) id D5A95140700; Tue, 5 Jun 2018 18:47:41 -0600 (MDT) From: Simon Glass To: U-Boot Mailing List Date: Tue, 5 Jun 2018 18:46:45 -0600 Message-Id: <20180606004705.79641-10-sjg@chromium.org> X-Mailer: git-send-email 2.17.1.1185.g55be947832-goog In-Reply-To: <20180606004705.79641-1-sjg@chromium.org> References: <20180606004705.79641-1-sjg@chromium.org> Cc: Tom Rini , Devicetree Compiler Subject: [U-Boot] [PATCH 09/29] libfdt: Add get_property() and del_node() 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" Add support for these functions in the Python binding. This patch stands in for a pending upstream change. Signed-off-by: Simon Glass --- scripts/dtc/pylibfdt/libfdt.i_shipped | 32 +++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/scripts/dtc/pylibfdt/libfdt.i_shipped b/scripts/dtc/pylibfdt/libfdt.i_shipped index 5b38e63b267..e180ee93088 100644 --- a/scripts/dtc/pylibfdt/libfdt.i_shipped +++ b/scripts/dtc/pylibfdt/libfdt.i_shipped @@ -398,6 +398,27 @@ class Fdt: return pdata return Property(pdata[0], pdata[1]) + def get_property(self, nodeoffset, prop_name, quiet=()): + """Obtains a property by name + + Args: + nodeoffset: Offset to the node to check + prop_name: Name of property to get + quiet: Errors to ignore (empty to raise on all errors) + + Returns: + Property object, or None if not found + + Raises: + FdtException on error (e.g. invalid prop_offset or device + tree format) + """ + pdata = check_err_null( + fdt_get_property(self._fdt, nodeoffset, prop_name), quiet) + if isinstance(pdata, (int)): + return pdata + return Property(pdata[0], pdata[1]) + @staticmethod def create_empty_tree(size, quiet=()): """Create an empty device tree ready for use @@ -632,6 +653,17 @@ class Fdt: """ return check_err(fdt_node_offset_by_phandle(self._fdt, phandle), quiet) + def del_node(self, nodeoffset): + """Delete a node + + Args: + nodeoffset: Node offset containing property to delete + + Raises: + FdtError if the node does not exist, or another error occurs + """ + return check_err(fdt_del_node(self._fdt, nodeoffset)) + class Property(bytearray): """Holds a device tree property name and value. From patchwork Wed Jun 6 00:46:46 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 925675 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" (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.b="Rc/MephM"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 410qt56qjmz9s1p for ; Wed, 6 Jun 2018 10:53:33 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id A2DE9C21E89; Wed, 6 Jun 2018 00:52:56 +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_DNSWL_BLOCKED, RCVD_IN_MSPIKE_H2, 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 8C2ECC21FE2; Wed, 6 Jun 2018 00:49:00 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 5F3DDC21FD0; Wed, 6 Jun 2018 00:47:52 +0000 (UTC) Received: from mail-io0-f171.google.com (mail-io0-f171.google.com [209.85.223.171]) by lists.denx.de (Postfix) with ESMTPS id 8DABEC21F60 for ; Wed, 6 Jun 2018 00:47:48 +0000 (UTC) Received: by mail-io0-f171.google.com with SMTP id r24-v6so5631404ioh.9 for ; Tue, 05 Jun 2018 17:47:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=6QBWxNAnxVaZ3sBcxm+G+pMYYvGIl3GAzDocqZmEWls=; b=Rc/MephMaaQOq2RJ/u9aGzYwgHEjYiQaralsrlGZDHwCFj+2Q3ZN5VeI3OEkqynsch i0zjMMbxCtqVZ1FYZGzEBcfYBgomxIcl7nb02eZLt+K3Un50l6O6clq8aBcABAMWsuX7 lp0LQDS6HxMcMALqX/oeoiB+H6Ybjs+vzDdPXtEQ6a1BBIJj+X/Bo1fp10I9bol9JJkP 4sbYs07qjfbS9WtuvmXhy85wAvwmLCPuK+b64uEX+PZUm415kbEpRRJwUpA6VGvX6Gf9 nzKpHVLCdKxbfqVYsYxl42Bmot6fDLY1tgxBqHjhzsLKCCgCoGvvAaiPGHARDNL5RT6C vuIQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=6QBWxNAnxVaZ3sBcxm+G+pMYYvGIl3GAzDocqZmEWls=; b=hAST8GzuEEUMATxcrY4Zj8NXikI9T7h+QdCJs7gcCi2aAqGAGYgzGKrP9D8DjePBPw PRNFSn1LR3aU2nLo5s3/ZR7jEeVJaLdV72fLU+NQQ1xmeRIqpFfVeiettM4BnHnxysbd B+e7NFj9OmDfZByYPcw8sKuC5b9CORWDQjaSlnqO/hJE6Fca5N6YRu6RJ+hnoGU5p9Lf eZBLHeRHiZZkBpEtgbbyXeGrfXKAPlUHq191Q31FVqY1/tmyCKlysn7H3is3/dVmqoGV 0Vtv2RtDBhJZn9+GLEa9CbYB3SQVBApu1hO9rmftsJ641Wtlw+GwEuFL3/dp9/yjEjgq bd3A== X-Gm-Message-State: APt69E32Xu2wGDaht5tyf9EmzyFfAcovTy18qJ5j+blAEivX5CtSJTiL eYX2EM+9R9scPqfCA9aEPIow+Q== X-Google-Smtp-Source: ADUXVKJYgq1BKJK/EnMAAsL8Ja0j5Uqu8uYx/DmU7LRbVT+uCOEYjoJLJPv/FF66IGiFskATMYWdBA== X-Received: by 2002:a6b:bf01:: with SMTP id p1-v6mr857485iof.67.1528246067007; Tue, 05 Jun 2018 17:47:47 -0700 (PDT) Received: from kiwi.bld.corp.google.com ([2620:15c:183:0:8223:87c:a681:66aa]) by smtp.gmail.com with ESMTPSA id j140-v6sm1337114itj.33.2018.06.05.17.47.46 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 05 Jun 2018 17:47:46 -0700 (PDT) Received: by kiwi.bld.corp.google.com (Postfix, from userid 121222) id 13775140700; Tue, 5 Jun 2018 18:47:46 -0600 (MDT) From: Simon Glass To: U-Boot Mailing List Date: Tue, 5 Jun 2018 18:46:46 -0600 Message-Id: <20180606004705.79641-11-sjg@chromium.org> X-Mailer: git-send-email 2.17.1.1185.g55be947832-goog In-Reply-To: <20180606004705.79641-1-sjg@chromium.org> References: <20180606004705.79641-1-sjg@chromium.org> Cc: Tom Rini Subject: [U-Boot] [PATCH 10/29] binman: Move coverage logic into a new test_util file 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" At present only binman has the logic for determining Python test coverage but this is useful for other tools also. Move it out into a separate file so it can be used by other tools. Signed-off-by: Simon Glass --- tools/binman/binman.py | 30 +++-------------------- tools/patman/test_util.py | 51 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+), 27 deletions(-) create mode 100644 tools/patman/test_util.py diff --git a/tools/binman/binman.py b/tools/binman/binman.py index 9bdf2237528..40438c42780 100755 --- a/tools/binman/binman.py +++ b/tools/binman/binman.py @@ -26,6 +26,7 @@ sys.path.insert(0, 'scripts/dtc/pylibfdt') import cmdline import command import control +import test_util def RunTests(debug, args): """Run the functional tests and any embedded doctests @@ -78,33 +79,8 @@ def RunTests(debug, args): def RunTestCoverage(): """Run the tests and check that we get 100% coverage""" - # This uses the build output from sandbox_spl to get _libfdt.so - cmd = ('PYTHONPATH=$PYTHONPATH:%s/sandbox_spl/tools python-coverage run ' - '--include "tools/binman/*.py" --omit "*test*,*binman.py" ' - 'tools/binman/binman.py -t' % options.build_dir) - os.system(cmd) - stdout = command.Output('python-coverage', 'report') - lines = stdout.splitlines() - - test_set= set([os.path.basename(line.split()[0]) - for line in lines if '/etype/' in line]) - glob_list = glob.glob(os.path.join(our_path, 'etype/*.py')) - all_set = set([os.path.basename(item) for item in glob_list]) - missing_list = all_set - missing_list.difference_update(test_set) - missing_list.remove('_testing.py') - coverage = lines[-1].split(' ')[-1] - ok = True - if missing_list: - print 'Missing tests for %s' % (', '.join(missing_list)) - ok = False - if coverage != '100%': - print stdout - print "Type 'coverage html' to get a report in htmlcov/index.html" - print 'Coverage error: %s, but should be 100%%' % coverage - ok = False - if not ok: - raise ValueError('Test coverage failure') + test_util.RunTestCoverage('tools/binman/binman.py', None, + ['*test*', '*binman.py', 'tools/patman/*', 'tools/dtoc/*'], options.build_dir) def RunBinman(options, args): """Main entry point to binman once arguments are parsed diff --git a/tools/patman/test_util.py b/tools/patman/test_util.py new file mode 100644 index 00000000000..a240f383777 --- /dev/null +++ b/tools/patman/test_util.py @@ -0,0 +1,51 @@ +# SPDX-License-Identifier: GPL-2.0+ +# +# Copyright (c) 2016 Google, Inc +# + +import glob +import os +import sys + +import command + +def RunTestCoverage(prog, filter_fname, exclude_list, build_dir): + """Run tests and check that we get 100% coverage + + Args: + prog: Program to run (with be passed a '-t' argument to run tests + filter_fname: Normally all *.py files in the program's directory will + be included. If this is not None, then it is used to filter the + list so that only filenames that don't contain filter_fname are + included. + exclude_list: List of file patterns to exclude from the coverage + calculation + build_dir: Build directory, used to locate libfdt.py + + Raises: + ValueError if the code coverage is not 100% + """ + # This uses the build output from sandbox_spl to get _libfdt.so + path = os.path.dirname(prog) + glob_list = glob.glob(os.path.join(path, '*.py')) + if filter_fname: + glob_list = [fname for fname in glob_list if filter_fname not in fname] + glob_list += exclude_list + glob_list.append('*libfdt.py') + cmd = ('PYTHONPATH=$PYTHONPATH:%s/sandbox_spl/tools python-coverage run ' + '--omit "%s" %s -t' % (build_dir, ','.join(glob_list), prog)) + os.system(cmd) + stdout = command.Output('python-coverage', 'report') + lines = stdout.splitlines() + + coverage = lines[-1].split(' ')[-1] + ok = True + print coverage + if coverage != '100%': + print stdout + print ("Type 'python-coverage html' to get a report in " + 'htmlcov/index.html') + print 'Coverage error: %s, but should be 100%%' % coverage + ok = False + if not ok: + raise ValueError('Test coverage failure') From patchwork Wed Jun 6 00:46:47 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 925688 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" (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.b="nI/HD/HS"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 410r2k1C8Fz9s02 for ; Wed, 6 Jun 2018 11:01:02 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id B9339C21E79; Wed, 6 Jun 2018 00:52:32 +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_DNSWL_BLOCKED, 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 AF400C21DFB; Wed, 6 Jun 2018 00:48:51 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 9EA98C21FE1; Wed, 6 Jun 2018 00:47:57 +0000 (UTC) Received: from mail-it0-f68.google.com (mail-it0-f68.google.com [209.85.214.68]) by lists.denx.de (Postfix) with ESMTPS id 7EFA0C21FAB for ; Wed, 6 Jun 2018 00:47:50 +0000 (UTC) Received: by mail-it0-f68.google.com with SMTP id a195-v6so5905096itd.3 for ; Tue, 05 Jun 2018 17:47:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=GmUTU3xgrfU1vxrvCRjxSsolpgc7Ecna8dDrtyYCVeE=; b=nI/HD/HSoPpjwvhRunPouruQVIq9YkYtdMY7gn5Z0nncNmoOOwbo2UPr7VCuEwOxmp 9FSS9cg/s73TLHIOpoQ0aPpY3tl5xbdvX6TVh+Y6N4Hz4Rv1j5YV0XT89Ajip1jW0KlU jtOXYOIs81OnQnfz1okZtm7I5dD8FbhYNV6E/uzQr56txR5UviajDdIBBv60uSXUjpAc uOcjv4lT7TTO0zdUgSMeqUiX6oDi8WYCRfaWvrzzRAMLkCVmYrjJg35LZRZ/JaZuE87u 4IaZSuXVzr9NeC8sEPNknfOfsjy1xVY4waOeQAdPb05Wqb5Bl0qcEfrqggWReHcOFXMC 2cpQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=GmUTU3xgrfU1vxrvCRjxSsolpgc7Ecna8dDrtyYCVeE=; b=jiIOAaYxPEdMhRtpx1EoUdOfexSyeeBeUBSL3f/FLWJuqLlSqsM3moGBOOKJzJFe9d F1CWllXKP8tHTdw+ZEC04EqTNPEQZ6vb9Rh9uKwu8F3s/AMuwhdbF+2aFgBwtxmEHQHk X//7kURuM4aOpD2NBcvo0yaYBpXtp/e1dRhfnvdLCiBLHdV6cXaX0+INMxV/ToBccCdI LIjrGjg6OpcVqmD0U6biy4p+Fou/YsB86Zz2p7UydS0a5PixNqnqm2FnbMCVaXfE2cdV ZaufckVgwT88S70Sy5hwyuinj4wFTjSgjd0u0gGBGJM8oee6/9KTJfSGtG3pGXZAiYpk GKCQ== X-Gm-Message-State: APt69E2x8vGddTj/FTLdfiDCwxda6+yLQ0AeZi4mP5TgOGjjUMkwynQ/ yy9Ot8OwjtSfPCTlZIYwsnbq1Q== X-Google-Smtp-Source: ADUXVKLjyWKCKJ5YP/eDZcPe2IUIa1DZxH3UGdfVfeQVKcrzVfqskOKtBFWuHGzNuOGRHCAiXYzmOA== X-Received: by 2002:a24:e10d:: with SMTP id n13-v6mr455120ith.83.1528246068904; Tue, 05 Jun 2018 17:47:48 -0700 (PDT) Received: from kiwi.bld.corp.google.com ([100.67.80.24]) by smtp.gmail.com with ESMTPSA id n5-v6sm5680725ioa.42.2018.06.05.17.47.48 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 05 Jun 2018 17:47:48 -0700 (PDT) Received: by kiwi.bld.corp.google.com (Postfix, from userid 121222) id C8915140700; Tue, 5 Jun 2018 18:47:47 -0600 (MDT) From: Simon Glass To: U-Boot Mailing List Date: Tue, 5 Jun 2018 18:46:47 -0600 Message-Id: <20180606004705.79641-12-sjg@chromium.org> X-Mailer: git-send-email 2.17.1.1185.g55be947832-goog In-Reply-To: <20180606004705.79641-1-sjg@chromium.org> References: <20180606004705.79641-1-sjg@chromium.org> Cc: Tom Rini Subject: [U-Boot] [PATCH 11/29] dtoc: Add some tests for the fdt module 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" At present this module is tested via the dtoc tests. This is a bit painful since the tests are at a higher level and so failures are more difficult to diagnose. Add some tests that exercise the fdt module directly. Signed-off-by: Simon Glass --- tools/dtoc/fdt.py | 12 +- tools/dtoc/test_fdt | 1 + tools/dtoc/test_fdt.py | 246 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 257 insertions(+), 2 deletions(-) create mode 120000 tools/dtoc/test_fdt create mode 100755 tools/dtoc/test_fdt.py diff --git a/tools/dtoc/fdt.py b/tools/dtoc/fdt.py index d08b0b53e61..5cde8c125ae 100644 --- a/tools/dtoc/fdt.py +++ b/tools/dtoc/fdt.py @@ -138,6 +138,7 @@ class Prop: else: return TYPE_INT, val + @classmethod def GetEmpty(self, type): """Get an empty / zero value of the given type @@ -335,12 +336,19 @@ class Fdt: """ return self._fdt - def CheckErr(errnum, msg): + def GetFdtObj(self): + """Get the contents of the FDT + + Returns: + The FDT contents as a libfdt.Fdt object + """ + return self._fdt_obj + + def CheckErr(self, errnum, msg): if errnum: raise ValueError('Error %d: %s: %s' % (errnum, libfdt.fdt_strerror(errnum), msg)) - def GetProps(self, node): """Get all properties from a node. diff --git a/tools/dtoc/test_fdt b/tools/dtoc/test_fdt new file mode 120000 index 00000000000..7c3b23031f0 --- /dev/null +++ b/tools/dtoc/test_fdt @@ -0,0 +1 @@ +test_fdt.py \ No newline at end of file diff --git a/tools/dtoc/test_fdt.py b/tools/dtoc/test_fdt.py new file mode 100755 index 00000000000..ba660ca9b75 --- /dev/null +++ b/tools/dtoc/test_fdt.py @@ -0,0 +1,246 @@ +#!/usr/bin/python +# SPDX-License-Identifier: GPL-2.0+ +# Copyright (c) 2018 Google, Inc +# Written by Simon Glass +# + +from optparse import OptionParser +import glob +import os +import sys +import unittest + +# Bring in the patman libraries +our_path = os.path.dirname(os.path.realpath(__file__)) +for dirname in ['../patman', '..']: + sys.path.insert(0, os.path.join(our_path, dirname)) + +import command +import fdt +from fdt import TYPE_BYTE, TYPE_INT, TYPE_STRING, TYPE_BOOL +from fdt_util import fdt32_to_cpu +import libfdt +import test_util +import tools + +class TestFdt(unittest.TestCase): + """Tests for the Fdt module + + This includes unit tests for some functions and functional tests for the fdt + module. + """ + @classmethod + def setUpClass(cls): + tools.PrepareOutputDir(None) + + @classmethod + def tearDownClass(cls): + tools._FinaliseForTest() + + def setUp(self): + self.dtb = fdt.FdtScan('tools/dtoc/dtoc_test_simple.dts') + + def testFdt(self): + """Test that we can open an Fdt""" + self.dtb.Scan() + root = self.dtb.GetRoot() + self.assertTrue(isinstance(root, fdt.Node)) + + def testGetNode(self): + """Test the GetNode() method""" + node = self.dtb.GetNode('/spl-test') + self.assertTrue(isinstance(node, fdt.Node)) + node = self.dtb.GetNode('/i2c@0/pmic@9') + self.assertTrue(isinstance(node, fdt.Node)) + self.assertEqual('pmic@9', node.name) + + def testFlush(self): + """Check that we can flush the device tree out to its file""" + fname = self.dtb._fname + with open(fname) as fd: + data = fd.read() + os.remove(fname) + with self.assertRaises(IOError): + open(fname) + self.dtb.Flush() + with open(fname) as fd: + data = fd.read() + + def testPack(self): + """Test that packing a device tree works""" + self.dtb.Pack() + + def testGetFdt(self): + """Tetst that we can access the raw device-tree data""" + self.assertTrue(isinstance(self.dtb.GetFdt(), bytearray)) + + def testGetProps(self): + """Tests obtaining a list of properties""" + node = self.dtb.GetNode('/spl-test') + props = self.dtb.GetProps(node) + self.assertEqual(['boolval', 'bytearray', 'byteval', 'compatible', + 'intarray', 'intval', 'longbytearray', + 'stringarray', 'stringval', 'u-boot,dm-pre-reloc'], + sorted(props.keys())) + + def testCheckError(self): + """Tests the ChecKError() function""" + with self.assertRaises(ValueError) as e: + self.dtb.CheckErr(-libfdt.NOTFOUND, 'hello') + self.assertIn('FDT_ERR_NOTFOUND: hello', str(e.exception)) + + +class TestNode(unittest.TestCase): + """Test operation of the Node class""" + + @classmethod + def setUpClass(cls): + tools.PrepareOutputDir(None) + + @classmethod + def tearDownClass(cls): + tools._FinaliseForTest() + + def setUp(self): + self.dtb = fdt.FdtScan('tools/dtoc/dtoc_test_simple.dts') + self.node = self.dtb.GetNode('/spl-test') + + def testOffset(self): + """Tests that we can obtain the offset of a node""" + self.assertTrue(self.node.Offset() > 0) + + def testDelete(self): + """Tests that we can delete a property""" + node2 = self.dtb.GetNode('/spl-test2') + offset1 = node2.Offset() + self.node.DeleteProp('intval') + offset2 = node2.Offset() + self.assertTrue(offset2 < offset1) + self.node.DeleteProp('intarray') + offset3 = node2.Offset() + self.assertTrue(offset3 < offset2) + + def testFindNode(self): + """Tests that we can find a node using the _FindNode() functoin""" + node = self.dtb.GetRoot()._FindNode('i2c@0') + self.assertEqual('i2c@0', node.name) + subnode = node._FindNode('pmic@9') + self.assertEqual('pmic@9', subnode.name) + + +class TestProp(unittest.TestCase): + """Test operation of the Prop class""" + + @classmethod + def setUpClass(cls): + tools.PrepareOutputDir(None) + + @classmethod + def tearDownClass(cls): + tools._FinaliseForTest() + + def setUp(self): + self.dtb = fdt.FdtScan('tools/dtoc/dtoc_test_simple.dts') + self.node = self.dtb.GetNode('/spl-test') + self.fdt = self.dtb.GetFdtObj() + + def testGetEmpty(self): + """Tests the GetEmpty() function for the various supported types""" + self.assertEqual(True, fdt.Prop.GetEmpty(fdt.TYPE_BOOL)) + self.assertEqual(chr(0), fdt.Prop.GetEmpty(fdt.TYPE_BYTE)) + self.assertEqual(chr(0) * 4, fdt.Prop.GetEmpty(fdt.TYPE_INT)) + self.assertEqual('', fdt.Prop.GetEmpty(fdt.TYPE_STRING)) + + def testGetOffset(self): + """Test we can get the offset of a property""" + prop = self.node.props['longbytearray'] + + # Add 12, which is sizeof(struct fdt_property), to get to start of data + offset = prop.GetOffset() + 12 + data = self.dtb._fdt[offset:offset + len(prop.value)] + bytes = [chr(x) for x in data] + self.assertEqual(bytes, prop.value) + + def testWiden(self): + """Test widening of values""" + node2 = self.dtb.GetNode('/spl-test2') + prop = self.node.props['intval'] + + # No action + prop2 = node2.props['intval'] + prop.Widen(prop2) + self.assertEqual(fdt.TYPE_INT, prop.type) + self.assertEqual(1, fdt32_to_cpu(prop.value)) + + # Convert singla value to array + prop2 = self.node.props['intarray'] + prop.Widen(prop2) + self.assertEqual(fdt.TYPE_INT, prop.type) + self.assertTrue(isinstance(prop.value, list)) + + # A 4-byte array looks like a single integer. When widened by a longer + # byte array, it should turn into an array. + prop = self.node.props['longbytearray'] + prop2 = node2.props['longbytearray'] + self.assertFalse(isinstance(prop2.value, list)) + self.assertEqual(4, len(prop2.value)) + prop2.Widen(prop) + self.assertTrue(isinstance(prop2.value, list)) + self.assertEqual(9, len(prop2.value)) + + # Similarly for a string array + prop = self.node.props['stringval'] + prop2 = node2.props['stringarray'] + self.assertFalse(isinstance(prop.value, list)) + self.assertEqual(7, len(prop.value)) + prop.Widen(prop2) + self.assertTrue(isinstance(prop.value, list)) + self.assertEqual(3, len(prop.value)) + + # Enlarging an existing array + prop = self.node.props['stringarray'] + prop2 = node2.props['stringarray'] + self.assertTrue(isinstance(prop.value, list)) + self.assertEqual(2, len(prop.value)) + prop.Widen(prop2) + self.assertTrue(isinstance(prop.value, list)) + self.assertEqual(3, len(prop.value)) + + +def RunTests(args): + """Run all the test we have for the fdt model + + Args: + args: List of positional args provided to fdt. This can hold a test + name to execute (as in 'fdt -t testFdt', for example) + """ + result = unittest.TestResult() + sys.argv = [sys.argv[0]] + test_name = args and args[0] or None + for module in (TestFdt, TestNode, TestProp): + if test_name: + try: + suite = unittest.TestLoader().loadTestsFromName(test_name, module) + except AttributeError: + continue + else: + suite = unittest.TestLoader().loadTestsFromTestCase(module) + suite.run(result) + + print result + for _, err in result.errors: + print err + for _, err in result.failures: + print err + +if __name__ != '__main__': + sys.exit(1) + +parser = OptionParser() +parser.add_option('-t', '--test', action='store_true', dest='test', + default=False, help='run tests') +(options, args) = parser.parse_args() + +# Run our meagre tests +if options.test: + RunTests(args) From patchwork Wed Jun 6 00:46:48 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 925690 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" (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.b="G0gTBQtE"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 410r371JGZz9s02 for ; Wed, 6 Jun 2018 11:01:23 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id D921EC21EDC; Wed, 6 Jun 2018 00:53:49 +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_DNSWL_BLOCKED, 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 8A1E6C21FAD; Wed, 6 Jun 2018 00:49:20 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id C6AFCC21FED; Wed, 6 Jun 2018 00:47:57 +0000 (UTC) Received: from mail-it0-f65.google.com (mail-it0-f65.google.com [209.85.214.65]) by lists.denx.de (Postfix) with ESMTPS id C01B2C21F6E for ; Wed, 6 Jun 2018 00:47:52 +0000 (UTC) Received: by mail-it0-f65.google.com with SMTP id k17-v6so15988164ita.0 for ; Tue, 05 Jun 2018 17:47:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=kqTyuuLY61c+HrWdYFF2vRe0ma6Us+nEz6KeuDrc6RM=; b=G0gTBQtEYfyO3aN8bOa7gObeKESJoUsMEAtZhkeAGqzjp3qrOHl2wLypPKK5CZlNa3 ZJdwh3lvuF6qpvMUCoSWbZUDYXetBv+NKtCTJOfJcU1pUUIXUALpcSSKhAWp/wDaE0/1 UG0S5P+GmBhkqw/jwzaj0kT4IUX7vZSXeIk3jv+t9E9KMUHgYvBCUPW8Jm9xjRAqrD0Y THHcgIEM/rbu9rp+0Pv/FNZfCz0ETJT98nblDzCpXgN/DAUHY/SWsnwEr8i+XxGEq8rc yjqhulWqqPhXuT9Grt1vAUPrv/JelyCS4wE6M7OaT3xGcVZ7LMPGQmFaC/wLkj3DjuIS mktQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=kqTyuuLY61c+HrWdYFF2vRe0ma6Us+nEz6KeuDrc6RM=; b=Wii7IikmftX4L1xD5MOFy5dqr1WAez5k2dWKn4dmXpaa+9VP9GA/wrwEFnBs9aw+s4 f9EG0y0HrT83sH85N+2+55dWCDi2akemGQ+Qz2vAZMYwx5YzLRnlZeDfHLpeTZRgvNTT 7dJhhQ8Rt6MUzaQxeuvxA97LB8hqVu4H0s3NhWTC2ASWpktAy19FI5kYzMZFeFK01Qmt hWkpWMQpC0pK2skZW6yw/yB1d+m89D6aqiIAdOgb0/hDf8IS/o0a34g6H3PV/D1PtvxB 5ZCdCEBnfCfYjwPzDahWqrzFv73lDKPQcUkpp1w8AuCugctko2Um4eytWCpnJssCwxb8 0dDg== X-Gm-Message-State: APt69E0MdoLjQYhM9ZwJzTV2TxjTwgcRaPyD3UGWX2htAYLZGPFKJtGO NqeSMq6y5zcV7A9/a5LPncXttA== X-Google-Smtp-Source: ADUXVKKMsCET+qrNQiBJNWY1kwYZmYW65j8rs6raLEXL33lKNCKqY06hQMfB0nIuBDFWGM+vjb9j9w== X-Received: by 2002:a24:552:: with SMTP id 79-v6mr487211itl.109.1528246071229; Tue, 05 Jun 2018 17:47:51 -0700 (PDT) Received: from kiwi.bld.corp.google.com ([100.67.80.24]) by smtp.gmail.com with ESMTPSA id d202-v6sm1517436itc.30.2018.06.05.17.47.50 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 05 Jun 2018 17:47:50 -0700 (PDT) Received: by kiwi.bld.corp.google.com (Postfix, from userid 121222) id D37E7140700; Tue, 5 Jun 2018 18:47:49 -0600 (MDT) From: Simon Glass To: U-Boot Mailing List Date: Tue, 5 Jun 2018 18:46:48 -0600 Message-Id: <20180606004705.79641-13-sjg@chromium.org> X-Mailer: git-send-email 2.17.1.1185.g55be947832-goog In-Reply-To: <20180606004705.79641-1-sjg@chromium.org> References: <20180606004705.79641-1-sjg@chromium.org> Cc: Tom Rini Subject: [U-Boot] [PATCH 12/29] dtoc: Update tests to write failures to /tmp 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" When a test fails due to an output mismatch (e.g. due to a new property being adding to a test file) it is currently hard to update the test to the new output. In particular the tabs in the file are written as \t in the Python tests. To make this easier, write both the expected and actual results to /tmp to allow use of meld, and copying into the test. Signed-off-by: Simon Glass --- tools/dtoc/test_dtoc.py | 56 ++++++++++++++++++++++++++++++----------- 1 file changed, 42 insertions(+), 14 deletions(-) diff --git a/tools/dtoc/test_dtoc.py b/tools/dtoc/test_dtoc.py index e475a7eb14e..ce6d2585a40 100644 --- a/tools/dtoc/test_dtoc.py +++ b/tools/dtoc/test_dtoc.py @@ -68,6 +68,34 @@ class TestDtoc(unittest.TestCase): def tearDownClass(cls): tools._RemoveOutputDir() + def _WritePythonString(self, fname, data): + """Write a string with tabs expanded as done in this Python file + + Args: + fname: Filename to write to + data: Raw string to convert + """ + data = data.replace('\t', '\\t') + with open(fname, 'w') as fd: + fd.write(data) + + def _CheckStrings(self, expected, actual): + """Check that a string matches its expected value + + If the strings do not match, they are written to the /tmp directory in + the same Python format as is used here in the test. This allows for + easy comparison and update of the tests. + + Args: + expected: Expected string + actual: Actual string + """ + if expected != actual: + self._WritePythonString('/tmp/binman.expected', expected) + self._WritePythonString('/tmp/binman.actual', actual) + print 'Failures written to /tmp/binman.{expected,actual}' + self.assertEquals(expected, actual) + def test_name(self): """Test conversion of device tree names to C identifiers""" self.assertEqual('serial_at_0x12', conv_name_to_c('serial@0x12')) @@ -138,7 +166,7 @@ class TestDtoc(unittest.TestCase): dtb_platdata.run_steps(['struct'], dtb_file, False, output) with open(output) as infile: data = infile.read() - self.assertEqual(HEADER + ''' + self._CheckStrings(HEADER + ''' struct dtd_sandbox_i2c_test { }; struct dtd_sandbox_pmic_test { @@ -162,7 +190,7 @@ struct dtd_sandbox_spl_test_2 { dtb_platdata.run_steps(['platdata'], dtb_file, False, output) with open(output) as infile: data = infile.read() - self.assertEqual(C_HEADER + ''' + self._CheckStrings(C_HEADER + ''' static struct dtd_sandbox_spl_test dtv_spl_test = { \t.bytearray\t\t= {0x6, 0x0, 0x0}, \t.byteval\t\t= 0x5, @@ -240,7 +268,7 @@ U_BOOT_DEVICE(pmic_at_9) = { dtb_platdata.run_steps(['struct'], dtb_file, False, output) with open(output) as infile: data = infile.read() - self.assertEqual(HEADER + ''' + self._CheckStrings(HEADER + ''' struct dtd_source { \tstruct phandle_2_arg clocks[4]; }; @@ -252,7 +280,7 @@ struct dtd_target { dtb_platdata.run_steps(['platdata'], dtb_file, False, output) with open(output) as infile: data = infile.read() - self.assertEqual(C_HEADER + ''' + self._CheckStrings(C_HEADER + ''' static struct dtd_target dtv_phandle_target = { \t.intval\t\t\t= 0x0, }; @@ -302,7 +330,7 @@ U_BOOT_DEVICE(phandle_source) = { dtb_platdata.run_steps(['struct'], dtb_file, False, output) with open(output) as infile: data = infile.read() - self.assertEqual(HEADER + ''' + self._CheckStrings(HEADER + ''' struct dtd_compat1 { \tfdt32_t\t\tintval; }; @@ -313,7 +341,7 @@ struct dtd_compat1 { dtb_platdata.run_steps(['platdata'], dtb_file, False, output) with open(output) as infile: data = infile.read() - self.assertEqual(C_HEADER + ''' + self._CheckStrings(C_HEADER + ''' static struct dtd_compat1 dtv_spl_test = { \t.intval\t\t\t= 0x1, }; @@ -332,7 +360,7 @@ U_BOOT_DEVICE(spl_test) = { dtb_platdata.run_steps(['struct'], dtb_file, False, output) with open(output) as infile: data = infile.read() - self.assertEqual(HEADER + ''' + self._CheckStrings(HEADER + ''' struct dtd_test1 { \tfdt64_t\t\treg[2]; }; @@ -347,7 +375,7 @@ struct dtd_test3 { dtb_platdata.run_steps(['platdata'], dtb_file, False, output) with open(output) as infile: data = infile.read() - self.assertEqual(C_HEADER + ''' + self._CheckStrings(C_HEADER + ''' static struct dtd_test1 dtv_test1 = { \t.reg\t\t\t= {0x1234, 0x5678}, }; @@ -384,7 +412,7 @@ U_BOOT_DEVICE(test3) = { dtb_platdata.run_steps(['struct'], dtb_file, False, output) with open(output) as infile: data = infile.read() - self.assertEqual(HEADER + ''' + self._CheckStrings(HEADER + ''' struct dtd_test1 { \tfdt32_t\t\treg[2]; }; @@ -396,7 +424,7 @@ struct dtd_test2 { dtb_platdata.run_steps(['platdata'], dtb_file, False, output) with open(output) as infile: data = infile.read() - self.assertEqual(C_HEADER + ''' + self._CheckStrings(C_HEADER + ''' static struct dtd_test1 dtv_test1 = { \t.reg\t\t\t= {0x1234, 0x5678}, }; @@ -424,7 +452,7 @@ U_BOOT_DEVICE(test2) = { dtb_platdata.run_steps(['struct'], dtb_file, False, output) with open(output) as infile: data = infile.read() - self.assertEqual(HEADER + ''' + self._CheckStrings(HEADER + ''' struct dtd_test1 { \tfdt64_t\t\treg[2]; }; @@ -439,7 +467,7 @@ struct dtd_test3 { dtb_platdata.run_steps(['platdata'], dtb_file, False, output) with open(output) as infile: data = infile.read() - self.assertEqual(C_HEADER + ''' + self._CheckStrings(C_HEADER + ''' static struct dtd_test1 dtv_test1 = { \t.reg\t\t\t= {0x123400000000, 0x5678}, }; @@ -476,7 +504,7 @@ U_BOOT_DEVICE(test3) = { dtb_platdata.run_steps(['struct'], dtb_file, False, output) with open(output) as infile: data = infile.read() - self.assertEqual(HEADER + ''' + self._CheckStrings(HEADER + ''' struct dtd_test1 { \tfdt64_t\t\treg[2]; }; @@ -491,7 +519,7 @@ struct dtd_test3 { dtb_platdata.run_steps(['platdata'], dtb_file, False, output) with open(output) as infile: data = infile.read() - self.assertEqual(C_HEADER + ''' + self._CheckStrings(C_HEADER + ''' static struct dtd_test1 dtv_test1 = { \t.reg\t\t\t= {0x1234, 0x567800000000}, }; From patchwork Wed Jun 6 00:46:49 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 925673 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" (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.b="ZlClgA7j"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 410qsQ67m0z9s02 for ; Wed, 6 Jun 2018 10:52:58 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 84438C21F98; Wed, 6 Jun 2018 00:51:51 +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_DNSWL_BLOCKED, 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 2970DC21FCE; Wed, 6 Jun 2018 00:48:45 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id A9B26C21E90; Wed, 6 Jun 2018 00:48:03 +0000 (UTC) Received: from mail-it0-f65.google.com (mail-it0-f65.google.com [209.85.214.65]) by lists.denx.de (Postfix) with ESMTPS id 8E254C21FBF for ; Wed, 6 Jun 2018 00:47:59 +0000 (UTC) Received: by mail-it0-f65.google.com with SMTP id p185-v6so5837652itp.4 for ; Tue, 05 Jun 2018 17:47:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=jNtsjZkh4RajLXYQ7dQKq/trZ0xTiWEuZvpC9x59pJs=; b=ZlClgA7jVaih+QE3iiZMW0lQwypXOmki5duNJpsqIJdrhJUXHHfJuP2KRQ8+YylBMs IJzCdIxkYr2zdI4jP0kXGi/rT7fZoKdrC0gujx01GciPFuIX9OREAi8fFt/1Tebzpa0o 1R5dbeJ0UU37c3V2e9yyrZbCm6lM6TffyBfuOTWGoXnzzV15lsA0A6F7f99G6Gv3cJN+ k/VZC9x6ll8HhD0yr7aIhWk953B84bySnlQav5jh14uo1DvE2kG3bJTzk+AfjSv4izVz h365d09oH+wq95yTb7GgusfbpsiExZO6rtvJWZ7xanQEd1rtlWbxJE1Pz6SwI9Aza5g4 eTNw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=jNtsjZkh4RajLXYQ7dQKq/trZ0xTiWEuZvpC9x59pJs=; b=GB8C5eO6URj6MZA2Xw6061yIi7GiG3XKyPHC+LvufcfGK8zRjcMV8lEv9emGWgz2bi qkSCw3ILAZ6EV/UdPWhm14XvTc/erl+yTvyQtOXASV9URootYqN/JXzKMAeEK1XTcXgU 9jmveJ1HFSlmYYWg2wWD1eA4ELGpiGK9g+g6d1m3iFtu59Mf7S9uFNpgwnrA2Zr8IsgE wJ2M/hetxB5HWHmKkg0yz0cX8gI6qyyeNPc/ue9oMw1o3B1BfRgRNZNMA1BgRU4vTmd5 aDBr31zDiBTsP2xTIgtC5Q4nZd6fE7FgB6OX0PPe3njes0ljxLhW+yXyXucDVrzphme0 SlEw== X-Gm-Message-State: APt69E2Di91aXfcF1A270wamelY5dfEeGZ9+jR7cX/6XT5yKgBuIf/Zs MxoS2R62bhAKLZbxhoCqqz8+h5ai4E0= X-Google-Smtp-Source: ADUXVKKs/Y278QkExUH+X4URmur4amOHLH3cUdVVyK9DiLAFL1vZ0H6jOnsAxMjcOH/VIg9Z54E6dQ== X-Received: by 2002:a24:8782:: with SMTP id f124-v6mr535364ite.30.1528246078010; Tue, 05 Jun 2018 17:47:58 -0700 (PDT) Received: from kiwi.bld.corp.google.com ([100.67.80.24]) by smtp.gmail.com with ESMTPSA id i10-v6sm2076018itb.38.2018.06.05.17.47.57 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 05 Jun 2018 17:47:57 -0700 (PDT) Received: by kiwi.bld.corp.google.com (Postfix, from userid 121222) id CBD4B140700; Tue, 5 Jun 2018 18:47:56 -0600 (MDT) From: Simon Glass To: U-Boot Mailing List Date: Tue, 5 Jun 2018 18:46:49 -0600 Message-Id: <20180606004705.79641-14-sjg@chromium.org> X-Mailer: git-send-email 2.17.1.1185.g55be947832-goog In-Reply-To: <20180606004705.79641-1-sjg@chromium.org> References: <20180606004705.79641-1-sjg@chromium.org> Cc: Tom Rini Subject: [U-Boot] [PATCH 13/29] dtoc: Update fdt tests to increase code coverage 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" At present only some of the fdt functionality is tested. Add more tests to cover most things. Also turn on test coverage, which currently sits at 99%. Signed-off-by: Simon Glass --- tools/dtoc/test_fdt.py | 62 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/tools/dtoc/test_fdt.py b/tools/dtoc/test_fdt.py index ba660ca9b75..6dd24f74e5b 100755 --- a/tools/dtoc/test_fdt.py +++ b/tools/dtoc/test_fdt.py @@ -119,6 +119,8 @@ class TestNode(unittest.TestCase): self.node.DeleteProp('intarray') offset3 = node2.Offset() self.assertTrue(offset3 < offset2) + with self.assertRaises(ValueError): + self.node.DeleteProp('missing') def testFindNode(self): """Tests that we can find a node using the _FindNode() functoin""" @@ -126,6 +128,7 @@ class TestNode(unittest.TestCase): self.assertEqual('i2c@0', node.name) subnode = node._FindNode('pmic@9') self.assertEqual('pmic@9', subnode.name) + self.assertEqual(None, node._FindNode('missing')) class TestProp(unittest.TestCase): @@ -144,6 +147,53 @@ class TestProp(unittest.TestCase): self.node = self.dtb.GetNode('/spl-test') self.fdt = self.dtb.GetFdtObj() + def testPhandle(self): + dtb = fdt.FdtScan('tools/dtoc/dtoc_test_phandle.dts') + node = dtb.GetNode('/phandle-source') + + def _ConvertProp(self, prop_name): + """Helper function to look up a property in self.node and return it + + Args: + Property name to find + + Return fdt.Prop object for this property + """ + p = self.fdt.get_property(self.node.Offset(), prop_name) + return fdt.Prop(self.node, -1, prop_name, p) + + def testMakeProp(self): + """Test we can convert all the the types that are supported""" + prop = self._ConvertProp('boolval') + self.assertEqual(fdt.TYPE_BOOL, prop.type) + self.assertEqual(True, prop.value) + + prop = self._ConvertProp('intval') + self.assertEqual(fdt.TYPE_INT, prop.type) + self.assertEqual(1, fdt32_to_cpu(prop.value)) + + prop = self._ConvertProp('intarray') + self.assertEqual(fdt.TYPE_INT, prop.type) + val = [fdt32_to_cpu(val) for val in prop.value] + self.assertEqual([2, 3, 4], val) + + prop = self._ConvertProp('byteval') + self.assertEqual(fdt.TYPE_BYTE, prop.type) + self.assertEqual(5, ord(prop.value)) + + prop = self._ConvertProp('longbytearray') + self.assertEqual(fdt.TYPE_BYTE, prop.type) + val = [ord(val) for val in prop.value] + self.assertEqual([9, 10, 11, 12, 13, 14, 15, 16, 17], val) + + prop = self._ConvertProp('stringval') + self.assertEqual(fdt.TYPE_STRING, prop.type) + self.assertEqual('message', prop.value) + + prop = self._ConvertProp('stringarray') + self.assertEqual(fdt.TYPE_STRING, prop.type) + self.assertEqual(['multi-word', 'message'], prop.value) + def testGetEmpty(self): """Tests the GetEmpty() function for the various supported types""" self.assertEqual(True, fdt.Prop.GetEmpty(fdt.TYPE_BOOL)) @@ -207,6 +257,12 @@ class TestProp(unittest.TestCase): self.assertEqual(3, len(prop.value)) +def RunTestCoverage(): + """Run the tests and check that we get 100% coverage""" + test_util.RunTestCoverage('tools/dtoc/test_fdt.py', '/fdt.py', + ['tools/patman/*.py'], options.build_dir) + + def RunTests(args): """Run all the test we have for the fdt model @@ -237,10 +293,16 @@ if __name__ != '__main__': sys.exit(1) parser = OptionParser() +parser.add_option('-B', '--build-dir', type='string', default='b', + help='Directory containing the build output') parser.add_option('-t', '--test', action='store_true', dest='test', default=False, help='run tests') +parser.add_option('-T', '--test-coverage', action='store_true', + default=False, help='run tests and check for 100% coverage') (options, args) = parser.parse_args() # Run our meagre tests if options.test: RunTests(args) +elif options.test_coverage: + RunTestCoverage() From patchwork Wed Jun 6 00:46:50 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 925677 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" (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.b="cvCfcp2p"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 410qtj65W3z9s02 for ; Wed, 6 Jun 2018 10:54:05 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 639E2C21F52; Wed, 6 Jun 2018 00:50:57 +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_DNSWL_BLOCKED, 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 DEA57C21F6E; Wed, 6 Jun 2018 00:48:29 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 2C51CC21EDE; Wed, 6 Jun 2018 00:48:06 +0000 (UTC) Received: from mail-it0-f48.google.com (mail-it0-f48.google.com [209.85.214.48]) by lists.denx.de (Postfix) with ESMTPS id C65ECC21FD1 for ; Wed, 6 Jun 2018 00:48:01 +0000 (UTC) Received: by mail-it0-f48.google.com with SMTP id 144-v6so5867626iti.5 for ; Tue, 05 Jun 2018 17:48:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=oGJFLzRgqSTZadE0KfdjtZYiBF2pc7f6p+e3fE8R7AA=; b=cvCfcp2p0cRWgZ3xi2QtiKYe3m+hBNtPCVyy3mQRe0+Fm6701IYOHlWS5SaQ+I9Gx4 CNW6FT13tHJ/HLeHIs9U8YaVAQYWH6Ywhm+GJeubIEWUC4ZrYAOb7Y0wBRbXEg4v1rMR +XggJp6cbHEDlxn+rUQDo9xI6C/2RCoCGjlSPR6yxWk2rctOPw119wHqJvwd2tKfx6GT pB+NFgDMkvSTcNp2NA2LM9AWPEericR8JzTJuT1tnAv5tJlVprK3FtCZfkj3Gy0jAun8 e7fX29X/iczCmMeGnx3ZnfqAm7hJSisPARAe4d73QImXOd5YhzvSP1UY2OXzkdzK7yHi rrNA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=oGJFLzRgqSTZadE0KfdjtZYiBF2pc7f6p+e3fE8R7AA=; b=iU2Tsw8bVMTJ3VDIUpPkA7l0jYGK61QX9iazS5q7s2MekU1pibp2nRfcoNXAI3i8kD 8qDjSLc8e4MSNEE53oqjn1aid5nBB/6KRAsB2QPm9LKlNv1UXHpF+K6/ytr5wZW24ncm 6iK81ponu4RSO2EAhnPbN/Mupa/V3FpFy7m4yvT4g5x5fdI0KtXT7TFlLzDFjS54pPlU JGhopwP5YDK772GhsesNt8CSaQwpMawgcaxf3lO5CpX4pB/mZn2B4kt7FSjF67LwO9Fs 3fntWmclaGgL/t5ZGekoP04YhlIF620kNB1H22xoSuc87JtWGMmPFMRkB5Gvh7V5Yza+ Z2EA== X-Gm-Message-State: APt69E2FLjHCMdrkhTDcxAQ2UFIpeBxosWgdjfWnmgcZ8GdonSqd97aa LDrPfWSyqx8Osp7L4Pp6qTDuGA== X-Google-Smtp-Source: ADUXVKK/zUuMqr4gL0UowA3NnNOormJy5h4PvNhKpiGryAo1ZSebOy1QjJgg6oQDGRQTxMjrQzzYKw== X-Received: by 2002:a24:154c:: with SMTP id 73-v6mr508956itq.51.1528246080242; Tue, 05 Jun 2018 17:48:00 -0700 (PDT) Received: from kiwi.bld.corp.google.com ([100.67.80.24]) by smtp.gmail.com with ESMTPSA id e204-v6sm6062316ioa.34.2018.06.05.17.47.58 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 05 Jun 2018 17:47:58 -0700 (PDT) Received: by kiwi.bld.corp.google.com (Postfix, from userid 121222) id 3CEF9140700; Tue, 5 Jun 2018 18:47:58 -0600 (MDT) From: Simon Glass To: U-Boot Mailing List Date: Tue, 5 Jun 2018 18:46:50 -0600 Message-Id: <20180606004705.79641-15-sjg@chromium.org> X-Mailer: git-send-email 2.17.1.1185.g55be947832-goog In-Reply-To: <20180606004705.79641-1-sjg@chromium.org> References: <20180606004705.79641-1-sjg@chromium.org> Cc: Tom Rini Subject: [U-Boot] [PATCH 14/29] dtoc: Make use of the new pylibfdt methods 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" Now that pylibfdt supports a fuller API we don't need to directly call the libfdt stubs. Update the code to use the Fdt methods instead. Some other cases remain which will be tidied up in a later commit, since they need larger changes. Signed-off-by: Simon Glass --- tools/dtoc/fdt.py | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/tools/dtoc/fdt.py b/tools/dtoc/fdt.py index 5cde8c125ae..18cde2604ff 100644 --- a/tools/dtoc/fdt.py +++ b/tools/dtoc/fdt.py @@ -10,6 +10,7 @@ import sys import fdt_util import libfdt +from libfdt import QUIET_NOTFOUND # This deals with a device tree, presenting it as an assortment of Node and # Prop objects, representing nodes and properties, respectively. This file @@ -211,22 +212,22 @@ class Node: This fills in the props and subnodes properties, recursively searching into subnodes so that the entire tree is built. """ + fdt_obj = self._fdt._fdt_obj self.props = self._fdt.GetProps(self) - phandle = self.props.get('phandle') + phandle = fdt_obj.get_phandle(self.Offset()) if phandle: - val = fdt_util.fdt32_to_cpu(phandle.value) - self._fdt.phandle_to_node[val] = self + self._fdt.phandle_to_node[phandle] = self - offset = libfdt.fdt_first_subnode(self._fdt.GetFdt(), self.Offset()) + offset = fdt_obj.first_subnode(self.Offset(), QUIET_NOTFOUND) while offset >= 0: sep = '' if self.path[-1] == '/' else '/' - name = self._fdt._fdt_obj.get_name(offset) + name = fdt_obj.get_name(offset) path = self.path + sep + name node = Node(self._fdt, self, offset, name, path) self.subnodes.append(node) node.Scan() - offset = libfdt.fdt_next_subnode(self._fdt.GetFdt(), offset) + offset = fdt_obj.next_subnode(offset, QUIET_NOTFOUND) def Refresh(self, my_offset): """Fix up the _offset for each node, recursively @@ -324,9 +325,8 @@ class Fdt: When nodes and properties shrink or are deleted, wasted space can build up in the device tree binary. """ - CheckErr(libfdt.fdt_pack(self._fdt), 'pack') - fdt_len = libfdt.fdt_totalsize(self._fdt) - del self._fdt[fdt_len:] + CheckErr(self._fdt_obj.pack(), 'pack') + self.Invalidate() def GetFdt(self): """Get the contents of the FDT @@ -363,13 +363,15 @@ class Fdt: ValueError: if the node does not exist. """ props_dict = {} - poffset = libfdt.fdt_first_property_offset(self._fdt, node._offset) + poffset = self._fdt_obj.first_property_offset(node._offset, + QUIET_NOTFOUND) while poffset >= 0: p = self._fdt_obj.get_property_by_offset(poffset) prop = Prop(node, poffset, p.name, p) props_dict[prop.name] = prop - poffset = libfdt.fdt_next_property_offset(self._fdt, poffset) + poffset = self._fdt_obj.next_property_offset(poffset, + QUIET_NOTFOUND) return props_dict def Invalidate(self): @@ -395,7 +397,7 @@ class Fdt: Returns: Position of @offset within the device tree binary """ - return libfdt.fdt_off_dt_struct(self._fdt) + offset + return self._fdt_obj.off_dt_struct() + offset @classmethod def Node(self, fdt, parent, offset, name, path): From patchwork Wed Jun 6 00:46:51 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 925685 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" (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.b="KOjsRs7g"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 410r1k3CSTz9s02 for ; Wed, 6 Jun 2018 11:00:10 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 20C47C21F85; Wed, 6 Jun 2018 00:53:15 +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=1.5 required=5.0 tests=RCVD_IN_DNSWL_BLOCKED, RCVD_IN_MSPIKE_H2, TVD_PH_BODY_ACCOUNTS_PRE, T_DKIM_INVALID autolearn=no autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 96D28C21E90; Wed, 6 Jun 2018 00:49:02 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 89CAAC21FC5; Wed, 6 Jun 2018 00:48:06 +0000 (UTC) Received: from mail-io0-f194.google.com (mail-io0-f194.google.com [209.85.223.194]) by lists.denx.de (Postfix) with ESMTPS id 0272EC21FD8 for ; Wed, 6 Jun 2018 00:48:03 +0000 (UTC) Received: by mail-io0-f194.google.com with SMTP id e15-v6so5665086iog.1 for ; Tue, 05 Jun 2018 17:48:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=aIdGIpMOsyMEhXAC0tax1kv+WIj8ZXpHbQNdQ80/ER8=; b=KOjsRs7geYI0daHAELDpAYbbaHcdycer5/OhIwz0AXXjz/BGOXLmWRPeJ3o3RyPKI1 I/5GIB9hIXUmPuGTu0BER/mtMQ3SgPMp1qkSW1fcI8pUvBVD9yADg+PyBMGyFSfSbl+M 6+0JKa7Q+o+O/MgEkPrxitZ60VYSCvLBsXmJdP3MFGAbtpp7cMOAsckRsICBe3o+MMmo CcHUvg+2kyfTujnNTtimoNdTXFjaG4FhJqCGBS0cceVp/OYBPBWXCohgnnvSvLdHbs1s Gy1w+Uhqcrn15dTKpoEcfZ1Jw9mssSVj+4bHCLp579b6C5UmR9apwOzyfk0F5yWn4uyh e62w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=aIdGIpMOsyMEhXAC0tax1kv+WIj8ZXpHbQNdQ80/ER8=; b=hvoWuTz3q7bi5dULVWj7bUAxHlOtuIL8/wAEzkr3lexhLZ3UMAvEr2TuTGd8kAjTVe ahhbTjrCBlim0BWWfqrsKFyBQ2WXtTTca61KQhsBklwlgZNbxmQ7DuISROkACxyCEF2x nn11Y4BdUHBuQDLZdKntO+g5OnnpFG168krPIXmJFX5P9MwGp4RG2BEeCHTzcHb9LBBt 9twhRvLiFu5Erak9I1AQ821ybabo+sBCVG6lbl8dUz1OyBe3KIm/Bsz8KCGVyg+GNweC 0wzvaFzOqxrsjyOE+iFnxUBMwLnQnWRk195vO67GXciNfBCv2Pc+jZZmRdawHF12SgIf pE5Q== X-Gm-Message-State: APt69E1FQcDl0r1oWCNP19JXGv/iWp0/0skIpZ4gJcYLIhi2zpm7JZrC fKZwNqhCujPq9cZuBBx+zyZm4g== X-Google-Smtp-Source: ADUXVKJzwB/NWnbkCwR9caCnX56ncKE9wNGohoRS7B1kizB4IDThFz9GdZJEVgI2BzFUpGEQICvv9A== X-Received: by 2002:a6b:9c95:: with SMTP id f143-v6mr865904ioe.22.1528246081402; Tue, 05 Jun 2018 17:48:01 -0700 (PDT) Received: from kiwi.bld.corp.google.com ([100.67.80.24]) by smtp.gmail.com with ESMTPSA id p20-v6sm127405itf.4.2018.06.05.17.48.00 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 05 Jun 2018 17:48:00 -0700 (PDT) Received: by kiwi.bld.corp.google.com (Postfix, from userid 121222) id EFD411409F9; Tue, 5 Jun 2018 18:47:59 -0600 (MDT) From: Simon Glass To: U-Boot Mailing List Date: Tue, 5 Jun 2018 18:46:51 -0600 Message-Id: <20180606004705.79641-16-sjg@chromium.org> X-Mailer: git-send-email 2.17.1.1185.g55be947832-goog In-Reply-To: <20180606004705.79641-1-sjg@chromium.org> References: <20180606004705.79641-1-sjg@chromium.org> Cc: Tom Rini Subject: [U-Boot] [PATCH 15/29] dtoc: Drop use of a local dtb buffer 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" At present the Fdt class has its own copy of the device tree. This is confusing an unnecessary now that pylibfdt has its own. Drop it and provide access functions to the buffer. This allows us to move the rest of the implementation to use pylibfdt methods instead of directly calling libfdt stubs. Signed-off-by: Simon Glass --- tools/dtoc/fdt.py | 16 ++++++++-------- tools/dtoc/test_fdt.py | 6 +++--- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/tools/dtoc/fdt.py b/tools/dtoc/fdt.py index 18cde2604ff..e24acf12804 100644 --- a/tools/dtoc/fdt.py +++ b/tools/dtoc/fdt.py @@ -235,12 +235,13 @@ class Node: Note: This does not take account of property offsets - these will not be updated. """ + fdt_obj = self._fdt._fdt_obj if self._offset != my_offset: self._offset = my_offset - offset = libfdt.fdt_first_subnode(self._fdt.GetFdt(), self._offset) + offset = fdt_obj.first_subnode(self._offset, QUIET_NOTFOUND) for subnode in self.subnodes: subnode.Refresh(offset) - offset = libfdt.fdt_next_subnode(self._fdt.GetFdt(), offset) + offset = fdt_obj.next_subnode(offset, QUIET_NOTFOUND) def DeleteProp(self, prop_name): """Delete a property of a node @@ -252,7 +253,7 @@ class Node: Raises: ValueError if the property does not exist """ - CheckErr(libfdt.fdt_delprop(self._fdt.GetFdt(), self.Offset(), prop_name), + CheckErr(self._fdt._fdt_obj.delprop(self.Offset(), prop_name), "Node '%s': delete property: '%s'" % (self.path, prop_name)) del self.props[prop_name] self._fdt.Invalidate() @@ -272,8 +273,7 @@ class Fdt: self._fname = fdt_util.EnsureCompiled(self._fname) with open(self._fname) as fd: - self._fdt = bytearray(fd.read()) - self._fdt_obj = libfdt.Fdt(self._fdt) + self._fdt_obj = libfdt.Fdt(fd.read()) def Scan(self, root='/'): """Scan a device tree, building up a tree of Node objects @@ -317,7 +317,7 @@ class Fdt: If the device tree has changed in memory, write it back to the file. """ with open(self._fname, 'wb') as fd: - fd.write(self._fdt) + fd.write(self._fdt_obj.as_bytearray()) def Pack(self): """Pack the device tree down to its minimum size @@ -328,13 +328,13 @@ class Fdt: CheckErr(self._fdt_obj.pack(), 'pack') self.Invalidate() - def GetFdt(self): + def GetContents(self): """Get the contents of the FDT Returns: The FDT contents as a string of bytes """ - return self._fdt + return self._fdt_obj.as_bytearray() def GetFdtObj(self): """Get the contents of the FDT diff --git a/tools/dtoc/test_fdt.py b/tools/dtoc/test_fdt.py index 6dd24f74e5b..ba95a4b77de 100755 --- a/tools/dtoc/test_fdt.py +++ b/tools/dtoc/test_fdt.py @@ -72,7 +72,7 @@ class TestFdt(unittest.TestCase): def testGetFdt(self): """Tetst that we can access the raw device-tree data""" - self.assertTrue(isinstance(self.dtb.GetFdt(), bytearray)) + self.assertTrue(isinstance(self.dtb.GetContents(), bytearray)) def testGetProps(self): """Tests obtaining a list of properties""" @@ -119,7 +119,7 @@ class TestNode(unittest.TestCase): self.node.DeleteProp('intarray') offset3 = node2.Offset() self.assertTrue(offset3 < offset2) - with self.assertRaises(ValueError): + with self.assertRaises(libfdt.FdtException): self.node.DeleteProp('missing') def testFindNode(self): @@ -207,7 +207,7 @@ class TestProp(unittest.TestCase): # Add 12, which is sizeof(struct fdt_property), to get to start of data offset = prop.GetOffset() + 12 - data = self.dtb._fdt[offset:offset + len(prop.value)] + data = self.dtb.GetContents()[offset:offset + len(prop.value)] bytes = [chr(x) for x in data] self.assertEqual(bytes, prop.value) From patchwork Wed Jun 6 00:46:52 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 925678 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" (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.b="BcHpBGew"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 410qvN4yyvz9s02 for ; Wed, 6 Jun 2018 10:54:40 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 4CDF6C21EBA; Wed, 6 Jun 2018 00:51:15 +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_DNSWL_BLOCKED, 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 0C3ECC21F88; Wed, 6 Jun 2018 00:48:39 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 0D1FDC21F63; Wed, 6 Jun 2018 00:48:08 +0000 (UTC) Received: from mail-it0-f66.google.com (mail-it0-f66.google.com [209.85.214.66]) by lists.denx.de (Postfix) with ESMTPS id 4D6B1C21FC4 for ; Wed, 6 Jun 2018 00:48:04 +0000 (UTC) Received: by mail-it0-f66.google.com with SMTP id k17-v6so15988468ita.0 for ; Tue, 05 Jun 2018 17:48:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=xA8GQps6SQ8NrR0+6lcFs5o7pR+v6PBlO4HlSCSMQpo=; b=BcHpBGewm7VyVnAFoidiuQc3KeG68Z0aOuKJwt1KBDfoGl2OxxQAXcUf6mm44KesCY YNt0wamcxn4AsgwkwCxDa6/n/drdzN5VIQbKpJEFHyBrbSszhRgytJiqO1rNrbrjlCEN gXZ8HDApEYFh4UqJ8QbyNgaFxG5pTN0n1SnEr16CL2jsiEbPC2e+TFvHBGQDEM2z8pZN 1SME36d5FRHoF1ydlc+BC83yn6tY5jGHF3v9Q05paNWa/5bfyL2hfp7pyZiXEfHjpDsa nslSFxp6234FGoTzn7txiz9kagoupiUALd/9DHeZgWuXByxPoNMyePYS11F7qVZ/kLrd IpTQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=xA8GQps6SQ8NrR0+6lcFs5o7pR+v6PBlO4HlSCSMQpo=; b=W+eGTisOoUBxjZjbYNpc5i0GUMJprESTbKRqjXgvm+Q2UT2rFCRsFHwM0chqDESaiI WmBK7M66km0lSYqVbxl7RydgS6J3OgoH/uywpLfOVr79+u5ti9HBuRmnwbGgC8KYT/Rg UfDK+N+kum4wfU2L/4dd8/4Zji3fo3Q+sQNWrrOXDraHrKq5GiyG5UyMFGiVTMGFptZx 1Zw/NMlUhTor4TL/5VEo3d3wRSEM+OZwtW4cVypWLbwt5auVysDGOaZwTnK/nhuI7xvQ qqHNsjbcnjIeupcqTfGUxIsc0wxAbz5X6uWuM53qGJqgAyzr5X73bLQ+ZCNWYu4R9ZqU mIFQ== X-Gm-Message-State: APt69E1w1Hz8PAyFyfR5PstiFaTp2fOX3mELa1IuNIS8zkBiumgdlZuZ ZUCwehNnVjeKRR2E1b1aw5Yakw== X-Google-Smtp-Source: ADUXVKL6LzlY4Q2qmZT+Xy5XqsAlGOyxv7WhmuTH25ZGxs9ByaPj7x7T7tnoitxeDtyORKn9lnYqYg== X-Received: by 2002:a24:ad22:: with SMTP id c34-v6mr496617itf.75.1528246082720; Tue, 05 Jun 2018 17:48:02 -0700 (PDT) Received: from kiwi.bld.corp.google.com ([100.67.80.24]) by smtp.gmail.com with ESMTPSA id o137-v6sm7347768ioe.3.2018.06.05.17.48.01 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 05 Jun 2018 17:48:01 -0700 (PDT) Received: by kiwi.bld.corp.google.com (Postfix, from userid 121222) id 665FE140700; Tue, 5 Jun 2018 18:48:01 -0600 (MDT) From: Simon Glass To: U-Boot Mailing List Date: Tue, 5 Jun 2018 18:46:52 -0600 Message-Id: <20180606004705.79641-17-sjg@chromium.org> X-Mailer: git-send-email 2.17.1.1185.g55be947832-goog In-Reply-To: <20180606004705.79641-1-sjg@chromium.org> References: <20180606004705.79641-1-sjg@chromium.org> Cc: Tom Rini Subject: [U-Boot] [PATCH 16/29] dtoc: Keep track of property offsets 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" At present the Fdt class does not keep track of property offsets if they change due to removal of properties. Update the code to handle this, and add a test. Signed-off-by: Simon Glass --- tools/dtoc/fdt.py | 19 +++++++++++++++++++ tools/dtoc/test_fdt.py | 39 ++++++++++++++++++++++++++++++++------- 2 files changed, 51 insertions(+), 7 deletions(-) diff --git a/tools/dtoc/fdt.py b/tools/dtoc/fdt.py index e24acf12804..2d7b6328f11 100644 --- a/tools/dtoc/fdt.py +++ b/tools/dtoc/fdt.py @@ -49,6 +49,9 @@ class Prop: return self.type, self.value = self.BytesToValue(bytes) + def RefreshOffset(self, poffset): + self._offset = poffset + def GetPhandle(self): """Get a (single) phandle value from a property @@ -161,6 +164,7 @@ class Prop: Returns: The offset of the property (struct fdt_property) within the file """ + self._node._fdt.CheckCache() return self._node._fdt.GetStructOffset(self._offset) class Node: @@ -240,8 +244,22 @@ class Node: self._offset = my_offset offset = fdt_obj.first_subnode(self._offset, QUIET_NOTFOUND) for subnode in self.subnodes: + if subnode.name != fdt_obj.get_name(offset): + raise ValueError('Node name mismatch %s != %s' % + (subnode.name != fdt_obj.get_name(offset))) subnode.Refresh(offset) offset = fdt_obj.next_subnode(offset, QUIET_NOTFOUND) + if offset != -libfdt.FDT_ERR_NOTFOUND: + raise ValueError('Internal error, offset == %d' % offset) + + poffset = fdt_obj.first_property_offset(self._offset, QUIET_NOTFOUND) + while poffset >= 0: + p = fdt_obj.get_property_by_offset(poffset) + prop = self.props[p.name] + prop.RefreshOffset(poffset) + poffset = fdt_obj.next_property_offset(poffset, QUIET_NOTFOUND) + if poffset != -libfdt.FDT_ERR_NOTFOUND: + raise ValueError('Internal error, poffset == %d' % poffset) def DeleteProp(self, prop_name): """Delete a property of a node @@ -285,6 +303,7 @@ class Fdt: TODO(sjg@chromium.org): Implement the 'root' parameter """ + self._cached_offsets = True self._root = self.Node(self, None, 0, '/', '/') self._root.Scan() diff --git a/tools/dtoc/test_fdt.py b/tools/dtoc/test_fdt.py index ba95a4b77de..cd86144896f 100755 --- a/tools/dtoc/test_fdt.py +++ b/tools/dtoc/test_fdt.py @@ -23,6 +23,30 @@ import libfdt import test_util import tools +def _GetPropertyValue(dtb, node, prop_name): + """Low-level function to get the property value based on its offset + + This looks directly in the device tree at the property's offset to find + its value. It is useful as a check that the property is in the correct + place. + + Args: + node: Node to look in + prop_name: Property name to find + + Returns: + Tuple: + Prop object found + Value of property as a string (found using property offset) + """ + prop = node.props[prop_name] + + # Add 12, which is sizeof(struct fdt_property), to get to start of data + offset = prop.GetOffset() + 12 + data = dtb.GetContents()[offset:offset + len(prop.value)] + return prop, [chr(x) for x in data] + + class TestFdt(unittest.TestCase): """Tests for the Fdt module @@ -122,6 +146,12 @@ class TestNode(unittest.TestCase): with self.assertRaises(libfdt.FdtException): self.node.DeleteProp('missing') + def testDeleteGetOffset(self): + """Test that property offset update when properties are deleted""" + self.node.DeleteProp('intval') + prop, value = _GetPropertyValue(self.dtb, self.node, 'longbytearray') + self.assertEqual(prop.value, value) + def testFindNode(self): """Tests that we can find a node using the _FindNode() functoin""" node = self.dtb.GetRoot()._FindNode('i2c@0') @@ -203,13 +233,8 @@ class TestProp(unittest.TestCase): def testGetOffset(self): """Test we can get the offset of a property""" - prop = self.node.props['longbytearray'] - - # Add 12, which is sizeof(struct fdt_property), to get to start of data - offset = prop.GetOffset() + 12 - data = self.dtb.GetContents()[offset:offset + len(prop.value)] - bytes = [chr(x) for x in data] - self.assertEqual(bytes, prop.value) + prop, value = _GetPropertyValue(self.dtb, self.node, 'longbytearray') + self.assertEqual(prop.value, value) def testWiden(self): """Test widening of values""" From patchwork Wed Jun 6 00:46:53 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 925683 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" (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.b="lrKXkmJ+"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 410r053w4kz9s08 for ; Wed, 6 Jun 2018 10:58:45 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 34DC2C21FCA; Wed, 6 Jun 2018 00:51:34 +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_DNSWL_BLOCKED, RCVD_IN_MSPIKE_H2, 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 31AD1C21FCF; Wed, 6 Jun 2018 00:48:41 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 155C9C21F3A; Wed, 6 Jun 2018 00:48:10 +0000 (UTC) Received: from mail-io0-f196.google.com (mail-io0-f196.google.com [209.85.223.196]) by lists.denx.de (Postfix) with ESMTPS id B39DFC21F99 for ; Wed, 6 Jun 2018 00:48:06 +0000 (UTC) Received: by mail-io0-f196.google.com with SMTP id s26-v6so5650245ioj.4 for ; Tue, 05 Jun 2018 17:48:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=CsSGLed/ibfsyPX8A6nmJyJPehwHr6fuNr7MMw5FSSY=; b=lrKXkmJ+TPI9eH378H/C5UaUWJFCsqLvlc+Q4OKFikyHCHcnU4zNYtV3uFHGnw+I9U l7ytpco79CwobDjzg6DGSjimthViOMkThm7axKAUJfI10jH4egGKiGNQvFZP+aQCna1L iw0kKDa//XmLdDWp/Arxrrr3t6DzVV2icNCA5m2cvxJTxzArwOodV/hSxfG5LPRDZj30 pDS98xo6H9G7s9pqu+SNuxqJiIBNgkhhwC6g29u5PBRaLZfG4l4kyt5kZvChXKajb6s2 qTCCEiFSGsszWQrAnbNoKf7Yzp6nw66EKb5lM56Vf1bMTC2ZdJ5ZwES6nNbDei55pbT2 iQGA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=CsSGLed/ibfsyPX8A6nmJyJPehwHr6fuNr7MMw5FSSY=; b=hM7fSBHTGZ83JgkDAgdwtDZbsKn4U+XJUMNHENqYrr/sb/tpxZpxj6hFKbnK8Pe31E VCNvX/jEAoCa0n3cOou2m8rGpRh4gE5kPL+PEfPBhcnn3d6/l2mYQyE/Z8QhCetSTL0d VgaT8gtO2HkhU3DgxXSYg3TIFZOqFvOLLgkdQEwEwnNTCqI4RYjpC0YzwFAjR56gOcPK 0+MqORidGFWsqbWKozqHHfkeCCB/q08qIic1xU/Obj7DVlNDwFOaxeLBYY1HGyWxQRoF JR8sy0vyuGJ5FB19QZ5Wu/xW7ZQNwV7E0uEzJ/7EHi8gcnL6Ta2OjkyQZOznZMVSBLRy JR5A== X-Gm-Message-State: APt69E2nzi9+o3/Aa6eFWE8+S49/MmxillL3cXvPS05UF2MVyNi1WhTy 9Yync9qjiL7nPHJSMJBJX6wvqQ== X-Google-Smtp-Source: ADUXVKK5MYWMCzpx4TLEfIJGIHwy/NU9NbsEUB/8jMnhXGmtZOHB/StdconAuQF3iDPgBfjvs9sdbA== X-Received: by 2002:a6b:c38b:: with SMTP id t133-v6mr835528iof.197.1528246085175; Tue, 05 Jun 2018 17:48:05 -0700 (PDT) Received: from kiwi.bld.corp.google.com ([2620:15c:183:0:8223:87c:a681:66aa]) by smtp.gmail.com with ESMTPSA id z11-v6sm4427225ioc.8.2018.06.05.17.48.03 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 05 Jun 2018 17:48:04 -0700 (PDT) Received: by kiwi.bld.corp.google.com (Postfix, from userid 121222) id C1B961409F9; Tue, 5 Jun 2018 18:48:02 -0600 (MDT) From: Simon Glass To: U-Boot Mailing List Date: Tue, 5 Jun 2018 18:46:53 -0600 Message-Id: <20180606004705.79641-18-sjg@chromium.org> X-Mailer: git-send-email 2.17.1.1185.g55be947832-goog In-Reply-To: <20180606004705.79641-1-sjg@chromium.org> References: <20180606004705.79641-1-sjg@chromium.org> Cc: Tom Rini Subject: [U-Boot] [PATCH 17/29] dtoc: Fix Fdt.GetNode() to handle a missing node 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" At present the algortihm is not correct since it will return the root node if the requested node is not found and there are no slashes in the requested node name. Fix this and add a test. Signed-off-by: Simon Glass --- tools/dtoc/fdt.py | 5 ++++- tools/dtoc/test_fdt.py | 4 ++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/tools/dtoc/fdt.py b/tools/dtoc/fdt.py index 2d7b6328f11..fc8aeb81de5 100644 --- a/tools/dtoc/fdt.py +++ b/tools/dtoc/fdt.py @@ -324,7 +324,10 @@ class Fdt: Node object, or None if not found """ node = self._root - for part in path.split('/')[1:]: + parts = path.split('/') + if len(parts) < 2: + return None + for part in parts[1:]: node = node._FindNode(part) if not node: return None diff --git a/tools/dtoc/test_fdt.py b/tools/dtoc/test_fdt.py index cd86144896f..78afb33b056 100755 --- a/tools/dtoc/test_fdt.py +++ b/tools/dtoc/test_fdt.py @@ -77,6 +77,7 @@ class TestFdt(unittest.TestCase): node = self.dtb.GetNode('/i2c@0/pmic@9') self.assertTrue(isinstance(node, fdt.Node)) self.assertEqual('pmic@9', node.name) + self.assertEqual(None, self.dtb.GetNode('/i2c@0/pmic@9/missing')) def testFlush(self): """Check that we can flush the device tree out to its file""" @@ -177,6 +178,9 @@ class TestProp(unittest.TestCase): self.node = self.dtb.GetNode('/spl-test') self.fdt = self.dtb.GetFdtObj() + def testMissingNode(self): + self.assertEqual(None, self.dtb.GetNode('missing')) + def testPhandle(self): dtb = fdt.FdtScan('tools/dtoc/dtoc_test_phandle.dts') node = dtb.GetNode('/phandle-source') From patchwork Wed Jun 6 00:46:54 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 925682 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" (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.b="iw5npCqp"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 410qzh1Gl2z9s08 for ; Wed, 6 Jun 2018 10:58:24 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id DCD2CC21EC5; Wed, 6 Jun 2018 00:52:10 +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_DNSWL_BLOCKED, RCVD_IN_MSPIKE_H2, 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 8F1DEC21FDB; Wed, 6 Jun 2018 00:48:49 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id A28A7C21F2A; Wed, 6 Jun 2018 00:48:11 +0000 (UTC) Received: from mail-io0-f172.google.com (mail-io0-f172.google.com [209.85.223.172]) by lists.denx.de (Postfix) with ESMTPS id 895A5C21FB3 for ; Wed, 6 Jun 2018 00:48:07 +0000 (UTC) Received: by mail-io0-f172.google.com with SMTP id s26-v6so5650273ioj.4 for ; Tue, 05 Jun 2018 17:48:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=Fn2rok+3UmwrwHuKc/y0uoM/cSI4m2PJlY6+lEj4m74=; b=iw5npCqpr7Ixi3tY9DT9SG5FhwoC+PbI+Op2jtwiiYi2m8Itw53NRU33//CurB2Bdv XmFcyA4n3pXVS0Bc1z/iLqjMIHu+A/iEfloxEEEdLfIi0SOVY+uQKj2uESpERUIAlpqZ w3S2LLMBsScW9eCRFmIhXW56T8y8WKtON7XfjZoPjm0VtH7KhJ09uG+krtm5zKer0fkR sbUZvneqOAr+ONPWVpx1y8YGiiGMJZ4r7ef/45pZL4GASAQ2Bq+ENrxokebXLAU3ghG3 sY/UcrwR6792sNfX9YNEh6OnWUdz1ZX2Km/lahdU2wnEK4Y8kzufr5F/TibU4R/aCTY9 vnnQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=Fn2rok+3UmwrwHuKc/y0uoM/cSI4m2PJlY6+lEj4m74=; b=kXcz1L3TZ8QxHplgH/Jwt/4AX8w/nsNoiUARXgoXN5lm56CZkxxlTOKYbrtYxI1d5K 2y9Nryft+ZXhg7ZV+eBOYEi5pW2x9Dc/6dW1mDbQi8KhTZ/d3l+CwJIwsUaB27tbIpMa l30Y1LsbA0NLuMBHcx6uaYmhN8c/XANiLmPWqWf+zfhBTMFRCDvrN2XP15IN92XPRebS 6BQNH6ZwlaimTElSdkvqUAoZkiKJTZ5UchWAnn8MWsx0Ugqz9rk4NFE0WYzGuNou967l SkppSTZN7IRcbcXE3v38EIDvfb2LHUrUkziCpO+JTbw9gDSWOkt5L5XSSGR5McX2/yyB mPyQ== X-Gm-Message-State: APt69E2Z9wMPLK585R4103isv9p5SFRUlQ4kFy1Xo2PDR+n33Z1Q+t9U LFBS8RiXmlxnR/t5tOO9yY2upg== X-Google-Smtp-Source: ADUXVKIwcFXcPuAChAXj1GgxXLe48U9rh5a3qzReyIkF3jdiAYbKGa/V+ZdfWXCbpKxpAyzsAyPuzQ== X-Received: by 2002:a6b:407:: with SMTP id 7-v6mr887957ioe.140.1528246085947; Tue, 05 Jun 2018 17:48:05 -0700 (PDT) Received: from kiwi.bld.corp.google.com ([100.67.80.24]) by smtp.gmail.com with ESMTPSA id 81-v6sm6351045iou.73.2018.06.05.17.48.04 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 05 Jun 2018 17:48:05 -0700 (PDT) Received: by kiwi.bld.corp.google.com (Postfix, from userid 121222) id 2A1D3140700; Tue, 5 Jun 2018 18:48:04 -0600 (MDT) From: Simon Glass To: U-Boot Mailing List Date: Tue, 5 Jun 2018 18:46:54 -0600 Message-Id: <20180606004705.79641-19-sjg@chromium.org> X-Mailer: git-send-email 2.17.1.1185.g55be947832-goog In-Reply-To: <20180606004705.79641-1-sjg@chromium.org> References: <20180606004705.79641-1-sjg@chromium.org> Cc: Tom Rini Subject: [U-Boot] [PATCH 18/29] dtoc: Update fdt tests to increase code coverage 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" At present only some of the fdt functionality is tests. Add more tests to bring code coverage up further. Signed-off-by: Simon Glass --- tools/dtoc/dtoc_test_simple.dts | 1 + tools/dtoc/fdt.py | 16 ++++++--------- tools/dtoc/test_dtoc.py | 3 +++ tools/dtoc/test_fdt.py | 35 +++++++++++++++++++++++++++++++-- 4 files changed, 43 insertions(+), 12 deletions(-) diff --git a/tools/dtoc/dtoc_test_simple.dts b/tools/dtoc/dtoc_test_simple.dts index 895cc1fea28..a6e2ba8bef7 100644 --- a/tools/dtoc/dtoc_test_simple.dts +++ b/tools/dtoc/dtoc_test_simple.dts @@ -21,6 +21,7 @@ longbytearray = [09 0a 0b 0c 0d 0e 0f 10 11]; stringval = "message"; stringarray = "multi-word", "message"; + stringbad = "message", [01], "junk"; }; spl-test2 { diff --git a/tools/dtoc/fdt.py b/tools/dtoc/fdt.py index fc8aeb81de5..3595c63a07f 100644 --- a/tools/dtoc/fdt.py +++ b/tools/dtoc/fdt.py @@ -245,8 +245,8 @@ class Node: offset = fdt_obj.first_subnode(self._offset, QUIET_NOTFOUND) for subnode in self.subnodes: if subnode.name != fdt_obj.get_name(offset): - raise ValueError('Node name mismatch %s != %s' % - (subnode.name != fdt_obj.get_name(offset))) + raise ValueError('Internal error, node name mismatch %s != %s' % + (subnode.name, fdt_obj.get_name(offset))) subnode.Refresh(offset) offset = fdt_obj.next_subnode(offset, QUIET_NOTFOUND) if offset != -libfdt.FDT_ERR_NOTFOUND: @@ -255,11 +255,12 @@ class Node: poffset = fdt_obj.first_property_offset(self._offset, QUIET_NOTFOUND) while poffset >= 0: p = fdt_obj.get_property_by_offset(poffset) - prop = self.props[p.name] + prop = self.props.get(p.name) + if not prop: + raise ValueError("Internal error, property '%s' missing, " + 'offset %d' % (p.name, poffset)) prop.RefreshOffset(poffset) poffset = fdt_obj.next_property_offset(poffset, QUIET_NOTFOUND) - if poffset != -libfdt.FDT_ERR_NOTFOUND: - raise ValueError('Internal error, poffset == %d' % poffset) def DeleteProp(self, prop_name): """Delete a property of a node @@ -366,11 +367,6 @@ class Fdt: """ return self._fdt_obj - def CheckErr(self, errnum, msg): - if errnum: - raise ValueError('Error %d: %s: %s' % - (errnum, libfdt.fdt_strerror(errnum), msg)) - def GetProps(self, node): """Get all properties from a node. diff --git a/tools/dtoc/test_dtoc.py b/tools/dtoc/test_dtoc.py index ce6d2585a40..95818928b32 100644 --- a/tools/dtoc/test_dtoc.py +++ b/tools/dtoc/test_dtoc.py @@ -181,6 +181,7 @@ struct dtd_sandbox_spl_test { \tfdt32_t\t\tintval; \tunsigned char\tlongbytearray[9]; \tconst char *\tstringarray[3]; +\tunsigned char\tstringbad[14]; \tconst char *\tstringval; }; struct dtd_sandbox_spl_test_2 { @@ -195,6 +196,8 @@ static struct dtd_sandbox_spl_test dtv_spl_test = { \t.bytearray\t\t= {0x6, 0x0, 0x0}, \t.byteval\t\t= 0x5, \t.intval\t\t\t= 0x1, +\t.stringbad\t\t= {0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x0, +\t\t0x1, 0x6a, 0x75, 0x6e, 0x6b, 0x0}, \t.longbytearray\t\t= {0x9, 0xa, 0xb, 0xc, 0xd, 0xe, 0xf, 0x10, \t\t0x11}, \t.stringval\t\t= "message", diff --git a/tools/dtoc/test_fdt.py b/tools/dtoc/test_fdt.py index 78afb33b056..d6ea1951001 100755 --- a/tools/dtoc/test_fdt.py +++ b/tools/dtoc/test_fdt.py @@ -105,13 +105,13 @@ class TestFdt(unittest.TestCase): props = self.dtb.GetProps(node) self.assertEqual(['boolval', 'bytearray', 'byteval', 'compatible', 'intarray', 'intval', 'longbytearray', - 'stringarray', 'stringval', 'u-boot,dm-pre-reloc'], + 'stringarray', 'stringbad', 'stringval', 'u-boot,dm-pre-reloc'], sorted(props.keys())) def testCheckError(self): """Tests the ChecKError() function""" with self.assertRaises(ValueError) as e: - self.dtb.CheckErr(-libfdt.NOTFOUND, 'hello') + fdt.CheckErr(-libfdt.NOTFOUND, 'hello') self.assertIn('FDT_ERR_NOTFOUND: hello', str(e.exception)) @@ -161,6 +161,32 @@ class TestNode(unittest.TestCase): self.assertEqual('pmic@9', subnode.name) self.assertEqual(None, node._FindNode('missing')) + def testRefreshMissingNode(self): + """Test refreshing offsets when an extra node is present in dtb""" + # Delete it from our tables, not the device tree + del self.dtb._root.subnodes[-1] + with self.assertRaises(ValueError) as e: + self.dtb.Refresh() + self.assertIn('Internal error, offset', str(e.exception)) + + def testRefreshExtraNode(self): + """Test refreshing offsets when an expected node is missing""" + # Delete it from the device tre, not our tables + self.dtb.GetFdtObj().del_node(self.node.Offset()) + with self.assertRaises(ValueError) as e: + self.dtb.Refresh() + self.assertIn('Internal error, node name mismatch ' + 'spl-test != spl-test2', str(e.exception)) + + def testRefreshMissingProp(self): + """Test refreshing offsets when an extra property is present in dtb""" + # Delete it from our tables, not the device tree + del self.node.props['stringbad'] + with self.assertRaises(ValueError) as e: + self.dtb.Refresh() + self.assertIn("Internal error, property 'stringbad' missing, offset ", + str(e.exception)) + class TestProp(unittest.TestCase): """Test operation of the Prop class""" @@ -228,6 +254,11 @@ class TestProp(unittest.TestCase): self.assertEqual(fdt.TYPE_STRING, prop.type) self.assertEqual(['multi-word', 'message'], prop.value) + prop = self._ConvertProp('stringbad') + self.assertEqual(fdt.TYPE_BYTE, prop.type) + val = [ch for ch in 'message\x00\x01junk\0'] + self.assertEqual(val, prop.value) + def testGetEmpty(self): """Tests the GetEmpty() function for the various supported types""" self.assertEqual(True, fdt.Prop.GetEmpty(fdt.TYPE_BOOL)) From patchwork Wed Jun 6 00:46:55 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 925694 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" (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.b="boLZcHW9"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 410r512xZyz9s08 for ; Wed, 6 Jun 2018 11:03:01 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 1DD02C21FC7; Wed, 6 Jun 2018 00:54: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_DNSWL_BLOCKED, 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 2C5F9C21FB8; Wed, 6 Jun 2018 00:49:52 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 7F83FC21FB8; Wed, 6 Jun 2018 00:48:15 +0000 (UTC) Received: from mail-io0-f182.google.com (mail-io0-f182.google.com [209.85.223.182]) by lists.denx.de (Postfix) with ESMTPS id CECE6C21F52 for ; Wed, 6 Jun 2018 00:48:10 +0000 (UTC) Received: by mail-io0-f182.google.com with SMTP id e15-v6so5665305iog.1 for ; Tue, 05 Jun 2018 17:48:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=SXWTHbdcBhNPD5GOM7MYCR6ioU5B34xbUrrw4YGx/bU=; b=boLZcHW9AxfOSqaeM6kVOS1MAa7ksuwGrsbbcumIypyhQJmtkEZujyr2o1KtCABNfk oyeoeKxD7zuJclmacfqOKyvnwVxId02TF1UD8PcdS3BplRCrOnSwnAg/I2m651qSPR+M Ofbz5TuxViBSNMt8cC/WMpn+E+by5f71cxlZkSgVA3TyM0h6V2dvylMdHHNZFwhc8PdG go+HBEEdqQjw0VWYFjrG3SYv2wYNjo3vJqFqxT1onVIksoUiU1jOcZeUVUz9Z2SafibM qXKtJu37wghygD8FOpYnwIeyh8c1w4XE1JzuuCbg0ENhZzDAKP3kHpKv9M85qeWL+Xhz S4Eg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=SXWTHbdcBhNPD5GOM7MYCR6ioU5B34xbUrrw4YGx/bU=; b=RdicddQQYUX2xxJ52ETpeksiyHRWN7akRKNePdEdRs4uWqVZBm/PSDcCMWlz0gpaWw 1kwyz8befRKmYeBXpRNmIjyxkZBOYQ27vKiBRIkd87uYMenN9IXz3rBUVS4FNkuJOiq9 dRiRfOkTnF16KNRI0yS1Tt8I8CfxzjO4jEWaOwbXyKsPzQxymvf+t+Q+UhE5v+8foIJ1 xEjdkUM9ZaJr+sXkgl7vPGE9+TfOYpzWpTC/h1+q+w//ZV6mwP5I6ec4M16n8VABkaeV GlX4EbBe9ZuamPTlEufJWafa0wjBpKFuP3MrRW6sdaXgbitX0o6uINUcZggQ4jcog3q0 Jqtg== X-Gm-Message-State: APt69E3mvDB3m1cR0zqFZT8NLDZ6MgVhm5CJPq09+ITwINpSjkmp57pL R8uRfL2gqqqpkV5v6SgejxUAxg== X-Google-Smtp-Source: ADUXVKJHCjAWpooh9alPvcbNfeLJOrwZ51e6U6fTkF7oJJB32RCxay6RzT1eTNC3n8GTi2UHW/1D8Q== X-Received: by 2002:a6b:3b49:: with SMTP id i70-v6mr850697ioa.133.1528246089219; Tue, 05 Jun 2018 17:48:09 -0700 (PDT) Received: from kiwi.bld.corp.google.com ([100.67.80.24]) by smtp.gmail.com with ESMTPSA id s74-v6sm1496726ita.43.2018.06.05.17.48.08 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 05 Jun 2018 17:48:08 -0700 (PDT) Received: by kiwi.bld.corp.google.com (Postfix, from userid 121222) id ECF76140700; Tue, 5 Jun 2018 18:48:07 -0600 (MDT) From: Simon Glass To: U-Boot Mailing List Date: Tue, 5 Jun 2018 18:46:55 -0600 Message-Id: <20180606004705.79641-20-sjg@chromium.org> X-Mailer: git-send-email 2.17.1.1185.g55be947832-goog In-Reply-To: <20180606004705.79641-1-sjg@chromium.org> References: <20180606004705.79641-1-sjg@chromium.org> Cc: Tom Rini Subject: [U-Boot] [PATCH 19/29] dtoc: Fix properties with a single zero-arg phandle 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" At present a property with a single phandle looks like an integer value to dtoc. Correct this by adjusting it in the phandle-processing code. Add a test for this, so that code coverage increases to 100%. Signed-off-by: Simon Glass --- tools/dtoc/dtb_platdata.py | 12 ++++++++---- tools/dtoc/dtoc_test_phandle.dts | 6 ++++++ tools/dtoc/test_dtoc.py | 10 ++++++++++ tools/dtoc/test_fdt.py | 4 +++- 4 files changed, 27 insertions(+), 5 deletions(-) diff --git a/tools/dtoc/dtb_platdata.py b/tools/dtoc/dtb_platdata.py index 2f7302e5295..b1323aef198 100644 --- a/tools/dtoc/dtb_platdata.py +++ b/tools/dtoc/dtb_platdata.py @@ -211,15 +211,21 @@ class DtbPlatdata(object): Number of argument cells is this is a phandle, else None """ if prop.name in ['clocks']: + if not isinstance(prop.value, list): + prop.value = [prop.value] val = prop.value - if not isinstance(val, list): - val = [val] i = 0 max_args = 0 args = [] while i < len(val): phandle = fdt_util.fdt32_to_cpu(val[i]) + # If we get to the end of the list, stop. This can happen + # since some nodes have more phandles in the list than others, + # but we allocate enough space for the largest list. So those + # nodes with shorter lists end up with zeroes at the end. + if not phandle: + break target = self._fdt.phandle_to_node.get(phandle) if not target: raise ValueError("Cannot parse '%s' in node '%s'" % @@ -400,8 +406,6 @@ class DtbPlatdata(object): continue info = self.get_phandle_argc(prop, node.name) if info: - if not isinstance(prop.value, list): - prop.value = [prop.value] # Process the list as pairs of (phandle, id) pos = 0 for args in info.args: diff --git a/tools/dtoc/dtoc_test_phandle.dts b/tools/dtoc/dtoc_test_phandle.dts index 91dfec5c63f..a71acffc698 100644 --- a/tools/dtoc/dtoc_test_phandle.dts +++ b/tools/dtoc/dtoc_test_phandle.dts @@ -33,4 +33,10 @@ compatible = "source"; clocks = <&phandle &phandle_1 11 &phandle_2 12 13 &phandle>; }; + + phandle-source2 { + u-boot,dm-pre-reloc; + compatible = "source"; + clocks = <&phandle>; + }; }; diff --git a/tools/dtoc/test_dtoc.py b/tools/dtoc/test_dtoc.py index 95818928b32..41a4c53bb9d 100644 --- a/tools/dtoc/test_dtoc.py +++ b/tools/dtoc/test_dtoc.py @@ -324,6 +324,16 @@ U_BOOT_DEVICE(phandle_source) = { \t.platdata_size\t= sizeof(dtv_phandle_source), }; +static struct dtd_source dtv_phandle_source2 = { +\t.clocks\t\t\t= { +\t\t\t{&dtv_phandle_target, {}},}, +}; +U_BOOT_DEVICE(phandle_source2) = { +\t.name\t\t= "source", +\t.platdata\t= &dtv_phandle_source2, +\t.platdata_size\t= sizeof(dtv_phandle_source2), +}; + ''', data) def test_aliases(self): diff --git a/tools/dtoc/test_fdt.py b/tools/dtoc/test_fdt.py index d6ea1951001..97b8cbb794e 100755 --- a/tools/dtoc/test_fdt.py +++ b/tools/dtoc/test_fdt.py @@ -209,7 +209,9 @@ class TestProp(unittest.TestCase): def testPhandle(self): dtb = fdt.FdtScan('tools/dtoc/dtoc_test_phandle.dts') - node = dtb.GetNode('/phandle-source') + node = dtb.GetNode('/phandle-source2') + prop = node.props['clocks'] + self.assertTrue(prop.GetPhandle() > 0) def _ConvertProp(self, prop_name): """Helper function to look up a property in self.node and return it From patchwork Wed Jun 6 00:46:56 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 925679 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" (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.b="D0xmZVT0"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 410qyk17lrz9s08 for ; Wed, 6 Jun 2018 10:57:34 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id D6F21C21F22; Wed, 6 Jun 2018 00:55:44 +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_DNSWL_BLOCKED, 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 7CA82C21FD1; Wed, 6 Jun 2018 00:51:07 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 381EFC21F85; Wed, 6 Jun 2018 00:48:17 +0000 (UTC) Received: from mail-it0-f41.google.com (mail-it0-f41.google.com [209.85.214.41]) by lists.denx.de (Postfix) with ESMTPS id CA232C21F88 for ; Wed, 6 Jun 2018 00:48:12 +0000 (UTC) Received: by mail-it0-f41.google.com with SMTP id v83-v6so5840540itc.3 for ; Tue, 05 Jun 2018 17:48:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=NZO5UEkWmv9bxA80baNKeS1TIvdnjr5w+6Wvfu7ZRnM=; b=D0xmZVT0+UCg2ujzQXTAjpmQNcjO/KTdDRNsuTIcY88UdQ0nSp0Z/RxPfTGOqsXMo4 ZlRnQ7Mycw00+bD4ip2661lsmS8vJvYl3OR8E+DG6qoN/6ifivA4ov/4V7+G7Z2HmdbT uE9MQd/P3FnQxWPMY8MTH7MLY/8cjXnHgaMF4MeKB96tFIMnMGv33zGdLW5y96SaQg90 sbsbx4tyOknymC4of2rPU0pkmpFKGjWjTwGR8GuEszLXnRLEDtWdBAOjMtbEOQuyE/QI QNAaDleML35sUTXOHiDRlA8s093cXCvi6bDDEj3kqAXaNorg+/sAZlXVjLUYNREUu79A c3Ug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=NZO5UEkWmv9bxA80baNKeS1TIvdnjr5w+6Wvfu7ZRnM=; b=dBN5BZUpvw0Vv+rjur3TFFaHloNsNqDvaB/KAv0WNTLgEDXnib+ORhh5K53i5iaDAF EzWZOEVGCUH31Dshkfzg96LPU4yw73Rb4+g6GDuDb4RaORL42zFoJiwpW8db3suhPc5k nvYpllKwu2NUeFocOqY3XS6d17vFlEaE5Zm3VNv6WrBIhTSXLjQFYNNvpfL15RACtRVt QtjISJqjZATkyBfo0ahX38V9VPMv63Cc3qKBMVL1KcnK/d80YLMooAW806gbou2fqWwx nYVGwOeDlYXygDKKtzgW9xo0Ukn84yuujOqnOKdtgL9WIY2BA73h3B1CddwOKVqIx/ir uW9A== X-Gm-Message-State: APt69E2ecox3dLsjEse95icFRGWyTEfcQYxtP0jx/WKBuKWdorQ8lWt+ 0stdOoV1ViVMRLKDmzLW4X0ZJU0Lq1E= X-Google-Smtp-Source: ADUXVKJLzpZsmt8Xbf0So+tbBYSjg6w+LRnNRnEZD2tCFNETwf3ouWUIdkQ6UKqyvRKN87qL7tj0Mw== X-Received: by 2002:a24:ec44:: with SMTP id g65-v6mr539283ith.18.1528246091254; Tue, 05 Jun 2018 17:48:11 -0700 (PDT) Received: from kiwi.bld.corp.google.com ([100.67.80.24]) by smtp.gmail.com with ESMTPSA id k130-v6sm1315064itb.0.2018.06.05.17.48.10 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 05 Jun 2018 17:48:10 -0700 (PDT) Received: by kiwi.bld.corp.google.com (Postfix, from userid 121222) id B1B6D140700; Tue, 5 Jun 2018 18:48:09 -0600 (MDT) From: Simon Glass To: U-Boot Mailing List Date: Tue, 5 Jun 2018 18:46:56 -0600 Message-Id: <20180606004705.79641-21-sjg@chromium.org> X-Mailer: git-send-email 2.17.1.1185.g55be947832-goog In-Reply-To: <20180606004705.79641-1-sjg@chromium.org> References: <20180606004705.79641-1-sjg@chromium.org> Cc: Tom Rini Subject: [U-Boot] [PATCH 20/29] dtoc: Fix some minor errors 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" Fix some comments and a printf string which is incorrect. Signed-off-by: Simon Glass --- tools/dtoc/dtb_platdata.py | 3 ++- tools/dtoc/dtoc.py | 4 ++-- tools/dtoc/fdt.py | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/tools/dtoc/dtb_platdata.py b/tools/dtoc/dtb_platdata.py index b1323aef198..6cb12594466 100644 --- a/tools/dtoc/dtb_platdata.py +++ b/tools/dtoc/dtb_platdata.py @@ -316,7 +316,8 @@ class DtbPlatdata(object): total = na + ns if reg.type != fdt.TYPE_INT: - raise ValueError("Node '%s' reg property is not an int") + raise ValueError("Node '%s' reg property is not an int" % + node.name) if len(reg.value) % total: raise ValueError("Node '%s' reg property has %d cells " 'which is not a multiple of na + ns = %d + %d)' % diff --git a/tools/dtoc/dtoc.py b/tools/dtoc/dtoc.py index c891b063800..2e6a4db8bc1 100755 --- a/tools/dtoc/dtoc.py +++ b/tools/dtoc/dtoc.py @@ -40,8 +40,8 @@ def run_tests(args): """Run all the test we have for dtoc Args: - args: List of positional args provided to binman. This can hold a test - name to execute (as in 'binman -t testSections', for example) + args: List of positional args provided to dtoc. This can hold a test + name to execute (as in 'dtoc -t test_empty_file', for example) """ import test_dtoc diff --git a/tools/dtoc/fdt.py b/tools/dtoc/fdt.py index 3595c63a07f..f11fb75b1a4 100644 --- a/tools/dtoc/fdt.py +++ b/tools/dtoc/fdt.py @@ -435,7 +435,7 @@ class Fdt: return node def FdtScan(fname): - """Returns a new Fdt object from the implementation we are using""" + """Returns a new Fdt object""" dtb = Fdt(fname) dtb.Scan() return dtb From patchwork Wed Jun 6 00:46:57 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 925696 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" (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.b="ZXV3a6Af"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 410r5q1Vq7z9s02 for ; Wed, 6 Jun 2018 11:03:43 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id DDE89C21E90; Wed, 6 Jun 2018 00:57:19 +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_DNSWL_BLOCKED, 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 6901FC21F60; Wed, 6 Jun 2018 00:52:42 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 0E22DC21F78; Wed, 6 Jun 2018 00:48:19 +0000 (UTC) Received: from mail-it0-f67.google.com (mail-it0-f67.google.com [209.85.214.67]) by lists.denx.de (Postfix) with ESMTPS id 71CCAC21EC5 for ; Wed, 6 Jun 2018 00:48:15 +0000 (UTC) Received: by mail-it0-f67.google.com with SMTP id 76-v6so5904901itx.4 for ; Tue, 05 Jun 2018 17:48:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=wt4QTsAumnFfri+WJtGuaJy+rfzrtxQrxoxPS9Nixxg=; b=ZXV3a6AfQX7V6b9ToktzVyE9XY8r9VQ97GGdq4Y/irx3TP6Ac+nRusPJ+UV5lrKSOB clIwGSDnj88pID4yFpu9CH3CxuUjVeMii/hEcn6cy0pD2naHPsqGcBM6MbO9M4UvXPpi 1HG2KtRc8VxNX0QAErGIhM9s9yg+/TBEsxr3B1jzFEdJQ66RLReAXUV2axTThCqBSO4B IFoXGzV/Uk4/SsxX87lBOGLbQoRKWiN490K85j04phQoJaCJp5UiSymcTl8/h5bWQ+Vl x+j2OWTtV2ikxFTJzf3WTY98Xk9+7k0/MiAsEavDU1HPB1WfumfpWotxHgvPIzkYY/ii Thwg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=wt4QTsAumnFfri+WJtGuaJy+rfzrtxQrxoxPS9Nixxg=; b=NVg80pHyhbasRe5jCI2t1sCh5z5xrK61Qw3I8A0NzIYjwN5KZVOYAUjFBDGH4cuik7 qZ/tdCHOrd+N2xFsps0efTM/XeeS7hwpoo967ylEKOx5hiDzGkIAFpTz9duBkcM54JNG fP5Zndo79iq+cmnTzrUDsHEwN8Qu5HjYCTJhwE+00Qv4SeMf0f9JnWbfA/wpSL4Rri/J plrsY7xtzQFdAGA1+b8CbJM81utSBVV/vgmaQJn3sY1dug2R2njnb/ZHgBMaU8S9K9AE HL9uV+mbZ1ID8dnxCpqkjRmie1ncLA6325Fan1Brf/478BS1u5kRXu9zOGHxwz2CFbQm iaaA== X-Gm-Message-State: APt69E0pIKE/ED/En97XwKjfS9ntRW4GPOvXezPGMQJlFp9LlZYJYWL9 UNdffK8aupMRhbg9iqy4OiS4Zg== X-Google-Smtp-Source: ADUXVKJd1/a51K5ZdHSjsETM78/QVWsl80Cvm2OAsyJRNaZYw5P1WbedjzfNVg3ndRdrPSnfP7qIXQ== X-Received: by 2002:a24:5f84:: with SMTP id r126-v6mr470888itb.22.1528246093840; Tue, 05 Jun 2018 17:48:13 -0700 (PDT) Received: from kiwi.bld.corp.google.com ([2620:15c:183:0:8223:87c:a681:66aa]) by smtp.gmail.com with ESMTPSA id o9-v6sm1268768itf.6.2018.06.05.17.48.11 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 05 Jun 2018 17:48:11 -0700 (PDT) Received: by kiwi.bld.corp.google.com (Postfix, from userid 121222) id 85DBE140700; Tue, 5 Jun 2018 18:48:11 -0600 (MDT) From: Simon Glass To: U-Boot Mailing List Date: Tue, 5 Jun 2018 18:46:57 -0600 Message-Id: <20180606004705.79641-22-sjg@chromium.org> X-Mailer: git-send-email 2.17.1.1185.g55be947832-goog In-Reply-To: <20180606004705.79641-1-sjg@chromium.org> References: <20180606004705.79641-1-sjg@chromium.org> Cc: Tom Rini Subject: [U-Boot] [PATCH 21/29] dtoc: Add a test for code coverage 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" Add a -T option to run a code-coverage test on dtoc. At present this is about 96%. Future work will increase it to 100%. Signed-off-by: Simon Glass --- tools/dtoc/dtoc.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/tools/dtoc/dtoc.py b/tools/dtoc/dtoc.py index 2e6a4db8bc1..1fbc2db6e46 100755 --- a/tools/dtoc/dtoc.py +++ b/tools/dtoc/dtoc.py @@ -35,6 +35,7 @@ our_path = os.path.dirname(os.path.realpath(__file__)) sys.path.append(os.path.join(our_path, '../patman')) import dtb_platdata +import test_util def run_tests(args): """Run all the test we have for dtoc @@ -64,10 +65,19 @@ def run_tests(args): for _, err in result.failures: print err +def RunTestCoverage(): + """Run the tests and check that we get 100% coverage""" + sys.argv = [sys.argv[0]] + test_util.RunTestCoverage('tools/dtoc/dtoc.py', '/dtb_platdata.py', + ['tools/patman/*.py'], options.build_dir) + + if __name__ != '__main__': sys.exit(1) parser = OptionParser() +parser.add_option('-B', '--build-dir', type='string', default='b', + help='Directory containing the build output') parser.add_option('-d', '--dtb-file', action='store', help='Specify the .dtb input file') parser.add_option('--include-disabled', action='store_true', @@ -76,12 +86,17 @@ parser.add_option('-o', '--output', action='store', default='-', help='Select output filename') parser.add_option('-t', '--test', action='store_true', dest='test', default=False, help='run tests') +parser.add_option('-T', '--test-coverage', action='store_true', + default=False, help='run tests and check for 100% coverage') (options, args) = parser.parse_args() # Run our meagre tests if options.test: run_tests(args) +elif options.test_coverage: + RunTestCoverage() + else: dtb_platdata.run_steps(args, options.dtb_file, options.include_disabled, options.output) From patchwork Wed Jun 6 00:46:58 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 925698 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" (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.b="I+ZFqMrL"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 410r7P2407z9s02 for ; Wed, 6 Jun 2018 11:05:05 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id DDE0DC21F52; Wed, 6 Jun 2018 00:55: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_DNSWL_BLOCKED, RCVD_IN_MSPIKE_H2, 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 9AC36C21F9A; Wed, 6 Jun 2018 00:50:42 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 86581C21FD2; Wed, 6 Jun 2018 00:48:20 +0000 (UTC) Received: from mail-io0-f193.google.com (mail-io0-f193.google.com [209.85.223.193]) by lists.denx.de (Postfix) with ESMTPS id 9C83DC21EDE for ; Wed, 6 Jun 2018 00:48:16 +0000 (UTC) Received: by mail-io0-f193.google.com with SMTP id s26-v6so5650599ioj.4 for ; Tue, 05 Jun 2018 17:48:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=8Zmszm5OojaFsMm2tAXZyvo8gUj2HiHCDRUCd/f23RY=; b=I+ZFqMrLcIUW4qMT4mM9xSiBjguWdRMjEPEokxtVmvZj1vQocPAGhrC/ozL0abUN6O isoUHbIVWmW24j/4uBosIvLbsmYPJnH/afIRm0f3JDX1sSt8ZgepzRNpRNaD6RxpG0ET JYBU7Y1SdecAzvg1cYzaad38xwnuBfJEM60oivGFyImrDSgxjger/KwkMQ0nmDd6Itwo 28oLcWtFdDT77MdURQaJ5lefmheXNyvTmYrl1uriCC0Z8gEyJ+FuH7ikTjYYT0JewpCT kld5vrHwE3mI6jHgJO/nKP55u8CPcLesGa8HPFD2LzcVtCfMuMJKg8iG2H70k+qXbFm6 zkgg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=8Zmszm5OojaFsMm2tAXZyvo8gUj2HiHCDRUCd/f23RY=; b=RKgL3ZPqw77YOj2RKpyjdQlmkh4nHOLPxCDPkNTacQtmJ6D7tegIvERFpghZnaUc0m JmhdtvtOuT2YS1GtjZ4tjk+UF4km0vs2Rz/6/6ndFHNOboh4AFsvtrpWo2aY1P4+HVbX Xv0uKSFIRMrGLH/LIvHYfny6hZAwT43h+xNtU3nawIpO+S86nvm1LQNQkl+kCuga/Nxi xpQsdzAFPizrLMGwyzkm80I8WKHRIUqaSpB2axmwP48hoIvdhYU5Xehl4k9NUy0Z62JE 3VaEzK14WgcPY3P/6HTGID7ebDZ+H++IQmIbaCVggheEjCl/3g6o1ZbZqfFgykTTtNW2 keiw== X-Gm-Message-State: APt69E2527atf3NlEL0QPUplT3QnSpIzCqyclHgDsfAHTfdCGICeddrd NBCTHb+wV2IXwZnsMTfF/mPXjA== X-Google-Smtp-Source: ADUXVKIW4X1KsaDwjcOQu5NWu9az8eCUjDfm7OkuEuYBSqzMBAZ4JtpE0DlcwyIpv1cjAn4SPXn3nw== X-Received: by 2002:a6b:1902:: with SMTP id 2-v6mr848533ioz.304.1528246094963; Tue, 05 Jun 2018 17:48:14 -0700 (PDT) Received: from kiwi.bld.corp.google.com ([100.67.80.24]) by smtp.gmail.com with ESMTPSA id 194-v6sm1406187itm.32.2018.06.05.17.48.13 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 05 Jun 2018 17:48:14 -0700 (PDT) Received: by kiwi.bld.corp.google.com (Postfix, from userid 121222) id 6860E1409F9; Tue, 5 Jun 2018 18:48:13 -0600 (MDT) From: Simon Glass To: U-Boot Mailing List Date: Tue, 5 Jun 2018 18:46:58 -0600 Message-Id: <20180606004705.79641-23-sjg@chromium.org> X-Mailer: git-send-email 2.17.1.1185.g55be947832-goog In-Reply-To: <20180606004705.79641-1-sjg@chromium.org> References: <20180606004705.79641-1-sjg@chromium.org> Cc: Tom Rini Subject: [U-Boot] [PATCH 22/29] dtoc: Increase code coverage to 100% 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" Add more tests to increase dtoc code coverage to 100%. Correct a whitespace error in some test .dts files at the same time. Signed-off-by: Simon Glass --- tools/dtoc/dtoc_test_add_prop.dts | 24 ++++ tools/dtoc/dtoc_test_addr32_64.dts | 2 +- tools/dtoc/dtoc_test_addr64_32.dts | 2 +- tools/dtoc/dtoc_test_bad_reg.dts | 17 +++ tools/dtoc/dtoc_test_bad_reg2.dts | 17 +++ tools/dtoc/dtoc_test_phandle_bad.dts | 16 +++ tools/dtoc/dtoc_test_phandle_bad2.dts | 22 ++++ tools/dtoc/dtoc_test_phandle_reorder.dts | 23 ++++ tools/dtoc/dtoc_test_phandle_single.dts | 23 ++++ tools/dtoc/test_dtoc.py | 142 +++++++++++++++++++++++ 10 files changed, 286 insertions(+), 2 deletions(-) create mode 100644 tools/dtoc/dtoc_test_add_prop.dts create mode 100644 tools/dtoc/dtoc_test_bad_reg.dts create mode 100644 tools/dtoc/dtoc_test_bad_reg2.dts create mode 100644 tools/dtoc/dtoc_test_phandle_bad.dts create mode 100644 tools/dtoc/dtoc_test_phandle_bad2.dts create mode 100644 tools/dtoc/dtoc_test_phandle_reorder.dts create mode 100644 tools/dtoc/dtoc_test_phandle_single.dts diff --git a/tools/dtoc/dtoc_test_add_prop.dts b/tools/dtoc/dtoc_test_add_prop.dts new file mode 100644 index 00000000000..fa296e55527 --- /dev/null +++ b/tools/dtoc/dtoc_test_add_prop.dts @@ -0,0 +1,24 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Test device tree file for dtoc + * + * Copyright 2018 Google, Inc + */ + +/dts-v1/; + +/ { + #address-cells = <1>; + #size-cells = <1>; + spl-test { + u-boot,dm-pre-reloc; + compatible = "sandbox,spl-test"; + intval = <1>; + }; + + spl-test2 { + u-boot,dm-pre-reloc; + compatible = "sandbox,spl-test"; + intarray = <5>; + }; +}; diff --git a/tools/dtoc/dtoc_test_addr32_64.dts b/tools/dtoc/dtoc_test_addr32_64.dts index 7891ee59fa2..7599d5b0a59 100644 --- a/tools/dtoc/dtoc_test_addr32_64.dts +++ b/tools/dtoc/dtoc_test_addr32_64.dts @@ -5,7 +5,7 @@ * Copyright 2017 Google, Inc */ - /dts-v1/; +/dts-v1/; / { #address-cells = <1>; diff --git a/tools/dtoc/dtoc_test_addr64_32.dts b/tools/dtoc/dtoc_test_addr64_32.dts index 759a7e8e265..85e4f5fdaeb 100644 --- a/tools/dtoc/dtoc_test_addr64_32.dts +++ b/tools/dtoc/dtoc_test_addr64_32.dts @@ -5,7 +5,7 @@ * Copyright 2017 Google, Inc */ - /dts-v1/; +/dts-v1/; / { #address-cells = <2>; diff --git a/tools/dtoc/dtoc_test_bad_reg.dts b/tools/dtoc/dtoc_test_bad_reg.dts new file mode 100644 index 00000000000..1312acb619b --- /dev/null +++ b/tools/dtoc/dtoc_test_bad_reg.dts @@ -0,0 +1,17 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Test device tree file for dtoc + * + * Copyright 2018 Google, Inc + */ + +/dts-v1/; + +/ { + #address-cells = <1>; + #size-cells = <1>; + spl-test { + compatible = "test"; + reg = "fre"; + }; +}; diff --git a/tools/dtoc/dtoc_test_bad_reg2.dts b/tools/dtoc/dtoc_test_bad_reg2.dts new file mode 100644 index 00000000000..3e9efa43af1 --- /dev/null +++ b/tools/dtoc/dtoc_test_bad_reg2.dts @@ -0,0 +1,17 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Test device tree file for dtoc + * + * Copyright 2018 Google, Inc + */ + +/dts-v1/; + +/ { + #address-cells = <1>; + #size-cells = <1>; + spl-test { + compatible = "test"; + reg = <1 2 3>; + }; +}; diff --git a/tools/dtoc/dtoc_test_phandle_bad.dts b/tools/dtoc/dtoc_test_phandle_bad.dts new file mode 100644 index 00000000000..a3ddc595851 --- /dev/null +++ b/tools/dtoc/dtoc_test_phandle_bad.dts @@ -0,0 +1,16 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Test device tree file for dtoc + * + * Copyright 2018 Google, Inc + */ + +/dts-v1/; + +/ { + phandle-source { + u-boot,dm-pre-reloc; + compatible = "source"; + clocks = <20>; /* Invalid phandle */ + }; +}; diff --git a/tools/dtoc/dtoc_test_phandle_bad2.dts b/tools/dtoc/dtoc_test_phandle_bad2.dts new file mode 100644 index 00000000000..fe25f565fbb --- /dev/null +++ b/tools/dtoc/dtoc_test_phandle_bad2.dts @@ -0,0 +1,22 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Test device tree file for dtoc + * + * Copyright 2018 Google, Inc + */ + +/dts-v1/; + +/ { + phandle: phandle-target { + u-boot,dm-pre-reloc; + compatible = "target"; + intval = <0>; + }; + + phandle-source2 { + u-boot,dm-pre-reloc; + compatible = "source"; + clocks = <&phandle>; + }; +}; diff --git a/tools/dtoc/dtoc_test_phandle_reorder.dts b/tools/dtoc/dtoc_test_phandle_reorder.dts new file mode 100644 index 00000000000..aa71d56f27c --- /dev/null +++ b/tools/dtoc/dtoc_test_phandle_reorder.dts @@ -0,0 +1,23 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Test device tree file for dtoc + * + * Copyright 2018 Google, Inc + */ + +/dts-v1/; + +/ { + + phandle-source2 { + u-boot,dm-pre-reloc; + compatible = "source"; + clocks = <&phandle>; + }; + + phandle: phandle-target { + u-boot,dm-pre-reloc; + compatible = "target"; + #clock-cells = <0>; + }; +}; diff --git a/tools/dtoc/dtoc_test_phandle_single.dts b/tools/dtoc/dtoc_test_phandle_single.dts new file mode 100644 index 00000000000..aacd0b15fa1 --- /dev/null +++ b/tools/dtoc/dtoc_test_phandle_single.dts @@ -0,0 +1,23 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Test device tree file for dtoc + * + * Copyright 2018 Google, Inc + */ + +/dts-v1/; + +/ { + phandle: phandle-target { + u-boot,dm-pre-reloc; + compatible = "target"; + intval = <0>; + #clock-cells = <0>; + }; + + phandle-source2 { + u-boot,dm-pre-reloc; + compatible = "source"; + clocks = <&phandle>; + }; +}; diff --git a/tools/dtoc/test_dtoc.py b/tools/dtoc/test_dtoc.py index 41a4c53bb9d..95ecabc3a17 100644 --- a/tools/dtoc/test_dtoc.py +++ b/tools/dtoc/test_dtoc.py @@ -20,6 +20,7 @@ from dtb_platdata import get_value from dtb_platdata import tab_to import fdt import fdt_util +import test_util import tools our_path = os.path.dirname(os.path.realpath(__file__)) @@ -336,6 +337,68 @@ U_BOOT_DEVICE(phandle_source2) = { ''', data) + def test_phandle_single(self): + """Test output from a node containing a phandle reference""" + dtb_file = get_dtb_file('dtoc_test_phandle_single.dts') + output = tools.GetOutputFilename('output') + dtb_platdata.run_steps(['struct'], dtb_file, False, output) + with open(output) as infile: + data = infile.read() + self._CheckStrings(HEADER + ''' +struct dtd_source { +\tstruct phandle_0_arg clocks[1]; +}; +struct dtd_target { +\tfdt32_t\t\tintval; +}; +''', data) + + def test_phandle_reorder(self): + """Test that phandle targets are generated before their references""" + dtb_file = get_dtb_file('dtoc_test_phandle_reorder.dts') + output = tools.GetOutputFilename('output') + dtb_platdata.run_steps(['platdata'], dtb_file, False, output) + with open(output) as infile: + data = infile.read() + self._CheckStrings(C_HEADER + ''' +static struct dtd_target dtv_phandle_target = { +}; +U_BOOT_DEVICE(phandle_target) = { +\t.name\t\t= "target", +\t.platdata\t= &dtv_phandle_target, +\t.platdata_size\t= sizeof(dtv_phandle_target), +}; + +static struct dtd_source dtv_phandle_source2 = { +\t.clocks\t\t\t= { +\t\t\t{&dtv_phandle_target, {}},}, +}; +U_BOOT_DEVICE(phandle_source2) = { +\t.name\t\t= "source", +\t.platdata\t= &dtv_phandle_source2, +\t.platdata_size\t= sizeof(dtv_phandle_source2), +}; + +''', data) + + def test_phandle_bad(self): + """Test a node containing an invalid phandle fails""" + dtb_file = get_dtb_file('dtoc_test_phandle_bad.dts') + output = tools.GetOutputFilename('output') + with self.assertRaises(ValueError) as e: + dtb_platdata.run_steps(['struct'], dtb_file, False, output) + self.assertIn("Cannot parse 'clocks' in node 'phandle-source'", + str(e.exception)) + + def test_phandle_bad2(self): + """Test a phandle target missing its #*-cells property""" + dtb_file = get_dtb_file('dtoc_test_phandle_bad2.dts') + output = tools.GetOutputFilename('output') + with self.assertRaises(ValueError) as e: + dtb_platdata.run_steps(['struct'], dtb_file, False, output) + self.assertIn("Node 'phandle-target' has no '#clock-cells' property", + str(e.exception)) + def test_aliases(self): """Test output from a node with multiple compatible strings""" dtb_file = get_dtb_file('dtoc_test_aliases.dts') @@ -561,3 +624,82 @@ U_BOOT_DEVICE(test3) = { }; ''', data) + + def test_bad_reg(self): + """Test that a reg property with an invalid type generates an error""" + dtb_file = get_dtb_file('dtoc_test_bad_reg.dts') + output = tools.GetOutputFilename('output') + with self.assertRaises(ValueError) as e: + dtb_platdata.run_steps(['struct'], dtb_file, False, output) + self.assertIn("Node 'spl-test' reg property is not an int", + str(e.exception)) + + def test_bad_reg2(self): + """Test that a reg property with an invalid cell count is detected""" + dtb_file = get_dtb_file('dtoc_test_bad_reg2.dts') + output = tools.GetOutputFilename('output') + with self.assertRaises(ValueError) as e: + dtb_platdata.run_steps(['struct'], dtb_file, False, output) + self.assertIn("Node 'spl-test' reg property has 3 cells which is not a multiple of na + ns = 1 + 1)", + str(e.exception)) + + def test_add_prop(self): + """Test that a subequent node can add a new property to a struct""" + dtb_file = get_dtb_file('dtoc_test_add_prop.dts') + output = tools.GetOutputFilename('output') + dtb_platdata.run_steps(['struct'], dtb_file, False, output) + with open(output) as infile: + data = infile.read() + self._CheckStrings(HEADER + ''' +struct dtd_sandbox_spl_test { +\tfdt32_t\t\tintarray; +\tfdt32_t\t\tintval; +}; +''', data) + + dtb_platdata.run_steps(['platdata'], dtb_file, False, output) + with open(output) as infile: + data = infile.read() + self._CheckStrings(C_HEADER + ''' +static struct dtd_sandbox_spl_test dtv_spl_test = { +\t.intval\t\t\t= 0x1, +}; +U_BOOT_DEVICE(spl_test) = { +\t.name\t\t= "sandbox_spl_test", +\t.platdata\t= &dtv_spl_test, +\t.platdata_size\t= sizeof(dtv_spl_test), +}; + +static struct dtd_sandbox_spl_test dtv_spl_test2 = { +\t.intarray\t\t= 0x5, +}; +U_BOOT_DEVICE(spl_test2) = { +\t.name\t\t= "sandbox_spl_test", +\t.platdata\t= &dtv_spl_test2, +\t.platdata_size\t= sizeof(dtv_spl_test2), +}; + +''', data) + + def testStdout(self): + """Test output to stdout""" + dtb_file = get_dtb_file('dtoc_test_simple.dts') + with test_util.capture_sys_output() as (stdout, stderr): + dtb_platdata.run_steps(['struct'], dtb_file, False, '-') + + def testNoCommand(self): + """Test running dtoc without a command""" + with self.assertRaises(ValueError) as e: + dtb_platdata.run_steps([], '', False, '') + self.assertIn("Please specify a command: struct, platdata", + str(e.exception)) + + def testBadCommand(self): + """Test running dtoc with an invalid command""" + dtb_file = get_dtb_file('dtoc_test_simple.dts') + output = tools.GetOutputFilename('output') + with self.assertRaises(ValueError) as e: + dtb_platdata.run_steps(['invalid-cmd'], dtb_file, False, output) + self.assertIn("Unknown command 'invalid-cmd': (use: struct, platdata)", + str(e.exception)) + From patchwork Wed Jun 6 00:46:59 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 925689 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" (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.b="tgBnNGEb"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 410r33423qz9s02 for ; Wed, 6 Jun 2018 11:01:19 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 2CACEC21F22; Wed, 6 Jun 2018 00:56:00 +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_DNSWL_BLOCKED, RCVD_IN_MSPIKE_H2, 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 8827CC21FB3; Wed, 6 Jun 2018 00:51:43 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 71A20C21FD9; Wed, 6 Jun 2018 00:48:22 +0000 (UTC) Received: from mail-io0-f177.google.com (mail-io0-f177.google.com [209.85.223.177]) by lists.denx.de (Postfix) with ESMTPS id 7EAABC21F52 for ; Wed, 6 Jun 2018 00:48:18 +0000 (UTC) Received: by mail-io0-f177.google.com with SMTP id l25-v6so5611543ioh.12 for ; Tue, 05 Jun 2018 17:48:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=BpLtx6ZZmGCC/hUXPRYEBZ9FDMQxmxLEjnhqlM7JCvw=; b=tgBnNGEbyHhqO06eXHpMwf5CCBDzDohFSGIOUm8tfSGDAbMR/maXINGwFzE46EqDa3 XEjGFwFmPMX5M2C6Bzw05RcxQeGFeczlZx/CPcqXrVNbKDnve/X09ZDvG17kyukCEHe2 V9Ay9Si0mg5w3viNh9vVLGUI3DIdxXps127Ftve+gay6EFdkWqJtfyvhKBfd/Bfv/D30 11x9IfVYNRQSRJBSRO7s4NGctqChWJ/gXJMJktsXYafCS5II5mwL4uYK/rvJrzj47roY pssyYRENElVl9wGjfuuNbjGW5LDa1Ouw65qNKAiFDhgl11W8Gcum1J+N/MI8t17dQr9I aSrw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=BpLtx6ZZmGCC/hUXPRYEBZ9FDMQxmxLEjnhqlM7JCvw=; b=NnaV85dfKhVOOot62Jhb45XVn3LFwDreCS1WJr/yfXnVndgeUatfA8IIFrSNh7/U1V stcWACdQvsjrGXfreaQ/Z6iphj4YqsBUmEo0uxAwoEM8r53wC9Zu79b0ds27M4ebFYp/ 9UrhfFFS9CGQA3kOvHFO9SobB7p9H+wLwjA+ELmz+4a3v5L4MDeKITD+9uah4lpmeJNm kCt82lmAq2KkCpbYUQkgVqfr1AAMMPH7VtYjbaBYEgV7Jhe/fBHaA11wJvxBaOH8XQlm qIyam1f0aqmPD32uyDiV5kP74aN8d4Bm0xQB8TvCezbk8pO3p8yt/CtvNzD6I7v3XSQZ P8Cg== X-Gm-Message-State: APt69E1sa9Yb7QiJKGHkn2x3sMsjpqu3PQ/CAB+iVGc964EnAmBPHHVA ogNli4aLKSoUE3eSuNTzcPiZSwn+qJ8= X-Google-Smtp-Source: ADUXVKK4BxsudRmVZeNR3SZVmAEyvSNnkXM7GiRKQxift8kgZ0n70O8Dd2CGQpKy6DldGNG3NVPucQ== X-Received: by 2002:a6b:1a82:: with SMTP id a124-v6mr920094ioa.291.1528246096953; Tue, 05 Jun 2018 17:48:16 -0700 (PDT) Received: from kiwi.bld.corp.google.com ([100.67.80.24]) by smtp.gmail.com with ESMTPSA id f70-v6sm1254618ite.34.2018.06.05.17.48.15 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 05 Jun 2018 17:48:15 -0700 (PDT) Received: by kiwi.bld.corp.google.com (Postfix, from userid 121222) id 40A37140700; Tue, 5 Jun 2018 18:48:15 -0600 (MDT) From: Simon Glass To: U-Boot Mailing List Date: Tue, 5 Jun 2018 18:46:59 -0600 Message-Id: <20180606004705.79641-24-sjg@chromium.org> X-Mailer: git-send-email 2.17.1.1185.g55be947832-goog In-Reply-To: <20180606004705.79641-1-sjg@chromium.org> References: <20180606004705.79641-1-sjg@chromium.org> Cc: Tom Rini Subject: [U-Boot] [PATCH 23/29] binman: Move capture_sys_output() to test_util 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" This function is useful in various tests. Move it into the common test utility module. Signed-off-by: Simon Glass --- tools/binman/elf_test.py | 22 ++-------------------- tools/binman/image_test.py | 2 +- tools/patman/test_util.py | 22 ++++++++++++++++++++++ 3 files changed, 25 insertions(+), 21 deletions(-) diff --git a/tools/binman/elf_test.py b/tools/binman/elf_test.py index fb6e451cf0e..9c8f1feca85 100644 --- a/tools/binman/elf_test.py +++ b/tools/binman/elf_test.py @@ -4,33 +4,15 @@ # # Test for the elf module -from contextlib import contextmanager import os import sys import unittest -try: - from StringIO import StringIO -except ImportError: - from io import StringIO - import elf +import test_util binman_dir = os.path.dirname(os.path.realpath(sys.argv[0])) -# Use this to suppress stdout/stderr output: -# with capture_sys_output() as (stdout, stderr) -# ...do something... -@contextmanager -def capture_sys_output(): - capture_out, capture_err = StringIO(), StringIO() - old_out, old_err = sys.stdout, sys.stderr - try: - sys.stdout, sys.stderr = capture_out, capture_err - yield capture_out, capture_err - finally: - sys.stdout, sys.stderr = old_out, old_err - class FakeEntry: def __init__(self, contents_size): @@ -110,7 +92,7 @@ class TestElf(unittest.TestCase): entry = FakeEntry(20) section = FakeSection() elf_fname = os.path.join(binman_dir, 'test', 'u_boot_binman_syms') - with capture_sys_output() as (stdout, stderr): + with test_util.capture_sys_output() as (stdout, stderr): syms = elf.LookupAndWriteSymbols(elf_fname, entry, section) elf.debug = False self.assertTrue(len(stdout.getvalue()) > 0) diff --git a/tools/binman/image_test.py b/tools/binman/image_test.py index 45dd2378c8a..3775e1afb07 100644 --- a/tools/binman/image_test.py +++ b/tools/binman/image_test.py @@ -7,7 +7,7 @@ import unittest from image import Image -from elf_test import capture_sys_output +from test_util import capture_sys_output class TestImage(unittest.TestCase): def testInvalidFormat(self): diff --git a/tools/patman/test_util.py b/tools/patman/test_util.py index a240f383777..d159509e812 100644 --- a/tools/patman/test_util.py +++ b/tools/patman/test_util.py @@ -3,12 +3,19 @@ # Copyright (c) 2016 Google, Inc # +from contextlib import contextmanager import glob import os import sys import command +try: + from StringIO import StringIO +except ImportError: + from io import StringIO + + def RunTestCoverage(prog, filter_fname, exclude_list, build_dir): """Run tests and check that we get 100% coverage @@ -49,3 +56,18 @@ def RunTestCoverage(prog, filter_fname, exclude_list, build_dir): ok = False if not ok: raise ValueError('Test coverage failure') + + +# Use this to suppress stdout/stderr output: +# with capture_sys_output() as (stdout, stderr) +# ...do something... +@contextmanager +def capture_sys_output(): + capture_out, capture_err = StringIO(), StringIO() + old_out, old_err = sys.stdout, sys.stderr + try: + sys.stdout, sys.stderr = capture_out, capture_err + yield capture_out, capture_err + finally: + sys.stdout, sys.stderr = old_out, old_err + From patchwork Wed Jun 6 00:47:00 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 925680 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" (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.b="KnxD4zm8"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 410qzN2ndSz9s08 for ; Wed, 6 Jun 2018 10:58:08 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 140FBC21FB8; Wed, 6 Jun 2018 00:54:59 +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_DNSWL_BLOCKED, RCVD_IN_MSPIKE_H2, 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 66FFFC21FF7; Wed, 6 Jun 2018 00:50:37 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id DA40BC21FC7; Wed, 6 Jun 2018 00:48:24 +0000 (UTC) Received: from mail-io0-f195.google.com (mail-io0-f195.google.com [209.85.223.195]) by lists.denx.de (Postfix) with ESMTPS id 9E760C21FA6 for ; Wed, 6 Jun 2018 00:48:20 +0000 (UTC) Received: by mail-io0-f195.google.com with SMTP id d73-v6so5656598iog.3 for ; Tue, 05 Jun 2018 17:48:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=uVQ63ZaD6vM67a6mE4W8+2+fJwRuYjD4H1tXQmgaqKQ=; b=KnxD4zm8uCDstxvqxcljawUmnCJL492bN7pivVwZ3dI6m3GOftcKaF+SaosJe2Aaxl VvD7HPSmEaSjV9sythDP62db2/hSh/9SPRYktLpDpXlw3M7nXBXfzJ5U7J4H9SkuJjG7 wdRnxhNWsyUuDB7CG9MINgjM2Mzymketj7yLzxZ8N7INVMDd8bgk6zcxiqexW+SetEL0 K+vu00wRL1OAIM+Mw96G4kfZ5gqSh3jpzY3Nm+VWEg1tAbNJCzOvHY6VDFGS/BS6pHqV yDN84ry98CZXZrMORhe4ZuFH68eN5+jhWi8qH9iE8EY7n3h4HZ2Ds7Wy8A//9lc9uCze rY2g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=uVQ63ZaD6vM67a6mE4W8+2+fJwRuYjD4H1tXQmgaqKQ=; b=AYlR+vMcO9UKsv0rWvKJ/YpbgknJhl1+qbTjhPvd6CwMpcklKpgz4FT/hohmySb9OR DWyNKljaPIwhD5Y5cm3MK1I9PPlDembIw0kIRQuaDuaieNS0usolTaAuZom0YGumwQkM HLlqbU1xu3arGcCNAEY3ZsBDo3V9nRSEF7o8pVRynlihVMcO/AgwJB0eloT+hEa0oH9U pV53IUfo7hLnjkkTxqvX1OwNexShw7erzIW2Xs3cV0AUZZVRWrhLEJbjOAkRetyHTbEJ 8Ex3XHyTjz/ify8Vsi5TaxGRZC6913/rGSNulo4bWzcSyYucOLF8/2lfMo4ms++TPaJg 1jZw== X-Gm-Message-State: APt69E16TckMbwm/rywDqtwICdRLjWjOLA7RIYorEJI7qyiGXfV9Nbs3 Cu9XuZ721e+hUgBpCsMaIA8P3g== X-Google-Smtp-Source: ADUXVKIBsyDJGFNhEUBhk8jp5juIzpy+gIvUVNdocp6eTj1X73yfN5bRp63SBGENCeGYZ00ySihrnw== X-Received: by 2002:a6b:8208:: with SMTP id e8-v6mr845006iod.264.1528246099126; Tue, 05 Jun 2018 17:48:19 -0700 (PDT) Received: from kiwi.bld.corp.google.com ([100.67.80.24]) by smtp.gmail.com with ESMTPSA id o89-v6sm8089904ioi.85.2018.06.05.17.48.17 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 05 Jun 2018 17:48:17 -0700 (PDT) Received: by kiwi.bld.corp.google.com (Postfix, from userid 121222) id 0B6E21409F9; Tue, 5 Jun 2018 18:48:17 -0600 (MDT) From: Simon Glass To: U-Boot Mailing List Date: Tue, 5 Jun 2018 18:47:00 -0600 Message-Id: <20180606004705.79641-25-sjg@chromium.org> X-Mailer: git-send-email 2.17.1.1185.g55be947832-goog In-Reply-To: <20180606004705.79641-1-sjg@chromium.org> References: <20180606004705.79641-1-sjg@chromium.org> Cc: Tom Rini Subject: [U-Boot] [PATCH 24/29] dtoc: Avoid unwanted output during tests 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" At present some warnings are printed to indicate failures which are a known part of running the tests. Suppress these. Signed-off-by: Simon Glass --- tools/dtoc/fdt_util.py | 4 ++-- tools/dtoc/test_dtoc.py | 13 +++++++++---- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/tools/dtoc/fdt_util.py b/tools/dtoc/fdt_util.py index 2d09649f720..e7f5a809093 100644 --- a/tools/dtoc/fdt_util.py +++ b/tools/dtoc/fdt_util.py @@ -44,7 +44,7 @@ def fdt_cells_to_cpu(val, cells): out = out << 32 | fdt32_to_cpu(val[1]) return out -def EnsureCompiled(fname): +def EnsureCompiled(fname, capture_stderr=False): """Compile an fdt .dts source file into a .dtb binary blob if needed. Args: @@ -79,7 +79,7 @@ def EnsureCompiled(fname): args.extend(search_list) args.append(dts_input) dtc = os.environ.get('DTC') or 'dtc' - command.Run(dtc, *args) + command.Run(dtc, *args, capture_stderr=capture_stderr) return dtb_output def GetInt(node, propname, default=None): diff --git a/tools/dtoc/test_dtoc.py b/tools/dtoc/test_dtoc.py index 95ecabc3a17..d48cf392d81 100644 --- a/tools/dtoc/test_dtoc.py +++ b/tools/dtoc/test_dtoc.py @@ -47,16 +47,19 @@ C_HEADER = '''/* ''' -def get_dtb_file(dts_fname): + +def get_dtb_file(dts_fname, capture_stderr=False): """Compile a .dts file to a .dtb Args: dts_fname: Filename of .dts file in the current directory + capture_stderr: True to capture and discard stderr output Returns: Filename of compiled file in output directory """ - return fdt_util.EnsureCompiled(os.path.join(our_path, dts_fname)) + return fdt_util.EnsureCompiled(os.path.join(our_path, dts_fname), + capture_stderr=capture_stderr) class TestDtoc(unittest.TestCase): @@ -627,7 +630,8 @@ U_BOOT_DEVICE(test3) = { def test_bad_reg(self): """Test that a reg property with an invalid type generates an error""" - dtb_file = get_dtb_file('dtoc_test_bad_reg.dts') + # Capture stderr since dtc will emit warnings for this file + dtb_file = get_dtb_file('dtoc_test_bad_reg.dts', capture_stderr=True) output = tools.GetOutputFilename('output') with self.assertRaises(ValueError) as e: dtb_platdata.run_steps(['struct'], dtb_file, False, output) @@ -636,7 +640,8 @@ U_BOOT_DEVICE(test3) = { def test_bad_reg2(self): """Test that a reg property with an invalid cell count is detected""" - dtb_file = get_dtb_file('dtoc_test_bad_reg2.dts') + # Capture stderr since dtc will emit warnings for this file + dtb_file = get_dtb_file('dtoc_test_bad_reg2.dts', capture_stderr=True) output = tools.GetOutputFilename('output') with self.assertRaises(ValueError) as e: dtb_platdata.run_steps(['struct'], dtb_file, False, output) From patchwork Wed Jun 6 00:47:01 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 925684 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" (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.b="HrjEH600"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 410r0m6d72z9s08 for ; Wed, 6 Jun 2018 10:59:20 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 99E97C21E88; Wed, 6 Jun 2018 00:54:24 +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_DNSWL_BLOCKED, RCVD_IN_MSPIKE_H2, 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 97CBBC21F8E; Wed, 6 Jun 2018 00:49:47 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 3E08DC22006; Wed, 6 Jun 2018 00:48:24 +0000 (UTC) Received: from mail-io0-f194.google.com (mail-io0-f194.google.com [209.85.223.194]) by lists.denx.de (Postfix) with ESMTPS id 5AC04C21F0B for ; Wed, 6 Jun 2018 00:48:21 +0000 (UTC) Received: by mail-io0-f194.google.com with SMTP id g22-v6so5649092iob.7 for ; Tue, 05 Jun 2018 17:48:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=Wt4kmFD3ma+gBNStOVL/fsOkurju88wOIR8FZD+QLG4=; b=HrjEH600SGlBO20J63diOQr6/uRxdZqVwRTPMFapbM8TX5x4x44BXcJaa8dzWdI0p6 vhIIpAQzSXrY08iNJDAJXBv8AZE0ac9ahLmtpSCY44hbwauHpclnwIPAiFav9I5/dy5n XAF+fJOkHc16ku35wz73uG9PZNZayR8ZSkDmRPMqiwix1xYXDq1NoiKfyzqyyOyHHujL TrOqu+0T9nTpycbVl/Im2NjMj3UjwqlrCXQUyUg7MF/VijvArtvDY1fBZuk4C/g7/2f2 Pl2+ty8enSFjz8kaomZYcCMmgJA7/xOaiATgesUqwzxlovPYYdaEtqzOS3IXmNRJe4s6 1xzQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=Wt4kmFD3ma+gBNStOVL/fsOkurju88wOIR8FZD+QLG4=; b=IX78NTwnQYGFjnizX04O92yPsp6aosGDbsXeB4CWpEjOJPTZHQzX3NvTXgywQmS+ST MbwsYSBOG1iZJ3X29GOhJ/TXN8TD8cVVHh26S3Jhwf8BD1EId3M9MMNfG+TaaWrib3hi huzlRiBRwoRSkUdjRvRq/vQWSvqqLVMfAjwqgaGjJ/vMs2h0PCtEa31RZ08Re8JXYQhP g0E+JUGRisrOQnbaq+KtD9XwXPoDblniMkR9OpE7GnH9/0mr73fkzLo8kucdKo2kbsrQ pRJV5jsBrnTgPPF7HOxSbretwlFcI5GQr1A2cP5WNkMzvguCZgmS9qNUM+54aK1U1D69 UpHg== X-Gm-Message-State: APt69E3rH5217Jc0Kips9U2htIMEBeFKJYKbzKm0meX/dWh24TSwj0ST yAltiK3Zd0pEOoNEU/6lmYGrRjps69I= X-Google-Smtp-Source: ADUXVKKD1g8oWl4fAntuL4uMnb7ZHJG4sY7+uwDg6a9l+aaggsCdMBpIPheYkcq45fmHGkSeTGcUaA== X-Received: by 2002:a6b:1ad1:: with SMTP id a200-v6mr801950ioa.139.1528246099900; Tue, 05 Jun 2018 17:48:19 -0700 (PDT) Received: from kiwi.bld.corp.google.com ([2620:15c:183:0:8223:87c:a681:66aa]) by smtp.gmail.com with ESMTPSA id c90-v6sm1357803itd.13.2018.06.05.17.48.18 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 05 Jun 2018 17:48:19 -0700 (PDT) Received: by kiwi.bld.corp.google.com (Postfix, from userid 121222) id A7B7A140700; Tue, 5 Jun 2018 18:48:18 -0600 (MDT) From: Simon Glass To: U-Boot Mailing List Date: Tue, 5 Jun 2018 18:47:01 -0600 Message-Id: <20180606004705.79641-26-sjg@chromium.org> X-Mailer: git-send-email 2.17.1.1185.g55be947832-goog In-Reply-To: <20180606004705.79641-1-sjg@chromium.org> References: <20180606004705.79641-1-sjg@chromium.org> Cc: Tom Rini Subject: [U-Boot] [PATCH 25/29] dtoc: Add functions to add integer properties 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" Add a few simple functions to add a placeholder integer property, and set its value. Signed-off-by: Simon Glass --- tools/dtoc/fdt.py | 27 +++++++++++++++++++++++++++ tools/dtoc/test_fdt.py | 20 ++++++++++++++++++++ 2 files changed, 47 insertions(+) diff --git a/tools/dtoc/fdt.py b/tools/dtoc/fdt.py index f11fb75b1a4..7282b7e021c 100644 --- a/tools/dtoc/fdt.py +++ b/tools/dtoc/fdt.py @@ -277,6 +277,33 @@ class Node: del self.props[prop_name] self._fdt.Invalidate() + def AddZeroProp(self, prop_name): + """Add a new property to the device tree with an integer value of 0. + + Args: + prop_name: Name of property + """ + fdt_obj = self._fdt._fdt_obj + if fdt_obj.setprop_u32(self.Offset(), prop_name, 0, + (libfdt.NOSPACE,)) == -libfdt.NOSPACE: + fdt_obj.open_into(fdt_obj.totalsize() + 1024) + fdt_obj.setprop_u32(self.Offset(), prop_name, 0) + self.props[prop_name] = Prop(self, -1, prop_name, '\0' * 4) + self._fdt.Invalidate() + + def SetInt(self, prop_name, val): + """Update an integer property int the device tree. + + This is not allowed to change the size of the FDT. + + Args: + prop_name: Name of property + val: Value to set + """ + fdt_obj = self._fdt._fdt_obj + fdt_obj.setprop_u32(self.Offset(), prop_name, val) + + class Fdt: """Provides simple access to a flat device tree blob using libfdts. diff --git a/tools/dtoc/test_fdt.py b/tools/dtoc/test_fdt.py index 97b8cbb794e..0bc4bd64646 100755 --- a/tools/dtoc/test_fdt.py +++ b/tools/dtoc/test_fdt.py @@ -318,6 +318,26 @@ class TestProp(unittest.TestCase): self.assertTrue(isinstance(prop.value, list)) self.assertEqual(3, len(prop.value)) + def testAdd(self): + """Test adding properties""" + self.fdt.pack() + # This function should automatically expand the device tree + self.node.AddZeroProp('one') + self.node.AddZeroProp('two') + self.node.AddZeroProp('three') + + # Updating existing properties should be OK, since the device-tree size + # does not change + self.fdt.pack() + self.node.SetInt('one', 1) + self.node.SetInt('two', 2) + self.node.SetInt('three', 3) + + # This should fail since it would need to increase the device-tree size + with self.assertRaises(libfdt.FdtException) as e: + self.node.SetInt('four', 4) + self.assertIn('FDT_ERR_NOSPACE', str(e.exception)) + def RunTestCoverage(): """Run the tests and check that we get 100% coverage""" From patchwork Wed Jun 6 00:47:02 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 925686 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" (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.b="RtegHRL2"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 410r265fHfz9s02 for ; Wed, 6 Jun 2018 11:00:30 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 67856C21F85; Wed, 6 Jun 2018 00:54:08 +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_DNSWL_BLOCKED, 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 93FB2C21F0B; Wed, 6 Jun 2018 00:49:32 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 390DAC21FF9; Wed, 6 Jun 2018 00:48:28 +0000 (UTC) Received: from mail-io0-f176.google.com (mail-io0-f176.google.com [209.85.223.176]) by lists.denx.de (Postfix) with ESMTPS id B3B69C21F22 for ; Wed, 6 Jun 2018 00:48:23 +0000 (UTC) Received: by mail-io0-f176.google.com with SMTP id u4-v6so5656840iof.2 for ; Tue, 05 Jun 2018 17:48:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=jOZhMmKOMT9HCJ3jDljusJdOQkHz8XZnViXckbkEjpE=; b=RtegHRL2HsStTI0bvnh+H5ncq+CMAqBDrzJq2BZjB6F87b3+syBo/KLjAacgZvdSZQ Ic3WI9m0eIZF2+ksLj5ASP7999k9qcpu/wVBBGu9yqKv65/VcZlYKFzeqo/vqX7TbYNU 6QkLztTtNyrlqTJ4XKmV+i+5URbjIW24KpQzHb7WdEyAVcEAhhrTVR2wl2c75gZOqUNq 9zLL0AmlvtetLStaTk9dR+jo/hJwQ4hSMMUkpZPfYndFQkW9OcU7IgNSTslmoXgUJob4 Nv7v0r9GoxRPIZ0lc9LF8ZlLOcwthlqWaxeT6/jVJbIQL6Jdg8dCf3wTBPxZc33c5rhM mQ+w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=jOZhMmKOMT9HCJ3jDljusJdOQkHz8XZnViXckbkEjpE=; b=qmwcBPpGdeHRE3fx4JUN1jKjWv72LsdOg3P2iABcxcwZ89n092/SL8rkaBI4s8kYcg WRwuPCxiFrfDRBPgdZ1bnhc9j1hgf0FQB8ofcX1KJ0q2jiXt7CzmjTcVj8Wq0mkN7Bk1 W0Nsj9CnFrtMyEP2VE5mHEr5qJMKQefWnwpfZOLqRvBciod9E9ycYy8ZK6IZ39x3QGHx Cpqx+GYE7tWt9TBLQ+8D6+2yqIrv4pzGqdYFon0v73M7Modl0vh+KGXh53ip8J+Z7sBv VShjr3bLfSZnce7u9ObWpRk2VRkHeswwNJNmYLL9z1hr0CJwtliStHLebD36y6AVxpGw fJwg== X-Gm-Message-State: APt69E1rdgVeWjs/Vh3tGYad3TYlbQb1CgkkY5452v5dXAUIW6GGHi0P w9Ddz4PKdOKzgDhSNYQS5YXu1Q== X-Google-Smtp-Source: ADUXVKImtVjs1/8oQ8ps1eerJiHm777GpQGf/C27oII4aETl7mM5pfMRF9Q72QlVmXYs0521uSX8MA== X-Received: by 2002:a6b:39d4:: with SMTP id g203-v6mr917319ioa.165.1528246102209; Tue, 05 Jun 2018 17:48:22 -0700 (PDT) Received: from kiwi.bld.corp.google.com ([100.67.80.24]) by smtp.gmail.com with ESMTPSA id w20-v6sm5757925iob.24.2018.06.05.17.48.20 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 05 Jun 2018 17:48:21 -0700 (PDT) Received: by kiwi.bld.corp.google.com (Postfix, from userid 121222) id 347E1140700; Tue, 5 Jun 2018 18:48:20 -0600 (MDT) From: Simon Glass To: U-Boot Mailing List Date: Tue, 5 Jun 2018 18:47:02 -0600 Message-Id: <20180606004705.79641-27-sjg@chromium.org> X-Mailer: git-send-email 2.17.1.1185.g55be947832-goog In-Reply-To: <20180606004705.79641-1-sjg@chromium.org> References: <20180606004705.79641-1-sjg@chromium.org> Cc: Tom Rini Subject: [U-Boot] [PATCH 26/29] binman: Complete documentation of stages 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" At present one of the stages is badly numbered and not described. Fix this. Signed-off-by: Simon Glass --- tools/binman/README | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tools/binman/README b/tools/binman/README index f74e39242f6..3cfcf84d92c 100644 --- a/tools/binman/README +++ b/tools/binman/README @@ -495,9 +495,11 @@ contents of an entry in some way. For example, it would be possible to create an entry containing a hash of the contents of some other entries. At this stage the position and size of entries should not be adjusted. -6. WriteEntryInfo() +7. WriteSymbols() - write the value of symbols into the U-Boot SPL binary. +See 'Access to binman entry positions at run time' below for a description of +what happens in this stage. -7. BuildImage() - builds the image and writes it to a file. This is the final +8. BuildImage() - builds the image and writes it to a file. This is the final step. From patchwork Wed Jun 6 00:47:03 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 925681 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" (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.b="JYcqzY8p"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 410qzZ3WQRz9s08 for ; Wed, 6 Jun 2018 10:58:18 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 2E08EC21F3D; Wed, 6 Jun 2018 00:56:46 +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_DNSWL_BLOCKED, RCVD_IN_MSPIKE_H2, 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 F0C05C21FA5; Wed, 6 Jun 2018 00:52:06 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 0877CC21F9F; Wed, 6 Jun 2018 00:48:28 +0000 (UTC) Received: from mail-io0-f193.google.com (mail-io0-f193.google.com [209.85.223.193]) by lists.denx.de (Postfix) with ESMTPS id 8E37CC21F78 for ; Wed, 6 Jun 2018 00:48:24 +0000 (UTC) Received: by mail-io0-f193.google.com with SMTP id d22-v6so5622467iof.13 for ; Tue, 05 Jun 2018 17:48:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=Fg7z0+0lBqRpM2/Vd9YeCyhEaI0VYiGxibADTyXd7zo=; b=JYcqzY8poxUx18Y2v3xgvLbpbxXNm3ivHCkm9apfv9D6bCsbBehYdyoKDewH5kAG1A 1xTJvWByvmNY9fJ7IUXDCVUgz4OE+q6ku0qZzJzow4SwHJjzYPAdKNk0Jt9fW9qYSROM ZTu8kJHJxHdygOBer/vemkGkiduo6VTj0VJ4nvCVl0TwsrekYOCi0tTgoD1tXy69CQI0 hG3N3VsQnXz3AyrO19MHffpMoK0OaKCMvwPuT7NYBErNT4shD1VxgMz1LjnFgOOhFv0q 54YzVbUHesBvmn31HJLPwRhCoyUmiY20lDryrGeAQ+TggcdbJPwzfUzTmE3MXtY25zrx v0pA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=Fg7z0+0lBqRpM2/Vd9YeCyhEaI0VYiGxibADTyXd7zo=; b=sVd9SeACfbV6OWSC4M6s60ZImYW0rS55u7SwjXfTrRsSOstxmor1A6tPc0T1YZwk+Q yOXdlOmScLeh3wRHmyslW05N4sJFwNqEN4VbHev1g3jl9VDnYGu+UNOif/+qGwvpAR6q 0qQ5gAeOYsjWrjjToRNVOd5iiX/k20kNLrmO32I+fwkqtX3Ql6HkLb/SvisdTwVCNwlt txAv/A0k2CYj0Pqyttp5YTqGNCffrWqwMUHZMsqLMnxBYe6KaeOIARNf+BpaUzWitSHL G1zanBPmxVcK21X6VBN2+sVquv0LlABM7L6TXpcaN6yq7aJuiPsFaUHggIOjqR0iTk/1 UcLw== X-Gm-Message-State: APt69E1etaDxzbp7MqVNtDyqCqexArWgvqGv+Cm4PFL0VXmi25lTCYwF bCsY/jFWzGOfLl1F4ZAbWkhcNA== X-Google-Smtp-Source: ADUXVKJ4mV55qQPZoCp5augvy/4H5ie2cvDlj+ps84AfCD4HRKTpdbpjM9V0ldNKr/RlcOusNb/eEw== X-Received: by 2002:a6b:2550:: with SMTP id l77-v6mr830338iol.47.1528246102919; Tue, 05 Jun 2018 17:48:22 -0700 (PDT) Received: from kiwi.bld.corp.google.com ([2620:15c:183:0:8223:87c:a681:66aa]) by smtp.gmail.com with ESMTPSA id m13-v6sm4866580iob.86.2018.06.05.17.48.22 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 05 Jun 2018 17:48:22 -0700 (PDT) Received: by kiwi.bld.corp.google.com (Postfix, from userid 121222) id D26691409F9; Tue, 5 Jun 2018 18:48:21 -0600 (MDT) From: Simon Glass To: U-Boot Mailing List Date: Tue, 5 Jun 2018 18:47:03 -0600 Message-Id: <20180606004705.79641-28-sjg@chromium.org> X-Mailer: git-send-email 2.17.1.1185.g55be947832-goog In-Reply-To: <20180606004705.79641-1-sjg@chromium.org> References: <20180606004705.79641-1-sjg@chromium.org> Cc: Tom Rini Subject: [U-Boot] [PATCH 27/29] binman: Add a ProcessFdt() method 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" Some entry types modify the device tree, e.g. to remove microcode or add a property. So far this just modifies their local copy and does not affect a 'shared' device tree. Rather than doing this modification in the ObtainContents() method, and a new ProcessFdt() method which is specifically designed to modify this shared device tree. Move the existing device-tree code over to use this method, reducing ObtainContents() to the goal of just obtaining the contents without any processing, even for device tree. Signed-off-by: Simon Glass --- tools/binman/README | 23 +++++---- tools/binman/bsection.py | 15 ++++++ tools/binman/control.py | 52 ++++++++++++++++++++- tools/binman/entry.py | 3 ++ tools/binman/etype/section.py | 3 ++ tools/binman/etype/u_boot_dtb_with_ucode.py | 47 ++++++++++--------- tools/binman/etype/u_boot_ucode.py | 2 +- tools/binman/etype/u_boot_with_ucode_ptr.py | 7 ++- tools/binman/image.py | 3 ++ 9 files changed, 118 insertions(+), 37 deletions(-) diff --git a/tools/binman/README b/tools/binman/README index 3cfcf84d92c..008d5750528 100644 --- a/tools/binman/README +++ b/tools/binman/README @@ -462,7 +462,14 @@ Order of image creation Image creation proceeds in the following order, for each entry in the image. -1. GetEntryContents() - the contents of each entry are obtained, normally by +1. ProcessFdt() - process the device tree information as required by the +particular entry. This may involve adding or deleting properties. If the +processing is complete, this method should return True. If the processing +cannot complete because it needs the ProcessFdt() method of another entry to +run first, this method should return False, in which case it will be called +again later. + +2. GetEntryContents() - the contents of each entry are obtained, normally by reading from a file. This calls the Entry.ObtainContents() to read the contents. The default version of Entry.ObtainContents() calls Entry.GetDefaultFilename() and then reads that file. So a common mechanism @@ -471,35 +478,35 @@ functions must return True when they have read the contents. Binman will retry calling the functions a few times if False is returned, allowing dependencies between the contents of different entries. -2. GetEntryPositions() - calls Entry.GetPositions() for each entry. This can +3. GetEntryPositions() - calls Entry.GetPositions() for each entry. This can return a dict containing entries that need updating. The key should be the entry name and the value is a tuple (pos, size). This allows an entry to provide the position and size for other entries. The default implementation of GetEntryPositions() returns {}. -3. PackEntries() - calls Entry.Pack() which figures out the position and +4. PackEntries() - calls Entry.Pack() which figures out the position and size of an entry. The 'current' image position is passed in, and the function returns the position immediately after the entry being packed. The default implementation of Pack() is usually sufficient. -4. CheckSize() - checks that the contents of all the entries fits within +5. CheckSize() - checks that the contents of all the entries fits within the image size. If the image does not have a defined size, the size is set large enough to hold all the entries. -5. CheckEntries() - checks that the entries do not overlap, nor extend +6. CheckEntries() - checks that the entries do not overlap, nor extend outside the image. -6. ProcessEntryContents() - this calls Entry.ProcessContents() on each entry. +7. ProcessEntryContents() - this calls Entry.ProcessContents() on each entry. The default implementatoin does nothing. This can be overriden to adjust the contents of an entry in some way. For example, it would be possible to create an entry containing a hash of the contents of some other entries. At this stage the position and size of entries should not be adjusted. -7. WriteSymbols() - write the value of symbols into the U-Boot SPL binary. +8. WriteSymbols() - write the value of symbols into the U-Boot SPL binary. See 'Access to binman entry positions at run time' below for a description of what happens in this stage. -8. BuildImage() - builds the image and writes it to a file. This is the final +9. BuildImage() - builds the image and writes it to a file. This is the final step. diff --git a/tools/binman/bsection.py b/tools/binman/bsection.py index 06a6711350a..3ed361d69a2 100644 --- a/tools/binman/bsection.py +++ b/tools/binman/bsection.py @@ -90,6 +90,21 @@ class Section(object): entry.SetPrefix(self._name_prefix) self._entries[node.name] = entry + def ProcessFdt(self, fdt): + todo = self._entries.values() + for passnum in range(3): + next_todo = [] + for entry in todo: + if not entry.ProcessFdt(fdt): + next_todo.append(entry) + todo = next_todo + if not todo: + break + if todo: + self._Raise('Internal error: Could not complete processing of Fdt: ' + 'remaining %s' % todo) + return True + def CheckSize(self): """Check that the section contents does not exceed its size, etc.""" contents_size = 0 diff --git a/tools/binman/control.py b/tools/binman/control.py index 92434729061..5325a6a0066 100644 --- a/tools/binman/control.py +++ b/tools/binman/control.py @@ -21,6 +21,11 @@ import tout # Make this global so that it can be referenced from tests images = OrderedDict() +# Records the device-tree files known to binman, keyed by filename (e.g. +# 'u-boot-spl.dtb') +fdt_files = {} + + def _ReadImageDesc(binman_node): """Read the image descriptions from the /binman node @@ -53,6 +58,24 @@ def _FindBinmanNode(dtb): return node return None +def GetFdt(fname): + """Get the Fdt object for a particular device-tree filename + + Binman keeps track of at least one device-tree file called u-boot.dtb but + can also have others (e.g. for SPL). This function looks up the given + filename and returns the associated Fdt object. + + Args: + fname: Filename to look up (e.g. 'u-boot.dtb'). + + Returns: + Fdt object associated with the filename + """ + return fdt_files[fname] + +def GetFdtPath(fname): + return fdt_files[fname]._fname + def Binman(options, args): """The main control code for binman @@ -93,12 +116,39 @@ def Binman(options, args): try: tools.SetInputDirs(options.indir) tools.PrepareOutputDir(options.outdir, options.preserve) - dtb = fdt.FdtScan(dtb_fname) + + # Get the device tree ready by compiling it and copying the compiled + # output into a file in our output directly. Then scan it for use + # in binman. + dtb_fname = fdt_util.EnsureCompiled(dtb_fname) + fname = tools.GetOutputFilename('u-boot-out.dtb') + with open(dtb_fname) as infd: + with open(fname, 'wb') as outfd: + outfd.write(infd.read()) + dtb = fdt.FdtScan(fname) + + # Note the file so that GetFdt() can find it + fdt_files['u-boot.dtb'] = dtb node = _FindBinmanNode(dtb) if not node: raise ValueError("Device tree '%s' does not have a 'binman' " "node" % dtb_fname) + images = _ReadImageDesc(node) + + # Prepare the device tree by making sure that any missing + # properties are added (e.g. 'pos' and 'size'). The values of these + # may not be correct yet, but we add placeholders so that the + # size of the device tree is correct. Later, in + # SetCalculatedProperties() we will insert the correct values + # without changing the device-tree size, thus ensuring that our + # entry positions remain the same. + for image in images.values(): + image.ProcessFdt(dtb) + + dtb.Pack() + dtb.Flush() + for image in images.values(): # Perform all steps for this image, including checking and # writing it. This means that errors found with a later diff --git a/tools/binman/entry.py b/tools/binman/entry.py index 303c992e375..62e65c91266 100644 --- a/tools/binman/entry.py +++ b/tools/binman/entry.py @@ -130,6 +130,9 @@ class Entry(object): self.align_end = fdt_util.GetInt(self._node, 'align-end') self.pos_unset = fdt_util.GetBool(self._node, 'pos-unset') + def ProcessFdt(self, fdt): + return True + def SetPrefix(self, prefix): """Set the name prefix for a node diff --git a/tools/binman/etype/section.py b/tools/binman/etype/section.py index 36b31a849f8..9b38738d38d 100644 --- a/tools/binman/etype/section.py +++ b/tools/binman/etype/section.py @@ -17,6 +17,9 @@ class Entry_section(Entry): Entry.__init__(self, image, etype, node) self._section = bsection.Section(node.name, node) + def ProcessFdt(self, fdt): + return self._section.ProcessFdt(fdt) + def ObtainContents(self): return self._section.GetEntryContents() diff --git a/tools/binman/etype/u_boot_dtb_with_ucode.py b/tools/binman/etype/u_boot_dtb_with_ucode.py index 1e530d6570a..54c2298bc2e 100644 --- a/tools/binman/etype/u_boot_dtb_with_ucode.py +++ b/tools/binman/etype/u_boot_dtb_with_ucode.py @@ -5,6 +5,7 @@ # Entry-type module for U-Boot device tree with the microcode removed # +import control import fdt from entry import Entry from blob import Entry_blob @@ -22,13 +23,13 @@ class Entry_u_boot_dtb_with_ucode(Entry_blob): self.collate = False self.ucode_offset = None self.ucode_size = None + self.ucode = None + self.ready = False def GetDefaultFilename(self): return 'u-boot.dtb' - def ObtainContents(self): - Entry_blob.ObtainContents(self) - + def ProcessFdt(self, fdt): # If the section does not need microcode, there is nothing to do ucode_dest_entry = self.section.FindEntryType( 'u-boot-spl-with-ucode-ptr') @@ -38,36 +39,36 @@ class Entry_u_boot_dtb_with_ucode(Entry_blob): if not ucode_dest_entry or not ucode_dest_entry.target_pos: return True - # Create a new file to hold the copied device tree - dtb_name = 'u-boot-dtb-with-ucode.dtb' - fname = tools.GetOutputFilename(dtb_name) - with open(fname, 'wb') as fd: - fd.write(self.data) - # Remove the microcode - dtb = fdt.FdtScan(fname) - ucode = dtb.GetNode('/microcode') - if not ucode: + fname = self.GetDefaultFilename() + fdt = control.GetFdt(fname) + self.ucode = fdt.GetNode('/microcode') + if not self.ucode: raise self.Raise("No /microcode node found in '%s'" % fname) # There's no need to collate it (move all microcode into one place) # if we only have one chunk of microcode. - self.collate = len(ucode.subnodes) > 1 - for node in ucode.subnodes: + self.collate = len(self.ucode.subnodes) > 1 + for node in self.ucode.subnodes: data_prop = node.props.get('data') if data_prop: self.ucode_data += ''.join(data_prop.bytes) if self.collate: - prop = node.DeleteProp('data') - else: + node.DeleteProp('data') + return True + + def ObtainContents(self): + # Call the base class just in case it does something important. + Entry_blob.ObtainContents(self) + self._pathname = control.GetFdtPath(self._filename) + self.ReadContents() + if self.ucode: + for node in self.ucode.subnodes: + data_prop = node.props.get('data') + if data_prop and not self.collate: # Find the offset in the device tree of the ucode data self.ucode_offset = data_prop.GetOffset() + 12 self.ucode_size = len(data_prop.bytes) - if self.collate: - dtb.Pack() - dtb.Flush() - - # Make this file the contents of this entry - self._pathname = fname - self.ReadContents() + self.ready = True return True + diff --git a/tools/binman/etype/u_boot_ucode.py b/tools/binman/etype/u_boot_ucode.py index 8cae7deed3c..ea0c85cc5c7 100644 --- a/tools/binman/etype/u_boot_ucode.py +++ b/tools/binman/etype/u_boot_ucode.py @@ -71,7 +71,7 @@ class Entry_u_boot_ucode(Entry_blob): fdt_entry = self.section.FindEntryType('u-boot-dtb-with-ucode') if not fdt_entry: return True - if not fdt_entry.ucode_data: + if not fdt_entry.ready: return False if not fdt_entry.collate: diff --git a/tools/binman/etype/u_boot_with_ucode_ptr.py b/tools/binman/etype/u_boot_with_ucode_ptr.py index 86945f33184..8b1e41152e3 100644 --- a/tools/binman/etype/u_boot_with_ucode_ptr.py +++ b/tools/binman/etype/u_boot_with_ucode_ptr.py @@ -28,7 +28,7 @@ class Entry_u_boot_with_ucode_ptr(Entry_blob): def GetDefaultFilename(self): return 'u-boot-nodtb.bin' - def ObtainContents(self): + def ProcessFdt(self, fdt): # Figure out where to put the microcode pointer fname = tools.GetInputFilename(self.elf_fname) sym = elf.GetSymbolAddress(fname, '_dt_ucode_base_size') @@ -36,8 +36,7 @@ class Entry_u_boot_with_ucode_ptr(Entry_blob): self.target_pos = sym elif not fdt_util.GetBool(self._node, 'optional-ucode'): self.Raise('Cannot locate _dt_ucode_base_size symbol in u-boot') - - return Entry_blob.ObtainContents(self) + return True def ProcessContents(self): # If the image does not need microcode, there is nothing to do @@ -73,7 +72,7 @@ class Entry_u_boot_with_ucode_ptr(Entry_blob): pos, size = ucode_entry.pos, ucode_entry.size else: dtb_entry = self.section.FindEntryType('u-boot-dtb-with-ucode') - if not dtb_entry: + if not dtb_entry or not dtb_entry.ready: self.Raise('Cannot find microcode region u-boot-dtb-with-ucode') pos = dtb_entry.pos + dtb_entry.ucode_offset size = dtb_entry.ucode_size diff --git a/tools/binman/image.py b/tools/binman/image.py index 835b66c99f5..9732493709c 100644 --- a/tools/binman/image.py +++ b/tools/binman/image.py @@ -54,6 +54,9 @@ class Image: self._filename = filename self._section = bsection.Section('main-section', self._node) + def ProcessFdt(self, fdt): + return self._section.ProcessFdt(fdt) + def GetEntryContents(self): """Call ObtainContents() for the section """ From patchwork Wed Jun 6 00:47:04 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 925687 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" (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.b="jbFq33M1"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 410r2C1Hcfz9s02 for ; Wed, 6 Jun 2018 11:00:35 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id DE937C21F52; Wed, 6 Jun 2018 00:57:36 +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_DNSWL_BLOCKED, 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 9ABDBC21FD8; Wed, 6 Jun 2018 00:52:43 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 23CB2C21F22; Wed, 6 Jun 2018 00:48:32 +0000 (UTC) Received: from mail-it0-f48.google.com (mail-it0-f48.google.com [209.85.214.48]) by lists.denx.de (Postfix) with ESMTPS id 33D39C21F88 for ; Wed, 6 Jun 2018 00:48:26 +0000 (UTC) Received: by mail-it0-f48.google.com with SMTP id a195-v6so5906415itd.3 for ; Tue, 05 Jun 2018 17:48:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=6SYiQJUKodzHJEfAcvC4HyHZThY6W8pc5fEAUiLeIXo=; b=jbFq33M1Y8V/My8Ntrw9k+jNFNMk0SJlF645JsM2x82Z+773uLatGKrXzMIctxoPPt YcO6UPpXcgzBQXyvazbPKso51oFp51XIYQrNjwG/FBv9bvfkMIGynxWtPk2FAKcrU7Sd cuPK+D2xnaFte4dSHJCdoy/K3QwOMCJFg6/wT6nYnSa6ccxbtDgQ4SkUURStcpWMp3g9 dx7rfah76Nq8yWA3Wg+mUZvPbP5ZXeAfzRLZR4by8p8sGUIuokqKVvLeM5UJ3MhUaGyH caNkVBB9Lw1T+aN+g03EbkFFAuu1sji1+AKIILmY5QN5zArYG79VHUMgosLR8t7Mk/wl jJag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=6SYiQJUKodzHJEfAcvC4HyHZThY6W8pc5fEAUiLeIXo=; b=MBpghlzEj8a7isSBfvcwsTGkvF/MVdvaJbJ6YTH6wKHCaKbBlLc2Ez9CGgKPPaxnA3 nYKoH0vJovugGSHCqrNn/7O8HyHX7Sxz7OirMw3sSQW+4lfUYq8CHwx3rsS4aR56QfsV eHCRto0IOmuo3uFY8bXLnY3u53vhIDEvSeKgSold+NXJR/pgwAX2pGw7rf8TBmutQhUM yaHzuEXtfjVuJbEIniajAg4QMuQDBXXjyCgMHqPjIPHWgxhhU25q5+3hHpZkWPyscuVj oUONeIJUY7ACZcMXdlwsUWKAgoTMZ7L1/NDtMahfm84DPPj2/+zS1K8JmXjNvI4xnUqe xLtg== X-Gm-Message-State: APt69E08tYz6XUV9fcQ24RLdOFYkwGrX+TYtfvEgdrQbVejs37ZwE9nP oNTu1J4vC/AgTbGr73TBZE/lew== X-Google-Smtp-Source: ADUXVKJZ7M3CVXDgFb8EN7s9MbKD58TVPC7aUAacUfTsAvpvS+3KlIy2M0sq22HqkOliMU9JWu/ZEA== X-Received: by 2002:a24:b610:: with SMTP id g16-v6mr470273itf.13.1528246104583; Tue, 05 Jun 2018 17:48:24 -0700 (PDT) Received: from kiwi.bld.corp.google.com ([2620:15c:183:0:8223:87c:a681:66aa]) by smtp.gmail.com with ESMTPSA id e84-v6sm6025370ioi.32.2018.06.05.17.48.23 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 05 Jun 2018 17:48:23 -0700 (PDT) Received: by kiwi.bld.corp.google.com (Postfix, from userid 121222) id 57713140700; Tue, 5 Jun 2018 18:48:23 -0600 (MDT) From: Simon Glass To: U-Boot Mailing List Date: Tue, 5 Jun 2018 18:47:04 -0600 Message-Id: <20180606004705.79641-29-sjg@chromium.org> X-Mailer: git-send-email 2.17.1.1185.g55be947832-goog In-Reply-To: <20180606004705.79641-1-sjg@chromium.org> References: <20180606004705.79641-1-sjg@chromium.org> Cc: Tom Rini Subject: [U-Boot] [PATCH 28/29] binman: Add a SetCalculatedProperties() method 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" Once binman has packed the image, the position and size of each entry is known. It is then possible for binman to update the device tree with these positions. Since placeholder values have been added, this does not affect the size of the device tree and therefore the packing does not need to be performed again. Add a new SetCalculatedProperties method to handle this. Signed-off-by: Simon Glass --- tools/binman/README | 29 ++++++++++++++++++++--------- tools/binman/bsection.py | 8 ++++++++ tools/binman/cmdline.py | 2 ++ tools/binman/control.py | 4 ++++ tools/binman/entry.py | 11 +++++++++++ tools/binman/etype/section.py | 8 ++++++++ tools/binman/image.py | 14 ++++++++++++++ 7 files changed, 67 insertions(+), 9 deletions(-) diff --git a/tools/binman/README b/tools/binman/README index 008d5750528..8b598a75c80 100644 --- a/tools/binman/README +++ b/tools/binman/README @@ -462,14 +462,22 @@ Order of image creation Image creation proceeds in the following order, for each entry in the image. -1. ProcessFdt() - process the device tree information as required by the +1. AddMissingProperties() - binman can add calculated values to the device +tree as part of its processing, for example the position and size of each +entry. This method adds any properties associated with this, expanding the +device tree as needed. These properties can have placeholder values which are +set later by SetCalculatedProperties(). By that stage the size of sections +cannot be changed (since it would cause the images to need to be repacked), +but the correct values can be inserted. + +2. ProcessFdt() - process the device tree information as required by the particular entry. This may involve adding or deleting properties. If the processing is complete, this method should return True. If the processing cannot complete because it needs the ProcessFdt() method of another entry to run first, this method should return False, in which case it will be called again later. -2. GetEntryContents() - the contents of each entry are obtained, normally by +3. GetEntryContents() - the contents of each entry are obtained, normally by reading from a file. This calls the Entry.ObtainContents() to read the contents. The default version of Entry.ObtainContents() calls Entry.GetDefaultFilename() and then reads that file. So a common mechanism @@ -478,35 +486,38 @@ functions must return True when they have read the contents. Binman will retry calling the functions a few times if False is returned, allowing dependencies between the contents of different entries. -3. GetEntryPositions() - calls Entry.GetPositions() for each entry. This can +4. GetEntryPositions() - calls Entry.GetPositions() for each entry. This can return a dict containing entries that need updating. The key should be the entry name and the value is a tuple (pos, size). This allows an entry to provide the position and size for other entries. The default implementation of GetEntryPositions() returns {}. -4. PackEntries() - calls Entry.Pack() which figures out the position and +5. PackEntries() - calls Entry.Pack() which figures out the position and size of an entry. The 'current' image position is passed in, and the function returns the position immediately after the entry being packed. The default implementation of Pack() is usually sufficient. -5. CheckSize() - checks that the contents of all the entries fits within +6. CheckSize() - checks that the contents of all the entries fits within the image size. If the image does not have a defined size, the size is set large enough to hold all the entries. -6. CheckEntries() - checks that the entries do not overlap, nor extend +7. CheckEntries() - checks that the entries do not overlap, nor extend outside the image. -7. ProcessEntryContents() - this calls Entry.ProcessContents() on each entry. +8. SetCalculatedProperties() - update any calculated properties in the device +tree. This sets the correct 'pos' and 'size' vaues, for example. + +9. ProcessEntryContents() - this calls Entry.ProcessContents() on each entry. The default implementatoin does nothing. This can be overriden to adjust the contents of an entry in some way. For example, it would be possible to create an entry containing a hash of the contents of some other entries. At this stage the position and size of entries should not be adjusted. -8. WriteSymbols() - write the value of symbols into the U-Boot SPL binary. +10. WriteSymbols() - write the value of symbols into the U-Boot SPL binary. See 'Access to binman entry positions at run time' below for a description of what happens in this stage. -9. BuildImage() - builds the image and writes it to a file. This is the final +11. BuildImage() - builds the image and writes it to a file. This is the final step. diff --git a/tools/binman/bsection.py b/tools/binman/bsection.py index 3ed361d69a2..de439ef625f 100644 --- a/tools/binman/bsection.py +++ b/tools/binman/bsection.py @@ -90,6 +90,14 @@ class Section(object): entry.SetPrefix(self._name_prefix) self._entries[node.name] = entry + def AddMissingProperties(self): + for entry in self._entries.values(): + entry.AddMissingProperties() + + def SetCalculatedProperties(self): + for entry in self._entries.values(): + entry.SetCalculatedProperties() + def ProcessFdt(self, fdt): todo = self._entries.values() for passnum in range(3): diff --git a/tools/binman/cmdline.py b/tools/binman/cmdline.py index bf63919eb79..ae2d1670f9a 100644 --- a/tools/binman/cmdline.py +++ b/tools/binman/cmdline.py @@ -42,6 +42,8 @@ def ParseArgs(argv): default=False, help='run tests') parser.add_option('-T', '--test-coverage', action='store_true', default=False, help='run tests and check for 100% coverage') + parser.add_option('-u', '--update-fdt', action='store_true', + default=False, help='Update the binman node with position/size info') parser.add_option('-v', '--verbosity', default=1, type='int', help='Control verbosity: 0=silent, 1=progress, 3=full, ' '4=debug') diff --git a/tools/binman/control.py b/tools/binman/control.py index 5325a6a0066..eafabf05c7c 100644 --- a/tools/binman/control.py +++ b/tools/binman/control.py @@ -144,6 +144,8 @@ def Binman(options, args): # without changing the device-tree size, thus ensuring that our # entry positions remain the same. for image in images.values(): + if options.update_fdt: + image.AddMissingProperties() image.ProcessFdt(dtb) dtb.Pack() @@ -159,6 +161,8 @@ def Binman(options, args): image.PackEntries() image.CheckSize() image.CheckEntries() + if options.update_fdt: + image.SetCalculatedProperties() image.ProcessEntryContents() image.WriteSymbols() image.BuildImage() diff --git a/tools/binman/entry.py b/tools/binman/entry.py index 62e65c91266..6a173e663d0 100644 --- a/tools/binman/entry.py +++ b/tools/binman/entry.py @@ -130,6 +130,17 @@ class Entry(object): self.align_end = fdt_util.GetInt(self._node, 'align-end') self.pos_unset = fdt_util.GetBool(self._node, 'pos-unset') + def AddMissingProperties(self): + """Add new properties to the device tree as needed for this entry""" + for prop in ['pos', 'size']: + if not prop in self._node.props: + self._node.AddZeroProp(prop) + + def SetCalculatedProperties(self): + """Set the value of device-tree properties calculated by binman""" + self._node.SetInt('pos', self.pos) + self._node.SetInt('size', self.size) + def ProcessFdt(self, fdt): return True diff --git a/tools/binman/etype/section.py b/tools/binman/etype/section.py index 9b38738d38d..787257d3ec1 100644 --- a/tools/binman/etype/section.py +++ b/tools/binman/etype/section.py @@ -20,6 +20,10 @@ class Entry_section(Entry): def ProcessFdt(self, fdt): return self._section.ProcessFdt(fdt) + def AddMissingProperties(self): + Entry.AddMissingProperties(self) + self._section.AddMissingProperties() + def ObtainContents(self): return self._section.GetEntryContents() @@ -45,6 +49,10 @@ class Entry_section(Entry): """Write symbol values into binary files for access at run time""" self._section.WriteSymbols() + def SetCalculatedProperties(self): + Entry.SetCalculatedProperties(self) + self._section.SetCalculatedProperties() + def ProcessContents(self): self._section.ProcessEntryContents() super(Entry_section, self).ProcessContents() diff --git a/tools/binman/image.py b/tools/binman/image.py index 9732493709c..94028f19a51 100644 --- a/tools/binman/image.py +++ b/tools/binman/image.py @@ -54,6 +54,17 @@ class Image: self._filename = filename self._section = bsection.Section('main-section', self._node) + def AddMissingProperties(self): + """Add properties that are not present in the device tree + + When binman has completed packing the entries the position and size of + each entry are known. But before this the device tree may not specify + these. Add any missing properties, with a dummy value, so that the + size of the entry is correct. That way we can insert the correct values + later. + """ + self._section.AddMissingProperties() + def ProcessFdt(self, fdt): return self._section.ProcessFdt(fdt) @@ -82,6 +93,9 @@ class Image: """Check that entries do not overlap or extend outside the image""" self._section.CheckEntries() + def SetCalculatedProperties(self): + self._section.SetCalculatedProperties() + def ProcessEntryContents(self): """Call the ProcessContents() method for each entry From patchwork Wed Jun 6 00:47:05 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 925693 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" (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.b="ahLk1PsH"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 410r4z5LdRz9s02 for ; Wed, 6 Jun 2018 11:02:59 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 67AD5C21EBA; Wed, 6 Jun 2018 00:56: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=RCVD_IN_DNSWL_BLOCKED, 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 BEF92C21F2A; Wed, 6 Jun 2018 00:51:46 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 26491C21F27; Wed, 6 Jun 2018 00:48:33 +0000 (UTC) Received: from mail-it0-f68.google.com (mail-it0-f68.google.com [209.85.214.68]) by lists.denx.de (Postfix) with ESMTPS id 38994C21F52 for ; Wed, 6 Jun 2018 00:48:28 +0000 (UTC) Received: by mail-it0-f68.google.com with SMTP id u4-v6so5931061itg.0 for ; Tue, 05 Jun 2018 17:48:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=9Ng9azKyqh4Ma8o7xtXL2WZ7HBqzwz5izZtPmEfECWc=; b=ahLk1PsHApQfegr6tQRQdny3LTIwNzn40pCHyp7EWbeP7YFfrkS0qp6rZfUzJuQaUG DLnhQkJQtEFqNsDnSVQ4w3t0jNsT2nz2k3DDwDy6OVQMCyoTR+0+SYCBPrhl9uyp4KDU 1PoRMXxPXoSlB/EwDfh+6dApAQm7Lqv3aNlQ5qa5wU5jIS63ljH1wzBV67pIs/6LQmvO C5i8UUrYCQJeUPIomAruGT34iQI09sBfFAdxOmnL7dIqKbdUOcaswLxH40Gcb4jyhh7s zMM9FxD1NgraJhJTf4UWoigc2uYQukjvwHyOkDO/cIU0IIQUDHinNPRlgMXdBVeH21/A Pgfw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=9Ng9azKyqh4Ma8o7xtXL2WZ7HBqzwz5izZtPmEfECWc=; b=qE2n0Y2oybT9++Xa1Eb8f+hC9YSPiw3hUIp1Fa/iPa9nNYAos936PcSmsZJM8+CTAJ LkBRNheIjLe4aL2q3mcA9aQGuxo099/1nDTKoFfdv8zAaAvVKrW+4EmYbF0VT/wvHtt5 yBuE6H6NlThMCPWXL5WdwwAhrfRMO2keFrPIHTrPJXtD1rrV7Zr/RjWmBNpdLRDSydVh mdEklIpyZ3/FUeSTM6q2qQZL69LP84+VRVKNVH3ypTeMnJdLsOAWs8Myz5ivsIl/WgIY gdXezOhWCbK3nafUF3tt4GgypGAQskJbeVJrrKfbH7efoNYWwxJILHqZsSZDNpu9v4zm H90w== X-Gm-Message-State: APt69E1Zuc5rle/FkiVkoUQ80sAONYA5lHcDR0kivcQyDgByTXuBUybU dT1lww/5YUdVBlgYp8KUyGZBJw== X-Google-Smtp-Source: ADUXVKIBBU59NkDP8OWRSYmy39mFOe47XAFwNU0COAG7kDfzs4ZN5wr5MEpIKGnlSMw16U2urx0xdQ== X-Received: by 2002:a24:b914:: with SMTP id w20-v6mr496207ite.35.1528246106622; Tue, 05 Jun 2018 17:48:26 -0700 (PDT) Received: from kiwi.bld.corp.google.com ([2620:15c:183:0:8223:87c:a681:66aa]) by smtp.gmail.com with ESMTPSA id y33-v6sm1321420ita.24.2018.06.05.17.48.25 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 05 Jun 2018 17:48:25 -0700 (PDT) Received: by kiwi.bld.corp.google.com (Postfix, from userid 121222) id 99689140700; Tue, 5 Jun 2018 18:48:25 -0600 (MDT) From: Simon Glass To: U-Boot Mailing List Date: Tue, 5 Jun 2018 18:47:05 -0600 Message-Id: <20180606004705.79641-30-sjg@chromium.org> X-Mailer: git-send-email 2.17.1.1185.g55be947832-goog In-Reply-To: <20180606004705.79641-1-sjg@chromium.org> References: <20180606004705.79641-1-sjg@chromium.org> Cc: Tom Rini Subject: [U-Boot] [PATCH 29/29] binman: Support updating the device tree with calc'd info 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" It is useful to write the position and size of each entry back to the device tree so that U-Boot can access this at runtime. Add a feature to support this, along with associated tests. Signed-off-by: Simon Glass --- tools/binman/README | 6 +-- tools/binman/control.py | 2 + tools/binman/ftest.py | 69 ++++++++++++++++++++++++----- tools/binman/test/60_fdt_update.dts | 28 ++++++++++++ 4 files changed, 91 insertions(+), 14 deletions(-) create mode 100644 tools/binman/test/60_fdt_update.dts diff --git a/tools/binman/README b/tools/binman/README index 8b598a75c80..207928aa955 100644 --- a/tools/binman/README +++ b/tools/binman/README @@ -669,13 +669,11 @@ To do ----- Some ideas: -- Fill out the device tree to include the final position and size of each - entry (since the input file may not always specify these). See also - 'Access to binman entry positions at run time' above - Use of-platdata to make the information available to code that is unable to use device tree (such as a very small SPL image) - Allow easy building of images by specifying just the board name -- Produce a full Python binding for libfdt (for upstream) +- Produce a full Python binding for libfdt (for upstream). This is nearing + completion but some work remains - Add an option to decode an image into the constituent binaries - Support building an image for a board (-b) more completely, with a configurable build directory diff --git a/tools/binman/control.py b/tools/binman/control.py index eafabf05c7c..a40b300fdac 100644 --- a/tools/binman/control.py +++ b/tools/binman/control.py @@ -168,6 +168,8 @@ def Binman(options, args): image.BuildImage() if options.map: image.WriteMap() + with open(fname, 'wb') as outfd: + outfd.write(dtb.GetContents()) finally: tools.FinaliseOutputDir() finally: diff --git a/tools/binman/ftest.py b/tools/binman/ftest.py index af3b4dc3e56..b49b1b9b734 100644 --- a/tools/binman/ftest.py +++ b/tools/binman/ftest.py @@ -146,19 +146,23 @@ class TestFunctional(unittest.TestCase): # options.verbosity = tout.DEBUG return control.Binman(options, args) - def _DoTestFile(self, fname, debug=False, map=False): + def _DoTestFile(self, fname, debug=False, map=False, update_dtb=False): """Run binman with a given test file Args: fname: Device-tree source filename to use (e.g. 05_simple.dts) debug: True to enable debugging output map: True to output map files for the images + update_dtb: Update the position and size of each entry in the device + tree before packing it into the image """ args = ['-p', '-I', self._indir, '-d', self.TestFile(fname)] if debug: args.append('-D') if map: args.append('-m') + if update_dtb: + args.append('-up') return self._DoBinman(*args) def _SetupDtb(self, fname, outfile='u-boot.dtb'): @@ -183,7 +187,8 @@ class TestFunctional(unittest.TestCase): TestFunctional._MakeInputFile(outfile, data) return data - def _DoReadFileDtb(self, fname, use_real_dtb=False, map=False): + def _DoReadFileDtb(self, fname, use_real_dtb=False, map=False, + update_dtb=False): """Run binman and return the resulting image This runs binman with a given test file and then reads the resulting @@ -199,6 +204,8 @@ class TestFunctional(unittest.TestCase): test contents (the U_BOOT_DTB_DATA string) can be used. But in some test we need the real contents. map: True to output map files for the images + update_dtb: Update the position and size of each entry in the device + tree before packing it into the image Returns: Tuple: @@ -212,21 +219,22 @@ class TestFunctional(unittest.TestCase): dtb_data = self._SetupDtb(fname) try: - retcode = self._DoTestFile(fname, map=map) + retcode = self._DoTestFile(fname, map=map, update_dtb=update_dtb) self.assertEqual(0, retcode) + out_dtb_fname = control.GetFdtPath('u-boot.dtb') # Find the (only) image, read it and return its contents image = control.images['image'] - fname = tools.GetOutputFilename('image.bin') - self.assertTrue(os.path.exists(fname)) + image_fname = tools.GetOutputFilename('image.bin') + self.assertTrue(os.path.exists(image_fname)) if map: map_fname = tools.GetOutputFilename('image.map') with open(map_fname) as fd: map_data = fd.read() else: map_data = None - with open(fname) as fd: - return fd.read(), dtb_data, map_data + with open(image_fname) as fd: + return fd.read(), dtb_data, map_data, out_dtb_fname finally: # Put the test file back if use_real_dtb: @@ -300,6 +308,26 @@ class TestFunctional(unittest.TestCase): """ return struct.unpack('>L', dtb[4:8])[0] + def _GetPropTree(self, dtb_data, node_names): + def AddNode(node, path): + if node.name != '/': + path += '/' + node.name + #print 'path', path + for subnode in node.subnodes: + for prop in subnode.props.values(): + if prop.name in node_names: + prop_path = path + '/' + subnode.name + ':' + prop.name + tree[prop_path[len('/binman/'):]] = fdt_util.fdt32_to_cpu( + prop.value) + #print ' ', prop.name + AddNode(subnode, path) + + tree = {} + dtb = fdt.Fdt(dtb_data) + dtb.Scan() + AddNode(dtb.GetRoot(), '') + return tree + def testRun(self): """Test a basic run with valid args""" result = self._RunBinman('-h') @@ -845,7 +873,7 @@ class TestFunctional(unittest.TestCase): """Test that we can cope with an image without microcode (e.g. qemu)""" with open(self.TestFile('u_boot_no_ucode_ptr')) as fd: TestFunctional._MakeInputFile('u-boot', fd.read()) - data, dtb, _ = self._DoReadFileDtb('44_x86_optional_ucode.dts', True) + data, dtb, _, _ = self._DoReadFileDtb('44_x86_optional_ucode.dts', True) # Now check the device tree has no microcode self.assertEqual(U_BOOT_NODTB_DATA, data[:len(U_BOOT_NODTB_DATA)]) @@ -980,7 +1008,7 @@ class TestFunctional(unittest.TestCase): def testMap(self): """Tests outputting a map of the images""" - _, _, map_data = self._DoReadFileDtb('55_sections.dts', map=True) + _, _, map_data, _ = self._DoReadFileDtb('55_sections.dts', map=True) self.assertEqual('''Position Size Name 00000000 00000010 section@0 00000000 00000004 u-boot @@ -990,7 +1018,7 @@ class TestFunctional(unittest.TestCase): def testNamePrefix(self): """Tests that name prefixes are used""" - _, _, map_data = self._DoReadFileDtb('56_name_prefix.dts', map=True) + _, _, map_data, _ = self._DoReadFileDtb('56_name_prefix.dts', map=True) self.assertEqual('''Position Size Name 00000000 00000010 section@0 00000000 00000004 ro-u-boot @@ -1013,6 +1041,27 @@ class TestFunctional(unittest.TestCase): self.assertIn("Node '/binman/_testing': Cannot update entry size from " '2 to 1', str(e.exception)) + def testUpdateFdt(self): + """Test that we can update the device tree with pos/size info""" + _, _, _, out_dtb_fname = self._DoReadFileDtb('60_fdt_update.dts', + update_dtb=True) + props = self._GetPropTree(out_dtb_fname, ['pos', 'size']) + with open('/tmp/x.dtb', 'wb') as outf: + with open(out_dtb_fname) as inf: + outf.write(inf.read()) + self.assertEqual({ + 'section@0/u-boot:pos': 0, + 'section@0/u-boot:size': len(U_BOOT_DATA), + 'section@0:pos': 0, + 'section@0:size': 16, + + 'section@1/u-boot:pos': 0, + 'section@1/u-boot:size': len(U_BOOT_DATA), + 'section@1:pos': 16, + 'section@1:size': 16, + 'size': 40 + }, props) + if __name__ == "__main__": unittest.main() diff --git a/tools/binman/test/60_fdt_update.dts b/tools/binman/test/60_fdt_update.dts new file mode 100644 index 00000000000..28e483fd7b5 --- /dev/null +++ b/tools/binman/test/60_fdt_update.dts @@ -0,0 +1,28 @@ +/dts-v1/; + +/ { + #address-cells = <1>; + #size-cells = <1>; + + binman { + pad-byte = <0x26>; + size = <0x28>; + section@0 { + read-only; + name-prefix = "ro-"; + size = <0x10>; + pad-byte = <0x21>; + + u-boot { + }; + }; + section@1 { + name-prefix = "rw-"; + size = <0x10>; + pad-byte = <0x61>; + + u-boot { + }; + }; + }; +};