feat(boot): 升级改造为A/B分区(新固件先下B区整包校验后搬运A区)

分区: Boot 32KB | A区0x8000(29扇区232KB,运行) | B区0x42000(29扇区232KB,暂存) | 参数区0x7C000不变
流程: 仅擦B区下载→CRC32(B)通过→逐扇区搬运B→A→CRC32(A)通过→擦B区→置APP_BOOT_UPGRADE_FLAG复位
防变砖: 下载超时/CRC失败/AppSize非法均恢复APP_START_FLAG复位回老App; 断电续传靠重启后B区CRC判定
其他: GetCrc32/AppWriteFlash/EraseFlash基址参数化, FlashWrite尾字节0xFF补齐, 0x82增加状态守卫
协议与boot_para_t结构不变, 主机升级工具无需修改
This commit is contained in:
2026-09-23 11:16:47 +08:00
parent ffaf7a55a6
commit 48ed25015d
4 changed files with 140 additions and 38 deletions
+13 -10
View File
@@ -172,16 +172,16 @@ typedef enum {
/*当前设备版本/项目选择*/
#define GATEWAY_VER_INFO GATEWAY_VER1_0 //版本信息
#define GATEWAY_PRJ_NUM GATEWAY_PRJ_YAXIA //项目编号
#define GATEWAY_GW_NUM 0x0008 //网关编号(2字节, 1~65535)
#define GATEWAY_GW_NUM 0x0000 //网关编号(2字节, 1~65535)
/*CAT1服务器/Lora配置 - 替代原MAC_ADDR_TYPE编译宏, 在Boot中直接配置*/
#define GATEWAY_SVR_ADDR0 39 //服务器IP[0]
#define GATEWAY_SVR_ADDR1 106 //服务器IP[1]
#define GATEWAY_SVR_ADDR2 103 //服务器IP[2]
#define GATEWAY_SVR_ADDR3 147 //服务器IP[3]
#define GATEWAY_SVR_PORT 8088 //服务器端口
#define GATEWAY_SVR_PORT 8080 //服务器端口
#define GATEWAY_LORA_FREQ CH8 //Lora中心频率(可配置为CH0~CH119)
#define GATEWAY_LORA_FREQ CH0 //Lora中心频率(可配置为CH0~CH119)
/*默认通道配置 - 在Boot中直接配置, 替代原APP硬编码默认值*/
#define GATEWAY_MUCH CH_ETH //主上传通道
@@ -191,7 +191,7 @@ typedef enum {
/*********************************下载前必须检查配置项************************************/
/*****************************************************************************************/
/*Flash分区 - 32KB Boot + APP(0x8000起) + 参数区(0x7C000)*/
/*Flash分区 - 32KB Boot + APP_A区(0x8000,232KB,运行) + APP_B区(0x42000,232KB,升级暂存) + 参数区(0x7C000)*/
#define FLASH_SECTOR_SIZE 0x2000ul //8KB
#define FLASH_BASE ((uint32_t)0x00000000)
#define FLASH_SIZE (64u * FLASH_SECTOR_SIZE) //512KB
@@ -199,10 +199,13 @@ typedef enum {
#define SRAM_BASE ((uint32_t)0x1FFF8000)
#define SRAM_SIZE 0x2F000ul //192KB
#define BOOT_SIZE (4 * FLASH_SECTOR_SIZE) //32KB
#define APP_ADDRESS (FLASH_BASE + BOOT_SIZE) //0x8000
#define APP_SIZE (58 * FLASH_SECTOR_SIZE) //464KB
#define BOOT_PARA_ADDRESS (APP_ADDRESS + APP_SIZE) //0x7C000
#define BOOT_SIZE (4 * FLASH_SECTOR_SIZE) //32KB
#define APP_A_ADDRESS (FLASH_BASE + BOOT_SIZE) //0x8000 A区: 当前运行App
#define APP_BANK_SECTORS (29u) //A/B区各29扇区(232KB)
#define APP_BANK_SIZE (APP_BANK_SECTORS * FLASH_SECTOR_SIZE) //232KB
#define APP_B_ADDRESS (APP_A_ADDRESS + APP_BANK_SIZE) //0x42000 B区: 升级暂存
#define APP_ADDRESS APP_A_ADDRESS //兼容旧名, 指向A区
#define BOOT_PARA_ADDRESS (APP_B_ADDRESS + APP_BANK_SIZE) //0x7C000
#define BOOT_PARA_SIZE (FLASH_SECTOR_SIZE)
#define DEBUG 1
@@ -303,10 +306,10 @@ void FeedDog(void);
void Error_Handler(void);
/*Flash操作*/
void FlashWrite(uint32_t Addr, uint32_t *wData, uint8_t wLen);
void FlashWrite(uint32_t Addr, uint32_t *wData, int wLen);
void ReadBootPara(BootPara rData);
void WriteBootPara(BootPara wData);
void EraseFlash(void);
void EraseFlash(uint32_t BaseAddr, uint32_t SectorCnt);
#endif
+2
View File
@@ -52,6 +52,7 @@ typedef enum {
BL_WAIT_REV,
BL_GET_DATA_TIMEOUT,
BL_START_APP,
BL_COPY_TO_A, //B区镜像搬运到A区阶段
BL_RESET
}BootStatus_m;
@@ -62,6 +63,7 @@ typedef struct {
uint32_t AppPackageCnt;
uint32_t AppPackageIdx;
uint32_t RevErrCnt;
uint32_t CopyRetryCnt; //搬运重试计数
uint32_t FeedDogDlyCnt;
uint32_t BootLoader1mSDlyCnt;