Skip to content

Commit a1c6d2a

Browse files
laukik-hasemythbuster5
authored andcommitted
fix(esp_tee): Fix failing SPI1 flash protection test-cases
1 parent 0f1dbcc commit a1c6d2a

File tree

3 files changed

+24
-8
lines changed

3 files changed

+24
-8
lines changed

components/esp_tee/subproject/main/core/esp_secure_services_iram.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,11 @@ uint32_t _ss_spi_flash_hal_check_status(spi_flash_host_inst_t *host)
212212

213213
esp_err_t _ss_spi_flash_hal_common_command(spi_flash_host_inst_t *host, spi_flash_trans_t *trans)
214214
{
215+
bool paddr_chk = esp_tee_flash_check_paddr_in_tee_region(trans->address);
216+
if (paddr_chk) {
217+
ESP_LOGD(TAG, "[%s] Illegal flash access at 0x%08x", __func__, trans->address);
218+
return ESP_FAIL;
219+
}
215220
return spi_flash_hal_common_command(host, trans);
216221
}
217222

components/esp_tee/test_apps/tee_test_fw/main/test_esp_tee_flash_prot.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,13 +125,13 @@ static void test_esp_partition_api_w(const esp_partition_t *part)
125125
TEST_ASSERT_NOT_NULL(part);
126126
uint8_t buf_w[128];
127127
memset(buf_w, 0xA5, sizeof(buf_w));
128-
TEST_ESP_OK(esp_partition_write(part, 0x00, buf_w, sizeof(buf_w)));
128+
TEST_ESP_ERR(ESP_FAIL, esp_partition_write(part, 0x00, buf_w, sizeof(buf_w)));
129129
}
130130

131131
static void test_esp_partition_api_e(const esp_partition_t *part)
132132
{
133133
TEST_ASSERT_NOT_NULL(part);
134-
TEST_ESP_OK(esp_partition_erase_range(part, 0x00, SPI_FLASH_SEC_SIZE));
134+
TEST_ESP_ERR(ESP_FAIL, esp_partition_erase_range(part, 0x00, SPI_FLASH_SEC_SIZE));
135135
}
136136

137137
static void test_esp_partition_api(void)
@@ -229,12 +229,12 @@ static void test_esp_flash_api_w(uint32_t paddr)
229229
{
230230
uint8_t buf_w[128];
231231
memset(buf_w, 0xA5, sizeof(buf_w));
232-
TEST_ESP_OK(esp_flash_write(NULL, buf_w, paddr, sizeof(buf_w)));
232+
TEST_ESP_ERR(ESP_FAIL, esp_flash_write(NULL, buf_w, paddr, sizeof(buf_w)));
233233
}
234234

235235
static void test_esp_flash_api_e(uint32_t paddr)
236236
{
237-
TEST_ESP_OK(esp_flash_erase_region(NULL, paddr, SPI_FLASH_SEC_SIZE));
237+
TEST_ESP_ERR(ESP_FAIL, esp_flash_erase_region(NULL, paddr, SPI_FLASH_SEC_SIZE));
238238
}
239239

240240
static void test_esp_flash_api(void)

components/esp_tee/test_apps/tee_test_fw/pytest_esp_tee_ut.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# SPDX-FileCopyrightText: 2024-2025 Espressif Systems (Shanghai) CO LTD
22
# SPDX-License-Identifier: Apache-2.0
3+
import re
34
from enum import Enum
45
from typing import Dict
56
from typing import Tuple
@@ -20,7 +21,7 @@
2021

2122
CONFIG_OTA = [
2223
# 'config, target, skip_autoflash, markers',
23-
('ota', target, 'y', (pytest.mark.generic,))
24+
('ota', target, 'y', (pytest.mark.host_test,))
2425
for target in SUPPORTED_TARGETS
2526
]
2627

@@ -198,8 +199,18 @@ def expect_panic_rsn(dut: IdfDut, expected_rsn: str) -> None:
198199

199200
def run_multiple_stages(dut: IdfDut, test_case_num: int, stages: int, api: TeeFlashAccessApi) -> None:
200201
expected_ops = {
201-
TeeFlashAccessApi.ESP_PARTITION: ['read', 'program_page', 'program_page', 'erase_sector'],
202-
TeeFlashAccessApi.ESP_FLASH: ['program_page', 'read', 'erase_sector', 'program_page'],
202+
TeeFlashAccessApi.ESP_PARTITION: [
203+
'read',
204+
'program_page|common_command',
205+
'program_page|common_command',
206+
'erase_sector|common_command',
207+
],
208+
TeeFlashAccessApi.ESP_FLASH: [
209+
'program_page|common_command',
210+
'read',
211+
'erase_sector|common_command',
212+
'program_page|common_command',
213+
],
203214
}
204215

205216
flash_enc_enabled = dut.app.sdkconfig.get('SECURE_FLASH_ENC_ENABLED', True)
@@ -225,7 +236,7 @@ def run_multiple_stages(dut: IdfDut, test_case_num: int, stages: int, api: TeeFl
225236
r'\[_ss_spi_flash_hal_(\w+)\] Illegal flash access at \s*(0x[0-9a-fA-F]+)', timeout=10
226237
)
227238
actual_op = match.group(1).decode()
228-
if actual_op != curr_op:
239+
if not re.fullmatch(curr_op, actual_op):
229240
raise RuntimeError(f'Unexpected flash operation: {actual_op} (expected: {curr_op})')
230241
elif api == TeeFlashAccessApi.ESP_ROM_SPIFLASH:
231242
expect_panic_rsn(dut, 'APM - Authority exception')

0 commit comments

Comments
 (0)