test_avb.py 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. # Copyright (c) 2018, Linaro Limited
  2. #
  3. # SPDX-License-Identifier: GPL-2.0+
  4. #
  5. # Android Verified Boot 2.0 Test
  6. """
  7. This tests Android Verified Boot 2.0 support in U-Boot:
  8. For additional details about how to build proper vbmeta partition
  9. check doc/android/avb2.rst
  10. For configuration verification:
  11. - Corrupt boot partition and check for failure
  12. - Corrupt vbmeta partition and check for failure
  13. """
  14. import pytest
  15. import u_boot_utils as util
  16. # defauld mmc id
  17. mmc_dev = 1
  18. temp_addr = 0x90000000
  19. temp_addr2 = 0x90002000
  20. @pytest.mark.buildconfigspec('cmd_avb')
  21. @pytest.mark.buildconfigspec('cmd_mmc')
  22. def test_avb_verify(u_boot_console):
  23. """Run AVB 2.0 boot verification chain with avb subset of commands
  24. """
  25. success_str = "Verification passed successfully"
  26. response = u_boot_console.run_command('avb init %s' %str(mmc_dev))
  27. assert response == ''
  28. response = u_boot_console.run_command('avb verify')
  29. assert response.find(success_str)
  30. @pytest.mark.buildconfigspec('cmd_avb')
  31. @pytest.mark.buildconfigspec('cmd_mmc')
  32. @pytest.mark.notbuildconfigspec('sandbox')
  33. def test_avb_mmc_uuid(u_boot_console):
  34. """Check if 'avb get_uuid' works, compare results with
  35. 'part list mmc 1' output
  36. """
  37. response = u_boot_console.run_command('avb init %s' % str(mmc_dev))
  38. assert response == ''
  39. response = u_boot_console.run_command('mmc rescan; mmc dev %s' %
  40. str(mmc_dev))
  41. assert response.find('is current device')
  42. part_lines = u_boot_console.run_command('mmc part').splitlines()
  43. part_list = {}
  44. cur_partname = ''
  45. for line in part_lines:
  46. if '"' in line:
  47. start_pt = line.find('"')
  48. end_pt = line.find('"', start_pt + 1)
  49. cur_partname = line[start_pt + 1: end_pt]
  50. if 'guid:' in line:
  51. guid_to_check = line.split('guid:\t')
  52. part_list[cur_partname] = guid_to_check[1]
  53. # lets check all guids with avb get_guid
  54. for part, guid in part_list.items():
  55. avb_guid_resp = u_boot_console.run_command('avb get_uuid %s' % part)
  56. assert guid == avb_guid_resp.split('UUID: ')[1]
  57. @pytest.mark.buildconfigspec('cmd_avb')
  58. def test_avb_read_rb(u_boot_console):
  59. """Test reading rollback indexes
  60. """
  61. response = u_boot_console.run_command('avb init %s' % str(mmc_dev))
  62. assert response == ''
  63. response = u_boot_console.run_command('avb read_rb 1')
  64. assert response == 'Rollback index: 0'
  65. @pytest.mark.buildconfigspec('cmd_avb')
  66. def test_avb_is_unlocked(u_boot_console):
  67. """Test if device is in the unlocked state
  68. """
  69. response = u_boot_console.run_command('avb init %s' % str(mmc_dev))
  70. assert response == ''
  71. response = u_boot_console.run_command('avb is_unlocked')
  72. assert response == 'Unlocked = 1'
  73. @pytest.mark.buildconfigspec('cmd_avb')
  74. @pytest.mark.buildconfigspec('cmd_mmc')
  75. @pytest.mark.notbuildconfigspec('sandbox')
  76. def test_avb_mmc_read(u_boot_console):
  77. """Test mmc read operation
  78. """
  79. response = u_boot_console.run_command('mmc rescan; mmc dev %s 0' %
  80. str(mmc_dev))
  81. assert response.find('is current device')
  82. response = u_boot_console.run_command('mmc read 0x%x 0x100 0x1' % temp_addr)
  83. assert response.find('read: OK')
  84. response = u_boot_console.run_command('avb init %s' % str(mmc_dev))
  85. assert response == ''
  86. response = u_boot_console.run_command('avb read_part xloader 0 100 0x%x' %
  87. temp_addr2)
  88. assert response.find('Read 512 bytes')
  89. # Now lets compare two buffers
  90. response = u_boot_console.run_command('cmp 0x%x 0x%x 40' %
  91. (temp_addr, temp_addr2))
  92. assert response.find('64 word')
  93. @pytest.mark.buildconfigspec('cmd_avb')
  94. @pytest.mark.buildconfigspec('optee_ta_avb')
  95. def test_avb_persistent_values(u_boot_console):
  96. """Test reading/writing persistent storage to avb
  97. """
  98. response = u_boot_console.run_command('avb init %s' % str(mmc_dev))
  99. assert response == ''
  100. response = u_boot_console.run_command('avb write_pvalue test value_value')
  101. assert response == 'Wrote 12 bytes'
  102. response = u_boot_console.run_command('avb read_pvalue test 12')
  103. assert response == 'Read 12 bytes, value = value_value'