pytest_system_efuse_example.py 48 KB

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