blob: dc58c0d4dbdabdd022d6957b708c381d1d3c30fe [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001# SPDX-License-Identifier: GPL-2.0
Alexander Graf343cccb2016-11-17 18:31:05 +01002# Copyright (c) 2016, NVIDIA CORPORATION. All rights reserved.
3# Copyright (c) 2016, Alexander Graf <agraf@suse.de>
4#
5# based on test_net.py.
Alexander Graf343cccb2016-11-17 18:31:05 +01006
7# Test efi loader implementation
8
Alexander Graf343cccb2016-11-17 18:31:05 +01009"""
10Note: This test relies on boardenv_* containing configuration values to define
Heinrich Schuchardt844b66a2017-10-18 18:13:18 +020011which network environment is available for testing. Without this, the parts
Alexander Graf343cccb2016-11-17 18:31:05 +010012that rely on network will be automatically skipped.
13
14For example:
15
Tom Rinid705f992025-05-07 17:23:02 -060016.. code-block:: python
Alexander Graf343cccb2016-11-17 18:31:05 +010017
Tom Rinid705f992025-05-07 17:23:02 -060018 # Boolean indicating whether the Ethernet device is attached to USB, and hence
19 # USB enumeration needs to be performed prior to network tests.
20 # This variable may be omitted if its value is False.
21 env__net_uses_usb = False
Alexander Graf343cccb2016-11-17 18:31:05 +010022
Tom Rinid705f992025-05-07 17:23:02 -060023 # Boolean indicating whether the Ethernet device is attached to PCI, and hence
24 # PCI enumeration needs to be performed prior to network tests.
25 # This variable may be omitted if its value is False.
26 env__net_uses_pci = True
Alexander Graf343cccb2016-11-17 18:31:05 +010027
Tom Rinid705f992025-05-07 17:23:02 -060028 # True if a DHCP server is attached to the network, and should be tested.
29 # If DHCP testing is not possible or desired, this variable may be omitted or
30 # set to False.
31 env__net_dhcp_server = True
Alexander Graf343cccb2016-11-17 18:31:05 +010032
Tom Rinid705f992025-05-07 17:23:02 -060033 # A list of environment variables that should be set in order to configure a
34 # static IP. If solely relying on DHCP, this variable may be omitted or set to
35 # an empty list.
36 env__net_static_env_vars = [
37 ('ipaddr', '10.0.0.100'),
38 ('netmask', '255.255.255.0'),
39 ('serverip', '10.0.0.1'),
40 ]
Jerome Forissier56fc9e52024-09-11 11:58:26 +020041
Tom Rinid705f992025-05-07 17:23:02 -060042 # Details regarding a file that may be read from a TFTP server. This variable
43 # may be omitted or set to None if TFTP testing is not possible or desired.
44 env__efi_loader_helloworld_file = {
45 'fn': 'lib/efi_loader/helloworld.efi', # file name
46 'size': 5058624, # file length in bytes
47 'crc32': 'c2244b26', # CRC32 check sum
48 'addr': 0x40400000, # load address
49 }
50
51 # False if the helloworld EFI over HTTP boot test should be performed.
52 # If HTTP boot testing is not possible or desired, set this variable to True or
53 # ommit it.
54 env__efi_helloworld_net_http_test_skip = True
Alexander Graf343cccb2016-11-17 18:31:05 +010055"""
56
Heinrich Schuchardt9460c182021-11-22 08:24:08 +010057import pytest
Simon Glassfb916372025-02-09 09:07:15 -070058import utils
Heinrich Schuchardt9460c182021-11-22 08:24:08 +010059
Jerome Forissier56fc9e52024-09-11 11:58:26 +020060PROTO_TFTP, PROTO_HTTP = range(0, 2)
61
Alexander Graf343cccb2016-11-17 18:31:05 +010062net_set_up = False
63
Simon Glassddba5202025-02-09 09:07:14 -070064def test_efi_pre_commands(ubman):
Alexander Graf343cccb2016-11-17 18:31:05 +010065 """Execute any commands required to enable network hardware.
66
67 These commands are provided by the boardenv_* file; see the comment at the
68 beginning of this file.
69 """
70
Simon Glassddba5202025-02-09 09:07:14 -070071 init_usb = ubman.config.env.get('env__net_uses_usb', False)
Alexander Graf343cccb2016-11-17 18:31:05 +010072 if init_usb:
Simon Glassddba5202025-02-09 09:07:14 -070073 ubman.run_command('usb start')
Alexander Graf343cccb2016-11-17 18:31:05 +010074
Simon Glassddba5202025-02-09 09:07:14 -070075 init_pci = ubman.config.env.get('env__net_uses_pci', False)
Alexander Graf343cccb2016-11-17 18:31:05 +010076 if init_pci:
Simon Glassddba5202025-02-09 09:07:14 -070077 ubman.run_command('pci enum')
Alexander Graf343cccb2016-11-17 18:31:05 +010078
79@pytest.mark.buildconfigspec('cmd_dhcp')
Simon Glassddba5202025-02-09 09:07:14 -070080def test_efi_setup_dhcp(ubman):
Heinrich Schuchardt5ecb53a2020-07-13 12:22:23 +020081 """Set up the network using DHCP.
Alexander Graf343cccb2016-11-17 18:31:05 +010082
83 The boardenv_* file may be used to enable/disable this test; see the
84 comment at the beginning of this file.
85 """
86
Simon Glassddba5202025-02-09 09:07:14 -070087 test_dhcp = ubman.config.env.get('env__net_dhcp_server', False)
Alexander Graf343cccb2016-11-17 18:31:05 +010088 if not test_dhcp:
Simon Glassddba5202025-02-09 09:07:14 -070089 env_vars = ubman.config.env.get('env__net_static_env_vars', None)
Heinrich Schuchardt5ecb53a2020-07-13 12:22:23 +020090 if not env_vars:
91 pytest.skip('No DHCP server available')
Heinrich Schuchardt9460c182021-11-22 08:24:08 +010092 return
Alexander Graf343cccb2016-11-17 18:31:05 +010093
Simon Glassddba5202025-02-09 09:07:14 -070094 ubman.run_command('setenv autoload no')
95 output = ubman.run_command('dhcp')
Alexander Graf343cccb2016-11-17 18:31:05 +010096 assert 'DHCP client bound to address ' in output
97
98 global net_set_up
99 net_set_up = True
100
Heinrich Schuchardt05e6e742025-05-03 15:31:55 +0200101@pytest.mark.buildconfigspec('net', 'net_lwip')
Simon Glassddba5202025-02-09 09:07:14 -0700102def test_efi_setup_static(ubman):
Heinrich Schuchardt5ecb53a2020-07-13 12:22:23 +0200103 """Set up the network using a static IP configuration.
Alexander Graf343cccb2016-11-17 18:31:05 +0100104
105 The configuration is provided by the boardenv_* file; see the comment at
106 the beginning of this file.
107 """
108
Simon Glassddba5202025-02-09 09:07:14 -0700109 env_vars = ubman.config.env.get('env__net_static_env_vars', None)
Alexander Graf343cccb2016-11-17 18:31:05 +0100110 if not env_vars:
Simon Glassddba5202025-02-09 09:07:14 -0700111 test_dhcp = ubman.config.env.get('env__net_dhcp_server', False)
Heinrich Schuchardt5ecb53a2020-07-13 12:22:23 +0200112 if not test_dhcp:
113 pytest.skip('No static network configuration is defined')
114 return None
Alexander Graf343cccb2016-11-17 18:31:05 +0100115
116 for (var, val) in env_vars:
Simon Glassddba5202025-02-09 09:07:14 -0700117 ubman.run_command('setenv %s %s' % (var, val))
Alexander Graf343cccb2016-11-17 18:31:05 +0100118
119 global net_set_up
120 net_set_up = True
121
Simon Glassddba5202025-02-09 09:07:14 -0700122def fetch_file(ubman, env_conf, proto):
Jerome Forissier56fc9e52024-09-11 11:58:26 +0200123 """Grab an env described file via TFTP or HTTP and return its address
Alexander Graf343cccb2016-11-17 18:31:05 +0100124
Jerome Forissier56fc9e52024-09-11 11:58:26 +0200125 A file as described by an env config <env_conf> is downloaded from the
Alexander Grafd5586292016-11-18 13:18:00 +0100126 server. The address to that file is returned.
Alexander Graf343cccb2016-11-17 18:31:05 +0100127 """
Alexander Graf343cccb2016-11-17 18:31:05 +0100128 if not net_set_up:
129 pytest.skip('Network not initialized')
130
Simon Glassddba5202025-02-09 09:07:14 -0700131 f = ubman.config.env.get(env_conf, None)
Alexander Graf343cccb2016-11-17 18:31:05 +0100132 if not f:
Alexander Grafd5586292016-11-18 13:18:00 +0100133 pytest.skip('No %s binary specified in environment' % env_conf)
Alexander Graf343cccb2016-11-17 18:31:05 +0100134
135 addr = f.get('addr', None)
136 if not addr:
Simon Glassfb916372025-02-09 09:07:15 -0700137 addr = utils.find_ram_base(ubman)
Alexander Graf343cccb2016-11-17 18:31:05 +0100138
139 fn = f['fn']
Jerome Forissier56fc9e52024-09-11 11:58:26 +0200140 if proto == PROTO_TFTP:
141 cmd = 'tftpboot'
142 elif proto == PROTO_HTTP:
143 cmd = 'wget'
144 else:
145 assert False
Simon Glassddba5202025-02-09 09:07:14 -0700146 output = ubman.run_command('%s %x %s' % (cmd, addr, fn))
Alexander Graf343cccb2016-11-17 18:31:05 +0100147 expected_text = 'Bytes transferred = '
148 sz = f.get('size', None)
149 if sz:
150 expected_text += '%d' % sz
151 assert expected_text in output
152
153 expected_crc = f.get('crc32', None)
154 if not expected_crc:
Alexander Grafd5586292016-11-18 13:18:00 +0100155 return addr
Alexander Graf343cccb2016-11-17 18:31:05 +0100156
Simon Glassddba5202025-02-09 09:07:14 -0700157 if ubman.config.buildconfig.get('config_cmd_crc32', 'n') != 'y':
Alexander Grafd5586292016-11-18 13:18:00 +0100158 return addr
Alexander Graf343cccb2016-11-17 18:31:05 +0100159
Simon Glassddba5202025-02-09 09:07:14 -0700160 output = ubman.run_command('crc32 %x $filesize' % addr)
Alexander Graf343cccb2016-11-17 18:31:05 +0100161 assert expected_crc in output
162
Alexander Grafd5586292016-11-18 13:18:00 +0100163 return addr
164
Simon Glassddba5202025-02-09 09:07:14 -0700165def do_test_efi_helloworld_net(ubman, proto):
Tom Rinid705f992025-05-07 17:23:02 -0600166 """Download and execute the helloworld appliation
167
168 The helloworld.efi file is downloaded based on the value passed to us as a
169 protocol and is executed using the fallback device tree at $fdtcontroladdr.
170 """
Simon Glassddba5202025-02-09 09:07:14 -0700171 addr = fetch_file(ubman, 'env__efi_loader_helloworld_file', proto)
Jerome Forissier56fc9e52024-09-11 11:58:26 +0200172
Simon Glassddba5202025-02-09 09:07:14 -0700173 output = ubman.run_command('bootefi %x' % addr)
Jerome Forissier56fc9e52024-09-11 11:58:26 +0200174 expected_text = 'Hello, world'
175 assert expected_text in output
176 expected_text = '## Application failed'
177 assert expected_text not in output
178
Heinrich Schuchardtf8ce1852020-03-28 10:41:20 +0100179@pytest.mark.buildconfigspec('of_control')
Simon Glassb343ee32024-09-26 23:59:31 +0200180@pytest.mark.buildconfigspec('bootefi_hello_compile')
Jerome Forissier1ec01eb2024-09-11 11:58:25 +0200181@pytest.mark.buildconfigspec('cmd_tftpboot')
Simon Glassddba5202025-02-09 09:07:14 -0700182def test_efi_helloworld_net_tftp(ubman):
Alexander Grafd5586292016-11-18 13:18:00 +0100183 """Run the helloworld.efi binary via TFTP.
184
Tom Rinid705f992025-05-07 17:23:02 -0600185 Call the do_test_efi_helloworld_net function to execute the test via TFTP.
Alexander Grafd5586292016-11-18 13:18:00 +0100186 """
187
Simon Glassddba5202025-02-09 09:07:14 -0700188 do_test_efi_helloworld_net(ubman, PROTO_TFTP);
Alexander Grafd5586292016-11-18 13:18:00 +0100189
Jerome Forissier56fc9e52024-09-11 11:58:26 +0200190@pytest.mark.buildconfigspec('of_control')
Andrew Goodbody7dfc57a2024-10-25 17:47:32 +0100191@pytest.mark.buildconfigspec('bootefi_hello_compile')
Jerome Forissier56fc9e52024-09-11 11:58:26 +0200192@pytest.mark.buildconfigspec('cmd_wget')
Simon Glassddba5202025-02-09 09:07:14 -0700193def test_efi_helloworld_net_http(ubman):
Jerome Forissier56fc9e52024-09-11 11:58:26 +0200194 """Run the helloworld.efi binary via HTTP.
195
Tom Rinid705f992025-05-07 17:23:02 -0600196 Call the do_test_efi_helloworld_net function to execute the test via HTTP.
Jerome Forissier56fc9e52024-09-11 11:58:26 +0200197 """
Simon Glassddba5202025-02-09 09:07:14 -0700198 if ubman.config.env.get('env__efi_helloworld_net_http_test_skip', True):
Jerome Forissier56fc9e52024-09-11 11:58:26 +0200199 pytest.skip('helloworld.efi HTTP test is not enabled!')
200
Simon Glassddba5202025-02-09 09:07:14 -0700201 do_test_efi_helloworld_net(ubman, PROTO_HTTP);
Alexander Graf343cccb2016-11-17 18:31:05 +0100202
203@pytest.mark.buildconfigspec('cmd_bootefi_hello')
Simon Glassddba5202025-02-09 09:07:14 -0700204def test_efi_helloworld_builtin(ubman):
Alexander Graf343cccb2016-11-17 18:31:05 +0100205 """Run the builtin helloworld.efi binary.
206
207 The helloworld.efi file is included in U-Boot, execute it using the
208 special "bootefi hello" command.
209 """
210
Simon Glassddba5202025-02-09 09:07:14 -0700211 output = ubman.run_command('bootefi hello')
Alexander Graf343cccb2016-11-17 18:31:05 +0100212 expected_text = 'Hello, world'
213 assert expected_text in output
Alexander Grafd5586292016-11-18 13:18:00 +0100214
Heinrich Schuchardt783151e2020-03-30 20:27:42 +0200215@pytest.mark.buildconfigspec('of_control')
Alexander Grafd5586292016-11-18 13:18:00 +0100216@pytest.mark.buildconfigspec('cmd_bootefi')
Jerome Forissier1ec01eb2024-09-11 11:58:25 +0200217@pytest.mark.buildconfigspec('cmd_tftpboot')
Simon Glassddba5202025-02-09 09:07:14 -0700218def test_efi_grub_net(ubman):
Alexander Grafd5586292016-11-18 13:18:00 +0100219 """Run the grub.efi binary via TFTP.
220
221 The grub.efi file is downloaded from the TFTP server and gets
222 executed.
223 """
224
Simon Glassddba5202025-02-09 09:07:14 -0700225 addr = fetch_file(ubman, 'env__efi_loader_grub_file', PROTO_TFTP)
Alexander Grafd5586292016-11-18 13:18:00 +0100226
Simon Glassddba5202025-02-09 09:07:14 -0700227 ubman.run_command('bootefi %x' % addr, wait_for_prompt=False)
Alexander Grafd5586292016-11-18 13:18:00 +0100228
229 # Verify that we have an SMBIOS table
Simon Glassddba5202025-02-09 09:07:14 -0700230 check_smbios = ubman.config.env.get('env__efi_loader_check_smbios', False)
Alexander Grafd5586292016-11-18 13:18:00 +0100231 if check_smbios:
Simon Glassddba5202025-02-09 09:07:14 -0700232 ubman.wait_for('grub>')
233 ubman.run_command('lsefisystab', wait_for_prompt=False, wait_for_echo=False)
234 ubman.wait_for('SMBIOS')
Alexander Grafd5586292016-11-18 13:18:00 +0100235
236 # Then exit cleanly
Simon Glassddba5202025-02-09 09:07:14 -0700237 ubman.wait_for('grub>')
238 ubman.run_command('exit', wait_for_prompt=False, wait_for_echo=False)
239 ubman.wait_for(ubman.prompt)
Alexander Grafd5586292016-11-18 13:18:00 +0100240 # And give us our U-Boot prompt back
Simon Glassddba5202025-02-09 09:07:14 -0700241 ubman.run_command('')