blob: c057e36383f9cfaa3bf0dfdd89057ec56acd6f24 [file] [log] [blame]
Love Kumarb32a3d22024-01-19 15:31:29 +05301# SPDX-License-Identifier: GPL-2.0
2# (C) Copyright 2023, Advanced Micro Devices, Inc.
3
4import pytest
5import re
Simon Glassfb916372025-02-09 09:07:15 -07006import utils
Love Kumarb32a3d22024-01-19 15:31:29 +05307import test_net
8
9"""
10This test verifies different type of secure boot images loaded at the DDR for
11AMD's ZynqMP SoC.
12
13Note: This test relies on boardenv_* containing configuration values to define
14the files to be used for testing. Without this, this test will be automatically
15skipped. It also relies on dhcp or setup_static net test to support tftp to
16load files from a TFTP server.
17
18For example:
19
20# Details regarding the files that may be read from a TFTP server. This
21# variable may be omitted or set to None if zynqmp secure testing is not
22# possible or desired.
23env__zynqmp_secure_readable_file = {
24 'fn': 'auth_bhdr_ppk1.bin',
25 'enckupfn': 'auth_bhdr_enc_kup_load.bin',
26 'addr': 0x1000000,
27 'keyaddr': 0x100000,
28 'keyfn': 'aes.txt',
29}
30"""
31
32@pytest.mark.buildconfigspec('cmd_zynqmp')
Simon Glassddba5202025-02-09 09:07:14 -070033def test_zynqmp_secure_boot_image(ubman):
Love Kumarb32a3d22024-01-19 15:31:29 +053034 """This test verifies secure boot image at the DDR address for
35 authentication only case.
36 """
37
Simon Glassddba5202025-02-09 09:07:14 -070038 f = ubman.config.env.get('env__zynqmp_secure_readable_file', None)
Love Kumarb32a3d22024-01-19 15:31:29 +053039 if not f:
40 pytest.skip('No TFTP readable file for zynqmp secure cases to read')
41
Simon Glassddba5202025-02-09 09:07:14 -070042 test_net.test_net_dhcp(ubman)
Love Kumarb32a3d22024-01-19 15:31:29 +053043 if not test_net.net_set_up:
Simon Glassddba5202025-02-09 09:07:14 -070044 test_net.test_net_setup_static(ubman)
Love Kumarb32a3d22024-01-19 15:31:29 +053045
46 addr = f.get('addr', None)
47 if not addr:
Simon Glassfb916372025-02-09 09:07:15 -070048 addr = utils.find_ram_base(ubman)
Love Kumarb32a3d22024-01-19 15:31:29 +053049
50 expected_tftp = 'Bytes transferred = '
51 fn = f['fn']
Simon Glassddba5202025-02-09 09:07:14 -070052 output = ubman.run_command('tftpboot %x %s' % (addr, fn))
Love Kumarb32a3d22024-01-19 15:31:29 +053053 assert expected_tftp in output
54
Simon Glassddba5202025-02-09 09:07:14 -070055 output = ubman.run_command('zynqmp secure %x $filesize' % (addr))
Love Kumarb32a3d22024-01-19 15:31:29 +053056 assert 'Verified image at' in output
57 ver_addr = re.search(r'Verified image at 0x(.+)', output).group(1)
Simon Glassddba5202025-02-09 09:07:14 -070058 output = ubman.run_command('echo $?')
Love Kumarb32a3d22024-01-19 15:31:29 +053059 assert output.endswith('0')
Simon Glassddba5202025-02-09 09:07:14 -070060 output = ubman.run_command('print zynqmp_verified_img_addr')
Love Kumarb32a3d22024-01-19 15:31:29 +053061 assert f'zynqmp_verified_img_addr={ver_addr}' in output
62 assert 'Error' not in output
63
64
65@pytest.mark.buildconfigspec('cmd_zynqmp')
Simon Glassddba5202025-02-09 09:07:14 -070066def test_zynqmp_secure_boot_img_kup(ubman):
Love Kumarb32a3d22024-01-19 15:31:29 +053067 """This test verifies secure boot image at the DDR address for encryption
68 with kup key case.
69 """
70
Simon Glassddba5202025-02-09 09:07:14 -070071 f = ubman.config.env.get('env__zynqmp_secure_readable_file', None)
Love Kumarb32a3d22024-01-19 15:31:29 +053072 if not f:
73 pytest.skip('No TFTP readable file for zynqmp secure cases to read')
74
Simon Glassddba5202025-02-09 09:07:14 -070075 test_net.test_net_dhcp(ubman)
Love Kumarb32a3d22024-01-19 15:31:29 +053076 if not test_net.net_set_up:
Simon Glassddba5202025-02-09 09:07:14 -070077 test_net.test_net_setup_static(ubman)
Love Kumarb32a3d22024-01-19 15:31:29 +053078
79 keyaddr = f.get('keyaddr', None)
80 if not keyaddr:
Simon Glassfb916372025-02-09 09:07:15 -070081 addr = utils.find_ram_base(ubman)
Love Kumarb32a3d22024-01-19 15:31:29 +053082 expected_tftp = 'Bytes transferred = '
83 keyfn = f['keyfn']
Simon Glassddba5202025-02-09 09:07:14 -070084 output = ubman.run_command('tftpboot %x %s' % (keyaddr, keyfn))
Love Kumarb32a3d22024-01-19 15:31:29 +053085 assert expected_tftp in output
86
87 addr = f.get('addr', None)
88 if not addr:
Simon Glassfb916372025-02-09 09:07:15 -070089 addr = utils.find_ram_base(ubman)
Love Kumarb32a3d22024-01-19 15:31:29 +053090 expected_tftp = 'Bytes transferred = '
91 fn = f['enckupfn']
Simon Glassddba5202025-02-09 09:07:14 -070092 output = ubman.run_command('tftpboot %x %s' % (addr, fn))
Love Kumarb32a3d22024-01-19 15:31:29 +053093 assert expected_tftp in output
94
Simon Glassddba5202025-02-09 09:07:14 -070095 output = ubman.run_command(
Love Kumarb32a3d22024-01-19 15:31:29 +053096 'zynqmp secure %x $filesize %x' % (addr, keyaddr)
97 )
98 assert 'Verified image at' in output
99 ver_addr = re.search(r'Verified image at 0x(.+)', output).group(1)
Simon Glassddba5202025-02-09 09:07:14 -0700100 output = ubman.run_command('echo $?')
Love Kumarb32a3d22024-01-19 15:31:29 +0530101 assert output.endswith('0')
Simon Glassddba5202025-02-09 09:07:14 -0700102 output = ubman.run_command('print zynqmp_verified_img_addr')
Love Kumarb32a3d22024-01-19 15:31:29 +0530103 assert f'zynqmp_verified_img_addr={ver_addr}' in output
104 assert 'Error' not in output