pytest_system_efuse_example.py 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962
  1. # SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD
  2. # SPDX-License-Identifier: Unlicense OR CC0-1.0
  3. from __future__ import unicode_literals
  4. import logging
  5. import os
  6. import pytest
  7. from pytest_embedded import Dut
  8. @pytest.mark.generic
  9. @pytest.mark.esp32
  10. @pytest.mark.esp32c2
  11. @pytest.mark.esp32c3
  12. def test_examples_efuse(dut: Dut) -> None:
  13. dut.expect(r'example: Coding Scheme (3/4)|(NONE)|(REPEAT)|(RS \(Reed-Solomon coding\))', timeout=20)
  14. dut.expect(['example: read efuse fields',
  15. r'example: 1. read MAC address: {}'.format(r':'.join((r'[0-9a-f]{2}',) * 6)),
  16. 'example: 2. read secure_version: 0',
  17. 'example: 3. read custom fields',
  18. 'example: module_version = 0',
  19. 'example: device_role = None',
  20. 'example: setting_1 = 0',
  21. 'example: setting_2 = 0',
  22. 'example: custom_secure_version = 0',
  23. 'example: This example does not burn any efuse in reality only virtually',
  24. 'example: Write operations in efuse fields are performed virtually',
  25. 'example: write custom efuse fields',
  26. 'efuse: Virtual efuses enabled: Not really burning eFuses',
  27. 'example: module_version = 1',
  28. 'example: device_role = Slave',
  29. 'example: setting_1 = 3',
  30. 'example: setting_2 = 4',
  31. 'example: custom_secure_version = 5',
  32. 'example: Done'], expect_all=True)
  33. @pytest.mark.generic
  34. @pytest.mark.esp32
  35. @pytest.mark.esp32s2
  36. @pytest.mark.esp32c2
  37. @pytest.mark.esp32c3
  38. @pytest.mark.parametrize('config', ['virt_flash_enc',], indirect=True)
  39. @pytest.mark.parametrize('skip_autoflash', ['y'], indirect=True)
  40. def test_examples_efuse_with_virt_flash_enc(dut: Dut) -> None:
  41. # check and log bin size
  42. binary_file = os.path.join(dut.app.binary_path, 'bootloader', 'bootloader.bin')
  43. bin_size = os.path.getsize(binary_file)
  44. logging.info('{}_bootloader_virt_flash_enc_bin_size: {}KB'.format(dut.app.target, bin_size // 1024))
  45. print(' - Erase flash')
  46. dut.serial.erase_flash()
  47. print(' - Start app (flash partition_table and app)')
  48. dut.serial.write_flash_no_enc()
  49. dut.expect('Loading virtual efuse blocks from real efuses')
  50. dut.expect('Checking flash encryption...')
  51. dut.expect('Generating new flash encryption key...')
  52. if dut.app.target == 'esp32':
  53. dut.expect('Writing EFUSE_BLK_KEY0 with purpose 2')
  54. dut.expect('Setting CRYPT_CONFIG efuse to 0xF')
  55. dut.expect('Not disabling UART bootloader encryption')
  56. dut.expect('Disable UART bootloader decryption...')
  57. dut.expect('Disable UART bootloader MMU cache...')
  58. dut.expect('Disable JTAG...')
  59. dut.expect('Disable ROM BASIC interpreter fallback...')
  60. else:
  61. if dut.app.target == 'esp32c2':
  62. dut.expect('Writing EFUSE_BLK_KEY0 with purpose 1')
  63. else:
  64. dut.expect('Writing EFUSE_BLK_KEY0 with purpose 4')
  65. dut.expect('Not disabling UART bootloader encryption')
  66. dut.expect('Disable UART bootloader cache...')
  67. dut.expect('Disable JTAG...')
  68. dut.expect('bootloader encrypted successfully')
  69. dut.expect('partition table encrypted and loaded successfully')
  70. dut.expect('Flash encryption completed', timeout=90)
  71. dut.expect('Resetting with flash encryption enabled...')
  72. dut.expect('Loading virtual efuse blocks from flash')
  73. dut.expect('Checking flash encryption...')
  74. if dut.app.target == 'esp32':
  75. dut.expect_exact('flash encryption is enabled (3 plaintext flashes left)', timeout=3)
  76. else:
  77. dut.expect_exact('flash encryption is enabled (1 plaintext flashes left)')
  78. dut.expect_exact('Flash encryption mode is DEVELOPMENT (not secure)')
  79. dut.expect('Start eFuse example')
  80. dut.expect('example: Done')
  81. @pytest.mark.generic
  82. @pytest.mark.esp32s2
  83. @pytest.mark.parametrize('config', ['virt_flash_enc_aes_256',], indirect=True)
  84. @pytest.mark.parametrize('skip_autoflash', ['y'], indirect=True)
  85. def test_examples_efuse_with_virt_flash_enc_aes_256(dut: Dut) -> None:
  86. # Only ESP32-S2 has support AES-256 FLASH_ENCRYPTION key
  87. # check and log bin size
  88. binary_file = os.path.join(dut.app.binary_path, 'bootloader', 'bootloader.bin')
  89. bin_size = os.path.getsize(binary_file)
  90. logging.info('{}_bootloader_virt_flash_enc_aes_256_bin_size: {}KB'.format(dut.app.target, bin_size // 1024))
  91. print(' - Erase flash')
  92. dut.serial.erase_flash()
  93. print(' - Start app (flash partition_table and app)')
  94. dut.serial.write_flash_no_enc()
  95. dut.expect('Loading virtual efuse blocks from real efuses')
  96. dut.expect('Checking flash encryption...')
  97. dut.expect('Generating new flash encryption key...')
  98. dut.expect('Writing EFUSE_BLK_KEY0 with purpose 2')
  99. dut.expect('Writing EFUSE_BLK_KEY1 with purpose 3')
  100. dut.expect('Not disabling UART bootloader encryption')
  101. dut.expect('Disable UART bootloader cache...')
  102. dut.expect('Disable JTAG...')
  103. dut.expect('bootloader encrypted successfully')
  104. dut.expect('partition table encrypted and loaded successfully')
  105. dut.expect('Flash encryption completed', timeout=90)
  106. dut.expect('Resetting with flash encryption enabled...')
  107. dut.expect('Loading virtual efuse blocks from flash')
  108. dut.expect('Checking flash encryption...')
  109. dut.expect_exact('flash encryption is enabled (1 plaintext flashes left)')
  110. dut.expect_exact('Flash encryption mode is DEVELOPMENT (not secure)')
  111. dut.expect('Start eFuse example')
  112. dut.expect('example: Done')
  113. @pytest.mark.generic
  114. @pytest.mark.esp32
  115. @pytest.mark.esp32c2
  116. @pytest.mark.esp32c3
  117. @pytest.mark.esp32s2
  118. @pytest.mark.parametrize('config', ['virt_flash_enc',], indirect=True)
  119. @pytest.mark.parametrize('skip_autoflash', ['y'], indirect=True)
  120. def test_examples_efuse_with_virt_flash_enc_pre_loaded(dut: Dut) -> None:
  121. print(' - Erase flash')
  122. dut.serial.erase_flash()
  123. print(' - Start app (flash partition_table and app)')
  124. dut.serial.write_flash_no_enc()
  125. dut.expect('Loading virtual efuse blocks from real efuses')
  126. dut.expect('Flash encryption completed', timeout=90)
  127. dut.expect('Resetting with flash encryption enabled...')
  128. dut.expect_exact('Flash encryption mode is DEVELOPMENT (not secure)')
  129. dut.expect('Start eFuse example')
  130. dut.expect('example: Done')
  131. if dut.app.target == 'esp32':
  132. print(' - Flash emul_efuse with pre-loaded efuses (FLASH_CRYPT_CNT 1 -> 0)')
  133. # offset of this eFuse is taken from components/efuse/esp32/esp_efuse_table.csv
  134. FLASH_CRYPT_CNT = 20
  135. # Resets eFuse, which enables Flash encryption feature
  136. dut.serial.erase_field_on_emul_efuse([FLASH_CRYPT_CNT])
  137. elif dut.app.target == 'esp32c2':
  138. FLASH_CRYPT_CNT = 39
  139. dut.serial.erase_field_on_emul_efuse([FLASH_CRYPT_CNT])
  140. else:
  141. # offset of this eFuse is taken from components/efuse/{target}/esp_efuse_table.csv
  142. print(' - Flash emul_efuse with pre-loaded efuses (SPI_BOOT_CRYPT_CNT 1 -> 0)')
  143. SPI_BOOT_CRYPT_CNT = 82
  144. # Resets eFuse, which enables Flash encryption feature
  145. dut.serial.erase_field_on_emul_efuse([SPI_BOOT_CRYPT_CNT])
  146. print(' - Start app (flash partition_table and app)')
  147. dut.serial.write_flash_no_enc()
  148. dut.expect('Loading virtual efuse blocks from flash')
  149. dut.expect('Checking flash encryption...')
  150. dut.expect('Using pre-loaded flash encryption key in efuse')
  151. if dut.app.target == 'esp32':
  152. dut.expect('Setting CRYPT_CONFIG efuse to 0xF')
  153. dut.expect('Not disabling UART bootloader encryption')
  154. dut.expect('Disable UART bootloader decryption...')
  155. dut.expect('Disable UART bootloader MMU cache...')
  156. dut.expect('Disable JTAG...')
  157. dut.expect('Disable ROM BASIC interpreter fallback...')
  158. else:
  159. dut.expect('Not disabling UART bootloader encryption')
  160. dut.expect('Disable UART bootloader cache...')
  161. dut.expect('Disable JTAG...')
  162. dut.expect('bootloader encrypted successfully')
  163. dut.expect('partition table encrypted and loaded successfully')
  164. dut.expect('Flash encryption completed', timeout=90)
  165. dut.expect('Resetting with flash encryption enabled...')
  166. dut.expect('Loading virtual efuse blocks from flash')
  167. dut.expect('Checking flash encryption...')
  168. if dut.app.target == 'esp32':
  169. dut.expect_exact('flash encryption is enabled (3 plaintext flashes left)')
  170. else:
  171. dut.expect_exact('flash encryption is enabled (1 plaintext flashes left)')
  172. dut.expect_exact('Flash encryption mode is DEVELOPMENT (not secure)')
  173. dut.expect('Start eFuse example')
  174. dut.expect('example: Done')
  175. @pytest.mark.generic
  176. @pytest.mark.esp32
  177. @pytest.mark.esp32c2
  178. @pytest.mark.esp32c3
  179. @pytest.mark.esp32s2
  180. @pytest.mark.parametrize('config', ['virt_flash_enc_release',], indirect=True)
  181. @pytest.mark.parametrize('skip_autoflash', ['y'], indirect=True)
  182. def test_examples_efuse_with_virt_flash_enc_release(dut: Dut) -> None:
  183. # check and log bin size
  184. binary_file = os.path.join(dut.app.binary_path, 'bootloader', 'bootloader.bin')
  185. bin_size = os.path.getsize(binary_file)
  186. logging.info('{}_bootloader_virt_flash_enc_release_bin_size: {}KB'.format(dut.app.target, bin_size // 1024))
  187. dut.serial.erase_flash()
  188. print(' - Start app (flash partition_table and app)')
  189. dut.serial.write_flash_no_enc()
  190. dut.expect('Loading virtual efuse blocks from real efuses')
  191. dut.expect('Checking flash encryption...')
  192. dut.expect('Generating new flash encryption key...')
  193. if dut.app.target == 'esp32':
  194. dut.expect('Writing EFUSE_BLK_KEY0 with purpose 2')
  195. dut.expect('Setting CRYPT_CONFIG efuse to 0xF')
  196. dut.expect('Disable UART bootloader encryption...')
  197. dut.expect('Disable UART bootloader decryption...')
  198. dut.expect('Disable UART bootloader MMU cache...')
  199. dut.expect('Disable JTAG...')
  200. dut.expect('Disable ROM BASIC interpreter fallback...')
  201. else:
  202. if dut.app.target == 'esp32c2':
  203. dut.expect('Writing EFUSE_BLK_KEY0 with purpose 1')
  204. else:
  205. dut.expect('Writing EFUSE_BLK_KEY0 with purpose 4')
  206. dut.expect('Disable UART bootloader encryption')
  207. dut.expect('Disable UART bootloader cache...')
  208. dut.expect('Disable JTAG...')
  209. dut.expect('bootloader encrypted successfully')
  210. dut.expect('partition table encrypted and loaded successfully')
  211. dut.expect('Setting CRYPT_CNT for permanent encryption', timeout=90)
  212. dut.expect('Flash encryption completed')
  213. dut.expect('Resetting with flash encryption enabled...')
  214. dut.expect('Loading virtual efuse blocks from flash')
  215. dut.expect('Checking flash encryption...')
  216. dut.expect_exact('flash encryption is enabled (0 plaintext flashes left)', timeout=5)
  217. dut.expect('Flash encryption mode is RELEASE')
  218. dut.expect('Start eFuse example')
  219. dut.expect('example: Done')
  220. @pytest.mark.generic
  221. @pytest.mark.esp32
  222. @pytest.mark.parametrize('config', ['virt_secure_boot_v1',], indirect=True)
  223. @pytest.mark.parametrize('skip_autoflash', ['y'], indirect=True)
  224. def test_examples_efuse_with_virt_secure_boot_v1(dut: Dut) -> None:
  225. # only for ESP32
  226. # check and log bin size
  227. binary_file = os.path.join(dut.app.binary_path, 'bootloader', 'bootloader.bin')
  228. bin_size = os.path.getsize(binary_file)
  229. logging.info('{}_bootloader_virt_secure_boot_v1_bin_size: {}KB'.format(dut.app.target, bin_size // 1024))
  230. print(' - Erase flash')
  231. dut.serial.erase_flash()
  232. print(' - Flash bootloader')
  233. dut.serial.bootloader_flash()
  234. print(' - Start app (flash partition_table and app)')
  235. dut.serial.flash()
  236. dut.expect('Loading virtual efuse blocks from real efuses')
  237. dut.expect('Verifying image signature...')
  238. dut.expect('secure_boot_v1: Generating new secure boot key...')
  239. dut.expect('secure_boot_v1: Generating secure boot digest...')
  240. dut.expect('secure_boot_v1: Digest generation complete')
  241. dut.expect('Checking secure boot...')
  242. dut.expect('secure_boot_v1: blowing secure boot efuse...')
  243. dut.expect('Read & write protecting new key...')
  244. dut.expect('Disable JTAG...')
  245. dut.expect('Disable ROM BASIC interpreter fallback...')
  246. dut.expect('secure_boot_v1: secure boot is now enabled for bootloader image')
  247. dut.expect('cpu_start: Pro cpu up')
  248. dut.expect('Loading virtual efuse blocks from flash')
  249. dut.expect('Start eFuse example')
  250. dut.expect('example: Done')
  251. dut.serial.hard_reset()
  252. dut.expect('Loading virtual efuse blocks from flash')
  253. dut.expect('Verifying image signature...')
  254. dut.expect('secure_boot_v1: bootloader secure boot is already enabled. No need to generate digest. continuing..')
  255. dut.expect('boot: Checking secure boot...')
  256. dut.expect('secure_boot_v1: bootloader secure boot is already enabled, continuing..')
  257. dut.expect('Start eFuse example')
  258. dut.expect('example: Done')
  259. @pytest.mark.generic
  260. @pytest.mark.esp32
  261. @pytest.mark.parametrize('config', ['virt_secure_boot_v1',], indirect=True)
  262. @pytest.mark.parametrize('skip_autoflash', ['y'], indirect=True)
  263. def test_examples_efuse_with_virt_secure_boot_v1_pre_loaded(dut: Dut) -> None:
  264. print(' - Erase flash')
  265. dut.serial.erase_flash()
  266. print(' - Flash bootloader')
  267. dut.serial.bootloader_flash()
  268. print(' - Start app (flash partition_table and app)')
  269. dut.serial.flash()
  270. dut.expect('Loading virtual efuse blocks from real efuses')
  271. dut.expect('cpu_start: Pro cpu up')
  272. dut.expect('Loading virtual efuse blocks from flash')
  273. dut.expect('Start eFuse example')
  274. dut.expect('example: Done')
  275. print(' - Flash emul_efuse with pre-loaded efuses (ABS_DONE_0 1 -> 0)')
  276. # offset of this eFuse is taken from components/efuse/esp32/esp_efuse_table.csv
  277. ABS_DONE_0 = 196
  278. # Resets eFuse, which enables Secure boot (V1) feature
  279. dut.serial.erase_field_on_emul_efuse([ABS_DONE_0])
  280. print(' - Start app (flash partition_table and app)')
  281. dut.serial.flash()
  282. dut.expect('Loading virtual efuse blocks from flash')
  283. dut.expect('Verifying image signature...')
  284. dut.expect('secure_boot_v1: Using pre-loaded secure boot key in EFUSE block 2')
  285. dut.expect('secure_boot_v1: Generating secure boot digest...')
  286. dut.expect('secure_boot_v1: Digest generation complete')
  287. dut.expect('Checking secure boot...')
  288. dut.expect('secure_boot_v1: blowing secure boot efuse...')
  289. dut.expect('Read & write protecting new key...')
  290. dut.expect('Disable JTAG...')
  291. dut.expect('Disable ROM BASIC interpreter fallback...')
  292. dut.expect('secure_boot_v1: secure boot is now enabled for bootloader image')
  293. dut.expect('cpu_start: Pro cpu up')
  294. dut.expect('Loading virtual efuse blocks from flash')
  295. dut.expect('Start eFuse example')
  296. dut.expect('example: Done')
  297. dut.serial.hard_reset()
  298. dut.expect('Loading virtual efuse blocks from flash')
  299. dut.expect('Verifying image signature...')
  300. dut.expect('secure_boot_v1: bootloader secure boot is already enabled. No need to generate digest. continuing..')
  301. dut.expect('Checking secure boot...')
  302. dut.expect('secure_boot_v1: bootloader secure boot is already enabled, continuing..')
  303. dut.expect('Start eFuse example')
  304. dut.expect('example: Done')
  305. @pytest.mark.esp32
  306. @pytest.mark.parametrize('config', [('virt_secure_boot_v2.esp32'),], indirect=True)
  307. @pytest.mark.parametrize('skip_autoflash', ['y'], indirect=True)
  308. def test_examples_efuse_with_virt_secure_boot_v2(dut: Dut) -> None:
  309. # only for ESP32 ECO3
  310. binary_file = os.path.join(dut.app.binary_path, 'bootloader', 'bootloader.bin')
  311. bin_size = os.path.getsize(binary_file)
  312. logging.info('{}_bootloader_secure_boot_v2_bin_size: {}KB'.format(dut.app.target, bin_size // 1024))
  313. print(' - Erase flash')
  314. dut.serial.erase_flash()
  315. print(' - Flash bootloader')
  316. dut.serial.bootloader_flash()
  317. print(' - Start app (flash partition_table and app)')
  318. dut.serial.flash()
  319. dut.expect('Loading virtual efuse blocks from real efuses')
  320. dut.expect('Verifying image signature...')
  321. dut.expect('secure_boot_v2: Secure boot V2 is not enabled yet and eFuse digest keys are not set')
  322. dut.expect('secure_boot_v2: Verifying with RSA-PSS...', timeout=20)
  323. dut.expect('secure_boot_v2: Signature verified successfully!')
  324. dut.expect('secure_boot_v2: enabling secure boot v2...')
  325. dut.expect('Verifying image signature...')
  326. dut.expect('secure_boot_v2: Secure boot V2 is not enabled yet and eFuse digest keys are not set')
  327. dut.expect('secure_boot_v2: Verifying with RSA-PSS...')
  328. dut.expect('secure_boot_v2: Signature verified successfully!')
  329. dut.expect('secure_boot_v2: Secure boot digests absent, generating..')
  330. dut.expect('secure_boot_v2: Digests successfully calculated, 1 valid signatures')
  331. dut.expect_exact('secure_boot_v2: 1 signature block(s) found appended to the bootloader')
  332. dut.expect('Writing EFUSE_BLK_KEY1 with purpose 3')
  333. dut.expect('secure_boot_v2: Digests successfully calculated, 1 valid signatures')
  334. dut.expect_exact('secure_boot_v2: 1 signature block(s) found appended to the app')
  335. dut.expect_exact('secure_boot_v2: Application key(0) matches with bootloader key(0)')
  336. dut.expect('secure_boot_v2: blowing secure boot efuse...')
  337. dut.expect('Disable JTAG...')
  338. dut.expect('Disable ROM BASIC interpreter fallback...')
  339. dut.expect('UART ROM Download mode kept enabled - SECURITY COMPROMISED')
  340. dut.expect('Prevent read disabling of additional efuses...')
  341. dut.expect('secure_boot_v2: Secure boot permanently enabled')
  342. dut.expect('cpu_start: Pro cpu up')
  343. dut.expect('Loading virtual efuse blocks from flash')
  344. dut.expect('Start eFuse example')
  345. dut.expect('example: Done')
  346. dut.serial.hard_reset()
  347. dut.expect('Loading virtual efuse blocks from flash')
  348. dut.expect('Verifying image signature...')
  349. dut.expect('secure_boot_v2: Verifying with RSA-PSS...')
  350. dut.expect('secure_boot_v2: Signature verified successfully!')
  351. dut.expect('secure_boot_v2: enabling secure boot v2...')
  352. dut.expect('secure_boot_v2: secure boot v2 is already enabled, continuing..')
  353. dut.expect('Start eFuse example')
  354. dut.expect('example: Done')
  355. print(' - Erase flash')
  356. dut.serial.erase_flash()
  357. print(' - Flash bootloader and app')
  358. dut.serial.bootloader_flash()
  359. dut.serial.flash()
  360. dut.expect('Loading virtual efuse blocks from real efuses')
  361. dut.expect('Loading virtual efuse blocks from flash')
  362. dut.expect('Start eFuse example')
  363. dut.expect('example: Done')
  364. print(' - Flash emul_efuse with pre-loaded efuses (ABS_DONE_1 1 -> 0)')
  365. # offset of this eFuse is taken from components/efuse/esp32/esp_efuse_table.csv
  366. ABS_DONE_1 = 197
  367. # Resets eFuse, which enables Secure boot (V2) feature
  368. dut.serial.erase_field_on_emul_efuse([ABS_DONE_1])
  369. print(' - Start app (flash partition_table and app)')
  370. dut.serial.flash()
  371. dut.expect('Loading virtual efuse blocks from flash')
  372. dut.expect('Verifying image signature...')
  373. dut.expect('secure_boot_v2: Verifying with RSA-PSS...')
  374. dut.expect('secure_boot_v2: Signature verified successfully!')
  375. dut.expect('secure_boot_v2: enabling secure boot v2...')
  376. dut.expect('Verifying image signature...')
  377. dut.expect('secure_boot_v2: Verifying with RSA-PSS...')
  378. dut.expect('secure_boot_v2: Signature verified successfully!')
  379. dut.expect('secure_boot_v2: Secure boot digests already present')
  380. dut.expect('secure_boot_v2: Using pre-loaded public key digest in eFuse')
  381. dut.expect('secure_boot_v2: Digests successfully calculated, 1 valid signatures')
  382. dut.expect_exact('secure_boot_v2: 1 signature block(s) found appended to the app')
  383. dut.expect_exact('secure_boot_v2: Application key(0) matches with bootloader key(0)')
  384. dut.expect('secure_boot_v2: blowing secure boot efuse...')
  385. dut.expect('Disable JTAG...')
  386. dut.expect('Disable ROM BASIC interpreter fallback...')
  387. dut.expect('UART ROM Download mode kept enabled - SECURITY COMPROMISED')
  388. dut.expect('Prevent read disabling of additional efuses...')
  389. dut.expect('secure_boot_v2: Secure boot permanently enabled')
  390. dut.expect('cpu_start: Pro cpu up')
  391. dut.expect('Loading virtual efuse blocks from flash')
  392. dut.expect('Start eFuse example')
  393. dut.expect('example: Done')
  394. dut.serial.hard_reset()
  395. dut.expect('Loading virtual efuse blocks from flash')
  396. dut.expect('Verifying image signature...')
  397. dut.expect('secure_boot_v2: Verifying with RSA-PSS...')
  398. dut.expect('secure_boot_v2: Signature verified successfully!')
  399. dut.expect('secure_boot_v2: enabling secure boot v2...')
  400. dut.expect('secure_boot_v2: secure boot v2 is already enabled, continuing..')
  401. dut.expect('Start eFuse example')
  402. dut.expect('example: Done')
  403. @pytest.mark.esp32
  404. @pytest.mark.parametrize('config', [('virt_secure_boot_v2.esp32'),], indirect=True)
  405. @pytest.mark.parametrize('skip_autoflash', ['y'], indirect=True)
  406. def test_examples_efuse_with_virt_secure_boot_v2_pre_loaded(dut: Dut) -> None:
  407. print(' - Erase flash')
  408. dut.erase_flash()
  409. print(' - Flash bootloader and app')
  410. dut.bootloader_flash()
  411. print(' - Start app (flash partition_table and app)')
  412. dut.serial.flash()
  413. dut.expect('Loading virtual efuse blocks from real efuses')
  414. dut.expect('cpu_start: Pro cpu up')
  415. dut.expect('Loading virtual efuse blocks from flash')
  416. dut.expect('Start eFuse example')
  417. dut.expect('example: Done')
  418. print(' - Flash emul_efuse with pre-loaded efuses (ABS_DONE_1 1 -> 0)')
  419. # offset of this eFuse is taken from components/efuse/esp32/esp_efuse_table.csv
  420. ABS_DONE_1 = 197
  421. # Resets eFuse, which enables Secure boot (V2) feature
  422. dut.serial.erase_field_on_emul_efuse([ABS_DONE_1])
  423. print(' - Start app (flash partition_table and app)')
  424. dut.serial.flash()
  425. dut.expect('Loading virtual efuse blocks from flash')
  426. dut.expect('Verifying image signature...')
  427. dut.expect('secure_boot_v2: Verifying with RSA-PSS...')
  428. dut.expect('secure_boot_v2: Signature verified successfully!')
  429. dut.expect('secure_boot_v2: enabling secure boot v2...')
  430. dut.expect('Verifying image signature...')
  431. dut.expect('secure_boot_v2: Verifying with RSA-PSS...')
  432. dut.expect('secure_boot_v2: Signature verified successfully!')
  433. dut.expect('secure_boot_v2: Secure boot digests already present')
  434. dut.expect('secure_boot_v2: Using pre-loaded public key digest in eFuse')
  435. dut.expect('secure_boot_v2: Digests successfully calculated, 1 valid signatures')
  436. dut.expect_exact('secure_boot_v2: 1 signature block(s) found appended to the app')
  437. dut.expect_exact('secure_boot_v2: Application key(0) matches with bootloader key(0)')
  438. dut.expect('secure_boot_v2: blowing secure boot efuse...')
  439. dut.expect('Disable JTAG...')
  440. dut.expect('Disable ROM BASIC interpreter fallback...')
  441. dut.expect('UART ROM Download mode kept enabled - SECURITY COMPROMISED')
  442. dut.expect('Prevent read disabling of additional efuses...')
  443. dut.expect('secure_boot_v2: Secure boot permanently enabled')
  444. dut.expect('cpu_start: Pro cpu up')
  445. dut.expect('Loading virtual efuse blocks from flash')
  446. dut.expect('Start eFuse example')
  447. dut.expect('example: Done')
  448. dut.serial.hard_reset()
  449. dut.expect('Loading virtual efuse blocks from flash')
  450. dut.expect('Verifying image signature...')
  451. dut.expect('secure_boot_v2: Verifying with RSA-PSS...')
  452. dut.expect('secure_boot_v2: Signature verified successfully!')
  453. dut.expect('secure_boot_v2: enabling secure boot v2...')
  454. dut.expect('secure_boot_v2: secure boot v2 is already enabled, continuing..')
  455. dut.expect('Start eFuse example')
  456. dut.expect('example: Done')
  457. def test_examples_efuse_with_virt_secure_boot_v2_esp32xx(dut: Dut) -> None:
  458. # check and log bin size
  459. binary_file = os.path.join(dut.app.binary_path, 'bootloader', 'bootloader.bin')
  460. bin_size = os.path.getsize(binary_file)
  461. logging.info('{}_bootloader_virt_secure_boot_v2_bin_size: {}KB'.format(dut.app.target, bin_size // 1024))
  462. print(' - Erase flash')
  463. dut.serial.erase_flash()
  464. print(' - Flash bootloader')
  465. dut.serial.bootloader_flash()
  466. print(' - Start app (flash partition_table and app)')
  467. dut.serial.flash()
  468. dut.expect('Loading virtual efuse blocks from real efuses')
  469. dut.expect('Verifying image signature...')
  470. dut.expect('secure_boot_v2: Secure boot V2 is not enabled yet and eFuse digest keys are not set')
  471. if dut.app.target == 'esp32c2':
  472. signed_scheme = 'ECDSA'
  473. else:
  474. signed_scheme = 'RSA-PSS'
  475. dut.expect('secure_boot_v2: Verifying with %s...' % signed_scheme)
  476. dut.expect('secure_boot_v2: Signature verified successfully!')
  477. dut.expect('secure_boot_v2: enabling secure boot v2...')
  478. dut.expect('Verifying image signature...')
  479. dut.expect('secure_boot_v2: Secure boot V2 is not enabled yet and eFuse digest keys are not set')
  480. dut.expect('secure_boot_v2: Verifying with %s...' % signed_scheme)
  481. dut.expect('secure_boot_v2: Signature verified successfully!')
  482. dut.expect('secure_boot_v2: Secure boot digests absent, generating..')
  483. dut.expect('secure_boot_v2: Digests successfully calculated, 1 valid signatures')
  484. dut.expect_exact('secure_boot_v2: 1 signature block(s) found appended to the bootloader')
  485. if dut.app.target == 'esp32c2':
  486. dut.expect('Writing EFUSE_BLK_KEY0 with purpose 3')
  487. else:
  488. dut.expect('Writing EFUSE_BLK_KEY0 with purpose 9')
  489. dut.expect('secure_boot_v2: Digests successfully calculated, 1 valid signatures')
  490. dut.expect_exact('secure_boot_v2: 1 signature block(s) found appended to the app')
  491. dut.expect_exact('secure_boot_v2: Application key(0) matches with bootloader key(0)')
  492. if dut.app.target != 'esp32c2':
  493. dut.expect_exact('secure_boot_v2: Revoking empty key digest slot (1)...')
  494. dut.expect_exact('secure_boot_v2: Revoking empty key digest slot (2)...')
  495. dut.expect('secure_boot_v2: blowing secure boot efuse...')
  496. dut.expect('UART ROM Download mode kept enabled - SECURITY COMPROMISED')
  497. dut.expect('Disable hardware & software JTAG...')
  498. dut.expect('secure_boot_v2: Secure boot permanently enabled')
  499. dut.expect('cpu_start: Pro cpu up')
  500. dut.expect('Loading virtual efuse blocks from flash')
  501. dut.expect('Start eFuse example')
  502. dut.expect('example: Done')
  503. dut.serial.hard_reset()
  504. dut.expect('Loading virtual efuse blocks from flash')
  505. dut.expect('Verifying image signature...')
  506. dut.expect('secure_boot_v2: Verifying with %s...' % signed_scheme)
  507. dut.expect('secure_boot_v2: Signature verified successfully!')
  508. dut.expect('secure_boot_v2: enabling secure boot v2...')
  509. dut.expect('secure_boot_v2: secure boot v2 is already enabled, continuing..')
  510. dut.expect('Start eFuse example')
  511. dut.expect('example: Done')
  512. @pytest.mark.generic
  513. @pytest.mark.esp32c3
  514. @pytest.mark.parametrize('config', ['virt_secure_boot_v2.esp32c3'], indirect=True)
  515. @pytest.mark.parametrize('skip_autoflash', ['y'], indirect=True)
  516. def test_examples_efuse_with_virt_secure_boot_v2_esp32c3(dut: Dut) -> None:
  517. test_examples_efuse_with_virt_secure_boot_v2_esp32xx(dut)
  518. @pytest.mark.generic
  519. @pytest.mark.esp32c2
  520. @pytest.mark.parametrize('config', ['virt_secure_boot_v2.esp32c2'], indirect=True)
  521. @pytest.mark.parametrize('skip_autoflash', ['y'], indirect=True)
  522. def test_examples_efuse_with_virt_secure_boot_v2_esp32c2(dut: Dut) -> None:
  523. test_examples_efuse_with_virt_secure_boot_v2_esp32xx(dut)
  524. @pytest.mark.generic
  525. @pytest.mark.esp32s2
  526. @pytest.mark.parametrize('config', ['virt_secure_boot_v2.esp32s2'], indirect=True)
  527. @pytest.mark.parametrize('skip_autoflash', ['y'], indirect=True)
  528. def test_examples_efuse_with_virt_secure_boot_v2_esp32s2(dut: Dut) -> None:
  529. test_examples_efuse_with_virt_secure_boot_v2_esp32xx(dut)
  530. def test_example_efuse_with_virt_secure_boot_v2_esp32xx_pre_loaded(dut: Dut) -> None:
  531. print(' - Erase flash')
  532. dut.serial.erase_flash()
  533. print(' - Flash bootloader and app')
  534. dut.serial.bootloader_flash()
  535. dut.serial.flash()
  536. dut.expect('Loading virtual efuse blocks from real efuses')
  537. dut.expect('cpu_start: Pro cpu up')
  538. dut.expect('Loading virtual efuse blocks from flash')
  539. dut.expect('Start eFuse example')
  540. dut.expect('example: Done')
  541. print(' - Flash emul_efuse with pre-loaded efuses (SECURE_BOOT_EN 1 -> 0, SECURE_BOOT_KEY_REVOKE[0..2] -> 0)')
  542. # offsets of eFuses are taken from components/efuse/{target}/esp_efuse_table.csv
  543. if dut.app.target == 'esp32c2':
  544. SECURE_BOOT_EN = 53
  545. dut.serial.erase_field_on_emul_efuse([SECURE_BOOT_EN])
  546. else:
  547. SECURE_BOOT_EN = 116
  548. SECURE_BOOT_KEY_REVOKE0 = 85
  549. SECURE_BOOT_KEY_REVOKE1 = 86
  550. SECURE_BOOT_KEY_REVOKE2 = 87
  551. # Resets eFuse, which enables Secure boot feature
  552. # Resets eFuses, which control digest slots
  553. dut.serial.erase_field_on_emul_efuse([SECURE_BOOT_EN, SECURE_BOOT_KEY_REVOKE0, SECURE_BOOT_KEY_REVOKE1, SECURE_BOOT_KEY_REVOKE2])
  554. print(' - Start app (flash partition_table and app)')
  555. dut.serial.flash()
  556. dut.expect('Loading virtual efuse blocks from flash')
  557. dut.expect('Verifying image signature...')
  558. if dut.app.target == 'esp32c2':
  559. signed_scheme = 'ECDSA'
  560. else:
  561. signed_scheme = 'RSA-PSS'
  562. dut.expect('secure_boot_v2: Verifying with %s...' % signed_scheme)
  563. dut.expect('secure_boot_v2: Signature verified successfully!')
  564. dut.expect('secure_boot_v2: Secure boot digests already present')
  565. dut.expect('secure_boot_v2: Using pre-loaded public key digest in eFuse')
  566. dut.expect('secure_boot_v2: Digests successfully calculated, 1 valid signatures')
  567. dut.expect_exact('secure_boot_v2: 1 signature block(s) found appended to the app')
  568. if dut.app.target != 'esp32c2':
  569. dut.expect_exact('secure_boot_v2: Revoking empty key digest slot (1)...')
  570. dut.expect_exact('secure_boot_v2: Revoking empty key digest slot (2)...')
  571. dut.expect('secure_boot_v2: blowing secure boot efuse...')
  572. dut.expect('UART ROM Download mode kept enabled - SECURITY COMPROMISED')
  573. dut.expect('Disable hardware & software JTAG...')
  574. dut.expect('secure_boot_v2: Secure boot permanently enabled', timeout=20)
  575. dut.expect('cpu_start: Pro cpu up')
  576. dut.expect('Loading virtual efuse blocks from flash')
  577. dut.expect('Start eFuse example')
  578. dut.expect('example: Done')
  579. dut.serial.hard_reset()
  580. dut.expect('Loading virtual efuse blocks from flash')
  581. dut.expect('Verifying image signature...')
  582. dut.expect('secure_boot_v2: Verifying with %s...' % signed_scheme)
  583. dut.expect('secure_boot_v2: Signature verified successfully!')
  584. dut.expect('secure_boot_v2: enabling secure boot v2...')
  585. dut.expect('secure_boot_v2: secure boot v2 is already enabled, continuing..')
  586. dut.expect('Start eFuse example')
  587. dut.expect('example: Done')
  588. @pytest.mark.generic
  589. @pytest.mark.esp32c3
  590. @pytest.mark.parametrize('config', ['virt_secure_boot_v2.esp32c3'], indirect=True)
  591. @pytest.mark.parametrize('skip_autoflash', ['y'], indirect=True)
  592. def test_examples_efuse_with_virt_secure_boot_v2_esp32c3_pre_loaded(dut: Dut) -> None:
  593. test_example_efuse_with_virt_secure_boot_v2_esp32xx_pre_loaded(dut)
  594. @pytest.mark.generic
  595. @pytest.mark.esp32c2
  596. @pytest.mark.parametrize('config', ['virt_secure_boot_v2.esp32c2'], indirect=True)
  597. @pytest.mark.parametrize('skip_autoflash', ['y'], indirect=True)
  598. def test_examples_efuse_with_virt_secure_boot_v2_esp32c2_pre_loaded(dut: Dut) -> None:
  599. test_example_efuse_with_virt_secure_boot_v2_esp32xx_pre_loaded(dut)
  600. @pytest.mark.generic
  601. @pytest.mark.esp32s2
  602. @pytest.mark.parametrize('config', ['virt_secure_boot_v2.esp32s2'], indirect=True)
  603. @pytest.mark.parametrize('skip_autoflash', ['y'], indirect=True)
  604. def test_examples_efuse_with_virt_secure_boot_v2_esp32s2_pre_loaded(dut: Dut) -> None:
  605. test_example_efuse_with_virt_secure_boot_v2_esp32xx_pre_loaded(dut)
  606. @pytest.mark.generic
  607. @pytest.mark.esp32
  608. @pytest.mark.parametrize('config', ['virt_sb_v1_and_fe',], indirect=True)
  609. @pytest.mark.parametrize('skip_autoflash', ['y'], indirect=True)
  610. def test_examples_efuse_with_virt_sb_v1_and_fe(dut: Dut) -> None:
  611. # check and log bin size
  612. binary_file = os.path.join(dut.app.binary_path, 'bootloader', 'bootloader.bin')
  613. bin_size = os.path.getsize(binary_file)
  614. logging.info('{}_bootloader_virt_sb_v1_and_fe_bin_size: {}KB'.format(dut.app.target, bin_size // 1024))
  615. print(' - Erase flash')
  616. dut.serial.erase_flash()
  617. print(' - Flash bootloader')
  618. dut.serial.bootloader_flash()
  619. print(' - Start app (flash partition_table and app)')
  620. dut.serial.write_flash_no_enc()
  621. dut.expect('Loading virtual efuse blocks from real efuses')
  622. dut.expect('Verifying image signature...')
  623. dut.expect('secure_boot_v1: Generating new secure boot key...')
  624. dut.expect('secure_boot_v1: Generating secure boot digest...')
  625. dut.expect('secure_boot_v1: Digest generation complete')
  626. dut.expect('Checking flash encryption...')
  627. dut.expect('flash_encrypt: Generating new flash encryption key...')
  628. dut.expect('Writing EFUSE_BLK_KEY0 with purpose 2')
  629. dut.expect('flash_encrypt: Setting CRYPT_CONFIG efuse to 0xF')
  630. dut.expect('flash_encrypt: Not disabling UART bootloader encryption')
  631. dut.expect('flash_encrypt: Disable UART bootloader decryption...')
  632. dut.expect('flash_encrypt: Disable UART bootloader MMU cache...')
  633. dut.expect('flash_encrypt: Disable JTAG...')
  634. dut.expect('flash_encrypt: Disable ROM BASIC interpreter fallback...')
  635. dut.expect('flash_encrypt: bootloader encrypted successfully')
  636. dut.expect('flash_encrypt: partition table encrypted and loaded successfully')
  637. dut.expect('Verifying image signature...')
  638. dut.expect('flash_encrypt: Flash encryption completed', timeout=90)
  639. dut.expect('Checking secure boot...')
  640. dut.expect('secure_boot_v1: blowing secure boot efuse...')
  641. dut.expect('Read & write protecting new key...')
  642. dut.expect('Disable JTAG...')
  643. dut.expect('Disable ROM BASIC interpreter fallback...')
  644. dut.expect('secure_boot_v1: secure boot is now enabled for bootloader image')
  645. dut.expect('Resetting with flash encryption enabled...')
  646. dut.expect('Verifying image signature...')
  647. dut.expect('secure_boot_v1: bootloader secure boot is already enabled. No need to generate digest. continuing..')
  648. dut.expect('Checking flash encryption...')
  649. dut.expect_exact('flash_encrypt: flash encryption is enabled (3 plaintext flashes left)')
  650. dut.expect('Checking secure boot...')
  651. dut.expect('secure_boot_v1: bootloader secure boot is already enabled, continuing..')
  652. dut.expect('cpu_start: Pro cpu up')
  653. dut.expect('Loading virtual efuse blocks from flash')
  654. dut.expect_exact('flash_encrypt: Flash encryption mode is DEVELOPMENT (not secure)')
  655. dut.expect('Start eFuse example')
  656. dut.expect('example: Done')
  657. @pytest.mark.esp32
  658. @pytest.mark.parametrize('config', ['virt_sb_v2_and_fe.esp32',], indirect=True)
  659. @pytest.mark.parametrize('skip_autoflash', ['y'], indirect=True)
  660. def test_examples_efuse_with_virt_sb_v2_and_fe(dut: Dut) -> None:
  661. # check and log bin size
  662. binary_file = os.path.join(dut.app.binary_path, 'bootloader', 'bootloader.bin')
  663. bin_size = os.path.getsize(binary_file)
  664. logging.info('{}_bootloader_virt_sb_v2_and_fe_bin_size: {}KB'.format(dut.app.target, bin_size // 1024))
  665. print(' - Erase flash')
  666. dut.serial.erase_flash()
  667. print(' - Flash bootloader')
  668. dut.serial.bootloader_flash()
  669. print(' - Start app (flash partition_table and app)')
  670. dut.serial.write_flash_no_enc()
  671. dut.expect('Loading virtual efuse blocks from real efuses')
  672. dut.expect('secure_boot_v2: Secure boot V2 is not enabled yet and eFuse digest keys are not set')
  673. dut.expect('secure_boot_v2: Verifying with RSA-PSS...')
  674. dut.expect('secure_boot_v2: Signature verified successfully!')
  675. dut.expect('secure_boot_v2: enabling secure boot v2...')
  676. dut.expect('Verifying image signature...')
  677. dut.expect('secure_boot_v2: Secure boot V2 is not enabled yet and eFuse digest keys are not set')
  678. dut.expect('secure_boot_v2: Verifying with RSA-PSS...')
  679. dut.expect('secure_boot_v2: Signature verified successfully')
  680. dut.expect('secure_boot_v2: Secure boot digests absent, generating..')
  681. dut.expect('secure_boot_v2: Digests successfully calculated, 1 valid signatures')
  682. dut.expect_exact('secure_boot_v2: 1 signature block(s) found appended to the bootloader')
  683. dut.expect('Writing EFUSE_BLK_KEY1 with purpose 3')
  684. dut.expect('secure_boot_v2: Digests successfully calculated, 1 valid signatures')
  685. dut.expect_exact('secure_boot_v2: 1 signature block(s) found appended to the app')
  686. dut.expect_exact('secure_boot_v2: Application key(0) matches with bootloader key(0)')
  687. dut.expect('secure_boot_v2: blowing secure boot efuse...')
  688. dut.expect('Disable JTAG...')
  689. dut.expect('Disable ROM BASIC interpreter fallback...')
  690. dut.expect('UART ROM Download mode kept enabled - SECURITY COMPROMISED')
  691. dut.expect('secure_boot_v2: Secure boot permanently enabled')
  692. dut.expect('Checking flash encryption...')
  693. dut.expect('flash_encrypt: Generating new flash encryption key...')
  694. dut.expect('Writing EFUSE_BLK_KEY0 with purpose 2')
  695. dut.expect('flash_encrypt: Setting CRYPT_CONFIG efuse to 0xF')
  696. dut.expect('flash_encrypt: Not disabling UART bootloader encryption')
  697. dut.expect('flash_encrypt: Disable UART bootloader decryption...')
  698. dut.expect('flash_encrypt: Disable UART bootloader MMU cache...')
  699. dut.expect('flash_encrypt: Disable JTAG...')
  700. dut.expect('flash_encrypt: Disable ROM BASIC interpreter fallback...')
  701. dut.expect('Verifying image signature...')
  702. dut.expect('secure_boot_v2: Verifying with RSA-PSS...')
  703. dut.expect('secure_boot_v2: Signature verified successfully!')
  704. dut.expect('flash_encrypt: bootloader encrypted successfully')
  705. dut.expect('flash_encrypt: partition table encrypted and loaded successfully')
  706. dut.expect('Verifying image signature...')
  707. dut.expect('secure_boot_v2: Verifying with RSA-PSS...')
  708. dut.expect('secure_boot_v2: Signature verified successfully!')
  709. dut.expect('flash_encrypt: Flash encryption completed', timeout=90)
  710. dut.expect('Resetting with flash encryption enabled...')
  711. dut.expect('Loading virtual efuse blocks from flash')
  712. dut.expect('Verifying image signature...')
  713. dut.expect('secure_boot_v2: Verifying with RSA-PSS...')
  714. dut.expect('secure_boot_v2: Signature verified successfully!')
  715. dut.expect('secure_boot_v2: enabling secure boot v2...')
  716. dut.expect('secure_boot_v2: secure boot v2 is already enabled, continuing..')
  717. dut.expect_exact('flash_encrypt: flash encryption is enabled (3 plaintext flashes left)')
  718. dut.expect('cpu_start: Pro cpu up')
  719. dut.expect('Loading virtual efuse blocks from flash')
  720. dut.expect_exact('flash_encrypt: Flash encryption mode is DEVELOPMENT (not secure)')
  721. dut.expect('Start eFuse example')
  722. dut.expect('example: Done')
  723. def test_examples_efuse_with_virt_sb_v2_and_fe_esp32xx(dut: Dut) -> None:
  724. # check and log bin size
  725. binary_file = os.path.join(dut.app.binary_path, 'bootloader', 'bootloader.bin')
  726. bin_size = os.path.getsize(binary_file)
  727. logging.info('{}_bootloader_virt_sb_v2_and_fe_bin_size: {}KB'.format(dut.app.target, bin_size // 1024))
  728. dut.serial.erase_flash()
  729. print(' - Flash bootloader')
  730. dut.serial.bootloader_flash()
  731. print(' - Start app (flash partition_table and app)')
  732. dut.serial.write_flash_no_enc()
  733. dut.expect('Loading virtual efuse blocks from real efuses')
  734. dut.expect('Verifying image signature...')
  735. dut.expect('secure_boot_v2: Secure boot V2 is not enabled yet and eFuse digest keys are not set')
  736. signed_scheme = 'ECDSA' if dut.app.target == 'esp32c2' else 'RSA-PSS'
  737. dut.expect('secure_boot_v2: Verifying with %s...' % signed_scheme)
  738. dut.expect('secure_boot_v2: Signature verified successfully!')
  739. dut.expect('secure_boot_v2: enabling secure boot v2...')
  740. dut.expect('Verifying image signature...')
  741. dut.expect('secure_boot_v2: Secure boot V2 is not enabled yet and eFuse digest keys are not set')
  742. dut.expect('secure_boot_v2: Verifying with %s...' % signed_scheme)
  743. dut.expect('secure_boot_v2: Signature verified successfully!')
  744. dut.expect('secure_boot_v2: Secure boot digests absent, generating..')
  745. dut.expect('secure_boot_v2: Digests successfully calculated, 1 valid signatures')
  746. dut.expect_exact('secure_boot_v2: 1 signature block(s) found appended to the bootloader')
  747. if dut.app.target == 'esp32c2':
  748. dut.expect('Writing EFUSE_BLK_KEY0 with purpose 3')
  749. else:
  750. dut.expect('Writing EFUSE_BLK_KEY0 with purpose 9')
  751. dut.expect('secure_boot_v2: Digests successfully calculated, 1 valid signatures')
  752. dut.expect_exact('secure_boot_v2: 1 signature block(s) found appended to the app')
  753. dut.expect_exact('secure_boot_v2: Application key(0) matches with bootloader key(0)')
  754. if dut.app.target != 'esp32c2':
  755. dut.expect_exact('secure_boot_v2: Revoking empty key digest slot (1)...')
  756. dut.expect_exact('secure_boot_v2: Revoking empty key digest slot (2)...')
  757. dut.expect('secure_boot_v2: blowing secure boot efuse...')
  758. dut.expect('UART ROM Download mode kept enabled - SECURITY COMPROMISED')
  759. dut.expect('Disable hardware & software JTAG...')
  760. if dut.app.target != 'esp32c2':
  761. dut.expect('secure_boot_v2: Secure boot permanently enabled')
  762. dut.expect('Checking flash encryption...')
  763. dut.expect('flash_encrypt: Generating new flash encryption key...')
  764. if dut.app.target == 'esp32c2':
  765. dut.expect('Writing EFUSE_BLK_KEY0 with purpose 2')
  766. else:
  767. dut.expect('Writing EFUSE_BLK_KEY1 with purpose 4')
  768. dut.expect('Not disabling UART bootloader encryption')
  769. dut.expect('Disable UART bootloader cache...')
  770. dut.expect('Disable JTAG...')
  771. if dut.app.target == 'esp32c2':
  772. dut.expect('boot: Secure boot permanently enabled')
  773. dut.expect('Verifying image signature...')
  774. dut.expect('secure_boot_v2: Verifying with %s...' % signed_scheme)
  775. dut.expect('secure_boot_v2: Signature verified successfully!')
  776. dut.expect('flash_encrypt: bootloader encrypted successfully')
  777. dut.expect('flash_encrypt: partition table encrypted and loaded successfully')
  778. dut.expect('Verifying image signature...')
  779. dut.expect('secure_boot_v2: Verifying with %s...' % signed_scheme)
  780. dut.expect('secure_boot_v2: Signature verified successfully!')
  781. dut.expect('flash_encrypt: Flash encryption completed', timeout=90)
  782. dut.expect('Resetting with flash encryption enabled...')
  783. dut.expect('Loading virtual efuse blocks from flash')
  784. dut.expect('Verifying image signature...')
  785. dut.expect('secure_boot_v2: Verifying with %s...' % signed_scheme)
  786. dut.expect('secure_boot_v2: Signature verified successfully!')
  787. dut.expect('secure_boot_v2: enabling secure boot v2...')
  788. dut.expect('secure_boot_v2: secure boot v2 is already enabled, continuing..')
  789. dut.expect_exact('flash_encrypt: flash encryption is enabled (1 plaintext flashes left)')
  790. dut.expect('cpu_start: Pro cpu up')
  791. dut.expect('Loading virtual efuse blocks from flash')
  792. dut.expect_exact('flash_encrypt: Flash encryption mode is DEVELOPMENT (not secure)')
  793. dut.expect('Start eFuse example')
  794. dut.expect('example: Done')
  795. @pytest.mark.esp32c3
  796. @pytest.mark.parametrize('config', ['virt_sb_v2_and_fe.esp32c3'], indirect=True)
  797. @pytest.mark.parametrize('skip_autoflash', ['y'], indirect=True)
  798. def test_examples_efuse_with_virt_sb_v2_and_fe_esp32c3(dut: Dut) -> None:
  799. test_examples_efuse_with_virt_sb_v2_and_fe_esp32xx(dut)
  800. @pytest.mark.esp32c2
  801. @pytest.mark.parametrize('config', ['virt_sb_v2_and_fe.esp32c2'], indirect=True)
  802. @pytest.mark.parametrize('skip_autoflash', ['y'], indirect=True)
  803. def test_examples_efuse_with_virt_sb_v2_and_fe_esp32c2(dut: Dut) -> None:
  804. test_examples_efuse_with_virt_sb_v2_and_fe_esp32xx(dut)
  805. @pytest.mark.esp32s2
  806. @pytest.mark.parametrize('config', ['virt_sb_v2_and_fe.esp32s2'], indirect=True)
  807. @pytest.mark.parametrize('skip_autoflash', ['y'], indirect=True)
  808. def test_examples_efuse_with_virt_sb_v2_and_fe_esp32s2(dut: Dut) -> None:
  809. test_examples_efuse_with_virt_sb_v2_and_fe_esp32xx(dut)