Merge pull request #11797 from ARMmbed/IOTSTOR-941

IOTSTOR-953: Fix address calculations from SlicingBlockDevice
pull/11813/head
Martin Kojtal 2019-11-05 09:09:14 +01:00 committed by GitHub
commit 355336ce43
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
52 changed files with 839 additions and 214 deletions

View File

@ -31,3 +31,4 @@
^TESTS/mbed_hal/trng/pithy
^TESTS/mbed_hal/trng/pithy
^tools
^UNITTESTS

View File

@ -76,7 +76,7 @@ if (COVERAGE)
endif()
# Append coverage compiler flags
set(COVERAGE_COMPILER_FLAGS "-g -O0 --coverage -fprofile-arcs -ftest-coverage")
set(COVERAGE_COMPILER_FLAGS "-g -O0 --coverage")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${COVERAGE_COMPILER_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${COVERAGE_COMPILER_FLAGS}")

View File

@ -0,0 +1,39 @@
/* Copyright (c) 2019 ARM Limited
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "gtest/gtest.h"
/*
* Purpose of this test is just to be empty baseline
* that does nothing, but includes all source files
* in the build.
* Do not add any tests here
*/
class EmptyBaseline : public testing::Test {
virtual void SetUp()
{
}
virtual void TearDown()
{
}
};
TEST_F(EmptyBaseline, constructor)
{
EXPECT_TRUE(true);
}

View File

@ -0,0 +1,54 @@
####################
# UNIT TESTS
####################
set(unittest-includes ${unittest-includes}
.
..
../features/mbedtls/mbed-crypto/inc/mbedtls/
../features/mbedtls/platform/inc/
../features/frameworks/mbed-trace/mbed-trace/
)
set(unittest-sources
../features/device_key/source/DeviceKey.cpp
../components/storage/blockdevice/COMPONENT_SPIF/SPIFBlockDevice.cpp
../components/storage/blockdevice/COMPONENT_I2CEE/I2CEEBlockDevice.cpp
../components/storage/blockdevice/COMPONENT_DATAFLASH/DataFlashBlockDevice.cpp
../components/storage/blockdevice/COMPONENT_FLASHIAP/FlashIAPBlockDevice.cpp
../components/storage/blockdevice/COMPONENT_RSPIF/SPIFReducedBlockDevice.cpp
../components/storage/blockdevice/COMPONENT_SD/SDBlockDevice.cpp
../components/storage/blockdevice/COMPONENT_QSPIF/QSPIFBlockDevice.cpp
../features/storage/filesystem/Dir.cpp
../features/storage/filesystem/FileSystem.cpp
../features/storage/filesystem/File.cpp
../features/storage/kvstore/global_api/kvstore_global_api.cpp
../features/storage/kvstore/securestore/SecureStore.cpp
../features/storage/kvstore/kv_map/KVMap.cpp
../features/storage/kvstore/tdbstore/TDBStore.cpp
../features/storage/kvstore/direct_access_devicekey/DirectAccessDevicekey.cpp
../features/storage/kvstore/conf/kv_config.cpp
../features/storage/kvstore/filesystemstore/FileSystemStore.cpp
../features/storage/system_storage/SystemStorage.cpp
../features/storage/nvstore/source/nvstore.cpp
../features/storage/blockdevice/ChainingBlockDevice.cpp
../features/storage/blockdevice/ReadOnlyBlockDevice.cpp
../features/storage/blockdevice/SlicingBlockDevice.cpp
../features/storage/blockdevice/MBRBlockDevice.cpp
../features/storage/blockdevice/HeapBlockDevice.cpp
../features/storage/blockdevice/FlashSimBlockDevice.cpp
../features/storage/blockdevice/ObservingBlockDevice.cpp
../features/storage/blockdevice/ProfilingBlockDevice.cpp
../features/storage/blockdevice/BufferedBlockDevice.cpp
../features/storage/blockdevice/ExhaustibleBlockDevice.cpp
)
set(unittest-test-sources
empty_baseline/empty_baseline.cpp
)
set(DEVICE_FLAGS "-DDEVICE_ANALOGIN -DDEVICE_ANALOGOUT -DDEVICE_CAN -DDEVICE_CRC -DDEVICE_ETHERNET -DDEVICE_FLASH -DDEVICE_I2C -DDEVICE_I2CSLAVE -DDEVICE_I2C_ASYNCH -DDEVICE_INTERRUPTIN -DDEVICE_LPTICKER -DDEVICE_PORTIN -DDEVICE_PORTINOUT -DDEVICE_PORTOUT -DDEVICE_PWMOUT -DDEVICE_QSPI -DDEVICE_SERIAL -DDEVICE_SERIAL_ASYNCH -DDEVICE_SERIAL_FC -DDEVICE_SPI -DDEVICE_SPISLAVE -DDEVICE_SPI_ASYNCH -DDEVICE_FLASH -DCOMPONENT_FLASHIAP")
set(CONF_FLAGS "-DMBED_CONF_PLATFORM_CTHUNK_COUNT_MAX=10 -DMBED_CONF_DATAFLASH_SPI_FREQ=1 -DMBED_CONF_FLASHIAP_BLOCK_DEVICE_BASE_ADDRESS=0 -DMBED_CONF_FLASHIAP_BLOCK_DEVICE_SIZE=0 -DMBED_CONF_QSPIF_QSPI_FREQ=1 -DMBED_CONF_QSPIF_QSPI_MIN_READ_SIZE=1 -DMBED_CONF_QSPIF_QSPI_MIN_PROG_SIZE=1 -DMBED_LFS_READ_SIZE=64 -DMBED_LFS_PROG_SIZE=64 -DMBED_LFS_BLOCK_SIZE=512 -DMBED_LFS_LOOKAHEAD=512 -DFLASHIAP_APP_ROM_END_ADDR=0x80000 -DMBED_CONF_STORAGE_TDB_INTERNAL_INTERNAL_SIZE=1024 -DMBED_CONF_STORAGE_TDB_INTERNAL_INTERNAL_BASE_ADDRESS=0x80000 -DMBED_CONF_STORAGE_STORAGE_TYPE=default")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${DEVICE_FLAGS} ${CONF_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${DEVICE_FLAGS} ${CONF_FLAGS}")

View File

@ -0,0 +1,120 @@
/* Copyright (c) 2019 ARM Limited
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "gtest/gtest.h"
#include "features/storage/blockdevice/HeapBlockDevice.h"
#include <string.h>
#include "mbed_assert.h"
#define BLOCK_SIZE (512)
#define DEVICE_SIZE (BLOCK_SIZE*10)
class HeapBlockDeviceTest : public testing::Test {
protected:
virtual void SetUp()
{
bd.init();
}
virtual void TearDown()
{
bd.deinit();
}
mbed::HeapBlockDevice bd{DEVICE_SIZE};
};
TEST_F(HeapBlockDeviceTest, constructor)
{
// HeapBlockDevice(bd_size_t size, bd_size_t read, bd_size_t program, bd_size_t erase);
mbed::HeapBlockDevice one{3000, 100, 200, 300};
EXPECT_EQ(one.init(), BD_ERROR_OK);
EXPECT_EQ(one.size(), 3000);
EXPECT_EQ(one.get_read_size(), 100);
EXPECT_EQ(one.get_program_size(), 200);
EXPECT_EQ(one.get_erase_size(), 300);
EXPECT_EQ(one.get_erase_size(0), 300);
EXPECT_EQ(one.deinit(), BD_ERROR_OK);
}
TEST_F(HeapBlockDeviceTest, double_init)
{
mbed::HeapBlockDevice one{DEVICE_SIZE};
EXPECT_EQ(one.init(), BD_ERROR_OK);
EXPECT_EQ(one.init(), BD_ERROR_OK);
EXPECT_EQ(one.deinit(), BD_ERROR_OK); // First de-init does only decrement the counter
EXPECT_EQ(one.deinit(), BD_ERROR_OK);
EXPECT_EQ(one.deinit(), BD_ERROR_OK); //Third one does not de-init, but return immediately
}
TEST_F(HeapBlockDeviceTest, get_type)
{
EXPECT_EQ(0, strcmp(bd.get_type(), "HEAP"));
}
TEST_F(HeapBlockDeviceTest, erase_program_read)
{
uint8_t *block = new uint8_t[BLOCK_SIZE] {0xaa,0xbb,0xcc};
uint8_t *buf = new uint8_t[BLOCK_SIZE];
EXPECT_EQ(bd.erase(0, BLOCK_SIZE), BD_ERROR_OK);
EXPECT_EQ(bd.program(block, 0, BLOCK_SIZE), BD_ERROR_OK);
EXPECT_EQ(bd.read(buf, 0, BLOCK_SIZE), BD_ERROR_OK);
EXPECT_EQ(0, memcmp(block, buf, BLOCK_SIZE));
delete[] block;
delete[] buf;
}
TEST_F(HeapBlockDeviceTest, use_uninitialized)
{
mbed::HeapBlockDevice one{DEVICE_SIZE};
uint8_t *buf = new uint8_t[BLOCK_SIZE];
EXPECT_EQ(one.read(buf, 0, BLOCK_SIZE), BD_ERROR_DEVICE_ERROR);
EXPECT_EQ(one.program(buf, 0, BLOCK_SIZE), BD_ERROR_DEVICE_ERROR);
delete[] buf;
}
TEST_F(HeapBlockDeviceTest, over_read)
{
uint8_t *buf = new uint8_t[BLOCK_SIZE];
EXPECT_EQ(bd.read(buf, DEVICE_SIZE, BLOCK_SIZE), BD_ERROR_DEVICE_ERROR);
delete[] buf;
}
TEST_F(HeapBlockDeviceTest, over_write)
{
uint8_t *buf = new uint8_t[BLOCK_SIZE] {0xaa,0xbb,0xcc};
EXPECT_EQ(bd.program(buf, DEVICE_SIZE, BLOCK_SIZE), BD_ERROR_DEVICE_ERROR);
delete[] buf;
}
TEST_F(HeapBlockDeviceTest, over_erase)
{
EXPECT_EQ(bd.erase(DEVICE_SIZE, BLOCK_SIZE), BD_ERROR_DEVICE_ERROR);
}
TEST_F(HeapBlockDeviceTest, erase_uninitialized)
{
mbed::HeapBlockDevice one{DEVICE_SIZE};
EXPECT_EQ(one.erase(DEVICE_SIZE, BLOCK_SIZE), BD_ERROR_DEVICE_ERROR);
}
TEST_F(HeapBlockDeviceTest, read_unprogrammed)
{
uint8_t *buf = new uint8_t[BLOCK_SIZE];
EXPECT_EQ(bd.read(buf, DEVICE_SIZE - BLOCK_SIZE, BLOCK_SIZE), BD_ERROR_OK);
// Ignore the content, it is now zero, but does not need to be.
delete[] buf;
}

View File

@ -0,0 +1,19 @@
####################
# UNIT TESTS
####################
set(unittest-includes ${unittest-includes}
.
..
)
set(unittest-sources
../features/storage/blockdevice/HeapBlockDevice.cpp
stubs/mbed_atomic_stub.c
stubs/mbed_assert_stub.c
)
set(unittest-test-sources
features/storage/blockdevice/HeapBlockDevice/test.cpp
)

View File

@ -0,0 +1,161 @@
/* Copyright (c) 2019 ARM Limited
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "gtest/gtest.h"
#include "features/storage/blockdevice/HeapBlockDevice.h"
#include "features/storage/blockdevice/SlicingBlockDevice.h"
#define BLOCK_SIZE (512)
#define DEVICE_SIZE (BLOCK_SIZE*10)
class VerifyBorders_HeapBlockDevice : public mbed::HeapBlockDevice {
public:
mutable bool borders_crossed;
mutable bd_size_t lower_limit;
mutable bd_size_t upper_limit;
VerifyBorders_HeapBlockDevice(bd_size_t size)
: HeapBlockDevice(size)
{
borders_crossed = false;
lower_limit = 0;
upper_limit = size;
}
virtual bool is_valid_read(bd_addr_t addr, bd_size_t size) const
{
borders_crossed |= addr < lower_limit;
borders_crossed |= addr + size > upper_limit;
return BlockDevice::is_valid_read(addr, size);
}
virtual bool is_valid_program(bd_addr_t addr, bd_size_t size) const
{
borders_crossed |= addr < lower_limit;
borders_crossed |= addr + size > upper_limit;
return BlockDevice::is_valid_program(addr, size);
}
virtual bool is_valid_erase(bd_addr_t addr, bd_size_t size) const
{
borders_crossed |= addr < lower_limit;
borders_crossed |= addr + size > upper_limit;
return BlockDevice::is_valid_erase(addr, size);
}
};
class SlicingBlockModuleTest : public testing::Test {
protected:
VerifyBorders_HeapBlockDevice bd{DEVICE_SIZE};
uint8_t *magic;
uint8_t *buf;
virtual void SetUp()
{
bd.init();
magic = new uint8_t[BLOCK_SIZE];
buf = new uint8_t[BLOCK_SIZE];
// Generate simple pattern to verify against
for (int i = 0; i < BLOCK_SIZE; i++) {
magic[i] = 0xaa + i;
}
}
virtual void TearDown()
{
bd.deinit();
delete[] magic;
delete[] buf;
}
};
TEST_F(SlicingBlockModuleTest, constructor)
{
mbed::SlicingBlockDevice slice(&bd, 0, bd.size());
EXPECT_EQ(slice.init(), BD_ERROR_OK);
EXPECT_EQ(slice.get_read_size(), bd.get_read_size());
EXPECT_EQ(slice.get_program_size(), bd.get_read_size());
EXPECT_EQ(slice.get_erase_size(), bd.get_read_size());
EXPECT_EQ(slice.get_erase_size(0), bd.get_read_size());
EXPECT_EQ(slice.deinit(), BD_ERROR_OK);
}
TEST_F(SlicingBlockModuleTest, slice_in_middle)
{
uint8_t *program = new uint8_t[BLOCK_SIZE] {0xbb,0xbb,0xbb};
//Write magic value to heap block before and after the space for slice
bd.program(magic, 0, BLOCK_SIZE);
bd.program(magic, BLOCK_SIZE * 3, BLOCK_SIZE);
bd.upper_limit = BLOCK_SIZE * 3;
bd.lower_limit = BLOCK_SIZE;
bd.borders_crossed = false;
//Skip first block, then create sclicing device, with size of 2 blocks
mbed::SlicingBlockDevice slice(&bd, BLOCK_SIZE, BLOCK_SIZE * 3);
EXPECT_EQ(slice.init(), BD_ERROR_OK);
EXPECT_EQ(BLOCK_SIZE * 2, slice.size());
EXPECT_EQ(bd.borders_crossed, false);
//Program a test value
EXPECT_EQ(slice.program(program, 0, BLOCK_SIZE), BD_ERROR_OK);
EXPECT_EQ(slice.program(program, BLOCK_SIZE, BLOCK_SIZE), BD_ERROR_OK);
EXPECT_EQ(bd.borders_crossed, false);
//Verify that blocks before and after the slicing blocks are not touched
bd.read(buf, 0, BLOCK_SIZE);
EXPECT_EQ(0, memcmp(buf, magic, BLOCK_SIZE));
bd.read(buf, BLOCK_SIZE * 3, BLOCK_SIZE);
EXPECT_EQ(0, memcmp(buf, magic, BLOCK_SIZE));
}
TEST_F(SlicingBlockModuleTest, slice_at_the_end)
{
uint8_t *program = new uint8_t[BLOCK_SIZE] {0xbb,0xbb,0xbb};
//Write magic value to heap block before the space for slice
// our bd is 10*BLOCK_SIZE, so sector 7
bd.program(magic, BLOCK_SIZE * 7, BLOCK_SIZE);
//Screate sclicing device, with size of 2 blocks
// Use negative index
mbed::SlicingBlockDevice slice(&bd, -BLOCK_SIZE*2);
EXPECT_EQ(slice.init(), BD_ERROR_OK);
EXPECT_EQ(BLOCK_SIZE * 2, slice.size());
//Program a test value
EXPECT_EQ(slice.program(program, 0, BLOCK_SIZE), BD_ERROR_OK);
EXPECT_EQ(slice.program(program, BLOCK_SIZE, BLOCK_SIZE), BD_ERROR_OK);
//Verify that blocks before and after the slicing blocks are not touched
bd.read(buf, BLOCK_SIZE * 7, BLOCK_SIZE);
EXPECT_EQ(0, memcmp(buf, magic, BLOCK_SIZE));
}
TEST_F(SlicingBlockModuleTest, over_write)
{
uint8_t *program = new uint8_t[BLOCK_SIZE] {0xbb,0xbb,0xbb};
//Screate sclicing device, with size of 2 blocks
mbed::SlicingBlockDevice slice(&bd, BLOCK_SIZE, BLOCK_SIZE * 3);
EXPECT_EQ(slice.init(), BD_ERROR_OK);
EXPECT_EQ(slice.program(program, 0, BLOCK_SIZE), BD_ERROR_OK);
EXPECT_EQ(slice.program(program, BLOCK_SIZE, BLOCK_SIZE), BD_ERROR_OK);
//Program a test value to address that is one pass the device size
EXPECT_EQ(slice.program(program, 2 * BLOCK_SIZE, BLOCK_SIZE), BD_ERROR_DEVICE_ERROR);
delete[] program;
}

View File

@ -0,0 +1,20 @@
####################
# UNIT TESTS
####################
set(unittest-includes ${unittest-includes}
.
..
)
set(unittest-sources
../features/storage/blockdevice/SlicingBlockDevice.cpp
../features/storage/blockdevice/HeapBlockDevice.cpp
stubs/mbed_atomic_stub.c
stubs/mbed_assert_stub.c
)
set(unittest-test-sources
moduletests/storage/blockdevice/SlicingBlockDevice/moduletest.cpp
)

View File

@ -57,113 +57,143 @@ uint32_t core_util_atomic_exchange_u32(volatile uint32_t *ptr, uint32_t desiredV
uint8_t core_util_atomic_incr_u8(volatile uint8_t *valuePtr, uint8_t delta)
{
return 0;
return *valuePtr += delta;
}
uint16_t core_util_atomic_incr_u16(volatile uint16_t *valuePtr, uint16_t delta)
{
return 0;
return *valuePtr += delta;
}
uint32_t core_util_atomic_incr_u32(volatile uint32_t *valuePtr, uint32_t delta)
{
return 0;
return *valuePtr += delta;
}
uint8_t core_util_atomic_decr_u8(volatile uint8_t *valuePtr, uint8_t delta)
{
return 0;
return *valuePtr -= delta;
}
uint16_t core_util_atomic_decr_u16(volatile uint16_t *valuePtr, uint16_t delta)
{
return 0;
return *valuePtr -= delta;
}
uint32_t core_util_atomic_decr_u32(volatile uint32_t *valuePtr, uint32_t delta)
{
return 0;
return *valuePtr -= delta;
}
uint8_t core_util_atomic_fetch_add_u8(volatile uint8_t *valuePtr, uint8_t arg)
{
return 0;
uint8_t v = *valuePtr;
*valuePtr += arg;
return v;
}
uint16_t core_util_atomic_fetch_add_u16(volatile uint16_t *valuePtr, uint16_t arg)
{
return 0;
uint16_t v = *valuePtr;
*valuePtr += arg;
return v;
}
uint32_t core_util_atomic_fetch_add_u32(volatile uint32_t *valuePtr, uint32_t arg)
{
return 0;
uint32_t v = *valuePtr;
*valuePtr += arg;
return v;
}
uint8_t core_util_atomic_fetch_sub_u8(volatile uint8_t *valuePtr, uint8_t arg)
{
return 0;
uint8_t v = *valuePtr;
*valuePtr -= arg;
return v;
}
uint16_t core_util_atomic_fetch_sub_u16(volatile uint16_t *valuePtr, uint16_t arg)
{
return 0;
uint16_t v = *valuePtr;
*valuePtr -= arg;
return v;
}
uint32_t core_util_atomic_fetch_sub_u32(volatile uint32_t *valuePtr, uint32_t arg)
{
return 0;
uint32_t v = *valuePtr;
*valuePtr -= arg;
return v;
}
uint8_t core_util_atomic_fetch_and_u8(volatile uint8_t *valuePtr, uint8_t arg)
{
return 0;
uint8_t v = *valuePtr;
*valuePtr &= arg;
return v;
}
uint16_t core_util_atomic_fetch_and_u16(volatile uint16_t *valuePtr, uint16_t arg)
{
return 0;
uint16_t v = *valuePtr;
*valuePtr &= arg;
return v;
}
uint32_t core_util_atomic_fetch_and_u32(volatile uint32_t *valuePtr, uint32_t arg)
{
return 0;
uint32_t v = *valuePtr;
*valuePtr &= arg;
return v;
}
uint8_t core_util_atomic_fetch_or_u8(volatile uint8_t *valuePtr, uint8_t arg)
{
return 0;
uint8_t v = *valuePtr;
*valuePtr |= arg;
return v;
}
uint16_t core_util_atomic_fetch_or_u16(volatile uint16_t *valuePtr, uint16_t arg)
{
return 0;
uint16_t v = *valuePtr;
*valuePtr |= arg;
return v;
}
uint32_t core_util_atomic_fetch_or_u32(volatile uint32_t *valuePtr, uint32_t arg)
{
return 0;
uint32_t v = *valuePtr;
*valuePtr |= arg;
return v;
}
uint8_t core_util_atomic_fetch_xor_u8(volatile uint8_t *valuePtr, uint8_t arg)
{
return 0;
uint8_t v = *valuePtr;
*valuePtr ^= arg;
return v;
}
uint16_t core_util_atomic_fetch_xor_u16(volatile uint16_t *valuePtr, uint16_t arg)
{
return 0;
uint16_t v = *valuePtr;
*valuePtr ^= arg;
return v;
}
uint32_t core_util_atomic_fetch_xor_u32(volatile uint32_t *valuePtr, uint32_t arg)
{
return 0;
uint32_t v = *valuePtr;
*valuePtr ^= arg;
return v;
}

View File

@ -40,8 +40,13 @@ typedef enum {
PullDefault = PullUp
} PinMode;
typedef enum {
PortA = 0,
} PortName;
#ifdef __cplusplus
}
#endif
#include "pinmap.h"
#endif

View File

@ -64,6 +64,7 @@ typedef void *osEventFlagsId_t;
/// Attributes structure for thread.
typedef struct {
int unused;
} osThreadAttr_t;
#define osWaitForever 0xFFFFFFFFU ///< Wait forever timeout value.

View File

@ -19,5 +19,6 @@
#define MBED_DEVICE_H
#include "objects.h"
#include "PinNames.h"
#endif

View File

@ -27,6 +27,7 @@ extern "C" {
#endif
typedef struct {
int unused;
} gpio_t;
#ifdef __cplusplus

View File

@ -34,11 +34,41 @@ struct serial_s {
int x;
};
struct pwmout_s {
int pwm_name;
struct dac_s {
int unused;
};
struct i2c_s {
int unused;
};
struct qspi_s {
int unused;
};
struct spi_s {
int unused;
};
struct analogin_s {
int unused;
};
struct port_s {
int unused;
};
struct pwmout_s {
int unused;
};
struct flash_s {
int unused;
};
struct can_s {
int unused;
};
#include "gpio_object.h"

View File

@ -0,0 +1,52 @@
/* Copyright (c) 2019 ARM Limited
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef __CTHUNK_H__
#define __CTHUNK_H__
/**
* Class for created a pointer with data bound to it
*
* @note Synchronization level: Not protected
*/
template<class T>
class CThunk {
public:
typedef void (T::*CCallbackSimple)(void);
typedef void (T::*CCallback)(void *context);
CThunk()
{}
CThunk(T *instance)
{}
CThunk(T &instance)
{}
void callback(CCallback callback)
{}
void callback(CCallbackSimple callback)
{
}
uint32_t entry(void)
{
return 0;
}
};
#endif/*__CTHUNK_H__*/

View File

@ -24,7 +24,7 @@
extern void mock_system_reset();
MBED_NORETURN static inline void system_reset(void)
static inline void system_reset(void)
{
mock_system_reset();
}

View File

@ -1,5 +1,4 @@
/*
* Copyright (c) , Arm Limited and affiliates.
/* Copyright (c) 2019 ARM Limited
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
@ -15,4 +14,23 @@
* limitations under the License.
*/
typedef void *Semaphore;
#ifndef SEMAPHORE_H
#define SEMAPHORE_H
#include <stdint.h>
#include "cmsis_os2.h"
namespace rtos {
class Semaphore {
public:
Semaphore(int32_t count = 0) {};
Semaphore(int32_t count, uint16_t max_count) {};
void acquire() {};
bool try_acquire() { return false; };
bool try_acquire_for(uint32_t millisec) { return false; };
bool try_acquire_until(uint64_t millisec) { return false; };
osStatus release(void) {return 0;};
};
}
#endif

View File

@ -0,0 +1,101 @@
/*
* Copyright (c) 2019 ARM Limited
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#ifndef THREAD_H
#define THREAD_H
#include <stdint.h>
#include "cmsis_os.h"
namespace rtos {
class Thread {
public:
Thread(osPriority priority = osPriorityNormal,
uint32_t stack_size = OS_STACK_SIZE,
unsigned char *stack_mem = nullptr, const char *name = nullptr)
{
}
Thread(uint32_t tz_module, osPriority priority = osPriorityNormal,
uint32_t stack_size = OS_STACK_SIZE,
unsigned char *stack_mem = nullptr, const char *name = nullptr)
{
}
osStatus start(mbed::Callback<void()> task) {
return 0;
}
osStatus join() {return 0;};
osStatus terminate(){return 0;};
osStatus set_priority(osPriority priority){return 0;};
osPriority get_priority() const{return osPriorityNormal;};
uint32_t flags_set(uint32_t flags){return 0;};
/** State of the Thread */
enum State {
Inactive, /**< NOT USED */
Ready, /**< Ready to run */
Running, /**< Running */
WaitingDelay, /**< Waiting for a delay to occur */
WaitingJoin, /**< Waiting for thread to join. Only happens when using RTX directly. */
WaitingThreadFlag, /**< Waiting for a thread flag to be set */
WaitingEventFlag, /**< Waiting for a event flag to be set */
WaitingMutex, /**< Waiting for a mutex event to occur */
WaitingSemaphore, /**< Waiting for a semaphore event to occur */
WaitingMemoryPool, /**< Waiting for a memory pool */
WaitingMessageGet, /**< Waiting for message to arrive */
WaitingMessagePut, /**< Waiting for message to be send */
WaitingInterval, /**< NOT USED */
WaitingOr, /**< NOT USED */
WaitingAnd, /**< NOT USED */
WaitingMailbox, /**< NOT USED (Mail is implemented as MemoryPool and Queue) */
/* Not in sync with RTX below here */
Deleted, /**< The task has been deleted or not started */
};
State get_state() const {
return Ready;
};
uint32_t stack_size() const {
return 0;
};
uint32_t free_stack() const {
return 0;
};
uint32_t used_stack() const {
return 0;
};
uint32_t max_stack() const {
return 0;
};
const char *get_name() const {
return "";
};
osThreadId_t get_id() const {
return 0;
};
};
}
#endif

View File

@ -16,7 +16,7 @@
#include "DataFlashBlockDevice.h"
#include "mbed_atomic.h"
#include "rtos/ThisThread.h"
#include <inttypes.h>
using namespace mbed;

View File

@ -17,8 +17,11 @@
#ifndef MBED_DATAFLASH_BLOCK_DEVICE_H
#define MBED_DATAFLASH_BLOCK_DEVICE_H
#include <mbed.h>
#include "BlockDevice.h"
#include "platform/PlatformMutex.h"
#include "PinNames.h"
#include "features/storage/blockdevice/BlockDevice.h"
#include "drivers/SPI.h"
#include "drivers/DigitalOut.h"
/** BlockDevice for DataFlash flash devices

View File

@ -20,7 +20,7 @@
#if DEVICE_FLASH
#include "FlashIAP.h"
#include "BlockDevice.h"
#include "features/storage/blockdevice/BlockDevice.h"
#include "platform/mbed_toolchain.h"
/** BlockDevice using the FlashIAP API

View File

@ -16,8 +16,8 @@
#ifndef MBED_I2CEEPROM_BLOCK_DEVICE_H
#define MBED_I2CEEPROM_BLOCK_DEVICE_H
#include "BlockDevice.h"
#include "I2C.h"
#include "features/storage/blockdevice/BlockDevice.h"
#include "drivers/I2C.h"
/** BlockDevice for I2C based flash device such as
* Microchip's 24LC or ATMEL's AT24C ranges

View File

@ -119,11 +119,11 @@ QSPIFBlockDevice::QSPIFBlockDevice(PinName io0, PinName io1, PinName io2, PinNam
_unique_device_status = add_new_csel_instance(csel);
if (_unique_device_status == 0) {
tr_debug("Adding a new QSPIFBlockDevice csel: %d\n", (int)csel);
tr_debug("Adding a new QSPIFBlockDevice csel: %d", (int)csel);
} else if (_unique_device_status == -1) {
tr_error("QSPIFBlockDevice with the same csel(%d) already exists\n", (int)csel);
tr_error("QSPIFBlockDevice with the same csel(%d) already exists", (int)csel);
} else {
tr_error("Too many different QSPIFBlockDevice devices - max allowed: %d\n", QSPIF_MAX_ACTIVE_FLASH_DEVICES);
tr_error("Too many different QSPIFBlockDevice devices - max allowed: %d", QSPIF_MAX_ACTIVE_FLASH_DEVICES);
}
}
@ -199,7 +199,7 @@ int QSPIFBlockDevice::init()
goto exit_point;
}
tr_debug("Vendor device ID = 0x%x 0x%x 0x%x 0x%x \n", vendor_device_ids[0],
tr_debug("Vendor device ID = 0x%x 0x%x 0x%x 0x%x", vendor_device_ids[0],
vendor_device_ids[1], vendor_device_ids[2], vendor_device_ids[3]);
switch (vendor_device_ids[0]) {
case 0xbf:

View File

@ -16,8 +16,8 @@
#ifndef MBED_QSPIF_BLOCK_DEVICE_H
#define MBED_QSPIF_BLOCK_DEVICE_H
#include "QSPI.h"
#include "BlockDevice.h"
#include "drivers/QSPI.h"
#include "features/storage/blockdevice/BlockDevice.h"
/** Enum qspif standard error codes
*

View File

@ -16,9 +16,9 @@
#ifndef MBED_RSPIF_BLOCK_DEVICE_H
#define MBED_RSPIF_BLOCK_DEVICE_H
#include "SPI.h"
#include "DigitalOut.h"
#include "BlockDevice.h"
#include "drivers/SPI.h"
#include "drivers/DigitalOut.h"
#include "features/storage/blockdevice/BlockDevice.h"
/** Reduced BlockDevice for SPI based flash devices
* *Should only be used by Boot Loader*

View File

@ -20,7 +20,7 @@
/* If the target has no SPI support, then SD Card is not supported. */
#if DEVICE_SPI
#include "BlockDevice.h"
#include "features/storage/blockdevice/BlockDevice.h"
#include "drivers/SPI.h"
#include "drivers/Timer.h"
#include "drivers/MbedCRC.h"

View File

@ -22,7 +22,6 @@
#include <inttypes.h>
#include "mbed_trace.h"
#include "mbed_debug.h"
#define TRACE_GROUP "SPIF"
using namespace mbed;
@ -158,7 +157,7 @@ int SPIFBlockDevice::init()
status = SPIF_BD_ERROR_DEVICE_ERROR;
goto exit_point;
} else {
debug_if(MBED_CONF_SPIF_DRIVER_DEBUG, "DEBUG: Initialize flash memory OK\n");
tr_debug("Initialize flash memory OK");
}
/* Read Manufacturer ID (1byte), and Device ID (2bytes)*/
@ -207,7 +206,7 @@ int SPIFBlockDevice::init()
_region_high_boundary[0] = _device_size_bytes - 1;
if ((sector_map_table_addr != 0) && (0 != sector_map_table_size)) {
debug_if(MBED_CONF_SPIF_DRIVER_DEBUG, "DEBUG: init - Parsing Sector Map Table - addr: 0x%" PRIx32 "h, Size: %d", sector_map_table_addr,
tr_debug("init - Parsing Sector Map Table - addr: 0x%" PRIx32 "h, Size: %d", sector_map_table_addr,
sector_map_table_size);
if (0 != _sfdp_parse_sector_map_table(sector_map_table_addr, sector_map_table_size)) {
tr_error("init - Parse Sector Map Table Failed");
@ -272,7 +271,7 @@ int SPIFBlockDevice::read(void *buffer, bd_addr_t addr, bd_size_t size)
}
int status = SPIF_BD_ERROR_OK;
debug_if(MBED_CONF_SPIF_DRIVER_DEBUG, "DEBUG Read - Inst: 0x%xh", _read_instruction);
tr_debug("Read - Inst: 0x%xh", _read_instruction);
_mutex->lock();
// Set Dummy Cycles for Specific Read Command Mode
@ -298,7 +297,7 @@ int SPIFBlockDevice::program(const void *buffer, bd_addr_t addr, bd_size_t size)
uint32_t offset = 0;
uint32_t chunk = 0;
debug_if(MBED_CONF_SPIF_DRIVER_DEBUG, "DEBUG: program - Buff: 0x%" PRIx32 "h, addr: %llu, size: %llu", (uint32_t)buffer, addr, size);
tr_debug("program - Buff: 0x%" PRIx32 "h, addr: %llu, size: %llu", (uint32_t)buffer, addr, size);
while (size > 0) {
@ -361,7 +360,7 @@ int SPIFBlockDevice::erase(bd_addr_t addr, bd_size_t in_size)
// Erase Types of selected region
uint8_t bitfield = _region_erase_types_bitfield[region];
debug_if(MBED_CONF_SPIF_DRIVER_DEBUG, "DEBUG: erase - addr: %llu, in_size: %llu", addr, in_size);
tr_debug("erase - addr: %llu, in_size: %llu", addr, in_size);
if ((addr + in_size) > _device_size_bytes) {
tr_error("erase exceeds flash device size");
@ -383,9 +382,9 @@ int SPIFBlockDevice::erase(bd_addr_t addr, bd_size_t in_size)
offset = addr % _erase_type_size_arr[type];
chunk = ((offset + size) < _erase_type_size_arr[type]) ? size : (_erase_type_size_arr[type] - offset);
debug_if(MBED_CONF_SPIF_DRIVER_DEBUG, "DEBUG: erase - addr: %llu, size:%d, Inst: 0x%xh, chunk: %" PRIu32 " , ",
tr_debug("erase - addr: %llu, size:%d, Inst: 0x%xh, chunk: %" PRIu32 " , ",
addr, size, cur_erase_inst, chunk);
debug_if(MBED_CONF_SPIF_DRIVER_DEBUG, "DEBUG: erase - Region: %d, Type:%d",
tr_debug("erase - Region: %d, Type:%d",
region, type);
_mutex->lock();
@ -571,7 +570,7 @@ spif_bd_error SPIFBlockDevice::_spi_send_program_command(int prog_inst, const vo
spif_bd_error SPIFBlockDevice::_spi_send_erase_command(int erase_inst, bd_addr_t addr, bd_size_t size)
{
debug_if(MBED_CONF_SPIF_DRIVER_DEBUG, "DEBUG: Erase Inst: 0x%xh, addr: %llu, size: %llu", erase_inst, addr, size);
tr_debug("Erase Inst: 0x%xh, addr: %llu, size: %llu", erase_inst, addr, size);
addr = (((int)addr) & 0xFFFFF000);
_spi_send_general_command(erase_inst, addr, NULL, 0, NULL, 0);
return SPIF_BD_ERROR_OK;
@ -745,12 +744,12 @@ int SPIFBlockDevice::_sfdp_parse_sfdp_headers(uint32_t &basic_table_addr, size_t
tr_error("init - _verify SFDP signature and version Failed");
return -1;
} else {
debug_if(MBED_CONF_SPIF_DRIVER_DEBUG, "DEBUG: init - verified SFDP Signature and version Successfully");
tr_debug("init - verified SFDP Signature and version Successfully");
}
// Discover Number of Parameter Headers
int number_of_param_headers = (int)(sfdp_header[6]) + 1;
debug_if(MBED_CONF_SPIF_DRIVER_DEBUG, "DEBUG: number of Param Headers: %d", number_of_param_headers);
tr_debug("number of Param Headers: %d", number_of_param_headers);
addr += SPIF_SFDP_HEADER_SIZE;
data_length = SPIF_PARAM_HEADER_SIZE;
@ -773,14 +772,14 @@ int SPIFBlockDevice::_sfdp_parse_sfdp_headers(uint32_t &basic_table_addr, size_t
if ((param_header[0] == 0) && (param_header[7] == 0xFF)) {
// Found Basic Params Table: LSB=0x00, MSB=0xFF
debug_if(MBED_CONF_SPIF_DRIVER_DEBUG, "DEBUG: Found Basic Param Table at Table: %d", i_ind + 1);
tr_debug("Found Basic Param Table at Table: %d", i_ind + 1);
basic_table_addr = ((param_header[6] << 16) | (param_header[5] << 8) | (param_header[4]));
// Supporting up to 64 Bytes Table (16 DWORDS)
basic_table_size = ((param_header[3] * 4) < SFDP_DEFAULT_BASIC_PARAMS_TABLE_SIZE_BYTES) ? (param_header[3] * 4) : 64;
} else if ((param_header[0] == 81) && (param_header[7] == 0xFF)) {
// Found Sector Map Table: LSB=0x81, MSB=0xFF
debug_if(MBED_CONF_SPIF_DRIVER_DEBUG, "DEBUG: Found Sector Map Table at Table: %d", i_ind + 1);
tr_debug("Found Sector Map Table at Table: %d", i_ind + 1);
sector_map_table_addr = ((param_header[6] << 16) | (param_header[5] << 8) | (param_header[4]));
sector_map_table_size = param_header[3] * 4;
@ -799,9 +798,9 @@ unsigned int SPIFBlockDevice::_sfdp_detect_page_size(uint8_t *basic_param_table_
// Page Size is specified by 4 Bits (N), calculated by 2^N
int page_to_power_size = ((int)basic_param_table_ptr[SPIF_BASIC_PARAM_TABLE_PAGE_SIZE_BYTE]) >> 4;
page_size = local_math_power(2, page_to_power_size);
debug_if(MBED_CONF_SPIF_DRIVER_DEBUG, "DEBUG: Detected Page Size: %d", page_size);
tr_debug("Detected Page Size: %d", page_size);
} else {
debug_if(MBED_CONF_SPIF_DRIVER_DEBUG, "DEBUG: Using Default Page Size: %d", page_size);
tr_debug("Using Default Page Size: %d", page_size);
}
return page_size;
}
@ -823,7 +822,7 @@ int SPIFBlockDevice::_sfdp_detect_erase_types_inst_and_size(uint8_t *basic_param
erase_type_inst_arr[i_ind] = 0xff; //0xFF default for unsupported type
erase_type_size_arr[i_ind] = local_math_power(2,
basic_param_table_ptr[SPIF_BASIC_PARAM_ERASE_TYPE_1_SIZE_BYTE + 2 * i_ind]); // Size given as 2^N
debug_if(MBED_CONF_SPIF_DRIVER_DEBUG, "DEBUG: Erase Type(A) %d - Inst: 0x%xh, Size: %d", (i_ind + 1), erase_type_inst_arr[i_ind],
tr_debug("Erase Type(A) %d - Inst: 0x%xh, Size: %d", (i_ind + 1), erase_type_inst_arr[i_ind],
erase_type_size_arr[i_ind]);
if (erase_type_size_arr[i_ind] > 1) {
// if size==1 type is not supported
@ -846,8 +845,8 @@ int SPIFBlockDevice::_sfdp_detect_erase_types_inst_and_size(uint8_t *basic_param
}
_region_erase_types_bitfield[0] |= bitfield; // If there's no region map, set region "0" types bitfield as defualt;
}
debug_if(MBED_CONF_SPIF_DRIVER_DEBUG, "INFO: Erase Type %d - Inst: 0x%xh, Size: %d", (i_ind + 1),
erase_type_inst_arr[i_ind], erase_type_size_arr[i_ind]);
tr_info("Erase Type %d - Inst: 0x%xh, Size: %d", (i_ind + 1),
erase_type_inst_arr[i_ind], erase_type_size_arr[i_ind]);
bitfield = bitfield << 1;
}
}
@ -864,40 +863,8 @@ int SPIFBlockDevice::_sfdp_detect_best_bus_read_mode(uint8_t *basic_param_table_
do {
// TBD - SPIF Dual Read Modes Require SPI driver support
/*
uint8_t examined_byte;
if (basic_param_table_size > SPIF_BASIC_PARAM_TABLE_QPI_READ_SUPPORT_BYTE) {
examined_byte = basic_param_table_ptr[SPIF_BASIC_PARAM_TABLE_QPI_READ_SUPPORT_BYTE];
if (examined_byte & 0x01) {
// Fast Read 2-2-2 Supported
read_inst = basic_param_table_ptr[SPIF_BASIC_PARAM_TABLE_222_READ_INST_BYTE];
_read_dummy_and_mode_cycles = (basic_param_table_ptr[SPIF_BASIC_PARAM_TABLE_222_READ_INST_BYTE - 1] >> 5)
+ (basic_param_table_ptr[SPIF_BASIC_PARAM_TABLE_222_READ_INST_BYTE - 1] & 0x1F);
debug_if(MBED_CONF_SPIF_DRIVER_DEBUG, "\nDEBUG: Read Bus Mode set to 2-2-2, Instruction: 0x%xh", read_inst);
break;
}
}
examined_byte = basic_param_table_ptr[SPIF_BASIC_PARAM_TABLE_FAST_READ_SUPPORT_BYTE];
if (examined_byte & 0x20) {
// Fast Read 1-2-2 Supported
read_inst = basic_param_table_ptr[SPIF_BASIC_PARAM_TABLE_122_READ_INST_BYTE];
_read_dummy_and_mode_cycles = (basic_param_table_ptr[SPIF_BASIC_PARAM_TABLE_122_READ_INST_BYTE - 1] >> 5)
+ (basic_param_table_ptr[SPIF_BASIC_PARAM_TABLE_122_READ_INST_BYTE - 1] & 0x1F);
debug_if(MBED_CONF_SPIF_DRIVER_DEBUG, "\nDEBUG: Read Bus Mode set to 1-2-2, Instruction: 0x%xh", read_inst);
break;
}
if (examined_byte & 0x01) {
// Fast Read 1-1-2 Supported
read_inst = basic_param_table_ptr[SPIF_BASIC_PARAM_TABLE_112_READ_INST_BYTE];
_read_dummy_and_mode_cycles = (basic_param_table_ptr[SPIF_BASIC_PARAM_TABLE_112_READ_INST_BYTE - 1] >> 5)
+ (basic_param_table_ptr[SPIF_BASIC_PARAM_TABLE_112_READ_INST_BYTE - 1] & 0x1F);
debug_if(MBED_CONF_SPIF_DRIVER_DEBUG, "\nDEBUG: Read Bus Mode set to 1-1-2, Instruction: 0x%xh", _read_instruction);
break;
}
*/
_read_dummy_and_mode_cycles = 0;
debug_if(MBED_CONF_SPIF_DRIVER_DEBUG, "\nDEBUG: Read Bus Mode set to 1-1-1, Instruction: 0x%xh", read_inst);
tr_debug("Read Bus Mode set to 1-1-1, Instruction: 0x%xh", read_inst);
} while (false);
return 0;
@ -908,13 +875,13 @@ int SPIFBlockDevice::_reset_flash_mem()
// Perform Soft Reset of the Device prior to initialization
int status = 0;
char status_value[2] = {0};
debug_if(MBED_CONF_SPIF_DRIVER_DEBUG, "INFO: _reset_flash_mem:\n");
tr_info("_reset_flash_mem:");
//Read the Status Register from device
if (SPIF_BD_ERROR_OK == _spi_send_general_command(SPIF_RDSR, SPI_NO_ADDRESS_COMMAND, NULL, 0, status_value, 1)) {
// store received values in status_value
debug_if(MBED_CONF_SPIF_DRIVER_DEBUG, "DEBUG: Reading Status Register Success: value = 0x%x\n", (int)status_value[0]);
tr_debug("Reading Status Register Success: value = 0x%x", (int)status_value[0]);
} else {
debug_if(MBED_CONF_SPIF_DRIVER_DEBUG, "ERROR: Reading Status Register failed\n");
tr_error("Reading Status Register failed");
status = -1;
}
@ -922,7 +889,7 @@ int SPIFBlockDevice::_reset_flash_mem()
//Send Reset Enable
if (SPIF_BD_ERROR_OK == _spi_send_general_command(SPIF_RSTEN, SPI_NO_ADDRESS_COMMAND, NULL, 0, NULL, 0)) {
// store received values in status_value
debug_if(MBED_CONF_SPIF_DRIVER_DEBUG, "DEBUG: Sending RSTEN Success\n");
tr_debug("Sending RSTEN Success");
} else {
tr_error("Sending RSTEN failed");
status = -1;
@ -932,7 +899,7 @@ int SPIFBlockDevice::_reset_flash_mem()
//Send Reset
if (SPIF_BD_ERROR_OK == _spi_send_general_command(SPIF_RST, SPI_NO_ADDRESS_COMMAND, NULL, 0, NULL, 0)) {
// store received values in status_value
debug_if(MBED_CONF_SPIF_DRIVER_DEBUG, "DEBUG: Sending RST Success\n");
tr_debug("Sending RST Success");
} else {
tr_error("Sending RST failed");
status = -1;

View File

@ -17,9 +17,9 @@
#define MBED_SPIF_BLOCK_DEVICE_H
#include "platform/SingletonPtr.h"
#include "SPI.h"
#include "DigitalOut.h"
#include "BlockDevice.h"
#include "drivers/SPI.h"
#include "drivers/DigitalOut.h"
#include "features/storage/blockdevice/BlockDevice.h"
/** Enum spif standard error codes
*

View File

@ -20,18 +20,16 @@
#include "mbedtls/config.h"
#include "mbedtls/cmac.h"
#include "mbedtls/platform.h"
#include "KVStore.h"
#include "TDBStore.h"
#include "KVMap.h"
#include "kv_config.h"
#include "features/storage/kvstore/include/KVStore.h"
#include "features/storage/kvstore/tdbstore/TDBStore.h"
#include "features/storage/kvstore/kv_map/KVMap.h"
#include "features/storage/kvstore/conf/kv_config.h"
#include "mbed_wait_api.h"
#include "stdlib.h"
#include <stdlib.h>
#include "platform/mbed_error.h"
#include <string.h>
#include "entropy.h"
#include "platform_mbed.h"
#include "mbed_trace.h"
#include "ssl_internal.h"
#define TRACE_GROUP "DEVKEY"
@ -272,14 +270,12 @@ int DeviceKey::generate_key_by_random(uint32_t *output, size_t size)
}
#if defined(DEVICE_TRNG) || defined(MBEDTLS_ENTROPY_NV_SEED) || defined(MBEDTLS_ENTROPY_HARDWARE_ALT)
uint32_t test_buff[DEVICE_KEY_32BYTE / sizeof(int)];
mbedtls_entropy_context *entropy = new mbedtls_entropy_context;
mbedtls_entropy_init(entropy);
memset(output, 0, size);
memset(test_buff, 0, size);
ret = mbedtls_entropy_func(entropy, (unsigned char *)output, size);
if (ret != MBED_SUCCESS || mbedtls_ssl_safer_memcmp(test_buff, (unsigned char *)output, size) == 0) {
if (ret != MBED_SUCCESS) {
ret = DEVICEKEY_GENERATE_RANDOM_ERROR;
} else {
ret = DEVICEKEY_SUCCESS;

View File

@ -117,11 +117,12 @@ bd_size_t HeapBlockDevice::size() const
int HeapBlockDevice::read(void *b, bd_addr_t addr, bd_size_t size)
{
MBED_ASSERT(_blocks != NULL);
MBED_ASSERT(is_valid_read(addr, size));
if (!_is_initialized) {
return BD_ERROR_DEVICE_ERROR;
}
if (!is_valid_read(addr, size)) {
return BD_ERROR_DEVICE_ERROR;
}
uint8_t *buffer = static_cast<uint8_t *>(b);
@ -145,11 +146,12 @@ int HeapBlockDevice::read(void *b, bd_addr_t addr, bd_size_t size)
int HeapBlockDevice::program(const void *b, bd_addr_t addr, bd_size_t size)
{
MBED_ASSERT(_blocks != NULL);
MBED_ASSERT(is_valid_program(addr, size));
if (!_is_initialized) {
return BD_ERROR_DEVICE_ERROR;
}
if (!is_valid_program(addr, size)) {
return BD_ERROR_DEVICE_ERROR;
}
const uint8_t *buffer = static_cast<const uint8_t *>(b);
@ -176,10 +178,12 @@ int HeapBlockDevice::program(const void *b, bd_addr_t addr, bd_size_t size)
int HeapBlockDevice::erase(bd_addr_t addr, bd_size_t size)
{
MBED_ASSERT(_blocks != NULL);
MBED_ASSERT(is_valid_erase(addr, size));
// TODO assert on programming unerased blocks
if (!_is_initialized) {
return BD_ERROR_DEVICE_ERROR;
}
if (!is_valid_erase(addr, size)) {
return BD_ERROR_DEVICE_ERROR;
}
return 0;
}

View File

@ -17,6 +17,7 @@
#include "SlicingBlockDevice.h"
#include "platform/mbed_assert.h"
#include "stddef.h"
#include <stdio.h>
namespace mbed {
@ -58,7 +59,9 @@ int SlicingBlockDevice::init()
}
// Check that block addresses are valid
MBED_ASSERT(is_valid_erase(_start, _stop - _start));
if (!is_valid_erase(0, _stop - _start)) {
return BD_ERROR_DEVICE_ERROR;
}
return 0;
}
@ -75,44 +78,41 @@ int SlicingBlockDevice::sync()
int SlicingBlockDevice::read(void *b, bd_addr_t addr, bd_size_t size)
{
MBED_ASSERT(is_valid_read(addr + _start, size));
if (!is_valid_read(addr, size)) {
return BD_ERROR_DEVICE_ERROR;
}
return _bd->read(b, addr + _start, size);
}
int SlicingBlockDevice::program(const void *b, bd_addr_t addr, bd_size_t size)
{
MBED_ASSERT(is_valid_program(addr + _start, size));
if (!is_valid_program(addr, size)) {
return BD_ERROR_DEVICE_ERROR;
}
return _bd->program(b, addr + _start, size);
}
int SlicingBlockDevice::erase(bd_addr_t addr, bd_size_t size)
{
MBED_ASSERT(is_valid_erase(addr + _start, size));
if (!is_valid_erase(addr, size)) {
return BD_ERROR_DEVICE_ERROR;
}
return _bd->erase(addr + _start, size);
}
bool SlicingBlockDevice::is_valid_read(bd_addr_t addr, bd_size_t size) const
{
return (
addr % get_read_size() == 0 &&
size % get_read_size() == 0 &&
addr + size <= (this->size() + _start));
return _bd->is_valid_read(_start + addr, size) && _start + addr + size <= _stop;
}
bool SlicingBlockDevice::is_valid_program(bd_addr_t addr, bd_size_t size) const
{
return (
addr % get_program_size() == 0 &&
size % get_program_size() == 0 &&
addr + size <= (this->size() + _start));
return _bd->is_valid_program(_start + addr, size) && _start + addr + size <= _stop;
}
bool SlicingBlockDevice::is_valid_erase(bd_addr_t addr, bd_size_t size) const
{
return (
addr % get_erase_size(addr) == 0 &&
(addr + size) % get_erase_size(addr + size - 1) == 0 &&
addr + size <= (this->size() + _start));
return _bd->is_valid_erase(_start + addr, size) && _start + addr + size <= _stop;
}
bd_size_t SlicingBlockDevice::get_read_size() const
@ -127,7 +127,7 @@ bd_size_t SlicingBlockDevice::get_program_size() const
bd_size_t SlicingBlockDevice::get_erase_size() const
{
return _bd->get_erase_size();
return _bd->get_erase_size(_start);
}
bd_size_t SlicingBlockDevice::get_erase_size(bd_addr_t addr) const

View File

@ -17,7 +17,7 @@
#ifndef DIR_H
#define DIR_H
#include "filesystem/FileSystem.h"
#include "features/storage/filesystem/FileSystem.h"
#include "platform/DirHandle.h"
namespace mbed {

View File

@ -17,7 +17,7 @@
#ifndef FILE_H
#define FILE_H
#include "filesystem/FileSystem.h"
#include "features/storage/filesystem/FileSystem.h"
#include "platform/FileHandle.h"
namespace mbed {

View File

@ -14,9 +14,9 @@
* limitations under the License.
*/
#include "filesystem/Dir.h"
#include "filesystem/File.h"
#include "filesystem/FileSystem.h"
#include "features/storage/filesystem/Dir.h"
#include "features/storage/filesystem/File.h"
#include "features/storage/filesystem/FileSystem.h"
#include <errno.h>
namespace mbed {

View File

@ -23,7 +23,7 @@
#include "platform/FileHandle.h"
#include "platform/DirHandle.h"
#include "platform/FileSystemLike.h"
#include "BlockDevice.h"
#include "features/storage/blockdevice/BlockDevice.h"
namespace mbed {
/** \addtogroup file system */

View File

@ -19,11 +19,12 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#include "diskio.h"
#include "ffconf.h"
#include "features/storage/filesystem/fat/ChaN/diskio.h"
#include "features/storage/filesystem/fat/ChaN/ffconf.h"
#include "features/storage/filesystem/fat/ChaN/ff.h"
#include "platform/mbed_debug.h"
#include "platform/mbed_critical.h"
#include "filesystem/mbed_filesystem.h"
#include "features/storage/filesystem/mbed_filesystem.h"
#include "FATFileSystem.h"
#include <errno.h>

View File

@ -26,12 +26,12 @@
#ifndef MBED_FATFILESYSTEM_H
#define MBED_FATFILESYSTEM_H
#include "FileSystem.h"
#include "BlockDevice.h"
#include "features/storage/filesystem/FileSystem.h"
#include "features/storage/blockdevice/BlockDevice.h"
#include "FileHandle.h"
#include "ff.h"
#include <stdint.h>
#include "PlatformMutex.h"
#include "features/storage/filesystem/fat/ChaN/ff.h"
namespace mbed {

View File

@ -13,11 +13,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "filesystem/mbed_filesystem.h"
#include "features/storage/filesystem/mbed_filesystem.h"
#include "LittleFileSystem.h"
#include "errno.h"
#include "lfs.h"
#include "lfs_util.h"
#include "features/storage/filesystem/littlefs/littlefs/lfs.h"
#include "features/storage/filesystem/littlefs/littlefs/lfs_util.h"
#include "MbedCRC.h"
namespace mbed {

View File

@ -20,10 +20,10 @@
#ifndef MBED_LFSFILESYSTEM_H
#define MBED_LFSFILESYSTEM_H
#include "FileSystem.h"
#include "BlockDevice.h"
#include "PlatformMutex.h"
#include "lfs.h"
#include "features/storage/filesystem/FileSystem.h"
#include "features/storage/blockdevice/BlockDevice.h"
#include "platform/PlatformMutex.h"
#include "features/storage/filesystem/littlefs/littlefs/lfs.h"
namespace mbed {

View File

@ -23,16 +23,15 @@
#include "platform/platform.h"
// FileSystem classes
#include "filesystem/FileSystem.h"
#include "filesystem/File.h"
#include "filesystem/Dir.h"
#include "features/storage/filesystem/FileSystem.h"
#include "features/storage/filesystem/File.h"
#include "features/storage/filesystem/Dir.h"
// BlockDevice classes
#include "BlockDevice.h"
#include "BlockDevice.h"
#include "ChainingBlockDevice.h"
#include "SlicingBlockDevice.h"
#include "HeapBlockDevice.h"
#include "features/storage/blockdevice/BlockDevice.h"
#include "features/storage/blockdevice/ChainingBlockDevice.h"
#include "features/storage/blockdevice/SlicingBlockDevice.h"
#include "features/storage/blockdevice/HeapBlockDevice.h"
/** @}*/
#endif

View File

@ -15,40 +15,40 @@
*/
#include "kv_config.h"
#include "KVStore.h"
#include "KVMap.h"
#include "BlockDevice.h"
#include "FileSystem.h"
#include "FileSystemStore.h"
#include "SlicingBlockDevice.h"
#include "FATFileSystem.h"
#include "LittleFileSystem.h"
#include "TDBStore.h"
#include "features/storage/kvstore/include/KVStore.h"
#include "features/storage/kvstore/kv_map/KVMap.h"
#include "features/storage/blockdevice/BlockDevice.h"
#include "features/storage/filesystem/FileSystem.h"
#include "features/storage/kvstore/filesystemstore/FileSystemStore.h"
#include "features/storage/blockdevice/SlicingBlockDevice.h"
#include "features/storage/filesystem/fat/FATFileSystem.h"
#include "features/storage/filesystem/littlefs/LittleFileSystem.h"
#include "features/storage/kvstore/tdbstore/TDBStore.h"
#include "mbed_error.h"
#include "FlashIAP.h"
#include "FlashSimBlockDevice.h"
#include "drivers/FlashIAP.h"
#include "features/storage/blockdevice/FlashSimBlockDevice.h"
#include "mbed_trace.h"
#include "SecureStore.h"
#include "features/storage/kvstore/securestore/SecureStore.h"
#define TRACE_GROUP "KVCFG"
#if COMPONENT_FLASHIAP
#include "FlashIAPBlockDevice.h"
#include "components/storage/blockdevice/COMPONENT_FLASHIAP/FlashIAPBlockDevice.h"
#endif
#if COMPONENT_QSPIF
#include "QSPIFBlockDevice.h"
#include "components/storage/blockdevice/COMPONENT_QSPIF/QSPIFBlockDevice.h"
#endif
#if COMPONENT_SPIF
#include "SPIFBlockDevice.h"
#include "components/storage/blockdevice/COMPONENT_SPIF/SPIFBlockDevice.h"
#endif
#if COMPONENT_DATAFLASH
#include "DataFlashBlockDevice.h"
#include "components/storage/blockdevice/COMPONENT_DATAFLASH/DataFlashBlockDevice.h"
#endif
#if COMPONENT_SD
#include "SDBlockDevice.h"
#include "components/storage/blockdevice/COMPONENT_SD/SDBlockDevice.h"
#endif
/**

View File

@ -17,6 +17,7 @@
// ----------------------------------------------------------- Includes -----------------------------------------------------------
#if DEVICE_FLASH
#include "DirectAccessDevicekey.h"
#include "drivers/FlashIAP.h"
#include <string.h>
#include <stdio.h>
#include "mbed_error.h"

View File

@ -17,10 +17,10 @@
*/
#include "FileSystemStore.h"
#include "kv_config.h"
#include "Dir.h"
#include "File.h"
#include "BlockDevice.h"
#include "features/storage/kvstore/conf/kv_config.h"
#include "features/storage/filesystem/Dir.h"
#include "features/storage/filesystem/File.h"
#include "features/storage/blockdevice/BlockDevice.h"
#include "mbed_error.h"
#include <string.h>
#include <stdio.h>

View File

@ -18,8 +18,8 @@
#ifndef MBED_FILE_SYSTEM_STORE_H
#define MBED_FILE_SYSTEM_STORE_H
#include "KVStore.h"
#include "FileSystem.h"
#include "features/storage/kvstore/include/KVStore.h"
#include "features/storage/filesystem/FileSystem.h"
namespace mbed {

View File

@ -15,9 +15,9 @@
*/
#include "kvstore_global_api.h"
#include "kv_config.h"
#include "KVMap.h"
#include "KVStore.h"
#include "features/storage/kvstore/conf/kv_config.h"
#include "features/storage/kvstore/kv_map/KVMap.h"
#include "features/storage/kvstore/include/KVStore.h"
#include "mbed_error.h"
using namespace mbed;

View File

@ -14,9 +14,9 @@
* limitations under the License.
*/
#include "KVStore.h"
#include "KVMap.h"
#include "kv_config.h"
#include "features/storage/kvstore/include/KVStore.h"
#include "features/storage/kvstore/kv_map/KVMap.h"
#include "features/storage/kvstore/conf/kv_config.h"
#include <stdlib.h>
#include "string.h"
#include "mbed_error.h"

View File

@ -16,11 +16,11 @@
#ifndef _KV_MAP
#define _KV_MAP
#include "KVStore.h"
#include "features/storage/kvstore/include/KVStore.h"
#include "platform/PlatformMutex.h"
#include "platform/SingletonPtr.h"
#include "BlockDevice.h"
#include "FileSystem.h"
#include "features/storage/blockdevice/BlockDevice.h"
#include "features/storage/filesystem/FileSystem.h"
namespace mbed {

View File

@ -23,7 +23,7 @@
#include MBEDTLS_CONFIG_FILE
#endif
#include "DeviceKey.h"
#include "features/device_key/source/DeviceKey.h"
#define SECURESTORE_ENABLED 1

View File

@ -26,7 +26,7 @@
#include "MbedCRC.h"
//Bypass the check of NVStore co existance if compiled for TARGET_TFM
#if !(BYPASS_NVSTORE_CHECK)
#include "SystemStorage.h"
#include "features/storage/system_storage/SystemStorage.h"
#endif
using namespace mbed;
@ -251,7 +251,7 @@ int TDBStore::read_record(uint8_t area, uint32_t offset, char *key,
return MBED_ERROR_INVALID_SIZE;
}
actual_data_size = std::min(data_buf_size, data_size - data_offset);
actual_data_size = std::min((size_t)data_buf_size, (size_t)data_size - data_offset);
if (copy_data && actual_data_size && !data_buf) {
return MBED_ERROR_INVALID_ARGUMENT;
@ -295,7 +295,7 @@ int TDBStore::read_record(uint8_t area, uint32_t offset, char *key,
// 3. After actual part is finished - read to work buffer
// 4. Copy data flag not set - read to work buffer
if (curr_data_offset < data_offset) {
chunk_size = std::min(work_buf_size, data_offset - curr_data_offset);
chunk_size = std::min((size_t)work_buf_size, (size_t)(data_offset - curr_data_offset));
dest_buf = _work_buf;
} else if (copy_data && (curr_data_offset < data_offset + actual_data_size)) {
chunk_size = actual_data_size;

View File

@ -19,9 +19,9 @@
#include <stdint.h>
#include <stdio.h>
#include "KVStore.h"
#include "BlockDevice.h"
#include "BufferedBlockDevice.h"
#include "features/storage/kvstore/include/KVStore.h"
#include "features/storage/blockdevice/BlockDevice.h"
#include "features/storage/blockdevice/BufferedBlockDevice.h"
#include "PlatformMutex.h"
namespace mbed {

View File

@ -14,35 +14,35 @@
* limitations under the License.
*/
#include "SystemStorage.h"
#include "BlockDevice.h"
#include "FileSystem.h"
#include "FATFileSystem.h"
#include "LittleFileSystem.h"
#include "features/storage/blockdevice/BlockDevice.h"
#include "features/storage/filesystem/FileSystem.h"
#include "features/storage/filesystem/fat/FATFileSystem.h"
#include "features/storage/filesystem/littlefs/LittleFileSystem.h"
#include "mbed_error.h"
#if COMPONENT_SPIF
#include "SPIFBlockDevice.h"
#include "components/storage/blockdevice/COMPONENT_SPIF/SPIFBlockDevice.h"
#endif
#if COMPONENT_RSPIF
#include "SPIFReducedBlockDevice.h"
#include "components/storage/blockdevice/COMPONENT_RSPIF/SPIFReducedBlockDevice.h"
#endif
#if COMPONENT_QSPIF
#include "QSPIFBlockDevice.h"
#include "components/storage/blockdevice/COMPONENT_QSPIF/QSPIFBlockDevice.h"
#endif
#if COMPONENT_DATAFLASH
#include "DataFlashBlockDevice.h"
#include "components/storage/blockdevice/COMPONENT_DATAFLASH/DataFlashBlockDevice.h"
#endif
#if COMPONENT_SD
#include "SDBlockDevice.h"
#include "components/storage/blockdevice/COMPONENT_SD/SDBlockDevice.h"
#endif
#if COMPONENT_FLASHIAP
#include "FlashIAPBlockDevice.h"
#include "components/storage/blockdevice/COMPONENT_FLASHIAP/FlashIAPBlockDevice.h"
#endif
using namespace mbed;

View File

@ -22,6 +22,7 @@
#include "PinNames.h"
#include <stdbool.h>
#include <stdint.h>
#ifdef __cplusplus
extern "C" {