summaryrefslogtreecommitdiff
path: root/test/py
diff options
context:
space:
mode:
authorTom Rini <trini@konsulko.com>2023-04-03 16:45:41 -0400
committerTom Rini <trini@konsulko.com>2023-04-03 16:45:41 -0400
commit288fe30a2367b8d0e3f416493150a38ebaa88459 (patch)
tree1f841eb95d9ceeda4aa3255fb1132a0342f9b19a /test/py
parentfd4ed6b7e83ec3aea9a2ce21baea8ca9676f40dd (diff)
parent9876c8c147144db2c120fcc9ffa6de27f6894441 (diff)
Merge branch 'next'
Signed-off-by: Tom Rini <trini@konsulko.com>
Diffstat (limited to 'test/py')
-rw-r--r--test/py/multiplexed_log.py5
-rw-r--r--test/py/requirements.txt1
-rw-r--r--test/py/tests/test_fs/test_ext.py36
-rw-r--r--test/py/tests/test_of_migrate.py108
-rw-r--r--test/py/tests/test_ofplatdata.py8
-rw-r--r--test/py/tests/test_vbe_vpl.py6
-rw-r--r--test/py/tests/test_vboot.py186
-rw-r--r--test/py/u_boot_utils.py5
8 files changed, 307 insertions, 48 deletions
diff --git a/test/py/multiplexed_log.py b/test/py/multiplexed_log.py
index 5e79075f2e6..63237594bb4 100644
--- a/test/py/multiplexed_log.py
+++ b/test/py/multiplexed_log.py
@@ -111,7 +111,7 @@ class RunAndLog(object):
"""Clean up any resources managed by this object."""
pass
- def run(self, cmd, cwd=None, ignore_errors=False, stdin=None):
+ def run(self, cmd, cwd=None, ignore_errors=False, stdin=None, env=None):
"""Run a command as a sub-process, and log the results.
The output is available at self.output which can be useful if there is
@@ -126,6 +126,7 @@ class RunAndLog(object):
or exits with an error code, otherwise an exception will be
raised if such problems occur.
stdin: Input string to pass to the command as stdin (or None)
+ env: Environment to use, or None to use the current one
Returns:
The output as a string.
@@ -139,7 +140,7 @@ class RunAndLog(object):
try:
p = subprocess.Popen(cmd, cwd=cwd,
stdin=subprocess.PIPE if stdin else None,
- stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
+ stdout=subprocess.PIPE, stderr=subprocess.STDOUT, env=env)
(stdout, stderr) = p.communicate(input=stdin)
if stdout is not None:
stdout = stdout.decode('utf-8')
diff --git a/test/py/requirements.txt b/test/py/requirements.txt
index fae8b59caf4..e241780f923 100644
--- a/test/py/requirements.txt
+++ b/test/py/requirements.txt
@@ -1,5 +1,6 @@
atomicwrites==1.4.1
attrs==19.3.0
+concurrencytest==0.1.2
coverage==4.5.4
extras==1.0.0
filelock==3.0.12
diff --git a/test/py/tests/test_fs/test_ext.py b/test/py/tests/test_fs/test_ext.py
index dba874fc59c..05fefa53a0e 100644
--- a/test/py/tests/test_fs/test_ext.py
+++ b/test/py/tests/test_fs/test_ext.py
@@ -8,11 +8,24 @@
This test verifies extended write operation on file system.
"""
+import os.path
import pytest
import re
+from subprocess import check_output
from fstest_defs import *
from fstest_helpers import assert_fs_integrity
+PLAIN_FILE='abcdefgh.txt'
+MANGLE_FILE='abcdefghi.txt'
+
+def str2fat(long_filename):
+ splitext = os.path.splitext(long_filename.upper())
+ name = splitext[0]
+ ext = splitext[1][1:]
+ if len(name) > 8:
+ name = '%s~1' % name[:6]
+ return '%-8s %s' % (name, ext)
+
@pytest.mark.boardspec('sandbox')
@pytest.mark.slow
class TestFsExt(object):
@@ -317,3 +330,26 @@ class TestFsExt(object):
assert('FILE0123456789_79' in output)
assert_fs_integrity(fs_type, fs_img)
+
+ def test_fs_ext12(self, u_boot_console, fs_obj_ext):
+ """
+ Test Case 12 - write plain and mangle file
+ """
+ fs_type,fs_img,md5val = fs_obj_ext
+ with u_boot_console.log.section('Test Case 12 - write plain and mangle file'):
+ # Test Case 12a - Check if command successfully returned
+ output = u_boot_console.run_command_list([
+ 'host bind 0 %s' % fs_img,
+ '%swrite host 0:0 %x /%s 0'
+ % (fs_type, ADDR, PLAIN_FILE),
+ '%swrite host 0:0 %x /%s 0'
+ % (fs_type, ADDR, MANGLE_FILE)])
+ assert('0 bytes written' in ''.join(output))
+ # Test Case 12b - Read file system content
+ output = check_output('mdir -i %s' % fs_img, shell=True).decode()
+ # Test Case 12c - Check if short filename is not mangled
+ assert(str2fat(PLAIN_FILE) in ''.join(output))
+ # Test Case 12d - Check if long filename is mangled
+ assert(str2fat(MANGLE_FILE) in ''.join(output))
+
+ assert_fs_integrity(fs_type, fs_img)
diff --git a/test/py/tests/test_of_migrate.py b/test/py/tests/test_of_migrate.py
new file mode 100644
index 00000000000..910f7c05510
--- /dev/null
+++ b/test/py/tests/test_of_migrate.py
@@ -0,0 +1,108 @@
+# SPDX-License-Identifier: GPL-2.0
+# Copyright 2023 Google LLC
+# Written by Simon Glass <sjg@chromium.org>
+
+"""Test handling of unmigrated u-boot,dm- tags"""
+
+import os
+import pytest
+
+import u_boot_utils as util
+
+# This is needed for Azure, since the default '..' directory is not writeable
+TMPDIR1 = '/tmp/test_no_migrate'
+TMPDIR2 = '/tmp/test_no_migrate_spl'
+TMPDIR3 = '/tmp/test_migrate'
+
+def build_for_migrate(cons, replace_pair, board, tmpdir, disable_migrate=True):
+ """Build an updated U-Boot with a slightly modified device tree
+
+ Args:
+ cons (ConsoleBase): U-Boot console
+ replace_pair (tuple):
+ String to find
+ String to replace it with
+ board (str): Board to build
+ tmpdir (str): Temporary directory to use
+ disable_migrate (bool): True to disable CONFIG_OF_TAG_MIGRATE in build
+ """
+ srcdir = cons.config.source_dir
+ build_dir = cons.config.build_dir
+
+ # Get the source for the existing dts
+ dt_dir = os.path.join(build_dir, 'arch', 'sandbox', 'dts')
+ orig_fname = os.path.join(dt_dir, 'sandbox.dtb')
+ out_dts = os.path.join(dt_dir, 'sandbox_out.dts')
+ util.run_and_log(cons, ['dtc', orig_fname, '-I', 'dtb', '-O', 'dts',
+ '-o', out_dts])
+
+ # Update it to use an old tag
+ with open(out_dts) as inf:
+ data = inf.read()
+ data = data.replace(*replace_pair)
+
+ dts_fname = os.path.join(dt_dir, 'sandbox_oldtag.dts')
+ with open(dts_fname, 'w') as outf:
+ print(data, file=outf)
+ dtb_fname = os.path.join(dt_dir, 'sandbox_oldtag.dtb')
+ util.run_and_log(cons, ['dtc', dts_fname, '-o', dtb_fname])
+
+ migrate = ['-a', '~CONFIG_OF_TAG_MIGRATE'] if disable_migrate else []
+
+ # Build sandbox with this new dtb, turning off OF_TAG_MIGRATE
+ env = dict(os.environ)
+ env['EXT_DTB'] = dtb_fname
+ env['DEVICE_TREE'] = 'sandbox_new'
+ env['NO_LTO'] = '1' # Speed up build
+ out = util.run_and_log(
+ cons, ['./tools/buildman/buildman', '-m', '--board', board,
+ *migrate, '-w', '-o', tmpdir], ignore_errors=True, env=env)
+ return out
+
+@pytest.mark.slow
+@pytest.mark.boardspec('sandbox')
+def test_of_no_migrate(u_boot_console):
+ """Test sandbox with old boot phase tags like u-boot,dm-pre-proper"""
+ cons = u_boot_console
+
+ build_for_migrate(cons, ['bootph-some-ram', 'u-boot,dm-pre-proper'],
+ 'sandbox', TMPDIR1)
+
+ # It should fail to run, since the lcd device will not be bound before
+ # relocation. so won't get its frame-buffer memory
+ out = util.run_and_log(
+ cons, [os.path.join(TMPDIR1, 'u-boot'), '-D', '-c', 'help'],
+ ignore_errors=True)
+ assert "Video device 'lcd' cannot allocate frame buffer memory" in out
+
+
+@pytest.mark.slow
+@pytest.mark.boardspec('sandbox_spl')
+@pytest.mark.boardspec('spl_of_platdata_inst')
+@pytest.mark.boardspec('!sandbox_tpl')
+def test_of_no_migrate_spl(u_boot_console):
+ """Test sandbox with old boot phase tags like u-boot,dm-spl"""
+ cons = u_boot_console
+
+ out = build_for_migrate(cons, ['bootph-pre-ram', 'u-boot,dm-spl'],
+ 'sandbox_spl', TMPDIR2)
+
+ # It should fail to build, since the SPL DT will not include 'spl-test'
+ # node, among others
+ assert "undefined type ‘struct dtd_sandbox_spl_test’" in out
+
+
+@pytest.mark.slow
+@pytest.mark.boardspec('sandbox')
+def test_of_migrate(u_boot_console):
+ """Test sandbox shows a message when tags were migrated"""
+ cons = u_boot_console
+
+ build_for_migrate(cons, ['bootph-some-ram', 'u-boot,dm-pre-proper'],
+ 'sandbox', TMPDIR3, disable_migrate=False)
+
+ # It should show a migration message
+ out = util.run_and_log(
+ cons, [os.path.join(TMPDIR3, 'u-boot'), '-D', '-c', 'help'],
+ ignore_errors=True)
+ assert "Warning: Device tree includes old 'u-boot,dm-' tags" in out
diff --git a/test/py/tests/test_ofplatdata.py b/test/py/tests/test_ofplatdata.py
index e9cce4daf48..51a188454f3 100644
--- a/test/py/tests/test_ofplatdata.py
+++ b/test/py/tests/test_ofplatdata.py
@@ -13,10 +13,10 @@ def test_spl_devicetree(u_boot_console):
fdtgrep = cons.config.build_dir + '/tools/fdtgrep'
output = util.run_and_log(cons, [fdtgrep, '-l', dtb])
- assert "u-boot,dm-pre-reloc" not in output
- assert "u-boot,dm-pre-proper" not in output
- assert "u-boot,dm-spl" not in output
- assert "u-boot,dm-tpl" not in output
+ assert "bootph-all" not in output
+ assert "bootph-some-ram" not in output
+ assert "bootph-pre-ram" not in output
+ assert "bootph-pre-sram" not in output
assert "spl-test5" not in output
assert "spl-test6" not in output
diff --git a/test/py/tests/test_vbe_vpl.py b/test/py/tests/test_vbe_vpl.py
index d1c9d0548ae..ed12d3a4618 100644
--- a/test/py/tests/test_vbe_vpl.py
+++ b/test/py/tests/test_vbe_vpl.py
@@ -15,6 +15,7 @@ def test_vbe_vpl(u_boot_console):
#cmd = [cons.config.build_dir + fname, '-v']
ram = os.path.join(cons.config.build_dir, 'ram.bin')
fdt = os.path.join(cons.config.build_dir, 'arch/sandbox/dts/test.dtb')
+ image_fname = os.path.join(cons.config.build_dir, 'image.bin')
# Enable firmware1 and the mmc that it uses. These are needed for the full
# VBE flow.
@@ -24,12 +25,13 @@ def test_vbe_vpl(u_boot_console):
cons, f'fdtput -t s {fdt} /bootstd/firmware1 status okay')
u_boot_utils.run_and_log(
cons, f'fdtput -t s {fdt} /mmc3 status okay')
+ u_boot_utils.run_and_log(
+ cons, f'fdtput -t s {fdt} /mmc3 filename {image_fname}')
# Remove any existing RAM file, so we don't have old data present
if os.path.exists(ram):
os.remove(ram)
- flags = ['-p', os.path.join(cons.config.build_dir, 'image.bin'), '-w',
- '-s', 'state.dtb']
+ flags = ['-p', image_fname, '-w', '-s', 'state.dtb']
cons.restart_uboot_with_flags(flags)
# Make sure that VBE was used in both VPL (to load SPL) and SPL (to load
diff --git a/test/py/tests/test_vboot.py b/test/py/tests/test_vboot.py
index e3e7ca4b215..04fa59f98b0 100644
--- a/test/py/tests/test_vboot.py
+++ b/test/py/tests/test_vboot.py
@@ -30,6 +30,12 @@ For pre-load header verification:
- Check that image verification fails
Tests run with both SHA1 and SHA256 hashing.
+
+This also tests fdt_add_pubkey utility in the simple way:
+- Create DTB and FIT files
+- Add keys with fdt_add_pubkey to DTB
+- Sign FIT image
+- Check with fit_check_sign that keys properly added to DTB file
"""
import os
@@ -40,6 +46,41 @@ import u_boot_utils as util
import vboot_forge
import vboot_evil
+# Common helper functions
+def dtc(dts, cons, dtc_args, datadir, tmpdir, dtb):
+ """Run the device tree compiler to compile a .dts file
+
+ The output file will be the same as the input file but with a .dtb
+ extension.
+
+ Args:
+ dts: Device tree file to compile.
+ cons: U-Boot console.
+ dtc_args: DTC arguments.
+ datadir: Path to data directory.
+ tmpdir: Path to temp directory.
+ dtb: Resulting DTB file.
+ """
+ dtb = dts.replace('.dts', '.dtb')
+ util.run_and_log(cons, 'dtc %s %s%s -O dtb '
+ '-o %s%s' % (dtc_args, datadir, dts, tmpdir, dtb))
+
+def make_fit(its, cons, mkimage, dtc_args, datadir, fit):
+ """Make a new FIT from the .its source file.
+
+ This runs 'mkimage -f' to create a new FIT.
+
+ Args:
+ its: Filename containing .its source.
+ cons: U-Boot console.
+ mkimage: Path to mkimage utility.
+ dtc_args: DTC arguments.
+ datadir: Path to data directory.
+ fit: Resulting FIT file.
+ """
+ util.run_and_log(cons, [mkimage, '-D', dtc_args, '-f',
+ '%s%s' % (datadir, its), fit])
+
# Only run the full suite on a few combinations, since it doesn't add any more
# test coverage.
TESTDATA_IN = [
@@ -82,19 +123,6 @@ def test_vboot(u_boot_console, name, sha_algo, padding, sign_options, required,
The SHA1 and SHA256 tests are combined into a single test since the
key-generation process is quite slow and we want to avoid doing it twice.
"""
- def dtc(dts):
- """Run the device tree compiler to compile a .dts file
-
- The output file will be the same as the input file but with a .dtb
- extension.
-
- Args:
- dts: Device tree file to compile.
- """
- dtb = dts.replace('.dts', '.dtb')
- util.run_and_log(cons, 'dtc %s %s%s -O dtb '
- '-o %s%s' % (dtc_args, datadir, dts, tmpdir, dtb))
-
def dtc_options(dts, options):
"""Run the device tree compiler to compile a .dts file
@@ -152,17 +180,6 @@ def test_vboot(u_boot_console, name, sha_algo, padding, sign_options, required,
assert('sandbox: continuing, as we cannot run'
not in ''.join(output))
- def make_fit(its):
- """Make a new FIT from the .its source file.
-
- This runs 'mkimage -f' to create a new FIT.
-
- Args:
- its: Filename containing .its source.
- """
- util.run_and_log(cons, [mkimage, '-D', dtc_args, '-f',
- '%s%s' % (datadir, its), fit])
-
def sign_fit(sha_algo, options):
"""Sign the FIT
@@ -286,12 +303,12 @@ def test_vboot(u_boot_console, name, sha_algo, padding, sign_options, required,
# Compile our device tree files for kernel and U-Boot. These are
# regenerated here since mkimage will modify them (by adding a
# public key) below.
- dtc('sandbox-kernel.dts')
- dtc('sandbox-u-boot.dts')
+ dtc('sandbox-kernel.dts', cons, dtc_args, datadir, tmpdir, dtb)
+ dtc('sandbox-u-boot.dts', cons, dtc_args, datadir, tmpdir, dtb)
# Build the FIT, but don't sign anything yet
cons.log.action('%s: Test FIT with signed images' % sha_algo)
- make_fit('sign-images-%s%s.its' % (sha_algo, padding))
+ make_fit('sign-images-%s%s.its' % (sha_algo, padding), cons, mkimage, dtc_args, datadir, fit)
run_bootm(sha_algo, 'unsigned images', ' - OK' if algo_arg else 'dev-', True)
# Sign images with our dev keys
@@ -299,10 +316,10 @@ def test_vboot(u_boot_console, name, sha_algo, padding, sign_options, required,
run_bootm(sha_algo, 'signed images', 'dev+', True)
# Create a fresh .dtb without the public keys
- dtc('sandbox-u-boot.dts')
+ dtc('sandbox-u-boot.dts', cons, dtc_args, datadir, tmpdir, dtb)
cons.log.action('%s: Test FIT with signed configuration' % sha_algo)
- make_fit('sign-configs-%s%s.its' % (sha_algo, padding))
+ make_fit('sign-configs-%s%s.its' % (sha_algo, padding), cons, mkimage, dtc_args, datadir, fit)
run_bootm(sha_algo, 'unsigned config', '%s+ OK' % ('sha256' if algo_arg else sha_algo), True)
# Sign images with our dev keys
@@ -352,7 +369,7 @@ def test_vboot(u_boot_console, name, sha_algo, padding, sign_options, required,
run_bootm(sha_algo, 'evil kernel@', msg, False, efit)
# Create a new properly signed fit and replace header bytes
- make_fit('sign-configs-%s%s.its' % (sha_algo, padding))
+ make_fit('sign-configs-%s%s.its' % (sha_algo, padding), cons, mkimage, dtc_args, datadir, fit)
sign_fit(sha_algo, sign_options)
bcfg = u_boot_console.config.buildconfig
max_size = int(bcfg.get('config_fit_signature_max_size', 0x10000000), 0)
@@ -399,19 +416,19 @@ def test_vboot(u_boot_console, name, sha_algo, padding, sign_options, required,
# Compile our device tree files for kernel and U-Boot. These are
# regenerated here since mkimage will modify them (by adding a
# public key) below.
- dtc('sandbox-kernel.dts')
- dtc('sandbox-u-boot.dts')
+ dtc('sandbox-kernel.dts', cons, dtc_args, datadir, tmpdir, dtb)
+ dtc('sandbox-u-boot.dts', cons, dtc_args, datadir, tmpdir, dtb)
cons.log.action('%s: Test FIT with configs images' % sha_algo)
# Build the FIT with prod key (keys required) and sign it. This puts the
# signature into sandbox-u-boot.dtb, marked 'required'
- make_fit('sign-configs-%s%s-prod.its' % (sha_algo, padding))
+ make_fit('sign-configs-%s%s-prod.its' % (sha_algo, padding), cons, mkimage, dtc_args, datadir, fit)
sign_fit(sha_algo, sign_options)
# Build the FIT with dev key (keys NOT required). This adds the
# signature into sandbox-u-boot.dtb, NOT marked 'required'.
- make_fit('sign-configs-%s%s.its' % (sha_algo, padding))
+ make_fit('sign-configs-%s%s.its' % (sha_algo, padding), cons, mkimage, dtc_args, datadir, fit)
sign_fit_norequire(sha_algo, sign_options)
# So now sandbox-u-boot.dtb two signatures, for the prod and dev keys.
@@ -423,7 +440,7 @@ def test_vboot(u_boot_console, name, sha_algo, padding, sign_options, required,
# Build the FIT with dev key (keys required) and sign it. This puts the
# signature into sandbox-u-boot.dtb, marked 'required'.
- make_fit('sign-configs-%s%s.its' % (sha_algo, padding))
+ make_fit('sign-configs-%s%s.its' % (sha_algo, padding), cons, mkimage, dtc_args, datadir, fit)
sign_fit(sha_algo, sign_options)
# Set the required-mode policy to "any".
@@ -461,17 +478,17 @@ def test_vboot(u_boot_console, name, sha_algo, padding, sign_options, required,
# Compile our device tree files for kernel and U-Boot. These are
# regenerated here since mkimage will modify them (by adding a
# public key) below.
- dtc('sandbox-kernel.dts')
+ dtc('sandbox-kernel.dts', cons, dtc_args, datadir, tmpdir, dtb)
dtc_options('sandbox-u-boot-global%s.dts' % padding, '-p 1024')
# Build the FIT with dev key (keys NOT required). This adds the
# signature into sandbox-u-boot.dtb, NOT marked 'required'.
- make_fit('simple-images.its')
+ make_fit('simple-images.its', cons, mkimage, dtc_args, datadir, fit)
sign_fit_dtb(sha_algo, '', dtb)
# Build the dtb for binman that define the pre-load header
# with the global sigature.
- dtc('sandbox-binman%s.dts' % padding)
+ dtc('sandbox-binman%s.dts' % padding, cons, dtc_args, datadir, tmpdir, dtb)
# Run binman to create the final image with the not signed fit
# and the pre-load header that contains the global signature.
@@ -531,3 +548,96 @@ def test_vboot(u_boot_console, name, sha_algo, padding, sign_options, required,
# Go back to the original U-Boot with the correct dtb.
cons.config.dtb = old_dtb
cons.restart_uboot()
+
+
+TESTDATA_IN = [
+ ['sha1-basic', 'sha1', '', None, False],
+ ['sha1-pad', 'sha1', '', '-E -p 0x10000', False],
+ ['sha1-pss', 'sha1', '-pss', None, False],
+ ['sha1-pss-pad', 'sha1', '-pss', '-E -p 0x10000', False],
+ ['sha256-basic', 'sha256', '', None, False],
+ ['sha256-pad', 'sha256', '', '-E -p 0x10000', False],
+ ['sha256-pss', 'sha256', '-pss', None, False],
+ ['sha256-pss-pad', 'sha256', '-pss', '-E -p 0x10000', False],
+ ['sha256-pss-required', 'sha256', '-pss', None, False],
+ ['sha256-pss-pad-required', 'sha256', '-pss', '-E -p 0x10000', False],
+ ['sha384-basic', 'sha384', '', None, False],
+ ['sha384-pad', 'sha384', '', '-E -p 0x10000', False],
+ ['algo-arg', 'algo-arg', '', '-o sha256,rsa2048', True],
+ ['sha256-global-sign', 'sha256', '', '', False],
+ ['sha256-global-sign-pss', 'sha256', '-pss', '', False],
+]
+
+# Mark all but the first test as slow, so they are not run with '-k not slow'
+TESTDATA = [TESTDATA_IN[0]]
+TESTDATA += [pytest.param(*v, marks=pytest.mark.slow) for v in TESTDATA_IN[1:]]
+
+@pytest.mark.boardspec('sandbox')
+@pytest.mark.buildconfigspec('fit_signature')
+@pytest.mark.requiredtool('dtc')
+@pytest.mark.requiredtool('openssl')
+@pytest.mark.parametrize("name,sha_algo,padding,sign_options,algo_arg", TESTDATA)
+def test_fdt_add_pubkey(u_boot_console, name, sha_algo, padding, sign_options, algo_arg):
+ """Test fdt_add_pubkey utility with bunch of different algo options."""
+
+ def sign_fit(sha_algo, options):
+ """Sign the FIT
+
+ Signs the FIT and writes the signature into it.
+
+ Args:
+ sha_algo: Either 'sha1' or 'sha256', to select the algorithm to
+ use.
+ options: Options to provide to mkimage.
+ """
+ args = [mkimage, '-F', '-k', tmpdir, fit]
+ if options:
+ args += options.split(' ')
+ cons.log.action('%s: Sign images' % sha_algo)
+ util.run_and_log(cons, args)
+
+ def test_add_pubkey(sha_algo, padding, sign_options):
+ """Test fdt_add_pubkey utility with given hash algorithm and padding.
+
+ This function tests if fdt_add_pubkey utility may add public keys into dtb.
+
+ Args:
+ sha_algo: Either 'sha1' or 'sha256', to select the algorithm to use
+ padding: Either '' or '-pss', to select the padding to use for the
+ rsa signature algorithm.
+ sign_options: Options to mkimage when signing a fit image.
+ """
+
+ # Create a fresh .dtb without the public keys
+ dtc('sandbox-u-boot.dts', cons, dtc_args, datadir, tmpdir, dtb)
+
+ cons.log.action('%s: Test fdt_add_pubkey with signed configuration' % sha_algo)
+ # Then add the dev key via the fdt_add_pubkey tool
+ util.run_and_log(cons, [fdt_add_pubkey, '-a', '%s,%s' % ('sha256' if algo_arg else sha_algo, \
+ 'rsa3072' if sha_algo == 'sha384' else 'rsa2048'),
+ '-k', tmpdir, '-n', 'dev', '-r', 'conf', dtb])
+
+ make_fit('sign-configs-%s%s.its' % (sha_algo, padding), cons, mkimage, dtc_args, datadir, fit)
+
+ # Sign images with our dev keys
+ sign_fit(sha_algo, sign_options)
+
+ # Check with fit_check_sign that FIT is signed with key
+ util.run_and_log(cons, [fit_check_sign, '-f', fit, '-k', dtb])
+
+ cons = u_boot_console
+ tmpdir = os.path.join(cons.config.result_dir, name) + '/'
+ if not os.path.exists(tmpdir):
+ os.mkdir(tmpdir)
+ datadir = cons.config.source_dir + '/test/py/tests/vboot/'
+ fit = '%stest.fit' % tmpdir
+ mkimage = cons.config.build_dir + '/tools/mkimage'
+ binman = cons.config.source_dir + '/tools/binman/binman'
+ fit_check_sign = cons.config.build_dir + '/tools/fit_check_sign'
+ fdt_add_pubkey = cons.config.build_dir + '/tools/fdt_add_pubkey'
+ dtc_args = '-I dts -O dtb -i %s' % tmpdir
+ dtb = '%ssandbox-u-boot.dtb' % tmpdir
+
+ # keys created in test_vboot test
+
+ test_add_pubkey(sha_algo, padding, sign_options)
diff --git a/test/py/u_boot_utils.py b/test/py/u_boot_utils.py
index c4fc23aeda3..9e161fbc238 100644
--- a/test/py/u_boot_utils.py
+++ b/test/py/u_boot_utils.py
@@ -157,7 +157,7 @@ def wait_until_file_open_fails(fn, ignore_errors):
return
raise Exception('File can still be opened')
-def run_and_log(u_boot_console, cmd, ignore_errors=False, stdin=None):
+def run_and_log(u_boot_console, cmd, ignore_errors=False, stdin=None, env=None):
"""Run a command and log its output.
Args:
@@ -170,6 +170,7 @@ def run_and_log(u_boot_console, cmd, ignore_errors=False, stdin=None):
an error code, otherwise an exception will be raised if such
problems occur.
stdin: Input string to pass to the command as stdin (or None)
+ env: Environment to use, or None to use the current one
Returns:
The output as a string.
@@ -177,7 +178,7 @@ def run_and_log(u_boot_console, cmd, ignore_errors=False, stdin=None):
if isinstance(cmd, str):
cmd = cmd.split()
runner = u_boot_console.log.get_runner(cmd[0], sys.stdout)
- output = runner.run(cmd, ignore_errors=ignore_errors, stdin=stdin)
+ output = runner.run(cmd, ignore_errors=ignore_errors, stdin=stdin, env=env)
runner.close()
return output