summaryrefslogtreecommitdiff
path: root/test/py
diff options
context:
space:
mode:
Diffstat (limited to 'test/py')
-rw-r--r--test/py/requirements.txt4
-rw-r--r--test/py/tests/test_android/test_avb.py2
-rw-r--r--test/py/tests/test_cat/conftest.py2
-rw-r--r--test/py/tests/test_cleanup_build.py105
-rw-r--r--test/py/tests/test_efi_bootmgr/conftest.py2
-rw-r--r--test/py/tests/test_efi_capsule/capsule_common.py142
-rw-r--r--test/py/tests/test_efi_capsule/conftest.py84
-rw-r--r--test/py/tests/test_efi_capsule/test_capsule_firmware_fit.py213
-rw-r--r--test/py/tests/test_efi_capsule/test_capsule_firmware_raw.py301
-rw-r--r--test/py/tests/test_efi_capsule/test_capsule_firmware_signed_fit.py269
-rw-r--r--test/py/tests/test_efi_capsule/test_capsule_firmware_signed_raw.py276
-rw-r--r--test/py/tests/test_efi_capsule/version.dts24
-rw-r--r--test/py/tests/test_efi_secboot/conftest.py4
-rw-r--r--test/py/tests/test_eficonfig/conftest.py2
-rw-r--r--test/py/tests/test_fs/conftest.py12
-rw-r--r--test/py/tests/test_scp03.py2
-rw-r--r--test/py/tests/test_tpm2.py19
-rw-r--r--test/py/tests/test_xxd/conftest.py2
18 files changed, 807 insertions, 658 deletions
diff --git a/test/py/requirements.txt b/test/py/requirements.txt
index 86d6266053..f7e76bdb91 100644
--- a/test/py/requirements.txt
+++ b/test/py/requirements.txt
@@ -20,8 +20,8 @@ pytest==6.2.5
pytest-xdist==2.5.0
python-mimeparse==1.6.0
python-subunit==1.3.0
-requests==2.27.1
-setuptools==58.3.0
+requests==2.31.0
+setuptools==65.5.1
six==1.16.0
testtools==2.3.0
traceback2==1.4.0
diff --git a/test/py/tests/test_android/test_avb.py b/test/py/tests/test_android/test_avb.py
index bc5c5b5582..238b48c90f 100644
--- a/test/py/tests/test_android/test_avb.py
+++ b/test/py/tests/test_android/test_avb.py
@@ -5,7 +5,7 @@
# Android Verified Boot 2.0 Test
"""
-This tests Android Verified Boot 2.0 support in U-boot:
+This tests Android Verified Boot 2.0 support in U-Boot:
For additional details about how to build proper vbmeta partition
check doc/android/avb2.rst
diff --git a/test/py/tests/test_cat/conftest.py b/test/py/tests/test_cat/conftest.py
index 058fe52352..fc396f50d3 100644
--- a/test/py/tests/test_cat/conftest.py
+++ b/test/py/tests/test_cat/conftest.py
@@ -13,7 +13,7 @@ def cat_data(u_boot_config):
"""Set up a file system to be used in cat tests
Args:
- u_boot_config -- U-boot configuration.
+ u_boot_config -- U-Boot configuration.
"""
mnt_point = u_boot_config.persistent_data_dir + '/test_cat'
image_path = u_boot_config.persistent_data_dir + '/cat.img'
diff --git a/test/py/tests/test_cleanup_build.py b/test/py/tests/test_cleanup_build.py
new file mode 100644
index 0000000000..5206ff73ec
--- /dev/null
+++ b/test/py/tests/test_cleanup_build.py
@@ -0,0 +1,105 @@
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (c) 2023 Tobias Deiminger <tdmg@linutronix.de>
+
+"""Test for unexpected leftovers after make clean"""
+
+import itertools
+import os
+import pathlib
+import shutil
+import sys
+
+import pytest
+
+# pylint: disable=redefined-outer-name
+
+
+@pytest.fixture
+def tmp_copy_of_builddir(u_boot_config, tmp_path):
+ """For each test, provide a temporary copy of the initial build directory."""
+ shutil.copytree(
+ u_boot_config.build_dir,
+ tmp_path,
+ symlinks=True,
+ dirs_exist_ok=True,
+ )
+ return tmp_path
+
+
+@pytest.fixture(scope="module")
+def run_make(u_boot_log):
+ """Provide function to run and log make without connecting to u-boot console."""
+ runner = u_boot_log.get_runner("make", sys.stdout)
+
+ def _run_make(build_dir, target):
+ cmd = ["make", f"O={build_dir}", target]
+ runner.run(cmd)
+
+ yield _run_make
+ runner.close()
+
+
+@pytest.fixture(scope="module")
+def most_generated_files():
+ """Path.glob style patterns to describe what should be removed by 'make clean'."""
+ return (
+ "**/*.c",
+ "**/*.dtb",
+ "**/*.dtbo",
+ "**/*.o",
+ "**/*.py",
+ "**/*.pyc",
+ "**/*.so",
+ "**/*.srec",
+ "u-boot*",
+ "[svt]pl/u-boot*",
+ )
+
+
+@pytest.fixture(scope="module")
+def all_generated_files(most_generated_files):
+ """Path.glob style patterns to describe what should be removed by 'make mrproper'."""
+ return most_generated_files + (".config", "**/*.h")
+
+
+def find_files(search_dir, include_patterns, exclude_dirs=None):
+ """Find files matching include_patterns, unless it's in one of exclude_dirs.
+
+ include_patterns -- Path.glob style pattern relative to search dir
+ exclude_dir -- directories to exclude, expected relative to search dir
+ """
+ matches = []
+ exclude_dirs = [] if exclude_dirs is None else exclude_dirs
+ for abs_path in itertools.chain.from_iterable(
+ pathlib.Path(search_dir).glob(pattern) for pattern in include_patterns
+ ):
+ if abs_path.is_dir():
+ continue
+ rel_path = pathlib.Path(os.path.relpath(abs_path, search_dir))
+ if not any(
+ rel_path.is_relative_to(exclude_dir) for exclude_dir in exclude_dirs
+ ):
+ matches.append(rel_path)
+ return matches
+
+
+def test_clean(run_make, tmp_copy_of_builddir, most_generated_files):
+ """Test if 'make clean' deletes most generated files."""
+ run_make(tmp_copy_of_builddir, "clean")
+ leftovers = find_files(
+ tmp_copy_of_builddir,
+ most_generated_files,
+ exclude_dirs=["scripts", "test/overlay"],
+ )
+ assert not leftovers, f"leftovers: {', '.join(map(str, leftovers))}"
+
+
+def test_mrproper(run_make, tmp_copy_of_builddir, all_generated_files):
+ """Test if 'make mrproper' deletes current configuration and all generated files."""
+ run_make(tmp_copy_of_builddir, "mrproper")
+ leftovers = find_files(
+ tmp_copy_of_builddir,
+ all_generated_files,
+ exclude_dirs=["test/overlay"],
+ )
+ assert not leftovers, f"leftovers: {', '.join(map(str, leftovers))}"
diff --git a/test/py/tests/test_efi_bootmgr/conftest.py b/test/py/tests/test_efi_bootmgr/conftest.py
index eabafa5429..0eca025058 100644
--- a/test/py/tests/test_efi_bootmgr/conftest.py
+++ b/test/py/tests/test_efi_bootmgr/conftest.py
@@ -12,7 +12,7 @@ def efi_bootmgr_data(u_boot_config):
"""Set up a file system to be used in UEFI bootmanager tests.
Args:
- u_boot_config -- U-boot configuration.
+ u_boot_config -- U-Boot configuration.
Return:
A path to disk image to be used for testing
diff --git a/test/py/tests/test_efi_capsule/capsule_common.py b/test/py/tests/test_efi_capsule/capsule_common.py
new file mode 100644
index 0000000000..9eef6767a6
--- /dev/null
+++ b/test/py/tests/test_efi_capsule/capsule_common.py
@@ -0,0 +1,142 @@
+# SPDX-License-Identifier: GPL-2.0+
+# Copyright (c) 2023, Linaro Limited
+
+
+"""Common function for UEFI capsule test."""
+
+from capsule_defs import CAPSULE_DATA_DIR, CAPSULE_INSTALL_DIR
+
+def setup(u_boot_console, disk_img, osindications):
+ """setup the test
+
+ Args:
+ u_boot_console -- A console connection to U-Boot.
+ disk_img -- A path to disk image to be used for testing.
+ osindications -- String of osindications value.
+ """
+ u_boot_console.run_command_list([
+ f'host bind 0 {disk_img}',
+ 'printenv -e PlatformLangCodes', # workaround for terminal size determination
+ 'efidebug boot add -b 1 TEST host 0:1 /helloworld.efi',
+ 'efidebug boot order 1',
+ 'env set dfu_alt_info "sf 0:0=u-boot-bin raw 0x100000 0x50000;'
+ 'u-boot-env raw 0x150000 0x200000"'])
+
+ if osindications is None:
+ u_boot_console.run_command('env set -e OsIndications')
+ else:
+ u_boot_console.run_command(f'env set -e -nv -bs -rt OsIndications ={osindications}')
+
+ u_boot_console.run_command('env save')
+
+def init_content(u_boot_console, target, filename, expected):
+ """initialize test content
+
+ Args:
+ u_boot_console -- A console connection to U-Boot.
+ target -- Target address to place the content.
+ filename -- File name of the content.
+ expected -- Expected string of the content.
+ """
+ output = u_boot_console.run_command_list([
+ 'sf probe 0:0',
+ f'fatload host 0:1 4000000 {CAPSULE_DATA_DIR}/{filename}',
+ f'sf write 4000000 {target} 10',
+ 'sf read 5000000 100000 10',
+ 'md.b 5000000 10'])
+ assert expected in ''.join(output)
+
+def place_capsule_file(u_boot_console, filenames):
+ """place the capsule file
+
+ Args:
+ u_boot_console -- A console connection to U-Boot.
+ filenames -- File name array of the target capsule files.
+ """
+ for name in filenames:
+ u_boot_console.run_command_list([
+ f'fatload host 0:1 4000000 {CAPSULE_DATA_DIR}/{name}',
+ f'fatwrite host 0:1 4000000 {CAPSULE_INSTALL_DIR}/{name} $filesize'])
+
+ output = u_boot_console.run_command(f'fatls host 0:1 {CAPSULE_INSTALL_DIR}')
+ for name in filenames:
+ assert name in ''.join(output)
+
+def exec_manual_update(u_boot_console, disk_img, filenames, need_reboot = True):
+ """execute capsule update manually
+
+ Args:
+ u_boot_console -- A console connection to U-Boot.
+ disk_img -- A path to disk image to be used for testing.
+ filenames -- File name array of the target capsule files.
+ need_reboot -- Flag indicates whether system reboot is required.
+ """
+ # make sure that dfu_alt_info exists even persistent variables
+ # are not available.
+ output = u_boot_console.run_command_list([
+ 'env set dfu_alt_info '
+ '"sf 0:0=u-boot-bin raw 0x100000 0x50000;'
+ 'u-boot-env raw 0x150000 0x200000"',
+ f'host bind 0 {disk_img}',
+ f'fatls host 0:1 {CAPSULE_INSTALL_DIR}'])
+ for name in filenames:
+ assert name in ''.join(output)
+
+ # need to run uefi command to initiate capsule handling
+ u_boot_console.run_command(
+ 'env print -e Capsule0000', wait_for_reboot = need_reboot)
+
+def check_file_removed(u_boot_console, disk_img, filenames):
+ """check files are removed
+
+ Args:
+ u_boot_console -- A console connection to U-Boot.
+ disk_img -- A path to disk image to be used for testing.
+ filenames -- File name array of the target capsule files.
+ """
+ output = u_boot_console.run_command_list([
+ f'host bind 0 {disk_img}',
+ f'fatls host 0:1 {CAPSULE_INSTALL_DIR}'])
+ for name in filenames:
+ assert name not in ''.join(output)
+
+def check_file_exist(u_boot_console, disk_img, filenames):
+ """check files exist
+
+ Args:
+ u_boot_console -- A console connection to U-Boot.
+ disk_img -- A path to disk image to be used for testing.
+ filenames -- File name array of the target capsule files.
+ """
+ output = u_boot_console.run_command_list([
+ f'host bind 0 {disk_img}',
+ f'fatls host 0:1 {CAPSULE_INSTALL_DIR}'])
+ for name in filenames:
+ assert name in ''.join(output)
+
+def verify_content(u_boot_console, target, expected):
+ """verify the content
+
+ Args:
+ u_boot_console -- A console connection to U-Boot.
+ target -- Target address to verify.
+ expected -- Expected string of the content.
+ """
+ output = u_boot_console.run_command_list([
+ 'sf probe 0:0',
+ f'sf read 4000000 {target} 10',
+ 'md.b 4000000 10'])
+ assert expected in ''.join(output)
+
+def do_reboot_dtb_specified(u_boot_config, u_boot_console, dtb_filename):
+ """do reboot with specified DTB
+
+ Args:
+ u_boot_config -- U-boot configuration.
+ u_boot_console -- A console connection to U-Boot.
+ dtb_filename -- DTB file name.
+ """
+ mnt_point = u_boot_config.persistent_data_dir + '/test_efi_capsule'
+ u_boot_console.config.dtb = mnt_point + CAPSULE_DATA_DIR \
+ + f'/{dtb_filename}'
+ u_boot_console.restart_uboot()
diff --git a/test/py/tests/test_efi_capsule/conftest.py b/test/py/tests/test_efi_capsule/conftest.py
index a337e62936..054be1ee97 100644
--- a/test/py/tests/test_efi_capsule/conftest.py
+++ b/test/py/tests/test_efi_capsule/conftest.py
@@ -17,7 +17,7 @@ def efi_capsule_data(request, u_boot_config):
for testing.
request -- Pytest request object.
- u_boot_config -- U-boot configuration.
+ u_boot_config -- U-Boot configuration.
"""
mnt_point = u_boot_config.persistent_data_dir + '/test_efi_capsule'
data_dir = mnt_point + CAPSULE_DATA_DIR
@@ -62,6 +62,23 @@ def efi_capsule_data(request, u_boot_config):
'-out SIGNER2.crt -nodes -days 365'
% data_dir, shell=True)
+ # Update dtb to add the version information
+ check_call('cd %s; '
+ 'cp %s/test/py/tests/test_efi_capsule/version.dts .'
+ % (data_dir, u_boot_config.source_dir), shell=True)
+ if capsule_auth_enabled:
+ check_call('cd %s; '
+ 'dtc -@ -I dts -O dtb -o version.dtbo version.dts; '
+ 'fdtoverlay -i test_sig.dtb '
+ '-o test_ver.dtb version.dtbo'
+ % (data_dir), shell=True)
+ else:
+ check_call('cd %s; '
+ 'dtc -@ -I dts -O dtb -o version.dtbo version.dts; '
+ 'fdtoverlay -i %s/arch/sandbox/dts/test.dtb '
+ '-o test_ver.dtb version.dtbo'
+ % (data_dir, u_boot_config.build_dir), shell=True)
+
# Create capsule files
# two regions: one for u-boot.bin and the other for u-boot.env
check_call('cd %s; echo -n u-boot:Old > u-boot.bin.old; echo -n u-boot:New > u-boot.bin.new; echo -n u-boot-env:Old > u-boot.env.old; echo -n u-boot-env:New > u-boot.env.new' % data_dir,
@@ -87,6 +104,26 @@ def efi_capsule_data(request, u_boot_config):
check_call('cd %s; %s/tools/mkeficapsule --index 1 --guid 058B7D83-50D5-4C47-A195-60D86AD341C4 uboot_bin_env.itb Test05' %
(data_dir, u_boot_config.build_dir),
shell=True)
+ check_call('cd %s; %s/tools/mkeficapsule --index 1 --fw-version 5 '
+ '--guid 09D7CF52-0720-4710-91D1-08469B7FE9C8 u-boot.bin.new Test101' %
+ (data_dir, u_boot_config.build_dir),
+ shell=True)
+ check_call('cd %s; %s/tools/mkeficapsule --index 2 --fw-version 10 '
+ '--guid 5A7021F5-FEF2-48B4-AABA-832E777418C0 u-boot.env.new Test102' %
+ (data_dir, u_boot_config.build_dir),
+ shell=True)
+ check_call('cd %s; %s/tools/mkeficapsule --index 1 --fw-version 2 '
+ '--guid 09D7CF52-0720-4710-91D1-08469B7FE9C8 u-boot.bin.new Test103' %
+ (data_dir, u_boot_config.build_dir),
+ shell=True)
+ check_call('cd %s; %s/tools/mkeficapsule --index 1 --fw-version 5 '
+ '--guid 3673B45D-6A7C-46F3-9E60-ADABB03F7937 uboot_bin_env.itb Test104' %
+ (data_dir, u_boot_config.build_dir),
+ shell=True)
+ check_call('cd %s; %s/tools/mkeficapsule --index 1 --fw-version 2 '
+ '--guid 3673B45D-6A7C-46F3-9E60-ADABB03F7937 uboot_bin_env.itb Test105' %
+ (data_dir, u_boot_config.build_dir),
+ shell=True)
if capsule_auth_enabled:
# raw firmware signed with proper key
@@ -123,6 +160,51 @@ def efi_capsule_data(request, u_boot_config):
'uboot_bin_env.itb Test14'
% (data_dir, u_boot_config.build_dir),
shell=True)
+ # raw firmware signed with proper key with version information
+ check_call('cd %s; '
+ '%s/tools/mkeficapsule --index 1 --monotonic-count 1 '
+ '--fw-version 5 '
+ '--private-key SIGNER.key --certificate SIGNER.crt '
+ '--guid 09D7CF52-0720-4710-91D1-08469B7FE9C8 '
+ 'u-boot.bin.new Test111'
+ % (data_dir, u_boot_config.build_dir),
+ shell=True)
+ # raw firmware signed with proper key with version information
+ check_call('cd %s; '
+ '%s/tools/mkeficapsule --index 2 --monotonic-count 1 '
+ '--fw-version 10 '
+ '--private-key SIGNER.key --certificate SIGNER.crt '
+ '--guid 5A7021F5-FEF2-48B4-AABA-832E777418C0 '
+ 'u-boot.env.new Test112'
+ % (data_dir, u_boot_config.build_dir),
+ shell=True)
+ # raw firmware signed with proper key with lower version information
+ check_call('cd %s; '
+ '%s/tools/mkeficapsule --index 1 --monotonic-count 1 '
+ '--fw-version 2 '
+ '--private-key SIGNER.key --certificate SIGNER.crt '
+ '--guid 09D7CF52-0720-4710-91D1-08469B7FE9C8 '
+ 'u-boot.bin.new Test113'
+ % (data_dir, u_boot_config.build_dir),
+ shell=True)
+ # FIT firmware signed with proper key with version information
+ check_call('cd %s; '
+ '%s/tools/mkeficapsule --index 1 --monotonic-count 1 '
+ '--fw-version 5 '
+ '--private-key SIGNER.key --certificate SIGNER.crt '
+ '--guid 3673B45D-6A7C-46F3-9E60-ADABB03F7937 '
+ 'uboot_bin_env.itb Test114'
+ % (data_dir, u_boot_config.build_dir),
+ shell=True)
+ # FIT firmware signed with proper key with lower version information
+ check_call('cd %s; '
+ '%s/tools/mkeficapsule --index 1 --monotonic-count 1 '
+ '--fw-version 2 '
+ '--private-key SIGNER.key --certificate SIGNER.crt '
+ '--guid 3673B45D-6A7C-46F3-9E60-ADABB03F7937 '
+ 'uboot_bin_env.itb Test115'
+ % (data_dir, u_boot_config.build_dir),
+ shell=True)
# Create a disk image with EFI system partition
check_call('virt-make-fs --partition=gpt --size=+1M --type=vfat %s %s' %
diff --git a/test/py/tests/test_efi_capsule/test_capsule_firmware_fit.py b/test/py/tests/test_efi_capsule/test_capsule_firmware_fit.py
index 9ee152818d..a3094c33f4 100644
--- a/test/py/tests/test_efi_capsule/test_capsule_firmware_fit.py
+++ b/test/py/tests/test_efi_capsule/test_capsule_firmware_fit.py
@@ -7,8 +7,15 @@ This test verifies capsule-on-disk firmware update for FIT images
"""
import pytest
-from capsule_defs import CAPSULE_DATA_DIR, CAPSULE_INSTALL_DIR
-
+from capsule_common import (
+ setup,
+ init_content,
+ place_capsule_file,
+ exec_manual_update,
+ check_file_removed,
+ verify_content,
+ do_reboot_dtb_specified
+)
@pytest.mark.boardspec('sandbox_flattree')
@pytest.mark.buildconfigspec('efi_capsule_firmware_fit')
@@ -40,37 +47,12 @@ class TestEfiCapsuleFirmwareFit():
u_boot_console.restart_uboot()
disk_img = efi_capsule_data
+ capsule_files = ['Test05']
with u_boot_console.log.section('Test Case 1-a, before reboot'):
- output = u_boot_console.run_command_list([
- 'host bind 0 %s' % disk_img,
- 'efidebug boot add -b 1 TEST host 0:1 /helloworld.efi -s ""',
- 'efidebug boot order 1',
- 'env set -e -nv -bs -rt OsIndications =0x0000000000000004',
- 'env set dfu_alt_info "sf 0:0=u-boot-bin raw 0x100000 0x50000;u-boot-env raw 0x150000 0x200000"',
- 'env save'])
-
- # initialize contents
- output = u_boot_console.run_command_list([
- 'sf probe 0:0',
- 'fatload host 0:1 4000000 %s/u-boot.bin.old' % CAPSULE_DATA_DIR,
- 'sf write 4000000 100000 10',
- 'sf read 5000000 100000 10',
- 'md.b 5000000 10'])
- assert 'Old' in ''.join(output)
- output = u_boot_console.run_command_list([
- 'sf probe 0:0',
- 'fatload host 0:1 4000000 %s/u-boot.env.old' % CAPSULE_DATA_DIR,
- 'sf write 4000000 150000 10',
- 'sf read 5000000 150000 10',
- 'md.b 5000000 10'])
- assert 'Old' in ''.join(output)
-
- # place a capsule file
- output = u_boot_console.run_command_list([
- 'fatload host 0:1 4000000 %s/Test05' % CAPSULE_DATA_DIR,
- 'fatwrite host 0:1 4000000 %s/Test05 $filesize' % CAPSULE_INSTALL_DIR,
- 'fatls host 0:1 %s' % CAPSULE_INSTALL_DIR])
- assert 'Test05' in ''.join(output)
+ setup(u_boot_console, disk_img, '0x0000000000000004')
+ init_content(u_boot_console, '100000', 'u-boot.bin.old', 'Old')
+ init_content(u_boot_console, '150000', 'u-boot.env.old', 'Old')
+ place_capsule_file(u_boot_console, capsule_files)
capsule_early = u_boot_config.buildconfig.get(
'config_efi_capsule_on_disk_early')
@@ -80,28 +62,13 @@ class TestEfiCapsuleFirmwareFit():
with u_boot_console.log.section('Test Case 1-b, after reboot'):
if not capsule_early:
- # make sure that dfu_alt_info exists even persistent variables
- # are not available.
- output = u_boot_console.run_command_list([
- 'env set dfu_alt_info "sf 0:0=u-boot-bin raw 0x100000 0x50000;u-boot-env raw 0x150000 0x200000"',
- 'host bind 0 %s' % disk_img,
- 'fatls host 0:1 %s' % CAPSULE_INSTALL_DIR])
- assert 'Test05' in ''.join(output)
-
- # need to run uefi command to initiate capsule handling
- output = u_boot_console.run_command(
- 'env print -e Capsule0000', wait_for_reboot = True)
+ exec_manual_update(u_boot_console, disk_img, capsule_files)
- output = u_boot_console.run_command_list([
- 'sf probe 0:0',
- 'sf read 4000000 100000 10',
- 'md.b 4000000 10'])
- assert 'u-boot:Old' in ''.join(output)
+ # deleted anyway
+ check_file_removed(u_boot_console, disk_img, capsule_files)
- output = u_boot_console.run_command_list([
- 'sf read 4000000 150000 10',
- 'md.b 4000000 10'])
- assert 'u-boot-env:Old' in ''.join(output)
+ verify_content(u_boot_console, '100000', 'u-boot:Old')
+ verify_content(u_boot_console, '150000', 'u-boot-env:Old')
def test_efi_capsule_fw2(
self, u_boot_config, u_boot_console, efi_capsule_data):
@@ -112,38 +79,12 @@ class TestEfiCapsuleFirmwareFit():
"""
disk_img = efi_capsule_data
+ capsule_files = ['Test04']
with u_boot_console.log.section('Test Case 2-a, before reboot'):
- output = u_boot_console.run_command_list([
- 'host bind 0 %s' % disk_img,
- 'printenv -e PlatformLangCodes', # workaround for terminal size determination
- 'efidebug boot add -b 1 TEST host 0:1 /helloworld.efi -s ""',
- 'efidebug boot order 1',
- 'env set -e -nv -bs -rt OsIndications =0x0000000000000004',
- 'env set dfu_alt_info "sf 0:0=u-boot-bin raw 0x100000 0x50000;u-boot-env raw 0x150000 0x200000"',
- 'env save'])
-
- # initialize contents
- output = u_boot_console.run_command_list([
- 'sf probe 0:0',
- 'fatload host 0:1 4000000 %s/u-boot.bin.old' % CAPSULE_DATA_DIR,
- 'sf write 4000000 100000 10',
- 'sf read 5000000 100000 10',
- 'md.b 5000000 10'])
- assert 'Old' in ''.join(output)
- output = u_boot_console.run_command_list([
- 'sf probe 0:0',
- 'fatload host 0:1 4000000 %s/u-boot.env.old' % CAPSULE_DATA_DIR,
- 'sf write 4000000 150000 10',
- 'sf read 5000000 150000 10',
- 'md.b 5000000 10'])
- assert 'Old' in ''.join(output)
-
- # place a capsule file
- output = u_boot_console.run_command_list([
- 'fatload host 0:1 4000000 %s/Test04' % CAPSULE_DATA_DIR,
- 'fatwrite host 0:1 4000000 %s/Test04 $filesize' % CAPSULE_INSTALL_DIR,
- 'fatls host 0:1 %s' % CAPSULE_INSTALL_DIR])
- assert 'Test04' in ''.join(output)
+ setup(u_boot_console, disk_img, '0x0000000000000004')
+ init_content(u_boot_console, '100000', 'u-boot.bin.old', 'Old')
+ init_content(u_boot_console, '150000', 'u-boot.env.old', 'Old')
+ place_capsule_file(u_boot_console, capsule_files)
capsule_early = u_boot_config.buildconfig.get(
'config_efi_capsule_on_disk_early')
@@ -155,36 +96,88 @@ class TestEfiCapsuleFirmwareFit():
with u_boot_console.log.section('Test Case 2-b, after reboot'):
if not capsule_early:
- # make sure that dfu_alt_info exists even persistent variables
- # are not available.
- output = u_boot_console.run_command_list([
- 'env set dfu_alt_info "sf 0:0=u-boot-bin raw 0x100000 0x50000;u-boot-env raw 0x150000 0x200000"',
- 'host bind 0 %s' % disk_img,
- 'fatls host 0:1 %s' % CAPSULE_INSTALL_DIR])
- assert 'Test04' in ''.join(output)
-
- # need to run uefi command to initiate capsule handling
- output = u_boot_console.run_command(
- 'env print -e Capsule0000', wait_for_reboot = True)
+ exec_manual_update(u_boot_console, disk_img, capsule_files)
- output = u_boot_console.run_command_list([
- 'host bind 0 %s' % disk_img,
- 'fatls host 0:1 %s' % CAPSULE_INSTALL_DIR])
- assert 'Test04' not in ''.join(output)
+ check_file_removed(u_boot_console, disk_img, capsule_files)
- output = u_boot_console.run_command_list([
- 'sf probe 0:0',
- 'sf read 4000000 100000 10',
- 'md.b 4000000 10'])
- if capsule_auth:
- assert 'u-boot:Old' in ''.join(output)
- else:
- assert 'u-boot:New' in ''.join(output)
+ expected = 'u-boot:Old' if capsule_auth else 'u-boot:New'
+ verify_content(u_boot_console, '100000', expected)
+
+ expected = 'u-boot-env:Old' if capsule_auth else 'u-boot-env:New'
+ verify_content(u_boot_console, '150000', expected)
+
+ def test_efi_capsule_fw3(
+ self, u_boot_config, u_boot_console, efi_capsule_data):
+ """ Test Case 3
+ Update U-Boot on SPI Flash, raw image format with fw_version and lowest_supported_version
+ 0x100000-0x150000: U-Boot binary (but dummy)
+ 0x150000-0x200000: U-Boot environment (but dummy)
+ """
+ disk_img = efi_capsule_data
+ capsule_files = ['Test104']
+ with u_boot_console.log.section('Test Case 3-a, before reboot'):
+ setup(u_boot_console, disk_img, '0x0000000000000004')
+ init_content(u_boot_console, '100000', 'u-boot.bin.old', 'Old')
+ init_content(u_boot_console, '150000', 'u-boot.env.old', 'Old')
+ place_capsule_file(u_boot_console, capsule_files)
+
+ # reboot
+ do_reboot_dtb_specified(u_boot_config, u_boot_console, 'test_ver.dtb')
+ capsule_early = u_boot_config.buildconfig.get(
+ 'config_efi_capsule_on_disk_early')
+ capsule_auth = u_boot_config.buildconfig.get(
+ 'config_efi_capsule_authenticate')
+ with u_boot_console.log.section('Test Case 3-b, after reboot'):
+ if not capsule_early:
+ exec_manual_update(u_boot_console, disk_img, capsule_files)
+
+ # deleted anyway
+ check_file_removed(u_boot_console, disk_img, capsule_files)
+
+ # make sure the dfu_alt_info exists because it is required for making ESRT.
output = u_boot_console.run_command_list([
- 'sf read 4000000 150000 10',
- 'md.b 4000000 10'])
+ 'env set dfu_alt_info "sf 0:0=u-boot-bin raw 0x100000 0x50000;'
+ 'u-boot-env raw 0x150000 0x200000"',
+ 'efidebug capsule esrt'])
+
if capsule_auth:
- assert 'u-boot-env:Old' in ''.join(output)
+ # capsule authentication failed
+ verify_content(u_boot_console, '100000', 'u-boot:Old')
+ verify_content(u_boot_console, '150000', 'u-boot-env:Old')
else:
- assert 'u-boot-env:New' in ''.join(output)
+ # ensure that SANDBOX_UBOOT_IMAGE_GUID is in the ESRT.
+ assert '3673B45D-6A7C-46F3-9E60-ADABB03F7937' in ''.join(output)
+ assert 'ESRT: fw_version=5' in ''.join(output)
+ assert 'ESRT: lowest_supported_fw_version=3' in ''.join(output)
+
+ verify_content(u_boot_console, '100000', 'u-boot:New')
+ verify_content(u_boot_console, '150000', 'u-boot-env:New')
+
+ def test_efi_capsule_fw4(
+ self, u_boot_config, u_boot_console, efi_capsule_data):
+ """ Test Case 4
+ Update U-Boot on SPI Flash, raw image format with fw_version and lowest_supported_version
+ but fw_version is lower than lowest_supported_version
+ No update should happen
+ 0x100000-0x150000: U-Boot binary (but dummy)
+ """
+ disk_img = efi_capsule_data
+ capsule_files = ['Test105']
+ with u_boot_console.log.section('Test Case 4-a, before reboot'):
+ setup(u_boot_console, disk_img, '0x0000000000000004')
+ init_content(u_boot_console, '100000', 'u-boot.bin.old', 'Old')
+ place_capsule_file(u_boot_console, capsule_files)
+
+ # reboot
+ do_reboot_dtb_specified(u_boot_config, u_boot_console, 'test_ver.dtb')
+
+ capsule_early = u_boot_config.buildconfig.get(
+ 'config_efi_capsule_on_disk_early')
+ with u_boot_console.log.section('Test Case 4-b, after reboot'):
+ if not capsule_early:
+ exec_manual_update(u_boot_console, disk_img, capsule_files)
+
+ check_file_removed(u_boot_console, disk_img, capsule_files)
+
+ verify_content(u_boot_console, '100000', 'u-boot:Old')
diff --git a/test/py/tests/test_efi_capsule/test_capsule_firmware_raw.py b/test/py/tests/test_efi_capsule/test_capsule_firmware_raw.py
index 92bfb14932..80d791e3de 100644
--- a/test/py/tests/test_efi_capsule/test_capsule_firmware_raw.py
+++ b/test/py/tests/test_efi_capsule/test_capsule_firmware_raw.py
@@ -7,7 +7,16 @@ This test verifies capsule-on-disk firmware update for raw images
"""
import pytest
-from capsule_defs import CAPSULE_DATA_DIR, CAPSULE_INSTALL_DIR
+from capsule_common import (
+ setup,
+ init_content,
+ place_capsule_file,
+ exec_manual_update,
+ check_file_removed,
+ check_file_exist,
+ verify_content,
+ do_reboot_dtb_specified
+)
@pytest.mark.boardspec('sandbox')
@pytest.mark.buildconfigspec('efi_capsule_firmware_raw')
@@ -40,37 +49,12 @@ class TestEfiCapsuleFirmwareRaw:
u_boot_console.restart_uboot()
disk_img = efi_capsule_data
+ capsule_files = ['Test03']
with u_boot_console.log.section('Test Case 1-a, before reboot'):
- output = u_boot_console.run_command_list([
- 'host bind 0 %s' % disk_img,
- 'efidebug boot add -b 1 TEST host 0:1 /helloworld.efi -s ""',
- 'efidebug boot order 1',
- 'env set -e -nv -bs -rt OsIndications =0x0000000000000004',
- 'env set dfu_alt_info "sf 0:0=u-boot-bin raw 0x100000 0x50000;u-boot-env raw 0x150000 0x200000"',
- 'env save'])
-
- # initialize contents
- output = u_boot_console.run_command_list([
- 'sf probe 0:0',
- 'fatload host 0:1 4000000 %s/u-boot.bin.old' % CAPSULE_DATA_DIR,
- 'sf write 4000000 100000 10',
- 'sf read 5000000 100000 10',
- 'md.b 5000000 10'])
- assert 'Old' in ''.join(output)
- output = u_boot_console.run_command_list([
- 'sf probe 0:0',
- 'fatload host 0:1 4000000 %s/u-boot.env.old' % CAPSULE_DATA_DIR,
- 'sf write 4000000 150000 10',
- 'sf read 5000000 150000 10',
- 'md.b 5000000 10'])
- assert 'Old' in ''.join(output)
-
- # place a capsule file
- output = u_boot_console.run_command_list([
- 'fatload host 0:1 4000000 %s/Test03' % CAPSULE_DATA_DIR,
- 'fatwrite host 0:1 4000000 %s/Test03 $filesize' % CAPSULE_INSTALL_DIR,
- 'fatls host 0:1 %s' % CAPSULE_INSTALL_DIR])
- assert 'Test03' in ''.join(output)
+ setup(u_boot_console, disk_img, '0x0000000000000004')
+ init_content(u_boot_console, '100000', 'u-boot.bin.old', 'Old')
+ init_content(u_boot_console, '150000', 'u-boot.env.old', 'Old')
+ place_capsule_file(u_boot_console, capsule_files)
# reboot
u_boot_console.restart_uboot()
@@ -80,28 +64,13 @@ class TestEfiCapsuleFirmwareRaw:
with u_boot_console.log.section('Test Case 1-b, after reboot'):
if not capsule_early:
- # make sure that dfu_alt_info exists even persistent variables
- # are not available.
- output = u_boot_console.run_command_list([
- 'env set dfu_alt_info "sf 0:0=u-boot-bin raw 0x100000 0x50000;u-boot-env raw 0x150000 0x200000"',
- 'host bind 0 %s' % disk_img,
- 'fatls host 0:1 %s' % CAPSULE_INSTALL_DIR])
- assert 'Test03' in ''.join(output)
-
- # need to run uefi command to initiate capsule handling
- output = u_boot_console.run_command(
- 'env print -e Capsule0000', wait_for_reboot = True)
+ exec_manual_update(u_boot_console, disk_img, capsule_files)
- output = u_boot_console.run_command_list([
- 'sf probe 0:0',
- 'sf read 4000000 100000 10',
- 'md.b 4000000 10'])
- assert 'u-boot:Old' in ''.join(output)
+ # deleted anyway
+ check_file_removed(u_boot_console, disk_img, capsule_files)
- output = u_boot_console.run_command_list([
- 'sf read 4000000 150000 10',
- 'md.b 4000000 10'])
- assert 'u-boot-env:Old' in ''.join(output)
+ verify_content(u_boot_console, '100000', 'u-boot:Old')
+ verify_content(u_boot_console, '150000', 'u-boot-env:Old')
def test_efi_capsule_fw2(
self, u_boot_config, u_boot_console, efi_capsule_data):
@@ -112,44 +81,12 @@ class TestEfiCapsuleFirmwareRaw:
0x150000-0x200000: U-Boot environment (but dummy)
"""
disk_img = efi_capsule_data
+ capsule_files = ['Test01', 'Test02']
with u_boot_console.log.section('Test Case 2-a, before reboot'):
- output = u_boot_console.run_command_list([
- 'host bind 0 %s' % disk_img,
- 'printenv -e PlatformLangCodes', # workaround for terminal size determination
- 'efidebug boot add -b 1 TEST host 0:1 /helloworld.efi -s ""',
- 'efidebug boot order 1',
- 'env set -e OsIndications',
- 'env set dfu_alt_info "sf 0:0=u-boot-bin raw 0x100000 0x50000;u-boot-env raw 0x150000 0x200000"',
- 'env save'])
-
- # initialize contents
- output = u_boot_console.run_command_list([
- 'sf probe 0:0',
- 'fatload host 0:1 4000000 %s/u-boot.bin.old' % CAPSULE_DATA_DIR,
- 'sf write 4000000 100000 10',
- 'sf read 5000000 100000 10',
- 'md.b 5000000 10'])
- assert 'Old' in ''.join(output)
- output = u_boot_console.run_command_list([
- 'sf probe 0:0',
- 'fatload host 0:1 4000000 %s/u-boot.env.old' % CAPSULE_DATA_DIR,
- 'sf write 4000000 150000 10',
- 'sf read 5000000 150000 10',
- 'md.b 5000000 10'])
- assert 'Old' in ''.join(output)
-
- # place the capsule files
- output = u_boot_console.run_command_list([
- 'fatload host 0:1 4000000 %s/Test01' % CAPSULE_DATA_DIR,
- 'fatwrite host 0:1 4000000 %s/Test01 $filesize' % CAPSULE_INSTALL_DIR,
- 'fatls host 0:1 %s' % CAPSULE_INSTALL_DIR])
- assert 'Test01' in ''.join(output)
-
- output = u_boot_console.run_command_list([
- 'fatload host 0:1 4000000 %s/Test02' % CAPSULE_DATA_DIR,
- 'fatwrite host 0:1 4000000 %s/Test02 $filesize' % CAPSULE_INSTALL_DIR,
- 'fatls host 0:1 %s' % CAPSULE_INSTALL_DIR])
- assert 'Test02' in ''.join(output)
+ setup(u_boot_console, disk_img, None)
+ init_content(u_boot_console, '100000', 'u-boot.bin.old', 'Old')
+ init_content(u_boot_console, '150000', 'u-boot.env.old', 'Old')
+ place_capsule_file(u_boot_console, capsule_files)
# reboot
u_boot_console.restart_uboot()
@@ -158,35 +95,12 @@ class TestEfiCapsuleFirmwareRaw:
'config_efi_capsule_on_disk_early')
with u_boot_console.log.section('Test Case 2-b, after reboot'):
if not capsule_early:
- # make sure that dfu_alt_info exists even persistent variables
- # are not available.
- output = u_boot_console.run_command_list([
- 'env set dfu_alt_info "sf 0:0=u-boot-bin raw 0x100000 0x50000;u-boot-env raw 0x150000 0x200000"',
- 'host bind 0 %s' % disk_img,
- 'fatls host 0:1 %s' % CAPSULE_INSTALL_DIR])
- assert 'Test01' in ''.join(output)
- assert 'Test02' in ''.join(output)
-
- # need to run uefi command to initiate capsule handling
- output = u_boot_console.run_command(
- 'env print -e Capsule0000')
-
- output = u_boot_console.run_command_list([
- 'host bind 0 %s' % disk_img,
- 'fatls host 0:1 %s' % CAPSULE_INSTALL_DIR])
- assert 'Test01' in ''.join(output)
- assert 'Test02' in ''.join(output)
+ exec_manual_update(u_boot_console, disk_img, capsule_files, False)
- output = u_boot_console.run_command_list([
- 'sf probe 0:0',
- 'sf read 4000000 100000 10',
- 'md.b 4000000 10'])
- assert 'u-boot:Old' in ''.join(output)
+ check_file_exist(u_boot_console, disk_img, capsule_files)
- output = u_boot_console.run_command_list([
- 'sf read 4000000 150000 10',
- 'md.b 4000000 10'])
- assert 'u-boot-env:Old' in ''.join(output)
+ verify_content(u_boot_console, '100000', 'u-boot:Old')
+ verify_content(u_boot_console, '150000', 'u-boot-env:Old')
def test_efi_capsule_fw3(
self, u_boot_config, u_boot_console, efi_capsule_data):
@@ -195,45 +109,12 @@ class TestEfiCapsuleFirmwareRaw:
0x100000-0x150000: U-Boot binary (but dummy)
"""
disk_img = efi_capsule_data
+ capsule_files = ['Test01', 'Test02']
with u_boot_console.log.section('Test Case 3-a, before reboot'):
- output = u_boot_console.run_command_list([
- 'host bind 0 %s' % disk_img,
- 'printenv -e PlatformLangCodes', # workaround for terminal size determination
- 'efidebug boot add -b 1 TEST host 0:1 /helloworld.efi -s ""',
- 'efidebug boot order 1',
- 'env set -e -nv -bs -rt OsIndications =0x0000000000000004',
- 'env set dfu_alt_info "sf 0:0=u-boot-bin raw 0x100000 0x50000;u-boot-env raw 0x150000 0x200000"',
- 'env save'])
-
- # initialize contents
- output = u_boot_console.run_command_list([
- 'sf probe 0:0',
- 'fatload host 0:1 4000000 %s/u-boot.bin.old' % CAPSULE_DATA_DIR,
- 'sf write 4000000 100000 10',
- 'sf read 5000000 100000 10',
- 'md.b 5000000 10'])
- assert 'Old' in ''.join(output)
-
- output = u_boot_console.run_command_list([
- 'sf probe 0:0',
- 'fatload host 0:1 4000000 %s/u-boot.env.old' % CAPSULE_DATA_DIR,
- 'sf write 4000000 150000 10',
- 'sf read 5000000 100000 10',
- 'md.b 5000000 10'])
- assert 'Old' in ''.join(output)
-
- # place the capsule files
- output = u_boot_console.run_command_list([
- 'fatload host 0:1 4000000 %s/Test01' % CAPSULE_DATA_DIR,
- 'fatwrite host 0:1 4000000 %s/Test01 $filesize' % CAPSULE_INSTALL_DIR,
- 'fatls host 0:1 %s' % CAPSULE_INSTALL_DIR])
- assert 'Test01' in ''.join(output)
-
- output = u_boot_console.run_command_list([
- 'fatload host 0:1 4000000 %s/Test02' % CAPSULE_DATA_DIR,
- 'fatwrite host 0:1 4000000 %s/Test02 $filesize' % CAPSULE_INSTALL_DIR,
- 'fatls host 0:1 %s' % CAPSULE_INSTALL_DIR])
- assert 'Test02' in ''.join(output)
+ setup(u_boot_console, disk_img, '0x0000000000000004')
+ init_content(u_boot_console, '100000', 'u-boot.bin.old', 'Old')
+ init_content(u_boot_console, '150000', 'u-boot.env.old', 'Old')
+ place_capsule_file(u_boot_console, capsule_files)
capsule_early = u_boot_config.buildconfig.get(
'config_efi_capsule_on_disk_early')
@@ -245,18 +126,7 @@ class TestEfiCapsuleFirmwareRaw:
with u_boot_console.log.section('Test Case 3-b, after reboot'):
if not capsule_early:
- # make sure that dfu_alt_info exists even persistent variables
- # are not available.
- output = u_boot_console.run_command_list([
- 'env set dfu_alt_info "sf 0:0=u-boot-bin raw 0x100000 0x50000;u-boot-env raw 0x150000 0x200000"',
- 'host bind 0 %s' % disk_img,
- 'fatls host 0:1 %s' % CAPSULE_INSTALL_DIR])
- assert 'Test01' in ''.join(output)
- assert 'Test02' in ''.join(output)
-
- # need to run uefi command to initiate capsule handling
- output = u_boot_console.run_command(
- 'env print -e Capsule0000', wait_for_reboot = True)
+ exec_manual_update(u_boot_console, disk_img, capsule_files)
# make sure the dfu_alt_info exists because it is required for making ESRT.
output = u_boot_console.run_command_list([
@@ -269,26 +139,91 @@ class TestEfiCapsuleFirmwareRaw:
# ensure that SANDBOX_UBOOT_IMAGE_GUID is in the ESRT.
assert '09D7CF52-0720-4710-91D1-08469B7FE9C8' in ''.join(output)
- output = u_boot_console.run_command_list([
- 'host bind 0 %s' % disk_img,
- 'fatls host 0:1 %s' % CAPSULE_INSTALL_DIR])
- assert 'Test01' not in ''.join(output)
- assert 'Test02' not in ''.join(output)
+ check_file_removed(u_boot_console, disk_img, capsule_files)
- output = u_boot_console.run_command_list([
- 'sf probe 0:0',
- 'sf read 4000000 100000 10',
- 'md.b 4000000 10'])
- if capsule_auth:
- assert 'u-boot:Old' in ''.join(output)
- else:
- assert 'u-boot:New' in ''.join(output)
+ expected = 'u-boot:Old' if capsule_auth else 'u-boot:New'
+ verify_content(u_boot_console, '100000', expected)
+
+ expected = 'u-boot-env:Old' if capsule_auth else 'u-boot-env:New'
+ verify_content(u_boot_console, '150000', expected)
+ def test_efi_capsule_fw4(
+ self, u_boot_config, u_boot_console, efi_capsule_data):
+ """ Test Case 4
+ Update U-Boot on SPI Flash, raw image format with fw_version and lowest_supported_version
+ 0x100000-0x150000: U-Boot binary (but dummy)
+ 0x150000-0x200000: U-Boot environment (but dummy)
+ """
+ disk_img = efi_capsule_data
+ capsule_files = ['Test101', 'Test102']
+ with u_boot_console.log.section('Test Case 4-a, before reboot'):
+ setup(u_boot_console, disk_img, '0x0000000000000004')
+ init_content(u_boot_console, '100000', 'u-boot.bin.old', 'Old')
+ init_content(u_boot_console, '150000', 'u-boot.env.old', 'Old')
+ place_capsule_file(u_boot_console, capsule_files)
+
+ # reboot
+ do_reboot_dtb_specified(u_boot_config, u_boot_console, 'test_ver.dtb')
+
+ capsule_early = u_boot_config.buildconfig.get(
+ 'config_efi_capsule_on_disk_early')
+ capsule_auth = u_boot_config.buildconfig.get(
+ 'config_efi_capsule_authenticate')
+ with u_boot_console.log.section('Test Case 4-b, after reboot'):
+ if not capsule_early:
+ exec_manual_update(u_boot_console, disk_img, capsule_files)
+
+ # deleted anyway
+ check_file_removed(u_boot_console, disk_img, capsule_files)
+
+ # make sure the dfu_alt_info exists because it is required for making ESRT.
output = u_boot_console.run_command_list([
- 'sf probe 0:0',
- 'sf read 4000000 150000 10',
- 'md.b 4000000 10'])
+ 'env set dfu_alt_info "sf 0:0=u-boot-bin raw 0x100000 0x50000'
+ 'u-boot-env raw 0x150000 0x200000"',
+ 'efidebug capsule esrt'])
+
if capsule_auth:
- assert 'u-boot-env:Old' in ''.join(output)
+ # capsule authentication failed
+ verify_content(u_boot_console, '100000', 'u-boot:Old')
+ verify_content(u_boot_console, '150000', 'u-boot-env:Old')
else:
- assert 'u-boot-env:New' in ''.join(output)
+ # ensure that SANDBOX_UBOOT_IMAGE_GUID is in the ESRT.
+ assert '09D7CF52-0720-4710-91D1-08469B7FE9C8' in ''.join(output)
+ assert 'ESRT: fw_version=5' in ''.join(output)
+ assert 'ESRT: lowest_supported_fw_version=3' in ''.join(output)
+
+ # ensure that SANDBOX_UBOOT_ENV_IMAGE_GUID is in the ESRT.
+ assert '5A7021F5-FEF2-48B4-AABA-832E777418C0' in ''.join(output)
+ assert 'ESRT: fw_version=10' in ''.join(output)
+ assert 'ESRT: lowest_supported_fw_version=7' in ''.join(output)
+
+ verify_content(u_boot_console, '100000', 'u-boot:New')
+ verify_content(u_boot_console, '150000', 'u-boot-env:New')
+
+ def test_efi_capsule_fw5(
+ self, u_boot_config, u_boot_console, efi_capsule_data):
+ """ Test Case 5
+ Update U-Boot on SPI Flash, raw image format with fw_version and lowest_supported_version
+ but fw_version is lower than lowest_supported_version
+ No update should happen
+ 0x100000-0x150000: U-Boot binary (but dummy)
+ """
+ disk_img = efi_capsule_data
+ capsule_files = ['Test103']
+ with u_boot_console.log.section('Test Case 5-a, before reboot'):
+ setup(u_boot_console, disk_img, '0x0000000000000004')
+ init_content(u_boot_console, '100000', 'u-boot.bin.old', 'Old')
+ place_capsule_file(u_boot_console, capsule_files)
+
+ # reboot
+ do_reboot_dtb_specified(u_boot_config, u_boot_console, 'test_ver.dtb')
+
+ capsule_early = u_boot_config.buildconfig.get(
+ 'config_efi_capsule_on_disk_early')
+ with u_boot_console.log.section('Test Case 5-b, after reboot'):
+ if not capsule_early:
+ exec_manual_update(u_boot_console, disk_img, capsule_files)
+
+ check_file_removed(u_boot_console, disk_img, capsule_files)
+
+ verify_content(u_boot_console, '100000', 'u-boot:Old')
diff --git a/test/py/tests/test_efi_capsule/test_capsule_firmware_signed_fit.py b/test/py/tests/test_efi_capsule/test_capsule_firmware_signed_fit.py
index ba8429e83c..94d6c3eef0 100644
--- a/test/py/tests/test_efi_capsule/test_capsule_firmware_signed_fit.py
+++ b/test/py/tests/test_efi_capsule/test_capsule_firmware_signed_fit.py
@@ -10,7 +10,15 @@ with signed capsule files containing FIT images
"""
import pytest
-from capsule_defs import CAPSULE_DATA_DIR, CAPSULE_INSTALL_DIR
+from capsule_common import (
+ setup,
+ init_content,
+ place_capsule_file,
+ exec_manual_update,
+ check_file_removed,
+ verify_content,
+ do_reboot_dtb_specified
+)
@pytest.mark.boardspec('sandbox_flattree')
@pytest.mark.buildconfigspec('efi_capsule_firmware_fit')
@@ -37,70 +45,23 @@ class TestEfiCapsuleFirmwareSignedFit():
should pass and the firmware be updated.
"""
disk_img = efi_capsule_data
+ capsule_files = ['Test13']
with u_boot_console.log.section('Test Case 1-a, before reboot'):
- output = u_boot_console.run_command_list([
- 'host bind 0 %s' % disk_img,
- 'printenv -e PlatformLangCodes', # workaround for terminal size determination
- 'efidebug boot add -b 1 TEST host 0:1 /helloworld.efi',
- 'efidebug boot order 1',
- 'env set -e -nv -bs -rt OsIndications =0x0000000000000004',
- 'env set dfu_alt_info '
- '"sf 0:0=u-boot-bin raw 0x100000 '
- '0x50000;u-boot-env raw 0x150000 0x200000"',
- 'env save'])
-
- # initialize content
- output = u_boot_console.run_command_list([
- 'sf probe 0:0',
- 'fatload host 0:1 4000000 %s/u-boot.bin.old'
- % CAPSULE_DATA_DIR,
- 'sf write 4000000 100000 10',
- 'sf read 5000000 100000 10',
- 'md.b 5000000 10'])
- assert 'Old' in ''.join(output)
-
- # place a capsule file
- output = u_boot_console.run_command_list([
- 'fatload host 0:1 4000000 %s/Test13' % CAPSULE_DATA_DIR,
- 'fatwrite host 0:1 4000000 %s/Test13 $filesize'
- % CAPSULE_INSTALL_DIR,
- 'fatls host 0:1 %s' % CAPSULE_INSTALL_DIR])
- assert 'Test13' in ''.join(output)
-
- # reboot
- mnt_point = u_boot_config.persistent_data_dir + '/test_efi_capsule'
- u_boot_console.config.dtb = mnt_point + CAPSULE_DATA_DIR \
- + '/test_sig.dtb'
- u_boot_console.restart_uboot()
+ setup(u_boot_console, disk_img, '0x0000000000000004')
+ init_content(u_boot_console, '100000', 'u-boot.bin.old', 'Old')
+ place_capsule_file(u_boot_console, capsule_files)
+
+ do_reboot_dtb_specified(u_boot_config, u_boot_console, 'test_sig.dtb')
capsule_early = u_boot_config.buildconfig.get(
'config_efi_capsule_on_disk_early')
with u_boot_console.log.section('Test Case 1-b, after reboot'):
if not capsule_early:
- # make sure that dfu_alt_info exists even persistent variables
- # are not available.
- output = u_boot_console.run_command_list([
- 'env set dfu_alt_info '
- '"sf 0:0=u-boot-bin raw 0x100000 '
- '0x50000;u-boot-env raw 0x150000 0x200000"',
- 'host bind 0 %s' % disk_img,
- 'fatls host 0:1 %s' % CAPSULE_INSTALL_DIR])
- assert 'Test13' in ''.join(output)
-
- # need to run uefi command to initiate capsule handling
- output = u_boot_console.run_command(
- 'env print -e Capsule0000', wait_for_reboot = True)
+ exec_manual_update(u_boot_console, disk_img, capsule_files)
- output = u_boot_console.run_command_list([
- 'host bind 0 %s' % disk_img,
- 'fatls host 0:1 %s' % CAPSULE_INSTALL_DIR])
- assert 'Test13' not in ''.join(output)
+ check_file_removed(u_boot_console, disk_img, capsule_files)
- output = u_boot_console.run_command_list([
- 'sf probe 0:0',
- 'sf read 4000000 100000 10',
- 'md.b 4000000 10'])
- assert 'u-boot:New' in ''.join(output)
+ verify_content(u_boot_console, '100000', 'u-boot:New')
def test_efi_capsule_auth2(
self, u_boot_config, u_boot_console, efi_capsule_data):
@@ -113,73 +74,26 @@ class TestEfiCapsuleFirmwareSignedFit():
not be updated.
"""
disk_img = efi_capsule_data
+ capsule_files = ['Test14']
with u_boot_console.log.section('Test Case 2-a, before reboot'):
- output = u_boot_console.run_command_list([
- 'host bind 0 %s' % disk_img,
- 'printenv -e PlatformLangCodes', # workaround for terminal size determination
- 'efidebug boot add -b 1 TEST host 0:1 /helloworld.efi',
- 'efidebug boot order 1',
- 'env set -e -nv -bs -rt OsIndications =0x0000000000000004',
- 'env set dfu_alt_info '
- '"sf 0:0=u-boot-bin raw 0x100000 '
- '0x50000;u-boot-env raw 0x150000 0x200000"',
- 'env save'])
-
- # initialize content
- output = u_boot_console.run_command_list([
- 'sf probe 0:0',
- 'fatload host 0:1 4000000 %s/u-boot.bin.old'
- % CAPSULE_DATA_DIR,
- 'sf write 4000000 100000 10',
- 'sf read 5000000 100000 10',
- 'md.b 5000000 10'])
- assert 'Old' in ''.join(output)
-
- # place a capsule file
- output = u_boot_console.run_command_list([
- 'fatload host 0:1 4000000 %s/Test14' % CAPSULE_DATA_DIR,
- 'fatwrite host 0:1 4000000 %s/Test14 $filesize'
- % CAPSULE_INSTALL_DIR,
- 'fatls host 0:1 %s' % CAPSULE_INSTALL_DIR])
- assert 'Test14' in ''.join(output)
-
- # reboot
- mnt_point = u_boot_config.persistent_data_dir + '/test_efi_capsule'
- u_boot_console.config.dtb = mnt_point + CAPSULE_DATA_DIR \
- + '/test_sig.dtb'
- u_boot_console.restart_uboot()
+ setup(u_boot_console, disk_img, '0x0000000000000004')
+ init_content(u_boot_console, '100000', 'u-boot.bin.old', 'Old')
+ place_capsule_file(u_boot_console, capsule_files)
+
+ do_reboot_dtb_specified(u_boot_config, u_boot_console, 'test_sig.dtb')
capsule_early = u_boot_config.buildconfig.get(
'config_efi_capsule_on_disk_early')
with u_boot_console.log.section('Test Case 2-b, after reboot'):
if not capsule_early:
- # make sure that dfu_alt_info exists even persistent variables
- # are not available.
- output = u_boot_console.run_command_list([
- 'env set dfu_alt_info '
- '"sf 0:0=u-boot-bin raw 0x100000 '
- '0x50000;u-boot-env raw 0x150000 0x200000"',
- 'host bind 0 %s' % disk_img,
- 'fatls host 0:1 %s' % CAPSULE_INSTALL_DIR])
- assert 'Test14' in ''.join(output)
-
- # need to run uefi command to initiate capsule handling
- output = u_boot_console.run_command(
- 'env print -e Capsule0000', wait_for_reboot = True)
+ exec_manual_update(u_boot_console, disk_img, capsule_files)
# deleted any way
- output = u_boot_console.run_command_list([
- 'host bind 0 %s' % disk_img,
- 'fatls host 0:1 %s' % CAPSULE_INSTALL_DIR])
- assert 'Test14' not in ''.join(output)
+ check_file_removed(u_boot_console, disk_img, capsule_files)
# TODO: check CapsuleStatus in CapsuleXXXX
- output = u_boot_console.run_command_list([
- 'sf probe 0:0',
- 'sf read 4000000 100000 10',
- 'md.b 4000000 10'])
- assert 'u-boot:Old' in ''.join(output)
+ verify_content(u_boot_console, '100000', 'u-boot:Old')
def test_efi_capsule_auth3(
self, u_boot_config, u_boot_console, efi_capsule_data):
@@ -191,70 +105,89 @@ class TestEfiCapsuleFirmwareSignedFit():
should fail and the firmware not be updated.
"""
disk_img = efi_capsule_data
+ capsule_files = ['Test02']
with u_boot_console.log.section('Test Case 3-a, before reboot'):
- output = u_boot_console.run_command_list([
- 'host bind 0 %s' % disk_img,
- 'printenv -e PlatformLangCodes', # workaround for terminal size determination
- 'efidebug boot add -b 1 TEST host 0:1 /helloworld.efi',
- 'efidebug boot order 1',
- 'env set -e -nv -bs -rt OsIndications =0x0000000000000004',
- 'env set dfu_alt_info '
- '"sf 0:0=u-boot-bin raw 0x100000 '
- '0x50000;u-boot-env raw 0x150000 0x200000"',
- 'env save'])
-
- # initialize content
- output = u_boot_console.run_command_list([
- 'sf probe 0:0',
- 'fatload host 0:1 4000000 %s/u-boot.bin.old'
- % CAPSULE_DATA_DIR,
- 'sf write 4000000 100000 10',
- 'sf read 5000000 100000 10',
- 'md.b 5000000 10'])
- assert 'Old' in ''.join(output)
-
- # place a capsule file
- output = u_boot_console.run_command_list([
- 'fatload host 0:1 4000000 %s/Test02' % CAPSULE_DATA_DIR,
- 'fatwrite host 0:1 4000000 %s/Test02 $filesize'
- % CAPSULE_INSTALL_DIR,
- 'fatls host 0:1 %s' % CAPSULE_INSTALL_DIR])
- assert 'Test02' in ''.join(output)
-
- # reboot
- mnt_point = u_boot_config.persistent_data_dir + '/test_efi_capsule'
- u_boot_console.config.dtb = mnt_point + CAPSULE_DATA_DIR \
- + '/test_sig.dtb'
- u_boot_console.restart_uboot()
+ setup(u_boot_console, disk_img, '0x0000000000000004')
+ init_content(u_boot_console, '100000', 'u-boot.bin.old', 'Old')
+ place_capsule_file(u_boot_console, capsule_files)
+
+ do_reboot_dtb_specified(u_boot_config, u_boot_console, 'test_sig.dtb')
capsule_early = u_boot_config.buildconfig.get(
'config_efi_capsule_on_disk_early')
with u_boot_console.log.section('Test Case 3-b, after reboot'):
if not capsule_early:
- # make sure that dfu_alt_info exists even persistent variables
- # are not available.
- output = u_boot_console.run_command_list([
- 'env set dfu_alt_info '
- '"sf 0:0=u-boot-bin raw 0x100000 '
- '0x50000;u-boot-env raw 0x150000 0x200000"',
- 'host bind 0 %s' % disk_img,
- 'fatls host 0:1 %s' % CAPSULE_INSTALL_DIR])
- assert 'Test02' in ''.join(output)
-
- # need to run uefi command to initiate capsule handling
- output = u_boot_console.run_command(
- 'env print -e Capsule0000', wait_for_reboot = True)
+ exec_manual_update(u_boot_console, disk_img, capsule_files)
# deleted any way
- output = u_boot_console.run_command_list([
- 'host bind 0 %s' % disk_img,
- 'fatls host 0:1 %s' % CAPSULE_INSTALL_DIR])
- assert 'Test02' not in ''.join(output)
+ check_file_removed(u_boot_console, disk_img, capsule_files)
# TODO: check CapsuleStatus in CapsuleXXXX
+ verify_content(u_boot_console, '100000', 'u-boot:Old')
+
+ def test_efi_capsule_auth4(
+ self, u_boot_config, u_boot_console, efi_capsule_data):
+ """Test Case 4 - Update U-Boot on SPI Flash, raw image format with version information
+ 0x100000-0x150000: U-Boot binary (but dummy)
+
+ If the capsule is properly signed, the authentication
+ should pass and the firmware be updated.
+ """
+ disk_img = efi_capsule_data
+ capsule_files = ['Test114']
+ with u_boot_console.log.section('Test Case 4-a, before reboot'):
+ setup(u_boot_console, disk_img, '0x0000000000000004')
+ init_content(u_boot_console, '100000', 'u-boot.bin.old', 'Old')
+ place_capsule_file(u_boot_console, capsule_files)
+
+ do_reboot_dtb_specified(u_boot_config, u_boot_console, 'test_ver.dtb')
+
+ capsule_early = u_boot_config.buildconfig.get(
+ 'config_efi_capsule_on_disk_early')
+ with u_boot_console.log.section('Test Case 4-b, after reboot'):
+ if not capsule_early:
+ exec_manual_update(u_boot_console, disk_img, capsule_files)
+
+ check_file_removed(u_boot_console, disk_img, capsule_files)
+
output = u_boot_console.run_command_list([
- 'sf probe 0:0',
- 'sf read 4000000 100000 10',
- 'md.b 4000000 10'])
- assert 'u-boot:Old' in ''.join(output)
+ 'env set dfu_alt_info "sf 0:0=u-boot-bin raw 0x100000 0x50000;'
+ 'u-boot-env raw 0x150000 0x200000"',
+ 'efidebug capsule esrt'])
+
+ # ensure that SANDBOX_UBOOT_IMAGE_GUID is in the ESRT.
+ assert '3673B45D-6A7C-46F3-9E60-ADABB03F7937' in ''.join(output)
+ assert 'ESRT: fw_version=5' in ''.join(output)
+ assert 'ESRT: lowest_supported_fw_version=3' in ''.join(output)
+
+ verify_content(u_boot_console, '100000', 'u-boot:New')
+ verify_content(u_boot_console, '150000', 'u-boot-env:New')
+
+ def test_efi_capsule_auth5(
+ self, u_boot_config, u_boot_console, efi_capsule_data):
+ """Test Case 5 - Update U-Boot on SPI Flash, raw image format with version information
+ 0x100000-0x150000: U-Boot binary (but dummy)
+
+ If the capsule is signed but fw_version is lower than lowest
+ supported version, the authentication should fail and the firmware
+ not be updated.
+ """
+ disk_img = efi_capsule_data
+ capsule_files = ['Test115']
+ with u_boot_console.log.section('Test Case 5-a, before reboot'):
+ setup(u_boot_console, disk_img, '0x0000000000000004')
+ init_content(u_boot_console, '100000', 'u-boot.bin.old', 'Old')
+ place_capsule_file(u_boot_console, capsule_files)
+
+ do_reboot_dtb_specified(u_boot_config, u_boot_console, 'test_ver.dtb')
+
+ capsule_early = u_boot_config.buildconfig.get(
+ 'config_efi_capsule_on_disk_early')
+ with u_boot_console.log.section('Test Case 5-b, after reboot'):
+ if not capsule_early:
+ exec_manual_update(u_boot_console, disk_img, capsule_files)
+
+ check_file_removed(u_boot_console, disk_img, capsule_files)
+
+ verify_content(u_boot_console, '100000', 'u-boot:Old')
diff --git a/test/py/tests/test_efi_capsule/test_capsule_firmware_signed_raw.py b/test/py/tests/test_efi_capsule/test_capsule_firmware_signed_raw.py
index 710d9925a3..ad2b1c6324 100644
--- a/test/py/tests/test_efi_capsule/test_capsule_firmware_signed_raw.py
+++ b/test/py/tests/test_efi_capsule/test_capsule_firmware_signed_raw.py
@@ -8,7 +8,15 @@ with signed capsule files containing raw images
"""
import pytest
-from capsule_defs import CAPSULE_DATA_DIR, CAPSULE_INSTALL_DIR
+from capsule_common import (
+ setup,
+ init_content,
+ place_capsule_file,
+ exec_manual_update,
+ check_file_removed,
+ verify_content,
+ do_reboot_dtb_specified
+)
@pytest.mark.boardspec('sandbox')
@pytest.mark.buildconfigspec('efi_capsule_firmware_raw')
@@ -34,69 +42,23 @@ class TestEfiCapsuleFirmwareSignedRaw():
should pass and the firmware be updated.
"""
disk_img = efi_capsule_data
+ capsule_files = ['Test11']
with u_boot_console.log.section('Test Case 1-a, before reboot'):
- output = u_boot_console.run_command_list([
- 'host bind 0 %s' % disk_img,
- 'efidebug boot add -b 1 TEST host 0:1 /helloworld.efi',
- 'efidebug boot order 1',
- 'env set -e -nv -bs -rt OsIndications =0x0000000000000004',
- 'env set dfu_alt_info '
- '"sf 0:0=u-boot-bin raw 0x100000 '
- '0x50000;u-boot-env raw 0x150000 0x200000"',
- 'env save'])
-
- # initialize content
- output = u_boot_console.run_command_list([
- 'sf probe 0:0',
- 'fatload host 0:1 4000000 %s/u-boot.bin.old'
- % CAPSULE_DATA_DIR,
- 'sf write 4000000 100000 10',
- 'sf read 5000000 100000 10',
- 'md.b 5000000 10'])
- assert 'Old' in ''.join(output)
-
- # place a capsule file
- output = u_boot_console.run_command_list([
- 'fatload host 0:1 4000000 %s/Test11' % CAPSULE_DATA_DIR,
- 'fatwrite host 0:1 4000000 %s/Test11 $filesize'
- % CAPSULE_INSTALL_DIR,
- 'fatls host 0:1 %s' % CAPSULE_INSTALL_DIR])
- assert 'Test11' in ''.join(output)
-
- # reboot
- mnt_point = u_boot_config.persistent_data_dir + '/test_efi_capsule'
- u_boot_console.config.dtb = mnt_point + CAPSULE_DATA_DIR \
- + '/test_sig.dtb'
- u_boot_console.restart_uboot()
+ setup(u_boot_console, disk_img, '0x0000000000000004')
+ init_content(u_boot_console, '100000', 'u-boot.bin.old', 'Old')
+ place_capsule_file(u_boot_console, capsule_files)
+
+ do_reboot_dtb_specified(u_boot_config, u_boot_console, 'test_sig.dtb')
capsule_early = u_boot_config.buildconfig.get(
'config_efi_capsule_on_disk_early')
with u_boot_console.log.section('Test Case 1-b, after reboot'):
if not capsule_early:
- # make sure that dfu_alt_info exists even persistent variables
- # are not available.
- output = u_boot_console.run_command_list([
- 'env set dfu_alt_info '
- '"sf 0:0=u-boot-bin raw 0x100000 '
- '0x50000;u-boot-env raw 0x150000 0x200000"',
- 'host bind 0 %s' % disk_img,
- 'fatls host 0:1 %s' % CAPSULE_INSTALL_DIR])
- assert 'Test11' in ''.join(output)
-
- # need to run uefi command to initiate capsule handling
- output = u_boot_console.run_command(
- 'env print -e Capsule0000', wait_for_reboot = True)
+ exec_manual_update(u_boot_console, disk_img, capsule_files)
- output = u_boot_console.run_command_list([
- 'host bind 0 %s' % disk_img,
- 'fatls host 0:1 %s' % CAPSULE_INSTALL_DIR])
- assert 'Test11' not in ''.join(output)
+ check_file_removed(u_boot_console, disk_img, capsule_files)
- output = u_boot_console.run_command_list([
- 'sf probe 0:0',
- 'sf read 4000000 100000 10',
- 'md.b 4000000 10'])
- assert 'u-boot:New' in ''.join(output)
+ verify_content(u_boot_console, '100000', 'u-boot:New')
def test_efi_capsule_auth2(
self, u_boot_config, u_boot_console, efi_capsule_data):
@@ -108,73 +70,25 @@ class TestEfiCapsuleFirmwareSignedRaw():
not be updated.
"""
disk_img = efi_capsule_data
+ capsule_files = ['Test12']
with u_boot_console.log.section('Test Case 2-a, before reboot'):
- output = u_boot_console.run_command_list([
- 'host bind 0 %s' % disk_img,
- 'printenv -e PlatformLangCodes', # workaround for terminal size determination
- 'efidebug boot add -b 1 TEST host 0:1 /helloworld.efi',
- 'efidebug boot order 1',
- 'env set -e -nv -bs -rt OsIndications =0x0000000000000004',
- 'env set dfu_alt_info '
- '"sf 0:0=u-boot-bin raw 0x100000 '
- '0x50000;u-boot-env raw 0x150000 0x200000"',
- 'env save'])
-
- # initialize content
- output = u_boot_console.run_command_list([
- 'sf probe 0:0',
- 'fatload host 0:1 4000000 %s/u-boot.bin.old'
- % CAPSULE_DATA_DIR,
- 'sf write 4000000 100000 10',
- 'sf read 5000000 100000 10',
- 'md.b 5000000 10'])
- assert 'Old' in ''.join(output)
-
- # place a capsule file
- output = u_boot_console.run_command_list([
- 'fatload host 0:1 4000000 %s/Test12' % CAPSULE_DATA_DIR,
- 'fatwrite host 0:1 4000000 %s/Test12 $filesize'
- % CAPSULE_INSTALL_DIR,
- 'fatls host 0:1 %s' % CAPSULE_INSTALL_DIR])
- assert 'Test12' in ''.join(output)
-
- # reboot
- mnt_point = u_boot_config.persistent_data_dir + '/test_efi_capsule'
- u_boot_console.config.dtb = mnt_point + CAPSULE_DATA_DIR \
- + '/test_sig.dtb'
- u_boot_console.restart_uboot()
+ setup(u_boot_console, disk_img, '0x0000000000000004')
+ init_content(u_boot_console, '100000', 'u-boot.bin.old', 'Old')
+ place_capsule_file(u_boot_console, capsule_files)
+
+ do_reboot_dtb_specified(u_boot_config, u_boot_console, 'test_sig.dtb')
capsule_early = u_boot_config.buildconfig.get(
'config_efi_capsule_on_disk_early')
with u_boot_console.log.section('Test Case 2-b, after reboot'):
if not capsule_early:
- # make sure that dfu_alt_info exists even persistent variables
- # are not available.
- output = u_boot_console.run_command_list([
- 'env set dfu_alt_info '
- '"sf 0:0=u-boot-bin raw 0x100000 '
- '0x50000;u-boot-env raw 0x150000 0x200000"',
- 'host bind 0 %s' % disk_img,
- 'fatls host 0:1 %s' % CAPSULE_INSTALL_DIR])
- assert 'Test12' in ''.join(output)
-
- # need to run uefi command to initiate capsule handling
- output = u_boot_console.run_command(
- 'env print -e Capsule0000', wait_for_reboot = True)
-
- # deleted any way
- output = u_boot_console.run_command_list([
- 'host bind 0 %s' % disk_img,
- 'fatls host 0:1 %s' % CAPSULE_INSTALL_DIR])
- assert 'Test12' not in ''.join(output)
+ exec_manual_update(u_boot_console, disk_img, capsule_files)
+
+ check_file_removed(u_boot_console, disk_img, capsule_files)
# TODO: check CapsuleStatus in CapsuleXXXX
- output = u_boot_console.run_command_list([
- 'sf probe 0:0',
- 'sf read 4000000 100000 10',
- 'md.b 4000000 10'])
- assert 'u-boot:Old' in ''.join(output)
+ verify_content(u_boot_console, '100000', 'u-boot:Old')
def test_efi_capsule_auth3(
self, u_boot_config, u_boot_console, efi_capsule_data):
@@ -185,70 +99,94 @@ class TestEfiCapsuleFirmwareSignedRaw():
should fail and the firmware not be updated.
"""
disk_img = efi_capsule_data
+ capsule_files = ['Test02']
with u_boot_console.log.section('Test Case 3-a, before reboot'):
- output = u_boot_console.run_command_list([
- 'host bind 0 %s' % disk_img,
- 'printenv -e PlatformLangCodes', # workaround for terminal size determination
- 'efidebug boot add -b 1 TEST host 0:1 /helloworld.efi',
- 'efidebug boot order 1',
- 'env set -e -nv -bs -rt OsIndications =0x0000000000000004',
- 'env set dfu_alt_info '
- '"sf 0:0=u-boot-bin raw 0x100000 '
- '0x50000;u-boot-env raw 0x150000 0x200000"',
- 'env save'])
-
- # initialize content
- output = u_boot_console.run_command_list([
- 'sf probe 0:0',
- 'fatload host 0:1 4000000 %s/u-boot.bin.old'
- % CAPSULE_DATA_DIR,
- 'sf write 4000000 100000 10',
- 'sf read 5000000 100000 10',
- 'md.b 5000000 10'])
- assert 'Old' in ''.join(output)
-
- # place a capsule file
- output = u_boot_console.run_command_list([
- 'fatload host 0:1 4000000 %s/Test02' % CAPSULE_DATA_DIR,
- 'fatwrite host 0:1 4000000 %s/Test02 $filesize'
- % CAPSULE_INSTALL_DIR,
- 'fatls host 0:1 %s' % CAPSULE_INSTALL_DIR])
- assert 'Test02' in ''.join(output)
-
- # reboot
- mnt_point = u_boot_config.persistent_data_dir + '/test_efi_capsule'
- u_boot_console.config.dtb = mnt_point + CAPSULE_DATA_DIR \
- + '/test_sig.dtb'
- u_boot_console.restart_uboot()
+ setup(u_boot_console, disk_img, '0x0000000000000004')
+ init_content(u_boot_console, '100000', 'u-boot.bin.old', 'Old')
+ place_capsule_file(u_boot_console, capsule_files)
+
+ do_reboot_dtb_specified(u_boot_config, u_boot_console, 'test_sig.dtb')
capsule_early = u_boot_config.buildconfig.get(
'config_efi_capsule_on_disk_early')
with u_boot_console.log.section('Test Case 3-b, after reboot'):
if not capsule_early:
- # make sure that dfu_alt_info exists even persistent variables
- # are not available.
- output = u_boot_console.run_command_list([
- 'env set dfu_alt_info '
- '"sf 0:0=u-boot-bin raw 0x100000 '
- '0x50000;u-boot-env raw 0x150000 0x200000"',
- 'host bind 0 %s' % disk_img,
- 'fatls host 0:1 %s' % CAPSULE_INSTALL_DIR])
- assert 'Test02' in ''.join(output)
-
- # need to run uefi command to initiate capsule handling
- output = u_boot_console.run_command(
- 'env print -e Capsule0000', wait_for_reboot = True)
+ exec_manual_update(u_boot_console, disk_img, capsule_files)
# deleted anyway
- output = u_boot_console.run_command_list([
- 'host bind 0 %s' % disk_img,
- 'fatls host 0:1 %s' % CAPSULE_INSTALL_DIR])
- assert 'Test02' not in ''.join(output)
+ check_file_removed(u_boot_console, disk_img, capsule_files)
# TODO: check CapsuleStatus in CapsuleXXXX
+ verify_content(u_boot_console, '100000', 'u-boot:Old')
+
+ def test_efi_capsule_auth4(
+ self, u_boot_config, u_boot_console, efi_capsule_data):
+ """Test Case 4 - Update U-Boot on SPI Flash, raw image format with version information
+ 0x100000-0x150000: U-Boot binary (but dummy)
+
+ If the capsule is properly signed, the authentication
+ should pass and the firmware be updated.
+ """
+ disk_img = efi_capsule_data
+ capsule_files = ['Test111', 'Test112']
+ with u_boot_console.log.section('Test Case 4-a, before reboot'):
+ setup(u_boot_console, disk_img, '0x0000000000000004')
+ init_content(u_boot_console, '100000', 'u-boot.bin.old', 'Old')
+ place_capsule_file(u_boot_console, capsule_files)
+
+ do_reboot_dtb_specified(u_boot_config, u_boot_console, 'test_ver.dtb')
+
+ capsule_early = u_boot_config.buildconfig.get(
+ 'config_efi_capsule_on_disk_early')
+ with u_boot_console.log.section('Test Case 4-b, after reboot'):
+ if not capsule_early:
+ exec_manual_update(u_boot_console, disk_img, capsule_files)
+
+ check_file_removed(u_boot_console, disk_img, capsule_files)
+
output = u_boot_console.run_command_list([
- 'sf probe 0:0',
- 'sf read 4000000 100000 10',
- 'md.b 4000000 10'])
- assert 'u-boot:Old' in ''.join(output)
+ 'env set dfu_alt_info "sf 0:0=u-boot-bin raw 0x100000 0x50000;'
+ 'u-boot-env raw 0x150000 0x200000"',
+ 'efidebug capsule esrt'])
+
+ # ensure that SANDBOX_UBOOT_IMAGE_GUID is in the ESRT.
+ assert '09D7CF52-0720-4710-91D1-08469B7FE9C8' in ''.join(output)
+ assert 'ESRT: fw_version=5' in ''.join(output)
+ assert 'ESRT: lowest_supported_fw_version=3' in ''.join(output)
+
+ # ensure that SANDBOX_UBOOT_ENV_IMAGE_GUID is in the ESRT.
+ assert '5A7021F5-FEF2-48B4-AABA-832E777418C0' in ''.join(output)
+ assert 'ESRT: fw_version=10' in ''.join(output)
+ assert 'ESRT: lowest_supported_fw_version=7' in ''.join(output)
+
+ verify_content(u_boot_console, '100000', 'u-boot:New')
+ verify_content(u_boot_console, '150000', 'u-boot-env:New')
+
+ def test_efi_capsule_auth5(
+ self, u_boot_config, u_boot_console, efi_capsule_data):
+ """Test Case 5 - Update U-Boot on SPI Flash, raw image format with version information
+ 0x100000-0x150000: U-Boot binary (but dummy)
+
+ If the capsule is signed but fw_version is lower than lowest
+ supported version, the authentication should fail and the firmware
+ not be updated.
+ """
+ disk_img = efi_capsule_data
+ capsule_files = ['Test113']
+ with u_boot_console.log.section('Test Case 5-a, before reboot'):
+ setup(u_boot_console, disk_img, '0x0000000000000004')
+ init_content(u_boot_console, '100000', 'u-boot.bin.old', 'Old')
+ place_capsule_file(u_boot_console, capsule_files)
+
+ do_reboot_dtb_specified(u_boot_config, u_boot_console, 'test_ver.dtb')
+
+ capsule_early = u_boot_config.buildconfig.get(
+ 'config_efi_capsule_on_disk_early')
+ with u_boot_console.log.section('Test Case 5-b, after reboot'):
+ if not capsule_early:
+ exec_manual_update(u_boot_console, disk_img, capsule_files)
+
+ check_file_removed(u_boot_console, disk_img, capsule_files)
+
+ verify_content(u_boot_console, '100000', 'u-boot:Old')
diff --git a/test/py/tests/test_efi_capsule/version.dts b/test/py/tests/test_efi_capsule/version.dts
new file mode 100644
index 0000000000..07850cc606
--- /dev/null
+++ b/test/py/tests/test_efi_capsule/version.dts
@@ -0,0 +1,24 @@
+// SPDX-License-Identifier: GPL-2.0+
+
+/dts-v1/;
+/plugin/;
+
+&{/} {
+ firmware-version {
+ image1 {
+ lowest-supported-version = <3>;
+ image-index = <1>;
+ image-type-id = "09D7CF52-0720-4710-91D1-08469B7FE9C8";
+ };
+ image2 {
+ lowest-supported-version = <7>;
+ image-index = <2>;
+ image-type-id = "5A7021F5-FEF2-48B4-AABA-832E777418C0";
+ };
+ image3 {
+ lowest-supported-version = <3>;
+ image-index = <1>;
+ image-type-id = "3673B45D-6A7C-46F3-9E60-ADABB03F7937";
+ };
+ };
+};
diff --git a/test/py/tests/test_efi_secboot/conftest.py b/test/py/tests/test_efi_secboot/conftest.py
index 30ff702943..ff7ac7c810 100644
--- a/test/py/tests/test_efi_secboot/conftest.py
+++ b/test/py/tests/test_efi_secboot/conftest.py
@@ -14,7 +14,7 @@ def efi_boot_env(request, u_boot_config):
Args:
request: Pytest request object.
- u_boot_config: U-boot configuration.
+ u_boot_config: U-Boot configuration.
Return:
A path to disk image to be used for testing
@@ -139,7 +139,7 @@ def efi_boot_env_intca(request, u_boot_config):
Args:
request: Pytest request object.
- u_boot_config: U-boot configuration.
+ u_boot_config: U-Boot configuration.
Return:
A path to disk image to be used for testing
diff --git a/test/py/tests/test_eficonfig/conftest.py b/test/py/tests/test_eficonfig/conftest.py
index f289df0362..0a82fbefd7 100644
--- a/test/py/tests/test_eficonfig/conftest.py
+++ b/test/py/tests/test_eficonfig/conftest.py
@@ -14,7 +14,7 @@ def efi_eficonfig_data(u_boot_config):
tests
Args:
- u_boot_config -- U-boot configuration.
+ u_boot_config -- U-Boot configuration.
Return:
A path to disk image to be used for testing
diff --git a/test/py/tests/test_fs/conftest.py b/test/py/tests/test_fs/conftest.py
index 9329ec6f1b..0d87d180c7 100644
--- a/test/py/tests/test_fs/conftest.py
+++ b/test/py/tests/test_fs/conftest.py
@@ -97,7 +97,7 @@ def pytest_generate_tests(metafunc):
# Helper functions
#
def fstype_to_ubname(fs_type):
- """Convert a file system type to an U-boot specific string
+ """Convert a file system type to an U-Boot specific string
A generated string can be used as part of file system related commands
or a config name in u-boot. Currently fat16 and fat32 are handled
@@ -217,7 +217,7 @@ def fs_obj_basic(request, u_boot_config):
Args:
request: Pytest request object.
- u_boot_config: U-boot configuration.
+ u_boot_config: U-Boot configuration.
Return:
A fixture for basic fs test, i.e. a triplet of file system type,
@@ -339,7 +339,7 @@ def fs_obj_ext(request, u_boot_config):
Args:
request: Pytest request object.
- u_boot_config: U-boot configuration.
+ u_boot_config: U-Boot configuration.
Return:
A fixture for extended fs test, i.e. a triplet of file system type,
@@ -440,7 +440,7 @@ def fs_obj_mkdir(request, u_boot_config):
Args:
request: Pytest request object.
- u_boot_config: U-boot configuration.
+ u_boot_config: U-Boot configuration.
Return:
A fixture for mkdir test, i.e. a duplet of file system type and
@@ -471,7 +471,7 @@ def fs_obj_unlink(request, u_boot_config):
Args:
request: Pytest request object.
- u_boot_config: U-boot configuration.
+ u_boot_config: U-Boot configuration.
Return:
A fixture for unlink test, i.e. a duplet of file system type and
@@ -551,7 +551,7 @@ def fs_obj_symlink(request, u_boot_config):
Args:
request: Pytest request object.
- u_boot_config: U-boot configuration.
+ u_boot_config: U-Boot configuration.
Return:
A fixture for basic fs test, i.e. a triplet of file system type,
diff --git a/test/py/tests/test_scp03.py b/test/py/tests/test_scp03.py
index 1f689252dd..1a104b365f 100644
--- a/test/py/tests/test_scp03.py
+++ b/test/py/tests/test_scp03.py
@@ -5,7 +5,7 @@
# SCP03 command test
"""
-This tests SCP03 command in U-boot.
+This tests SCP03 command in U-Boot.
For additional details check doc/usage/scp03.rst
"""
diff --git a/test/py/tests/test_tpm2.py b/test/py/tests/test_tpm2.py
index d2ad6f9e73..fce689cd99 100644
--- a/test/py/tests/test_tpm2.py
+++ b/test/py/tests/test_tpm2.py
@@ -41,11 +41,9 @@ def force_init(u_boot_console, force=False):
skip_test = u_boot_console.config.env.get('env__tpm_device_test_skip', False)
if skip_test:
pytest.skip('skip TPM device test')
- output = u_boot_console.run_command('tpm2 init')
+ output = u_boot_console.run_command('tpm2 autostart')
if force or not 'Error' in output:
u_boot_console.run_command('echo --- start of init ---')
- u_boot_console.run_command('tpm2 startup TPM2_SU_CLEAR')
- u_boot_console.run_command('tpm2 self_test full')
u_boot_console.run_command('tpm2 clear TPM2_RH_LOCKOUT')
output = u_boot_console.run_command('echo $?')
if not output.endswith('0'):
@@ -83,20 +81,13 @@ def tpm2_sandbox_init(u_boot_console):
This allows all tests to run in parallel, since no test depends on another.
"""
u_boot_console.restart_uboot()
- u_boot_console.run_command('tpm2 init')
+ u_boot_console.run_command('tpm2 autostart')
output = u_boot_console.run_command('echo $?')
assert output.endswith('0')
skip_test = u_boot_console.config.env.get('env__tpm_device_test_skip', False)
if skip_test:
pytest.skip('skip TPM device test')
- u_boot_console.run_command('tpm2 startup TPM2_SU_CLEAR')
- output = u_boot_console.run_command('echo $?')
- assert output.endswith('0')
-
- u_boot_console.run_command('tpm2 self_test full')
- output = u_boot_console.run_command('echo $?')
- assert output.endswith('0')
@pytest.mark.buildconfigspec('cmd_tpm_v2')
def test_tpm2_sandbox_self_test_full(u_boot_console):
@@ -281,6 +272,12 @@ def test_tpm2_pcr_extend(u_boot_console):
force_init(u_boot_console)
ram = u_boot_utils.find_ram_base(u_boot_console)
+ read_pcr = u_boot_console.run_command('tpm2 pcr_read 0 0x%x' % (ram + 0x20))
+ output = u_boot_console.run_command('echo $?')
+ assert output.endswith('0')
+ str = re.findall(r'\d+ known updates', read_pcr)[0]
+ updates = int(re.findall(r'\d+', str)[0])
+
u_boot_console.run_command('tpm2 pcr_extend 0 0x%x' % ram)
output = u_boot_console.run_command('echo $?')
assert output.endswith('0')
diff --git a/test/py/tests/test_xxd/conftest.py b/test/py/tests/test_xxd/conftest.py
index 59285aadf4..f35b8f1113 100644
--- a/test/py/tests/test_xxd/conftest.py
+++ b/test/py/tests/test_xxd/conftest.py
@@ -13,7 +13,7 @@ def xxd_data(u_boot_config):
"""Set up a file system to be used in xxd tests
Args:
- u_boot_config -- U-boot configuration.
+ u_boot_config -- U-Boot configuration.
"""
mnt_point = u_boot_config.persistent_data_dir + '/test_xxd'
image_path = u_boot_config.persistent_data_dir + '/xxd.img'