Files
DCU_APP/GD32E508_DCU_APP/shared/ota_layout.h
T

60 lines
3.1 KiB
C
Raw Normal View History

/**
* @file ota_layout.h
* @brief APP/BOOT 共用 OTA Flash 布局(唯一真源)。
* @note 两侧 sys/config.h 都必须 include 本头,禁止再抄地址常量。
* 相对路径:BOOT/APP 的 sys/config.h → ../../../shared/ota_layout.h
*
* 约定:0x00000000=AVAL(有效),0xFFFFFFFF=NOT_AVAL(擦除态/无效)。
*/
#ifndef SHARED_OTA_LAYOUT_H
#define SHARED_OTA_LAYOUT_H
#include <stdint.h>
/* ---- 整片 Flash 区段(GD32E508VE 512KB) ---- */
#define OTA_LAYOUT_BOOT_START 0x08000000U
#define OTA_LAYOUT_BOOT_SIZE 0x00012000U /* 72KB */
#define OTA_LAYOUT_APP_BACK_START 0x08012000U /* 216KB 备份区 */
#define OTA_LAYOUT_APP_MAIN_START 0x08048000U /* 216KB 主应用区 = APP VTOR */
#define OTA_LAYOUT_APP_MAX_SIZE 0x00035FFCU /* 216KB-4B,末尾 CRC32 */
#define OTA_LAYOUT_CONFIG_PAGE 0x0807E000U /* OTA 状态配置页 2KB */
#define OTA_LAYOUT_SLEEP_PAGE 0x0807E800U /* 睡眠配置页 2KB */
#define OTA_LAYOUT_PAGE_SIZE 0x00000800U /* FMC 单页 2KB */
/* ---- OTA 配置页 word 布局(word N = PAGE + 4*N) ---- */
#define OTA_LAYOUT_WORD_LATEST_AVAL 0U
#define OTA_LAYOUT_WORD_BACKUP_AVAL 1U
#define OTA_LAYOUT_WORD_LATEST_EN 2U
#define OTA_LAYOUT_WORD_BACKUP_EN 3U
#define OTA_LAYOUT_WORD_LATEST_CHECK 4U
#define OTA_LAYOUT_WORD_BACKUP_CHECK 5U
#define OTA_LAYOUT_WORD_BOOT_VER0 6U /* major|minor */
#define OTA_LAYOUT_WORD_BOOT_VER1 7U /* patch|build */
#define OTA_LAYOUT_WORD_ECAT_ARM 8U /* 0xACA70001 才允许 ECAT SDO 刷 APP */
#define OTA_LAYOUT_WORD_CRASH_COUNT 9U /* 连续 FWDGT 崩溃次数;APP 起板成功清 0 */
#define OTA_LAYOUT_ADDR_LATEST_AVAL (OTA_LAYOUT_CONFIG_PAGE + 4U * OTA_LAYOUT_WORD_LATEST_AVAL)
#define OTA_LAYOUT_ADDR_BACKUP_AVAL (OTA_LAYOUT_CONFIG_PAGE + 4U * OTA_LAYOUT_WORD_BACKUP_AVAL)
#define OTA_LAYOUT_ADDR_LATEST_EN (OTA_LAYOUT_CONFIG_PAGE + 4U * OTA_LAYOUT_WORD_LATEST_EN)
#define OTA_LAYOUT_ADDR_BACKUP_EN (OTA_LAYOUT_CONFIG_PAGE + 4U * OTA_LAYOUT_WORD_BACKUP_EN)
#define OTA_LAYOUT_ADDR_LATEST_CHECK (OTA_LAYOUT_CONFIG_PAGE + 4U * OTA_LAYOUT_WORD_LATEST_CHECK)
#define OTA_LAYOUT_ADDR_BACKUP_CHECK (OTA_LAYOUT_CONFIG_PAGE + 4U * OTA_LAYOUT_WORD_BACKUP_CHECK)
#define OTA_LAYOUT_ADDR_BOOT_VER0 (OTA_LAYOUT_CONFIG_PAGE + 4U * OTA_LAYOUT_WORD_BOOT_VER0)
#define OTA_LAYOUT_ADDR_BOOT_VER1 (OTA_LAYOUT_CONFIG_PAGE + 4U * OTA_LAYOUT_WORD_BOOT_VER1)
#define OTA_LAYOUT_ADDR_ECAT_ARM (OTA_LAYOUT_CONFIG_PAGE + 4U * OTA_LAYOUT_WORD_ECAT_ARM)
#define OTA_LAYOUT_ADDR_CRASH_COUNT (OTA_LAYOUT_CONFIG_PAGE + 4U * OTA_LAYOUT_WORD_CRASH_COUNT)
/** 配置页有效 word 数(擦页回写必须覆盖到此);页 2KB,余量充足。 */
#define OTA_LAYOUT_WORD_COUNT 10U
/** ECAT 下载 arm 令牌。避开擦除态与 AVAL。 */
#define OTA_LAYOUT_ECAT_ARM_KEY 0xACA70001U
/** 连续 FWDGT 达到该次数后 BOOT 停止自动跳 APP,只接受外部灌写。 */
#define OTA_LAYOUT_CRASH_STAY_MAX 3U
#define OTA_LAYOUT_AVAL 0x00000000U
#define OTA_LAYOUT_NOT_AVAL 0xFFFFFFFFU
#endif /* SHARED_OTA_LAYOUT_H */