由 小何 贡献,Ai-Thinker 进行整理
AI-WB2的easyflash文件系统,刷写程序、OTA后不掉数据哦
移植easyflash和另一个spiffs文件系统刷写程序、OTA后不掉数据原理都差不多,这里再说一次
查看项目下的Make File
This is a project Makefile. It is assumed the directory this Makefile resides in is a
project subdirectory.
PROJECT_NAME := LivingRoomCock PROJECT_PATH := $(abspath .) PROJECT_BOARD := evb export PROJECT_PATH PROJECT_BOARD #CONFIG_TOOLPREFIX :=
-include ./proj_config.mk
ifeq ($(origin BL60X_SDK_PATH), undefined) BL60X_SDK_PATH_GUESS ?= $(shell pwd) BL60X_SDK_PATH ?=
(info ****** Please SET BL60X_SDK_PATH ******) (BL60X_SDK_PATH)]) endif COMPONENTS_NETWORK := sntp dns_server COMPONENTS_BLSYS := bltime blfdt blmtd blota bloop loopadc looprt loopset COMPONENTS_VFS := romfs cjson
INCLUDE_COMPONENTS += freertos_riscv_ram bl602 bl602_std newlibc wifi wifi_manager wpa_supplicant bl602_os_adapter wifi_hosal hosal mbedtls_lts lwip lwip_dhcpd vfs yloop utils cli aws-iot httpc httpd dns_server netutils blog blog_testc INCLUDE_COMPONENTS += easyflash4 coredump lwip_altcp_tls_mbedtls blcrypto_suite bl_os_adapter rfparam_adapter_tmp spiffs
INCLUDE_COMPONENTS += $(COMPONENTS_NETWORK) INCLUDE_COMPONENTS += $(COMPONENTS_BLSYS) INCLUDE_COMPONENTS += $(COMPONENTS_VFS) INCLUDE_COMPONENTS += $(PROJECT_NAME)
include $(BL60X_SDK_PATH)/make_scripts_riscv/project.mk
最终调用make_scripts_riscv/project.mk
flash-only: cd
(APP_BIN) SDK_BOARD= (PROJECT_NAME) SDK_MEDIA_BIN= (APP_ROMFS_DIR) SDK_DTS= (PROJECT_BOARD_XTAL) BL_FLASH_TOOL_INPUT_PATH_cfg2_bin_input=$(APP_BIN) (SERIAL_BAUDRATE) --port= (BL60X_SDK_PATH)/tools/flash_tool/chips/bl602/partition/partition_cfg_4M.toml --dts= (BL60X_SDK_PATH)/tools/flash_tool/chips/bl602/builtin_imgs/boot2_isp_bl602_v6.5.1/boot2_iap_release.bin --firmware=$(APP_BIN)
最终得出Flash分区文是/tools/flash_tool/chips/bl602/partition/partition_cfg_4M.toml。 备份文件partition_cfg_4M.toml文件
增加easyflash文件系统分区
[pt_table] #partition table is 4K in size address0 = 0xE000 address1 = 0xF000
[[pt_entry]]
📜 点击展开完整代码
type = 0
name = "FW"
device = 0
address0 = 0x10000
size0 = 0x100000
address1 = 0x110000
size1 = 0x100000compressed image must set len,normal image can left it to 0
len = 0
[[pt_entry]]
📜 点击展开完整代码
type = 0
name = "spiffs"
device = 0
address0 = 0x210000
size0 = 0x28000
address1 = 0x238000
size1 = 0x8000compressed image must set len,normal image can left it to 0
len = 0
[[pt_entry]]
📜 点击展开完整代码
type = 2
name = "mfg"
device = 0
address0 = 0x240000
size0 = 0x32000
address1 = 0
size1 = 0compressed image must set len,normal image can left it to 0
len = 0
[[pt_entry]]
📜 点击展开完整代码
type = 3
name = "media"
device = 0
address0 = 0x272000
size0 = 0x1000
address1 = 0
size1 = 0compressed image must set len,normal image can left it to 0
len = 0
[[pt_entry]]
📜 点击展开完整代码
type = 4
name = "PSM"
device = 0
address0 = 0x273000
size0 = 0x33000
address1 = 0
size1 = 0compressed image must set len,normal image can left it to 0
len = 0
[[pt_entry]]
📜 点击展开完整代码
type = 5
name = "KEY"
device = 0
address0 = 0x2A6000
size0 = 0x2000
address1 = 0
size1 = 0compressed image must set len,normal image can left it to 0
len = 0
[[pt_entry]]
📜 点击展开完整代码
type = 6
name = "DATA"
device = 0
address0 = 0x2A8000
size0 = 0x5000
address1 = 0
size1 = 0compressed image must set len,normal image can left it to 0
len = 0
[[pt_entry]]
📜 点击展开完整代码
type = 7
name = "factory"
device = 0
address0 = 0x2AD000
size0 = 0x7000
address1 = 0
size1 = 0compressed image must set len,normal image can left it to 0
len = 0
#if user want to put RF calibration data on flash, uncomment following pt entry #[[pt_entry]] #type = 8 #name = "rf_para" #device = 0 #address0 = 0x1FF000 #size0 = 0x1000 #address1 = 0 #size1 = 0
compressed image must set len,normal image can left it to 0
#len = 0
[[pt_entry]]
📜 点击展开完整代码
type = 0
name = "spiffs"
device = 0
address0 = 0x210000 ##给spiffs文件系统用,开始地址
size0 = 0x28000 ##给spiffs文件系统用,大小
address1 = 0x238000 ##给easyflash文件系统用,开始地址
size1 = 0x8000 ##给easyflash文件系统用,大小compressed image must set len,normal image can left it to 0
len = 0
修改安信可已移植好的ef_port.c
/*
- This file is part of the EasyFlash Library.
- Copyright (c) 2015, Armink, <armink.ztl@gmail.com>
- 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.
- Function: Portable interface for each platform.
- Created on: 2015-01-16 */
#include <easyflash.h> #include <stdarg.h> #include <stdio.h> #include <string.h> #include <FreeRTOS.h> #include <semphr.h> #include <bl_mtd.h> #include <ef_cfg.h> #include <hosal_flash.h> #include <hal_boot2.h>
uint32_t ENV_AREA_SIZE; uint32_t SECTOR_NUM; uint32_t EF_START_ADDR;
/* default environment variables set for user */ static const ef_env default_env_set[] = { {"boot_times", "3", 1} };
static SemaphoreHandle_t env_cache_lock = NULL;
/**
- Flash port for hardware initialize.
- @param default_env default ENV set for user
- @param default_env_size default ENV size
- @return result */ EfErrCode ef_port_init(ef_env const **default_env, size_t *default_env_size) { uint32_t addr0, addr1; uint32_t size0, size1; int active, ret;
ret = hal_boot2_partition_addr("spiffs",&addr0,&addr1,&size0,&size1,&active);
if (size1 < 8 * 1024) { //printf("[ERROR]psm partition is less than 8k,easyflash can not work!"); return EF_ENV_INIT_FAILED; } else{ EF_START_ADDR = addr1; ENV_AREA_SIZE = (size1 / EF_ERASE_MIN_SIZE) * EF_ERASE_MIN_SIZE; SECTOR_NUM = ENV_AREA_SIZE / EF_ERASE_MIN_SIZE; //printf("ENV AREA SIZE %ld, SECTOR NUM %ld\r\n", ENV_AREA_SIZE, SECTOR_NUM);
*default_env = default_env_set; *default_env_size = sizeof(default_env_set) / sizeof(default_env_set[0]);
//printf("*default_env_size = 0x%08x\r\n", *default_env_size);
#if configUSE_RECURSIVE_MUTEXES env_cache_lock = xSemaphoreCreateRecursiveMutex(); #else env_cache_lock = xSemaphoreCreateMutex(); #endif return EF_NO_ERR; } }
/**
- Read data from flash.
- @note This operation's units is word.
- @param addr flash address
- @param buf buffer to store read data
- @param size read bytes size
- @return result */ EfErrCode ef_port_read(uint32_t addr, uint32_t *buf, size_t size) { EfErrCode result = EF_NO_ERR;
if(hosal_flash_raw_read((uint32_t*)buf, addr, size) != 0){ //printf("--------EF_READ_ERR--------"); result = EF_READ_ERR; } //printf("--------ef_port_read--------%ld;%lx;%d",*buf,addr,size); return result; }
/**
- Erase data on flash.
- @note This operation is irreversible.
- @note This operation's units is different which on many chips.
- @param addr flash address
- @param size erase bytes size
- @return result */ EfErrCode ef_port_erase(uint32_t addr, size_t size) { EfErrCode result = EF_NO_ERR;
/* make sure the start address is a multiple of EF_ERASE_MIN_SIZE */ EF_ASSERT(addr % EF_ERASE_MIN_SIZE == 0);
if(hosal_flash_raw_erase(addr, size) != 0){ //printf("--------EF_ERASE_ERR--------"); result = EF_ERASE_ERR; } //printf("--------ef_port_erase--------%lx;%d",addr,size); return result; } /**
- Write data to flash.
- @note This operation's units is word.
- @note This operation must after erase. @see flash_erase.
- @param addr flash address
- @param buf the write data buffer
- @param size write bytes size
- @return result */ EfErrCode ef_port_write(uint32_t addr, const uint32_t buf, size_t size) { EfErrCode result = EF_NO_ERR; if(hosal_flash_raw_write((const uint32_t)buf, addr, size) != 0){ //printf("--------EF_WRITE_ERR--------"); result = EF_WRITE_ERR; }
//printf("--------ef_port_write--------%ld;%lx;%d",*buf,addr,size); return result; }
/**
- lock the ENV ram cache / void ef_port_env_lock(void) { #if configUSE_RECURSIVE_MUTEXES xSemaphoreTakeRecursive(env_cache_lock, portMAX_DELAY); #else / You can add your code under here. */ xSemaphoreTake( env_cache_lock, portMAX_DELAY ); #endif
}
/**
- unlock the ENV ram cache / void ef_port_env_unlock(void) { #if configUSE_RECURSIVE_MUTEXES xSemaphoreGiveRecursive(env_cache_lock); #else / You can add your code under here. */ xSemaphoreGive( env_cache_lock ); #endif }
extern void vprint(const char fmt, va_list argp); /*
- This function is print flash debug info.
- @param file the file which has call this function
- @param line the line number which has call this function
- @param format output format
- @param ... args
*/ void ef_log_debug(const char *file, const long line, const char *format, ...) {
#ifdef PRINT_DEBUG
va_list args;
/* args point to the first variable parameter */ va_start(args, format);
/* You can add your code under here. */ vprint(format, args);
va_end(args);
#endif
}
/**
- This function is print flash routine info.
- @param format output format
- @param ... args */ void ef_log_info(const char *format, ...) { va_list args;
/* args point to the first variable parameter */ va_start(args, format);
/* You can add your code under here. / vprint(format, args); va_end(args); } /*
- This function is print flash non-package info.
- @param format output format
- @param ... args */ void ef_print(const char *format, ...) { va_list args;
📜 点击展开完整代码
/* args point to the first variable parameter */
va_start(args, format);
/* You can add your code under here. */
vprint(format, args);
va_end(args);
}
hal_boot2_partition_addr("spiffs",&addr0,&addr1,&size0,&size1,&active);这个函数可以得到分区文件partition_cfg_4M.toml的开始地址和大小。修改spiffs的起始地址和大小,cfg.phys_addr = addr0;cfg.phys_size = size0;spiffs文件系统就存在flash这个空间,烧写程序和OAT升级都不会破坏这个空间,也就是spiffs数据不会丢失。
ret = hal_boot2_partition_addr("spiffs",&addr0,&addr1,&size0,&size1,&active);
if (size1 < 8 * 1024) {
//printf("[ERROR]psm partition is less than 8k,easyflash can not work!");
return EF_ENV_INIT_FAILED;
}
else{
EF_START_ADDR = addr1;
ENV_AREA_SIZE = (size1 / EF_ERASE_MIN_SIZE) * EF_ERASE_MIN_SIZE;
SECTOR_NUM = ENV_AREA_SIZE / EF_ERASE_MIN_SIZE;这个给easyflash使用。烧写程序和OAT升级都不会破坏这个空间,也就是easyflash 数据不会丢失。
上传的附件: 
新建文件夹.rar(580.25 KB, 下载次数: 8)

