pytest_system_efuse_example.py 44 KB

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