1*4ca4b265SAlexander Graf# Copyright (c) 2016, NVIDIA CORPORATION. All rights reserved. 2*4ca4b265SAlexander Graf# Copyright (c) 2016, Alexander Graf <agraf@suse.de> 3*4ca4b265SAlexander Graf# 4*4ca4b265SAlexander Graf# based on test_net.py. 5*4ca4b265SAlexander Graf# 6*4ca4b265SAlexander Graf# SPDX-License-Identifier: GPL-2.0 7*4ca4b265SAlexander Graf 8*4ca4b265SAlexander Graf# Test efi loader implementation 9*4ca4b265SAlexander Graf 10*4ca4b265SAlexander Grafimport pytest 11*4ca4b265SAlexander Grafimport u_boot_utils 12*4ca4b265SAlexander Graf 13*4ca4b265SAlexander Graf""" 14*4ca4b265SAlexander GrafNote: This test relies on boardenv_* containing configuration values to define 15*4ca4b265SAlexander Grafwhich the network environment available for testing. Without this, the parts 16*4ca4b265SAlexander Grafthat rely on network will be automatically skipped. 17*4ca4b265SAlexander Graf 18*4ca4b265SAlexander GrafFor example: 19*4ca4b265SAlexander Graf 20*4ca4b265SAlexander Graf# Boolean indicating whether the Ethernet device is attached to USB, and hence 21*4ca4b265SAlexander Graf# USB enumeration needs to be performed prior to network tests. 22*4ca4b265SAlexander Graf# This variable may be omitted if its value is False. 23*4ca4b265SAlexander Grafenv__net_uses_usb = False 24*4ca4b265SAlexander Graf 25*4ca4b265SAlexander Graf# Boolean indicating whether the Ethernet device is attached to PCI, and hence 26*4ca4b265SAlexander Graf# PCI enumeration needs to be performed prior to network tests. 27*4ca4b265SAlexander Graf# This variable may be omitted if its value is False. 28*4ca4b265SAlexander Grafenv__net_uses_pci = True 29*4ca4b265SAlexander Graf 30*4ca4b265SAlexander Graf# True if a DHCP server is attached to the network, and should be tested. 31*4ca4b265SAlexander Graf# If DHCP testing is not possible or desired, this variable may be omitted or 32*4ca4b265SAlexander Graf# set to False. 33*4ca4b265SAlexander Grafenv__net_dhcp_server = True 34*4ca4b265SAlexander Graf 35*4ca4b265SAlexander Graf# A list of environment variables that should be set in order to configure a 36*4ca4b265SAlexander Graf# static IP. If solely relying on DHCP, this variable may be omitted or set to 37*4ca4b265SAlexander Graf# an empty list. 38*4ca4b265SAlexander Grafenv__net_static_env_vars = [ 39*4ca4b265SAlexander Graf ("ipaddr", "10.0.0.100"), 40*4ca4b265SAlexander Graf ("netmask", "255.255.255.0"), 41*4ca4b265SAlexander Graf ("serverip", "10.0.0.1"), 42*4ca4b265SAlexander Graf] 43*4ca4b265SAlexander Graf 44*4ca4b265SAlexander Graf# Details regarding a file that may be read from a TFTP server. This variable 45*4ca4b265SAlexander Graf# may be omitted or set to None if TFTP testing is not possible or desired. 46*4ca4b265SAlexander Grafenv__efi_loader_helloworld_file = { 47*4ca4b265SAlexander Graf "fn": "lib/efi_loader/helloworld.efi", 48*4ca4b265SAlexander Graf "size": 5058624, 49*4ca4b265SAlexander Graf "crc32": "c2244b26", 50*4ca4b265SAlexander Graf} 51*4ca4b265SAlexander Graf""" 52*4ca4b265SAlexander Graf 53*4ca4b265SAlexander Grafnet_set_up = False 54*4ca4b265SAlexander Graf 55*4ca4b265SAlexander Grafdef test_efi_pre_commands(u_boot_console): 56*4ca4b265SAlexander Graf """Execute any commands required to enable network hardware. 57*4ca4b265SAlexander Graf 58*4ca4b265SAlexander Graf These commands are provided by the boardenv_* file; see the comment at the 59*4ca4b265SAlexander Graf beginning of this file. 60*4ca4b265SAlexander Graf """ 61*4ca4b265SAlexander Graf 62*4ca4b265SAlexander Graf init_usb = u_boot_console.config.env.get('env__net_uses_usb', False) 63*4ca4b265SAlexander Graf if init_usb: 64*4ca4b265SAlexander Graf u_boot_console.run_command('usb start') 65*4ca4b265SAlexander Graf 66*4ca4b265SAlexander Graf init_pci = u_boot_console.config.env.get('env__net_uses_pci', False) 67*4ca4b265SAlexander Graf if init_pci: 68*4ca4b265SAlexander Graf u_boot_console.run_command('pci enum') 69*4ca4b265SAlexander Graf 70*4ca4b265SAlexander Graf@pytest.mark.buildconfigspec('cmd_dhcp') 71*4ca4b265SAlexander Grafdef test_efi_dhcp(u_boot_console): 72*4ca4b265SAlexander Graf """Test the dhcp command. 73*4ca4b265SAlexander Graf 74*4ca4b265SAlexander Graf The boardenv_* file may be used to enable/disable this test; see the 75*4ca4b265SAlexander Graf comment at the beginning of this file. 76*4ca4b265SAlexander Graf """ 77*4ca4b265SAlexander Graf 78*4ca4b265SAlexander Graf test_dhcp = u_boot_console.config.env.get('env__net_dhcp_server', False) 79*4ca4b265SAlexander Graf if not test_dhcp: 80*4ca4b265SAlexander Graf pytest.skip('No DHCP server available') 81*4ca4b265SAlexander Graf 82*4ca4b265SAlexander Graf u_boot_console.run_command('setenv autoload no') 83*4ca4b265SAlexander Graf output = u_boot_console.run_command('dhcp') 84*4ca4b265SAlexander Graf assert 'DHCP client bound to address ' in output 85*4ca4b265SAlexander Graf 86*4ca4b265SAlexander Graf global net_set_up 87*4ca4b265SAlexander Graf net_set_up = True 88*4ca4b265SAlexander Graf 89*4ca4b265SAlexander Graf@pytest.mark.buildconfigspec('net') 90*4ca4b265SAlexander Grafdef test_efi_setup_static(u_boot_console): 91*4ca4b265SAlexander Graf """Set up a static IP configuration. 92*4ca4b265SAlexander Graf 93*4ca4b265SAlexander Graf The configuration is provided by the boardenv_* file; see the comment at 94*4ca4b265SAlexander Graf the beginning of this file. 95*4ca4b265SAlexander Graf """ 96*4ca4b265SAlexander Graf 97*4ca4b265SAlexander Graf env_vars = u_boot_console.config.env.get('env__net_static_env_vars', None) 98*4ca4b265SAlexander Graf if not env_vars: 99*4ca4b265SAlexander Graf pytest.skip('No static network configuration is defined') 100*4ca4b265SAlexander Graf 101*4ca4b265SAlexander Graf for (var, val) in env_vars: 102*4ca4b265SAlexander Graf u_boot_console.run_command('setenv %s %s' % (var, val)) 103*4ca4b265SAlexander Graf 104*4ca4b265SAlexander Graf global net_set_up 105*4ca4b265SAlexander Graf net_set_up = True 106*4ca4b265SAlexander Graf 107*4ca4b265SAlexander Graf@pytest.mark.buildconfigspec('cmd_bootefi_hello') 108*4ca4b265SAlexander Grafdef test_efi_helloworld_net(u_boot_console): 109*4ca4b265SAlexander Graf """Run the helloworld.efi binary via TFTP. 110*4ca4b265SAlexander Graf 111*4ca4b265SAlexander Graf The helloworld.efi file is downloaded from the TFTP server and gets 112*4ca4b265SAlexander Graf executed. 113*4ca4b265SAlexander Graf """ 114*4ca4b265SAlexander Graf 115*4ca4b265SAlexander Graf if not net_set_up: 116*4ca4b265SAlexander Graf pytest.skip('Network not initialized') 117*4ca4b265SAlexander Graf 118*4ca4b265SAlexander Graf f = u_boot_console.config.env.get('env__efi_loader_helloworld_file', None) 119*4ca4b265SAlexander Graf if not f: 120*4ca4b265SAlexander Graf pytest.skip('No hello world binary specified in environment') 121*4ca4b265SAlexander Graf 122*4ca4b265SAlexander Graf addr = f.get('addr', None) 123*4ca4b265SAlexander Graf if not addr: 124*4ca4b265SAlexander Graf addr = u_boot_utils.find_ram_base(u_boot_console) + (1024 * 1024 * 4) 125*4ca4b265SAlexander Graf 126*4ca4b265SAlexander Graf fn = f['fn'] 127*4ca4b265SAlexander Graf output = u_boot_console.run_command('tftpboot %x %s' % (addr, fn)) 128*4ca4b265SAlexander Graf expected_text = 'Bytes transferred = ' 129*4ca4b265SAlexander Graf sz = f.get('size', None) 130*4ca4b265SAlexander Graf if sz: 131*4ca4b265SAlexander Graf expected_text += '%d' % sz 132*4ca4b265SAlexander Graf assert expected_text in output 133*4ca4b265SAlexander Graf 134*4ca4b265SAlexander Graf expected_crc = f.get('crc32', None) 135*4ca4b265SAlexander Graf if not expected_crc: 136*4ca4b265SAlexander Graf return 137*4ca4b265SAlexander Graf 138*4ca4b265SAlexander Graf if u_boot_console.config.buildconfig.get('config_cmd_crc32', 'n') != 'y': 139*4ca4b265SAlexander Graf return 140*4ca4b265SAlexander Graf 141*4ca4b265SAlexander Graf output = u_boot_console.run_command('crc32 %x $filesize' % addr) 142*4ca4b265SAlexander Graf assert expected_crc in output 143*4ca4b265SAlexander Graf 144*4ca4b265SAlexander Graf output = u_boot_console.run_command('bootefi %x' % addr) 145*4ca4b265SAlexander Graf expected_text = 'Hello, world' 146*4ca4b265SAlexander Graf assert expected_text in output 147*4ca4b265SAlexander Graf 148*4ca4b265SAlexander Graf@pytest.mark.buildconfigspec('cmd_bootefi_hello') 149*4ca4b265SAlexander Grafdef test_efi_helloworld_builtin(u_boot_console): 150*4ca4b265SAlexander Graf """Run the builtin helloworld.efi binary. 151*4ca4b265SAlexander Graf 152*4ca4b265SAlexander Graf The helloworld.efi file is included in U-Boot, execute it using the 153*4ca4b265SAlexander Graf special "bootefi hello" command. 154*4ca4b265SAlexander Graf """ 155*4ca4b265SAlexander Graf 156*4ca4b265SAlexander Graf output = u_boot_console.run_command('bootefi hello') 157*4ca4b265SAlexander Graf expected_text = 'Hello, world' 158*4ca4b265SAlexander Graf assert expected_text in output 159