test_mmc_rd.py 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. # SPDX-License-Identifier: GPL-2.0
  2. # Copyright (c) 2018, NVIDIA CORPORATION. All rights reserved.
  3. # Test U-Boot's "mmc read" command. The test reads data from the eMMC or SD
  4. # card, and validates the no errors occurred, and that the expected data was
  5. # read if the test configuration contains a CRC of the expected data.
  6. import pytest
  7. import u_boot_utils
  8. """
  9. This test relies on boardenv_* to containing configuration values to define
  10. which MMC devices should be tested. For example:
  11. env__mmc_rd_configs = (
  12. {
  13. "fixture_id": "emmc-boot0",
  14. "is_emmc": True,
  15. "devid": 0,
  16. "partid": 1,
  17. "sector": 0x10,
  18. "count": 1,
  19. },
  20. {
  21. "fixture_id": "emmc-boot1",
  22. "is_emmc": True,
  23. "devid": 0,
  24. "partid": 2,
  25. "sector": 0x10,
  26. "count": 1,
  27. },
  28. {
  29. "fixture_id": "emmc-data",
  30. "is_emmc": True,
  31. "devid": 0,
  32. "partid": 0,
  33. "sector": 0x10,
  34. "count": 0x1000,
  35. },
  36. {
  37. "fixture_id": "sd-mbr",
  38. "is_emmc": False,
  39. "devid": 1,
  40. "partid": None,
  41. "sector": 0,
  42. "count": 1,
  43. "crc32": "8f6ecf0d",
  44. },
  45. {
  46. "fixture_id": "sd-large",
  47. "is_emmc": False,
  48. "devid": 1,
  49. "partid": None,
  50. "sector": 0x10,
  51. "count": 0x1000,
  52. },
  53. )
  54. """
  55. @pytest.mark.buildconfigspec('cmd_mmc')
  56. def test_mmc_rd(u_boot_console, env__mmc_rd_config):
  57. """Test the "mmc read" command.
  58. Args:
  59. u_boot_console: A U-Boot console connection.
  60. env__mmc_rd_config: The single MMC configuration on which
  61. to run the test. See the file-level comment above for details
  62. of the format.
  63. Returns:
  64. Nothing.
  65. """
  66. is_emmc = env__mmc_rd_config['is_emmc']
  67. devid = env__mmc_rd_config['devid']
  68. partid = env__mmc_rd_config.get('partid', 0)
  69. sector = env__mmc_rd_config.get('sector', 0)
  70. count_sectors = env__mmc_rd_config.get('count', 1)
  71. expected_crc32 = env__mmc_rd_config.get('crc32', None)
  72. count_bytes = count_sectors * 512
  73. bcfg = u_boot_console.config.buildconfig
  74. has_cmd_memory = bcfg.get('config_cmd_memory', 'n') == 'y'
  75. has_cmd_crc32 = bcfg.get('config_cmd_crc32', 'n') == 'y'
  76. ram_base = u_boot_utils.find_ram_base(u_boot_console)
  77. addr = '0x%08x' % ram_base
  78. # Select MMC device
  79. cmd = 'mmc dev %d' % devid
  80. if is_emmc:
  81. cmd += ' %d' % partid
  82. response = u_boot_console.run_command(cmd)
  83. assert 'no card present' not in response
  84. if is_emmc:
  85. partid_response = "(part %d)" % partid
  86. else:
  87. partid_response = ""
  88. good_response = 'mmc%d%s is current device' % (devid, partid_response)
  89. assert good_response in response
  90. # Clear target RAM
  91. if expected_crc32:
  92. if has_cmd_memory and has_cmd_crc32:
  93. cmd = 'mw.b %s 0 0x%x' % (addr, count_bytes)
  94. u_boot_console.run_command(cmd)
  95. cmd = 'crc32 %s 0x%x' % (addr, count_bytes)
  96. response = u_boot_console.run_command(cmd)
  97. assert expected_crc32 not in response
  98. else:
  99. u_boot_console.log.warning(
  100. 'CONFIG_CMD_MEMORY or CONFIG_CMD_CRC32 != y: Skipping RAM clear')
  101. # Read data
  102. cmd = 'mmc read %s %x %x' % (addr, sector, count_sectors)
  103. response = u_boot_console.run_command(cmd)
  104. good_response = 'MMC read: dev # %d, block # %d, count %d ... %d blocks read: OK' % (
  105. devid, sector, count_sectors, count_sectors)
  106. assert good_response in response
  107. # Check target RAM
  108. if expected_crc32:
  109. if has_cmd_crc32:
  110. cmd = 'crc32 %s 0x%x' % (addr, count_bytes)
  111. response = u_boot_console.run_command(cmd)
  112. assert expected_crc32 in response
  113. else:
  114. u_boot_console.log.warning('CONFIG_CMD_CRC32 != y: Skipping check')