rtt更新
This commit is contained in:
@@ -9,8 +9,17 @@
|
||||
*/
|
||||
|
||||
#include <fal.h>
|
||||
#include <rtdevice.h>
|
||||
|
||||
static uint8_t init_ok = 0;
|
||||
#define DBG_TAG "FAL"
|
||||
#ifdef FAL_USING_DEBUG
|
||||
#define DBG_LVL DBG_LOG
|
||||
#else
|
||||
#define DBG_LVL DBG_WARNING
|
||||
#endif
|
||||
#include <rtdbg.h>
|
||||
|
||||
static rt_uint8_t init_ok = 0;
|
||||
|
||||
/**
|
||||
* FAL (Flash Abstraction Layer) initialization.
|
||||
@@ -40,12 +49,12 @@ __exit:
|
||||
if ((result > 0) && (!init_ok))
|
||||
{
|
||||
init_ok = 1;
|
||||
log_i("RT-Thread Flash Abstraction Layer initialize success.");
|
||||
LOG_I("RT-Thread Flash Abstraction Layer initialize success.");
|
||||
}
|
||||
else if(result <= 0)
|
||||
{
|
||||
init_ok = 0;
|
||||
log_e("RT-Thread Flash Abstraction Layer initialize failed.");
|
||||
LOG_E("RT-Thread Flash Abstraction Layer initialize failed.");
|
||||
}
|
||||
|
||||
return result;
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2018, RT-Thread Development Team
|
||||
* Copyright (c) 2006-2024 RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
@@ -11,14 +11,22 @@
|
||||
#include <fal.h>
|
||||
#include <string.h>
|
||||
|
||||
#define DBG_TAG "FAL"
|
||||
#ifdef FAL_USING_DEBUG
|
||||
#define DBG_LVL DBG_LOG
|
||||
#else
|
||||
#define DBG_LVL DBG_WARNING
|
||||
#endif
|
||||
#include <rtdbg.h>
|
||||
|
||||
/* flash device table, must defined by user */
|
||||
#if !defined(FAL_FLASH_DEV_TABLE)
|
||||
#error "You must defined flash device table (FAL_FLASH_DEV_TABLE) on 'fal_cfg.h'"
|
||||
#endif
|
||||
|
||||
static const struct fal_flash_dev * const device_table[] = FAL_FLASH_DEV_TABLE;
|
||||
static const size_t device_table_len = sizeof(device_table) / sizeof(device_table[0]);
|
||||
static uint8_t init_ok = 0;
|
||||
static const rt_size_t device_table_len = sizeof(device_table) / sizeof(device_table[0]);
|
||||
static rt_uint8_t init_ok = 0;
|
||||
|
||||
/**
|
||||
* Initialize all flash device on FAL flash table
|
||||
@@ -27,7 +35,7 @@ static uint8_t init_ok = 0;
|
||||
*/
|
||||
int fal_flash_init(void)
|
||||
{
|
||||
size_t i, j, offset;
|
||||
rt_size_t i, j, offset;
|
||||
|
||||
if (init_ok)
|
||||
{
|
||||
@@ -36,25 +44,33 @@ int fal_flash_init(void)
|
||||
|
||||
for (i = 0; i < device_table_len; i++)
|
||||
{
|
||||
assert(device_table[i]->ops.read);
|
||||
assert(device_table[i]->ops.write);
|
||||
assert(device_table[i]->ops.erase);
|
||||
RT_ASSERT(device_table[i]->ops.read);
|
||||
RT_ASSERT(device_table[i]->ops.write);
|
||||
RT_ASSERT(device_table[i]->ops.erase);
|
||||
/* init flash device on flash table */
|
||||
if (device_table[i]->ops.init)
|
||||
{
|
||||
device_table[i]->ops.init();
|
||||
}
|
||||
log_d("Flash device | %*.*s | addr: 0x%08lx | len: 0x%08x | blk_size: 0x%08x |initialized finish.",
|
||||
LOG_D("Flash device | %*.*s | addr: 0x%08lx | len: 0x%08x | blk_size: 0x%08x |initialized finish.",
|
||||
FAL_DEV_NAME_MAX, FAL_DEV_NAME_MAX, device_table[i]->name, device_table[i]->addr, device_table[i]->len,
|
||||
device_table[i]->blk_size);
|
||||
offset = 0;
|
||||
for (j = 0; j < FAL_DEV_BLK_MAX; j ++)
|
||||
{
|
||||
const struct flash_blk *blk = &device_table[i]->blocks[j];
|
||||
size_t blk_len = blk->count * blk->size;
|
||||
rt_size_t blk_len = blk->count * blk->size;
|
||||
if (blk->count == 0 || blk->size == 0)
|
||||
break;
|
||||
log_d(" blk%2d | addr: 0x%08lx | len: 0x%08x | blk_size: 0x%08x |initialized finish.",
|
||||
|
||||
if(offset > device_table[i]->len)
|
||||
{
|
||||
LOG_I("Flash device %*.*s: add block failed, offset %d > len %d.",
|
||||
FAL_DEV_NAME_MAX, FAL_DEV_NAME_MAX, device_table[i]->name, device_table[i]->addr, offset, device_table[i]->len);
|
||||
break;
|
||||
}
|
||||
|
||||
LOG_D(" blk%2d | addr: 0x%08lx | len: 0x%08x | blk_size: 0x%08x |initialized finish.",
|
||||
j, device_table[i]->addr + offset, blk_len, blk->size);
|
||||
offset += blk_len;
|
||||
}
|
||||
@@ -74,10 +90,10 @@ int fal_flash_init(void)
|
||||
*/
|
||||
const struct fal_flash_dev *fal_flash_device_find(const char *name)
|
||||
{
|
||||
assert(init_ok);
|
||||
assert(name);
|
||||
RT_ASSERT(init_ok);
|
||||
RT_ASSERT(name);
|
||||
|
||||
size_t i;
|
||||
rt_size_t i;
|
||||
|
||||
for (i = 0; i < device_table_len; i++)
|
||||
{
|
||||
|
@@ -10,7 +10,15 @@
|
||||
|
||||
#include <fal.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#define DBG_TAG "FAL"
|
||||
#ifdef FAL_USING_DEBUG
|
||||
#define DBG_LVL DBG_LOG
|
||||
#else
|
||||
#define DBG_LVL DBG_WARNING
|
||||
#endif
|
||||
#include <rtdbg.h>
|
||||
|
||||
|
||||
/* partition magic word */
|
||||
#define FAL_PART_MAGIC_WORD 0x45503130
|
||||
@@ -55,8 +63,8 @@ static struct fal_partition *partition_table = NULL;
|
||||
static struct part_flash_info *part_flash_cache = NULL;
|
||||
#endif /* FAL_PART_HAS_TABLE_CFG */
|
||||
|
||||
static uint8_t init_ok = 0;
|
||||
static size_t partition_table_len = 0;
|
||||
static rt_uint8_t init_ok = 0;
|
||||
static rt_size_t partition_table_len = 0;
|
||||
|
||||
/**
|
||||
* print the partition table
|
||||
@@ -64,7 +72,7 @@ static size_t partition_table_len = 0;
|
||||
void fal_show_part_table(void)
|
||||
{
|
||||
char *item1 = "name", *item2 = "flash_dev";
|
||||
size_t i, part_name_max = strlen(item1), flash_dev_name_max = strlen(item2);
|
||||
rt_size_t i, part_name_max = strlen(item1), flash_dev_name_max = strlen(item2);
|
||||
const struct fal_partition *part;
|
||||
|
||||
if (partition_table_len)
|
||||
@@ -82,10 +90,10 @@ void fal_show_part_table(void)
|
||||
}
|
||||
}
|
||||
}
|
||||
log_i("==================== FAL partition table ====================");
|
||||
log_i("| %-*.*s | %-*.*s | offset | length |", part_name_max, FAL_DEV_NAME_MAX, item1, flash_dev_name_max,
|
||||
LOG_I("==================== FAL partition table ====================");
|
||||
LOG_I("| %-*.*s | %-*.*s | offset | length |", part_name_max, FAL_DEV_NAME_MAX, item1, flash_dev_name_max,
|
||||
FAL_DEV_NAME_MAX, item2);
|
||||
log_i("-------------------------------------------------------------");
|
||||
LOG_I("-------------------------------------------------------------");
|
||||
for (i = 0; i < partition_table_len; i++)
|
||||
{
|
||||
|
||||
@@ -95,26 +103,26 @@ void fal_show_part_table(void)
|
||||
part = &partition_table[partition_table_len - i - 1];
|
||||
#endif
|
||||
|
||||
log_i("| %-*.*s | %-*.*s | 0x%08lx | 0x%08x |", part_name_max, FAL_DEV_NAME_MAX, part->name, flash_dev_name_max,
|
||||
LOG_I("| %-*.*s | %-*.*s | 0x%08lx | 0x%08x |", part_name_max, FAL_DEV_NAME_MAX, part->name, flash_dev_name_max,
|
||||
FAL_DEV_NAME_MAX, part->flash_name, part->offset, part->len);
|
||||
}
|
||||
log_i("=============================================================");
|
||||
LOG_I("=============================================================");
|
||||
}
|
||||
|
||||
static int check_and_update_part_cache(const struct fal_partition *table, size_t len)
|
||||
static int check_and_update_part_cache(const struct fal_partition *table, rt_size_t len)
|
||||
{
|
||||
const struct fal_flash_dev *flash_dev = NULL;
|
||||
size_t i;
|
||||
rt_size_t i;
|
||||
|
||||
#ifndef FAL_PART_HAS_TABLE_CFG
|
||||
if (part_flash_cache)
|
||||
{
|
||||
FAL_FREE(part_flash_cache);
|
||||
rt_free(part_flash_cache);
|
||||
}
|
||||
part_flash_cache = FAL_MALLOC(len * sizeof(struct part_flash_info));
|
||||
part_flash_cache = rt_malloc(len * sizeof(struct part_flash_info));
|
||||
if (part_flash_cache == NULL)
|
||||
{
|
||||
log_e("Initialize failed! No memory for partition table cache");
|
||||
LOG_E("Initialize failed! No memory for partition table cache");
|
||||
return -2;
|
||||
}
|
||||
#endif
|
||||
@@ -124,13 +132,13 @@ static int check_and_update_part_cache(const struct fal_partition *table, size_t
|
||||
flash_dev = fal_flash_device_find(table[i].flash_name);
|
||||
if (flash_dev == NULL)
|
||||
{
|
||||
log_d("Warning: Do NOT found the flash device(%s).", table[i].flash_name);
|
||||
LOG_D("Warning: Do NOT found the flash device(%s).", table[i].flash_name);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (table[i].offset >= (long)flash_dev->len)
|
||||
{
|
||||
log_e("Initialize failed! Partition(%s) offset address(%ld) out of flash bound(<%d).",
|
||||
LOG_E("Initialize failed! Partition(%s) offset address(%ld) out of flash bound(<%d).",
|
||||
table[i].name, table[i].offset, flash_dev->len);
|
||||
partition_table_len = 0;
|
||||
|
||||
@@ -162,38 +170,38 @@ int fal_partition_init(void)
|
||||
#else
|
||||
/* load partition table from the end address FAL_PART_TABLE_END_OFFSET, error return 0 */
|
||||
long part_table_offset = FAL_PART_TABLE_END_OFFSET;
|
||||
size_t table_num = 0, table_item_size = 0;
|
||||
uint8_t part_table_find_ok = 0;
|
||||
uint32_t read_magic_word;
|
||||
rt_size_t table_num = 0, table_item_size = 0;
|
||||
rt_uint8_t part_table_find_ok = 0;
|
||||
rt_uint32_t read_magic_word;
|
||||
fal_partition_t new_part = NULL;
|
||||
size_t i;
|
||||
rt_size_t i;
|
||||
const struct fal_flash_dev *flash_dev = NULL;
|
||||
|
||||
flash_dev = fal_flash_device_find(FAL_PART_TABLE_FLASH_DEV_NAME);
|
||||
if (flash_dev == NULL)
|
||||
{
|
||||
log_e("Initialize failed! Flash device (%s) NOT found.", FAL_PART_TABLE_FLASH_DEV_NAME);
|
||||
LOG_E("Initialize failed! Flash device (%s) NOT found.", FAL_PART_TABLE_FLASH_DEV_NAME);
|
||||
goto _exit;
|
||||
}
|
||||
|
||||
/* check partition table offset address */
|
||||
if (part_table_offset < 0 || part_table_offset >= (long) flash_dev->len)
|
||||
{
|
||||
log_e("Setting partition table end offset address(%ld) out of flash bound(<%d).", part_table_offset, flash_dev->len);
|
||||
LOG_E("Setting partition table end offset address(%ld) out of flash bound(<%d).", part_table_offset, flash_dev->len);
|
||||
goto _exit;
|
||||
}
|
||||
|
||||
table_item_size = sizeof(struct fal_partition);
|
||||
new_part = (fal_partition_t)FAL_MALLOC(table_item_size);
|
||||
new_part = (fal_partition_t)rt_malloc(table_item_size);
|
||||
if (new_part == NULL)
|
||||
{
|
||||
log_e("Initialize failed! No memory for table buffer.");
|
||||
LOG_E("Initialize failed! No memory for table buffer.");
|
||||
goto _exit;
|
||||
}
|
||||
|
||||
/* find partition table location */
|
||||
{
|
||||
uint8_t read_buf[64];
|
||||
rt_uint8_t read_buf[64];
|
||||
|
||||
part_table_offset -= sizeof(read_buf);
|
||||
while (part_table_offset >= 0)
|
||||
@@ -208,7 +216,7 @@ int fal_partition_init(void)
|
||||
{
|
||||
part_table_find_ok = 1;
|
||||
part_table_offset += i;
|
||||
log_d("Find the partition table on '%s' offset @0x%08lx.", FAL_PART_TABLE_FLASH_DEV_NAME,
|
||||
LOG_D("Find the partition table on '%s' offset @0x%08lx.", FAL_PART_TABLE_FLASH_DEV_NAME,
|
||||
part_table_offset);
|
||||
break;
|
||||
}
|
||||
@@ -249,10 +257,10 @@ int fal_partition_init(void)
|
||||
while (part_table_find_ok)
|
||||
{
|
||||
memset(new_part, 0x00, table_num);
|
||||
if (flash_dev->ops.read(part_table_offset - table_item_size * (table_num), (uint8_t *) new_part,
|
||||
if (flash_dev->ops.read(part_table_offset - table_item_size * (table_num), (rt_uint8_t *) new_part,
|
||||
table_item_size) < 0)
|
||||
{
|
||||
log_e("Initialize failed! Flash device (%s) read error!", flash_dev->name);
|
||||
LOG_E("Initialize failed! Flash device (%s) read error!", flash_dev->name);
|
||||
table_num = 0;
|
||||
break;
|
||||
}
|
||||
@@ -262,10 +270,10 @@ int fal_partition_init(void)
|
||||
break;
|
||||
}
|
||||
|
||||
partition_table = (fal_partition_t) FAL_REALLOC(partition_table, table_item_size * (table_num + 1));
|
||||
partition_table = (fal_partition_t) rt_realloc(partition_table, table_item_size * (table_num + 1));
|
||||
if (partition_table == NULL)
|
||||
{
|
||||
log_e("Initialize failed! No memory for partition table");
|
||||
LOG_E("Initialize failed! No memory for partition table");
|
||||
table_num = 0;
|
||||
break;
|
||||
}
|
||||
@@ -277,7 +285,7 @@ int fal_partition_init(void)
|
||||
|
||||
if (table_num == 0)
|
||||
{
|
||||
log_e("Partition table NOT found on flash: %s (len: %d) from offset: 0x%08x.", FAL_PART_TABLE_FLASH_DEV_NAME,
|
||||
LOG_E("Partition table NOT found on flash: %s (len: %d) from offset: 0x%08x.", FAL_PART_TABLE_FLASH_DEV_NAME,
|
||||
FAL_DEV_NAME_MAX, FAL_PART_TABLE_END_OFFSET);
|
||||
goto _exit;
|
||||
}
|
||||
@@ -297,14 +305,14 @@ int fal_partition_init(void)
|
||||
|
||||
_exit:
|
||||
|
||||
#if FAL_DEBUG
|
||||
#ifdef FAL_USING_DEBUG
|
||||
fal_show_part_table();
|
||||
#endif
|
||||
#endif /* FAL_USING_DEBUG */
|
||||
|
||||
#ifndef FAL_PART_HAS_TABLE_CFG
|
||||
if (new_part)
|
||||
{
|
||||
FAL_FREE(new_part);
|
||||
rt_free(new_part);
|
||||
}
|
||||
#endif /* !FAL_PART_HAS_TABLE_CFG */
|
||||
|
||||
@@ -324,7 +332,7 @@ const struct fal_partition *fal_partition_find(const char *name)
|
||||
if (!init_ok)
|
||||
return NULL;
|
||||
|
||||
size_t i;
|
||||
rt_size_t i;
|
||||
|
||||
for (i = 0; i < partition_table_len; i++)
|
||||
{
|
||||
@@ -339,8 +347,8 @@ const struct fal_partition *fal_partition_find(const char *name)
|
||||
|
||||
static const struct fal_flash_dev *flash_device_find_by_part(const struct fal_partition *part)
|
||||
{
|
||||
assert(part >= partition_table);
|
||||
assert(part <= &partition_table[partition_table_len - 1]);
|
||||
RT_ASSERT(part >= partition_table);
|
||||
RT_ASSERT(part <= &partition_table[partition_table_len - 1]);
|
||||
|
||||
return part_flash_cache[part - partition_table].flash_dev;
|
||||
}
|
||||
@@ -352,9 +360,9 @@ static const struct fal_flash_dev *flash_device_find_by_part(const struct fal_pa
|
||||
*
|
||||
* @return partition table
|
||||
*/
|
||||
const struct fal_partition *fal_get_partition_table(size_t *len)
|
||||
const struct fal_partition *fal_get_partition_table(rt_size_t *len)
|
||||
{
|
||||
assert(len);
|
||||
RT_ASSERT(len);
|
||||
|
||||
if (!init_ok)
|
||||
return NULL;
|
||||
@@ -371,13 +379,13 @@ const struct fal_partition *fal_get_partition_table(size_t *len)
|
||||
* @param table partition table
|
||||
* @param len partition table length
|
||||
*/
|
||||
void fal_set_partition_table_temp(struct fal_partition *table, size_t len)
|
||||
void fal_set_partition_table_temp(struct fal_partition *table, rt_size_t len)
|
||||
{
|
||||
assert(table);
|
||||
RT_ASSERT(table);
|
||||
|
||||
if (!init_ok)
|
||||
{
|
||||
log_e("FAL NOT initialized");
|
||||
LOG_E("FAL NOT initialized");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -398,31 +406,31 @@ void fal_set_partition_table_temp(struct fal_partition *table, size_t len)
|
||||
* @return >= 0: successful read data size
|
||||
* -1: error
|
||||
*/
|
||||
int fal_partition_read(const struct fal_partition *part, uint32_t addr, uint8_t *buf, size_t size)
|
||||
int fal_partition_read(const struct fal_partition *part, rt_uint32_t addr, rt_uint8_t *buf, rt_size_t size)
|
||||
{
|
||||
int ret = 0;
|
||||
const struct fal_flash_dev *flash_dev = NULL;
|
||||
|
||||
assert(part);
|
||||
assert(buf);
|
||||
RT_ASSERT(part);
|
||||
RT_ASSERT(buf);
|
||||
|
||||
if (addr + size > part->len)
|
||||
{
|
||||
log_e("Partition read error! Partition(%s) address(0x%08x) out of bound(0x%08x).", part->name, addr + size, part->len);
|
||||
LOG_E("Partition read error! Partition(%s) address(0x%08x) out of bound(0x%08x).", part->name, addr + size, part->len);
|
||||
return -1;
|
||||
}
|
||||
|
||||
flash_dev = flash_device_find_by_part(part);
|
||||
if (flash_dev == NULL)
|
||||
{
|
||||
log_e("Partition read error! Don't found flash device(%s) of the partition(%s).", part->flash_name, part->name);
|
||||
LOG_E("Partition read error! Don't found flash device(%s) of the partition(%s).", part->flash_name, part->name);
|
||||
return -1;
|
||||
}
|
||||
|
||||
ret = flash_dev->ops.read(part->offset + addr, buf, size);
|
||||
if (ret < 0)
|
||||
{
|
||||
log_e("Partition read error! Flash device(%s) read error!", part->flash_name);
|
||||
LOG_E("Partition read error! Flash device(%s) read error!", part->flash_name);
|
||||
}
|
||||
|
||||
return ret;
|
||||
@@ -439,31 +447,31 @@ int fal_partition_read(const struct fal_partition *part, uint32_t addr, uint8_t
|
||||
* @return >= 0: successful write data size
|
||||
* -1: error
|
||||
*/
|
||||
int fal_partition_write(const struct fal_partition *part, uint32_t addr, const uint8_t *buf, size_t size)
|
||||
int fal_partition_write(const struct fal_partition *part, rt_uint32_t addr, const rt_uint8_t *buf, rt_size_t size)
|
||||
{
|
||||
int ret = 0;
|
||||
const struct fal_flash_dev *flash_dev = NULL;
|
||||
|
||||
assert(part);
|
||||
assert(buf);
|
||||
RT_ASSERT(part);
|
||||
RT_ASSERT(buf);
|
||||
|
||||
if (addr + size > part->len)
|
||||
{
|
||||
log_e("Partition write error! Partition address out of bound.");
|
||||
LOG_E("Partition write error! Partition address out of bound.");
|
||||
return -1;
|
||||
}
|
||||
|
||||
flash_dev = flash_device_find_by_part(part);
|
||||
if (flash_dev == NULL)
|
||||
{
|
||||
log_e("Partition write error! Don't found flash device(%s) of the partition(%s).", part->flash_name, part->name);
|
||||
LOG_E("Partition write error! Don't found flash device(%s) of the partition(%s).", part->flash_name, part->name);
|
||||
return -1;
|
||||
}
|
||||
|
||||
ret = flash_dev->ops.write(part->offset + addr, buf, size);
|
||||
if (ret < 0)
|
||||
{
|
||||
log_e("Partition write error! Flash device(%s) write error!", part->flash_name);
|
||||
LOG_E("Partition write error! Flash device(%s) write error!", part->flash_name);
|
||||
}
|
||||
|
||||
return ret;
|
||||
@@ -479,30 +487,30 @@ int fal_partition_write(const struct fal_partition *part, uint32_t addr, const u
|
||||
* @return >= 0: successful erased data size
|
||||
* -1: error
|
||||
*/
|
||||
int fal_partition_erase(const struct fal_partition *part, uint32_t addr, size_t size)
|
||||
int fal_partition_erase(const struct fal_partition *part, rt_uint32_t addr, rt_size_t size)
|
||||
{
|
||||
int ret = 0;
|
||||
const struct fal_flash_dev *flash_dev = NULL;
|
||||
|
||||
assert(part);
|
||||
RT_ASSERT(part);
|
||||
|
||||
if (addr + size > part->len)
|
||||
{
|
||||
log_e("Partition erase error! Partition address out of bound.");
|
||||
LOG_E("Partition erase error! Partition address out of bound.");
|
||||
return -1;
|
||||
}
|
||||
|
||||
flash_dev = flash_device_find_by_part(part);
|
||||
if (flash_dev == NULL)
|
||||
{
|
||||
log_e("Partition erase error! Don't found flash device(%s) of the partition(%s).", part->flash_name, part->name);
|
||||
LOG_E("Partition erase error! Don't found flash device(%s) of the partition(%s).", part->flash_name, part->name);
|
||||
return -1;
|
||||
}
|
||||
|
||||
ret = flash_dev->ops.erase(part->offset + addr, size);
|
||||
if (ret < 0)
|
||||
{
|
||||
log_e("Partition erase error! Flash device(%s) erase error!", part->flash_name);
|
||||
LOG_E("Partition erase error! Flash device(%s) erase error!", part->flash_name);
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
@@ -10,12 +10,18 @@
|
||||
*/
|
||||
|
||||
#include <fal.h>
|
||||
|
||||
#ifdef RT_VER_NUM
|
||||
#include <rtthread.h>
|
||||
#include <rtdevice.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <rtdevice.h>
|
||||
|
||||
#define DBG_TAG "FAL"
|
||||
#ifdef FAL_USING_DEBUG
|
||||
#define DBG_LVL DBG_LOG
|
||||
#else
|
||||
#define DBG_LVL DBG_WARNING
|
||||
#endif
|
||||
#include <rtdbg.h>
|
||||
|
||||
|
||||
/* ========================== block device ======================== */
|
||||
struct fal_blk_device
|
||||
@@ -34,7 +40,7 @@ static rt_err_t blk_dev_control(rt_device_t dev, rt_uint8_t cmd, void *args)
|
||||
{
|
||||
struct fal_blk_device *part = (struct fal_blk_device*) dev;
|
||||
|
||||
assert(part != RT_NULL);
|
||||
RT_ASSERT(part != RT_NULL);
|
||||
|
||||
if (cmd == RT_DEVICE_CTRL_BLK_GETGEOME)
|
||||
{
|
||||
@@ -46,7 +52,7 @@ static rt_err_t blk_dev_control(rt_device_t dev, rt_uint8_t cmd, void *args)
|
||||
return -RT_ERROR;
|
||||
}
|
||||
|
||||
memcpy(geometry, &part->geometry, sizeof(struct rt_device_blk_geometry));
|
||||
rt_memcpy(geometry, &part->geometry, sizeof(struct rt_device_blk_geometry));
|
||||
}
|
||||
else if (cmd == RT_DEVICE_CTRL_BLK_ERASE)
|
||||
{
|
||||
@@ -80,7 +86,7 @@ static rt_ssize_t blk_dev_read(rt_device_t dev, rt_off_t pos, void* buffer, rt_s
|
||||
int ret = 0;
|
||||
struct fal_blk_device *part = (struct fal_blk_device*) dev;
|
||||
|
||||
assert(part != RT_NULL);
|
||||
RT_ASSERT(part != RT_NULL);
|
||||
|
||||
ret = fal_partition_read(part->fal_part, pos * part->geometry.block_size, buffer, size * part->geometry.block_size);
|
||||
|
||||
@@ -104,7 +110,7 @@ static rt_ssize_t blk_dev_write(rt_device_t dev, rt_off_t pos, const void* buffe
|
||||
rt_size_t phy_size;
|
||||
|
||||
part = (struct fal_blk_device*) dev;
|
||||
assert(part != RT_NULL);
|
||||
RT_ASSERT(part != RT_NULL);
|
||||
|
||||
/* change the block device's logic address to physical address */
|
||||
phy_pos = pos * part->geometry.bytes_per_sector;
|
||||
@@ -157,13 +163,13 @@ struct rt_device *fal_blk_device_create(const char *parition_name)
|
||||
|
||||
if (!fal_part)
|
||||
{
|
||||
log_e("Error: the partition name (%s) is not found.", parition_name);
|
||||
LOG_E("Error: the partition name (%s) is not found.", parition_name);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if ((fal_flash = fal_flash_device_find(fal_part->flash_name)) == NULL)
|
||||
{
|
||||
log_e("Error: the flash device name (%s) is not found.", fal_part->flash_name);
|
||||
LOG_E("Error: the flash device name (%s) is not found.", fal_part->flash_name);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -192,12 +198,12 @@ struct rt_device *fal_blk_device_create(const char *parition_name)
|
||||
/* no private */
|
||||
blk_dev->parent.user_data = RT_NULL;
|
||||
|
||||
log_i("The FAL block device (%s) created successfully", fal_part->name);
|
||||
LOG_I("The FAL block device (%s) created successfully", fal_part->name);
|
||||
rt_device_register(RT_DEVICE(blk_dev), fal_part->name, RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_STANDALONE);
|
||||
}
|
||||
else
|
||||
{
|
||||
log_e("Error: no memory for create FAL block device");
|
||||
LOG_E("Error: no memory for create FAL block device");
|
||||
}
|
||||
|
||||
return RT_DEVICE(blk_dev);
|
||||
@@ -217,7 +223,7 @@ static rt_ssize_t mtd_nor_dev_read(struct rt_mtd_nor_device* device, rt_off_t of
|
||||
int ret = 0;
|
||||
struct fal_mtd_nor_device *part = (struct fal_mtd_nor_device*) device;
|
||||
|
||||
assert(part != RT_NULL);
|
||||
RT_ASSERT(part != RT_NULL);
|
||||
|
||||
ret = fal_partition_read(part->fal_part, offset, data, length);
|
||||
|
||||
@@ -239,7 +245,7 @@ static rt_ssize_t mtd_nor_dev_write(struct rt_mtd_nor_device* device, rt_off_t o
|
||||
struct fal_mtd_nor_device *part;
|
||||
|
||||
part = (struct fal_mtd_nor_device*) device;
|
||||
assert(part != RT_NULL);
|
||||
RT_ASSERT(part != RT_NULL);
|
||||
|
||||
ret = fal_partition_write(part->fal_part, offset, data, length);
|
||||
|
||||
@@ -261,7 +267,7 @@ static rt_err_t mtd_nor_dev_erase(struct rt_mtd_nor_device* device, rt_off_t off
|
||||
struct fal_mtd_nor_device *part;
|
||||
|
||||
part = (struct fal_mtd_nor_device*) device;
|
||||
assert(part != RT_NULL);
|
||||
RT_ASSERT(part != RT_NULL);
|
||||
|
||||
ret = fal_partition_erase(part->fal_part, offset, length);
|
||||
|
||||
@@ -299,13 +305,13 @@ struct rt_device *fal_mtd_nor_device_create(const char *parition_name)
|
||||
|
||||
if (!fal_part)
|
||||
{
|
||||
log_e("Error: the partition name (%s) is not found.", parition_name);
|
||||
LOG_E("Error: the partition name (%s) is not found.", parition_name);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if ((fal_flash = fal_flash_device_find(fal_part->flash_name)) == NULL)
|
||||
{
|
||||
log_e("Error: the flash device name (%s) is not found.", fal_part->flash_name);
|
||||
LOG_E("Error: the flash device name (%s) is not found.", fal_part->flash_name);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -321,12 +327,12 @@ struct rt_device *fal_mtd_nor_device_create(const char *parition_name)
|
||||
/* set ops */
|
||||
mtd_nor_dev->parent.ops = &_ops;
|
||||
|
||||
log_i("The FAL MTD NOR device (%s) created successfully", fal_part->name);
|
||||
LOG_I("The FAL MTD NOR device (%s) created successfully", fal_part->name);
|
||||
rt_mtd_nor_register_device(fal_part->name, &mtd_nor_dev->parent);
|
||||
}
|
||||
else
|
||||
{
|
||||
log_e("Error: no memory for create FAL MTD NOR device");
|
||||
LOG_E("Error: no memory for create FAL MTD NOR device");
|
||||
}
|
||||
|
||||
return RT_DEVICE(&mtd_nor_dev->parent);
|
||||
@@ -348,7 +354,7 @@ static rt_ssize_t char_dev_read(rt_device_t dev, rt_off_t pos, void *buffer, rt_
|
||||
int ret = 0;
|
||||
struct fal_char_device *part = (struct fal_char_device *) dev;
|
||||
|
||||
assert(part != RT_NULL);
|
||||
RT_ASSERT(part != RT_NULL);
|
||||
|
||||
if (pos + size > part->fal_part->len)
|
||||
size = part->fal_part->len - pos;
|
||||
@@ -367,7 +373,7 @@ static rt_ssize_t char_dev_write(rt_device_t dev, rt_off_t pos, const void *buff
|
||||
struct fal_char_device *part;
|
||||
|
||||
part = (struct fal_char_device *) dev;
|
||||
assert(part != RT_NULL);
|
||||
RT_ASSERT(part != RT_NULL);
|
||||
|
||||
if (pos == 0)
|
||||
{
|
||||
@@ -410,7 +416,7 @@ static int char_dev_fopen(struct dfs_file *fd)
|
||||
{
|
||||
struct fal_char_device *part = (struct fal_char_device *) fd->vnode->data;
|
||||
|
||||
assert(part != RT_NULL);
|
||||
RT_ASSERT(part != RT_NULL);
|
||||
|
||||
switch (fd->flags & O_ACCMODE)
|
||||
{
|
||||
@@ -429,12 +435,12 @@ static int char_dev_fopen(struct dfs_file *fd)
|
||||
return RT_EOK;
|
||||
}
|
||||
|
||||
static int char_dev_fread(struct dfs_file *fd, void *buf, size_t count)
|
||||
static int char_dev_fread(struct dfs_file *fd, void *buf, rt_size_t count)
|
||||
{
|
||||
int ret = 0;
|
||||
struct fal_char_device *part = (struct fal_char_device *) fd->vnode->data;
|
||||
|
||||
assert(part != RT_NULL);
|
||||
RT_ASSERT(part != RT_NULL);
|
||||
|
||||
if (DFS_FILE_POS(fd) + count > part->fal_part->len)
|
||||
count = part->fal_part->len - DFS_FILE_POS(fd);
|
||||
@@ -449,12 +455,12 @@ static int char_dev_fread(struct dfs_file *fd, void *buf, size_t count)
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int char_dev_fwrite(struct dfs_file *fd, const void *buf, size_t count)
|
||||
static int char_dev_fwrite(struct dfs_file *fd, const void *buf, rt_size_t count)
|
||||
{
|
||||
int ret = 0;
|
||||
struct fal_char_device *part = (struct fal_char_device *) fd->vnode->data;
|
||||
|
||||
assert(part != RT_NULL);
|
||||
RT_ASSERT(part != RT_NULL);
|
||||
|
||||
if (DFS_FILE_POS(fd) + count > part->fal_part->len)
|
||||
count = part->fal_part->len - DFS_FILE_POS(fd);
|
||||
@@ -498,13 +504,13 @@ struct rt_device *fal_char_device_create(const char *parition_name)
|
||||
|
||||
if (!fal_part)
|
||||
{
|
||||
log_e("Error: the partition name (%s) is not found.", parition_name);
|
||||
LOG_E("Error: the partition name (%s) is not found.", parition_name);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if ((fal_flash_device_find(fal_part->flash_name)) == NULL)
|
||||
{
|
||||
log_e("Error: the flash device name (%s) is not found.", fal_part->flash_name);
|
||||
LOG_E("Error: the flash device name (%s) is not found.", fal_part->flash_name);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -530,7 +536,7 @@ struct rt_device *fal_char_device_create(const char *parition_name)
|
||||
#endif
|
||||
|
||||
rt_device_register(RT_DEVICE(char_dev), fal_part->name, RT_DEVICE_FLAG_RDWR);
|
||||
log_i("The FAL char device (%s) created successfully", fal_part->name);
|
||||
LOG_I("The FAL char device (%s) created successfully", fal_part->name);
|
||||
|
||||
#ifdef RT_USING_POSIX_DEVIO
|
||||
/* set fops */
|
||||
@@ -540,7 +546,7 @@ struct rt_device *fal_char_device_create(const char *parition_name)
|
||||
}
|
||||
else
|
||||
{
|
||||
log_e("Error: no memory for create FAL char device");
|
||||
LOG_E("Error: no memory for create FAL char device");
|
||||
}
|
||||
|
||||
return RT_DEVICE(char_dev);
|
||||
@@ -551,7 +557,7 @@ struct rt_device *fal_char_device_create(const char *parition_name)
|
||||
#include <finsh.h>
|
||||
extern int fal_init_check(void);
|
||||
|
||||
static void fal(uint8_t argc, char **argv) {
|
||||
static void fal(rt_uint8_t argc, char **argv) {
|
||||
|
||||
#define __is_print(ch) ((unsigned int)((ch) - ' ') < 127u - ' ')
|
||||
#define HEXDUMP_WIDTH 16
|
||||
@@ -564,7 +570,7 @@ static void fal(uint8_t argc, char **argv) {
|
||||
int result = 0;
|
||||
static const struct fal_flash_dev *flash_dev = NULL;
|
||||
static const struct fal_partition *part_dev = NULL;
|
||||
size_t i = 0, j = 0;
|
||||
rt_size_t i = 0, j = 0;
|
||||
|
||||
const char* help_info[] =
|
||||
{
|
||||
@@ -593,7 +599,7 @@ static void fal(uint8_t argc, char **argv) {
|
||||
else
|
||||
{
|
||||
const char *operator = argv[1];
|
||||
uint32_t addr, size;
|
||||
rt_uint32_t addr, size;
|
||||
|
||||
if (!strcmp(operator, "probe"))
|
||||
{
|
||||
@@ -651,7 +657,7 @@ static void fal(uint8_t argc, char **argv) {
|
||||
{
|
||||
addr = strtol(argv[2], NULL, 0);
|
||||
size = strtol(argv[3], NULL, 0);
|
||||
uint8_t *data = rt_malloc(size);
|
||||
rt_uint8_t *data = rt_malloc(size);
|
||||
if (data)
|
||||
{
|
||||
if (flash_dev)
|
||||
@@ -713,7 +719,7 @@ static void fal(uint8_t argc, char **argv) {
|
||||
{
|
||||
addr = strtol(argv[2], NULL, 0);
|
||||
size = argc - 3;
|
||||
uint8_t *data = rt_malloc(size);
|
||||
rt_uint8_t *data = rt_malloc(size);
|
||||
if (data)
|
||||
{
|
||||
for (i = 0; i < size; i++)
|
||||
@@ -784,9 +790,9 @@ static void fal(uint8_t argc, char **argv) {
|
||||
return;
|
||||
}
|
||||
/* full chip benchmark test */
|
||||
uint32_t start_time, time_cast;
|
||||
size_t write_size = strtol(argv[2], NULL, 0), read_size = strtol(argv[2], NULL, 0), cur_op_size;
|
||||
uint8_t *write_data = (uint8_t *)rt_malloc(write_size), *read_data = (uint8_t *)rt_malloc(read_size);
|
||||
rt_uint32_t start_time, time_cast;
|
||||
rt_size_t write_size = strtol(argv[2], NULL, 0), read_size = strtol(argv[2], NULL, 0), cur_op_size;
|
||||
rt_uint8_t *write_data = (rt_uint8_t *)rt_malloc(write_size), *read_data = (rt_uint8_t *)rt_malloc(read_size);
|
||||
|
||||
if (write_data && read_data)
|
||||
{
|
||||
@@ -880,7 +886,7 @@ static void fal(uint8_t argc, char **argv) {
|
||||
result = fal_partition_read(part_dev, i, read_data, cur_op_size);
|
||||
}
|
||||
/* data check */
|
||||
for (size_t index = 0; index < cur_op_size; index ++)
|
||||
for (rt_size_t index = 0; index < cur_op_size; index ++)
|
||||
{
|
||||
if (write_data[index] != read_data[index])
|
||||
{
|
||||
@@ -936,4 +942,3 @@ static void fal(uint8_t argc, char **argv) {
|
||||
MSH_CMD_EXPORT(fal, FAL (Flash Abstraction Layer) operate.);
|
||||
|
||||
#endif /* defined(RT_USING_FINSH) && defined(FINSH_USING_MSH) */
|
||||
#endif /* RT_VER_NUM */
|
||||
|
Reference in New Issue
Block a user