修改 ah fw 在fw img 之后读取附加的oem数据

This commit is contained in:
2024-10-26 14:10:20 +08:00
parent 1a60d3f171
commit d5325ac3aa
6 changed files with 93 additions and 17 deletions

View File

@@ -20,6 +20,10 @@ Information is free from patent or copyright infringement.
extern "C" {
#endif
#define BOARD_OEM_INFO_SIZE_MAX (8192)
/**
* @brief load oem configuration information from oem partition,
* then set module type.

View File

@@ -387,14 +387,6 @@ void board_oem_signal_mtx_binding(iot_board_info_v1_t *rc_info)
// 抓取额外的差分oem数据
static uint32_t board_load_oem_cfg_ext(uint8_t *buff,uint32_t buff_size)
{
return 0;
}
@@ -416,6 +408,7 @@ uint32_t board_load_oem_cfg()
uint8_t diff_idx_array[BOARD_RESOURCE_NUM_MAX] = {0};
uint32_t crc_cal;
uint8_t gpio;
int read_oem_ext_flag=0;
/* init cpu index value */
#if (BUILD_AMP_TYPE == IOT_BUILD_AMP_NONE)
@@ -438,7 +431,7 @@ uint32_t board_load_oem_cfg()
/* [TODO]: optimize the logic to look up only on the first startup */
iot_layout_get_part_size(PART_NUM_OEM, &oem_part_size);
oem_diff_offset = sizeof(iot_oem_cfg_t) + IOT_OEM_SECTION_START_ADDR;
buf_oem = os_mem_malloc(IOT_DRIVER_MID, oem_part_size - oem_diff_offset);
buf_oem = os_mem_malloc(IOT_DRIVER_MID, BOARD_OEM_INFO_SIZE_MAX);
if (buf_oem == NULL) {
ret = ERR_FAIL;
goto out;
@@ -464,7 +457,13 @@ uint32_t board_load_oem_cfg()
hdr_check:
if (hw_ver_cal != hw_ver_rc) {
if (ptr_hdr->have_next == 0) {
goto out;
if(read_oem_ext_flag ||
iot_oem_read_mtd_ext(&buf_oem[offset],BOARD_OEM_INFO_SIZE_MAX-offset)){
goto out;
} else {
ptr_hdr->have_next = 1;
read_oem_ext_flag = 1;
}
}
// 统计有多少个rc table
cnt_rc++;

View File

@@ -48,6 +48,11 @@ extern "C" {
#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_DUMMY_LEN 106
/* use simple pair passcode for security check */
#define IOT_OEM_SEC_TYPE_PASSCODE 1
@@ -219,6 +224,14 @@ extern const uint8_t g_iot_sec_root_sm2_pub_v1[IOT_SEC_ROOT_SM2_PUB_LEN];
*/
uint32_t iot_oem_read_mtd(uint8_t *buf, uint32_t size, uint32_t offset);
/**
* @brief iot_oem_read_mtd_ext() - read oem ext data from flash fw section.
* @param buf: pointer to receive oem data.
* @param size: length to receive oem data.
* @retval 0 success; others fail.
*/
uint32_t iot_oem_read_mtd_ext(uint8_t *buf, uint32_t size);
/**
* @brief iot_oem_init - init oem function.
* warning, iot_oem_init should be called after pib load

View File

@@ -5,7 +5,7 @@
#include <stdint.h>
#include <sys/stat.h>
#include <arpa/inet.h>
#include "sha256.h"
#include "../ram/inc/sha256.h"
#include "iot_img_hdr.h"
char default_hash_iv[]={0x12,0x34,0x56,0x78,0x87,0x65,0x43,0x21,0x5A,0x5A,0x5A,0x5A,0x00,0x7E,0xC3,0x00};
@@ -575,6 +575,38 @@ int ah_GetConfig(char *pcfgName, ah_cfg *pcfg)
#define PACKAGE_HEADER_SIZE 96
// 填充额外的oem数据
int ah_add_oem_ext(char *buf)
{
int file_size;
char *buf_start=buf;
FILE *fp = NULL;
struct stat st;
const char *file_name="oem_ext.bin";
const char *oem_magic_str="_oem_ext";
if((0 != stat(file_name, &st))
||(NULL == (fp=fopen(file_name, "r"))))
{
printf(NEW_LINE"Cannot open image file(%s)."NEW_LINE, file_name);
return 0;
}
memcpy(buf,oem_magic_str,strlen(oem_magic_str));
buf += strlen(oem_magic_str);
fseek(fp, 0, SEEK_END);
file_size = ftell(fp);
fseek(fp, 0, SEEK_SET);
fread(buf, 1, file_size, fp);
buf += file_size;
fclose(fp);
fp = NULL;
return buf-buf_start;
}
// 这里添加的是img的头
void ah_fillHeader(char* p_buf, ah_cfg *cfg, int cnt, int fileSize, int _CRC,
unsigned char *sha)
@@ -998,6 +1030,11 @@ int ah_funConstruct(char argc, char *argv[])
/*update buffer pointer*/
p_buf += len;
// 在这里添加 oem_ext.bin
if(cfg.image[cnt].image_type == imgV1FRWPLC){
p_buf+=ah_add_oem_ext(p_buf);
}
/*new bin file's size*/
len = p_buf - p_saved_buf;
total_size += len;

View File

@@ -8,8 +8,9 @@
#include "../../../inc/hw/reg/riscv3/2/gpio_mtx_sig.h"
#include "oem_common.h"
#include "../oem_common.h"
#include "oem_tool_hw.h"
#include "iot_oem_struct_v1.h"
#define RC_TOTAL_GPIO 128
#define RC_TOTAL_UART IOT_UART_MAX_NUM_V1

View File

@@ -31,6 +31,7 @@ Information is free from patent or copyright infringement.
#include "iot_uart_api.h"
#include "iot_crc_api.h"
#include "iot_crypto_dsa_api.h"
#include "iot_string.h"
/**
* user type for iot
@@ -110,14 +111,25 @@ uint32_t iot_oem_read_mtd(uint8_t *buf, uint32_t size, uint32_t offset)
// 抓取额外的差分oem数据
uint32_t iot_oem_read_mtd_ext(uint8_t *buff,size_t buff_size)
uint32_t iot_oem_read_mtd_ext(uint8_t *buff,uint32_t buff_size)
{
int fd;
int ret;
int fd = 0;
int offset;
int status;
int fw_prtition=PART_NUM_FW1;
int fw_size;
uint32_t ret = ERR_FAIL;
uint8_t fw_prtition = PART_NUM_FW1;
char str_buff[10]={0};
const char *oem_ext_magic_str = IOT_OEM_EXT_MAGIC_STR;
int oem_ext_magic_str_len = strlen(oem_ext_magic_str);
do {
status = dev_get_boot_fw_part_num(&fw_prtition);
if (status) {
break;
}
fw_size=mtd_get_hdr_img_size(fw_prtition);
offset=IOT_OEM_EXT_SECTION_OFFSET(fw_size);
fd = dev_open(fw_prtition, 0);
if (fd < 0) {
fd = 0;
@@ -127,6 +139,17 @@ uint32_t iot_oem_read_mtd_ext(uint8_t *buff,size_t buff_size)
if (status < 0) {
break;
}
status = dev_read(fd, buff, oem_ext_magic_str_len);
if (status < 0) {
break;
}
if(iot_strcmp(str_buff,oem_ext_magic_str) != 0){
break;
}
status = dev_seek(fd, offset+oem_ext_magic_str_len, DEV_SEEK_SET);
if (status < 0) {
break;
}
status = dev_read(fd, buff, buff_size);
if (status < 0) {
break;
@@ -137,7 +160,6 @@ uint32_t iot_oem_read_mtd_ext(uint8_t *buff,size_t buff_size)
dev_close(fd);
}
return ret;
}