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.
13 This test relies on boardenv_* to containing configuration values to define
14 which MMC devices should be tested. For example:
16 # Configuration data for test_mmc_dev, test_mmc_rescan, test_mmc_info; defines
17 # whole MMC devices that mmc dev/rescan/info commands may operate upon.
18 env__mmc_dev_configs = (
20 'fixture_id': 'emmc-boot0',
30 'fixture_id': 'emmc-boot1',
40 'fixture_id': 'emmc-data',
61 # Configuration data for test_mmc_rd; defines regions of the MMC (entire
62 # devices, or ranges of sectors) which can be read:
63 env__mmc_rd_configs = (
65 'fixture_id': 'emmc-boot0',
73 'fixture_id': 'emmc-boot1',
81 'fixture_id': 'emmc-data',
89 'fixture_id': 'sd-mbr',
98 'fixture_id': 'sd-large',
108 def mmc_dev(u_boot_console, is_emmc, devid, partid):
109 """Run the "mmc dev" command.
112 u_boot_console: A U-Boot console connection.
113 is_emmc: Whether the device is eMMC
122 cmd = 'mmc dev %d' % devid
124 cmd += ' %d' % partid
125 response = u_boot_console.run_command(cmd)
126 assert 'no card present' not in response
128 partid_response = '(part %d)' % partid
131 good_response = 'mmc%d%s is current device' % (devid, partid_response)
132 assert good_response in response
134 @pytest.mark.buildconfigspec('cmd_mmc')
135 def test_mmc_dev(u_boot_console, env__mmc_dev_config):
136 """Test the "mmc dev" command.
139 u_boot_console: A U-Boot console connection.
140 env__mmc_dev_config: The single MMC configuration on which
141 to run the test. See the file-level comment above for details
148 is_emmc = env__mmc_dev_config['is_emmc']
149 devid = env__mmc_dev_config['devid']
150 partid = env__mmc_dev_config.get('partid', 0)
153 mmc_dev(u_boot_console, is_emmc, devid, partid)
155 @pytest.mark.buildconfigspec('cmd_mmc')
156 def test_mmc_rescan(u_boot_console, env__mmc_dev_config):
157 """Test the "mmc rescan" command.
160 u_boot_console: A U-Boot console connection.
161 env__mmc_dev_config: The single MMC configuration on which
162 to run the test. See the file-level comment above for details
169 is_emmc = env__mmc_dev_config['is_emmc']
170 devid = env__mmc_dev_config['devid']
171 partid = env__mmc_dev_config.get('partid', 0)
174 mmc_dev(u_boot_console, is_emmc, devid, partid)
178 response = u_boot_console.run_command(cmd)
179 assert 'no card present' not in response
181 @pytest.mark.buildconfigspec('cmd_mmc')
182 def test_mmc_info(u_boot_console, env__mmc_dev_config):
183 """Test the "mmc info" command.
186 u_boot_console: A U-Boot console connection.
187 env__mmc_dev_config: The single MMC configuration on which
188 to run the test. See the file-level comment above for details
195 is_emmc = env__mmc_dev_config['is_emmc']
196 devid = env__mmc_dev_config['devid']
197 partid = env__mmc_dev_config.get('partid', 0)
198 info_device = env__mmc_dev_config['info_device']
199 info_speed = env__mmc_dev_config['info_speed']
200 info_mode = env__mmc_dev_config['info_mode']
201 info_buswidth = env__mmc_dev_config['info_buswidth']
204 mmc_dev(u_boot_console, is_emmc, devid, partid)
206 # Read MMC device information
208 response = u_boot_console.run_command(cmd)
209 good_response = "Device: %s" % info_device
210 assert good_response in response
211 good_response = "Bus Speed: %s" % info_speed
212 assert good_response in response
213 good_response = "Mode : %s" % info_mode
214 assert good_response in response
215 good_response = "Bus Width: %s" % info_buswidth
216 assert good_response in response
218 @pytest.mark.buildconfigspec('cmd_mmc')
219 def test_mmc_rd(u_boot_console, env__mmc_rd_config):
220 """Test the "mmc read" command.
223 u_boot_console: A U-Boot console connection.
224 env__mmc_rd_config: The single MMC configuration on which
225 to run the test. See the file-level comment above for details
232 is_emmc = env__mmc_rd_config['is_emmc']
233 devid = env__mmc_rd_config['devid']
234 partid = env__mmc_rd_config.get('partid', 0)
235 sector = env__mmc_rd_config.get('sector', 0)
236 count_sectors = env__mmc_rd_config.get('count', 1)
237 expected_crc32 = env__mmc_rd_config.get('crc32', None)
238 read_duration_max = env__mmc_rd_config.get('read_duration_max', 0)
240 count_bytes = count_sectors * 512
241 bcfg = u_boot_console.config.buildconfig
242 has_cmd_memory = bcfg.get('config_cmd_memory', 'n') == 'y'
243 has_cmd_crc32 = bcfg.get('config_cmd_crc32', 'n') == 'y'
244 ram_base = u_boot_utils.find_ram_base(u_boot_console)
245 addr = '0x%08x' % ram_base
248 mmc_dev(u_boot_console, is_emmc, devid, partid)
252 if has_cmd_memory and has_cmd_crc32:
253 cmd = 'mw.b %s 0 0x%x' % (addr, count_bytes)
254 u_boot_console.run_command(cmd)
256 cmd = 'crc32 %s 0x%x' % (addr, count_bytes)
257 response = u_boot_console.run_command(cmd)
258 assert expected_crc32 not in response
260 u_boot_console.log.warning(
261 'CONFIG_CMD_MEMORY or CONFIG_CMD_CRC32 != y: Skipping RAM clear')
264 cmd = 'mmc read %s %x %x' % (addr, sector, count_sectors)
266 response = u_boot_console.run_command(cmd)
268 good_response = 'MMC read: dev # %d, block # %d, count %d ... %d blocks read: OK' % (
269 devid, sector, count_sectors, count_sectors)
270 assert good_response in response
275 cmd = 'crc32 %s 0x%x' % (addr, count_bytes)
276 response = u_boot_console.run_command(cmd)
277 assert expected_crc32 in response
279 u_boot_console.log.warning('CONFIG_CMD_CRC32 != y: Skipping check')
281 # Check if the command did not take too long
282 if read_duration_max:
283 elapsed = tend - tstart
284 u_boot_console.log.info('Reading %d bytes took %f seconds' %
285 (count_bytes, elapsed))
286 assert elapsed <= (read_duration_max - 0.01)