1 # Copyright (c) 2016, NVIDIA CORPORATION. All rights reserved.
2 # Copyright (c) 2016, Alexander Graf <agraf@suse.de>
4 # based on test_net.py.
6 # SPDX-License-Identifier: GPL-2.0
8 # Test efi loader implementation
14 Note: This test relies on boardenv_* containing configuration values to define
15 which the network environment available for testing. Without this, the parts
16 that rely on network will be automatically skipped.
20 # Boolean indicating whether the Ethernet device is attached to USB, and hence
21 # USB enumeration needs to be performed prior to network tests.
22 # This variable may be omitted if its value is False.
23 env__net_uses_usb = False
25 # Boolean indicating whether the Ethernet device is attached to PCI, and hence
26 # PCI enumeration needs to be performed prior to network tests.
27 # This variable may be omitted if its value is False.
28 env__net_uses_pci = True
30 # True if a DHCP server is attached to the network, and should be tested.
31 # If DHCP testing is not possible or desired, this variable may be omitted or
33 env__net_dhcp_server = True
35 # A list of environment variables that should be set in order to configure a
36 # static IP. If solely relying on DHCP, this variable may be omitted or set to
38 env__net_static_env_vars = [
39 ("ipaddr", "10.0.0.100"),
40 ("netmask", "255.255.255.0"),
41 ("serverip", "10.0.0.1"),
44 # Details regarding a file that may be read from a TFTP server. This variable
45 # may be omitted or set to None if TFTP testing is not possible or desired.
46 env__efi_loader_helloworld_file = {
47 "fn": "lib/efi_loader/helloworld.efi",
55 def test_efi_pre_commands(u_boot_console):
56 """Execute any commands required to enable network hardware.
58 These commands are provided by the boardenv_* file; see the comment at the
59 beginning of this file.
62 init_usb = u_boot_console.config.env.get('env__net_uses_usb', False)
64 u_boot_console.run_command('usb start')
66 init_pci = u_boot_console.config.env.get('env__net_uses_pci', False)
68 u_boot_console.run_command('pci enum')
70 @pytest.mark.buildconfigspec('cmd_dhcp')
71 def test_efi_dhcp(u_boot_console):
72 """Test the dhcp command.
74 The boardenv_* file may be used to enable/disable this test; see the
75 comment at the beginning of this file.
78 test_dhcp = u_boot_console.config.env.get('env__net_dhcp_server', False)
80 pytest.skip('No DHCP server available')
82 u_boot_console.run_command('setenv autoload no')
83 output = u_boot_console.run_command('dhcp')
84 assert 'DHCP client bound to address ' in output
89 @pytest.mark.buildconfigspec('net')
90 def test_efi_setup_static(u_boot_console):
91 """Set up a static IP configuration.
93 The configuration is provided by the boardenv_* file; see the comment at
94 the beginning of this file.
97 env_vars = u_boot_console.config.env.get('env__net_static_env_vars', None)
99 pytest.skip('No static network configuration is defined')
101 for (var, val) in env_vars:
102 u_boot_console.run_command('setenv %s %s' % (var, val))
107 def fetch_tftp_file(u_boot_console, env_conf):
108 """Grab an env described file via TFTP and return its address
110 A file as described by an env config <env_conf> is downloaded from the TFTP
111 server. The address to that file is returned.
114 pytest.skip('Network not initialized')
116 f = u_boot_console.config.env.get(env_conf, None)
118 pytest.skip('No %s binary specified in environment' % env_conf)
120 addr = f.get('addr', None)
122 addr = u_boot_utils.find_ram_base(u_boot_console) + (1024 * 1024 * 4)
125 output = u_boot_console.run_command('tftpboot %x %s' % (addr, fn))
126 expected_text = 'Bytes transferred = '
127 sz = f.get('size', None)
129 expected_text += '%d' % sz
130 assert expected_text in output
132 expected_crc = f.get('crc32', None)
136 if u_boot_console.config.buildconfig.get('config_cmd_crc32', 'n') != 'y':
139 output = u_boot_console.run_command('crc32 %x $filesize' % addr)
140 assert expected_crc in output
144 @pytest.mark.buildconfigspec('cmd_bootefi_hello_compile')
145 def test_efi_helloworld_net(u_boot_console):
146 """Run the helloworld.efi binary via TFTP.
148 The helloworld.efi file is downloaded from the TFTP server and gets
152 addr = fetch_tftp_file(u_boot_console, 'env__efi_loader_helloworld_file')
154 output = u_boot_console.run_command('bootefi %x' % addr)
155 expected_text = 'Hello, world'
156 assert expected_text in output
158 @pytest.mark.buildconfigspec('cmd_bootefi_hello')
159 def test_efi_helloworld_builtin(u_boot_console):
160 """Run the builtin helloworld.efi binary.
162 The helloworld.efi file is included in U-Boot, execute it using the
163 special "bootefi hello" command.
166 output = u_boot_console.run_command('bootefi hello')
167 expected_text = 'Hello, world'
168 assert expected_text in output
170 @pytest.mark.buildconfigspec('cmd_bootefi')
171 def test_efi_grub_net(u_boot_console):
172 """Run the grub.efi binary via TFTP.
174 The grub.efi file is downloaded from the TFTP server and gets
178 addr = fetch_tftp_file(u_boot_console, 'env__efi_loader_grub_file')
180 u_boot_console.run_command('bootefi %x' % addr, wait_for_prompt=False)
182 # Verify that we have an SMBIOS table
183 check_smbios = u_boot_console.config.env.get('env__efi_loader_check_smbios', False)
185 u_boot_console.wait_for('grub>')
186 output = u_boot_console.run_command('lsefisystab', wait_for_prompt=False, wait_for_echo=False)
187 u_boot_console.wait_for('SMBIOS')
190 u_boot_console.wait_for('grub>')
191 output = u_boot_console.run_command('exit', wait_for_prompt=False, wait_for_echo=False)
192 u_boot_console.wait_for('r = 0')
194 # And give us our U-Boot prompt back
195 u_boot_console.run_command('')