pytest_system_efuse_example.py 43 KB

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