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 @pytest.mark.buildconfigspec('cmd_mmc')
61 def test_mmc_rd(u_boot_console, env__mmc_rd_config):
62 """Test the "mmc read" command.
65 u_boot_console: A U-Boot console connection.
66 env__mmc_rd_config: The single MMC configuration on which
67 to run the test. See the file-level comment above for details
74 is_emmc = env__mmc_rd_config['is_emmc']
75 devid = env__mmc_rd_config['devid']
76 partid = env__mmc_rd_config.get('partid', 0)
77 sector = env__mmc_rd_config.get('sector', 0)
78 count_sectors = env__mmc_rd_config.get('count', 1)
79 expected_crc32 = env__mmc_rd_config.get('crc32', None)
81 count_bytes = count_sectors * 512
82 bcfg = u_boot_console.config.buildconfig
83 has_cmd_memory = bcfg.get('config_cmd_memory', 'n') == 'y'
84 has_cmd_crc32 = bcfg.get('config_cmd_crc32', 'n') == 'y'
85 ram_base = u_boot_utils.find_ram_base(u_boot_console)
86 addr = '0x%08x' % ram_base
89 cmd = 'mmc dev %d' % devid
92 response = u_boot_console.run_command(cmd)
93 assert 'no card present' not in response
95 partid_response = "(part %d)" % partid
98 good_response = 'mmc%d%s is current device' % (devid, partid_response)
99 assert good_response in response
103 if has_cmd_memory and has_cmd_crc32:
104 cmd = 'mw.b %s 0 0x%x' % (addr, count_bytes)
105 u_boot_console.run_command(cmd)
107 cmd = 'crc32 %s 0x%x' % (addr, count_bytes)
108 response = u_boot_console.run_command(cmd)
109 assert expected_crc32 not in response
111 u_boot_console.log.warning(
112 'CONFIG_CMD_MEMORY or CONFIG_CMD_CRC32 != y: Skipping RAM clear')
115 cmd = 'mmc read %s %x %x' % (addr, sector, count_sectors)
116 response = u_boot_console.run_command(cmd)
117 good_response = 'MMC read: dev # %d, block # %d, count %d ... %d blocks read: OK' % (
118 devid, sector, count_sectors, count_sectors)
119 assert good_response in response
124 cmd = 'crc32 %s 0x%x' % (addr, count_bytes)
125 response = u_boot_console.run_command(cmd)
126 assert expected_crc32 in response
128 u_boot_console.log.warning('CONFIG_CMD_CRC32 != y: Skipping check')