test_avb.py 4.1 KB

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