1*65a6b3c2SMichal Simek# SPDX-License-Identifier: GPL-2.0 2*65a6b3c2SMichal Simek# 3*65a6b3c2SMichal Simek# Copyright (c) 2018, Xilinx Inc. 4*65a6b3c2SMichal Simek# 5*65a6b3c2SMichal Simek# Michal Simek 6*65a6b3c2SMichal Simek# Siva Durga Prasad Paladugu 7*65a6b3c2SMichal Simek 8*65a6b3c2SMichal Simekimport pytest 9*65a6b3c2SMichal Simekimport re 10*65a6b3c2SMichal Simekimport random 11*65a6b3c2SMichal Simekimport u_boot_utils 12*65a6b3c2SMichal Simek 13*65a6b3c2SMichal Simek""" 14*65a6b3c2SMichal SimekNote: This test relies on boardenv_* containing configuration values to define 15*65a6b3c2SMichal Simekthe network available and files to be used for testing. Without this, this test 16*65a6b3c2SMichal Simekwill be automatically skipped. 17*65a6b3c2SMichal Simek 18*65a6b3c2SMichal SimekFor example: 19*65a6b3c2SMichal Simek 20*65a6b3c2SMichal Simek# True if a DHCP server is attached to the network, and should be tested. 21*65a6b3c2SMichal Simekenv__net_dhcp_server = True 22*65a6b3c2SMichal Simek 23*65a6b3c2SMichal Simek# A list of environment variables that should be set in order to configure a 24*65a6b3c2SMichal Simek# static IP. In this test case we atleast need serverip for performing tftpb 25*65a6b3c2SMichal Simek# to get required files. 26*65a6b3c2SMichal Simekenv__net_static_env_vars = [ 27*65a6b3c2SMichal Simek ("ipaddr", "10.0.0.100"), 28*65a6b3c2SMichal Simek ("netmask", "255.255.255.0"), 29*65a6b3c2SMichal Simek ("serverip", "10.0.0.1"), 30*65a6b3c2SMichal Simek] 31*65a6b3c2SMichal Simek 32*65a6b3c2SMichal Simek# Details regarding the files that may be read from a TFTP server. . 33*65a6b3c2SMichal Simekenv__fpga_secure_readable_file = { 34*65a6b3c2SMichal Simek "fn": "auth_bhdr_ppk1_bit.bin", 35*65a6b3c2SMichal Simek "enckupfn": "auth_bhdr_enc_kup_load_bit.bin", 36*65a6b3c2SMichal Simek "addr": 0x1000000, 37*65a6b3c2SMichal Simek "keyaddr": 0x100000, 38*65a6b3c2SMichal Simek "keyfn": "key.txt", 39*65a6b3c2SMichal Simek} 40*65a6b3c2SMichal Simek 41*65a6b3c2SMichal Simekenv__fpga_under_test = { 42*65a6b3c2SMichal Simek "dev": 0, 43*65a6b3c2SMichal Simek "addr" : 0x1000000, 44*65a6b3c2SMichal Simek "bitstream_load": "compress.bin", 45*65a6b3c2SMichal Simek "bitstream_load_size": 1831960, 46*65a6b3c2SMichal Simek "bitstream_loadp": "compress_pr.bin", 47*65a6b3c2SMichal Simek "bitstream_loadp_size": 423352, 48*65a6b3c2SMichal Simek "bitstream_loadb": "compress.bit", 49*65a6b3c2SMichal Simek "bitstream_loadb_size": 1832086, 50*65a6b3c2SMichal Simek "bitstream_loadbp": "compress_pr.bit", 51*65a6b3c2SMichal Simek "bitstream_loadbp_size": 423491, 52*65a6b3c2SMichal Simek "mkimage_legacy": "download.ub", 53*65a6b3c2SMichal Simek "mkimage_legacy_size": 13321468, 54*65a6b3c2SMichal Simek "mkimage_legacy_gz": "download.gz.ub", 55*65a6b3c2SMichal Simek "mkimage_legacy_gz_size": 53632, 56*65a6b3c2SMichal Simek "mkimage_fit": "download-fit.ub", 57*65a6b3c2SMichal Simek "mkimage_fit_size": 13322784, 58*65a6b3c2SMichal Simek "loadfs": "mmc 0 compress.bin", 59*65a6b3c2SMichal Simek "loadfs_size": 1831960, 60*65a6b3c2SMichal Simek "loadfs_block_size": 0x10000, 61*65a6b3c2SMichal Simek} 62*65a6b3c2SMichal Simek""" 63*65a6b3c2SMichal Simek 64*65a6b3c2SMichal Simekimport test_net 65*65a6b3c2SMichal Simek 66*65a6b3c2SMichal Simekdef check_dev(u_boot_console): 67*65a6b3c2SMichal Simek f = u_boot_console.config.env.get('env__fpga_under_test', None) 68*65a6b3c2SMichal Simek if not f: 69*65a6b3c2SMichal Simek pytest.skip('No FPGA to test') 70*65a6b3c2SMichal Simek 71*65a6b3c2SMichal Simek dev = f.get('dev', -1) 72*65a6b3c2SMichal Simek if dev < 0: 73*65a6b3c2SMichal Simek pytest.fail('No dev specified via env__fpga_under_test') 74*65a6b3c2SMichal Simek 75*65a6b3c2SMichal Simek return dev, f 76*65a6b3c2SMichal Simek 77*65a6b3c2SMichal Simekdef load_file_from_var(u_boot_console, name): 78*65a6b3c2SMichal Simek dev, f = check_dev(u_boot_console) 79*65a6b3c2SMichal Simek 80*65a6b3c2SMichal Simek addr = f.get('addr', -1) 81*65a6b3c2SMichal Simek if addr < 0: 82*65a6b3c2SMichal Simek pytest.fail('No address specified via env__fpga_under_test') 83*65a6b3c2SMichal Simek 84*65a6b3c2SMichal Simek test_net.test_net_dhcp(u_boot_console) 85*65a6b3c2SMichal Simek test_net.test_net_setup_static(u_boot_console) 86*65a6b3c2SMichal Simek bit = f['%s' % (name)] 87*65a6b3c2SMichal Simek bit_size = f['%s_size' % (name)] 88*65a6b3c2SMichal Simek 89*65a6b3c2SMichal Simek expected_tftp = 'Bytes transferred = %d' % bit_size 90*65a6b3c2SMichal Simek output = u_boot_console.run_command('tftpboot %x %s' % (addr, bit)) 91*65a6b3c2SMichal Simek assert expected_tftp in output 92*65a6b3c2SMichal Simek 93*65a6b3c2SMichal Simek return f, dev, addr, bit, bit_size 94*65a6b3c2SMichal Simek 95*65a6b3c2SMichal Simek###### FPGA FAIL test ###### 96*65a6b3c2SMichal Simekexpected_usage = 'fpga - loadable FPGA image support' 97*65a6b3c2SMichal Simek 98*65a6b3c2SMichal Simek@pytest.mark.xfail 99*65a6b3c2SMichal Simek@pytest.mark.buildconfigspec('cmd_fpga') 100*65a6b3c2SMichal Simekdef test_fpga_fail(u_boot_console): 101*65a6b3c2SMichal Simek # Test non valid fpga subcommand 102*65a6b3c2SMichal Simek expected = 'fpga: non existing command' 103*65a6b3c2SMichal Simek output = u_boot_console.run_command('fpga broken 0') 104*65a6b3c2SMichal Simek #assert expected in output 105*65a6b3c2SMichal Simek assert expected_usage in output 106*65a6b3c2SMichal Simek 107*65a6b3c2SMichal Simek@pytest.mark.buildconfigspec('cmd_fpga') 108*65a6b3c2SMichal Simekdef test_fpga_help(u_boot_console): 109*65a6b3c2SMichal Simek # Just show help 110*65a6b3c2SMichal Simek output = u_boot_console.run_command('fpga') 111*65a6b3c2SMichal Simek assert expected_usage in output 112*65a6b3c2SMichal Simek 113*65a6b3c2SMichal Simek 114*65a6b3c2SMichal Simek###### FPGA DUMP tests ###### 115*65a6b3c2SMichal Simek 116*65a6b3c2SMichal Simek@pytest.mark.buildconfigspec('cmd_fpga') 117*65a6b3c2SMichal Simekdef test_fpga_dump(u_boot_console): 118*65a6b3c2SMichal Simek pytest.skip('Not implemented now') 119*65a6b3c2SMichal Simek 120*65a6b3c2SMichal Simek@pytest.mark.buildconfigspec('cmd_fpga') 121*65a6b3c2SMichal Simekdef test_fpga_dump_variable(u_boot_console): 122*65a6b3c2SMichal Simek # Same as above but via "fpga" variable 123*65a6b3c2SMichal Simek pytest.skip('Not implemented now') 124*65a6b3c2SMichal Simek 125*65a6b3c2SMichal Simek###### FPGA INFO tests ###### 126*65a6b3c2SMichal Simek 127*65a6b3c2SMichal Simek@pytest.mark.buildconfigspec('cmd_fpga') 128*65a6b3c2SMichal Simekdef test_fpga_info_fail(u_boot_console): 129*65a6b3c2SMichal Simek # Maybe this can be skipped completely 130*65a6b3c2SMichal Simek dev, f = check_dev(u_boot_console) 131*65a6b3c2SMichal Simek 132*65a6b3c2SMichal Simek # Multiple parameters to fpga info should fail 133*65a6b3c2SMichal Simek expected = 'fpga: more parameters passed' 134*65a6b3c2SMichal Simek output = u_boot_console.run_command('fpga info 0 0') 135*65a6b3c2SMichal Simek #assert expected in output 136*65a6b3c2SMichal Simek assert expected_usage in output 137*65a6b3c2SMichal Simek 138*65a6b3c2SMichal Simek@pytest.mark.buildconfigspec('cmd_fpga') 139*65a6b3c2SMichal Simekdef test_fpga_info_list(u_boot_console): 140*65a6b3c2SMichal Simek # Maybe this can be skipped completely 141*65a6b3c2SMichal Simek dev, f = check_dev(u_boot_console) 142*65a6b3c2SMichal Simek 143*65a6b3c2SMichal Simek # Code is design in a way that if fpga dev is not passed it should 144*65a6b3c2SMichal Simek # return list of all fpga devices in the system 145*65a6b3c2SMichal Simek u_boot_console.run_command('setenv fpga') 146*65a6b3c2SMichal Simek output = u_boot_console.run_command('fpga info') 147*65a6b3c2SMichal Simek assert expected_usage not in output 148*65a6b3c2SMichal Simek 149*65a6b3c2SMichal Simek@pytest.mark.buildconfigspec('cmd_fpga') 150*65a6b3c2SMichal Simekdef test_fpga_info(u_boot_console): 151*65a6b3c2SMichal Simek dev, f = check_dev(u_boot_console) 152*65a6b3c2SMichal Simek 153*65a6b3c2SMichal Simek output = u_boot_console.run_command('fpga info %x' % (dev)) 154*65a6b3c2SMichal Simek assert expected_usage not in output 155*65a6b3c2SMichal Simek 156*65a6b3c2SMichal Simek@pytest.mark.buildconfigspec('cmd_fpga') 157*65a6b3c2SMichal Simekdef test_fpga_info_variable(u_boot_console): 158*65a6b3c2SMichal Simek dev, f = check_dev(u_boot_console) 159*65a6b3c2SMichal Simek 160*65a6b3c2SMichal Simek # 161*65a6b3c2SMichal Simek # fpga variable is storing device number which doesn't need to be passed 162*65a6b3c2SMichal Simek # 163*65a6b3c2SMichal Simek u_boot_console.run_command('setenv fpga %x' % (dev)) 164*65a6b3c2SMichal Simek 165*65a6b3c2SMichal Simek output = u_boot_console.run_command('fpga info') 166*65a6b3c2SMichal Simek # Variable cleanup 167*65a6b3c2SMichal Simek u_boot_console.run_command('setenv fpga') 168*65a6b3c2SMichal Simek assert expected_usage not in output 169*65a6b3c2SMichal Simek 170*65a6b3c2SMichal Simek###### FPGA LOAD tests ###### 171*65a6b3c2SMichal Simek 172*65a6b3c2SMichal Simek@pytest.mark.buildconfigspec('cmd_fpga') 173*65a6b3c2SMichal Simek@pytest.mark.buildconfigspec('cmd_echo') 174*65a6b3c2SMichal Simekdef test_fpga_load_fail(u_boot_console): 175*65a6b3c2SMichal Simek f, dev, addr, bit, bit_size = load_file_from_var(u_boot_console, 'bitstream_load') 176*65a6b3c2SMichal Simek 177*65a6b3c2SMichal Simek for cmd in ['dump', 'load', 'loadb']: 178*65a6b3c2SMichal Simek # missing dev parameter 179*65a6b3c2SMichal Simek expected = 'fpga: incorrect parameters passed' 180*65a6b3c2SMichal Simek output = u_boot_console.run_command('fpga %s %x $filesize' % (cmd, addr)) 181*65a6b3c2SMichal Simek #assert expected in output 182*65a6b3c2SMichal Simek assert expected_usage in output 183*65a6b3c2SMichal Simek 184*65a6b3c2SMichal Simek # more parameters - 0 at the end 185*65a6b3c2SMichal Simek expected = 'fpga: more parameters passed' 186*65a6b3c2SMichal Simek output = u_boot_console.run_command('fpga %s %x %x $filesize 0' % (cmd, dev, addr)) 187*65a6b3c2SMichal Simek #assert expected in output 188*65a6b3c2SMichal Simek assert expected_usage in output 189*65a6b3c2SMichal Simek 190*65a6b3c2SMichal Simek # 0 address 191*65a6b3c2SMichal Simek expected = 'fpga: zero fpga_data address' 192*65a6b3c2SMichal Simek output = u_boot_console.run_command('fpga %s %x 0 $filesize' % (cmd, dev)) 193*65a6b3c2SMichal Simek #assert expected in output 194*65a6b3c2SMichal Simek assert expected_usage in output 195*65a6b3c2SMichal Simek 196*65a6b3c2SMichal Simek # 0 filesize 197*65a6b3c2SMichal Simek expected = 'fpga: zero size' 198*65a6b3c2SMichal Simek output = u_boot_console.run_command('fpga %s %x %x 0' % (cmd, dev, addr)) 199*65a6b3c2SMichal Simek #assert expected in output 200*65a6b3c2SMichal Simek assert expected_usage in output 201*65a6b3c2SMichal Simek 202*65a6b3c2SMichal Simek@pytest.mark.buildconfigspec('cmd_fpga') 203*65a6b3c2SMichal Simek@pytest.mark.buildconfigspec('cmd_echo') 204*65a6b3c2SMichal Simekdef test_fpga_load(u_boot_console): 205*65a6b3c2SMichal Simek f, dev, addr, bit, bit_size = load_file_from_var(u_boot_console, 'bitstream_load') 206*65a6b3c2SMichal Simek 207*65a6b3c2SMichal Simek expected_text = 'FPGA loaded successfully' 208*65a6b3c2SMichal Simek output = u_boot_console.run_command('fpga load %x %x $filesize && echo %s' % (dev, addr, expected_text)) 209*65a6b3c2SMichal Simek assert expected_text in output 210*65a6b3c2SMichal Simek 211*65a6b3c2SMichal Simek@pytest.mark.buildconfigspec('cmd_fpga') 212*65a6b3c2SMichal Simek@pytest.mark.buildconfigspec('cmd_fpga_loadp') 213*65a6b3c2SMichal Simek@pytest.mark.buildconfigspec('cmd_echo') 214*65a6b3c2SMichal Simekdef test_fpga_loadp(u_boot_console): 215*65a6b3c2SMichal Simek f, dev, addr, bit, bit_size = load_file_from_var(u_boot_console, 'bitstream_load') 216*65a6b3c2SMichal Simek 217*65a6b3c2SMichal Simek expected_text = 'FPGA loaded successfully' 218*65a6b3c2SMichal Simek output = u_boot_console.run_command('fpga load %x %x $filesize && echo %s' % (dev, addr, expected_text)) 219*65a6b3c2SMichal Simek assert expected_text in output 220*65a6b3c2SMichal Simek 221*65a6b3c2SMichal Simek # And load also partial bistream 222*65a6b3c2SMichal Simek f, dev, addr, bit, bit_size = load_file_from_var(u_boot_console, 'bitstream_loadp') 223*65a6b3c2SMichal Simek 224*65a6b3c2SMichal Simek expected_text = 'FPGA loaded successfully' 225*65a6b3c2SMichal Simek output = u_boot_console.run_command('fpga loadp %x %x $filesize && echo %s' % (dev, addr, expected_text)) 226*65a6b3c2SMichal Simek assert expected_text in output 227*65a6b3c2SMichal Simek 228*65a6b3c2SMichal Simek@pytest.mark.buildconfigspec('cmd_fpga') 229*65a6b3c2SMichal Simek@pytest.mark.buildconfigspec('cmd_echo') 230*65a6b3c2SMichal Simekdef test_fpga_loadb(u_boot_console): 231*65a6b3c2SMichal Simek f, dev, addr, bit, bit_size = load_file_from_var(u_boot_console, 'bitstream_loadb') 232*65a6b3c2SMichal Simek 233*65a6b3c2SMichal Simek expected_text = 'FPGA loaded successfully' 234*65a6b3c2SMichal Simek output = u_boot_console.run_command('fpga loadb %x %x $filesize && echo %s' % (dev, addr, expected_text)) 235*65a6b3c2SMichal Simek assert expected_text in output 236*65a6b3c2SMichal Simek 237*65a6b3c2SMichal Simek@pytest.mark.buildconfigspec('cmd_fpga') 238*65a6b3c2SMichal Simek@pytest.mark.buildconfigspec('cmd_fpga_loadbp') 239*65a6b3c2SMichal Simek@pytest.mark.buildconfigspec('cmd_echo') 240*65a6b3c2SMichal Simekdef test_fpga_loadbp(u_boot_console): 241*65a6b3c2SMichal Simek f, dev, addr, bit, bit_size = load_file_from_var(u_boot_console, 'bitstream_loadb') 242*65a6b3c2SMichal Simek 243*65a6b3c2SMichal Simek expected_text = 'FPGA loaded successfully' 244*65a6b3c2SMichal Simek output = u_boot_console.run_command('fpga loadb %x %x $filesize && echo %s' % (dev, addr, expected_text)) 245*65a6b3c2SMichal Simek assert expected_text in output 246*65a6b3c2SMichal Simek 247*65a6b3c2SMichal Simek # And load also partial bistream in bit format 248*65a6b3c2SMichal Simek f, dev, addr, bit, bit_size = load_file_from_var(u_boot_console, 'bitstream_loadbp') 249*65a6b3c2SMichal Simek 250*65a6b3c2SMichal Simek expected_text = 'FPGA loaded successfully' 251*65a6b3c2SMichal Simek output = u_boot_console.run_command('fpga loadbp %x %x $filesize && echo %s' % (dev, addr, expected_text)) 252*65a6b3c2SMichal Simek assert expected_text in output 253*65a6b3c2SMichal Simek 254*65a6b3c2SMichal Simek###### FPGA LOADMK tests ###### 255*65a6b3c2SMichal Simek 256*65a6b3c2SMichal Simek@pytest.mark.buildconfigspec('cmd_fpga') 257*65a6b3c2SMichal Simek@pytest.mark.buildconfigspec('cmd_fpga_loadmk') 258*65a6b3c2SMichal Simek@pytest.mark.buildconfigspec('cmd_echo') 259*65a6b3c2SMichal Simek@pytest.mark.buildconfigspec('image_format_legacy') 260*65a6b3c2SMichal Simekdef test_fpga_loadmk_fail(u_boot_console): 261*65a6b3c2SMichal Simek f, dev, addr, bit, bit_size = load_file_from_var(u_boot_console, 'mkimage_legacy') 262*65a6b3c2SMichal Simek 263*65a6b3c2SMichal Simek u_boot_console.run_command('imi %x' % (addr)) 264*65a6b3c2SMichal Simek 265*65a6b3c2SMichal Simek # load image but pass incorrect address to show error message 266*65a6b3c2SMichal Simek expected = 'Unknown image type' 267*65a6b3c2SMichal Simek output = u_boot_console.run_command('fpga loadmk %x %x' % (dev, addr + 0x10)) 268*65a6b3c2SMichal Simek assert expected in output 269*65a6b3c2SMichal Simek 270*65a6b3c2SMichal Simek # Pass more parameters then command expects - 0 at the end 271*65a6b3c2SMichal Simek output = u_boot_console.run_command('fpga loadmk %x %x 0' % (dev, addr)) 272*65a6b3c2SMichal Simek #assert expected in output 273*65a6b3c2SMichal Simek assert expected_usage in output 274*65a6b3c2SMichal Simek 275*65a6b3c2SMichal Simek@pytest.mark.buildconfigspec('cmd_fpga') 276*65a6b3c2SMichal Simek@pytest.mark.buildconfigspec('cmd_fpga_loadmk') 277*65a6b3c2SMichal Simek@pytest.mark.buildconfigspec('cmd_echo') 278*65a6b3c2SMichal Simek@pytest.mark.buildconfigspec('image_format_legacy') 279*65a6b3c2SMichal Simekdef test_fpga_loadmk_legacy(u_boot_console): 280*65a6b3c2SMichal Simek f, dev, addr, bit, bit_size = load_file_from_var(u_boot_console, 'mkimage_legacy') 281*65a6b3c2SMichal Simek 282*65a6b3c2SMichal Simek u_boot_console.run_command('imi %x' % (addr)) 283*65a6b3c2SMichal Simek 284*65a6b3c2SMichal Simek expected_text = 'FPGA loaded successfully' 285*65a6b3c2SMichal Simek output = u_boot_console.run_command('fpga loadmk %x %x && echo %s' % (dev, addr, expected_text)) 286*65a6b3c2SMichal Simek assert expected_text in output 287*65a6b3c2SMichal Simek 288*65a6b3c2SMichal Simek@pytest.mark.xfail 289*65a6b3c2SMichal Simek@pytest.mark.buildconfigspec('cmd_fpga') 290*65a6b3c2SMichal Simek@pytest.mark.buildconfigspec('cmd_fpga_loadmk') 291*65a6b3c2SMichal Simek@pytest.mark.buildconfigspec('cmd_echo') 292*65a6b3c2SMichal Simek@pytest.mark.buildconfigspec('image_format_legacy') 293*65a6b3c2SMichal Simekdef test_fpga_loadmk_legacy_variable_fpga(u_boot_console): 294*65a6b3c2SMichal Simek f, dev, addr, bit, bit_size = load_file_from_var(u_boot_console, 'mkimage_legacy') 295*65a6b3c2SMichal Simek 296*65a6b3c2SMichal Simek u_boot_console.run_command('imi %x' % (addr)) 297*65a6b3c2SMichal Simek 298*65a6b3c2SMichal Simek u_boot_console.run_command('setenv fpga %x' % (dev)) 299*65a6b3c2SMichal Simek 300*65a6b3c2SMichal Simek # this testcase should cover case which looks like it is supported but dev pointer is broken by loading mkimage address 301*65a6b3c2SMichal Simek expected_text = 'FPGA loaded successfully' 302*65a6b3c2SMichal Simek output = u_boot_console.run_command('fpga loadmk %x && echo %s' % (addr, expected_text)) 303*65a6b3c2SMichal Simek u_boot_console.run_command('setenv fpga') 304*65a6b3c2SMichal Simek assert expected_text in output 305*65a6b3c2SMichal Simek 306*65a6b3c2SMichal Simek@pytest.mark.buildconfigspec('cmd_fpga') 307*65a6b3c2SMichal Simek@pytest.mark.buildconfigspec('cmd_fpga_loadmk') 308*65a6b3c2SMichal Simek@pytest.mark.buildconfigspec('cmd_echo') 309*65a6b3c2SMichal Simek@pytest.mark.buildconfigspec('image_format_legacy') 310*65a6b3c2SMichal Simekdef test_fpga_loadmk_legacy_variable_fpgadata(u_boot_console): 311*65a6b3c2SMichal Simek f, dev, addr, bit, bit_size = load_file_from_var(u_boot_console, 'mkimage_legacy') 312*65a6b3c2SMichal Simek 313*65a6b3c2SMichal Simek u_boot_console.run_command('imi %x' % (addr)) 314*65a6b3c2SMichal Simek 315*65a6b3c2SMichal Simek u_boot_console.run_command('setenv fpgadata %x' % (addr)) 316*65a6b3c2SMichal Simek 317*65a6b3c2SMichal Simek # this testcase should cover case which looks like it is supported but dev pointer is broken by loading mkimage address 318*65a6b3c2SMichal Simek expected_text = 'FPGA loaded successfully' 319*65a6b3c2SMichal Simek output = u_boot_console.run_command('fpga loadmk %x && echo %s' % (dev, expected_text)) 320*65a6b3c2SMichal Simek u_boot_console.run_command('setenv fpgadata') 321*65a6b3c2SMichal Simek assert expected_text in output 322*65a6b3c2SMichal Simek 323*65a6b3c2SMichal Simek@pytest.mark.buildconfigspec('cmd_fpga') 324*65a6b3c2SMichal Simek@pytest.mark.buildconfigspec('cmd_fpga_loadmk') 325*65a6b3c2SMichal Simek@pytest.mark.buildconfigspec('cmd_echo') 326*65a6b3c2SMichal Simek@pytest.mark.buildconfigspec('image_format_legacy') 327*65a6b3c2SMichal Simekdef test_fpga_loadmk_legacy_variable(u_boot_console): 328*65a6b3c2SMichal Simek f, dev, addr, bit, bit_size = load_file_from_var(u_boot_console, 'mkimage_legacy') 329*65a6b3c2SMichal Simek 330*65a6b3c2SMichal Simek u_boot_console.run_command('imi %x' % (addr)) 331*65a6b3c2SMichal Simek 332*65a6b3c2SMichal Simek u_boot_console.run_command('setenv fpga %x' % (dev)) 333*65a6b3c2SMichal Simek u_boot_console.run_command('setenv fpgadata %x' % (addr)) 334*65a6b3c2SMichal Simek 335*65a6b3c2SMichal Simek # this testcase should cover case which looks like it is supported but dev pointer is broken by loading mkimage address 336*65a6b3c2SMichal Simek expected_text = 'FPGA loaded successfully' 337*65a6b3c2SMichal Simek output = u_boot_console.run_command('fpga loadmk && echo %s' % (expected_text)) 338*65a6b3c2SMichal Simek u_boot_console.run_command('setenv fpga') 339*65a6b3c2SMichal Simek u_boot_console.run_command('setenv fpgadata') 340*65a6b3c2SMichal Simek assert expected_text in output 341*65a6b3c2SMichal Simek 342*65a6b3c2SMichal Simek@pytest.mark.buildconfigspec('cmd_fpga') 343*65a6b3c2SMichal Simek@pytest.mark.buildconfigspec('cmd_fpga_loadmk') 344*65a6b3c2SMichal Simek@pytest.mark.buildconfigspec('cmd_echo') 345*65a6b3c2SMichal Simek@pytest.mark.buildconfigspec('image_format_legacy') 346*65a6b3c2SMichal Simek@pytest.mark.buildconfigspec('gzip') 347*65a6b3c2SMichal Simekdef test_fpga_loadmk_legacy_gz(u_boot_console): 348*65a6b3c2SMichal Simek f, dev, addr, bit, bit_size = load_file_from_var(u_boot_console, 'mkimage_legacy_gz') 349*65a6b3c2SMichal Simek 350*65a6b3c2SMichal Simek u_boot_console.run_command('imi %x' % (addr)) 351*65a6b3c2SMichal Simek 352*65a6b3c2SMichal Simek expected_text = 'FPGA loaded successfully' 353*65a6b3c2SMichal Simek output = u_boot_console.run_command('fpga loadmk %x %x && echo %s' % (dev, addr, expected_text)) 354*65a6b3c2SMichal Simek assert expected_text in output 355*65a6b3c2SMichal Simek 356*65a6b3c2SMichal Simek@pytest.mark.buildconfigspec('cmd_fpga') 357*65a6b3c2SMichal Simek@pytest.mark.buildconfigspec('cmd_fpga_loadmk') 358*65a6b3c2SMichal Simek@pytest.mark.buildconfigspec('fit') 359*65a6b3c2SMichal Simek@pytest.mark.buildconfigspec('cmd_echo') 360*65a6b3c2SMichal Simekdef test_fpga_loadmk_fit(u_boot_console): 361*65a6b3c2SMichal Simek f, dev, addr, bit, bit_size = load_file_from_var(u_boot_console, 'mkimage_fit') 362*65a6b3c2SMichal Simek 363*65a6b3c2SMichal Simek u_boot_console.run_command('imi %x' % (addr)) 364*65a6b3c2SMichal Simek 365*65a6b3c2SMichal Simek expected_text = 'FPGA loaded successfully' 366*65a6b3c2SMichal Simek output = u_boot_console.run_command('fpga loadmk %x %x:fpga && echo %s' % (dev, addr, expected_text)) 367*65a6b3c2SMichal Simek assert expected_text in output 368*65a6b3c2SMichal Simek 369*65a6b3c2SMichal Simek@pytest.mark.buildconfigspec('cmd_fpga') 370*65a6b3c2SMichal Simek@pytest.mark.buildconfigspec('cmd_fpga_loadmk') 371*65a6b3c2SMichal Simek@pytest.mark.buildconfigspec('fit') 372*65a6b3c2SMichal Simek@pytest.mark.buildconfigspec('cmd_echo') 373*65a6b3c2SMichal Simekdef test_fpga_loadmk_fit_variable_fpga(u_boot_console): 374*65a6b3c2SMichal Simek f, dev, addr, bit, bit_size = load_file_from_var(u_boot_console, 'mkimage_fit') 375*65a6b3c2SMichal Simek 376*65a6b3c2SMichal Simek u_boot_console.run_command('imi %x' % (addr)) 377*65a6b3c2SMichal Simek # FIXME this should fail - broken support in past 378*65a6b3c2SMichal Simek u_boot_console.run_command('setenv fpga %x' % (dev)) 379*65a6b3c2SMichal Simek 380*65a6b3c2SMichal Simek expected_text = 'FPGA loaded successfully' 381*65a6b3c2SMichal Simek output = u_boot_console.run_command('fpga loadmk %x:fpga && echo %s' % (addr, expected_text)) 382*65a6b3c2SMichal Simek u_boot_console.run_command('setenv fpga') 383*65a6b3c2SMichal Simek assert expected_text in output 384*65a6b3c2SMichal Simek 385*65a6b3c2SMichal Simek@pytest.mark.buildconfigspec('cmd_fpga') 386*65a6b3c2SMichal Simek@pytest.mark.buildconfigspec('cmd_fpga_loadmk') 387*65a6b3c2SMichal Simek@pytest.mark.buildconfigspec('fit') 388*65a6b3c2SMichal Simek@pytest.mark.buildconfigspec('cmd_echo') 389*65a6b3c2SMichal Simekdef test_fpga_loadmk_fit_variable_fpgadata(u_boot_console): 390*65a6b3c2SMichal Simek f, dev, addr, bit, bit_size = load_file_from_var(u_boot_console, 'mkimage_fit') 391*65a6b3c2SMichal Simek 392*65a6b3c2SMichal Simek u_boot_console.run_command('imi %x' % (addr)) 393*65a6b3c2SMichal Simek # FIXME this should fail - broken support in past 394*65a6b3c2SMichal Simek u_boot_console.run_command('setenv fpgadata %x:fpga' % (addr)) 395*65a6b3c2SMichal Simek 396*65a6b3c2SMichal Simek expected_text = 'FPGA loaded successfully' 397*65a6b3c2SMichal Simek output = u_boot_console.run_command('fpga loadmk %x && echo %s' % (dev, expected_text)) 398*65a6b3c2SMichal Simek u_boot_console.run_command('setenv fpgadata') 399*65a6b3c2SMichal Simek assert expected_text in output 400*65a6b3c2SMichal Simek 401*65a6b3c2SMichal Simek@pytest.mark.buildconfigspec('cmd_fpga') 402*65a6b3c2SMichal Simek@pytest.mark.buildconfigspec('cmd_fpga_loadmk') 403*65a6b3c2SMichal Simek@pytest.mark.buildconfigspec('fit') 404*65a6b3c2SMichal Simek@pytest.mark.buildconfigspec('cmd_echo') 405*65a6b3c2SMichal Simekdef test_fpga_loadmk_fit_variable(u_boot_console): 406*65a6b3c2SMichal Simek f, dev, addr, bit, bit_size = load_file_from_var(u_boot_console, 'mkimage_fit') 407*65a6b3c2SMichal Simek 408*65a6b3c2SMichal Simek u_boot_console.run_command('imi %x' % (addr)) 409*65a6b3c2SMichal Simek 410*65a6b3c2SMichal Simek u_boot_console.run_command('setenv fpga %x' % (dev)) 411*65a6b3c2SMichal Simek u_boot_console.run_command('setenv fpgadata %x:fpga' % (addr)) 412*65a6b3c2SMichal Simek 413*65a6b3c2SMichal Simek expected_text = 'FPGA loaded successfully' 414*65a6b3c2SMichal Simek output = u_boot_console.run_command('fpga loadmk && echo %s' % (expected_text)) 415*65a6b3c2SMichal Simek u_boot_console.run_command('setenv fpga') 416*65a6b3c2SMichal Simek u_boot_console.run_command('setenv fpgadata') 417*65a6b3c2SMichal Simek assert expected_text in output 418*65a6b3c2SMichal Simek 419*65a6b3c2SMichal Simek###### FPGA LOAD tests ###### 420*65a6b3c2SMichal Simek 421*65a6b3c2SMichal Simek@pytest.mark.buildconfigspec('cmd_fpga') 422*65a6b3c2SMichal Simekdef test_fpga_loadfs_fail(u_boot_console): 423*65a6b3c2SMichal Simek dev, f = check_dev(u_boot_console) 424*65a6b3c2SMichal Simek 425*65a6b3c2SMichal Simek addr = f.get('addr', -1) 426*65a6b3c2SMichal Simek if addr < 0: 427*65a6b3c2SMichal Simek pytest.fail('No address specified via env__fpga_under_test') 428*65a6b3c2SMichal Simek 429*65a6b3c2SMichal Simek bit = f['loadfs'] 430*65a6b3c2SMichal Simek bit_size = f['loadfs_size'] 431*65a6b3c2SMichal Simek block_size = f['loadfs_block_size'] 432*65a6b3c2SMichal Simek 433*65a6b3c2SMichal Simek # less params - dev number removed 434*65a6b3c2SMichal Simek expected = 'fpga: incorrect parameters passed' 435*65a6b3c2SMichal Simek output = u_boot_console.run_command('fpga loadfs %x %x %x %s' % (addr, bit_size, block_size, bit)) 436*65a6b3c2SMichal Simek #assert expected in output 437*65a6b3c2SMichal Simek assert expected_usage in output 438*65a6b3c2SMichal Simek 439*65a6b3c2SMichal Simek # one more param - 0 at the end 440*65a6b3c2SMichal Simek # This is the longest command that's why there is no message from cmd/fpga.c 441*65a6b3c2SMichal Simek output = u_boot_console.run_command('fpga loadfs %x %x %x %x %s 0' % (dev, addr, bit_size, block_size, bit)) 442*65a6b3c2SMichal Simek assert expected_usage in output 443*65a6b3c2SMichal Simek 444*65a6b3c2SMichal Simek # zero address 0 445*65a6b3c2SMichal Simek expected = 'fpga: zero fpga_data address' 446*65a6b3c2SMichal Simek output = u_boot_console.run_command('fpga loadfs %x %x %x %x %s' % (dev, 0, bit_size, block_size, bit)) 447*65a6b3c2SMichal Simek #assert expected in output 448*65a6b3c2SMichal Simek assert expected_usage in output 449*65a6b3c2SMichal Simek 450*65a6b3c2SMichal Simek # bit_size 0 451*65a6b3c2SMichal Simek expected = 'fpga: zero size' 452*65a6b3c2SMichal Simek output = u_boot_console.run_command('fpga loadfs %x %x %x %x %s' % (dev, addr, 0, block_size, bit)) 453*65a6b3c2SMichal Simek #assert expected in output 454*65a6b3c2SMichal Simek assert expected_usage in output 455*65a6b3c2SMichal Simek 456*65a6b3c2SMichal Simek # block size 0 457*65a6b3c2SMichal Simek # FIXME this should pass but it failing too 458*65a6b3c2SMichal Simek output = u_boot_console.run_command('fpga loadfs %x %x %x %x %s' % (dev, addr, bit_size, 0, bit)) 459*65a6b3c2SMichal Simek assert expected_usage in output 460*65a6b3c2SMichal Simek 461*65a6b3c2SMichal Simek # non existing bitstream name 462*65a6b3c2SMichal Simek expected = 'Unable to read file noname' 463*65a6b3c2SMichal Simek output = u_boot_console.run_command('fpga loadfs %x %x %x %x mmc 0 noname' % (dev, addr, bit_size, block_size)) 464*65a6b3c2SMichal Simek assert expected in output 465*65a6b3c2SMichal Simek assert expected_usage in output 466*65a6b3c2SMichal Simek 467*65a6b3c2SMichal Simek # -1 dev number 468*65a6b3c2SMichal Simek expected = 'fpga_fsload: Invalid device number -1' 469*65a6b3c2SMichal Simek output = u_boot_console.run_command('fpga loadfs %d %x %x %x mmc 0 noname' % (-1, addr, bit_size, block_size)) 470*65a6b3c2SMichal Simek assert expected in output 471*65a6b3c2SMichal Simek assert expected_usage in output 472*65a6b3c2SMichal Simek 473*65a6b3c2SMichal Simek 474*65a6b3c2SMichal Simek@pytest.mark.buildconfigspec('cmd_fpga') 475*65a6b3c2SMichal Simek@pytest.mark.buildconfigspec('cmd_echo') 476*65a6b3c2SMichal Simekdef test_fpga_loadfs(u_boot_console): 477*65a6b3c2SMichal Simek dev, f = check_dev(u_boot_console) 478*65a6b3c2SMichal Simek 479*65a6b3c2SMichal Simek addr = f.get('addr', -1) 480*65a6b3c2SMichal Simek if addr < 0: 481*65a6b3c2SMichal Simek pytest.fail('No address specified via env__fpga_under_test') 482*65a6b3c2SMichal Simek 483*65a6b3c2SMichal Simek bit = f['loadfs'] 484*65a6b3c2SMichal Simek bit_size = f['loadfs_size'] 485*65a6b3c2SMichal Simek block_size = f['loadfs_block_size'] 486*65a6b3c2SMichal Simek 487*65a6b3c2SMichal Simek # This should be done better 488*65a6b3c2SMichal Simek expected_text = 'FPGA loaded successfully' 489*65a6b3c2SMichal Simek output = u_boot_console.run_command('fpga loadfs %x %x %x %x %s && echo %s' % (dev, addr, bit_size, block_size, bit, expected_text)) 490*65a6b3c2SMichal Simek assert expected_text in output 491*65a6b3c2SMichal Simek 492*65a6b3c2SMichal Simek@pytest.mark.buildconfigspec('cmd_fpga') 493*65a6b3c2SMichal Simek@pytest.mark.buildconfigspec('cmd_fpga_load_secure') 494*65a6b3c2SMichal Simek@pytest.mark.buildconfigspec('cmd_net') 495*65a6b3c2SMichal Simek@pytest.mark.buildconfigspec('cmd_dhcp') 496*65a6b3c2SMichal Simek@pytest.mark.buildconfigspec('net') 497*65a6b3c2SMichal Simekdef test_fpga_secure_bit_auth(u_boot_console): 498*65a6b3c2SMichal Simek 499*65a6b3c2SMichal Simek test_net.test_net_dhcp(u_boot_console) 500*65a6b3c2SMichal Simek test_net.test_net_setup_static(u_boot_console) 501*65a6b3c2SMichal Simek 502*65a6b3c2SMichal Simek f = u_boot_console.config.env.get('env__fpga_secure_readable_file', None) 503*65a6b3c2SMichal Simek if not f: 504*65a6b3c2SMichal Simek pytest.skip('No TFTP readable file to read') 505*65a6b3c2SMichal Simek 506*65a6b3c2SMichal Simek addr = f.get('addr', None) 507*65a6b3c2SMichal Simek if not addr: 508*65a6b3c2SMichal Simek addr = u_boot_utils.find_ram_base(u_boot_console) 509*65a6b3c2SMichal Simek 510*65a6b3c2SMichal Simek expected_tftp = 'Bytes transferred = ' 511*65a6b3c2SMichal Simek fn = f['fn'] 512*65a6b3c2SMichal Simek output = u_boot_console.run_command('tftpboot %x %s' % (addr, fn)) 513*65a6b3c2SMichal Simek assert expected_tftp in output 514*65a6b3c2SMichal Simek 515*65a6b3c2SMichal Simek expected_zynqmpsecure = 'Bitstream successfully loaded' 516*65a6b3c2SMichal Simek output = u_boot_console.run_command('fpga loads 0 %x $filesize 0 2' % (addr)) 517*65a6b3c2SMichal Simek assert expected_zynqmpsecure in output 518*65a6b3c2SMichal Simek 519*65a6b3c2SMichal Simek 520*65a6b3c2SMichal Simek@pytest.mark.buildconfigspec('cmd_fpga') 521*65a6b3c2SMichal Simek@pytest.mark.buildconfigspec('cmd_fpga_load_secure') 522*65a6b3c2SMichal Simek@pytest.mark.buildconfigspec('cmd_net') 523*65a6b3c2SMichal Simek@pytest.mark.buildconfigspec('cmd_dhcp') 524*65a6b3c2SMichal Simek@pytest.mark.buildconfigspec('net') 525*65a6b3c2SMichal Simekdef test_fpga_secure_bit_img_auth_kup(u_boot_console): 526*65a6b3c2SMichal Simek 527*65a6b3c2SMichal Simek test_net.test_net_dhcp(u_boot_console) 528*65a6b3c2SMichal Simek test_net.test_net_setup_static(u_boot_console) 529*65a6b3c2SMichal Simek 530*65a6b3c2SMichal Simek f = u_boot_console.config.env.get('env__fpga_secure_readable_file', None) 531*65a6b3c2SMichal Simek if not f: 532*65a6b3c2SMichal Simek pytest.skip('No TFTP readable file to read') 533*65a6b3c2SMichal Simek 534*65a6b3c2SMichal Simek keyaddr = f.get('keyaddr', None) 535*65a6b3c2SMichal Simek if not keyaddr: 536*65a6b3c2SMichal Simek addr = u_boot_utils.find_ram_base(u_boot_console) 537*65a6b3c2SMichal Simek expected_tftp = 'Bytes transferred = ' 538*65a6b3c2SMichal Simek keyfn = f['keyfn'] 539*65a6b3c2SMichal Simek output = u_boot_console.run_command('tftpboot %x %s' % (keyaddr, keyfn)) 540*65a6b3c2SMichal Simek assert expected_tftp in output 541*65a6b3c2SMichal Simek 542*65a6b3c2SMichal Simek addr = f.get('addr', None) 543*65a6b3c2SMichal Simek if not addr: 544*65a6b3c2SMichal Simek addr = u_boot_utils.find_ram_base(u_boot_console) 545*65a6b3c2SMichal Simek expected_tftp = 'Bytes transferred = ' 546*65a6b3c2SMichal Simek fn = f['enckupfn'] 547*65a6b3c2SMichal Simek output = u_boot_console.run_command('tftpboot %x %s' % (addr, fn)) 548*65a6b3c2SMichal Simek assert expected_tftp in output 549*65a6b3c2SMichal Simek 550*65a6b3c2SMichal Simek expected_zynqmpsecure = 'Bitstream successfully loaded' 551*65a6b3c2SMichal Simek output = u_boot_console.run_command('fpga loads 0 %x $filesize 0 1 %x' % (addr, keyaddr)) 552*65a6b3c2SMichal Simek assert expected_zynqmpsecure in output 553