14bdc90f9SStephen Warren# SPDX-License-Identifier: GPL-2.0 283d290c5STom Rini# Copyright (c) 2018, NVIDIA CORPORATION. All rights reserved. 34bdc90f9SStephen Warren 44bdc90f9SStephen Warren# Test U-Boot's "mmc read" command. The test reads data from the eMMC or SD 54bdc90f9SStephen Warren# card, and validates the no errors occurred, and that the expected data was 64bdc90f9SStephen Warren# read if the test configuration contains a CRC of the expected data. 74bdc90f9SStephen Warren 84bdc90f9SStephen Warrenimport pytest 94bdc90f9SStephen Warrenimport u_boot_utils 104bdc90f9SStephen Warren 114bdc90f9SStephen Warren""" 124bdc90f9SStephen WarrenThis test relies on boardenv_* to containing configuration values to define 134bdc90f9SStephen Warrenwhich MMC devices should be tested. For example: 144bdc90f9SStephen Warren 154bdc90f9SStephen Warrenenv__mmc_rd_configs = ( 164bdc90f9SStephen Warren { 17*871bf7d9SSimon Glass 'fixture_id': 'emmc-boot0', 18*871bf7d9SSimon Glass 'is_emmc': True, 19*871bf7d9SSimon Glass 'devid': 0, 20*871bf7d9SSimon Glass 'partid': 1, 21*871bf7d9SSimon Glass 'sector': 0x10, 22*871bf7d9SSimon Glass 'count': 1, 234bdc90f9SStephen Warren }, 244bdc90f9SStephen Warren { 25*871bf7d9SSimon Glass 'fixture_id': 'emmc-boot1', 26*871bf7d9SSimon Glass 'is_emmc': True, 27*871bf7d9SSimon Glass 'devid': 0, 28*871bf7d9SSimon Glass 'partid': 2, 29*871bf7d9SSimon Glass 'sector': 0x10, 30*871bf7d9SSimon Glass 'count': 1, 314bdc90f9SStephen Warren }, 324bdc90f9SStephen Warren { 33*871bf7d9SSimon Glass 'fixture_id': 'emmc-data', 34*871bf7d9SSimon Glass 'is_emmc': True, 35*871bf7d9SSimon Glass 'devid': 0, 36*871bf7d9SSimon Glass 'partid': 0, 37*871bf7d9SSimon Glass 'sector': 0x10, 38*871bf7d9SSimon Glass 'count': 0x1000, 394bdc90f9SStephen Warren }, 404bdc90f9SStephen Warren { 41*871bf7d9SSimon Glass 'fixture_id': 'sd-mbr', 42*871bf7d9SSimon Glass 'is_emmc': False, 43*871bf7d9SSimon Glass 'devid': 1, 44*871bf7d9SSimon Glass 'partid': None, 45*871bf7d9SSimon Glass 'sector': 0, 46*871bf7d9SSimon Glass 'count': 1, 47*871bf7d9SSimon Glass 'crc32': '8f6ecf0d', 484bdc90f9SStephen Warren }, 494bdc90f9SStephen Warren { 50*871bf7d9SSimon Glass 'fixture_id': 'sd-large', 51*871bf7d9SSimon Glass 'is_emmc': False, 52*871bf7d9SSimon Glass 'devid': 1, 53*871bf7d9SSimon Glass 'partid': None, 54*871bf7d9SSimon Glass 'sector': 0x10, 55*871bf7d9SSimon Glass 'count': 0x1000, 564bdc90f9SStephen Warren }, 574bdc90f9SStephen Warren) 584bdc90f9SStephen Warren""" 594bdc90f9SStephen Warren 604bdc90f9SStephen Warren@pytest.mark.buildconfigspec('cmd_mmc') 614bdc90f9SStephen Warrendef test_mmc_rd(u_boot_console, env__mmc_rd_config): 624bdc90f9SStephen Warren """Test the "mmc read" command. 634bdc90f9SStephen Warren 644bdc90f9SStephen Warren Args: 654bdc90f9SStephen Warren u_boot_console: A U-Boot console connection. 664bdc90f9SStephen Warren env__mmc_rd_config: The single MMC configuration on which 674bdc90f9SStephen Warren to run the test. See the file-level comment above for details 684bdc90f9SStephen Warren of the format. 694bdc90f9SStephen Warren 704bdc90f9SStephen Warren Returns: 714bdc90f9SStephen Warren Nothing. 724bdc90f9SStephen Warren """ 734bdc90f9SStephen Warren 744bdc90f9SStephen Warren is_emmc = env__mmc_rd_config['is_emmc'] 754bdc90f9SStephen Warren devid = env__mmc_rd_config['devid'] 764bdc90f9SStephen Warren partid = env__mmc_rd_config.get('partid', 0) 774bdc90f9SStephen Warren sector = env__mmc_rd_config.get('sector', 0) 784bdc90f9SStephen Warren count_sectors = env__mmc_rd_config.get('count', 1) 794bdc90f9SStephen Warren expected_crc32 = env__mmc_rd_config.get('crc32', None) 804bdc90f9SStephen Warren 814bdc90f9SStephen Warren count_bytes = count_sectors * 512 824bdc90f9SStephen Warren bcfg = u_boot_console.config.buildconfig 834bdc90f9SStephen Warren has_cmd_memory = bcfg.get('config_cmd_memory', 'n') == 'y' 844bdc90f9SStephen Warren has_cmd_crc32 = bcfg.get('config_cmd_crc32', 'n') == 'y' 854bdc90f9SStephen Warren ram_base = u_boot_utils.find_ram_base(u_boot_console) 864bdc90f9SStephen Warren addr = '0x%08x' % ram_base 874bdc90f9SStephen Warren 884bdc90f9SStephen Warren # Select MMC device 894bdc90f9SStephen Warren cmd = 'mmc dev %d' % devid 904bdc90f9SStephen Warren if is_emmc: 914bdc90f9SStephen Warren cmd += ' %d' % partid 924bdc90f9SStephen Warren response = u_boot_console.run_command(cmd) 934bdc90f9SStephen Warren assert 'no card present' not in response 944bdc90f9SStephen Warren if is_emmc: 95*871bf7d9SSimon Glass partid_response = '(part %d)' % partid 964bdc90f9SStephen Warren else: 97*871bf7d9SSimon Glass partid_response = '' 984bdc90f9SStephen Warren good_response = 'mmc%d%s is current device' % (devid, partid_response) 994bdc90f9SStephen Warren assert good_response in response 1004bdc90f9SStephen Warren 1014bdc90f9SStephen Warren # Clear target RAM 1024bdc90f9SStephen Warren if expected_crc32: 1034bdc90f9SStephen Warren if has_cmd_memory and has_cmd_crc32: 1044bdc90f9SStephen Warren cmd = 'mw.b %s 0 0x%x' % (addr, count_bytes) 1054bdc90f9SStephen Warren u_boot_console.run_command(cmd) 1064bdc90f9SStephen Warren 1074bdc90f9SStephen Warren cmd = 'crc32 %s 0x%x' % (addr, count_bytes) 1084bdc90f9SStephen Warren response = u_boot_console.run_command(cmd) 1094bdc90f9SStephen Warren assert expected_crc32 not in response 1104bdc90f9SStephen Warren else: 1114bdc90f9SStephen Warren u_boot_console.log.warning( 1124bdc90f9SStephen Warren 'CONFIG_CMD_MEMORY or CONFIG_CMD_CRC32 != y: Skipping RAM clear') 1134bdc90f9SStephen Warren 1144bdc90f9SStephen Warren # Read data 1154bdc90f9SStephen Warren cmd = 'mmc read %s %x %x' % (addr, sector, count_sectors) 1164bdc90f9SStephen Warren response = u_boot_console.run_command(cmd) 1174bdc90f9SStephen Warren good_response = 'MMC read: dev # %d, block # %d, count %d ... %d blocks read: OK' % ( 1184bdc90f9SStephen Warren devid, sector, count_sectors, count_sectors) 1194bdc90f9SStephen Warren assert good_response in response 1204bdc90f9SStephen Warren 1214bdc90f9SStephen Warren # Check target RAM 1224bdc90f9SStephen Warren if expected_crc32: 1234bdc90f9SStephen Warren if has_cmd_crc32: 1244bdc90f9SStephen Warren cmd = 'crc32 %s 0x%x' % (addr, count_bytes) 1254bdc90f9SStephen Warren response = u_boot_console.run_command(cmd) 1264bdc90f9SStephen Warren assert expected_crc32 in response 1274bdc90f9SStephen Warren else: 1284bdc90f9SStephen Warren u_boot_console.log.warning('CONFIG_CMD_CRC32 != y: Skipping check') 129