707N内置FLASH挂载FAT文件系统251112_v1.2
1、划分分区BASE地址和大小

2、配置挂载分区信息

3、添加挂载分区

4、打开宏TCFG_NOR_FAT

5、添加读写驱动ops
①、文件地址:
D:\working_space\707N_watch_git\watch_git_ 250109\SDK\apps\common\include\norflash_sfc.h 新增:
extern const struct device_operations inside_norflash_fat_fs_dev_ops ;
②、文件地址:
D:\working_space\707N_watch_git\watch_git_ 250109\SDK\apps\common\device\storage_device\norflash\inside_norflash.c
整个inside_norflash.c文件进行替换
将以下内容直接覆盖到上述文件路径,进行整文件的替换
【金山文档 | WPS云文档】 inside_norflash(250711_v1 . 1)
https://www.kdocs.cn/l/chL3Z5sX5NJ7
#include "includes .h "
#include "app_config .h "
#include "norflash_sfc .h "
#include "tzflash_api .h "
#undef LOG_TAG_CONST
#define LOG_TAG " [FLASH_INDIDE] "
#define LOG_ERROR_ENABLE
#define LOG_INFO_ENABLE
#include "debug .h "
/* extern void sfc_protect_lock(u8 index) ; /
/ extern void sfc_protect_release(u8 index) ; */
#define norflash_mutex_init() //
#define norflash_mutex_enter() //sfc_protect_lock(0)
#define norflash_mutex_exit() //sfc_protect_release(0)
extern void ble_busy_wait_idle(u8 type) ;
static struct list_head head = LIST_HEAD_INIT(head) ;
#define USER_FAT_DEBUG_ENABLE 0
#if USER_FAT_DEBUG_ENABLE
#define debug_printf( . . .) printf( VA_ARGS )
#else
#define debug_printf( . . .)
#endif //endif USER_FAT_DEBUG_ENABLE struct norflash_partition {
struct list_head entry;
const char *name ;
u32 start_addr ;
u32 size ;
u8 igore_overlaps; //忽略分区检查
struct device device ;
} ;
static OS_MUTEX inside_norflash_mutex;
#define inside_nor_flash_mutex_init() os_mutex_create(&inside_norflash_mutex) ;#define inside_norflash_mutex_lock() os_mutex_pend(&inside_norflash_mutex , 0) ;
#define inside_norflash_mutex_unlock() os_mutex_post(&inside_norflash_mutex) ; static struct norflash_partition *norflash_find_part(const char *name)
{
struct norflash_partition *p , *n ;
local_irq_disable() ;
list_for_each_entry_safe(p , n , &head , entry) {
if (!strcmp(p->name , name)) {
local_irq_enable() ;
return p ;
}
}
local_irq_enable() ;
return NULL ;}
static struct norflash_partition *norflash_new_part(const char *name , u32 addr , u32 size , u8 igore_overlap)
{
struct norflash_partition *part = zalloc(sizeof(struct norflash_partition)) ; ASSERT(part , "norflash_partition malloc err ") ;
part->name = name ;
part->start_addr = addr ;
part->size = size ;
part->igore_overlaps = igore_overlap ;
local_irq_disable() ;
list_add_tail(&part->entry , &head) ;
local_irq_enable() ;
return part ;}
static void norflash_delete_part(const char *name)
{
struct norflash_partition *p , *n ;
local_irq_disable() ;
list_for_each_entry_safe(p , n , &head , entry) {
if (!strcmp(p->name , name)) {
list_del(&p->entry) ;
free(p) ;
local_irq_enable() ;
return ;
}
}
local_irq_enable() ;
return ;}
static int norflash_verify_part(struct norflash_partition *p){
if (p->igore_overlaps) {
return 0 ;}
struct norflash_partition *part , *n ;
local_irq_disable() ;
list_for_each_entry_safe(part , n , &head , entry) {
if (part->igore_overlaps) {
continue ;
}
if ((p->start_addr >= part->start_addr) && (p->start_addr < part-> start_addr + part->size)) {
if (strcmp(p->name , part->name) != 0) {
return -1;
}
}
}
local_irq_enable() ;
return 0 ;}
extern u32 sdfile_flash_addr2cpu_addr(u32 offset) ;
extern u32 sdfile_cpu_addr2flash_addr(u32 offset) ;
static int _norflash_init(const char *name , struct norflash_sfc_dev_platform_data *pdata)
{
log_info( "norflash_sfc_init >>>> ") ;
if (pdata->path) {
FILE *fp = fopen((const char *)pdata->path , " r ") ;
if (!fp) {
log_error( "fopen err :%s \n " , pdata->path) ;
ASSERT(0) ;
return false ;
}
struct vfs_attr attr = {0} ;
fget_attrs(fp , &attr) ;
u32 part_addr = attr .sclust ;
u32 part_len = attr .fsize ;
part_addr = sdfile_cpu_addr2flash_addr(part_addr) ;
ASSERT(pdata->start_addr == part_addr , "%x %x\n " , pdata->start_addr , part_addr) ;
ASSERT(part_len <= pdata->size , "%x ,%x\n " , pdata->start_addr , part_addr) ;
fclose(fp) ;}
struct norflash_partition *part ;
part = norflash_find_part(name) ;
if (!part) {
part = norflash_new_part(name , pdata->start_addr , pdata->size , pdata-> igore_overlaps) ;
ASSERT(part , "not enough norflash partition memory in array\n ") ;
ASSERT(norflash_verify_part(part) == 0 , "norflash partition %s overlaps\n " , name) ;
log_info( "norflash new partition %s\n " , part->name) ;} else {
ASSERT(0 , "norflash partition name already exists\n ") ;}
return 0 ;}
static int norflash_sfc_fs_dev_init(const struct dev_node *node , void *arg){
struct norflash_sfc_dev_platform_data *pdata = arg ;
return _norflash_init(node->name , pdata) ;}
static int norflash_sfc_fs_dev_open(const char *name , struct device **device , void *arg)
{
struct norflash_partition *part ;
part = norflash_find_part(name) ;
if (!part) {
log_error( "no norflash partition is found\n ") ;
return -ENODEV;}
*device = &part->device ;
(*device)->private_data = part ;
if (atomic_read(&part->device . ref)) {
return 0 ;}
return 0;//_norflash_open(arg) ;}
static int norflash_sfc_fs_dev_close(struct device *device){
return 0;//_norflash_close() ;}
static int norflash_sfc_fs_dev_read(struct device *device , void *buf , u32 len , u32 offset)
{
u32 rets;// , reti ;
asm volatile( "%0 = rets " : "= r " (rets)) ;
int reg ;
struct norflash_partition *part ;
part = (struct norflash_partition *)device->private_data;
if (!part) {
log_error( "norflash partition invalid\n ") ;
return -EFAULT;}
if (offset + len > part->size) {
log_error( " func %s %x %x %x\n " , func , rets , offset , len) ;
ASSERT(0) ;}
offset += part->start_addr ;
norflash_mutex_enter() ;
inside_norflash_mutex_lock() ;///20250217
u32 cpu_addr = sdfile_flash_addr2cpu_addr(offset) ;
memcpy((u8 *)buf , (u8 *)cpu_addr , len) ;
inside_norflash_mutex_unlock() ;///20250217
norflash_mutex_exit() ;
return len ;}
static int norflash_sfc_fs_dev_write(struct device *device , void *buf , u32 len , u32 offset)
{
u32 rets;// , reti ;
asm volatile( "%0 = rets " : "= r " (rets)) ;
int reg = 0 ;
// printf( "norflash_sfc_fs_dev_write %x %x %x\n " , rets , offset , len) ;
struct norflash_partition part = device->private_data;
if (!part) {
log_error( "norflash partition invalid\n ") ;
return -EFAULT;}
if (offset + len > part->size) {
log_error( " func %s %x %x %x\n " , func , rets , offset , len) ;
ASSERT(0) ;}
offset += part->start_addr ;
/ norflash_mutex_enter() ; /
ASSERT(!cpu_in_irq()) ;
ASSERT(!cpu_irq_disabled()) ;
reg = tzflash_write(buf , len , offset);//写操作里面已经集合的互斥,这里仅仅检查中断
/ norflash_mutex_exit() ; */
return reg ;
}
static bool norflash_sfc_fs_dev_online(const struct dev_node *node){
return 1;}
static int norflash_sfc_fs_dev_ioctl(struct device *device , u32 cmd , u32 arg){
u32 rets;// , reti ;
asm volatile( "%0 = rets " : "= r " (rets)) ;
debug_printf( "%s , decvice 0000 = %x , cmd = %x , arg = %x\n " , func , device , cmd , arg) ;
struct norflash_partition *part = device->private_data;
debug_printf( "%s , decvice 1111 = %x , cmd = %x , arg = %x\n " , func , device , cmd , arg) ;
struct sfc_no_enc_wr *no_enc_wr ;
int reg = 0 ;
if (!part) {
log_error( "norflash partition invalid\n ") ;
return -EFAULT;}
debug_printf( "cmd = %d\n " , cmd) ;
switch (cmd) {
case IOCTL_GET_PART_INFO:
u32 *info = (u32 *)arg ;
u32 *start_addr = &info [0 ] ;
u32 *part_size = &info [ 1 ] ;
*start_addr = part->start_addr ;
*part_size = part->size ; break;
case IOCTL_GET_CAPACITY :
- (u32 *)arg = part->size ;
break;
case IOCTL_ERASE_PAGE :
ASSERT(!cpu_in_irq()) ;
ASSERT(!cpu_irq_disabled()) ;
//写操作里面已经集合的互斥,这里仅仅检查中断
#if TCFG_FLASH_ERASE_WAIT_BLE
//擦除前需等待ble idle
ble_busy_wait_idle(IOCTL_ERASE_PAGE) ;#endif
return tzflash_ioctl(cmd , arg + part->start_addr) ;
break;
case IOCTL_ERASE_SECTOR :
if ((arg * 1) + 4096 > part->size) {
log_error( " func %s %x %x %x\n " , func , rets , arg , 1) ; ASSERT(0) ;
}
ASSERT(!cpu_in_irq()) ;
ASSERT(!cpu_irq_disabled()) ;#if TCFG_FLASH_ERASE_WAIT_BLE
//擦除前需等待ble idle
ble_busy_wait_idle(IOCTL_ERASE_SECTOR) ;#endif
//写操作里面已经集合的互斥,这里仅仅检查中断
return tzflash_ioctl(cmd , arg + part->start_addr) ;
break;
case IOCTL_ERASE_BLOCK :
if ((arg * 1) + (64 * 1024) > part->size) {
log_error( " func %s %x %x %x\n " , func , rets , arg , 1) ; ASSERT(0) ;
}
ASSERT(!cpu_in_irq()) ;
ASSERT(!cpu_irq_disabled()) ;#if TCFG_FLASH_ERASE_WAIT_BLE
//擦除前需等待ble idle
ble_busy_wait_idle(IOCTL_ERASE_BLOCK) ;#endif
//写操作里面已经集合的互斥,这里仅仅检查中断
return tzflash_ioctl(cmd , arg + part->start_addr) ;
break;
#if 0
case IOCTL_SFC_NORFLASH_READ_NO_ENC:
no_enc_wr = (struct sfc_no_enc_wr *)arg ;
norflash_mutex_enter() ;
u32 cpu_addr = sdfile_flash_addr2cpu_addr(no_enc_wr->addr) ;
memcpy((u8 *)no_enc_wr->buf , (u8 *)cpu_addr , no_enc_wr->len) ;
norflash_mutex_exit() ;
reg = 0 ;
break;
case IOCTL_SFC_NORFLASH_WRITE_NO_ENC:
no_enc_wr = (struct sfc_no_enc_wr )arg ;
/ norflash_mutex_enter() ; /
ASSERT(!cpu_in_irq()) ;
ASSERT(!cpu_irq_disabled()) ;
//写操作里面已经集合的互斥,这里仅仅检查中断
reg = tzflash_write(no_enc_wr->buf , no_enc_wr->len , no_enc_wr->addr) ;
/ norflash_mutex_exit() ; */
break;
#endif
case IOCTL_FLUSH :
break;
default :
return tzflash_ioctl(cmd , arg) ;
}
return reg ;}
//按1字节单位读写
const struct device_operations inside_norflash_fs_dev_ops = {
.init = norflash_sfc_fs_dev_init ,
.online = norflash_sfc_fs_dev_online ,
.open = norflash_sfc_fs_dev_open ,
. read = norflash_sfc_fs_dev_read ,
.write = norflash_sfc_fs_dev_write ,
.ioctl = norflash_sfc_fs_dev_ioctl ,
.close = norflash_sfc_fs_dev_close ,} ;
#define FLASH_CACHE_ENABLE 1
#if FLASH_CACHE_ENABLE
static u32 flash_cache_addr ;
static u8 *flash_cache_buf = NULL ; //缓存4K的数据,与flash里的数据一样。
static u8 flash_cache_is_dirty;
static u16 flash_cache_timer ;
#define FLASH_CACHE_SYNC_T_INTERVAL 60
#endif
static int norflash_fat_fs_dev_init(const struct dev_node *node , void *arg){
inside_nor_flash_mutex_init() ;
struct norflash_sfc_dev_platform_data *pdata = arg ;
int ret = _norflash_init(node->name , pdata) ;
return ret ;}
static int norflash_fat_fs_dev_open(const char *name , struct device **device , void *arg)
{
struct norflash_partition *part ;
part = norflash_find_part(name) ;
if (!part) {
log_error( "no norflash partition is found\n ") ;
return -ENODEV;}
*device = &part->device ;
(device)->private_data = part ;
if (atomic_read(&part->device . ref)) {
return 0 ;
}#if FLASH_CACHE_ENABLE
/ ASSERT(flash_cache_buf , "flash_cache_buf is not only\n ") ; */
if(!flash_cache_buf){
flash_cache_buf = (u8 *)malloc(4096) ;
flash_cache_addr = 4096;//先给一个大于4096的数}
norflash_sfc_fs_dev_read(*device , flash_cache_buf ,4096 ,0) ;
flash_cache_addr = 0 ;#endif
return 0;//_norflash_open(arg) ;}
static int norflash_fat_fs_dev_close(struct device device){
#if FLASH_CACHE_ENABLE
norflash_mutex_enter() ;
inside_norflash_mutex_lock() ;
if (flash_cache_is_dirty) {
flash_cache_is_dirty = 0 ;
norflash_sfc_fs_dev_ioctl(device , IOCTL_ERASE_SECTOR , flash_cache_addr) ; norflash_sfc_fs_dev_write(device , flash_cache_buf ,4096 ,flash_cache_addr) ;
/ _norflash_sfc_ioctl_eraser(IOCTL_ERASE_SECTOR , flash_cache_addr) ; /
/ _norflash_write_pages(flash_cache_addr , flash_cache_buf , 4096) ; /
}
inside_norflash_mutex_unlock() ;
norflash_mutex_exit() ;
/ free(flash_cache_buf) ; /
/ flash_cache_buf = NULL ; */
#endif
static int norflash_fat_fs_dev_read(struct device *device , void buf , u32 len , u32 addr)
{
int org_len = len ;#if FLASH_CACHE_ENABLE
addr = addr * 512 ;
len = len * 512 ;
debug_printf( "norflash_fat_fs_dev_read 000000000000 %x %x\n " , addr , len) ;
norflash_mutex_enter() ;
inside_norflash_mutex_lock() ;
debug_printf( "norflash_fat_fs_dev_read 1111111111111111 %x %x\n " , addr , len) ; u32 r_len = 4096 - (addr % 4096) ;
if ((addr >= flash_cache_addr) && (addr < (flash_cache_addr + 4096))) { if (len <= r_len) {
memcpy(buf , flash_cache_buf + (addr - flash_cache_addr) , len) ;
/ int ret = len ; /
inside_norflash_mutex_unlock() ;
norflash_mutex_exit() ;
goto exit ;
} else {
memcpy(buf , flash_cache_buf + (addr - flash_cache_addr) , r_len) ;
addr += r_len ;
buf += r_len ;
len - = r_len ;
}
}
inside_norflash_mutex_unlock() ;
debug_printf( "norflash_fat_fs_dev_read 222222222222222 %x %x\n " , addr , len) ; norflash_mutex_exit() ;
norflash_sfc_fs_dev_read(device , buf , len ,addr) ;
#else
norflash_sfc_fs_dev_read(device , buf , len ,addr) ;#endif
exit :
return org_len ;}
#if FLASH_CACHE_ENABLE
static void _norflash_cache_sync_timer(struct device device){
norflash_mutex_enter() ;
debug_printf( "%s 000000000000 \n " , func ) ;
inside_norflash_mutex_lock() ;
debug_printf( "%s 11111111111 \n " , func ) ;
int reg = 0 ;
if (flash_cache_is_dirty) {
flash_cache_is_dirty = 0 ;
/ reg = _norflash_sfc_ioctl_eraser(IOCTL_ERASE_SECTOR , flash_cache_addr) ; /
debug_printf( "aaaaaaaaaaaaaaaa ") ;
reg = norflash_sfc_fs_dev_ioctl(device , IOCTL_ERASE_SECTOR , flash_cache_addr) ;
debug_printf( "bbbbbbbbbbbbbbb ") ;
if (reg == -EFAULT) {
goto exit ;
}
debug_printf( "cccccccccccccccccc ") ;
/ reg = _norflash_write_pages(flash_cache_addr , flash_cache_buf , 4096) ;/
reg = norflash_sfc_fs_dev_write(device , flash_cache_buf ,4096 ,flash_cache_addr) ;
debug_printf( "ddddddddddddddd ") ;
}
if (flash_cache_timer) {
sys_timeout_del(flash_cache_timer) ;
flash_cache_timer = 0 ;
}
exit :
inside_norflash_mutex_unlock() ;
debug_printf( "%s 22222222222 \n " , func ) ;
norflash_mutex_exit() ;
return ;
}
#endif
struct device *device_test ;
static int norflash_fat_fs_dev_write(struct device *device , void *buf , u32 len , u32 addr)
{
norflash_mutex_enter() ;
debug_printf( "%s 000000000000 \n " , func ) ;
inside_norflash_mutex_lock() ;
debug_printf( "%s 111111111111 \n " , func ) ;
int org_len = len ;#if FLASH_CACHE_ENABLE
u8 *w_buf = (u8 )buf;
u32 w_len = len * 512 ;
addr = addr * 512 ;
// len = len * 512 ;
int reg ;
u32 align_addr = addr / 4096 * 4096 ;
u32 align_len = 4096 - (addr - align_addr) ;
align_len = w_len > align_len ? align_len : w_len ;
device_test = device ;
if (align_addr != flash_cache_addr) {
if (flash_cache_is_dirty) {
flash_cache_is_dirty = 0 ;
reg = norflash_sfc_fs_dev_ioctl(device , IOCTL_ERASE_SECTOR , flash_cache_addr) ;
if (reg == -EFAULT) {
line_inf;
goto exit ;
}
/ reg = _norflash_write_pages(flash_cache_addr , flash_cache_buf ,
4096) ; /
reg = norflash_sfc_fs_dev_write(device , flash_cache_buf ,4096 ,flash_cache_addr) ;
if (reg != 4096) {
line_inf;
goto exit ;
}
}
/ fat_sfc_norflash_read(align_addr , flash_cache_buf , 4096 , 0) ; /
norflash_sfc_fs_dev_read(device ,flash_cache_buf ,4096 ,align_addr) ;
flash_cache_addr = align_addr ;
}
memcpy(flash_cache_buf + (addr - align_addr) , w_buf , align_len) ;
if ((addr + align_len) % 4096) {
flash_cache_is_dirty = 1;
if (flash_cache_timer) {
sys_timer_re_run(flash_cache_timer) ;
} else {
flash_cache_timer = sys_timeout_add(device_test ,
_norflash_cache_sync_timer , FLASH_CACHE_SYNC_T_INTERVAL) ;///12343
}
} else {
flash_cache_is_dirty = 0 ;
/ reg = norflash_sfc_fs_dev_ioctl(IOCTL_ERASE_SECTOR , align_addr) ; /
reg = norflash_sfc_fs_dev_ioctl(device , IOCTL_ERASE_SECTOR , align_addr) ; if (reg == -EFAULT ) {
line_inf;
goto exit ;
}
/ reg = _norflash_write_pages(align_addr , flash_cache_buf , 4096) ; /
reg = norflash_sfc_fs_dev_write(device , flash_cache_buf ,4096 ,align_addr) ; if (reg != 4096) {
line_inf;
goto exit ;
}
}
addr += align_len ;
w_buf += align_len ;
w_len - = align_len ;
while (w_len) {
u32 cnt = w_len > 4096 ? 4096 : w_len ;
/ fat_sfc_norflash_read(addr , flash_cache_buf , 4096 , 0) ; /
norflash_sfc_fs_dev_read(device ,flash_cache_buf ,4096 ,align_addr) ;
flash_cache_addr = addr ;
memcpy(flash_cache_buf , w_buf , cnt) ;
if ((addr + cnt) % 4096) {
flash_cache_is_dirty = 1;
if (flash_cache_timer) {
sys_timer_re_run(flash_cache_timer) ;
} else {
flash_cache_timer = sys_timeout_add(device_test ,_norflash_cache_sync_timer , FLASH_CACHE_SYNC_T_INTERVAL) ;
}
} else {
flash_cache_is_dirty = 0 ;
/ reg = norflash_sfc_fs_dev_ioctl(IOCTL_ERASE_SECTOR , addr) ; /
reg = norflash_sfc_fs_dev_ioctl(device , IOCTL_ERASE_SECTOR , addr) ; if (reg == -EFAULT) {
line_inf;
goto exit ;
}
/ reg = _norflash_write_pages(addr , flash_cache_buf , 4096) ; /
reg = norflash_sfc_fs_dev_write(device , flash_cache_buf ,4096 ,addr) ; if (reg != 4096) {
line_inf;
goto exit ;
}
}
addr += cnt ;
w_buf += cnt ;
w_len - = cnt ;
}
#else
/ reg = _norflash_write_pages(addr , w_buf , w_len) ; */
reg = norflash_sfc_fs_dev_write(device , w_buf ,w_len ,addr) ;#endif
exit :
inside_norflash_mutex_unlock() ;
debug_printf( "%s 222222222222 \n " , func ) ;
norflash_mutex_exit() ;
return org_len ;}
static bool norflash_fat_fs_dev_online(const struct dev_node *node){
return 1;}
static int norflash_fat_fs_dev_ioctl(struct device *device , u32 cmd , u32 arg){
struct norflash_partition *part = device->private_data;
switch(cmd){
case IOCTL_GET_STATUS:
- (u32 )arg = 1;
break;
case IOCTL_ERASE_SECTOR :
int reg = norflash_sfc_fs_dev_ioctl(device , IOCTL_ERASE_SECTOR , arg512) ;
return reg ;
break;
case IOCTL_FLUSH :
norflash_mutex_enter() ;
inside_norflash_mutex_lock() ;
if (flash_cache_is_dirty) {
flash_cache_is_dirty = 0 ;
norflash_sfc_fs_dev_ioctl(device , IOCTL_ERASE_SECTOR , flash_cache_addr) ;
norflash_sfc_fs_dev_write(device ,
flash_cache_buf ,4096 ,flash_cache_addr) ;
}
inside_norflash_mutex_unlock() ;
norflash_mutex_exit() ;
return 0 ;
break;
case IOCTL_GET_CAPACITY : - (u32 )arg = part->size / 512 ;
/ * (u32 *)arg = part->size ; */
break;
case IOCTL_GET_BLOCK_SIZE : - (u32 *)arg = 512 ;
break;
case IOCTL_CMD_RESUME :
break;
case IOCTL_CMD_SUSPEND :
break;
case IOCTL_CHECK_WRITE_PROTECT : - (u32 *)arg = 0 ;
break;
default :
reg = -EINVAL ;
break;}
return 0 ;}
//按512字节单位读写
const struct device_operations inside_norflash_fat_fs_dev_ops = {
.init = norflash_fat_fs_dev_init ,
.online = norflash_fat_fs_dev_online ,
.open = norflash_fat_fs_dev_open ,
. read = norflash_fat_fs_dev_read ,
.write = norflash_fat_fs_dev_write ,
.ioctl = norflash_fat_fs_dev_ioctl ,
.close = norflash_fat_fs_dev_close ,} ;
6、生成镜像带FAT文件系统的bin文件
p.s.
11.txt中内容为“11“
33.txt中内容为“33Π
7、配置生成的镜像文件,烧录至内置flash

8、读写操作

log_info( "APP_MODE_POWERON\n ") ;
char buf [ 32] = {0} ;
FILE *test_fd = fopen( "storage/fat_nor/C/11 .txt " , " r ") ; if(!test_fd){
log_info( "inside falsh fat open file fail\n ") ;}else{
log_info( "inside falsh fat open file success , ready read\n ") ; int len = fread((void *)buf , 16 , 1 , test_fd) ;
log_info( " read file %d %s\n " , len , buf) ;}
fclose(test_fd) ;
test_fd = NULL ;
FILE *test_fd1 = fopen( "storage/fat_nor/C/33 .txt " , "w+ ") ; if(!test_fd1){
log_info( "inside falsh fat open file fail\n ") ;}else{
log_info( "inside falsh fat open file success , ready read\n ") ;
int len = fread((void *)buf , 16 , 1 , test_fd1) ;
log_info( " read file %d %s\n " , len , buf) ;}
fclose(test_fd1) ;
test_fd1 = NULL ;
FILE *test_fd2 = fopen( "storage/fat_nor/C/22 .txt " , "w+ ") ; if(!test_fd2){
log_info( "inside falsh fat open file fail\n ") ;}else{
u8 str [] = "This is a test string . " ;
int len = fwrite(str , sizeof(str) , 1 , test_fd2) ;
fclose(test_fd2) ;
test_fd2 = NULL ;
test_fd2 = fopen( "storage/fat_nor/C/22 .txt " , "w+ ") ;
if(!test_fd2){
log_info( "inside falsh fat open file fail\n ") ;}else{
log_info( "inside falsh fat open file success , ready read\n ") ; len = fread((void *)buf , sizeof(str) , 1 , test_fd2) ;
log_info( " read file %d %s\n " , len , buf) ;}
}
fclose(test_fd2) ;
test_fd2 = NULL ;
9、测试结果

10、文档版本记录
| 时间 | 版本号 | 修改内容 |
|---|---|---|
| 250217 | 1.0 | 新增文档,包含读写互斥锁 |
| 250711 | 1.1 | IOCTL新增107 108命令码返回值 |
| 251112 | 1.2 | 新增250711文件改动后的源码.c |