1 # SPDX-License-Identifier: GPL-2.0
2 # Copyright (c) 2018, NVIDIA CORPORATION. All rights reserved.
4 # Test U-Boot's "mmc read" command. The test reads data from the eMMC or SD
5 # card, and validates the no errors occurred, and that the expected data was
6 # read if the test configuration contains a CRC of the expected data.
12 This test relies on boardenv_* to containing configuration values to define
13 which MMC devices should be tested. For example:
15 env__mmc_rd_configs = (
17 'fixture_id': 'emmc-boot0',
25 'fixture_id': 'emmc-boot1',
33 'fixture_id': 'emmc-data',
41 'fixture_id': 'sd-mbr',
50 'fixture_id': 'sd-large',
60 def mmc_dev(u_boot_console, is_emmc, devid, partid):
61 """Run the "mmc dev" command.
64 u_boot_console: A U-Boot console connection.
65 is_emmc: Whether the device is eMMC
74 cmd = 'mmc dev %d' % devid
77 response = u_boot_console.run_command(cmd)
78 assert 'no card present' not in response
80 partid_response = '(part %d)' % partid
83 good_response = 'mmc%d%s is current device' % (devid, partid_response)
84 assert good_response in response
86 @pytest.mark.buildconfigspec('cmd_mmc')
87 def test_mmc_dev(u_boot_console, env__mmc_rd_config):
88 """Test the "mmc dev" command.
91 u_boot_console: A U-Boot console connection.
92 env__mmc_rd_config: The single MMC configuration on which
93 to run the test. See the file-level comment above for details
100 is_emmc = env__mmc_rd_config['is_emmc']
101 devid = env__mmc_rd_config['devid']
102 partid = env__mmc_rd_config.get('partid', 0)
105 mmc_dev(u_boot_console, is_emmc, devid, partid)
107 @pytest.mark.buildconfigspec('cmd_mmc')
108 def test_mmc_rescan(u_boot_console, env__mmc_rd_config):
109 """Test the "mmc rescan" command.
112 u_boot_console: A U-Boot console connection.
113 env__mmc_rd_config: The single MMC configuration on which
114 to run the test. See the file-level comment above for details
121 is_emmc = env__mmc_rd_config['is_emmc']
122 devid = env__mmc_rd_config['devid']
123 partid = env__mmc_rd_config.get('partid', 0)
126 mmc_dev(u_boot_console, is_emmc, devid, partid)
130 response = u_boot_console.run_command(cmd)
131 assert 'no card present' not in response
133 @pytest.mark.buildconfigspec('cmd_mmc')
134 def test_mmc_info(u_boot_console, env__mmc_rd_config):
135 """Test the "mmc info" command.
138 u_boot_console: A U-Boot console connection.
139 env__mmc_rd_config: The single MMC configuration on which
140 to run the test. See the file-level comment above for details
147 is_emmc = env__mmc_rd_config['is_emmc']
148 devid = env__mmc_rd_config['devid']
149 partid = env__mmc_rd_config.get('partid', 0)
150 info_device = env__mmc_rd_config['info_device']
151 info_speed = env__mmc_rd_config['info_speed']
152 info_mode = env__mmc_rd_config['info_mode']
153 info_buswidth = env__mmc_rd_config['info_buswidth']
156 mmc_dev(u_boot_console, is_emmc, devid, partid)
158 # Read MMC device information
160 response = u_boot_console.run_command(cmd)
161 good_response = "Device: %s" % info_device
162 assert good_response in response
163 good_response = "Bus Speed: %s" % info_speed
164 assert good_response in response
165 good_response = "Mode : %s" % info_mode
166 assert good_response in response
167 good_response = "Bus Width: %s" % info_buswidth
168 assert good_response in response
170 @pytest.mark.buildconfigspec('cmd_mmc')
171 def test_mmc_rd(u_boot_console, env__mmc_rd_config):
172 """Test the "mmc read" command.
175 u_boot_console: A U-Boot console connection.
176 env__mmc_rd_config: The single MMC configuration on which
177 to run the test. See the file-level comment above for details
184 is_emmc = env__mmc_rd_config['is_emmc']
185 devid = env__mmc_rd_config['devid']
186 partid = env__mmc_rd_config.get('partid', 0)
187 sector = env__mmc_rd_config.get('sector', 0)
188 count_sectors = env__mmc_rd_config.get('count', 1)
189 expected_crc32 = env__mmc_rd_config.get('crc32', None)
191 count_bytes = count_sectors * 512
192 bcfg = u_boot_console.config.buildconfig
193 has_cmd_memory = bcfg.get('config_cmd_memory', 'n') == 'y'
194 has_cmd_crc32 = bcfg.get('config_cmd_crc32', 'n') == 'y'
195 ram_base = u_boot_utils.find_ram_base(u_boot_console)
196 addr = '0x%08x' % ram_base
199 mmc_dev(u_boot_console, is_emmc, devid, partid)
203 if has_cmd_memory and has_cmd_crc32:
204 cmd = 'mw.b %s 0 0x%x' % (addr, count_bytes)
205 u_boot_console.run_command(cmd)
207 cmd = 'crc32 %s 0x%x' % (addr, count_bytes)
208 response = u_boot_console.run_command(cmd)
209 assert expected_crc32 not in response
211 u_boot_console.log.warning(
212 'CONFIG_CMD_MEMORY or CONFIG_CMD_CRC32 != y: Skipping RAM clear')
215 cmd = 'mmc read %s %x %x' % (addr, sector, count_sectors)
216 response = u_boot_console.run_command(cmd)
217 good_response = 'MMC read: dev # %d, block # %d, count %d ... %d blocks read: OK' % (
218 devid, sector, count_sectors, count_sectors)
219 assert good_response in response
224 cmd = 'crc32 %s 0x%x' % (addr, count_bytes)
225 response = u_boot_console.run_command(cmd)
226 assert expected_crc32 in response
228 u_boot_console.log.warning('CONFIG_CMD_CRC32 != y: Skipping check')