Stephen Warren | 83698e3 | 2018-02-20 12:51:54 -0700 | [diff] [blame] | 1 | # SPDX-License-Identifier: GPL-2.0 |
Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 2 | # Copyright (c) 2018, NVIDIA CORPORATION. All rights reserved. |
Stephen Warren | 83698e3 | 2018-02-20 12:51:54 -0700 | [diff] [blame] | 3 | |
| 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. |
| 7 | |
| 8 | import pytest |
| 9 | import u_boot_utils |
| 10 | |
| 11 | """ |
| 12 | This test relies on boardenv_* to containing configuration values to define |
| 13 | which MMC devices should be tested. For example: |
| 14 | |
| 15 | env__mmc_rd_configs = ( |
| 16 | { |
Simon Glass | e9f4d87 | 2018-12-27 08:11:13 -0700 | [diff] [blame^] | 17 | 'fixture_id': 'emmc-boot0', |
| 18 | 'is_emmc': True, |
| 19 | 'devid': 0, |
| 20 | 'partid': 1, |
| 21 | 'sector': 0x10, |
| 22 | 'count': 1, |
Stephen Warren | 83698e3 | 2018-02-20 12:51:54 -0700 | [diff] [blame] | 23 | }, |
| 24 | { |
Simon Glass | e9f4d87 | 2018-12-27 08:11:13 -0700 | [diff] [blame^] | 25 | 'fixture_id': 'emmc-boot1', |
| 26 | 'is_emmc': True, |
| 27 | 'devid': 0, |
| 28 | 'partid': 2, |
| 29 | 'sector': 0x10, |
| 30 | 'count': 1, |
Stephen Warren | 83698e3 | 2018-02-20 12:51:54 -0700 | [diff] [blame] | 31 | }, |
| 32 | { |
Simon Glass | e9f4d87 | 2018-12-27 08:11:13 -0700 | [diff] [blame^] | 33 | 'fixture_id': 'emmc-data', |
| 34 | 'is_emmc': True, |
| 35 | 'devid': 0, |
| 36 | 'partid': 0, |
| 37 | 'sector': 0x10, |
| 38 | 'count': 0x1000, |
Stephen Warren | 83698e3 | 2018-02-20 12:51:54 -0700 | [diff] [blame] | 39 | }, |
| 40 | { |
Simon Glass | e9f4d87 | 2018-12-27 08:11:13 -0700 | [diff] [blame^] | 41 | 'fixture_id': 'sd-mbr', |
| 42 | 'is_emmc': False, |
| 43 | 'devid': 1, |
| 44 | 'partid': None, |
| 45 | 'sector': 0, |
| 46 | 'count': 1, |
| 47 | 'crc32': '8f6ecf0d', |
Stephen Warren | 83698e3 | 2018-02-20 12:51:54 -0700 | [diff] [blame] | 48 | }, |
| 49 | { |
Simon Glass | e9f4d87 | 2018-12-27 08:11:13 -0700 | [diff] [blame^] | 50 | 'fixture_id': 'sd-large', |
| 51 | 'is_emmc': False, |
| 52 | 'devid': 1, |
| 53 | 'partid': None, |
| 54 | 'sector': 0x10, |
| 55 | 'count': 0x1000, |
Stephen Warren | 83698e3 | 2018-02-20 12:51:54 -0700 | [diff] [blame] | 56 | }, |
| 57 | ) |
| 58 | """ |
| 59 | |
| 60 | @pytest.mark.buildconfigspec('cmd_mmc') |
| 61 | def test_mmc_rd(u_boot_console, env__mmc_rd_config): |
| 62 | """Test the "mmc read" command. |
| 63 | |
| 64 | Args: |
| 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 |
| 68 | of the format. |
| 69 | |
| 70 | Returns: |
| 71 | Nothing. |
| 72 | """ |
| 73 | |
| 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) |
| 80 | |
| 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 |
| 87 | |
| 88 | # Select MMC device |
| 89 | cmd = 'mmc dev %d' % devid |
| 90 | if is_emmc: |
| 91 | cmd += ' %d' % partid |
| 92 | response = u_boot_console.run_command(cmd) |
| 93 | assert 'no card present' not in response |
| 94 | if is_emmc: |
Simon Glass | e9f4d87 | 2018-12-27 08:11:13 -0700 | [diff] [blame^] | 95 | partid_response = '(part %d)' % partid |
Stephen Warren | 83698e3 | 2018-02-20 12:51:54 -0700 | [diff] [blame] | 96 | else: |
Simon Glass | e9f4d87 | 2018-12-27 08:11:13 -0700 | [diff] [blame^] | 97 | partid_response = '' |
Stephen Warren | 83698e3 | 2018-02-20 12:51:54 -0700 | [diff] [blame] | 98 | good_response = 'mmc%d%s is current device' % (devid, partid_response) |
| 99 | assert good_response in response |
| 100 | |
| 101 | # Clear target RAM |
| 102 | if expected_crc32: |
| 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) |
| 106 | |
| 107 | cmd = 'crc32 %s 0x%x' % (addr, count_bytes) |
| 108 | response = u_boot_console.run_command(cmd) |
| 109 | assert expected_crc32 not in response |
| 110 | else: |
| 111 | u_boot_console.log.warning( |
| 112 | 'CONFIG_CMD_MEMORY or CONFIG_CMD_CRC32 != y: Skipping RAM clear') |
| 113 | |
| 114 | # Read data |
| 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 |
| 120 | |
| 121 | # Check target RAM |
| 122 | if expected_crc32: |
| 123 | if has_cmd_crc32: |
| 124 | cmd = 'crc32 %s 0x%x' % (addr, count_bytes) |
| 125 | response = u_boot_console.run_command(cmd) |
| 126 | assert expected_crc32 in response |
| 127 | else: |
| 128 | u_boot_console.log.warning('CONFIG_CMD_CRC32 != y: Skipping check') |