From bdeb54592f5499e06f6514eba46d95b3bdd8d7c2 Mon Sep 17 00:00:00 2001 From: Yossi Levy Date: Sun, 6 Jan 2019 14:55:54 +0200 Subject: [PATCH] This commit fixes an issue in which boards with FlashIAP block device enabled fails the FlashIAP block device tests exists under the component directory. That's because they have no start address and size configured in the mbed_lib.json file. In order to simplify the test for targets with no definitions in the mbed_lib.json, the test will calculate the start address as the first sector after the application ends and up to the max size available. --- .../TESTS/filesystem/fopen/fopen.cpp | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/components/storage/blockdevice/COMPONENT_FLASHIAP/TESTS/filesystem/fopen/fopen.cpp b/components/storage/blockdevice/COMPONENT_FLASHIAP/TESTS/filesystem/fopen/fopen.cpp index 354d74fa14..3ec8474ffe 100644 --- a/components/storage/blockdevice/COMPONENT_FLASHIAP/TESTS/filesystem/fopen/fopen.cpp +++ b/components/storage/blockdevice/COMPONENT_FLASHIAP/TESTS/filesystem/fopen/fopen.cpp @@ -22,6 +22,7 @@ */ //#include "mbed.h" +#include "FlashIAP.h" #include "LittleFileSystem.h" #include "fslittle_debug.h" #include "fslittle_test.h" @@ -48,6 +49,15 @@ using namespace utest::v1; #endif /// @endcond +// Align a value to a specified size. +// Parameters : +// val - [IN] Value. +// size - [IN] Size. +// Return : Aligned value. +static inline uint32_t align_up(uint32_t val, uint32_t size) +{ + return (((val - 1) / size) + 1) * size; +} /* DEVICE_SPI * This symbol is defined in targets.json if the target has a SPI interface, which is required for SDCard support. @@ -1247,7 +1257,29 @@ control_t fslittle_fopen_test_00(const size_t call_count) (void) call_count; int32_t ret = -1; +#if (MBED_CONF_FLASHIAP_BLOCK_DEVICE_SIZE == 0) && (MBED_CONF_FLASHIAP_BLOCK_DEVICE_BASE_ADDRESS == 0xFFFFFFFF) + + size_t flash_size; + uint32_t start_address; + uint32_t bottom_address; + mbed::FlashIAP flash_driver; + + ret = flash_driver.init(); + TEST_ASSERT_EQUAL(0, ret); + + //Find the start of first sector after text area + bottom_address = align_up(FLASHIAP_APP_ROM_END_ADDR, flash_driver.get_sector_size(FLASHIAP_APP_ROM_END_ADDR)); + start_address = flash_driver.get_flash_start(); + flash_size = flash_driver.get_flash_size(); + ret = flash_driver.deinit(); + flash = new FlashIAPBlockDevice(bottom_address, start_address + flash_size - bottom_address); + +#else + flash = new FlashIAPBlockDevice(); + +#endif + ret = flash->init(); TEST_ASSERT_EQUAL(0, ret);