test_avb.py 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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. def test_avb_mmc_uuid(u_boot_console):
  33. """Check if 'avb get_uuid' works, compare results with
  34. 'part list mmc 1' output
  35. """
  36. response = u_boot_console.run_command('avb init %s' % str(mmc_dev))
  37. assert response == ''
  38. response = u_boot_console.run_command('mmc rescan; mmc dev %s' %
  39. str(mmc_dev))
  40. assert response.find('is current device')
  41. part_lines = u_boot_console.run_command('mmc part').splitlines()
  42. part_list = {}
  43. cur_partname = ''
  44. for line in part_lines:
  45. if '"' in line:
  46. start_pt = line.find('"')
  47. end_pt = line.find('"', start_pt + 1)
  48. cur_partname = line[start_pt + 1: end_pt]
  49. if 'guid:' in line:
  50. guid_to_check = line.split('guid:\t')
  51. part_list[cur_partname] = guid_to_check[1]
  52. # lets check all guids with avb get_guid
  53. for part, guid in part_list.iteritems():
  54. avb_guid_resp = u_boot_console.run_command('avb get_uuid %s' % part)
  55. assert guid == avb_guid_resp.split('UUID: ')[1]
  56. @pytest.mark.buildconfigspec('cmd_avb')
  57. def test_avb_read_rb(u_boot_console):
  58. """Test reading rollback indexes
  59. """
  60. response = u_boot_console.run_command('avb init %s' % str(mmc_dev))
  61. assert response == ''
  62. response = u_boot_console.run_command('avb read_rb 1')
  63. assert response == 'Rollback index: 0'
  64. @pytest.mark.buildconfigspec('cmd_avb')
  65. def test_avb_is_unlocked(u_boot_console):
  66. """Test if device is in the unlocked state
  67. """
  68. response = u_boot_console.run_command('avb init %s' % str(mmc_dev))
  69. assert response == ''
  70. response = u_boot_console.run_command('avb is_unlocked')
  71. assert response == 'Unlocked = 1'
  72. @pytest.mark.buildconfigspec('cmd_avb')
  73. @pytest.mark.buildconfigspec('cmd_mmc')
  74. def test_avb_mmc_read(u_boot_console):
  75. """Test mmc read operation
  76. """
  77. response = u_boot_console.run_command('mmc rescan; mmc dev %s 0' %
  78. str(mmc_dev))
  79. assert response.find('is current device')
  80. response = u_boot_console.run_command('mmc read 0x%x 0x100 0x1' % temp_addr)
  81. assert response.find('read: OK')
  82. response = u_boot_console.run_command('avb init %s' % str(mmc_dev))
  83. assert response == ''
  84. response = u_boot_console.run_command('avb read_part xloader 0 100 0x%x' %
  85. temp_addr2)
  86. assert response.find('Read 512 bytes')
  87. # Now lets compare two buffers
  88. response = u_boot_console.run_command('cmp 0x%x 0x%x 40' %
  89. (temp_addr, temp_addr2))
  90. assert response.find('64 word')
  91. @pytest.mark.buildconfigspec('cmd_avb')
  92. @pytest.mark.buildconfigspec('optee_ta_avb')
  93. def test_avb_persistent_values(u_boot_console):
  94. """Test reading/writing persistent storage to avb
  95. """
  96. response = u_boot_console.run_command('avb init %s' % str(mmc_dev))
  97. assert response == ''
  98. response = u_boot_console.run_command('avb write_pvalue test value_value')
  99. assert response == 'Wrote 12 bytes'
  100. response = u_boot_console.run_command('avb read_pvalue test 12')
  101. assert response == 'Read 12 bytes, value = value_value'