blob: f066a03b182c0611d6e6fa9b7583ea3f55f6cbfa [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 to authentication and
11decryption using AES and RSA features for AMD's Zynq SoC.
12
13Note: This test relies on boardenv_* containing configuration values to define
14the network available and files to be used for testing. Without this, this test
15will be automatically skipped. It also relies on dhcp or setup_static net test
16to support tftp to load files from a TFTP server.
17
18For example:
19
20# Details regarding the files that may be read from a TFTP server and addresses
21# and size for aes and rsa cases respectively. This variable may be omitted or
22# set to None if zynqmp secure testing is not possible or desired.
23env__zynq_aes_readable_file = {
24 'fn': 'zynq_aes_image.bin',
25 'fnbit': 'zynq_aes_bit.bin',
26 'fnpbit': 'zynq_aes_par_bit.bin',
27 'srcaddr': 0x1000000,
28 'dstaddr': 0x2000000,
29 'dstlen': 0x1000000,
30}
31
32env__zynq_rsa_readable_file = {
33 'fn': 'zynq_rsa_image.bin',
34 'fninvalid': 'zynq_rsa_image_invalid.bin',
35 'srcaddr': 0x1000000,
36}
37"""
38
Simon Glassddba5202025-02-09 09:07:14 -070039def zynq_secure_pre_commands(ubman):
40 output = ubman.run_command('print modeboot')
Love Kumarb32a3d22024-01-19 15:31:29 +053041 if not 'modeboot=' in output:
42 pytest.skip('bootmode cannnot be determined')
43 m = re.search('modeboot=(.+?)boot', output)
44 if not m:
45 pytest.skip('bootmode cannnot be determined')
46 bootmode = m.group(1)
47 if bootmode == 'jtag':
48 pytest.skip('skipping due to jtag bootmode')
49
50@pytest.mark.buildconfigspec('cmd_zynq_aes')
Simon Glassddba5202025-02-09 09:07:14 -070051def test_zynq_aes_image(ubman):
52 f = ubman.config.env.get('env__zynq_aes_readable_file', None)
Love Kumarb32a3d22024-01-19 15:31:29 +053053 if not f:
54 pytest.skip('No TFTP readable file for zynq secure aes case to read')
55
56 dstaddr = f.get('dstaddr', None)
57 if not dstaddr:
58 pytest.skip('No dstaddr specified in env file to read')
59
60 dstsize = f.get('dstlen', None)
61 if not dstsize:
62 pytest.skip('No dstlen specified in env file to read')
63
Simon Glassddba5202025-02-09 09:07:14 -070064 zynq_secure_pre_commands(ubman)
65 test_net.test_net_dhcp(ubman)
Love Kumarb32a3d22024-01-19 15:31:29 +053066 if not test_net.net_set_up:
Simon Glassddba5202025-02-09 09:07:14 -070067 test_net.test_net_setup_static(ubman)
Love Kumarb32a3d22024-01-19 15:31:29 +053068
69 srcaddr = f.get('srcaddr', None)
70 if not srcaddr:
Simon Glassfb916372025-02-09 09:07:15 -070071 addr = utils.find_ram_base(ubman)
Love Kumarb32a3d22024-01-19 15:31:29 +053072
73 expected_tftp = 'Bytes transferred = '
74 fn = f['fn']
Simon Glassddba5202025-02-09 09:07:14 -070075 output = ubman.run_command('tftpboot %x %s' % (srcaddr, fn))
Love Kumarb32a3d22024-01-19 15:31:29 +053076 assert expected_tftp in output
77
78 expected_op = 'zynq aes [operation type] <srcaddr>'
Simon Glassddba5202025-02-09 09:07:14 -070079 output = ubman.run_command(
Love Kumarb32a3d22024-01-19 15:31:29 +053080 'zynq aes %x $filesize %x %x' % (srcaddr, dstaddr, dstsize)
81 )
82 assert expected_op not in output
Simon Glassddba5202025-02-09 09:07:14 -070083 output = ubman.run_command('echo $?')
Love Kumarb32a3d22024-01-19 15:31:29 +053084 assert output.endswith('0')
85
86@pytest.mark.buildconfigspec('cmd_zynq_aes')
Simon Glassddba5202025-02-09 09:07:14 -070087def test_zynq_aes_bitstream(ubman):
88 f = ubman.config.env.get('env__zynq_aes_readable_file', None)
Love Kumarb32a3d22024-01-19 15:31:29 +053089 if not f:
90 pytest.skip('No TFTP readable file for zynq secure aes case to read')
91
Simon Glassddba5202025-02-09 09:07:14 -070092 zynq_secure_pre_commands(ubman)
93 test_net.test_net_dhcp(ubman)
Love Kumarb32a3d22024-01-19 15:31:29 +053094 if not test_net.net_set_up:
Simon Glassddba5202025-02-09 09:07:14 -070095 test_net.test_net_setup_static(ubman)
Love Kumarb32a3d22024-01-19 15:31:29 +053096
97 srcaddr = f.get('srcaddr', None)
98 if not srcaddr:
Simon Glassfb916372025-02-09 09:07:15 -070099 addr = utils.find_ram_base(ubman)
Love Kumarb32a3d22024-01-19 15:31:29 +0530100
101 expected_tftp = 'Bytes transferred = '
102 fn = f['fnbit']
Simon Glassddba5202025-02-09 09:07:14 -0700103 output = ubman.run_command('tftpboot %x %s' % (srcaddr, fn))
Love Kumarb32a3d22024-01-19 15:31:29 +0530104 assert expected_tftp in output
105
106 expected_op = 'zynq aes [operation type] <srcaddr>'
Simon Glassddba5202025-02-09 09:07:14 -0700107 output = ubman.run_command(
Love Kumarb32a3d22024-01-19 15:31:29 +0530108 'zynq aes load %x $filesize' % (srcaddr)
109 )
110 assert expected_op not in output
Simon Glassddba5202025-02-09 09:07:14 -0700111 output = ubman.run_command('echo $?')
Love Kumarb32a3d22024-01-19 15:31:29 +0530112 assert output.endswith('0')
113
114@pytest.mark.buildconfigspec('cmd_zynq_aes')
Simon Glassddba5202025-02-09 09:07:14 -0700115def test_zynq_aes_partial_bitstream(ubman):
116 f = ubman.config.env.get('env__zynq_aes_readable_file', None)
Love Kumarb32a3d22024-01-19 15:31:29 +0530117 if not f:
118 pytest.skip('No TFTP readable file for zynq secure aes case to read')
119
Simon Glassddba5202025-02-09 09:07:14 -0700120 zynq_secure_pre_commands(ubman)
121 test_net.test_net_dhcp(ubman)
Love Kumarb32a3d22024-01-19 15:31:29 +0530122 if not test_net.net_set_up:
Simon Glassddba5202025-02-09 09:07:14 -0700123 test_net.test_net_setup_static(ubman)
Love Kumarb32a3d22024-01-19 15:31:29 +0530124
125 srcaddr = f.get('srcaddr', None)
126 if not srcaddr:
Simon Glassfb916372025-02-09 09:07:15 -0700127 addr = utils.find_ram_base(ubman)
Love Kumarb32a3d22024-01-19 15:31:29 +0530128
129 expected_tftp = 'Bytes transferred = '
130 fn = f['fnpbit']
Simon Glassddba5202025-02-09 09:07:14 -0700131 output = ubman.run_command('tftpboot %x %s' % (srcaddr, fn))
Love Kumarb32a3d22024-01-19 15:31:29 +0530132 assert expected_tftp in output
133
134 expected_op = 'zynq aes [operation type] <srcaddr>'
Simon Glassddba5202025-02-09 09:07:14 -0700135 output = ubman.run_command('zynq aes loadp %x $filesize' % (srcaddr))
Love Kumarb32a3d22024-01-19 15:31:29 +0530136 assert expected_op not in output
Simon Glassddba5202025-02-09 09:07:14 -0700137 output = ubman.run_command('echo $?')
Love Kumarb32a3d22024-01-19 15:31:29 +0530138 assert output.endswith('0')
139
140@pytest.mark.buildconfigspec('cmd_zynq_rsa')
Simon Glassddba5202025-02-09 09:07:14 -0700141def test_zynq_rsa_image(ubman):
142 f = ubman.config.env.get('env__zynq_rsa_readable_file', None)
Love Kumarb32a3d22024-01-19 15:31:29 +0530143 if not f:
144 pytest.skip('No TFTP readable file for zynq secure rsa case to read')
145
Simon Glassddba5202025-02-09 09:07:14 -0700146 zynq_secure_pre_commands(ubman)
147 test_net.test_net_dhcp(ubman)
Love Kumarb32a3d22024-01-19 15:31:29 +0530148 if not test_net.net_set_up:
Simon Glassddba5202025-02-09 09:07:14 -0700149 test_net.test_net_setup_static(ubman)
Love Kumarb32a3d22024-01-19 15:31:29 +0530150
151 srcaddr = f.get('srcaddr', None)
152 if not srcaddr:
Simon Glassfb916372025-02-09 09:07:15 -0700153 addr = utils.find_ram_base(ubman)
Love Kumarb32a3d22024-01-19 15:31:29 +0530154
155 expected_tftp = 'Bytes transferred = '
156 fn = f['fn']
Simon Glassddba5202025-02-09 09:07:14 -0700157 output = ubman.run_command('tftpboot %x %s' % (srcaddr, fn))
Love Kumarb32a3d22024-01-19 15:31:29 +0530158 assert expected_tftp in output
159
160 expected_op = 'zynq rsa <baseaddr>'
Simon Glassddba5202025-02-09 09:07:14 -0700161 output = ubman.run_command('zynq rsa %x ' % (srcaddr))
Love Kumarb32a3d22024-01-19 15:31:29 +0530162 assert expected_op not in output
Simon Glassddba5202025-02-09 09:07:14 -0700163 output = ubman.run_command('echo $?')
Love Kumarb32a3d22024-01-19 15:31:29 +0530164 assert output.endswith('0')
165
166@pytest.mark.buildconfigspec('cmd_zynq_rsa')
Simon Glassddba5202025-02-09 09:07:14 -0700167def test_zynq_rsa_image_invalid(ubman):
168 f = ubman.config.env.get('env__zynq_rsa_readable_file', None)
Love Kumarb32a3d22024-01-19 15:31:29 +0530169 if not f:
170 pytest.skip('No TFTP readable file for zynq secure rsa case to read')
171
Simon Glassddba5202025-02-09 09:07:14 -0700172 zynq_secure_pre_commands(ubman)
173 test_net.test_net_dhcp(ubman)
Love Kumarb32a3d22024-01-19 15:31:29 +0530174 if not test_net.net_set_up:
Simon Glassddba5202025-02-09 09:07:14 -0700175 test_net.test_net_setup_static(ubman)
Love Kumarb32a3d22024-01-19 15:31:29 +0530176
177 srcaddr = f.get('srcaddr', None)
178 if not srcaddr:
Simon Glassfb916372025-02-09 09:07:15 -0700179 addr = utils.find_ram_base(ubman)
Love Kumarb32a3d22024-01-19 15:31:29 +0530180
181 expected_tftp = 'Bytes transferred = '
182 fninvalid = f['fninvalid']
Simon Glassddba5202025-02-09 09:07:14 -0700183 output = ubman.run_command('tftpboot %x %s' % (srcaddr, fninvalid))
Love Kumarb32a3d22024-01-19 15:31:29 +0530184 assert expected_tftp in output
185
186 expected_op = 'zynq rsa <baseaddr>'
Simon Glassddba5202025-02-09 09:07:14 -0700187 output = ubman.run_command('zynq rsa %x ' % (srcaddr))
Love Kumarb32a3d22024-01-19 15:31:29 +0530188 assert expected_op in output
Simon Glassddba5202025-02-09 09:07:14 -0700189 output = ubman.run_command('echo $?')
Love Kumarb32a3d22024-01-19 15:31:29 +0530190 assert not output.endswith('0')