1 # Copyright (c) 2018, NVIDIA CORPORATION. All rights reserved.
3 # SPDX-License-Identifier: GPL-2.0
5 # Test U-Boot's "mmc read" command. The test reads data from the eMMC or SD
6 # card, and validates the no errors occurred, and that the expected data was
7 # 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 @pytest.mark.buildconfigspec('cmd_mmc')
62 def test_mmc_rd(u_boot_console, env__mmc_rd_config):
63 """Test the "mmc read" command.
66 u_boot_console: A U-Boot console connection.
67 env__mmc_rd_config: The single MMC configuration on which
68 to run the test. See the file-level comment above for details
75 is_emmc = env__mmc_rd_config['is_emmc']
76 devid = env__mmc_rd_config['devid']
77 partid = env__mmc_rd_config.get('partid', 0)
78 sector = env__mmc_rd_config.get('sector', 0)
79 count_sectors = env__mmc_rd_config.get('count', 1)
80 expected_crc32 = env__mmc_rd_config.get('crc32', None)
82 count_bytes = count_sectors * 512
83 bcfg = u_boot_console.config.buildconfig
84 has_cmd_memory = bcfg.get('config_cmd_memory', 'n') == 'y'
85 has_cmd_crc32 = bcfg.get('config_cmd_crc32', 'n') == 'y'
86 ram_base = u_boot_utils.find_ram_base(u_boot_console)
87 addr = '0x%08x' % ram_base
90 cmd = 'mmc dev %d' % devid
93 response = u_boot_console.run_command(cmd)
94 assert 'no card present' not in response
96 partid_response = "(part %d)" % partid
99 good_response = 'mmc%d%s is current device' % (devid, partid_response)
100 assert good_response in response
104 if has_cmd_memory and has_cmd_crc32:
105 cmd = 'mw.b %s 0 0x%x' % (addr, count_bytes)
106 u_boot_console.run_command(cmd)
108 cmd = 'crc32 %s 0x%x' % (addr, count_bytes)
109 response = u_boot_console.run_command(cmd)
110 assert expected_crc32 not in response
112 u_boot_console.log.warning(
113 'CONFIG_CMD_MEMORY or CONFIG_CMD_CRC32 != y: Skipping RAM clear')
116 cmd = 'mmc read %s %x %x' % (addr, sector, count_sectors)
117 response = u_boot_console.run_command(cmd)
118 good_response = 'MMC read: dev # %d, block # %d, count %d ... %d blocks read: OK' % (
119 devid, sector, count_sectors, count_sectors)
120 assert good_response in response
125 cmd = 'crc32 %s 0x%x' % (addr, count_bytes)
126 response = u_boot_console.run_command(cmd)
127 assert expected_crc32 in response
129 u_boot_console.log.warning('CONFIG_CMD_CRC32 != y: Skipping check')