blob: 58f2655191fe1fbd43502ddd3fec27d358c179d6 [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
16# Boolean indicating whether the Ethernet device is attached to USB, and hence
17# USB enumeration needs to be performed prior to network tests.
18# This variable may be omitted if its value is False.
19env__net_uses_usb = False
20
21# Boolean indicating whether the Ethernet device is attached to PCI, and hence
22# PCI enumeration needs to be performed prior to network tests.
23# This variable may be omitted if its value is False.
24env__net_uses_pci = True
25
26# True if a DHCP server is attached to the network, and should be tested.
27# If DHCP testing is not possible or desired, this variable may be omitted or
28# set to False.
29env__net_dhcp_server = True
30
31# A list of environment variables that should be set in order to configure a
32# static IP. If solely relying on DHCP, this variable may be omitted or set to
33# an empty list.
34env__net_static_env_vars = [
Simon Glasse9f4d872018-12-27 08:11:13 -070035 ('ipaddr', '10.0.0.100'),
36 ('netmask', '255.255.255.0'),
37 ('serverip', '10.0.0.1'),
Alexander Graf343cccb2016-11-17 18:31:05 +010038]
39
40# Details regarding a file that may be read from a TFTP server. This variable
41# may be omitted or set to None if TFTP testing is not possible or desired.
42env__efi_loader_helloworld_file = {
Heinrich Schuchardt0e5f6532019-12-19 13:39:30 +010043 'fn': 'lib/efi_loader/helloworld.efi', # file name
44 'size': 5058624, # file length in bytes
45 'crc32': 'c2244b26', # CRC32 check sum
46 'addr': 0x40400000, # load address
Alexander Graf343cccb2016-11-17 18:31:05 +010047}
Jerome Forissier56fc9e52024-09-11 11:58:26 +020048
49# False if the helloworld EFI over HTTP boot test should be performed.
50# If HTTP boot testing is not possible or desired, set this variable to True or
51# ommit it.
52env__efi_helloworld_net_http_test_skip = True
Alexander Graf343cccb2016-11-17 18:31:05 +010053"""
54
Heinrich Schuchardt9460c182021-11-22 08:24:08 +010055import pytest
Simon Glassfb916372025-02-09 09:07:15 -070056import utils
Heinrich Schuchardt9460c182021-11-22 08:24:08 +010057
Jerome Forissier56fc9e52024-09-11 11:58:26 +020058PROTO_TFTP, PROTO_HTTP = range(0, 2)
59
Alexander Graf343cccb2016-11-17 18:31:05 +010060net_set_up = False
61
Simon Glassddba5202025-02-09 09:07:14 -070062def test_efi_pre_commands(ubman):
Alexander Graf343cccb2016-11-17 18:31:05 +010063 """Execute any commands required to enable network hardware.
64
65 These commands are provided by the boardenv_* file; see the comment at the
66 beginning of this file.
67 """
68
Simon Glassddba5202025-02-09 09:07:14 -070069 init_usb = ubman.config.env.get('env__net_uses_usb', False)
Alexander Graf343cccb2016-11-17 18:31:05 +010070 if init_usb:
Simon Glassddba5202025-02-09 09:07:14 -070071 ubman.run_command('usb start')
Alexander Graf343cccb2016-11-17 18:31:05 +010072
Simon Glassddba5202025-02-09 09:07:14 -070073 init_pci = ubman.config.env.get('env__net_uses_pci', False)
Alexander Graf343cccb2016-11-17 18:31:05 +010074 if init_pci:
Simon Glassddba5202025-02-09 09:07:14 -070075 ubman.run_command('pci enum')
Alexander Graf343cccb2016-11-17 18:31:05 +010076
77@pytest.mark.buildconfigspec('cmd_dhcp')
Simon Glassddba5202025-02-09 09:07:14 -070078def test_efi_setup_dhcp(ubman):
Heinrich Schuchardt5ecb53a2020-07-13 12:22:23 +020079 """Set up the network using DHCP.
Alexander Graf343cccb2016-11-17 18:31:05 +010080
81 The boardenv_* file may be used to enable/disable this test; see the
82 comment at the beginning of this file.
83 """
84
Simon Glassddba5202025-02-09 09:07:14 -070085 test_dhcp = ubman.config.env.get('env__net_dhcp_server', False)
Alexander Graf343cccb2016-11-17 18:31:05 +010086 if not test_dhcp:
Simon Glassddba5202025-02-09 09:07:14 -070087 env_vars = ubman.config.env.get('env__net_static_env_vars', None)
Heinrich Schuchardt5ecb53a2020-07-13 12:22:23 +020088 if not env_vars:
89 pytest.skip('No DHCP server available')
Heinrich Schuchardt9460c182021-11-22 08:24:08 +010090 return
Alexander Graf343cccb2016-11-17 18:31:05 +010091
Simon Glassddba5202025-02-09 09:07:14 -070092 ubman.run_command('setenv autoload no')
93 output = ubman.run_command('dhcp')
Alexander Graf343cccb2016-11-17 18:31:05 +010094 assert 'DHCP client bound to address ' in output
95
96 global net_set_up
97 net_set_up = True
98
99@pytest.mark.buildconfigspec('net')
Simon Glassddba5202025-02-09 09:07:14 -0700100def test_efi_setup_static(ubman):
Heinrich Schuchardt5ecb53a2020-07-13 12:22:23 +0200101 """Set up the network using a static IP configuration.
Alexander Graf343cccb2016-11-17 18:31:05 +0100102
103 The configuration is provided by the boardenv_* file; see the comment at
104 the beginning of this file.
105 """
106
Simon Glassddba5202025-02-09 09:07:14 -0700107 env_vars = ubman.config.env.get('env__net_static_env_vars', None)
Alexander Graf343cccb2016-11-17 18:31:05 +0100108 if not env_vars:
Simon Glassddba5202025-02-09 09:07:14 -0700109 test_dhcp = ubman.config.env.get('env__net_dhcp_server', False)
Heinrich Schuchardt5ecb53a2020-07-13 12:22:23 +0200110 if not test_dhcp:
111 pytest.skip('No static network configuration is defined')
112 return None
Alexander Graf343cccb2016-11-17 18:31:05 +0100113
114 for (var, val) in env_vars:
Simon Glassddba5202025-02-09 09:07:14 -0700115 ubman.run_command('setenv %s %s' % (var, val))
Alexander Graf343cccb2016-11-17 18:31:05 +0100116
117 global net_set_up
118 net_set_up = True
119
Simon Glassddba5202025-02-09 09:07:14 -0700120def fetch_file(ubman, env_conf, proto):
Jerome Forissier56fc9e52024-09-11 11:58:26 +0200121 """Grab an env described file via TFTP or HTTP and return its address
Alexander Graf343cccb2016-11-17 18:31:05 +0100122
Jerome Forissier56fc9e52024-09-11 11:58:26 +0200123 A file as described by an env config <env_conf> is downloaded from the
Alexander Grafd5586292016-11-18 13:18:00 +0100124 server. The address to that file is returned.
Alexander Graf343cccb2016-11-17 18:31:05 +0100125 """
Alexander Graf343cccb2016-11-17 18:31:05 +0100126 if not net_set_up:
127 pytest.skip('Network not initialized')
128
Simon Glassddba5202025-02-09 09:07:14 -0700129 f = ubman.config.env.get(env_conf, None)
Alexander Graf343cccb2016-11-17 18:31:05 +0100130 if not f:
Alexander Grafd5586292016-11-18 13:18:00 +0100131 pytest.skip('No %s binary specified in environment' % env_conf)
Alexander Graf343cccb2016-11-17 18:31:05 +0100132
133 addr = f.get('addr', None)
134 if not addr:
Simon Glassfb916372025-02-09 09:07:15 -0700135 addr = utils.find_ram_base(ubman)
Alexander Graf343cccb2016-11-17 18:31:05 +0100136
137 fn = f['fn']
Jerome Forissier56fc9e52024-09-11 11:58:26 +0200138 if proto == PROTO_TFTP:
139 cmd = 'tftpboot'
140 elif proto == PROTO_HTTP:
141 cmd = 'wget'
142 else:
143 assert False
Simon Glassddba5202025-02-09 09:07:14 -0700144 output = ubman.run_command('%s %x %s' % (cmd, addr, fn))
Alexander Graf343cccb2016-11-17 18:31:05 +0100145 expected_text = 'Bytes transferred = '
146 sz = f.get('size', None)
147 if sz:
148 expected_text += '%d' % sz
149 assert expected_text in output
150
151 expected_crc = f.get('crc32', None)
152 if not expected_crc:
Alexander Grafd5586292016-11-18 13:18:00 +0100153 return addr
Alexander Graf343cccb2016-11-17 18:31:05 +0100154
Simon Glassddba5202025-02-09 09:07:14 -0700155 if ubman.config.buildconfig.get('config_cmd_crc32', 'n') != 'y':
Alexander Grafd5586292016-11-18 13:18:00 +0100156 return addr
Alexander Graf343cccb2016-11-17 18:31:05 +0100157
Simon Glassddba5202025-02-09 09:07:14 -0700158 output = ubman.run_command('crc32 %x $filesize' % addr)
Alexander Graf343cccb2016-11-17 18:31:05 +0100159 assert expected_crc in output
160
Alexander Grafd5586292016-11-18 13:18:00 +0100161 return addr
162
Simon Glassddba5202025-02-09 09:07:14 -0700163def do_test_efi_helloworld_net(ubman, proto):
164 addr = fetch_file(ubman, 'env__efi_loader_helloworld_file', proto)
Jerome Forissier56fc9e52024-09-11 11:58:26 +0200165
Simon Glassddba5202025-02-09 09:07:14 -0700166 output = ubman.run_command('bootefi %x' % addr)
Jerome Forissier56fc9e52024-09-11 11:58:26 +0200167 expected_text = 'Hello, world'
168 assert expected_text in output
169 expected_text = '## Application failed'
170 assert expected_text not in output
171
Heinrich Schuchardtf8ce1852020-03-28 10:41:20 +0100172@pytest.mark.buildconfigspec('of_control')
Simon Glassb343ee32024-09-26 23:59:31 +0200173@pytest.mark.buildconfigspec('bootefi_hello_compile')
Jerome Forissier1ec01eb2024-09-11 11:58:25 +0200174@pytest.mark.buildconfigspec('cmd_tftpboot')
Simon Glassddba5202025-02-09 09:07:14 -0700175def test_efi_helloworld_net_tftp(ubman):
Alexander Grafd5586292016-11-18 13:18:00 +0100176 """Run the helloworld.efi binary via TFTP.
177
Heinrich Schuchardtf8ce1852020-03-28 10:41:20 +0100178 The helloworld.efi file is downloaded from the TFTP server and is executed
179 using the fallback device tree at $fdtcontroladdr.
Alexander Grafd5586292016-11-18 13:18:00 +0100180 """
181
Simon Glassddba5202025-02-09 09:07:14 -0700182 do_test_efi_helloworld_net(ubman, PROTO_TFTP);
Alexander Grafd5586292016-11-18 13:18:00 +0100183
Jerome Forissier56fc9e52024-09-11 11:58:26 +0200184@pytest.mark.buildconfigspec('of_control')
Andrew Goodbody7dfc57a2024-10-25 17:47:32 +0100185@pytest.mark.buildconfigspec('bootefi_hello_compile')
Jerome Forissier56fc9e52024-09-11 11:58:26 +0200186@pytest.mark.buildconfigspec('cmd_wget')
Simon Glassddba5202025-02-09 09:07:14 -0700187def test_efi_helloworld_net_http(ubman):
Jerome Forissier56fc9e52024-09-11 11:58:26 +0200188 """Run the helloworld.efi binary via HTTP.
189
190 The helloworld.efi file is downloaded from the HTTP server and is executed
191 using the fallback device tree at $fdtcontroladdr.
192 """
Simon Glassddba5202025-02-09 09:07:14 -0700193 if ubman.config.env.get('env__efi_helloworld_net_http_test_skip', True):
Jerome Forissier56fc9e52024-09-11 11:58:26 +0200194 pytest.skip('helloworld.efi HTTP test is not enabled!')
195
Simon Glassddba5202025-02-09 09:07:14 -0700196 do_test_efi_helloworld_net(ubman, PROTO_HTTP);
Alexander Graf343cccb2016-11-17 18:31:05 +0100197
198@pytest.mark.buildconfigspec('cmd_bootefi_hello')
Simon Glassddba5202025-02-09 09:07:14 -0700199def test_efi_helloworld_builtin(ubman):
Alexander Graf343cccb2016-11-17 18:31:05 +0100200 """Run the builtin helloworld.efi binary.
201
202 The helloworld.efi file is included in U-Boot, execute it using the
203 special "bootefi hello" command.
204 """
205
Simon Glassddba5202025-02-09 09:07:14 -0700206 output = ubman.run_command('bootefi hello')
Alexander Graf343cccb2016-11-17 18:31:05 +0100207 expected_text = 'Hello, world'
208 assert expected_text in output
Alexander Grafd5586292016-11-18 13:18:00 +0100209
Heinrich Schuchardt783151e2020-03-30 20:27:42 +0200210@pytest.mark.buildconfigspec('of_control')
Alexander Grafd5586292016-11-18 13:18:00 +0100211@pytest.mark.buildconfigspec('cmd_bootefi')
Jerome Forissier1ec01eb2024-09-11 11:58:25 +0200212@pytest.mark.buildconfigspec('cmd_tftpboot')
Simon Glassddba5202025-02-09 09:07:14 -0700213def test_efi_grub_net(ubman):
Alexander Grafd5586292016-11-18 13:18:00 +0100214 """Run the grub.efi binary via TFTP.
215
216 The grub.efi file is downloaded from the TFTP server and gets
217 executed.
218 """
219
Simon Glassddba5202025-02-09 09:07:14 -0700220 addr = fetch_file(ubman, 'env__efi_loader_grub_file', PROTO_TFTP)
Alexander Grafd5586292016-11-18 13:18:00 +0100221
Simon Glassddba5202025-02-09 09:07:14 -0700222 ubman.run_command('bootefi %x' % addr, wait_for_prompt=False)
Alexander Grafd5586292016-11-18 13:18:00 +0100223
224 # Verify that we have an SMBIOS table
Simon Glassddba5202025-02-09 09:07:14 -0700225 check_smbios = ubman.config.env.get('env__efi_loader_check_smbios', False)
Alexander Grafd5586292016-11-18 13:18:00 +0100226 if check_smbios:
Simon Glassddba5202025-02-09 09:07:14 -0700227 ubman.wait_for('grub>')
228 ubman.run_command('lsefisystab', wait_for_prompt=False, wait_for_echo=False)
229 ubman.wait_for('SMBIOS')
Alexander Grafd5586292016-11-18 13:18:00 +0100230
231 # Then exit cleanly
Simon Glassddba5202025-02-09 09:07:14 -0700232 ubman.wait_for('grub>')
233 ubman.run_command('exit', wait_for_prompt=False, wait_for_echo=False)
234 ubman.wait_for(ubman.prompt)
Alexander Grafd5586292016-11-18 13:18:00 +0100235 # And give us our U-Boot prompt back
Simon Glassddba5202025-02-09 09:07:14 -0700236 ubman.run_command('')