MW22-02A/BSP/Driver/getcfg/config_info.h

110 lines
4.8 KiB
C
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#ifndef _CONFIG_INFO_H_
#define _CONFIG_INFO_H_
#include "comm_types.h"
#ifdef __cplusplus
extern "C" {
#endif
#pragma pack(push,1)
#define EXT_FLASH_SECTOR_SIZE (1024*4)
#define EXT_FLASH_BLOCK_NUM (0)
#define EXT_FLASH_BLOCK_NUM_1 (1)
//升级包在片外flash缓存时使用的地址信息
#define UPGRADE_FLASH_BUFF_BEGIN_ADDR (1024*1024*1)//1M-2M
#define UPGRADE_FLASH_BUFF_END_ADDR (1024*1024*2-1)
#define UPGRADE_FLASH_BUFF_SIZE (1024*1024*1)
#define UPGRADE_FLASH_BUFF_BEGIN_BLOCK (UPGRADE_FLASH_BUFF_BEGIN_ADDR / Flash_BLOCKBYTE_LENGTH)
//bootloader地址信息
#define BOOTLOADER_ADDR_BEGIN (0)
#define BOOTLOADER_ADDR_END (1024*58-1)
#define BOOTLOADER_SECTOR_BEGIN (BOOTLOADER_ADDR_BEGIN / ON_CHIP_FLASH_SECTOR_SIZE) //Bootloader起始sector
//应用程序地址信息
#define APP_ADDR_BEGIN (1024*64)
#define APP_ADDR_END (1024*500-1)//500k
#define APP_SECTOR_BEGIN (APP_ADDR_BEGIN / ON_CHIP_FLASH_SECTOR_SIZE) //应用程序起始sector
//安全证书地址信息--放在w25q128中
#define CERT_ADDR_BEGIN (1024*4*2)//0block 2sector(4k) 包头放在1sector
#define CERT_ADDR_END (1024*4*3-1)
#define CERT_SECTOR_BEGIN (CERT_ADDR_BEGIN / EXT_FLASH_SECTOR_SIZE)//安全加密芯片证书
//密钥地址信息--放在w25q128中
#define KEY_ADDR_BEGIN (1024*4*4)//0block 4sector(4k) 包头放在3sector
#define KEY_ADDR_END (1024*4*5-1)
#define KEY_SECTOR_BEGIN (KEY_ADDR_BEGIN / EXT_FLASH_SECTOR_SIZE)//安全加密芯片密钥
//配置文件地址信息--放在w25q128中
#define CFG_FILE_ADDR_BEGIN (1024*4*6)//0block 6sector(4k) 包头放在5sector
#define CFG_FILE_ADDR_END (1024*4*7-1)
#define CFG_FILE_SECTOR_BEGIN (CFG_FILE_ADDR_BEGIN / EXT_FLASH_SECTOR_SIZE)//配置文件
//应用程序包头存储地址信息在应用程序前2个sector保存
#define APP_PKG_HEAD_BEGIN (APP_ADDR_BEGIN - ON_CHIP_FLASH_SECTOR_SIZE)
#define APP_PKG_HEAD_END (APP_ADDR_BEGIN-1)
#define APP_PKG_HEAD_SECTOR_BEGIN (APP_PKG_HEAD_BEGIN/ON_CHIP_FLASH_SECTOR_SIZE)//头存储的sector
#define APP_PGK_HEAD ((hy_release_file_head*)APP_PKG_HEAD_BEGIN)
//安全证书包头存储地址信息在芯片安全证书前1个sector保存
#define CERT_HEAD_BEGIN (CERT_ADDR_BEGIN - EXT_FLASH_SECTOR_SIZE)
#define CERT_HEAD_END (CERT_ADDR_BEGIN-1)
#define CERT_HEAD_SECTOR_BEGIN (CERT_HEAD_BEGIN/EXT_FLASH_SECTOR_SIZE)//头存储的sector
//密钥包头存储地址信息在密钥前2个sector保存
#define KEY_HEAD_BEGIN (KEY_ADDR_BEGIN - EXT_FLASH_SECTOR_SIZE)
#define KEY_HEAD_END (KEY_ADDR_BEGIN-1)
#define KEY_HEAD_SECTOR_BEGIN (KEY_HEAD_BEGIN/EXT_FLASH_SECTOR_SIZE)//头存储的sector
//配置文件包头存储地址信息在配置文件前2个sector保存
#define CFG_FILE_HEAD_BEGIN (CFG_FILE_ADDR_BEGIN - EXT_FLASH_SECTOR_SIZE)
#define CFG_FILE_HEAD_END (CFG_FILE_ADDR_BEGIN-1)
#define CFG_FILE_HEAD_SECTOR_BEGIN (CFG_FILE_HEAD_BEGIN/EXT_FLASH_SECTOR_SIZE)//头存储的sector
#define HY_RELEASE_FILE_FLAG (*((u_int32_t *)"HYPK"))
#define HY_PKG_TYPE_APP 1 //升级文件类型是application应用程序
#define HY_PKG_TYPE_BOOT_LOADER 2 //升级文件类型是bootloader
#define HY_PKG_TYPE_CERT 3 //加密芯片证书
#define HY_PKG_TYPE_PUB_KEY 4 //公钥
#define HY_PKG_TYPE_CFG_FILE 5 //配置文件
//发布包文件头--------------------------------------------------------------------
typedef struct _hy_release_file_head{
u_int32_t flag; // 4byte 标志,必须为"HYPK" 如果文件不是以此开头,则认为是非法文件
u_int32_t head_len; //4byte 头长度 文件头长度,包含"标志"
u_int8_t file_type; //1byte 文件类型1 1应用程序升级包 2:bootloader
u_int16_t file_format_ver; //2byte 文件格式版本号1 用于确定文件的处理方式
u_int8_t hardware_type[2]; //2byte 硬件类型 升级包适用的硬件类型
u_int16_t hardware_ver; //2byte 硬件版本 升级包适用的硬件版本
u_int32_t software_ver; //4byte 软件版本 本升级包的应用软件版本
u_int32_t data_len; //4byte 数据长度 不包含2个字节的crc
u_int32_t addr; //4byte 烧写地址
u_int8_t head_checksum; //1byte 头校验 以上内容的checksum包括"标志",单字节异或
u_int8_t data[1]; //数据
}hy_release_file_head;
#define RELEASE_PKG_HEAD_SIZE(x) ((char *)(&(x)->head_checksum) - (char *)(x) + sizeof(u_int8_t))//不包含数据
#define RELEASE_PKG_CRC16(x) (*(u_int16_t *)(&((x)->data[(x)->data_len])))
#define RELEASE_PKG_TOTAL_LEN(x) ((x)->data_len + RELEASE_PKG_HEAD_SIZE(x)+sizeof(u_int16_t))//总长度
//函数声明
BOOL get_cert1_from_file(void);
BOOL get_key_from_file(void);
BOOL get_system_config_from_file(void);
BOOL write_file_to_ext_flash(hy_release_file_head *pkg_head);
BOOL write_pack_head_to_ext_flash(hy_release_file_head *pkg_head);
BOOL app_crc_OK(u_int8_t file_type);
BOOL ext_flash_erase(hy_release_file_head *pkg_head);
u_int8_t upgrade_pkg_head_checksum_OK(hy_release_file_head *pkg_head);
BOOL pack_head_verify(u_int8_t file_type);
void erase_ext_flash(u_int8_t block_begin,u_int32_t total_len);
#pragma pack(pop)
#ifdef __cplusplus
}
#endif
#endif //_CONFIG_INFO_H_