Import Mbed OS hard-float snapshot
This commit is contained in:
105
storage/blockdevice/COMPONENT_FLASHIAP/COMMON/fslittle_debug.h
Normal file
105
storage/blockdevice/COMPONENT_FLASHIAP/COMMON/fslittle_debug.h
Normal file
@@ -0,0 +1,105 @@
|
||||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2016 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.
|
||||
*/
|
||||
|
||||
/** @file fslittle_debug.h
|
||||
*
|
||||
* component debug header file.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __FSLITTLE_DEBUG
|
||||
#define __FSLITTLE_DEBUG
|
||||
|
||||
#include <stdint.h>
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
/* Debug Support */
|
||||
|
||||
#define FSLITTLE_LOG_NONE 0
|
||||
#define FSLITTLE_LOG_ERR 1
|
||||
#define FSLITTLE_LOG_WARN 2
|
||||
#define FSLITTLE_LOG_NOTICE 3
|
||||
#define FSLITTLE_LOG_INFO 4
|
||||
#define FSLITTLE_LOG_DEBUG 5
|
||||
#define FSLITTLE_LOG_FENTRY 6
|
||||
|
||||
#define FSLITTLE_LOG(_fmt, ...) \
|
||||
do \
|
||||
{ \
|
||||
printf(_fmt, __VA_ARGS__); \
|
||||
}while(0);
|
||||
|
||||
#define noFSLITTLE_DEBUG
|
||||
#ifdef FSLITTLE_DEBUG
|
||||
|
||||
extern uint32_t fslittle_optDebug_g;
|
||||
extern uint32_t fslittle_optLogLevel_g;
|
||||
|
||||
|
||||
/* uncomment for asserts to work */
|
||||
/* #undef NDEBUG */
|
||||
// todo: port to mbedOSV3++ #include <core-util/assert.h>
|
||||
|
||||
#define FSLITTLE_INLINE
|
||||
// todo: port to mbedOSV3++ #define FSLITTLE_ASSERT CORE_UTIL_ASSERT
|
||||
#define FSLITTLE_ASSERT(...)
|
||||
|
||||
#define FSLITTLE_DBGLOG(_fmt, ...) \
|
||||
do \
|
||||
{ \
|
||||
if(fslittle_optDebug_g && (fslittle_optLogLevel_g >= FSLITTLE_LOG_DEBUG)) \
|
||||
{ \
|
||||
printf(_fmt, __VA_ARGS__); \
|
||||
} \
|
||||
}while(0);
|
||||
|
||||
|
||||
#define FSLITTLE_ERRLOG(_fmt, ...) \
|
||||
do \
|
||||
{ \
|
||||
if(fslittle_optDebug_g && (fslittle_optLogLevel_g >= FSLITTLE_LOG_ERR)) \
|
||||
{ \
|
||||
printf(_fmt, __VA_ARGS__); \
|
||||
} \
|
||||
}while(0);
|
||||
|
||||
|
||||
#define FSLITTLE_FENTRYLOG(_fmt, ...) \
|
||||
do \
|
||||
{ \
|
||||
if(fslittle_optDebug_g && (fslittle_optLogLevel_g >= FSLITTLE_LOG_FENTRY)) \
|
||||
{ \
|
||||
printf(_fmt, __VA_ARGS__); \
|
||||
} \
|
||||
}while(0);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#else
|
||||
#define FSLITTLE_ASSERT(_x) do { } while(0)
|
||||
#define FSLITTLE_INLINE inline
|
||||
#define FSLITTLE_DBGLOG(_fmt, ...) do { } while(0)
|
||||
#define FSLITTLE_ERRLOG(_fmt, ...) do { } while(0)
|
||||
#define FSLITTLE_FENTRYLOG(_fmt, ...) do { } while(0)
|
||||
#endif /* FSLITTLE_DEBUG */
|
||||
|
||||
|
||||
#endif /*__FSLITTLE_DEBUG*/
|
||||
117
storage/blockdevice/COMPONENT_FLASHIAP/COMMON/fslittle_test.c
Normal file
117
storage/blockdevice/COMPONENT_FLASHIAP/COMMON/fslittle_test.c
Normal file
@@ -0,0 +1,117 @@
|
||||
/* @file fslittle_test.c
|
||||
*
|
||||
* mbed Microcontroller Library
|
||||
* Copyright (c) 2006-2016 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.
|
||||
*
|
||||
* test support code implementation file.
|
||||
*/
|
||||
|
||||
#include "fslittle_debug.h"
|
||||
#include "fslittle_test.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
#include <inttypes.h>
|
||||
#include <ctype.h>
|
||||
|
||||
|
||||
#ifdef FSLITTLE_DEBUG
|
||||
uint32_t fslittle_optDebug_g = 1;
|
||||
uint32_t fslittle_optLogLevel_g = FSLITTLE_LOG_NONE; /*FSLITTLE_LOG_NONE|FSLITTLE_LOG_ERR|FSLITTLE_LOG_DEBUG|FSLITTLE_LOG_FENTRY; */
|
||||
#endif
|
||||
|
||||
/* ruler for measuring text strings */
|
||||
/* 1 1 1 1 1 1 1 1 1 1 2 2 2 */
|
||||
/* 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 */
|
||||
/* 1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890 */
|
||||
|
||||
const uint8_t fslittle_test_byte_data_table[FSLITTLE_TEST_BYTE_DATA_TABLE_SIZE] = {
|
||||
0x2d, 0xf3, 0x31, 0x4c, 0x11, 0x4f, 0xde, 0x0d, 0xbd, 0xbc, 0xa6, 0x78, 0x36, 0x5c, 0x1d, 0x28,
|
||||
0x5f, 0xa9, 0x10, 0x65, 0x54, 0x45, 0x21, 0x1a, 0x88, 0xfe, 0x76, 0x45, 0xb9, 0xac, 0x65, 0x9a,
|
||||
0x34, 0x9d, 0x73, 0x10, 0xb4, 0xa9, 0x2e, 0x90, 0x95, 0x68, 0xac, 0xfe, 0xc5, 0x2d, 0x15, 0x03,
|
||||
0x34, 0x70, 0xf1, 0x1d, 0x48, 0xa1, 0xa0, 0xed, 0x5c, 0x2f, 0xf5, 0x2b, 0xb9, 0x84, 0xbb, 0x45,
|
||||
0x32, 0xdd, 0xb1, 0x33, 0x95, 0x2a, 0xbc, 0x26, 0xf0, 0x89, 0xba, 0xf4, 0xbd, 0xf9, 0x5d, 0x2e,
|
||||
0x6e, 0x11, 0xc6, 0xa7, 0x78, 0xfc, 0xc9, 0x0e, 0x6b, 0x38, 0xba, 0x14, 0x1b, 0xab, 0x4c, 0x20,
|
||||
0x91, 0xe4, 0xb0, 0xf1, 0x2b, 0x14, 0x07, 0x6b, 0xb5, 0xcd, 0xe3, 0x49, 0x75, 0xac, 0xe8, 0x98,
|
||||
0xf1, 0x58, 0x8f, 0xd9, 0xc4, 0x8f, 0x00, 0x17, 0xb5, 0x06, 0x6a, 0x33, 0xbd, 0xa7, 0x40, 0x5a,
|
||||
0xbf, 0x49, 0xf7, 0x27, 0x1b, 0x4c, 0x3e, 0x6f, 0xe3, 0x08, 0x1f, 0xfd, 0xa6, 0xd4, 0xc7, 0x5f,
|
||||
0xa4, 0xa6, 0x82, 0xad, 0x19, 0xd5, 0x5c, 0xd8, 0x3a, 0x49, 0x85, 0xc9, 0x21, 0x83, 0xf6, 0xc6,
|
||||
0x84, 0xf9, 0x76, 0x89, 0xf3, 0x2d, 0x17, 0x50, 0x97, 0x38, 0x48, 0x9a, 0xe1, 0x82, 0xcd, 0xac,
|
||||
0xa8, 0x1d, 0xd7, 0x96, 0x5e, 0xb3, 0x08, 0xa8, 0x3a, 0xc7, 0x2b, 0x05, 0xaf, 0xdc, 0x16, 0xdf,
|
||||
0x48, 0x0f, 0x2a, 0x7e, 0x3a, 0x82, 0xd7, 0x80, 0xd6, 0x49, 0x27, 0x5d, 0xe3, 0x07, 0x62, 0xb3,
|
||||
0xc3, 0x6c, 0xba, 0xb2, 0xaa, 0x9f, 0xd9, 0x03, 0x0d, 0x27, 0xa8, 0xe0, 0xd6, 0xee, 0x79, 0x4b,
|
||||
0xd6, 0x97, 0x99, 0xb7, 0x11, 0xd6, 0x0d, 0x34, 0xae, 0x99, 0x4a, 0x93, 0x95, 0xd0, 0x5a, 0x34,
|
||||
0x19, 0xa2, 0x69, 0x57, 0xcf, 0x7c, 0x3d, 0x98, 0x88, 0x5d, 0x04, 0xf2, 0xd7, 0xac, 0xa5, 0x63
|
||||
};
|
||||
|
||||
|
||||
/* @brief test utility function to delete the file identified by filename
|
||||
*/
|
||||
int32_t fslittle_test_delete(const char *filename)
|
||||
{
|
||||
FSLITTLE_FENTRYLOG("%s:entered.\r\n", __func__);
|
||||
return remove(filename);
|
||||
}
|
||||
|
||||
|
||||
/* @brief test utility function to create a file
|
||||
*
|
||||
* @param filename name of the file including path
|
||||
* @param data data to store in file
|
||||
* @param len number of bytes of data present in the data buffer.
|
||||
*/
|
||||
int32_t fslittle_test_create(const char *filename, const char *data, size_t len)
|
||||
{
|
||||
int32_t ret = -1;
|
||||
FILE *fp = NULL;
|
||||
|
||||
FSLITTLE_FENTRYLOG("%s:entered (filename=%s, len=%d).\n", __func__, filename, (int) len);
|
||||
fp = fopen(filename, "w+");
|
||||
if (fp == NULL) {
|
||||
return ret;
|
||||
}
|
||||
ret = fwrite((const void *) data, len, 1, fp);
|
||||
if (ret < 0) {
|
||||
fclose(fp);
|
||||
return ret;
|
||||
}
|
||||
fclose(fp);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
/* @brief support function for generating a kv_name
|
||||
* @param name buffer to hold kv name
|
||||
* @param len length of kv name to generate
|
||||
*
|
||||
*/
|
||||
int32_t fslittle_test_filename_gen(char *name, const size_t len)
|
||||
{
|
||||
size_t i;
|
||||
uint32_t pos = 0;
|
||||
|
||||
const char *buf = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!$-_@";
|
||||
const int buf_len = strlen(buf);
|
||||
FSLITTLE_FENTRYLOG("%s:entered\n", __func__);
|
||||
for (i = 0; i < len; i++) {
|
||||
pos = rand() % (buf_len);
|
||||
name[i] = buf[pos];
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,75 @@
|
||||
/** @file fslittle_test.h
|
||||
*
|
||||
* mbed Microcontroller Library
|
||||
* Copyright (c) 2006-2016 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.
|
||||
*
|
||||
* Header file for test support data structures and function API.
|
||||
*/
|
||||
#ifndef __FSLITTLE_TEST_H
|
||||
#define __FSLITTLE_TEST_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Defines */
|
||||
//#define FSLITTLE_INIT_1_TABLE_HEAD { "a", ""}
|
||||
#define FSLITTLE_INIT_1_TABLE_MID_NODE { "/sd/01234567.txt", "abcdefghijklmnopqrstuvwxyz"}
|
||||
//#define FSLITTLE_INIT_1_TABLE_TAIL { "/sd/fopentst/hello/world/animal/wobbly/dog/foot/backrght.txt", "present"}
|
||||
#define FSLITTLE_TEST_RW_TABLE_SENTINEL 0xffffffff
|
||||
#define FSLITTLE_TEST_BYTE_DATA_TABLE_SIZE 256
|
||||
#define FSLITTLE_UTEST_MSG_BUF_SIZE 256
|
||||
#define FSLITTLE_UTEST_DEFAULT_TIMEOUT_MS 10000
|
||||
#define FSLITTLE_MBED_HOSTTEST_TIMEOUT 60
|
||||
#define FSLITTLE_MAX_FILE_BASENAME 8
|
||||
#define FSLITTLE_MAX_FILE_EXTNAME 3
|
||||
#define FSLITTLE_BUF_MAX_LENGTH 64
|
||||
#define FSLITTLE_FILENAME_MAX_LENGTH 255
|
||||
|
||||
|
||||
/* support macro for make string for utest _MESSAGE macros, which dont support formatted output */
|
||||
#define FSLITTLE_TEST_UTEST_MESSAGE(_buf, _max_len, _fmt, ...) \
|
||||
do \
|
||||
{ \
|
||||
snprintf((_buf), (_max_len), (_fmt), __VA_ARGS__); \
|
||||
}while(0);
|
||||
|
||||
|
||||
/*
|
||||
* Structures
|
||||
*/
|
||||
|
||||
/* kv data for test */
|
||||
typedef struct fslittle_kv_data_t {
|
||||
const char *filename;
|
||||
const char *value;
|
||||
} fslittle_kv_data_t;
|
||||
|
||||
|
||||
extern const uint8_t fslittle_test_byte_data_table[FSLITTLE_TEST_BYTE_DATA_TABLE_SIZE];
|
||||
|
||||
int32_t fslittle_test_create(const char *filename, const char *data, size_t len);
|
||||
int32_t fslittle_test_delete(const char *key_name);
|
||||
int32_t fslittle_test_filename_gen(char *name, const size_t len);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __FSLITTLE_TEST_H */
|
||||
270
storage/blockdevice/COMPONENT_FLASHIAP/FlashIAPBlockDevice.cpp
Normal file
270
storage/blockdevice/COMPONENT_FLASHIAP/FlashIAPBlockDevice.cpp
Normal file
@@ -0,0 +1,270 @@
|
||||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2016 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.
|
||||
*/
|
||||
|
||||
#if DEVICE_FLASH
|
||||
|
||||
#include "FlashIAPBlockDevice.h"
|
||||
#include "mbed_atomic.h"
|
||||
#include "mbed_error.h"
|
||||
|
||||
using namespace mbed;
|
||||
#include <inttypes.h>
|
||||
|
||||
#define FLASHIAP_READ_SIZE 1
|
||||
|
||||
// Debug available
|
||||
#ifndef FLASHIAP_DEBUG
|
||||
#define FLASHIAP_DEBUG 0
|
||||
#endif
|
||||
|
||||
#if FLASHIAP_DEBUG
|
||||
#define DEBUG_PRINTF(...) printf(__VA_ARGS__)
|
||||
#else
|
||||
#define DEBUG_PRINTF(...)
|
||||
#endif
|
||||
|
||||
FlashIAPBlockDevice::FlashIAPBlockDevice(uint32_t address, uint32_t size)
|
||||
: _flash(), _base(address), _size(size), _is_initialized(false), _init_ref_count(0)
|
||||
{
|
||||
if ((address == 0xFFFFFFFF) || (size == 0)) {
|
||||
MBED_ERROR(MBED_ERROR_INVALID_ARGUMENT,
|
||||
"Base address and size need to be set in flashiap-block-device configuration in order to use default constructor");
|
||||
}
|
||||
}
|
||||
|
||||
FlashIAPBlockDevice::~FlashIAPBlockDevice()
|
||||
{
|
||||
deinit();
|
||||
}
|
||||
|
||||
int FlashIAPBlockDevice::init()
|
||||
{
|
||||
DEBUG_PRINTF("init\r\n");
|
||||
|
||||
if (!_is_initialized) {
|
||||
_init_ref_count = 0;
|
||||
}
|
||||
|
||||
uint32_t val = core_util_atomic_incr_u32(&_init_ref_count, 1);
|
||||
|
||||
if (val != 1) {
|
||||
return BD_ERROR_OK;
|
||||
}
|
||||
|
||||
int ret = _flash.init();
|
||||
|
||||
if (ret) {
|
||||
core_util_atomic_decr_u32(&_init_ref_count, 1);
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (_size + _base > _flash.get_flash_size() + _flash.get_flash_start()) {
|
||||
core_util_atomic_decr_u32(&_init_ref_count, 1);
|
||||
return BD_ERROR_DEVICE_ERROR;
|
||||
}
|
||||
|
||||
if (_base < _flash.get_flash_start()) {
|
||||
core_util_atomic_decr_u32(&_init_ref_count, 1);
|
||||
return BD_ERROR_DEVICE_ERROR;
|
||||
}
|
||||
|
||||
if (!_base) {
|
||||
_base = _flash.get_flash_start();
|
||||
}
|
||||
|
||||
if (!_size) {
|
||||
_size = _flash.get_flash_size() - (_base - _flash.get_flash_start());
|
||||
}
|
||||
|
||||
_is_initialized = true;
|
||||
return ret;
|
||||
}
|
||||
|
||||
int FlashIAPBlockDevice::deinit()
|
||||
{
|
||||
DEBUG_PRINTF("deinit\r\n");
|
||||
|
||||
if (!_is_initialized) {
|
||||
_init_ref_count = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint32_t val = core_util_atomic_decr_u32(&_init_ref_count, 1);
|
||||
|
||||
if (val) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
_is_initialized = false;
|
||||
|
||||
return _flash.deinit();
|
||||
}
|
||||
|
||||
int FlashIAPBlockDevice::read(void *buffer,
|
||||
bd_addr_t virtual_address,
|
||||
bd_size_t size)
|
||||
{
|
||||
DEBUG_PRINTF("read: %" PRIX64 " %" PRIX64 "\r\n", virtual_address, size);
|
||||
|
||||
/* Default to error return code; success must be set explicitly. */
|
||||
int result = BD_ERROR_DEVICE_ERROR;
|
||||
|
||||
/* Check that the address and size are properly aligned and fit. */
|
||||
if (_is_initialized && is_valid_read(virtual_address, size)) {
|
||||
|
||||
/* Convert virtual address to the physical address for the device. */
|
||||
bd_addr_t physical_address = _base + virtual_address;
|
||||
|
||||
/* Read data using the internal flash driver. */
|
||||
result = _flash.read(buffer, physical_address, size);
|
||||
|
||||
DEBUG_PRINTF("physical: %" PRIX64 "\r\n", physical_address);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
int FlashIAPBlockDevice::program(const void *buffer,
|
||||
bd_addr_t virtual_address,
|
||||
bd_size_t size)
|
||||
{
|
||||
DEBUG_PRINTF("program: %" PRIX64 " %" PRIX64 "\r\n", virtual_address, size);
|
||||
|
||||
/* Default to error return code; success must be set explicitly. */
|
||||
int result = BD_ERROR_DEVICE_ERROR;
|
||||
|
||||
/* Check that the address and size are properly aligned and fit. */
|
||||
if (_is_initialized && is_valid_program(virtual_address, size)) {
|
||||
|
||||
/* Convert virtual address to the physical address for the device. */
|
||||
bd_addr_t physical_address = _base + virtual_address;
|
||||
|
||||
/* Write data using the internal flash driver. */
|
||||
result = _flash.program(buffer, physical_address, size);
|
||||
|
||||
DEBUG_PRINTF("physical: %" PRIX64 " %" PRIX64 "\r\n",
|
||||
physical_address,
|
||||
size);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
int FlashIAPBlockDevice::erase(bd_addr_t virtual_address,
|
||||
bd_size_t size)
|
||||
{
|
||||
DEBUG_PRINTF("erase: %" PRIX64 " %" PRIX64 "\r\n", virtual_address, size);
|
||||
|
||||
/* Default to error return code; success must be set explicitly. */
|
||||
int result = BD_ERROR_DEVICE_ERROR;
|
||||
|
||||
/* Check that the address and size are properly aligned and fit. */
|
||||
if (_is_initialized && is_valid_erase(virtual_address, size)) {
|
||||
|
||||
/* Convert virtual address to the physical address for the device. */
|
||||
bd_addr_t physical_address = _base + virtual_address;
|
||||
|
||||
/* Erase sector */
|
||||
result = _flash.erase(physical_address, size);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
bd_size_t FlashIAPBlockDevice::get_read_size() const
|
||||
{
|
||||
DEBUG_PRINTF("get_read_size: %d\r\n", FLASHIAP_READ_SIZE);
|
||||
|
||||
return FLASHIAP_READ_SIZE;
|
||||
}
|
||||
|
||||
bd_size_t FlashIAPBlockDevice::get_program_size() const
|
||||
{
|
||||
if (!_is_initialized) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint32_t page_size = _flash.get_page_size();
|
||||
|
||||
DEBUG_PRINTF("get_program_size: %" PRIX32 "\r\n", page_size);
|
||||
|
||||
return page_size;
|
||||
}
|
||||
|
||||
bd_size_t FlashIAPBlockDevice::get_erase_size() const
|
||||
{
|
||||
if (!_is_initialized) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint32_t erase_size = _flash.get_sector_size(_base);
|
||||
|
||||
DEBUG_PRINTF("get_erase_size: %" PRIX32 "\r\n", erase_size);
|
||||
|
||||
return erase_size;
|
||||
}
|
||||
|
||||
bd_size_t FlashIAPBlockDevice::get_erase_size(bd_addr_t addr) const
|
||||
{
|
||||
if (!_is_initialized) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint32_t erase_size = _flash.get_sector_size(_base + addr);
|
||||
|
||||
DEBUG_PRINTF("get_erase_size: %" PRIX32 "\r\n", erase_size);
|
||||
|
||||
return erase_size;
|
||||
}
|
||||
|
||||
int FlashIAPBlockDevice::get_erase_value() const
|
||||
{
|
||||
if (!_is_initialized) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
uint8_t erase_val = _flash.get_erase_value();
|
||||
|
||||
DEBUG_PRINTF("get_erase_value: %" PRIX8 "\r\n", erase_val);
|
||||
|
||||
return erase_val;
|
||||
}
|
||||
|
||||
|
||||
bd_size_t FlashIAPBlockDevice::size() const
|
||||
{
|
||||
DEBUG_PRINTF("size: %" PRIX64 "\r\n", _size);
|
||||
|
||||
return _size;
|
||||
}
|
||||
|
||||
const char *FlashIAPBlockDevice::get_type() const
|
||||
{
|
||||
return "FLASHIAP";
|
||||
}
|
||||
|
||||
bool FlashIAPBlockDevice::is_valid_erase(bd_addr_t addr, bd_size_t size) const
|
||||
{
|
||||
/* Calculate address alignment for the full flash */
|
||||
bd_addr_t base_addr = addr + (_base - _flash.get_flash_start());
|
||||
|
||||
return (
|
||||
addr + size <= this->size() &&
|
||||
base_addr % get_erase_size(addr) == 0 &&
|
||||
(base_addr + size) % get_erase_size(addr + size - 1) == 0);
|
||||
}
|
||||
#endif /* DEVICE_FLASH */
|
||||
150
storage/blockdevice/COMPONENT_FLASHIAP/FlashIAPBlockDevice.h
Normal file
150
storage/blockdevice/COMPONENT_FLASHIAP/FlashIAPBlockDevice.h
Normal file
@@ -0,0 +1,150 @@
|
||||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2016 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 MBED_FLASHIAP_BLOCK_DEVICE_H
|
||||
#define MBED_FLASHIAP_BLOCK_DEVICE_H
|
||||
|
||||
#if DEVICE_FLASH
|
||||
|
||||
#include "FlashIAP.h"
|
||||
#include "blockdevice/BlockDevice.h"
|
||||
#include "platform/mbed_toolchain.h"
|
||||
|
||||
/** BlockDevice using the FlashIAP API
|
||||
*
|
||||
*/
|
||||
class FlashIAPBlockDevice : public mbed::BlockDevice {
|
||||
public:
|
||||
|
||||
/** Creates a FlashIAPBlockDevice
|
||||
*
|
||||
* @param address Physical address where the block device start
|
||||
* @param size The block device size
|
||||
*/
|
||||
FlashIAPBlockDevice(uint32_t address = MBED_CONF_FLASHIAP_BLOCK_DEVICE_BASE_ADDRESS,
|
||||
uint32_t size = MBED_CONF_FLASHIAP_BLOCK_DEVICE_SIZE);
|
||||
|
||||
virtual ~FlashIAPBlockDevice();
|
||||
|
||||
/** Initialize a block device
|
||||
*
|
||||
* @return 0 on success or a negative error code on failure
|
||||
*/
|
||||
virtual int init();
|
||||
|
||||
/** Deinitialize a block device
|
||||
*
|
||||
* @return 0 on success or a negative error code on failure
|
||||
*/
|
||||
virtual int deinit();
|
||||
|
||||
/** Read blocks from a block device
|
||||
*
|
||||
* @param buffer Buffer to write blocks to
|
||||
* @param addr Address of block to begin reading from
|
||||
* @param size Size to read in bytes, must be a multiple of read block size
|
||||
* @return 0 on success, negative error code on failure
|
||||
*/
|
||||
virtual int read(void *buffer, mbed::bd_addr_t addr, mbed::bd_size_t size);
|
||||
|
||||
/** Program blocks to a block device
|
||||
*
|
||||
* The blocks must have been erased prior to being programmed
|
||||
*
|
||||
* @param buffer Buffer of data to write to blocks
|
||||
* @param addr Address of block to begin writing to
|
||||
* @param size Size to write in bytes, must be a multiple of program block size
|
||||
* @return 0 on success, negative error code on failure
|
||||
*/
|
||||
virtual int program(const void *buffer, mbed::bd_addr_t addr, mbed::bd_size_t size);
|
||||
|
||||
/** Erase blocks on a block device
|
||||
*
|
||||
* The state of an erased block is undefined until it has been programmed
|
||||
*
|
||||
* @param addr Address of block to begin erasing
|
||||
* @param size Size to erase in bytes, must be a multiple of erase block size
|
||||
* @return 0 on success, negative error code on failure
|
||||
*/
|
||||
virtual int erase(mbed::bd_addr_t addr, mbed::bd_size_t size);
|
||||
|
||||
/** Get the size of a readable block
|
||||
*
|
||||
* @return Size of a readable block in bytes
|
||||
*/
|
||||
virtual mbed::bd_size_t get_read_size() const;
|
||||
|
||||
/** Get the size of a programable block
|
||||
*
|
||||
* @return Size of a programable block in bytes
|
||||
* @note Must be a multiple of the read size
|
||||
*/
|
||||
virtual mbed::bd_size_t get_program_size() const;
|
||||
|
||||
/** Get the size of a eraseable block
|
||||
*
|
||||
* @return Size of a eraseable block in bytes
|
||||
* @note Must be a multiple of the program size
|
||||
*/
|
||||
virtual mbed::bd_size_t get_erase_size() const;
|
||||
|
||||
/** Get the size of an erasable block given address
|
||||
*
|
||||
* @param addr Address within the erasable block
|
||||
* @return Size of an erasable block in bytes
|
||||
* @note Must be a multiple of the program size
|
||||
*/
|
||||
virtual mbed::bd_size_t get_erase_size(mbed::bd_addr_t addr) const;
|
||||
|
||||
/** Get the value of storage when erased
|
||||
*
|
||||
* @return The value of storage when erased
|
||||
*/
|
||||
virtual int get_erase_value() const;
|
||||
|
||||
/** Get the total size of the underlying device
|
||||
*
|
||||
* @return Size of the underlying device in bytes
|
||||
*/
|
||||
virtual mbed::bd_size_t size() const;
|
||||
|
||||
/** Get the BlockDevice class type.
|
||||
*
|
||||
* @return A string represent the BlockDevice class type.
|
||||
*/
|
||||
virtual const char *get_type() const;
|
||||
|
||||
/** Convenience function for checking block erase validity
|
||||
*
|
||||
* @param addr Address of block to begin erasing
|
||||
* @param size Size to erase in bytes
|
||||
* @return True if erase is valid for underlying block device
|
||||
*/
|
||||
virtual bool is_valid_erase(bd_addr_t addr, bd_size_t size) const;
|
||||
|
||||
|
||||
private:
|
||||
// Device configuration
|
||||
mbed::FlashIAP _flash;
|
||||
mbed::bd_addr_t _base;
|
||||
mbed::bd_size_t _size;
|
||||
bool _is_initialized;
|
||||
uint32_t _init_ref_count;
|
||||
};
|
||||
|
||||
#endif /* DEVICE_FLASH */
|
||||
#endif /* MBED_FLASHIAP_BLOCK_DEVICE_H */
|
||||
31
storage/blockdevice/COMPONENT_FLASHIAP/mbed_lib.json
Normal file
31
storage/blockdevice/COMPONENT_FLASHIAP/mbed_lib.json
Normal file
@@ -0,0 +1,31 @@
|
||||
{
|
||||
"name": "flashiap-block-device",
|
||||
"config": {
|
||||
"base-address": {
|
||||
"help": "Base address for the block device on the external flash.",
|
||||
"value": "0xFFFFFFFF"
|
||||
},
|
||||
"size": {
|
||||
"help": "Memory allocated for block device.",
|
||||
"value": "0"
|
||||
}
|
||||
},
|
||||
"target_overrides": {
|
||||
"REALTEK_RTL8195AM": {
|
||||
"base-address": "0x1C0000",
|
||||
"size": "0x40000"
|
||||
},
|
||||
"FVP_MPS2": {
|
||||
"base-address": "0x00200000",
|
||||
"size": "0x200000"
|
||||
},
|
||||
"S5JS100": {
|
||||
"base-address": "0x40EF5000",
|
||||
"size": "0x80000"
|
||||
},
|
||||
"MIMXRT1050_EVK": {
|
||||
"base-address": "0x60400000",
|
||||
"size": "0x3C00000"
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user