Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | # SPDX-License-Identifier: GPL-2.0 |
Alexander Graf | 4ca4b26 | 2016-11-17 18:31:05 +0100 | [diff] [blame] | 2 | # 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 Graf | 4ca4b26 | 2016-11-17 18:31:05 +0100 | [diff] [blame] | 6 | |
| 7 | # Test efi loader implementation |
| 8 | |
Alexander Graf | 4ca4b26 | 2016-11-17 18:31:05 +0100 | [diff] [blame] | 9 | """ |
| 10 | Note: This test relies on boardenv_* containing configuration values to define |
Heinrich Schuchardt | 83dee94 | 2017-10-18 18:13:18 +0200 | [diff] [blame] | 11 | which network environment is available for testing. Without this, the parts |
Alexander Graf | 4ca4b26 | 2016-11-17 18:31:05 +0100 | [diff] [blame] | 12 | that rely on network will be automatically skipped. |
| 13 | |
| 14 | For 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. |
| 19 | env__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. |
| 24 | env__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. |
| 29 | env__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. |
| 34 | env__net_static_env_vars = [ |
Simon Glass | 871bf7d | 2018-12-27 08:11:13 -0700 | [diff] [blame] | 35 | ('ipaddr', '10.0.0.100'), |
| 36 | ('netmask', '255.255.255.0'), |
| 37 | ('serverip', '10.0.0.1'), |
Alexander Graf | 4ca4b26 | 2016-11-17 18:31:05 +0100 | [diff] [blame] | 38 | ] |
| 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. |
| 42 | env__efi_loader_helloworld_file = { |
Heinrich Schuchardt | 3510280 | 2019-12-19 13:39:30 +0100 | [diff] [blame] | 43 | '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 Graf | 4ca4b26 | 2016-11-17 18:31:05 +0100 | [diff] [blame] | 47 | } |
Jerome Forissier | d2056e2 | 2024-09-11 11:58:26 +0200 | [diff] [blame] | 48 | |
| 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. |
| 52 | env__efi_helloworld_net_http_test_skip = True |
Alexander Graf | 4ca4b26 | 2016-11-17 18:31:05 +0100 | [diff] [blame] | 53 | """ |
| 54 | |
Heinrich Schuchardt | 1ae35c7 | 2021-11-22 08:24:08 +0100 | [diff] [blame] | 55 | import pytest |
| 56 | import u_boot_utils |
| 57 | |
Jerome Forissier | d2056e2 | 2024-09-11 11:58:26 +0200 | [diff] [blame] | 58 | PROTO_TFTP, PROTO_HTTP = range(0, 2) |
| 59 | |
Alexander Graf | 4ca4b26 | 2016-11-17 18:31:05 +0100 | [diff] [blame] | 60 | net_set_up = False |
| 61 | |
| 62 | def test_efi_pre_commands(u_boot_console): |
| 63 | """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 | |
| 69 | init_usb = u_boot_console.config.env.get('env__net_uses_usb', False) |
| 70 | if init_usb: |
| 71 | u_boot_console.run_command('usb start') |
| 72 | |
| 73 | init_pci = u_boot_console.config.env.get('env__net_uses_pci', False) |
| 74 | if init_pci: |
| 75 | u_boot_console.run_command('pci enum') |
| 76 | |
| 77 | @pytest.mark.buildconfigspec('cmd_dhcp') |
Heinrich Schuchardt | f49ca85 | 2020-07-13 12:22:23 +0200 | [diff] [blame] | 78 | def test_efi_setup_dhcp(u_boot_console): |
| 79 | """Set up the network using DHCP. |
Alexander Graf | 4ca4b26 | 2016-11-17 18:31:05 +0100 | [diff] [blame] | 80 | |
| 81 | The boardenv_* file may be used to enable/disable this test; see the |
| 82 | comment at the beginning of this file. |
| 83 | """ |
| 84 | |
| 85 | test_dhcp = u_boot_console.config.env.get('env__net_dhcp_server', False) |
| 86 | if not test_dhcp: |
Heinrich Schuchardt | f49ca85 | 2020-07-13 12:22:23 +0200 | [diff] [blame] | 87 | env_vars = u_boot_console.config.env.get('env__net_static_env_vars', None) |
| 88 | if not env_vars: |
| 89 | pytest.skip('No DHCP server available') |
Heinrich Schuchardt | 1ae35c7 | 2021-11-22 08:24:08 +0100 | [diff] [blame] | 90 | return |
Alexander Graf | 4ca4b26 | 2016-11-17 18:31:05 +0100 | [diff] [blame] | 91 | |
| 92 | u_boot_console.run_command('setenv autoload no') |
| 93 | output = u_boot_console.run_command('dhcp') |
| 94 | 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') |
| 100 | def test_efi_setup_static(u_boot_console): |
Heinrich Schuchardt | f49ca85 | 2020-07-13 12:22:23 +0200 | [diff] [blame] | 101 | """Set up the network using a static IP configuration. |
Alexander Graf | 4ca4b26 | 2016-11-17 18:31:05 +0100 | [diff] [blame] | 102 | |
| 103 | The configuration is provided by the boardenv_* file; see the comment at |
| 104 | the beginning of this file. |
| 105 | """ |
| 106 | |
| 107 | env_vars = u_boot_console.config.env.get('env__net_static_env_vars', None) |
| 108 | if not env_vars: |
Heinrich Schuchardt | f49ca85 | 2020-07-13 12:22:23 +0200 | [diff] [blame] | 109 | test_dhcp = u_boot_console.config.env.get('env__net_dhcp_server', False) |
| 110 | if not test_dhcp: |
| 111 | pytest.skip('No static network configuration is defined') |
| 112 | return None |
Alexander Graf | 4ca4b26 | 2016-11-17 18:31:05 +0100 | [diff] [blame] | 113 | |
| 114 | for (var, val) in env_vars: |
| 115 | u_boot_console.run_command('setenv %s %s' % (var, val)) |
| 116 | |
| 117 | global net_set_up |
| 118 | net_set_up = True |
| 119 | |
Jerome Forissier | d2056e2 | 2024-09-11 11:58:26 +0200 | [diff] [blame] | 120 | def fetch_file(u_boot_console, env_conf, proto): |
| 121 | """Grab an env described file via TFTP or HTTP and return its address |
Alexander Graf | 4ca4b26 | 2016-11-17 18:31:05 +0100 | [diff] [blame] | 122 | |
Jerome Forissier | d2056e2 | 2024-09-11 11:58:26 +0200 | [diff] [blame] | 123 | A file as described by an env config <env_conf> is downloaded from the |
Alexander Graf | 0e4e38a | 2016-11-18 13:18:00 +0100 | [diff] [blame] | 124 | server. The address to that file is returned. |
Alexander Graf | 4ca4b26 | 2016-11-17 18:31:05 +0100 | [diff] [blame] | 125 | """ |
Alexander Graf | 4ca4b26 | 2016-11-17 18:31:05 +0100 | [diff] [blame] | 126 | if not net_set_up: |
| 127 | pytest.skip('Network not initialized') |
| 128 | |
Alexander Graf | 0e4e38a | 2016-11-18 13:18:00 +0100 | [diff] [blame] | 129 | f = u_boot_console.config.env.get(env_conf, None) |
Alexander Graf | 4ca4b26 | 2016-11-17 18:31:05 +0100 | [diff] [blame] | 130 | if not f: |
Alexander Graf | 0e4e38a | 2016-11-18 13:18:00 +0100 | [diff] [blame] | 131 | pytest.skip('No %s binary specified in environment' % env_conf) |
Alexander Graf | 4ca4b26 | 2016-11-17 18:31:05 +0100 | [diff] [blame] | 132 | |
| 133 | addr = f.get('addr', None) |
| 134 | if not addr: |
Quentin Schulz | f4eef40 | 2018-07-09 19:16:27 +0200 | [diff] [blame] | 135 | addr = u_boot_utils.find_ram_base(u_boot_console) |
Alexander Graf | 4ca4b26 | 2016-11-17 18:31:05 +0100 | [diff] [blame] | 136 | |
| 137 | fn = f['fn'] |
Jerome Forissier | d2056e2 | 2024-09-11 11:58:26 +0200 | [diff] [blame] | 138 | if proto == PROTO_TFTP: |
| 139 | cmd = 'tftpboot' |
| 140 | elif proto == PROTO_HTTP: |
| 141 | cmd = 'wget' |
| 142 | else: |
| 143 | assert False |
| 144 | output = u_boot_console.run_command('%s %x %s' % (cmd, addr, fn)) |
Alexander Graf | 4ca4b26 | 2016-11-17 18:31:05 +0100 | [diff] [blame] | 145 | 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 Graf | 0e4e38a | 2016-11-18 13:18:00 +0100 | [diff] [blame] | 153 | return addr |
Alexander Graf | 4ca4b26 | 2016-11-17 18:31:05 +0100 | [diff] [blame] | 154 | |
| 155 | if u_boot_console.config.buildconfig.get('config_cmd_crc32', 'n') != 'y': |
Alexander Graf | 0e4e38a | 2016-11-18 13:18:00 +0100 | [diff] [blame] | 156 | return addr |
Alexander Graf | 4ca4b26 | 2016-11-17 18:31:05 +0100 | [diff] [blame] | 157 | |
| 158 | output = u_boot_console.run_command('crc32 %x $filesize' % addr) |
| 159 | assert expected_crc in output |
| 160 | |
Alexander Graf | 0e4e38a | 2016-11-18 13:18:00 +0100 | [diff] [blame] | 161 | return addr |
| 162 | |
Jerome Forissier | d2056e2 | 2024-09-11 11:58:26 +0200 | [diff] [blame] | 163 | def do_test_efi_helloworld_net(u_boot_console, proto): |
| 164 | addr = fetch_file(u_boot_console, 'env__efi_loader_helloworld_file', proto) |
Alexander Graf | 0e4e38a | 2016-11-18 13:18:00 +0100 | [diff] [blame] | 165 | |
Alexander Graf | 4ca4b26 | 2016-11-17 18:31:05 +0100 | [diff] [blame] | 166 | output = u_boot_console.run_command('bootefi %x' % addr) |
| 167 | expected_text = 'Hello, world' |
| 168 | assert expected_text in output |
Heinrich Schuchardt | c001837 | 2020-07-17 20:21:00 +0200 | [diff] [blame] | 169 | expected_text = '## Application failed' |
| 170 | assert expected_text not in output |
Alexander Graf | 4ca4b26 | 2016-11-17 18:31:05 +0100 | [diff] [blame] | 171 | |
Jerome Forissier | d2056e2 | 2024-09-11 11:58:26 +0200 | [diff] [blame] | 172 | @pytest.mark.buildconfigspec('of_control') |
Simon Glass | 6fe8087 | 2024-09-26 23:59:31 +0200 | [diff] [blame] | 173 | @pytest.mark.buildconfigspec('bootefi_hello_compile') |
Jerome Forissier | d2056e2 | 2024-09-11 11:58:26 +0200 | [diff] [blame] | 174 | @pytest.mark.buildconfigspec('cmd_tftpboot') |
| 175 | def test_efi_helloworld_net_tftp(u_boot_console): |
| 176 | """Run the helloworld.efi binary via TFTP. |
| 177 | |
| 178 | The helloworld.efi file is downloaded from the TFTP server and is executed |
| 179 | using the fallback device tree at $fdtcontroladdr. |
| 180 | """ |
| 181 | |
| 182 | do_test_efi_helloworld_net(u_boot_console, PROTO_TFTP); |
| 183 | |
| 184 | @pytest.mark.buildconfigspec('of_control') |
| 185 | @pytest.mark.buildconfigspec('cmd_bootefi_hello_compile') |
| 186 | @pytest.mark.buildconfigspec('cmd_wget') |
| 187 | def test_efi_helloworld_net_http(u_boot_console): |
| 188 | """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 | """ |
| 193 | if u_boot_console.config.env.get('env__efi_helloworld_net_http_test_skip', True): |
| 194 | pytest.skip('helloworld.efi HTTP test is not enabled!') |
| 195 | |
| 196 | do_test_efi_helloworld_net(u_boot_console, PROTO_HTTP); |
| 197 | |
Alexander Graf | 4ca4b26 | 2016-11-17 18:31:05 +0100 | [diff] [blame] | 198 | @pytest.mark.buildconfigspec('cmd_bootefi_hello') |
| 199 | def test_efi_helloworld_builtin(u_boot_console): |
| 200 | """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 | |
| 206 | output = u_boot_console.run_command('bootefi hello') |
| 207 | expected_text = 'Hello, world' |
| 208 | assert expected_text in output |
Alexander Graf | 0e4e38a | 2016-11-18 13:18:00 +0100 | [diff] [blame] | 209 | |
Heinrich Schuchardt | 6735755 | 2020-03-30 20:27:42 +0200 | [diff] [blame] | 210 | @pytest.mark.buildconfigspec('of_control') |
Alexander Graf | 0e4e38a | 2016-11-18 13:18:00 +0100 | [diff] [blame] | 211 | @pytest.mark.buildconfigspec('cmd_bootefi') |
Jerome Forissier | 9f8c10c | 2024-09-11 11:58:25 +0200 | [diff] [blame] | 212 | @pytest.mark.buildconfigspec('cmd_tftpboot') |
Alexander Graf | 0e4e38a | 2016-11-18 13:18:00 +0100 | [diff] [blame] | 213 | def test_efi_grub_net(u_boot_console): |
| 214 | """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 | |
Jerome Forissier | d2056e2 | 2024-09-11 11:58:26 +0200 | [diff] [blame] | 220 | addr = fetch_file(u_boot_console, 'env__efi_loader_grub_file', PROTO_TFTP) |
Alexander Graf | 0e4e38a | 2016-11-18 13:18:00 +0100 | [diff] [blame] | 221 | |
| 222 | u_boot_console.run_command('bootefi %x' % addr, wait_for_prompt=False) |
| 223 | |
| 224 | # Verify that we have an SMBIOS table |
| 225 | check_smbios = u_boot_console.config.env.get('env__efi_loader_check_smbios', False) |
| 226 | if check_smbios: |
| 227 | u_boot_console.wait_for('grub>') |
Heinrich Schuchardt | 1ae35c7 | 2021-11-22 08:24:08 +0100 | [diff] [blame] | 228 | u_boot_console.run_command('lsefisystab', wait_for_prompt=False, wait_for_echo=False) |
Alexander Graf | 0e4e38a | 2016-11-18 13:18:00 +0100 | [diff] [blame] | 229 | u_boot_console.wait_for('SMBIOS') |
| 230 | |
| 231 | # Then exit cleanly |
| 232 | u_boot_console.wait_for('grub>') |
Heinrich Schuchardt | c001837 | 2020-07-17 20:21:00 +0200 | [diff] [blame] | 233 | u_boot_console.run_command('exit', wait_for_prompt=False, wait_for_echo=False) |
Heinrich Schuchardt | 87438b5 | 2020-07-24 20:55:37 +0200 | [diff] [blame] | 234 | u_boot_console.wait_for(u_boot_console.prompt) |
Alexander Graf | 0e4e38a | 2016-11-18 13:18:00 +0100 | [diff] [blame] | 235 | # And give us our U-Boot prompt back |
| 236 | u_boot_console.run_command('') |