1 # SPDX-License-Identifier: GPL-2.0
2 # Copyright (c) 2019, Texas Instrument
3 # Author: Jean-Jacques Hiblot <jjhiblot@ti.com>
5 # Test U-Boot's "mmc write" command. The test generates random data, writes it
6 # to the eMMC or SD card, then reads it back and performs a comparison.
12 This test relies on boardenv_* to containing configuration values to define
13 which MMC devices should be tested. For example:
15 env__mmc_wr_configs = (
17 "fixture_id": "emmc-boot0",
23 "test_iterations": 50,
26 "fixture_id": "emmc-boot1",
32 "test_iterations": 50,
38 @pytest.mark.buildconfigspec('cmd_mmc')
39 @pytest.mark.buildconfigspec('cmd_memory')
40 @pytest.mark.buildconfigspec('cmd_random')
41 def test_mmc_wr(u_boot_console, env__mmc_wr_config):
42 """Test the "mmc write" command.
45 u_boot_console: A U-Boot console connection.
46 env__mmc_wr_config: The single MMC configuration on which
47 to run the test. See the file-level comment above for details
54 is_emmc = env__mmc_wr_config['is_emmc']
55 devid = env__mmc_wr_config['devid']
56 partid = env__mmc_wr_config.get('partid', 0)
57 sector = env__mmc_wr_config.get('sector', 0)
58 count_sectors = env__mmc_wr_config.get('count', 1)
59 test_iterations = env__mmc_wr_config.get('test_iterations', 1)
62 count_bytes = count_sectors * 512
63 bcfg = u_boot_console.config.buildconfig
64 ram_base = u_boot_utils.find_ram_base(u_boot_console)
65 src_addr = '0x%08x' % ram_base
66 dst_addr = '0x%08x' % (ram_base + count_bytes)
69 for i in range(test_iterations):
70 # Generate random data
71 cmd = 'random %s %x' % (src_addr, count_bytes)
72 response = u_boot_console.run_command(cmd)
73 good_response = '%d bytes filled with random data' % (count_bytes)
74 assert good_response in response
77 cmd = 'mmc dev %d' % devid
80 response = u_boot_console.run_command(cmd)
81 assert 'no card present' not in response
83 partid_response = "(part %d)" % partid
86 good_response = 'mmc%d%s is current device' % (devid, partid_response)
87 assert good_response in response
90 cmd = 'mmc write %s %x %x' % (src_addr, sector, count_sectors)
91 response = u_boot_console.run_command(cmd)
92 good_response = 'MMC write: dev # %d, block # %d, count %d ... %d blocks written: OK' % (devid, sector, count_sectors, count_sectors)
93 assert good_response in response
96 cmd = 'mmc read %s %x %x' % (dst_addr, sector, count_sectors)
97 response = u_boot_console.run_command(cmd)
98 good_response = 'MMC read: dev # %d, block # %d, count %d ... %d blocks read: OK' % (devid, sector, count_sectors, count_sectors)
99 assert good_response in response
101 # Compare src and dst data
102 cmd = 'cmp.b %s %s %x' % (src_addr, dst_addr, count_bytes)
103 response = u_boot_console.run_command(cmd)
104 good_response = 'Total of %d byte(s) were the same' % (count_bytes)
105 assert good_response in response