Andrew Geissler | 2daf84b | 2023-03-31 09:57:23 -0500 | [diff] [blame] | 1 | From 3bca7e6bae9a5017fff83b0a7d2d0d78b422a741 Mon Sep 17 00:00:00 2001 |
| 2 | From: Mohamed Omar Asaker <mohamed.omarasaker@arm.com> |
| 3 | Date: Mon, 7 Nov 2022 12:51:58 +0000 |
| 4 | Subject: [PATCH 02/10] Platform: corstone1000: Add IO test in ci_regressions |
| 5 | |
| 6 | The test is simply writing data on the edge of a block |
| 7 | then reading back again. |
| 8 | this test is preformed on two flash devices: |
| 9 | - Nor Flash |
| 10 | - Flash emu in the SRAM for testing |
| 11 | |
| 12 | Signed-off-by: Mohamed Omar Asaker <mohamed.omarasaker@arm.com> |
| 13 | Change-Id: I4950086e9e3dcbde29ab5b4ed5fe61fec7ebec86 |
| 14 | Upstream-Status: Accepted [TF-Mv1.8.0] |
| 15 | --- |
| 16 | .../ci_regression_tests/CMakeLists.txt | 10 + |
| 17 | .../Driver_Flash_SRAM_Emu.c | 327 ++++++++++++++++++ |
| 18 | .../ci_regression_tests/s_io_storage_test.c | 147 ++++++++ |
| 19 | .../ci_regression_tests/s_io_storage_test.h | 15 + |
| 20 | .../corstone1000/ci_regression_tests/s_test.c | 5 + |
| 21 | .../ci_regression_tests/s_test_config.cmake | 5 + |
| 22 | .../ci_regression_tests/test_flash.h | 25 ++ |
| 23 | 7 files changed, 534 insertions(+) |
| 24 | create mode 100644 platform/ext/target/arm/corstone1000/ci_regression_tests/Driver_Flash_SRAM_Emu.c |
| 25 | create mode 100644 platform/ext/target/arm/corstone1000/ci_regression_tests/s_io_storage_test.c |
| 26 | create mode 100644 platform/ext/target/arm/corstone1000/ci_regression_tests/s_io_storage_test.h |
| 27 | create mode 100644 platform/ext/target/arm/corstone1000/ci_regression_tests/test_flash.h |
| 28 | |
| 29 | diff --git a/platform/ext/target/arm/corstone1000/ci_regression_tests/CMakeLists.txt b/platform/ext/target/arm/corstone1000/ci_regression_tests/CMakeLists.txt |
| 30 | index 9543e29e55..405b2b3702 100644 |
| 31 | --- a/platform/ext/target/arm/corstone1000/ci_regression_tests/CMakeLists.txt |
| 32 | +++ b/platform/ext/target/arm/corstone1000/ci_regression_tests/CMakeLists.txt |
| 33 | @@ -17,12 +17,18 @@ target_sources(tfm_test_suite_extra_s |
| 34 | PRIVATE |
| 35 | ${CMAKE_CURRENT_SOURCE_DIR}/s_test.c |
| 36 | ../Native_Driver/firewall.c |
| 37 | + ../io/io_storage.c |
| 38 | + ../io/io_block.c |
| 39 | + ../io/io_flash.c |
| 40 | + Driver_Flash_SRAM_Emu.c |
| 41 | + s_io_storage_test.c |
| 42 | ) |
| 43 | |
| 44 | target_include_directories(tfm_test_suite_extra_s |
| 45 | PRIVATE |
| 46 | ../Device/Include |
| 47 | ../Native_Driver |
| 48 | + ../io |
| 49 | ) |
| 50 | |
| 51 | target_link_libraries(tfm_test_suite_extra_s |
| 52 | @@ -33,4 +39,8 @@ target_link_libraries(tfm_test_suite_extra_s |
| 53 | target_compile_definitions(tfm_test_suite_extra_s |
| 54 | PRIVATE |
| 55 | $<$<BOOL:${PLATFORM_IS_FVP}>:PLATFORM_IS_FVP> |
| 56 | + TEST_FLASH_SIZE_IN_BYTES=${TEST_FLASH_SIZE_IN_BYTES} |
| 57 | + TEST_FLASH_SECTOR_SIZE_IN_BYTES=${TEST_FLASH_SECTOR_SIZE_IN_BYTES} |
| 58 | + TEST_FLASH_PAGE_SIZE=${TEST_FLASH_PAGE_SIZE} |
| 59 | + TEST_FLASH_PROGRAM_UNIT=${TEST_FLASH_PROGRAM_UNIT} |
| 60 | ) |
| 61 | diff --git a/platform/ext/target/arm/corstone1000/ci_regression_tests/Driver_Flash_SRAM_Emu.c b/platform/ext/target/arm/corstone1000/ci_regression_tests/Driver_Flash_SRAM_Emu.c |
| 62 | new file mode 100644 |
| 63 | index 0000000000..06b6b51c09 |
| 64 | --- /dev/null |
| 65 | +++ b/platform/ext/target/arm/corstone1000/ci_regression_tests/Driver_Flash_SRAM_Emu.c |
| 66 | @@ -0,0 +1,327 @@ |
| 67 | +/* |
| 68 | + * Copyright (c) 2013-2022 ARM Limited. All rights reserved. |
| 69 | + * |
| 70 | + * SPDX-License-Identifier: Apache-2.0 |
| 71 | + * |
| 72 | + * Licensed under the Apache License, Version 2.0 (the License); you may |
| 73 | + * not use this file except in compliance with the License. |
| 74 | + * You may obtain a copy of the License at |
| 75 | + * |
| 76 | + * www.apache.org/licenses/LICENSE-2.0 |
| 77 | + * |
| 78 | + * Unless required by applicable law or agreed to in writing, software |
| 79 | + * distributed under the License is distributed on an AS IS BASIS, WITHOUT |
| 80 | + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 81 | + * See the License for the specific language governing permissions and |
| 82 | + * limitations under the License. |
| 83 | + */ |
| 84 | + |
| 85 | +#include <string.h> |
| 86 | +#include <stdint.h> |
| 87 | +#include "Driver_Flash.h" |
| 88 | +#include "test_flash.h" |
| 89 | +#include "tfm_sp_log.h" |
| 90 | + |
| 91 | +#ifndef ARG_UNUSED |
| 92 | +#define ARG_UNUSED(arg) ((void)arg) |
| 93 | +#endif |
| 94 | + |
| 95 | +/* Driver version */ |
| 96 | +#define ARM_FLASH_DRV_VERSION ARM_DRIVER_VERSION_MAJOR_MINOR(1, 1) |
| 97 | +#define ARM_FLASH_DRV_ERASE_VALUE 0xFF |
| 98 | + |
| 99 | + |
| 100 | +/** |
| 101 | + * There is no real flash memory. This driver just emulates a flash |
| 102 | + * interface and behaviour on top of the SRAM memory. |
| 103 | + */ |
| 104 | + |
| 105 | +/** |
| 106 | + * Data width values for ARM_FLASH_CAPABILITIES::data_width |
| 107 | + * \ref ARM_FLASH_CAPABILITIES |
| 108 | + */ |
| 109 | + enum { |
| 110 | + DATA_WIDTH_8BIT = 0u, |
| 111 | + DATA_WIDTH_16BIT, |
| 112 | + DATA_WIDTH_32BIT, |
| 113 | + DATA_WIDTH_ENUM_SIZE |
| 114 | +}; |
| 115 | + |
| 116 | +static const uint32_t data_width_byte[DATA_WIDTH_ENUM_SIZE] = { |
| 117 | + sizeof(uint8_t), |
| 118 | + sizeof(uint16_t), |
| 119 | + sizeof(uint32_t), |
| 120 | +}; |
| 121 | + |
| 122 | + |
| 123 | +/* |
| 124 | + * ARM FLASH device structure |
| 125 | + * |
| 126 | + */ |
| 127 | +struct arm_flash_dev_t { |
| 128 | + const uint8_t* memory_base; /*!< FLASH memory base address */ |
| 129 | + ARM_FLASH_INFO *data; /*!< FLASH data */ |
| 130 | +}; |
| 131 | + |
| 132 | +/* Flash emulated memory */ |
| 133 | +static uint8_t flash_memory[TEST_FLASH_SIZE_IN_BYTES] |
| 134 | + __attribute__((aligned(TEST_FLASH_SECTOR_SIZE_IN_BYTES))); |
| 135 | + |
| 136 | +/* Flash Status */ |
| 137 | +static ARM_FLASH_STATUS FlashStatus = {0, 0, 0}; |
| 138 | + |
| 139 | +/* Driver Version */ |
| 140 | +static const ARM_DRIVER_VERSION DriverVersion = { |
| 141 | + ARM_FLASH_API_VERSION, |
| 142 | + ARM_FLASH_DRV_VERSION |
| 143 | +}; |
| 144 | + |
| 145 | +/* Driver Capabilities */ |
| 146 | +static const ARM_FLASH_CAPABILITIES DriverCapabilities = { |
| 147 | + 0, /* event_ready */ |
| 148 | + 0, /* data_width = 0:8-bit, 1:16-bit, 2:32-bit */ |
| 149 | + 1 /* erase_chip */ |
| 150 | +}; |
| 151 | + |
| 152 | +static int32_t is_range_valid(struct arm_flash_dev_t *flash_dev, |
| 153 | + uint32_t offset) |
| 154 | +{ |
| 155 | + uint32_t flash_limit = 0; |
| 156 | + int32_t rc = 0; |
| 157 | + |
| 158 | + flash_limit = (flash_dev->data->sector_count * flash_dev->data->sector_size); |
| 159 | + if (offset > flash_limit) { |
| 160 | + rc = -1; |
| 161 | + } |
| 162 | + return rc; |
| 163 | +} |
| 164 | + |
| 165 | +static int32_t is_write_aligned(struct arm_flash_dev_t *flash_dev, |
| 166 | + uint32_t param) |
| 167 | +{ |
| 168 | + int32_t rc = 0; |
| 169 | + |
| 170 | + if ((param % flash_dev->data->program_unit) != 0) { |
| 171 | + rc = -1; |
| 172 | + } |
| 173 | + return rc; |
| 174 | +} |
| 175 | + |
| 176 | +static int32_t is_sector_aligned(struct arm_flash_dev_t *flash_dev, |
| 177 | + uint32_t offset) |
| 178 | +{ |
| 179 | + int32_t rc = 0; |
| 180 | + |
| 181 | + if ((offset % flash_dev->data->sector_size) != 0) { |
| 182 | + rc = -1; |
| 183 | + } |
| 184 | + return rc; |
| 185 | +} |
| 186 | + |
| 187 | +static int32_t is_flash_ready_to_write(const uint8_t *start_addr, uint32_t cnt) |
| 188 | +{ |
| 189 | + int32_t rc = 0; |
| 190 | + uint32_t i; |
| 191 | + |
| 192 | + for (i = 0; i < cnt; i++) { |
| 193 | + if(start_addr[i] != ARM_FLASH_DRV_ERASE_VALUE) { |
| 194 | + rc = -1; |
| 195 | + break; |
| 196 | + } |
| 197 | + } |
| 198 | + |
| 199 | + return rc; |
| 200 | +} |
| 201 | + |
| 202 | +static ARM_FLASH_INFO ARM_TEST_FLASH_DEV_DATA = { |
| 203 | + .sector_info = NULL,/* Uniform sector layout */ |
| 204 | + .sector_count = TEST_FLASH_SIZE_IN_BYTES / TEST_FLASH_SECTOR_SIZE_IN_BYTES, |
| 205 | + .sector_size = TEST_FLASH_SECTOR_SIZE_IN_BYTES, |
| 206 | + .page_size = TEST_FLASH_PAGE_SIZE, |
| 207 | + .program_unit = TEST_FLASH_PROGRAM_UNIT, |
| 208 | + .erased_value = ARM_FLASH_DRV_ERASE_VALUE}; |
| 209 | + |
| 210 | +static struct arm_flash_dev_t ARM_TEST_FLASH_DEV = { |
| 211 | + .memory_base = flash_memory, |
| 212 | + .data = &(ARM_TEST_FLASH_DEV_DATA)}; |
| 213 | + |
| 214 | +static struct arm_flash_dev_t *TEST_FLASH_DEV = &ARM_TEST_FLASH_DEV; |
| 215 | + |
| 216 | +/* |
| 217 | + * Functions |
| 218 | + */ |
| 219 | + |
| 220 | +static ARM_DRIVER_VERSION ARM_Flash_GetVersion(void) |
| 221 | +{ |
| 222 | + return DriverVersion; |
| 223 | +} |
| 224 | + |
| 225 | +static ARM_FLASH_CAPABILITIES ARM_Flash_GetCapabilities(void) |
| 226 | +{ |
| 227 | + return DriverCapabilities; |
| 228 | +} |
| 229 | + |
| 230 | +static int32_t ARM_Flash_Initialize(ARM_Flash_SignalEvent_t cb_event) |
| 231 | +{ |
| 232 | + ARG_UNUSED(cb_event); |
| 233 | + |
| 234 | + if (DriverCapabilities.data_width >= DATA_WIDTH_ENUM_SIZE) { |
| 235 | + return ARM_DRIVER_ERROR; |
| 236 | + } |
| 237 | + |
| 238 | + /* Nothing to be done */ |
| 239 | + return ARM_DRIVER_OK; |
| 240 | +} |
| 241 | + |
| 242 | +static int32_t ARM_Flash_Uninitialize(void) |
| 243 | +{ |
| 244 | + /* Nothing to be done */ |
| 245 | + return ARM_DRIVER_OK; |
| 246 | +} |
| 247 | + |
| 248 | +static int32_t ARM_Flash_PowerControl(ARM_POWER_STATE state) |
| 249 | +{ |
| 250 | + switch (state) { |
| 251 | + case ARM_POWER_FULL: |
| 252 | + /* Nothing to be done */ |
| 253 | + return ARM_DRIVER_OK; |
| 254 | + break; |
| 255 | + |
| 256 | + case ARM_POWER_OFF: |
| 257 | + case ARM_POWER_LOW: |
| 258 | + default: |
| 259 | + return ARM_DRIVER_ERROR_UNSUPPORTED; |
| 260 | + } |
| 261 | +} |
| 262 | + |
| 263 | +static int32_t ARM_Flash_ReadData(uint32_t addr, void *data, uint32_t cnt) |
| 264 | +{ |
| 265 | + int32_t rc = 0; |
| 266 | + |
| 267 | + /* The addr given is a relative address*/ |
| 268 | + uint32_t offset = addr; |
| 269 | + addr += (uint32_t)(TEST_FLASH_DEV->memory_base); |
| 270 | + |
| 271 | + /* Conversion between data items and bytes */ |
| 272 | + cnt *= data_width_byte[DriverCapabilities.data_width]; |
| 273 | + |
| 274 | + /* Check flash memory boundaries */ |
| 275 | + rc = is_range_valid(TEST_FLASH_DEV, offset + cnt); |
| 276 | + if (rc != 0) { |
| 277 | + return ARM_DRIVER_ERROR_PARAMETER; |
| 278 | + } |
| 279 | + |
| 280 | + /* Flash interface just emulated over SRAM, use memcpy */ |
| 281 | + memcpy(data, (void *)addr, cnt); |
| 282 | + |
| 283 | + /* Conversion between bytes and data items */ |
| 284 | + cnt /= data_width_byte[DriverCapabilities.data_width]; |
| 285 | + |
| 286 | + return cnt; |
| 287 | +} |
| 288 | + |
| 289 | +static int32_t ARM_Flash_ProgramData(uint32_t addr, const void *data, |
| 290 | + uint32_t cnt) |
| 291 | +{ |
| 292 | + int32_t rc = 0; |
| 293 | + |
| 294 | + /* The addr given is a relative address*/ |
| 295 | + uint32_t offset = addr; |
| 296 | + addr += (uint32_t)(TEST_FLASH_DEV->memory_base); |
| 297 | + |
| 298 | + /* Conversion between data items and bytes */ |
| 299 | + cnt *= data_width_byte[DriverCapabilities.data_width]; |
| 300 | + |
| 301 | + /* Check flash memory boundaries and alignment with minimal write size */ |
| 302 | + rc = is_range_valid(TEST_FLASH_DEV, offset + cnt); |
| 303 | + rc |= is_write_aligned(TEST_FLASH_DEV, offset); |
| 304 | + rc |= is_write_aligned(TEST_FLASH_DEV, cnt); |
| 305 | + if (rc != 0) { |
| 306 | + return ARM_DRIVER_ERROR_PARAMETER; |
| 307 | + } |
| 308 | + |
| 309 | + /* Check if the flash area to write the data was erased previously */ |
| 310 | + rc = is_flash_ready_to_write((const uint8_t*)addr, cnt); |
| 311 | + if (rc != 0) { |
| 312 | + return ARM_DRIVER_ERROR; |
| 313 | + } |
| 314 | + |
| 315 | + /* Flash interface just emulated over SRAM, use memcpy */ |
| 316 | + memcpy((void *)addr, data, cnt); |
| 317 | + |
| 318 | + /* Conversion between bytes and data items */ |
| 319 | + cnt /= data_width_byte[DriverCapabilities.data_width]; |
| 320 | + |
| 321 | + return cnt; |
| 322 | +} |
| 323 | + |
| 324 | +static int32_t ARM_Flash_EraseSector(uint32_t addr) |
| 325 | +{ |
| 326 | + uint32_t rc = 0; |
| 327 | + |
| 328 | + /* The addr given is a relative address*/ |
| 329 | + uint32_t offset = addr; |
| 330 | + addr += (uint32_t)(TEST_FLASH_DEV->memory_base); |
| 331 | + |
| 332 | + rc = is_range_valid(TEST_FLASH_DEV, offset); |
| 333 | + rc |= is_sector_aligned(TEST_FLASH_DEV, offset); |
| 334 | + if (rc != 0) { |
| 335 | + return ARM_DRIVER_ERROR_PARAMETER; |
| 336 | + } |
| 337 | + |
| 338 | + /* Flash interface just emulated over SRAM, use memset */ |
| 339 | + memset((void *)addr, |
| 340 | + TEST_FLASH_DEV->data->erased_value, |
| 341 | + TEST_FLASH_DEV->data->sector_size); |
| 342 | + return ARM_DRIVER_OK; |
| 343 | +} |
| 344 | + |
| 345 | +static int32_t ARM_Flash_EraseChip(void) |
| 346 | +{ |
| 347 | + uint32_t i; |
| 348 | + uint32_t addr = TEST_FLASH_DEV->memory_base; |
| 349 | + int32_t rc = ARM_DRIVER_ERROR_UNSUPPORTED; |
| 350 | + |
| 351 | + /* Check driver capability erase_chip bit */ |
| 352 | + if (DriverCapabilities.erase_chip == 1) { |
| 353 | + for (i = 0; i < TEST_FLASH_DEV->data->sector_count; i++) { |
| 354 | + /* Flash interface just emulated over SRAM, use memset */ |
| 355 | + memset((void *)addr, |
| 356 | + TEST_FLASH_DEV->data->erased_value, |
| 357 | + TEST_FLASH_DEV->data->sector_size); |
| 358 | + |
| 359 | + addr += TEST_FLASH_DEV->data->sector_size; |
| 360 | + rc = ARM_DRIVER_OK; |
| 361 | + } |
| 362 | + } |
| 363 | + return rc; |
| 364 | +} |
| 365 | + |
| 366 | +static ARM_FLASH_STATUS ARM_Flash_GetStatus(void) |
| 367 | +{ |
| 368 | + return FlashStatus; |
| 369 | +} |
| 370 | + |
| 371 | +static ARM_FLASH_INFO * ARM_Flash_GetInfo(void) |
| 372 | +{ |
| 373 | + return TEST_FLASH_DEV->data; |
| 374 | +} |
| 375 | + |
| 376 | + |
| 377 | +/* Global Variables */ |
| 378 | + |
| 379 | +ARM_DRIVER_FLASH Driver_TEST_FLASH = { |
| 380 | + ARM_Flash_GetVersion, |
| 381 | + ARM_Flash_GetCapabilities, |
| 382 | + ARM_Flash_Initialize, |
| 383 | + ARM_Flash_Uninitialize, |
| 384 | + ARM_Flash_PowerControl, |
| 385 | + ARM_Flash_ReadData, |
| 386 | + ARM_Flash_ProgramData, |
| 387 | + ARM_Flash_EraseSector, |
| 388 | + ARM_Flash_EraseChip, |
| 389 | + ARM_Flash_GetStatus, |
| 390 | + ARM_Flash_GetInfo |
| 391 | +}; |
| 392 | + |
| 393 | +uintptr_t flash_base_address = flash_memory; |
| 394 | diff --git a/platform/ext/target/arm/corstone1000/ci_regression_tests/s_io_storage_test.c b/platform/ext/target/arm/corstone1000/ci_regression_tests/s_io_storage_test.c |
| 395 | new file mode 100644 |
| 396 | index 0000000000..f8be384a74 |
| 397 | --- /dev/null |
| 398 | +++ b/platform/ext/target/arm/corstone1000/ci_regression_tests/s_io_storage_test.c |
| 399 | @@ -0,0 +1,147 @@ |
| 400 | +/* |
| 401 | + * Copyright (c) 2022, Arm Limited. All rights reserved. |
| 402 | + * |
| 403 | + * SPDX-License-Identifier: BSD-3-Clause |
| 404 | + * |
| 405 | + */ |
| 406 | + |
| 407 | +#include "s_io_storage_test.h" |
| 408 | + |
| 409 | +#include "Driver_Flash.h" |
| 410 | +#include "flash_layout.h" |
| 411 | +#include "io_block.h" |
| 412 | +#include "io_driver.h" |
| 413 | +#include "io_flash.h" |
| 414 | +#include "tfm_sp_log.h" |
| 415 | + |
| 416 | +#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(*(array))) |
| 417 | + |
| 418 | +extern ARM_DRIVER_FLASH Driver_FLASH0; |
| 419 | +extern ARM_DRIVER_FLASH Driver_TEST_FLASH; |
| 420 | +extern uintptr_t flash_base_address; |
| 421 | + |
| 422 | +void s_test_io_storage_multiple_flash_simultaneous(struct test_result_t *ret) { |
| 423 | + /* FLASH0 */ |
| 424 | + static io_dev_connector_t* flash0_dev_con; |
| 425 | + static uint8_t local_block_flash0[FLASH_SECTOR_SIZE]; |
| 426 | + ARM_FLASH_INFO* flash0_info = Driver_FLASH0.GetInfo(); |
| 427 | + size_t flash0_block_size = flash0_info->sector_size; |
| 428 | + io_flash_dev_spec_t flash0_dev_spec = { |
| 429 | + .buffer = local_block_flash0, |
| 430 | + .bufferlen = flash0_block_size, |
| 431 | + .base_addr = FLASH_BASE_ADDRESS, |
| 432 | + .flash_driver = &Driver_FLASH0, |
| 433 | + }; |
| 434 | + io_block_spec_t flash0_spec = { |
| 435 | + .offset = FLASH_BASE_ADDRESS, |
| 436 | + .length = flash0_info->sector_count * flash0_info->sector_size}; |
| 437 | + uintptr_t flash0_dev_handle = NULL; |
| 438 | + uintptr_t flash0_handle = NULL; |
| 439 | + |
| 440 | + /* EMU TEST FLASH */ |
| 441 | + static io_dev_connector_t* flash_emu_dev_con; |
| 442 | + static uint8_t local_block_flash_emu[TEST_FLASH_SECTOR_SIZE_IN_BYTES] |
| 443 | + __attribute__((aligned(TEST_FLASH_SECTOR_SIZE_IN_BYTES))); |
| 444 | + ARM_FLASH_INFO* flash_emu_info = Driver_TEST_FLASH.GetInfo(); |
| 445 | + size_t flash_emu_block_size = flash_emu_info->sector_size; |
| 446 | + io_flash_dev_spec_t flash_emu_dev_spec = { |
| 447 | + .buffer = local_block_flash_emu, |
| 448 | + .bufferlen = flash_emu_block_size, |
| 449 | + .base_addr = flash_base_address, |
| 450 | + .flash_driver = &Driver_TEST_FLASH, |
| 451 | + }; |
| 452 | + io_block_spec_t flash_emu_spec = { |
| 453 | + .offset = flash_base_address, |
| 454 | + .length = flash_emu_info->sector_count * flash_emu_info->sector_size}; |
| 455 | + uintptr_t flash_emu_dev_handle = NULL; |
| 456 | + uintptr_t flash_emu_handle = NULL; |
| 457 | + |
| 458 | + /* Common */ |
| 459 | + int rc = -1; |
| 460 | + static uint8_t test_data[] = {0xEE, 0xDD, 0xCC, 0xBB, 0xAA, |
| 461 | + 0x10, 0x50, 0xA0, 0xD0, 0x51, |
| 462 | + 0x55, 0x44, 0x33, 0x22, 0x11}; |
| 463 | + static uint8_t actual_data[15]; |
| 464 | + size_t bytes_written_count = 0; |
| 465 | + size_t bytes_read_count = 0; |
| 466 | + |
| 467 | + memset(local_block_flash0, -1, sizeof(local_block_flash0)); |
| 468 | + memset(local_block_flash_emu, -1, sizeof(local_block_flash_emu)); |
| 469 | + |
| 470 | + /* Register */ |
| 471 | + register_io_dev_flash(&flash0_dev_con); |
| 472 | + register_io_dev_flash(&flash_emu_dev_con); |
| 473 | + |
| 474 | + io_dev_open(flash0_dev_con, &flash0_dev_spec, &flash0_dev_handle); |
| 475 | + io_dev_open(flash_emu_dev_con, &flash_emu_dev_spec, &flash_emu_dev_handle); |
| 476 | + |
| 477 | + /* Write Data */ |
| 478 | + io_open(flash0_dev_handle, &flash0_spec, &flash0_handle); |
| 479 | + io_open(flash_emu_dev_handle, &flash_emu_spec, &flash_emu_handle); |
| 480 | + |
| 481 | + io_seek(flash0_handle, IO_SEEK_SET, |
| 482 | + BANK_1_PARTITION_OFFSET + flash0_info->sector_size - 7); |
| 483 | + io_seek(flash_emu_handle, IO_SEEK_SET, flash_emu_info->sector_size - 7); |
| 484 | + |
| 485 | + io_write(flash0_handle, test_data, ARRAY_LENGTH(test_data), |
| 486 | + &bytes_written_count); |
| 487 | + if (bytes_written_count != ARRAY_LENGTH(test_data)) { |
| 488 | + LOG_ERRFMT("io_write failed to write %d bytes for flash0", |
| 489 | + ARRAY_LENGTH(test_data)); |
| 490 | + LOG_ERRFMT("bytes_written_count %d for flash0", bytes_written_count); |
| 491 | + ret->val = TEST_FAILED; |
| 492 | + } |
| 493 | + io_write(flash_emu_handle, test_data, ARRAY_LENGTH(test_data), |
| 494 | + &bytes_written_count); |
| 495 | + if (bytes_written_count != ARRAY_LENGTH(test_data)) { |
| 496 | + LOG_ERRFMT("io_write failed to write %d bytes for flash emu", |
| 497 | + ARRAY_LENGTH(test_data)); |
| 498 | + LOG_ERRFMT("bytes_written_count %d for flash emu", bytes_written_count); |
| 499 | + ret->val = TEST_FAILED; |
| 500 | + } |
| 501 | + io_close(flash0_handle); |
| 502 | + io_close(flash_emu_handle); |
| 503 | + |
| 504 | + /* Read Data */ |
| 505 | + io_open(flash0_dev_handle, &flash0_spec, &flash0_handle); |
| 506 | + io_open(flash_emu_dev_handle, &flash_emu_spec, &flash_emu_handle); |
| 507 | + |
| 508 | + io_seek(flash0_handle, IO_SEEK_SET, |
| 509 | + BANK_1_PARTITION_OFFSET + flash0_info->sector_size - 7); |
| 510 | + io_seek(flash_emu_handle, IO_SEEK_SET, flash_emu_info->sector_size - 7); |
| 511 | + |
| 512 | + /* Flash0 */ |
| 513 | + io_read(flash0_handle, actual_data, ARRAY_LENGTH(actual_data), |
| 514 | + &bytes_read_count); |
| 515 | + if (bytes_read_count != ARRAY_LENGTH(test_data)) { |
| 516 | + LOG_ERRFMT("io_read failed to read %d bytes for flash0", |
| 517 | + ARRAY_LENGTH(test_data)); |
| 518 | + LOG_ERRFMT("bytes_read_count %d for flash0", bytes_read_count); |
| 519 | + ret->val = TEST_FAILED; |
| 520 | + } |
| 521 | + if (memcmp((uint8_t*)test_data, actual_data, ARRAY_LENGTH(actual_data)) != |
| 522 | + 0) { |
| 523 | + LOG_ERRFMT("Data written != Data read\r\n"); |
| 524 | + ret->val = TEST_FAILED; |
| 525 | + } |
| 526 | + |
| 527 | + memset(actual_data, -1, sizeof(actual_data)); |
| 528 | + |
| 529 | + /* Flash Emu */ |
| 530 | + io_read(flash_emu_handle, actual_data, ARRAY_LENGTH(actual_data), |
| 531 | + &bytes_read_count); |
| 532 | + if (bytes_read_count != ARRAY_LENGTH(test_data)) { |
| 533 | + LOG_ERRFMT("io_read failed to read %d bytes for flash emu", |
| 534 | + ARRAY_LENGTH(test_data)); |
| 535 | + LOG_ERRFMT("bytes_read_count %d for flash emu", bytes_read_count); |
| 536 | + ret->val = TEST_FAILED; |
| 537 | + } |
| 538 | + if (memcmp((uint8_t*)test_data, actual_data, ARRAY_LENGTH(actual_data)) != |
| 539 | + 0) { |
| 540 | + LOG_ERRFMT("Data written != Data read\r\n"); |
| 541 | + ret->val = TEST_FAILED; |
| 542 | + } |
| 543 | + |
| 544 | + LOG_INFFMT("PASS: %s\n\r", __func__); |
| 545 | + ret->val = TEST_PASSED; |
| 546 | +} |
| 547 | \ No newline at end of file |
| 548 | diff --git a/platform/ext/target/arm/corstone1000/ci_regression_tests/s_io_storage_test.h b/platform/ext/target/arm/corstone1000/ci_regression_tests/s_io_storage_test.h |
| 549 | new file mode 100644 |
| 550 | index 0000000000..fa9012776f |
| 551 | --- /dev/null |
| 552 | +++ b/platform/ext/target/arm/corstone1000/ci_regression_tests/s_io_storage_test.h |
| 553 | @@ -0,0 +1,15 @@ |
| 554 | +/* |
| 555 | + * Copyright (c) 2022, Arm Limited. All rights reserved. |
| 556 | + * |
| 557 | + * SPDX-License-Identifier: BSD-3-Clause |
| 558 | + * |
| 559 | + */ |
| 560 | + |
| 561 | +#ifndef __S_IO_STORAGE_TEST_H__ |
| 562 | +#define __S_IO_STORAGE_TEST_H__ |
| 563 | + |
| 564 | +#include "extra_s_tests.h" |
| 565 | + |
| 566 | +void s_test_io_storage_multiple_flash_simultaneous(struct test_result_t *ret); |
| 567 | + |
| 568 | +#endif /* __S_IO_STORAGE_TEST_H__ */ |
| 569 | \ No newline at end of file |
| 570 | diff --git a/platform/ext/target/arm/corstone1000/ci_regression_tests/s_test.c b/platform/ext/target/arm/corstone1000/ci_regression_tests/s_test.c |
| 571 | index a0bf47a04b..9a8453ff57 100644 |
| 572 | --- a/platform/ext/target/arm/corstone1000/ci_regression_tests/s_test.c |
| 573 | +++ b/platform/ext/target/arm/corstone1000/ci_regression_tests/s_test.c |
| 574 | @@ -11,6 +11,7 @@ |
| 575 | #include "platform_base_address.h" |
| 576 | #include "firewall.h" |
| 577 | #include "tfm_sp_log.h" |
| 578 | +#include "s_io_storage_test.h" |
| 579 | |
| 580 | /* TODO: if needed each test function can be made as a separate test case, in |
| 581 | * such case EXTRA_TEST_XX definitions can be removed */ |
| 582 | @@ -19,6 +20,8 @@ |
| 583 | |
| 584 | #define DISABLED_TEST 0 |
| 585 | |
| 586 | +int test_io_storage_multiple_flash_simultaneous(void); |
| 587 | + |
| 588 | enum host_firewall_host_comp_id_t { |
| 589 | HOST_FCTRL = (0x00u), |
| 590 | COMP_SYSPERIPH, |
| 591 | @@ -184,6 +187,8 @@ void s_test(struct test_result_t *ret) |
| 592 | static struct test_t plat_s_t[] = { |
| 593 | {&s_test, "TFM_S_EXTRA_TEST_1001", |
| 594 | "Extra Secure test"}, |
| 595 | + {&s_test_io_storage_multiple_flash_simultaneous, "TFM_S_EXTRA_TEST_1002", |
| 596 | + "Extra Secure test: io storage access multiple flash simultaneous"}, |
| 597 | }; |
| 598 | |
| 599 | void register_testsuite_extra_s_interface(struct test_suite_t *p_test_suite) |
| 600 | diff --git a/platform/ext/target/arm/corstone1000/ci_regression_tests/s_test_config.cmake b/platform/ext/target/arm/corstone1000/ci_regression_tests/s_test_config.cmake |
| 601 | index bb8d26bf1c..05b7cd7852 100644 |
| 602 | --- a/platform/ext/target/arm/corstone1000/ci_regression_tests/s_test_config.cmake |
| 603 | +++ b/platform/ext/target/arm/corstone1000/ci_regression_tests/s_test_config.cmake |
| 604 | @@ -6,3 +6,8 @@ |
| 605 | #------------------------------------------------------------------------------- |
| 606 | |
| 607 | ############ Define secure test specific cmake configurations here ############# |
| 608 | + |
| 609 | +set (TEST_FLASH_SIZE_IN_BYTES 48U CACHE STRING "The size of the emulated flash used in io tests") |
| 610 | +set (TEST_FLASH_SECTOR_SIZE_IN_BYTES 16U CACHE STRING "The sector size of the emulated flash used in io tests") |
| 611 | +set (TEST_FLASH_PAGE_SIZE 8U CACHE STRING "The page size of the emulated flash used in io tests") |
| 612 | +set (TEST_FLASH_PROGRAM_UNIT 1U CACHE STRING "The program unit of the emulated flash used in io tests") |
| 613 | diff --git a/platform/ext/target/arm/corstone1000/ci_regression_tests/test_flash.h b/platform/ext/target/arm/corstone1000/ci_regression_tests/test_flash.h |
| 614 | new file mode 100644 |
| 615 | index 0000000000..4d073a1d71 |
| 616 | --- /dev/null |
| 617 | +++ b/platform/ext/target/arm/corstone1000/ci_regression_tests/test_flash.h |
| 618 | @@ -0,0 +1,25 @@ |
| 619 | +/* |
| 620 | + * Copyright (c) 2017-2022 Arm Limited. All rights reserved. |
| 621 | + * |
| 622 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 623 | + * you may not use this file except in compliance with the License. |
| 624 | + * You may obtain a copy of the License at |
| 625 | + * |
| 626 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 627 | + * |
| 628 | + * Unless required by applicable law or agreed to in writing, software |
| 629 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 630 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 631 | + * See the License for the specific language governing permissions and |
| 632 | + * limitations under the License. |
| 633 | + */ |
| 634 | + |
| 635 | +#ifndef __TEST_FLASH_H__ |
| 636 | +#define __TEST_FLASH_H__ |
| 637 | + |
| 638 | +#define TEST_FLASH_SIZE_IN_BYTES (48) // 48 bytes |
| 639 | +#define TEST_FLASH_SECTOR_SIZE_IN_BYTES (16) // 16 bytes |
| 640 | +#define TEST_FLASH_PAGE_SIZE (8U) // 8 bytes |
| 641 | +#define TEST_FLASH_PROGRAM_UNIT (1U) /* 1 B */ |
| 642 | + |
| 643 | +#endif /* __TEST_FLASH_H__ */ |
| 644 | -- |
| 645 | 2.25.1 |
| 646 | |