test_mmc_wr.py 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. # SPDX-License-Identifier: GPL-2.0
  2. # Copyright (c) 2019, Texas Instrument
  3. # Author: Jean-Jacques Hiblot <jjhiblot@ti.com>
  4. # Test U-Boot's "mmc write" command. The test generates random data, writes it
  5. # to the eMMC or SD card, then reads it back and performs a comparison.
  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_wr_configs = (
  12. {
  13. "fixture_id": "emmc-boot0",
  14. "is_emmc": True,
  15. "devid": 1,
  16. "partid": 1,
  17. "sector": 0x10,
  18. "count": 100,
  19. "test_iterations": 50,
  20. },
  21. {
  22. "fixture_id": "emmc-boot1",
  23. "is_emmc": True,
  24. "devid": 1,
  25. "partid": 2,
  26. "sector": 0x10,
  27. "count": 100,
  28. "test_iterations": 50,
  29. },
  30. )
  31. """
  32. @pytest.mark.buildconfigspec('cmd_mmc')
  33. @pytest.mark.buildconfigspec('cmd_memory')
  34. @pytest.mark.buildconfigspec('cmd_random')
  35. def test_mmc_wr(u_boot_console, env__mmc_wr_config):
  36. """Test the "mmc write" command.
  37. Args:
  38. u_boot_console: A U-Boot console connection.
  39. env__mmc_wr_config: The single MMC configuration on which
  40. to run the test. See the file-level comment above for details
  41. of the format.
  42. Returns:
  43. Nothing.
  44. """
  45. is_emmc = env__mmc_wr_config['is_emmc']
  46. devid = env__mmc_wr_config['devid']
  47. partid = env__mmc_wr_config.get('partid', 0)
  48. sector = env__mmc_wr_config.get('sector', 0)
  49. count_sectors = env__mmc_wr_config.get('count', 1)
  50. test_iterations = env__mmc_wr_config.get('test_iterations', 1)
  51. count_bytes = count_sectors * 512
  52. bcfg = u_boot_console.config.buildconfig
  53. ram_base = u_boot_utils.find_ram_base(u_boot_console)
  54. src_addr = '0x%08x' % ram_base
  55. dst_addr = '0x%08x' % (ram_base + count_bytes)
  56. for i in range(test_iterations):
  57. # Generate random data
  58. cmd = 'random %s %x' % (src_addr, count_bytes)
  59. response = u_boot_console.run_command(cmd)
  60. good_response = '%d bytes filled with random data' % (count_bytes)
  61. assert good_response in response
  62. # Select MMC device
  63. cmd = 'mmc dev %d' % devid
  64. if is_emmc:
  65. cmd += ' %d' % partid
  66. response = u_boot_console.run_command(cmd)
  67. assert 'no card present' not in response
  68. if is_emmc:
  69. partid_response = "(part %d)" % partid
  70. else:
  71. partid_response = ""
  72. good_response = 'mmc%d%s is current device' % (devid, partid_response)
  73. assert good_response in response
  74. # Write data
  75. cmd = 'mmc write %s %x %x' % (src_addr, sector, count_sectors)
  76. response = u_boot_console.run_command(cmd)
  77. good_response = 'MMC write: dev # %d, block # %d, count %d ... %d blocks written: OK' % (devid, sector, count_sectors, count_sectors)
  78. assert good_response in response
  79. # Read data
  80. cmd = 'mmc read %s %x %x' % (dst_addr, sector, count_sectors)
  81. response = u_boot_console.run_command(cmd)
  82. good_response = 'MMC read: dev # %d, block # %d, count %d ... %d blocks read: OK' % (devid, sector, count_sectors, count_sectors)
  83. assert good_response in response
  84. # Compare src and dst data
  85. cmd = 'cmp.b %s %s %x' % (src_addr, dst_addr, count_bytes)
  86. response = u_boot_console.run_command(cmd)
  87. good_response = 'Total of %d byte(s) were the same' % (count_bytes)
  88. assert good_response in response