改为 在压缩前添加 oem_ext 但固件启动不起来

This commit is contained in:
2024-10-28 19:37:39 +08:00
parent 538d4b4ac4
commit 8b0435853d
8 changed files with 128 additions and 100 deletions

View File

@@ -11,40 +11,43 @@ import sys
env_dict=os.environ.copy() env_dict=os.environ.copy()
env_dict.pop('SHELL',None) _pop_list=[
env_dict.pop('COLORTERM',None) 'SHELL',
env_dict.pop('TERM_PROGRAM_VERSION',None) 'COLORTERM',
env_dict.pop('LANGUAGE',None) 'TERM_PROGRAM_VERSION',
env_dict.pop('XDG_SESSION_TYPE',None) 'LANGUAGE',
env_dict.pop('VSCODE_GIT_ASKPASS_NODE',None) 'XDG_SESSION_TYPE',
env_dict.pop('MOTD_SHOWN',None) 'VSCODE_GIT_ASKPASS_NODE',
env_dict.pop('HOME',None) 'MOTD_SHOWN',
env_dict.pop('LANG',None) 'HOME',
env_dict.pop('LS_COLORS',None) 'LANG',
env_dict.pop('SSL_CERT_DIR',None) 'LS_COLORS',
env_dict.pop('GIT_ASKPASS',None) 'SSL_CERT_DIR',
env_dict.pop('SSH_CONNECTION',None) 'GIT_ASKPASS',
env_dict.pop('VSCODE_GIT_ASKPASS_EXTRA_ARGS',None) 'SSH_CONNECTION',
env_dict.pop('LESSCLOSE',None) 'VSCODE_GIT_ASKPASS_EXTRA_ARGS',
env_dict.pop('XDG_SESSION_CLASS',None) 'LESSCLOSE',
env_dict.pop('TERM',None) 'XDG_SESSION_CLASS',
env_dict.pop('LESSOPEN',None) 'TERM',
env_dict.pop('USER',None) 'LESSOPEN',
env_dict.pop('VSCODE_GIT_IPC_HANDLE',None) 'USER',
env_dict.pop('SHLVL',None) 'VSCODE_GIT_IPC_HANDLE',
env_dict.pop('XDG_SESSION_ID',None) 'SHLVL',
env_dict.pop('XDG_RUNTIME_DIR',None) 'XDG_SESSION_ID',
env_dict.pop('SSL_CERT_FILE',None) 'XDG_RUNTIME_DIR',
env_dict.pop('SSH_CLIENT',None) 'SSL_CERT_FILE',
env_dict.pop('VSCODE_GIT_ASKPASS_MAIN',None) 'SSH_CLIENT',
env_dict.pop('XDG_DATA_DIRS',None) 'VSCODE_GIT_ASKPASS_MAIN',
env_dict.pop('BROWSER',None) 'XDG_DATA_DIRS',
env_dict.pop('PATH',None) 'BROWSER',
env_dict.pop('DBUS_SESSION_BUS_ADDRESS',None) 'PATH',
env_dict.pop('OLDPWD',None) 'DBUS_SESSION_BUS_ADDRESS',
env_dict.pop('TERM_PROGRAM',None) 'OLDPWD',
env_dict.pop('VSCODE_IPC_HOOK_CLI',None) 'TERM_PROGRAM',
env_dict.pop('aaaaaaa',None) 'VSCODE_IPC_HOOK_CLI',
]
for item in _pop_list:
env_dict.pop(item,None)

View File

@@ -764,7 +764,7 @@ e_err:
* @param hdr: pointer to save header information. * @param hdr: pointer to save header information.
* @return ERR_FAIL: failed; ERR_OK: succeed. * @return ERR_FAIL: failed; ERR_OK: succeed.
*/ */
static uint32_t mtd_get_hdr(uint8_t part_num, imgHdr *hdr) uint32_t mtd_get_hdr(uint8_t part_num, imgHdr *hdr)
{ {
int fd; int fd;
static uint8_t last_part = PART_NUM_INVALID; static uint8_t last_part = PART_NUM_INVALID;

View File

@@ -418,10 +418,13 @@ uint32_t board_load_oem_cfg()
g_board_cpu_idx = cpu_get_mhartid(); g_board_cpu_idx = cpu_get_mhartid();
#endif #endif
iot_printf("start load oemcfg\n");
iot_printf("%s:%d\n"__FILE__,__LINE__);
ret = iot_oem_get_cfg(&oemcfg); ret = iot_oem_get_cfg(&oemcfg);
if (ret != ERR_OK) { if (ret != ERR_OK) {
goto out; goto out;
} }
iot_printf("%s:%d\n"__FILE__,__LINE__);
g_board_info.board_id = oemcfg->board_id; g_board_info.board_id = oemcfg->board_id;
IOT_ASSERT(oemcfg->board_cfg_ver == IOT_OEM_VER_V1); IOT_ASSERT(oemcfg->board_cfg_ver == IOT_OEM_VER_V1);
@@ -437,16 +440,19 @@ uint32_t board_load_oem_cfg()
goto out; goto out;
} }
// 读取oem的差分部分 // 读取oem的差分部分
iot_printf("%s:%d\n"__FILE__,__LINE__);
ret = iot_oem_read_mtd(buf_oem, oem_part_size - oem_diff_offset, ret = iot_oem_read_mtd(buf_oem, oem_part_size - oem_diff_offset,
oem_diff_offset); oem_diff_offset);
if (ret != ERR_OK) { if (ret != ERR_OK) {
goto out; goto out;
} }
iot_printf("%s:%d\n"__FILE__,__LINE__);
ret = ERR_FAIL; ret = ERR_FAIL;
hw_ver_cal = iot_board_hw_version_hex(); hw_ver_cal = iot_board_hw_version_hex();
/* if hw_version is not written during production test, it defaults to f */ /* if hw_version is not written during production test, it defaults to f */
if (hw_ver_cal == 0xffffffff) { if (hw_ver_cal == 0xffffffff) {
iot_printf("%s:%d\n"__FILE__,__LINE__);
hw_ver_cal = 0; hw_ver_cal = 0;
} }
// ptr_rc 是 iot_board_info_v1_t 类型的指针 // ptr_rc 是 iot_board_info_v1_t 类型的指针
@@ -457,7 +463,7 @@ uint32_t board_load_oem_cfg()
hdr_check: hdr_check:
if (hw_ver_cal != hw_ver_rc) { if (hw_ver_cal != hw_ver_rc) {
if (ptr_hdr->have_next == 0) { if (ptr_hdr->have_next == 0) {
if(read_oem_ext_flag || if(read_oem_ext_flag ||
iot_oem_read_mtd_ext(&buf_oem[offset],BOARD_OEM_INFO_SIZE_MAX-offset)){ iot_oem_read_mtd_ext(&buf_oem[offset],BOARD_OEM_INFO_SIZE_MAX-offset)){
goto out; goto out;
} else { } else {

View File

@@ -17,6 +17,7 @@ Information is free from patent or copyright infringement.
#include "iot_flash_api.h" #include "iot_flash_api.h"
#include "iot_flash_layout.h" #include "iot_flash_layout.h"
#include "iot_img_hdr.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
@@ -244,6 +245,14 @@ int32_t iot_log_save_done(uint8_t lock);
*/ */
uint32_t mtd_copy_part(uint8_t src_part, uint8_t dest_part); uint32_t mtd_copy_part(uint8_t src_part, uint8_t dest_part);
/**
* @brief mtd_get_hdr(): get firmware header information of specified partition.
* @param part_num: the specified partition.
* @param hdr: pointer to save header information.
* @return ERR_FAIL: failed; ERR_OK: succeed.
*/
uint32_t mtd_get_hdr(uint8_t part_num, imgHdr *hdr);
/** /**
* @brief mtd_get_hdr_img_size(uint8_t part) - get img size in hdr * @brief mtd_get_hdr_img_size(uint8_t part) - get img size in hdr
* @param part: part number in flash block. * @param part: part number in flash block.

View File

@@ -48,9 +48,6 @@ extern "C" {
#define IOT_OEM_SECTION_SEC_ADDR (3072) #define IOT_OEM_SECTION_SEC_ADDR (3072)
#define IOT_OEM_EXT_SECTION_OFFSET(fw_size) \
(((fw_size+31)&(~0x1f))+IOT_OEM_SECTION_START_ADDR)
#define IOT_OEM_EXT_MAGIC_STR "_oem_ext" #define IOT_OEM_EXT_MAGIC_STR "_oem_ext"
#define IOT_OEM_DUMMY_LEN 106 #define IOT_OEM_DUMMY_LEN 106

View File

@@ -581,6 +581,7 @@ int ah_GetConfig(char *pcfgName, ah_cfg *pcfg)
int ah_add_oem_ext(char *buf) int ah_add_oem_ext(char *buf)
{ {
int file_size; int file_size;
int used_size;
char *buf_start=buf; char *buf_start=buf;
FILE *fp = NULL; FILE *fp = NULL;
struct stat st; struct stat st;
@@ -594,8 +595,6 @@ int ah_add_oem_ext(char *buf)
} else { } else {
printf(NEW_LINE"Open image file(%s)."NEW_LINE, file_name); printf(NEW_LINE"Open image file(%s)."NEW_LINE, file_name);
} }
memcpy(buf,oem_magic_str,strlen(oem_magic_str));
buf += strlen(oem_magic_str);
fseek(fp, 0, SEEK_END); fseek(fp, 0, SEEK_END);
file_size = ftell(fp); file_size = ftell(fp);
fseek(fp, 0, SEEK_SET); fseek(fp, 0, SEEK_SET);
@@ -603,6 +602,16 @@ int ah_add_oem_ext(char *buf)
buf += file_size; buf += file_size;
fclose(fp); fclose(fp);
fp = NULL; fp = NULL;
// 保存oem占用的长度 不包括魔法字符串长度和 used_size占用的4个字节
used_size=file_size;
// 大端
buf[0]=(used_size>>24)&0xff;
buf[1]=(used_size>>16)&0xff;
buf[2]=(used_size>>8)&0xff;
buf[3]=(used_size)&0xff;
buf+=4;
memcpy(buf,oem_magic_str,strlen(oem_magic_str));
buf += strlen(oem_magic_str);
return buf-buf_start; return buf-buf_start;
} }
@@ -776,6 +785,9 @@ int ah_addHeader(char argc, char *argv[])
fclose(fps); fclose(fps);
fps = NULL; fps = NULL;
// 在这里添加 oem_ext.bin
fileSize+=ah_add_oem_ext(p_buf + imgHeaderSize + fileSize);
crcSize = IMAGE_LEN_FOR_CRC(fileSize); crcSize = IMAGE_LEN_FOR_CRC(fileSize);
/* Clear pad bytes to '0' */ /* Clear pad bytes to '0' */
@@ -1032,10 +1044,10 @@ int ah_funConstruct(char argc, char *argv[])
/*update buffer pointer*/ /*update buffer pointer*/
p_buf += len; p_buf += len;
// 在这里添加 oem_ext.bin // // 在这里添加 oem_ext.bin
if(cfg.image[cnt].image_type == imgV1FRWPLC){ // if(cfg.image[cnt].image_type == imgV1FRWPLC){
p_buf+=ah_add_oem_ext(p_buf); // p_buf+=ah_add_oem_ext(p_buf);
} // }
/*new bin file's size*/ /*new bin file's size*/
len = p_buf - p_saved_buf; len = p_buf - p_saved_buf;

View File

@@ -113,52 +113,52 @@ uint32_t iot_oem_read_mtd(uint8_t *buf, uint32_t size, uint32_t offset)
// 抓取额外的差分oem数据 // 抓取额外的差分oem数据
uint32_t iot_oem_read_mtd_ext(uint8_t *buff,uint32_t buff_size) uint32_t iot_oem_read_mtd_ext(uint8_t *buff,uint32_t buff_size)
{ {
int fd = 0; int oem_size;
int offset;
int status; int status;
int fw_size; int fw_size;
uint32_t ret = ERR_FAIL; uint32_t ret = ERR_FAIL;
uint8_t fw_prtition = PART_NUM_FW1; uint8_t fw_prtition = PART_NUM_FW1;
char str_buff[10]={0}; char str_buff[10]={0};
imgHdr hdr={0};
const imgHdr *run_fw_hdr;
const uint8_t *data;
const char *oem_ext_magic_str = IOT_OEM_EXT_MAGIC_STR; const char *oem_ext_magic_str = IOT_OEM_EXT_MAGIC_STR;
int oem_ext_magic_str_len = strlen(oem_ext_magic_str); int oem_ext_magic_str_len = strlen(oem_ext_magic_str);
iot_printf("%s:%d\n"__FILE__,__LINE__);
do { do {
status = dev_get_boot_fw_part_num(&fw_prtition); status = dev_get_boot_fw_part_num(&fw_prtition);
if (status) { if (status) {
break; break;
} }
fw_size=mtd_get_hdr_img_size(fw_prtition); iot_printf("%s:%d\n"__FILE__,__LINE__);
offset=IOT_OEM_EXT_SECTION_OFFSET(fw_size); mtd_get_hdr(fw_prtition,&hdr);
fd = dev_open(fw_prtition, 0); if(hdr.v1.hdrVer!=hdrVer_10){
if (fd < 0) {
fd = 0;
break;
}
status = dev_seek(fd, offset, DEV_SEEK_SET);
if (status < 0) {
break;
}
status = dev_read(fd, buff, oem_ext_magic_str_len);
if (status < 0) {
break; break;
} }
iot_printf("%s:%d\n"__FILE__,__LINE__);
run_fw_hdr=(const imgHdr *)(hdr.v1.runAddr-HEADER_TOLTAL_SIZE);
fw_size=run_fw_hdr->v1.imgSize;
data=(const uint8_t *)(hdr.v1.runAddr+fw_size-oem_ext_magic_str_len);
iot_printf("%s:%d\n"__FILE__,__LINE__);
os_mem_cpy(str_buff,data,oem_ext_magic_str_len);
iot_printf("%s:%d\n"__FILE__,__LINE__);
if(iot_strcmp(str_buff,oem_ext_magic_str) != 0){ if(iot_strcmp(str_buff,oem_ext_magic_str) != 0){
break; break;
} }
status = dev_seek(fd, offset+oem_ext_magic_str_len, DEV_SEEK_SET); iot_printf("%s:%d\n"__FILE__,__LINE__);
if (status < 0) { data-=4;
break; oem_size=((data[0]<<24)|(data[1]<<16)|(data[2]<<8)|data[3]);
} data=data-oem_size;
status = dev_read(fd, buff, buff_size); iot_printf("%s:%d\n"__FILE__,__LINE__);
if (status < 0) { if(buff_size<oem_size){
break; break;
} }
iot_printf("%s:%d\n"__FILE__,__LINE__);
os_mem_cpy(buff,data,oem_size);
iot_printf("%s:%d\n"__FILE__,__LINE__);
ret = ERR_OK; ret = ERR_OK;
} while(0); } while(0);
if (fd) {
dev_close(fd);
}
return ret; return ret;
} }

View File

@@ -344,6 +344,38 @@ if [ "x${CHIP_VER_UPPER}" == "x3" ]; then
else else
cp ${TOP_DIR}/ap/.output/plc/lib/${HT_FILE} $CUR_DIR/ht.bin cp ${TOP_DIR}/ap/.output/plc/lib/${HT_FILE} $CUR_DIR/ht.bin
fi fi
# prepare oem.bin
# 根据core类型指定oem文件
if [ "x${CORE_TYPE_UPPER}" == "xAMPPLC" ]; then
if [ ${IOT_SMART_BUILD} == 1 ]; then
OEM_CFG=${BOARD_UPPER}"_AMPIOT_OEM.ini"
OEM_FILE=${BOARD_UPPER}"_AMPIOT_OEM.bin"
else
OEM_CFG=${BOARD_UPPER}"_AMPSG_OEM.ini"
OEM_FILE=${BOARD_UPPER}"_AMPSG_OEM.bin"
fi
else
OEM_CFG=${BOARD_UPPER}"_OEM.ini"
OEM_FILE=${BOARD_UPPER}"_OEM.bin"
fi
cp $TOP_DIR/tools/oem/$OEM_CFG ./tmp_oem.ini
#set mid for iot board(cco and sta use same oem.ini)
# smart模式需要根据img类型动态修改mid值
if [ ${IOT_SMART_BUILD} == 1 ]; then
if [ "${IMG_UPPER}" == "CCO" ]; then
sed -i "s/mid.*/mid 1/g" ./tmp_oem.ini
elif [ "${IMG_UPPER}" == "STA" ]; then
sed -i "s/mid.*/mid 0/g" ./tmp_oem.ini
fi
fi
if [ "${RUN_UPPER}" != "UPGRADE" ]; then
# 打包非升级文件的时候生成 oem.bin
./oem_tool --input=./tmp_oem.ini --output=$TOP_DIR/tools/oem/$OEM_FILE
fi
rm ./tmp_oem.ini
cp $TOP_DIR/tools/oem/$OEM_FILE $CUR_DIR/oem.bin
# 修改配置文件中的layout index配置 # 修改配置文件中的layout index配置
sed -i "/img_type=./a layout_index=${FLASH_LAYOUT_INDEX}" ${TMP_CFG_NAME} sed -i "/img_type=./a layout_index=${FLASH_LAYOUT_INDEX}" ${TMP_CFG_NAME}
@@ -512,37 +544,6 @@ if [ "x${CHIP_VER_UPPER}" == "x3" ]; then
sed -i "s,vendor_id=18516,vendor_id=22864,g" ${TMP_CFG_NAME} sed -i "s,vendor_id=18516,vendor_id=22864,g" ${TMP_CFG_NAME}
fi fi
# prepare oem.bin
# 根据core类型指定oem文件
if [ "x${CORE_TYPE_UPPER}" == "xAMPPLC" ]; then
if [ ${IOT_SMART_BUILD} == 1 ]; then
OEM_CFG=${BOARD_UPPER}"_AMPIOT_OEM.ini"
OEM_FILE=${BOARD_UPPER}"_AMPIOT_OEM.bin"
else
OEM_CFG=${BOARD_UPPER}"_AMPSG_OEM.ini"
OEM_FILE=${BOARD_UPPER}"_AMPSG_OEM.bin"
fi
else
OEM_CFG=${BOARD_UPPER}"_OEM.ini"
OEM_FILE=${BOARD_UPPER}"_OEM.bin"
fi
cp $TOP_DIR/tools/oem/$OEM_CFG ./tmp_oem.ini
#set mid for iot board(cco and sta use same oem.ini)
# smart模式需要根据img类型动态修改mid值
if [ ${IOT_SMART_BUILD} == 1 ]; then
if [ "${IMG_UPPER}" == "CCO" ]; then
sed -i "s/mid.*/mid 1/g" ./tmp_oem.ini
elif [ "${IMG_UPPER}" == "STA" ]; then
sed -i "s/mid.*/mid 0/g" ./tmp_oem.ini
fi
fi
if [ "${RUN_UPPER}" != "UPGRADE" ]; then
# 打包非升级文件的时候生成 oem.bin
./oem_tool --input=./tmp_oem.ini --output=$TOP_DIR/tools/oem/$OEM_FILE
fi
rm ./tmp_oem.ini
cp $TOP_DIR/tools/oem/$OEM_FILE $CUR_DIR/oem.bin
# prepare pib file # prepare pib file
# 根据board类型来选择pib文件 # 根据board类型来选择pib文件
PIB_IMG=${BOARD_UPPER} PIB_IMG=${BOARD_UPPER}