blob: 41a75f885e1ef4fc5209c2a1af0cf254a69de780 [file] [log] [blame]
Jean-Jacques Hiblota35de5a2019-06-17 17:49:21 +02001# SPDX-License-Identifier: GPL-2.0
2# Copyright (c) 2019, Texas Instrument
3# Author: Jean-Jacques Hiblot <jjhiblot@ti.com>
4
5# Test U-Boot's "mmc write" command. The test generates random data, writes it
6# to the eMMC or SD card, then reads it back and performs a comparison.
7
8import pytest
Simon Glassfb916372025-02-09 09:07:15 -07009import utils
Jean-Jacques Hiblota35de5a2019-06-17 17:49:21 +020010
11"""
12This test relies on boardenv_* to containing configuration values to define
13which MMC devices should be tested. For example:
14
15env__mmc_wr_configs = (
16 {
17 "fixture_id": "emmc-boot0",
18 "is_emmc": True,
19 "devid": 1,
20 "partid": 1,
21 "sector": 0x10,
22 "count": 100,
23 "test_iterations": 50,
24 },
25 {
26 "fixture_id": "emmc-boot1",
27 "is_emmc": True,
28 "devid": 1,
29 "partid": 2,
30 "sector": 0x10,
31 "count": 100,
32 "test_iterations": 50,
33 },
34)
35
36"""
37
Tom Rini1ba07812019-10-24 11:59:18 -040038@pytest.mark.buildconfigspec('cmd_mmc')
39@pytest.mark.buildconfigspec('cmd_memory')
40@pytest.mark.buildconfigspec('cmd_random')
Simon Glassddba5202025-02-09 09:07:14 -070041def test_mmc_wr(ubman, env__mmc_wr_config):
Jean-Jacques Hiblota35de5a2019-06-17 17:49:21 +020042 """Test the "mmc write" command.
43
44 Args:
Simon Glassddba5202025-02-09 09:07:14 -070045 ubman: A U-Boot console connection.
Jean-Jacques Hiblota35de5a2019-06-17 17:49:21 +020046 env__mmc_wr_config: The single MMC configuration on which
47 to run the test. See the file-level comment above for details
48 of the format.
49
50 Returns:
51 Nothing.
52 """
53
54 is_emmc = env__mmc_wr_config['is_emmc']
55 devid = env__mmc_wr_config['devid']
56 partid = env__mmc_wr_config.get('partid', 0)
57 sector = env__mmc_wr_config.get('sector', 0)
58 count_sectors = env__mmc_wr_config.get('count', 1)
59 test_iterations = env__mmc_wr_config.get('test_iterations', 1)
60
61
62 count_bytes = count_sectors * 512
Simon Glassddba5202025-02-09 09:07:14 -070063 bcfg = ubman.config.buildconfig
Simon Glassfb916372025-02-09 09:07:15 -070064 ram_base = utils.find_ram_base(ubman)
Jean-Jacques Hiblota35de5a2019-06-17 17:49:21 +020065 src_addr = '0x%08x' % ram_base
66 dst_addr = '0x%08x' % (ram_base + count_bytes)
67
68
69 for i in range(test_iterations):
Tom Rini7f24c192019-10-24 11:59:20 -040070 # Generate random data
71 cmd = 'random %s %x' % (src_addr, count_bytes)
Simon Glassddba5202025-02-09 09:07:14 -070072 response = ubman.run_command(cmd)
Tom Rini7f24c192019-10-24 11:59:20 -040073 good_response = '%d bytes filled with random data' % (count_bytes)
74 assert good_response in response
Jean-Jacques Hiblota35de5a2019-06-17 17:49:21 +020075
Tom Rini7f24c192019-10-24 11:59:20 -040076 # Select MMC device
77 cmd = 'mmc dev %d' % devid
78 if is_emmc:
79 cmd += ' %d' % partid
Simon Glassddba5202025-02-09 09:07:14 -070080 response = ubman.run_command(cmd)
Tom Rini7f24c192019-10-24 11:59:20 -040081 assert 'no card present' not in response
82 if is_emmc:
83 partid_response = "(part %d)" % partid
84 else:
85 partid_response = ""
86 good_response = 'mmc%d%s is current device' % (devid, partid_response)
87 assert good_response in response
Jean-Jacques Hiblota35de5a2019-06-17 17:49:21 +020088
Tom Rini7f24c192019-10-24 11:59:20 -040089 # Write data
90 cmd = 'mmc write %s %x %x' % (src_addr, sector, count_sectors)
Simon Glassddba5202025-02-09 09:07:14 -070091 response = ubman.run_command(cmd)
Tom Rini7f24c192019-10-24 11:59:20 -040092 good_response = 'MMC write: dev # %d, block # %d, count %d ... %d blocks written: OK' % (devid, sector, count_sectors, count_sectors)
93 assert good_response in response
Jean-Jacques Hiblota35de5a2019-06-17 17:49:21 +020094
Tom Rini7f24c192019-10-24 11:59:20 -040095 # Read data
96 cmd = 'mmc read %s %x %x' % (dst_addr, sector, count_sectors)
Simon Glassddba5202025-02-09 09:07:14 -070097 response = ubman.run_command(cmd)
Tom Rini7f24c192019-10-24 11:59:20 -040098 good_response = 'MMC read: dev # %d, block # %d, count %d ... %d blocks read: OK' % (devid, sector, count_sectors, count_sectors)
99 assert good_response in response
Jean-Jacques Hiblota35de5a2019-06-17 17:49:21 +0200100
Tom Rini7f24c192019-10-24 11:59:20 -0400101 # Compare src and dst data
102 cmd = 'cmp.b %s %s %x' % (src_addr, dst_addr, count_bytes)
Simon Glassddba5202025-02-09 09:07:14 -0700103 response = ubman.run_command(cmd)
Tom Rini7f24c192019-10-24 11:59:20 -0400104 good_response = 'Total of %d byte(s) were the same' % (count_bytes)
105 assert good_response in response