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