From: Ana Bobillo <[email protected]>

Add capsule on disk tests for the checks that need a capsule file or a
signed capsule:

- a capsule file shorter than the capsule header;
- signed capsules whose FMP payload header has a header_size smaller
  than the header or larger than the image.

None of them may update the firmware, and each file is removed.

Signed-off-by: Ana Bobillo <[email protected]>
---
Changes in v2:
- New patch: capsule on disk tests for patches 1 and 5 (Heinrich)

 arch/sandbox/dts/sandbox_capsule.dtsi         | 52 +++++++++++++++++
 .../test_capsule_firmware_raw.py              | 34 +++++++++++
 .../test_capsule_firmware_signed_raw.py       | 56 +++++++++++++++++++
 3 files changed, 142 insertions(+)

diff --git a/arch/sandbox/dts/sandbox_capsule.dtsi 
b/arch/sandbox/dts/sandbox_capsule.dtsi
index 34d29916b30..f7418f9794a 100644
--- a/arch/sandbox/dts/sandbox_capsule.dtsi
+++ b/arch/sandbox/dts/sandbox_capsule.dtsi
@@ -166,4 +166,56 @@
                        };
                };
        };
+
+       capsule12 {
+               filename = "Test116";
+               efi-capsule {
+                       image-index = <0x1>;
+                       image-guid = SANDBOX_UBOOT_IMAGE_GUID;
+                       private-key = CAPSULE_PRIV_KEY;
+                       public-key-cert = CAPSULE_PUB_KEY;
+                       monotonic-count = <0x1>;
+
+                       /* FMP payload header, header_size 0: smaller than the 
header */
+                       payload-header {
+                               type = "text";
+                               text = "MSS1";
+                       };
+
+                       payload-header-rest {
+                               type = "fill";
+                               size = <12>;
+                       };
+
+                       text {
+                               text = "u-boot:New";
+                       };
+               };
+       };
+
+       capsule13 {
+               filename = "Test117";
+               efi-capsule {
+                       image-index = <0x1>;
+                       image-guid = SANDBOX_UBOOT_IMAGE_GUID;
+                       private-key = CAPSULE_PRIV_KEY;
+                       public-key-cert = CAPSULE_PUB_KEY;
+                       monotonic-count = <0x1>;
+
+                       /* FMP payload header, header_size 64: larger than the 
image */
+                       payload-header {
+                               type = "text";
+                               text = "MSS1\x40";
+                       };
+
+                       payload-header-rest {
+                               type = "fill";
+                               size = <11>;
+                       };
+
+                       text {
+                               text = "u-boot:New";
+                       };
+               };
+       };
 };
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 b8cb483b380..a79a975c67e 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,6 +7,7 @@ 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 (
     capsule_setup,
     init_content,
@@ -238,3 +239,36 @@ class TestEfiCapsuleFirmwareRaw:
             check_file_removed(ubman, disk_img, capsule_files)
 
             verify_content(ubman, '100000', 'u-boot:Old')
+
+    def test_efi_capsule_fw6(
+            self, u_boot_config, ubman, efi_capsule_data):
+        """ Test Case 6
+        Update U-Boot on SPI Flash with a capsule file shorter than
+        the capsule header
+        No update should happen
+        0x100000-0x150000: U-Boot binary (but dummy)
+        """
+        disk_img = efi_capsule_data
+        capsule_files = ['Test01']
+        with ubman.log.section('Test Case 6-a, before reboot'):
+            capsule_setup(ubman, disk_img, '0x0000000000000004')
+            init_content(ubman, '100000', 'u-boot.bin.old', 'Old')
+            # place only the first 16 bytes of the capsule file
+            ubman.run_command_list([
+                f'fatload host 0:1 4000000 {CAPSULE_DATA_DIR}/Test01',
+                f'fatwrite host 0:1 4000000 {CAPSULE_INSTALL_DIR}/Test01 10'])
+
+        capsule_early = u_boot_config.buildconfig.get(
+            'config_efi_capsule_on_disk_early')
+
+        # reboot
+        ubman.restart_uboot(expect_reset = capsule_early)
+
+        with ubman.log.section('Test Case 6-b, after reboot'):
+            if not capsule_early:
+                exec_manual_update(ubman, disk_img, capsule_files)
+
+            # deleted anyway
+            check_file_removed(ubman, disk_img, capsule_files)
+
+            verify_content(ubman, '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 a500c499bb9..6e4cca9bfe6 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
@@ -190,3 +190,59 @@ class TestEfiCapsuleFirmwareSignedRaw():
             check_file_removed(ubman, disk_img, capsule_files)
 
             verify_content(ubman, '100000', 'u-boot:Old')
+
+    def test_efi_capsule_auth6(
+            self, u_boot_config, ubman, efi_capsule_data):
+        """Test Case 6 - Update U-Boot on SPI Flash, raw image format
+        0x100000-0x150000: U-Boot binary (but dummy)
+
+        If the capsule is properly signed but the header_size of the
+        FMP payload header in its image is smaller than the header,
+        the firmware should not be updated.
+        """
+        disk_img = efi_capsule_data
+        capsule_files = ['Test116']
+        with ubman.log.section('Test Case 6-a, before reboot'):
+            capsule_setup(ubman, disk_img, '0x0000000000000004')
+            init_content(ubman, '100000', 'u-boot.bin.old', 'Old')
+            place_capsule_file(ubman, capsule_files)
+
+        do_reboot_dtb_specified(u_boot_config, ubman, 'test_sig.dtb')
+
+        capsule_early = u_boot_config.buildconfig.get(
+            'config_efi_capsule_on_disk_early')
+        with ubman.log.section('Test Case 6-b, after reboot'):
+            if not capsule_early:
+                exec_manual_update(ubman, disk_img, capsule_files)
+
+            check_file_removed(ubman, disk_img, capsule_files)
+
+            verify_content(ubman, '100000', 'u-boot:Old')
+
+    def test_efi_capsule_auth7(
+            self, u_boot_config, ubman, efi_capsule_data):
+        """Test Case 7 - Update U-Boot on SPI Flash, raw image format
+        0x100000-0x150000: U-Boot binary (but dummy)
+
+        If the capsule is properly signed but the header_size of the
+        FMP payload header in its image is larger than the image,
+        the firmware should not be updated.
+        """
+        disk_img = efi_capsule_data
+        capsule_files = ['Test117']
+        with ubman.log.section('Test Case 7-a, before reboot'):
+            capsule_setup(ubman, disk_img, '0x0000000000000004')
+            init_content(ubman, '100000', 'u-boot.bin.old', 'Old')
+            place_capsule_file(ubman, capsule_files)
+
+        do_reboot_dtb_specified(u_boot_config, ubman, 'test_sig.dtb')
+
+        capsule_early = u_boot_config.buildconfig.get(
+            'config_efi_capsule_on_disk_early')
+        with ubman.log.section('Test Case 7-b, after reboot'):
+            if not capsule_early:
+                exec_manual_update(ubman, disk_img, capsule_files)
+
+            check_file_removed(ubman, disk_img, capsule_files)
+
+            verify_content(ubman, '100000', 'u-boot:Old')

Reply via email to