pytest_system_efuse_example.py 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975
  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.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('Flash Encryption is in RELEASE mode')
  220. dut.expect('example: Done')
  221. @pytest.mark.generic
  222. @pytest.mark.esp32
  223. @pytest.mark.parametrize('config', ['virt_secure_boot_v1',], indirect=True)
  224. @pytest.mark.parametrize('skip_autoflash', ['y'], indirect=True)
  225. def test_examples_efuse_with_virt_secure_boot_v1(dut: Dut) -> None:
  226. # only for ESP32
  227. # check and log bin size
  228. binary_file = os.path.join(dut.app.binary_path, 'bootloader', 'bootloader.bin')
  229. bin_size = os.path.getsize(binary_file)
  230. logging.info('{}_bootloader_virt_secure_boot_v1_bin_size: {}KB'.format(dut.app.target, bin_size // 1024))
  231. print(' - Erase flash')
  232. dut.serial.erase_flash()
  233. print(' - Flash bootloader')
  234. dut.serial.bootloader_flash()
  235. print(' - Start app (flash partition_table and app)')
  236. dut.serial.flash()
  237. dut.expect('Loading virtual efuse blocks from real efuses')
  238. dut.expect('Verifying image signature...')
  239. dut.expect('secure_boot_v1: Generating new secure boot key...')
  240. dut.expect('secure_boot_v1: Generating secure boot digest...')
  241. dut.expect('secure_boot_v1: Digest generation complete')
  242. dut.expect('Checking secure boot...')
  243. dut.expect('secure_boot_v1: blowing secure boot efuse...')
  244. dut.expect('Read & write protecting new key...')
  245. dut.expect('Disable JTAG...')
  246. dut.expect('Disable ROM BASIC interpreter fallback...')
  247. dut.expect('secure_boot_v1: secure boot is now enabled for bootloader image')
  248. dut.expect('Loading virtual efuse blocks from flash')
  249. dut.expect('main_task: Calling app_main()')
  250. dut.expect('Start eFuse example')
  251. dut.expect('example: Done')
  252. dut.serial.hard_reset()
  253. dut.expect('Loading virtual efuse blocks from flash')
  254. dut.expect('Verifying image signature...')
  255. dut.expect('secure_boot_v1: bootloader secure boot is already enabled. No need to generate digest. continuing..')
  256. dut.expect('boot: Checking secure boot...')
  257. dut.expect('secure_boot_v1: bootloader secure boot is already enabled, continuing..')
  258. dut.expect('Start eFuse example')
  259. dut.expect('example: Done')
  260. @pytest.mark.generic
  261. @pytest.mark.esp32
  262. @pytest.mark.parametrize('config', ['virt_secure_boot_v1',], indirect=True)
  263. @pytest.mark.parametrize('skip_autoflash', ['y'], indirect=True)
  264. def test_examples_efuse_with_virt_secure_boot_v1_pre_loaded(dut: Dut) -> None:
  265. print(' - Erase flash')
  266. dut.serial.erase_flash()
  267. print(' - Flash bootloader')
  268. dut.serial.bootloader_flash()
  269. print(' - Start app (flash partition_table and app)')
  270. dut.serial.flash()
  271. dut.expect('Loading virtual efuse blocks from real efuses')
  272. dut.expect('Loading virtual efuse blocks from flash')
  273. dut.expect('main_task: Calling app_main()')
  274. dut.expect('Start eFuse example')
  275. dut.expect('example: Done')
  276. print(' - Flash emul_efuse with pre-loaded efuses (ABS_DONE_0 1 -> 0)')
  277. # offset of this eFuse is taken from components/efuse/esp32/esp_efuse_table.csv
  278. ABS_DONE_0 = 196
  279. # Resets eFuse, which enables Secure boot (V1) feature
  280. dut.serial.erase_field_on_emul_efuse([ABS_DONE_0])
  281. print(' - Start app (flash partition_table and app)')
  282. dut.serial.flash()
  283. dut.expect('Loading virtual efuse blocks from flash')
  284. dut.expect('Verifying image signature...')
  285. dut.expect('secure_boot_v1: Using pre-loaded secure boot key in EFUSE block 2')
  286. dut.expect('secure_boot_v1: Generating secure boot digest...')
  287. dut.expect('secure_boot_v1: Digest generation complete')
  288. dut.expect('Checking secure boot...')
  289. dut.expect('secure_boot_v1: blowing secure boot efuse...')
  290. dut.expect('Read & write protecting new key...')
  291. dut.expect('Disable JTAG...')
  292. dut.expect('Disable ROM BASIC interpreter fallback...')
  293. dut.expect('secure_boot_v1: secure boot is now enabled for bootloader image')
  294. dut.expect('Loading virtual efuse blocks from flash')
  295. dut.expect('main_task: Calling app_main()')
  296. dut.expect('Start eFuse example')
  297. dut.expect('example: Done')
  298. dut.serial.hard_reset()
  299. dut.expect('Loading virtual efuse blocks from flash')
  300. dut.expect('Verifying image signature...')
  301. dut.expect('secure_boot_v1: bootloader secure boot is already enabled. No need to generate digest. continuing..')
  302. dut.expect('Checking secure boot...')
  303. dut.expect('secure_boot_v1: bootloader secure boot is already enabled, continuing..')
  304. dut.expect('Start eFuse example')
  305. dut.expect('example: Done')
  306. @pytest.mark.generic
  307. @pytest.mark.esp32
  308. @pytest.mark.parametrize('config', [('virt_secure_boot_v2.esp32'),], indirect=True)
  309. @pytest.mark.parametrize('skip_autoflash', ['y'], indirect=True)
  310. def test_examples_efuse_with_virt_secure_boot_v2(dut: Dut) -> None:
  311. # only for ESP32 ECO3
  312. binary_file = os.path.join(dut.app.binary_path, 'bootloader', 'bootloader.bin')
  313. bin_size = os.path.getsize(binary_file)
  314. logging.info('{}_bootloader_secure_boot_v2_bin_size: {}KB'.format(dut.app.target, bin_size // 1024))
  315. print(' - Erase flash')
  316. dut.serial.erase_flash()
  317. print(' - Flash bootloader')
  318. dut.serial.bootloader_flash()
  319. print(' - Start app (flash partition_table and app)')
  320. dut.serial.flash()
  321. dut.expect('Loading virtual efuse blocks from real efuses')
  322. dut.expect('Verifying image signature...')
  323. dut.expect('secure_boot_v2: Secure boot V2 is not enabled yet and eFuse digest keys are not set')
  324. dut.expect('secure_boot_v2: Verifying with RSA-PSS...', timeout=20)
  325. dut.expect('secure_boot_v2: Signature verified successfully!')
  326. dut.expect('secure_boot_v2: enabling secure boot v2...')
  327. dut.expect('Verifying image signature...')
  328. dut.expect('secure_boot_v2: Secure boot V2 is not enabled yet and eFuse digest keys are not set')
  329. dut.expect('secure_boot_v2: Verifying with RSA-PSS...')
  330. dut.expect('secure_boot_v2: Signature verified successfully!')
  331. dut.expect('secure_boot_v2: Secure boot digests absent, generating..')
  332. dut.expect('secure_boot_v2: Digests successfully calculated, 1 valid signatures')
  333. dut.expect_exact('secure_boot_v2: 1 signature block(s) found appended to the bootloader')
  334. dut.expect('Writing EFUSE_BLK_KEY1 with purpose 3')
  335. dut.expect('secure_boot_v2: Digests successfully calculated, 1 valid signatures')
  336. dut.expect_exact('secure_boot_v2: 1 signature block(s) found appended to the app')
  337. dut.expect_exact('secure_boot_v2: Application key(0) matches with bootloader key(0)')
  338. dut.expect('secure_boot_v2: blowing secure boot efuse...')
  339. dut.expect('Disable JTAG...')
  340. dut.expect('Disable ROM BASIC interpreter fallback...')
  341. dut.expect('UART ROM Download mode kept enabled - SECURITY COMPROMISED')
  342. dut.expect('Prevent read disabling of additional efuses...')
  343. dut.expect('secure_boot_v2: Secure boot permanently enabled')
  344. dut.expect('Loading virtual efuse blocks from flash')
  345. dut.expect('main_task: Calling app_main()')
  346. dut.expect('Start eFuse example')
  347. dut.expect('example: Done')
  348. dut.serial.hard_reset()
  349. dut.expect('Loading virtual efuse blocks from flash')
  350. dut.expect('Verifying image signature...')
  351. dut.expect('secure_boot_v2: Verifying with RSA-PSS...')
  352. dut.expect('secure_boot_v2: Signature verified successfully!')
  353. dut.expect('secure_boot_v2: enabling secure boot v2...')
  354. dut.expect('secure_boot_v2: secure boot v2 is already enabled, continuing..')
  355. dut.expect('Start eFuse example')
  356. dut.expect('example: Done')
  357. print(' - Erase flash')
  358. dut.serial.erase_flash()
  359. print(' - Flash bootloader and app')
  360. dut.serial.bootloader_flash()
  361. dut.serial.flash()
  362. dut.expect('Loading virtual efuse blocks from real efuses')
  363. dut.expect('Loading virtual efuse blocks from flash')
  364. dut.expect('Start eFuse example')
  365. dut.expect('example: Done')
  366. print(' - Flash emul_efuse with pre-loaded efuses (ABS_DONE_1 1 -> 0)')
  367. # offset of this eFuse is taken from components/efuse/esp32/esp_efuse_table.csv
  368. ABS_DONE_1 = 197
  369. # Resets eFuse, which enables Secure boot (V2) feature
  370. dut.serial.erase_field_on_emul_efuse([ABS_DONE_1])
  371. print(' - Start app (flash partition_table and app)')
  372. dut.serial.flash()
  373. dut.expect('Loading virtual efuse blocks from flash')
  374. dut.expect('Verifying image signature...')
  375. dut.expect('secure_boot_v2: Verifying with RSA-PSS...')
  376. dut.expect('secure_boot_v2: Signature verified successfully!')
  377. dut.expect('secure_boot_v2: enabling secure boot v2...')
  378. dut.expect('Verifying image signature...')
  379. dut.expect('secure_boot_v2: Verifying with RSA-PSS...')
  380. dut.expect('secure_boot_v2: Signature verified successfully!')
  381. dut.expect('secure_boot_v2: Secure boot digests already present')
  382. dut.expect('secure_boot_v2: Using pre-loaded public key digest in eFuse')
  383. dut.expect('secure_boot_v2: Digests successfully calculated, 1 valid signatures')
  384. dut.expect_exact('secure_boot_v2: 1 signature block(s) found appended to the app')
  385. dut.expect_exact('secure_boot_v2: Application key(0) matches with bootloader key(0)')
  386. dut.expect('secure_boot_v2: blowing secure boot efuse...')
  387. dut.expect('Disable JTAG...')
  388. dut.expect('Disable ROM BASIC interpreter fallback...')
  389. dut.expect('UART ROM Download mode kept enabled - SECURITY COMPROMISED')
  390. dut.expect('Prevent read disabling of additional efuses...')
  391. dut.expect('secure_boot_v2: Secure boot permanently enabled')
  392. dut.expect('Loading virtual efuse blocks from flash')
  393. dut.expect('main_task: Calling app_main()')
  394. dut.expect('Start eFuse example')
  395. dut.expect('example: Done')
  396. dut.serial.hard_reset()
  397. dut.expect('Loading virtual efuse blocks from flash')
  398. dut.expect('Verifying image signature...')
  399. dut.expect('secure_boot_v2: Verifying with RSA-PSS...')
  400. dut.expect('secure_boot_v2: Signature verified successfully!')
  401. dut.expect('secure_boot_v2: enabling secure boot v2...')
  402. dut.expect('secure_boot_v2: secure boot v2 is already enabled, continuing..')
  403. dut.expect('Start eFuse example')
  404. dut.expect('example: Done')
  405. @pytest.mark.generic
  406. @pytest.mark.esp32
  407. @pytest.mark.parametrize('config', [('virt_secure_boot_v2.esp32'),], indirect=True)
  408. @pytest.mark.parametrize('skip_autoflash', ['y'], indirect=True)
  409. def test_examples_efuse_with_virt_secure_boot_v2_pre_loaded(dut: Dut) -> None:
  410. print(' - Erase flash')
  411. dut.serial.erase_flash()
  412. print(' - Flash bootloader and app')
  413. dut.serial.bootloader_flash()
  414. print(' - Start app (flash partition_table and app)')
  415. dut.serial.flash()
  416. dut.expect('Loading virtual efuse blocks from real efuses')
  417. dut.expect('Loading virtual efuse blocks from flash')
  418. dut.expect('main_task: Calling app_main()')
  419. dut.expect('Start eFuse example')
  420. dut.expect('example: Done')
  421. print(' - Flash emul_efuse with pre-loaded efuses (ABS_DONE_1 1 -> 0)')
  422. # offset of this eFuse is taken from components/efuse/esp32/esp_efuse_table.csv
  423. ABS_DONE_1 = 197
  424. # Resets eFuse, which enables Secure boot (V2) feature
  425. dut.serial.erase_field_on_emul_efuse([ABS_DONE_1])
  426. print(' - Start app (flash partition_table and app)')
  427. dut.serial.flash()
  428. dut.expect('Loading virtual efuse blocks from flash')
  429. dut.expect('Verifying image signature...')
  430. dut.expect('secure_boot_v2: Verifying with RSA-PSS...')
  431. dut.expect('secure_boot_v2: Signature verified successfully!')
  432. dut.expect('secure_boot_v2: enabling secure boot v2...')
  433. dut.expect('Verifying image signature...')
  434. dut.expect('secure_boot_v2: Verifying with RSA-PSS...')
  435. dut.expect('secure_boot_v2: Signature verified successfully!')
  436. dut.expect('secure_boot_v2: Secure boot digests already present')
  437. dut.expect('secure_boot_v2: Using pre-loaded public key digest in eFuse')
  438. dut.expect('secure_boot_v2: Digests successfully calculated, 1 valid signatures')
  439. dut.expect_exact('secure_boot_v2: 1 signature block(s) found appended to the app')
  440. dut.expect_exact('secure_boot_v2: Application key(0) matches with bootloader key(0)')
  441. dut.expect('secure_boot_v2: blowing secure boot efuse...')
  442. dut.expect('Disable JTAG...')
  443. dut.expect('Disable ROM BASIC interpreter fallback...')
  444. dut.expect('UART ROM Download mode kept enabled - SECURITY COMPROMISED')
  445. dut.expect('Prevent read disabling of additional efuses...')
  446. dut.expect('secure_boot_v2: Secure boot permanently enabled')
  447. dut.expect('Loading virtual efuse blocks from flash')
  448. dut.expect('main_task: Calling app_main()')
  449. dut.expect('Start eFuse example')
  450. dut.expect('example: Done')
  451. dut.serial.hard_reset()
  452. dut.expect('Loading virtual efuse blocks from flash')
  453. dut.expect('Verifying image signature...')
  454. dut.expect('secure_boot_v2: Verifying with RSA-PSS...')
  455. dut.expect('secure_boot_v2: Signature verified successfully!')
  456. dut.expect('secure_boot_v2: enabling secure boot v2...')
  457. dut.expect('secure_boot_v2: secure boot v2 is already enabled, continuing..')
  458. dut.expect('Start eFuse example')
  459. dut.expect('example: Done')
  460. def test_examples_efuse_with_virt_secure_boot_v2_esp32xx(dut: Dut) -> None:
  461. # check and log bin size
  462. binary_file = os.path.join(dut.app.binary_path, 'bootloader', 'bootloader.bin')
  463. bin_size = os.path.getsize(binary_file)
  464. logging.info('{}_bootloader_virt_secure_boot_v2_bin_size: {}KB'.format(dut.app.target, bin_size // 1024))
  465. print(' - Erase flash')
  466. dut.serial.erase_flash()
  467. print(' - Flash bootloader')
  468. dut.serial.bootloader_flash()
  469. print(' - Start app (flash partition_table and app)')
  470. dut.serial.flash()
  471. dut.expect('Loading virtual efuse blocks from real efuses')
  472. dut.expect('Verifying image signature...')
  473. dut.expect('secure_boot_v2: Secure boot V2 is not enabled yet and eFuse digest keys are not set')
  474. if dut.app.target == 'esp32c2':
  475. signed_scheme = 'ECDSA'
  476. else:
  477. signed_scheme = 'RSA-PSS'
  478. dut.expect('secure_boot_v2: Verifying with %s...' % signed_scheme)
  479. dut.expect('secure_boot_v2: Signature verified successfully!')
  480. dut.expect('secure_boot_v2: enabling secure boot v2...')
  481. dut.expect('Verifying image signature...')
  482. dut.expect('secure_boot_v2: Secure boot V2 is not enabled yet and eFuse digest keys are not set')
  483. dut.expect('secure_boot_v2: Verifying with %s...' % signed_scheme)
  484. dut.expect('secure_boot_v2: Signature verified successfully!')
  485. dut.expect('secure_boot_v2: Secure boot digests absent, generating..')
  486. dut.expect('secure_boot_v2: Digests successfully calculated, 1 valid signatures')
  487. dut.expect_exact('secure_boot_v2: 1 signature block(s) found appended to the bootloader')
  488. if dut.app.target == 'esp32c2':
  489. dut.expect('Writing EFUSE_BLK_KEY0 with purpose 3')
  490. else:
  491. dut.expect('Writing EFUSE_BLK_KEY0 with purpose 9')
  492. dut.expect('secure_boot_v2: Digests successfully calculated, 1 valid signatures')
  493. dut.expect_exact('secure_boot_v2: 1 signature block(s) found appended to the app')
  494. dut.expect_exact('secure_boot_v2: Application key(0) matches with bootloader key(0)')
  495. if dut.app.target != 'esp32c2':
  496. dut.expect_exact('secure_boot_v2: Revoking empty key digest slot (1)...')
  497. dut.expect_exact('secure_boot_v2: Revoking empty key digest slot (2)...')
  498. dut.expect('secure_boot_v2: blowing secure boot efuse...')
  499. dut.expect('UART ROM Download mode kept enabled - SECURITY COMPROMISED')
  500. dut.expect('Disable hardware & software JTAG...')
  501. dut.expect('secure_boot_v2: Secure boot permanently enabled')
  502. dut.expect('Loading virtual efuse blocks from flash')
  503. dut.expect('main_task: Calling app_main()')
  504. dut.expect('Start eFuse example')
  505. dut.expect('example: Done')
  506. dut.serial.hard_reset()
  507. dut.expect('Loading virtual efuse blocks from flash')
  508. dut.expect('Verifying image signature...')
  509. dut.expect('secure_boot_v2: Verifying with %s...' % signed_scheme)
  510. dut.expect('secure_boot_v2: Signature verified successfully!')
  511. dut.expect('secure_boot_v2: enabling secure boot v2...')
  512. dut.expect('secure_boot_v2: secure boot v2 is already enabled, continuing..')
  513. dut.expect('Start eFuse example')
  514. dut.expect('example: Done')
  515. @pytest.mark.generic
  516. @pytest.mark.esp32c3
  517. @pytest.mark.parametrize('config', ['virt_secure_boot_v2.esp32c3'], indirect=True)
  518. @pytest.mark.parametrize('skip_autoflash', ['y'], indirect=True)
  519. def test_examples_efuse_with_virt_secure_boot_v2_esp32c3(dut: Dut) -> None:
  520. test_examples_efuse_with_virt_secure_boot_v2_esp32xx(dut)
  521. @pytest.mark.generic
  522. @pytest.mark.esp32c2
  523. @pytest.mark.parametrize('config', ['virt_secure_boot_v2.esp32c2'], indirect=True)
  524. @pytest.mark.parametrize('skip_autoflash', ['y'], indirect=True)
  525. def test_examples_efuse_with_virt_secure_boot_v2_esp32c2(dut: Dut) -> None:
  526. test_examples_efuse_with_virt_secure_boot_v2_esp32xx(dut)
  527. @pytest.mark.generic
  528. @pytest.mark.esp32s2
  529. @pytest.mark.parametrize('config', ['virt_secure_boot_v2.esp32s2'], indirect=True)
  530. @pytest.mark.parametrize('skip_autoflash', ['y'], indirect=True)
  531. def test_examples_efuse_with_virt_secure_boot_v2_esp32s2(dut: Dut) -> None:
  532. test_examples_efuse_with_virt_secure_boot_v2_esp32xx(dut)
  533. def test_example_efuse_with_virt_secure_boot_v2_esp32xx_pre_loaded(dut: Dut) -> None:
  534. print(' - Erase flash')
  535. dut.serial.erase_flash()
  536. print(' - Flash bootloader and app')
  537. dut.serial.bootloader_flash()
  538. dut.serial.flash()
  539. dut.expect('Loading virtual efuse blocks from real efuses')
  540. dut.expect('Loading virtual efuse blocks from flash')
  541. dut.expect('main_task: Calling app_main()')
  542. dut.expect('Start eFuse example')
  543. dut.expect('example: Done')
  544. print(' - Flash emul_efuse with pre-loaded efuses (SECURE_BOOT_EN 1 -> 0, SECURE_BOOT_KEY_REVOKE[0..2] -> 0)')
  545. # offsets of eFuses are taken from components/efuse/{target}/esp_efuse_table.csv
  546. if dut.app.target == 'esp32c2':
  547. SECURE_BOOT_EN = 53
  548. dut.serial.erase_field_on_emul_efuse([SECURE_BOOT_EN])
  549. else:
  550. SECURE_BOOT_EN = 116
  551. SECURE_BOOT_KEY_REVOKE0 = 85
  552. SECURE_BOOT_KEY_REVOKE1 = 86
  553. SECURE_BOOT_KEY_REVOKE2 = 87
  554. # Resets eFuse, which enables Secure boot feature
  555. # Resets eFuses, which control digest slots
  556. dut.serial.erase_field_on_emul_efuse([SECURE_BOOT_EN, SECURE_BOOT_KEY_REVOKE0, SECURE_BOOT_KEY_REVOKE1, SECURE_BOOT_KEY_REVOKE2])
  557. print(' - Start app (flash partition_table and app)')
  558. dut.serial.flash()
  559. dut.expect('Loading virtual efuse blocks from flash')
  560. dut.expect('Verifying image signature...')
  561. if dut.app.target == 'esp32c2':
  562. signed_scheme = 'ECDSA'
  563. else:
  564. signed_scheme = 'RSA-PSS'
  565. dut.expect('secure_boot_v2: Verifying with %s...' % signed_scheme)
  566. dut.expect('secure_boot_v2: Signature verified successfully!')
  567. dut.expect('secure_boot_v2: Secure boot digests already present')
  568. dut.expect('secure_boot_v2: Using pre-loaded public key digest in eFuse')
  569. dut.expect('secure_boot_v2: Digests successfully calculated, 1 valid signatures')
  570. dut.expect_exact('secure_boot_v2: 1 signature block(s) found appended to the app')
  571. if dut.app.target != 'esp32c2':
  572. dut.expect_exact('secure_boot_v2: Revoking empty key digest slot (1)...')
  573. dut.expect_exact('secure_boot_v2: Revoking empty key digest slot (2)...')
  574. dut.expect('secure_boot_v2: blowing secure boot efuse...')
  575. dut.expect('UART ROM Download mode kept enabled - SECURITY COMPROMISED')
  576. dut.expect('Disable hardware & software JTAG...')
  577. dut.expect('secure_boot_v2: Secure boot permanently enabled', timeout=20)
  578. dut.expect('Loading virtual efuse blocks from flash')
  579. dut.expect('main_task: Calling app_main()')
  580. dut.expect('Start eFuse example')
  581. dut.expect('example: Done')
  582. dut.serial.hard_reset()
  583. dut.expect('Loading virtual efuse blocks from flash')
  584. dut.expect('Verifying image signature...')
  585. dut.expect('secure_boot_v2: Verifying with %s...' % signed_scheme)
  586. dut.expect('secure_boot_v2: Signature verified successfully!')
  587. dut.expect('secure_boot_v2: enabling secure boot v2...')
  588. dut.expect('secure_boot_v2: secure boot v2 is already enabled, continuing..')
  589. dut.expect('Start eFuse example')
  590. dut.expect('example: Done')
  591. @pytest.mark.generic
  592. @pytest.mark.esp32c3
  593. @pytest.mark.parametrize('config', ['virt_secure_boot_v2.esp32c3'], indirect=True)
  594. @pytest.mark.parametrize('skip_autoflash', ['y'], indirect=True)
  595. def test_examples_efuse_with_virt_secure_boot_v2_esp32c3_pre_loaded(dut: Dut) -> None:
  596. test_example_efuse_with_virt_secure_boot_v2_esp32xx_pre_loaded(dut)
  597. @pytest.mark.generic
  598. @pytest.mark.esp32c2
  599. @pytest.mark.parametrize('config', ['virt_secure_boot_v2.esp32c2'], indirect=True)
  600. @pytest.mark.parametrize('skip_autoflash', ['y'], indirect=True)
  601. def test_examples_efuse_with_virt_secure_boot_v2_esp32c2_pre_loaded(dut: Dut) -> None:
  602. test_example_efuse_with_virt_secure_boot_v2_esp32xx_pre_loaded(dut)
  603. @pytest.mark.generic
  604. @pytest.mark.esp32s2
  605. @pytest.mark.parametrize('config', ['virt_secure_boot_v2.esp32s2'], indirect=True)
  606. @pytest.mark.parametrize('skip_autoflash', ['y'], indirect=True)
  607. def test_examples_efuse_with_virt_secure_boot_v2_esp32s2_pre_loaded(dut: Dut) -> None:
  608. test_example_efuse_with_virt_secure_boot_v2_esp32xx_pre_loaded(dut)
  609. @pytest.mark.generic
  610. @pytest.mark.esp32
  611. @pytest.mark.parametrize('config', ['virt_sb_v1_and_fe',], indirect=True)
  612. @pytest.mark.parametrize('skip_autoflash', ['y'], indirect=True)
  613. def test_examples_efuse_with_virt_sb_v1_and_fe(dut: Dut) -> None:
  614. # check and log bin size
  615. binary_file = os.path.join(dut.app.binary_path, 'bootloader', 'bootloader.bin')
  616. bin_size = os.path.getsize(binary_file)
  617. logging.info('{}_bootloader_virt_sb_v1_and_fe_bin_size: {}KB'.format(dut.app.target, bin_size // 1024))
  618. print(' - Erase flash')
  619. dut.serial.erase_flash()
  620. print(' - Flash bootloader')
  621. dut.serial.bootloader_flash()
  622. print(' - Start app (flash partition_table and app)')
  623. dut.serial.write_flash_no_enc()
  624. dut.expect('Loading virtual efuse blocks from real efuses')
  625. dut.expect('Verifying image signature...')
  626. dut.expect('secure_boot_v1: Generating new secure boot key...')
  627. dut.expect('secure_boot_v1: Generating secure boot digest...')
  628. dut.expect('secure_boot_v1: Digest generation complete')
  629. dut.expect('Checking flash encryption...')
  630. dut.expect('flash_encrypt: Generating new flash encryption key...')
  631. dut.expect('Writing EFUSE_BLK_KEY0 with purpose 2')
  632. dut.expect('flash_encrypt: Setting CRYPT_CONFIG efuse to 0xF')
  633. dut.expect('flash_encrypt: Not disabling UART bootloader encryption')
  634. dut.expect('flash_encrypt: Disable UART bootloader decryption...')
  635. dut.expect('flash_encrypt: Disable UART bootloader MMU cache...')
  636. dut.expect('flash_encrypt: Disable JTAG...')
  637. dut.expect('flash_encrypt: Disable ROM BASIC interpreter fallback...')
  638. dut.expect('flash_encrypt: bootloader encrypted successfully')
  639. dut.expect('flash_encrypt: partition table encrypted and loaded successfully')
  640. dut.expect('Verifying image signature...')
  641. dut.expect('flash_encrypt: Flash encryption completed', timeout=90)
  642. dut.expect('Checking secure boot...')
  643. dut.expect('secure_boot_v1: blowing secure boot efuse...')
  644. dut.expect('Read & write protecting new key...')
  645. dut.expect('Disable JTAG...')
  646. dut.expect('Disable ROM BASIC interpreter fallback...')
  647. dut.expect('secure_boot_v1: secure boot is now enabled for bootloader image')
  648. dut.expect('Resetting with flash encryption enabled...')
  649. dut.expect('Verifying image signature...')
  650. dut.expect('secure_boot_v1: bootloader secure boot is already enabled. No need to generate digest. continuing..')
  651. dut.expect('Checking flash encryption...')
  652. dut.expect_exact('flash_encrypt: flash encryption is enabled (3 plaintext flashes left)')
  653. dut.expect('Checking secure boot...')
  654. dut.expect('secure_boot_v1: bootloader secure boot is already enabled, continuing..')
  655. dut.expect('Loading virtual efuse blocks from flash')
  656. dut.expect_exact('flash_encrypt: Flash encryption mode is DEVELOPMENT (not secure)')
  657. dut.expect('main_task: Calling app_main()')
  658. dut.expect('Start eFuse example')
  659. dut.expect('example: Flash Encryption is NOT in RELEASE mode')
  660. dut.expect('example: Secure Boot is in RELEASE mode')
  661. dut.expect('example: Done')
  662. @pytest.mark.generic
  663. @pytest.mark.esp32
  664. @pytest.mark.parametrize('config', ['virt_sb_v2_and_fe.esp32',], indirect=True)
  665. @pytest.mark.parametrize('skip_autoflash', ['y'], indirect=True)
  666. def test_examples_efuse_with_virt_sb_v2_and_fe(dut: Dut) -> None:
  667. # check and log bin size
  668. binary_file = os.path.join(dut.app.binary_path, 'bootloader', 'bootloader.bin')
  669. bin_size = os.path.getsize(binary_file)
  670. logging.info('{}_bootloader_virt_sb_v2_and_fe_bin_size: {}KB'.format(dut.app.target, bin_size // 1024))
  671. print(' - Erase flash')
  672. dut.serial.erase_flash()
  673. print(' - Flash bootloader')
  674. dut.serial.bootloader_flash()
  675. print(' - Start app (flash partition_table and app)')
  676. dut.serial.write_flash_no_enc()
  677. dut.expect('Loading virtual efuse blocks from real efuses')
  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: enabling secure boot v2...')
  682. dut.expect('Verifying image signature...')
  683. dut.expect('secure_boot_v2: Secure boot V2 is not enabled yet and eFuse digest keys are not set')
  684. dut.expect('secure_boot_v2: Verifying with RSA-PSS...')
  685. dut.expect('secure_boot_v2: Signature verified successfully')
  686. dut.expect('secure_boot_v2: Secure boot digests absent, generating..')
  687. dut.expect('secure_boot_v2: Digests successfully calculated, 1 valid signatures')
  688. dut.expect_exact('secure_boot_v2: 1 signature block(s) found appended to the bootloader')
  689. dut.expect('Writing EFUSE_BLK_KEY1 with purpose 3')
  690. dut.expect('secure_boot_v2: Digests successfully calculated, 1 valid signatures')
  691. dut.expect_exact('secure_boot_v2: 1 signature block(s) found appended to the app')
  692. dut.expect_exact('secure_boot_v2: Application key(0) matches with bootloader key(0)')
  693. dut.expect('secure_boot_v2: blowing secure boot efuse...')
  694. dut.expect('Disable JTAG...')
  695. dut.expect('Disable ROM BASIC interpreter fallback...')
  696. dut.expect('Disable ROM Download mode...')
  697. dut.expect('secure_boot_v2: Secure boot permanently enabled')
  698. dut.expect('Checking flash encryption...')
  699. dut.expect('flash_encrypt: Generating new flash encryption key...')
  700. dut.expect('Writing EFUSE_BLK_KEY0 with purpose 2')
  701. dut.expect('flash_encrypt: Setting CRYPT_CONFIG efuse to 0xF')
  702. dut.expect('flash_encrypt: Not disabling UART bootloader encryption')
  703. dut.expect('flash_encrypt: Disable UART bootloader decryption...')
  704. dut.expect('flash_encrypt: Disable UART bootloader MMU cache...')
  705. dut.expect('flash_encrypt: Disable JTAG...')
  706. dut.expect('flash_encrypt: Disable ROM BASIC interpreter fallback...')
  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: bootloader encrypted successfully')
  711. dut.expect('flash_encrypt: partition table encrypted and loaded successfully')
  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('flash_encrypt: Flash encryption completed', timeout=90)
  716. dut.expect('Resetting with flash encryption enabled...')
  717. dut.expect('Loading virtual efuse blocks from flash')
  718. dut.expect('Verifying image signature...')
  719. dut.expect('secure_boot_v2: Verifying with RSA-PSS...')
  720. dut.expect('secure_boot_v2: Signature verified successfully!')
  721. dut.expect('secure_boot_v2: enabling secure boot v2...')
  722. dut.expect('secure_boot_v2: secure boot v2 is already enabled, continuing..')
  723. dut.expect_exact('flash_encrypt: flash encryption is enabled (3 plaintext flashes left)')
  724. dut.expect('Loading virtual efuse blocks from flash')
  725. dut.expect_exact('flash_encrypt: Flash encryption mode is DEVELOPMENT (not secure)')
  726. dut.expect('main_task: Calling app_main()')
  727. dut.expect('Start eFuse example')
  728. dut.expect('example: Flash Encryption is NOT in RELEASE mode')
  729. dut.expect('example: Secure Boot is in RELEASE mode')
  730. dut.expect('example: Done')
  731. def test_examples_efuse_with_virt_sb_v2_and_fe_esp32xx(dut: Dut) -> None:
  732. # check and log bin size
  733. binary_file = os.path.join(dut.app.binary_path, 'bootloader', 'bootloader.bin')
  734. bin_size = os.path.getsize(binary_file)
  735. logging.info('{}_bootloader_virt_sb_v2_and_fe_bin_size: {}KB'.format(dut.app.target, bin_size // 1024))
  736. dut.serial.erase_flash()
  737. print(' - Flash bootloader')
  738. dut.serial.bootloader_flash()
  739. print(' - Start app (flash partition_table and app)')
  740. dut.serial.write_flash_no_enc()
  741. dut.expect('Loading virtual efuse blocks from real efuses')
  742. dut.expect('Verifying image signature...')
  743. dut.expect('secure_boot_v2: Secure boot V2 is not enabled yet and eFuse digest keys are not set')
  744. signed_scheme = 'ECDSA' if dut.app.target == 'esp32c2' else 'RSA-PSS'
  745. dut.expect('secure_boot_v2: Verifying with %s...' % signed_scheme)
  746. dut.expect('secure_boot_v2: Signature verified successfully!')
  747. dut.expect('secure_boot_v2: enabling secure boot v2...')
  748. dut.expect('Verifying image signature...')
  749. dut.expect('secure_boot_v2: Secure boot V2 is not enabled yet and eFuse digest keys are not set')
  750. dut.expect('secure_boot_v2: Verifying with %s...' % signed_scheme)
  751. dut.expect('secure_boot_v2: Signature verified successfully!')
  752. dut.expect('secure_boot_v2: Secure boot digests absent, generating..')
  753. dut.expect('secure_boot_v2: Digests successfully calculated, 1 valid signatures')
  754. dut.expect_exact('secure_boot_v2: 1 signature block(s) found appended to the bootloader')
  755. if dut.app.target == 'esp32c2':
  756. dut.expect('Writing EFUSE_BLK_KEY0 with purpose 3')
  757. else:
  758. dut.expect('Writing EFUSE_BLK_KEY0 with purpose 9')
  759. dut.expect('secure_boot_v2: Digests successfully calculated, 1 valid signatures')
  760. dut.expect_exact('secure_boot_v2: 1 signature block(s) found appended to the app')
  761. dut.expect_exact('secure_boot_v2: Application key(0) matches with bootloader key(0)')
  762. if dut.app.target != 'esp32c2':
  763. dut.expect_exact('secure_boot_v2: Revoking empty key digest slot (1)...')
  764. dut.expect_exact('secure_boot_v2: Revoking empty key digest slot (2)...')
  765. dut.expect('secure_boot_v2: blowing secure boot efuse...')
  766. dut.expect('Enabling Security download mode...')
  767. dut.expect('Disable hardware & software JTAG...')
  768. if dut.app.target != 'esp32c2':
  769. dut.expect('secure_boot_v2: Secure boot permanently enabled')
  770. dut.expect('Checking flash encryption...')
  771. dut.expect('flash_encrypt: Generating new flash encryption key...')
  772. if dut.app.target == 'esp32c2':
  773. dut.expect('Writing EFUSE_BLK_KEY0 with purpose 2')
  774. else:
  775. dut.expect('Writing EFUSE_BLK_KEY1 with purpose 4')
  776. dut.expect('Not disabling UART bootloader encryption')
  777. dut.expect('Disable UART bootloader cache...')
  778. dut.expect('Disable JTAG...')
  779. if dut.app.target == 'esp32c2':
  780. dut.expect('boot: Secure boot permanently enabled')
  781. dut.expect('Verifying image signature...')
  782. dut.expect('secure_boot_v2: Verifying with %s...' % signed_scheme)
  783. dut.expect('secure_boot_v2: Signature verified successfully!')
  784. dut.expect('flash_encrypt: bootloader encrypted successfully')
  785. dut.expect('flash_encrypt: partition table encrypted and loaded successfully')
  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: Flash encryption completed', timeout=90)
  790. dut.expect('Resetting with flash encryption enabled...')
  791. dut.expect('Loading virtual efuse blocks from flash')
  792. dut.expect('Verifying image signature...')
  793. dut.expect('secure_boot_v2: Verifying with %s...' % signed_scheme)
  794. dut.expect('secure_boot_v2: Signature verified successfully!')
  795. dut.expect('secure_boot_v2: enabling secure boot v2...')
  796. dut.expect('secure_boot_v2: secure boot v2 is already enabled, continuing..')
  797. dut.expect_exact('flash_encrypt: flash encryption is enabled (1 plaintext flashes left)')
  798. dut.expect('Loading virtual efuse blocks from flash')
  799. dut.expect_exact('flash_encrypt: Flash encryption mode is DEVELOPMENT (not secure)')
  800. dut.expect('main_task: Calling app_main()')
  801. dut.expect('Start eFuse example')
  802. dut.expect('example: Flash Encryption is NOT in RELEASE mode')
  803. dut.expect('example: Secure Boot is in RELEASE mode')
  804. dut.expect('example: Done')
  805. @pytest.mark.generic
  806. @pytest.mark.esp32c3
  807. @pytest.mark.parametrize('config', ['virt_sb_v2_and_fe.esp32c3'], indirect=True)
  808. @pytest.mark.parametrize('skip_autoflash', ['y'], indirect=True)
  809. def test_examples_efuse_with_virt_sb_v2_and_fe_esp32c3(dut: Dut) -> None:
  810. test_examples_efuse_with_virt_sb_v2_and_fe_esp32xx(dut)
  811. @pytest.mark.generic
  812. @pytest.mark.esp32c2
  813. @pytest.mark.parametrize('config', ['virt_sb_v2_and_fe.esp32c2'], indirect=True)
  814. @pytest.mark.parametrize('skip_autoflash', ['y'], indirect=True)
  815. def test_examples_efuse_with_virt_sb_v2_and_fe_esp32c2(dut: Dut) -> None:
  816. test_examples_efuse_with_virt_sb_v2_and_fe_esp32xx(dut)
  817. @pytest.mark.generic
  818. @pytest.mark.esp32s2
  819. @pytest.mark.parametrize('config', ['virt_sb_v2_and_fe.esp32s2'], indirect=True)
  820. @pytest.mark.parametrize('skip_autoflash', ['y'], indirect=True)
  821. def test_examples_efuse_with_virt_sb_v2_and_fe_esp32s2(dut: Dut) -> None:
  822. test_examples_efuse_with_virt_sb_v2_and_fe_esp32xx(dut)