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 env__mmc_rd_configs = (
18 'fixture_id': 'emmc-boot0',
26 'fixture_id': 'emmc-boot1',
34 'fixture_id': 'emmc-data',
42 'fixture_id': 'sd-mbr',
51 'fixture_id': 'sd-large',
61 def mmc_dev(u_boot_console, is_emmc, devid, partid):
62 """Run the "mmc dev" command.
65 u_boot_console: A U-Boot console connection.
66 is_emmc: Whether the device is eMMC
75 cmd = 'mmc dev %d' % devid
78 response = u_boot_console.run_command(cmd)
79 assert 'no card present' not in response
81 partid_response = '(part %d)' % partid
84 good_response = 'mmc%d%s is current device' % (devid, partid_response)
85 assert good_response in response
87 @pytest.mark.buildconfigspec('cmd_mmc')
88 def test_mmc_dev(u_boot_console, env__mmc_rd_config):
89 """Test the "mmc dev" command.
92 u_boot_console: A U-Boot console connection.
93 env__mmc_rd_config: The single MMC configuration on which
94 to run the test. See the file-level comment above for details
101 is_emmc = env__mmc_rd_config['is_emmc']
102 devid = env__mmc_rd_config['devid']
103 partid = env__mmc_rd_config.get('partid', 0)
106 mmc_dev(u_boot_console, is_emmc, devid, partid)
108 @pytest.mark.buildconfigspec('cmd_mmc')
109 def test_mmc_rescan(u_boot_console, env__mmc_rd_config):
110 """Test the "mmc rescan" command.
113 u_boot_console: A U-Boot console connection.
114 env__mmc_rd_config: The single MMC configuration on which
115 to run the test. See the file-level comment above for details
122 is_emmc = env__mmc_rd_config['is_emmc']
123 devid = env__mmc_rd_config['devid']
124 partid = env__mmc_rd_config.get('partid', 0)
127 mmc_dev(u_boot_console, is_emmc, devid, partid)
131 response = u_boot_console.run_command(cmd)
132 assert 'no card present' not in response
134 @pytest.mark.buildconfigspec('cmd_mmc')
135 def test_mmc_info(u_boot_console, env__mmc_rd_config):
136 """Test the "mmc info" command.
139 u_boot_console: A U-Boot console connection.
140 env__mmc_rd_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_rd_config['is_emmc']
149 devid = env__mmc_rd_config['devid']
150 partid = env__mmc_rd_config.get('partid', 0)
151 info_device = env__mmc_rd_config['info_device']
152 info_speed = env__mmc_rd_config['info_speed']
153 info_mode = env__mmc_rd_config['info_mode']
154 info_buswidth = env__mmc_rd_config['info_buswidth']
157 mmc_dev(u_boot_console, is_emmc, devid, partid)
159 # Read MMC device information
161 response = u_boot_console.run_command(cmd)
162 good_response = "Device: %s" % info_device
163 assert good_response in response
164 good_response = "Bus Speed: %s" % info_speed
165 assert good_response in response
166 good_response = "Mode : %s" % info_mode
167 assert good_response in response
168 good_response = "Bus Width: %s" % info_buswidth
169 assert good_response in response
171 @pytest.mark.buildconfigspec('cmd_mmc')
172 def test_mmc_rd(u_boot_console, env__mmc_rd_config):
173 """Test the "mmc read" command.
176 u_boot_console: A U-Boot console connection.
177 env__mmc_rd_config: The single MMC configuration on which
178 to run the test. See the file-level comment above for details
185 is_emmc = env__mmc_rd_config['is_emmc']
186 devid = env__mmc_rd_config['devid']
187 partid = env__mmc_rd_config.get('partid', 0)
188 sector = env__mmc_rd_config.get('sector', 0)
189 count_sectors = env__mmc_rd_config.get('count', 1)
190 expected_crc32 = env__mmc_rd_config.get('crc32', None)
191 read_duration_max = env__mmc_rd_config.get('read_duration_max', 0)
193 count_bytes = count_sectors * 512
194 bcfg = u_boot_console.config.buildconfig
195 has_cmd_memory = bcfg.get('config_cmd_memory', 'n') == 'y'
196 has_cmd_crc32 = bcfg.get('config_cmd_crc32', 'n') == 'y'
197 ram_base = u_boot_utils.find_ram_base(u_boot_console)
198 addr = '0x%08x' % ram_base
201 mmc_dev(u_boot_console, is_emmc, devid, partid)
205 if has_cmd_memory and has_cmd_crc32:
206 cmd = 'mw.b %s 0 0x%x' % (addr, count_bytes)
207 u_boot_console.run_command(cmd)
209 cmd = 'crc32 %s 0x%x' % (addr, count_bytes)
210 response = u_boot_console.run_command(cmd)
211 assert expected_crc32 not in response
213 u_boot_console.log.warning(
214 'CONFIG_CMD_MEMORY or CONFIG_CMD_CRC32 != y: Skipping RAM clear')
217 cmd = 'mmc read %s %x %x' % (addr, sector, count_sectors)
219 response = u_boot_console.run_command(cmd)
221 good_response = 'MMC read: dev # %d, block # %d, count %d ... %d blocks read: OK' % (
222 devid, sector, count_sectors, count_sectors)
223 assert good_response in response
228 cmd = 'crc32 %s 0x%x' % (addr, count_bytes)
229 response = u_boot_console.run_command(cmd)
230 assert expected_crc32 in response
232 u_boot_console.log.warning('CONFIG_CMD_CRC32 != y: Skipping check')
234 # Check if the command did not take too long
235 if read_duration_max:
236 elapsed = tend - tstart
237 u_boot_console.log.info('Reading %d bytes took %f seconds' %
238 (count_bytes, elapsed))
239 assert elapsed <= (read_duration_max - 0.01)