大于限制的oem参数单独保存到一个文件

This commit is contained in:
2024-10-26 23:44:55 +08:00
parent d5325ac3aa
commit a15be0b476
4 changed files with 77 additions and 25 deletions

View File

@@ -591,6 +591,8 @@ int ah_add_oem_ext(char *buf)
{
printf(NEW_LINE"Cannot open image file(%s)."NEW_LINE, file_name);
return 0;
} else {
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);

View File

@@ -139,16 +139,16 @@ static iot_bootram_cmd_line_entity_t *btm_cmd_get_entity(char *cmd, int len)
static iot_bootram_cmd_line_entity_t *btm_cmd_get_entity_by_index(char *cmd, int len,int index)
{
iot_bootram_cmd_line_entity_t *p_cmd_handle = NULL;
// static iot_bootram_cmd_line_entity_t *btm_cmd_get_entity_by_index(char *cmd, int len,int index)
// {
// iot_bootram_cmd_line_entity_t *p_cmd_handle = NULL;
if(index >= cline_commands.total_cnt || index < 0){
return NULL;
}
p_cmd_handle = &(cline_commands.entity[index]);
return p_cmd_handle;
}
// if(index >= cline_commands.total_cnt || index < 0){
// return NULL;
// }
// p_cmd_handle = &(cline_commands.entity[index]);
// return p_cmd_handle;
// }

View File

@@ -34,6 +34,9 @@
#define oem_debug_print(fmt, ...)
#endif
#define OEM_FILE_MAX_SIZE (3000)
#define OEM_INFO_MAX_SIZE (8192)
typedef enum _category_type_t {
CATEGORY_GENERAL = 0,
CATEGORY_RC_HDR,
@@ -92,6 +95,9 @@ typedef struct _current_rc_info_t {
typedef struct _diff_data_buffer_t {
uint8_t buf[4096];
uint16_t len_total;
uint16_t len_cut;
uint16_t last_offset;
uint16_t cut_flag;
} diff_data_buffer_t;
typedef struct _oem_tool_info_t {
@@ -1077,6 +1083,26 @@ again:
return 0;
}
// 重新装填 rc_hdr
// index rc 结构体 的序号,have_next 是否有下一个buf_index 存放hdr的buf_index
static int rc_reflush_rc_hdr(int index, int have_next, int buf_index)
{
/* fill header information (crc and offset) */
oem_tool.rc_list[index]->hdr.have_next = have_next;
oem_tool.rc_list[index]->hdr.crc =
iot_getcrc32((uint8_t *)&oem_tool.rc_list[index]->hdr +
sizeof(uint32_t),
sizeof(iot_board_info_v1_t) - sizeof(uint32_t));
/* copy header info again */
// 把修改过参数的rc_hdr 重新复制到buff中
memcpy(&oem_tool.buf.buf[buf_index],
&oem_tool.rc_list[index]->hdr, sizeof(iot_oem_rc_hdr_v1_t));
return 0;
}
uint8_t rc_data_merge()
{
uint16_t buf_index_last;
@@ -1087,6 +1113,7 @@ uint8_t rc_data_merge()
if (oem_tool.rc_list[index]->hdr.mode == 0) {
if (index != 0) {
/* save the complete resource table */
// 不是差分模式 全部复制过来
oem_debug_print("save complete rc data\n");
memcpy(&oem_tool.buf.buf[oem_tool.buf.len_total],
&oem_tool.rc_list[index]->hdr, sizeof(iot_board_info_v1_t));
@@ -1116,26 +1143,29 @@ uint8_t rc_data_merge()
buf_index_last);
}
/* oem partition size is 4K, including image header(64 bytes) and an
/* oem partition size is 8K, including image header(64 bytes) and an
* iot_oem_cfg_t structure. the remaining space holds differential data.
*/
if (oem_tool.buf.len_total > 4096 - sizeof(iot_oem_cfg_t) - 64) {
if (oem_tool.buf.len_total > OEM_INFO_MAX_SIZE - sizeof(iot_oem_cfg_t) - 64) {
die("diff data length exceeded the limit\n");
}
/* fill header information (crc and offset) */
if (oem_tool.rc_list[index + 1] != 0) {
oem_tool.rc_list[index]->hdr.have_next = 1;
rc_reflush_rc_hdr(index, 1, buf_index_last);
} else {
oem_tool.rc_list[index]->hdr.have_next = 0;
rc_reflush_rc_hdr(index, 0, buf_index_last);
}
oem_tool.rc_list[index]->hdr.crc = \
iot_getcrc32((uint8_t *)&oem_tool.rc_list[index]->hdr +
sizeof(uint32_t), sizeof(iot_board_info_v1_t) - sizeof(uint32_t));
/* copy header info again */
memcpy(&oem_tool.buf.buf[buf_index_last],
&oem_tool.rc_list[index]->hdr, sizeof(iot_oem_rc_hdr_v1_t));
if (oem_tool.buf.len_total + sizeof(iot_oem_cfg_t) <= OEM_FILE_MAX_SIZE) {
// 更新截断位置
oem_tool.buf.len_cut = oem_tool.buf.len_total;
} else {
// 如果本次的数据导致尺寸超出了,则上一个数据需要修改 have_next = 0
if (oem_tool.buf.cut_flag == 0) {
rc_reflush_rc_hdr(index - 1, 0, oem_tool.buf.last_offset);
oem_tool.buf.cut_flag = 1;
}
}
oem_tool.buf.last_offset = buf_index_last;
}
/* The first resource is put into the OEM architecture */
@@ -1183,6 +1213,20 @@ void load_database_hw(const char *filename)
fclose (fp);
}
static void save_ext_data_hw(const char *filename,const uint8_t *buff,uint32_t size)
{
FILE *fp;
fp = fopen(filename, "wb");
fwrite(buff, size, 1, fp);
fclose(fp);
}
void save_database_hw(const char *filename)
{
FILE *fp;
@@ -1202,10 +1246,16 @@ void save_database_hw(const char *filename)
die ("error write oem.bin: %s", strerror(errno));
fwrite(buf, sizeof(iot_oem_cfg_t), 1, fp);
if (oem_tool.buf.len_total) {
if (oem_tool.buf.len_cut) {
// oem_tool.buf中存储的是差分后的配置信息 每个差分都是原配置的一个副本修改差异值
oem_debug_print("find diff data, write to file\n");
fwrite(oem_tool.buf.buf, sizeof(uint8_t), oem_tool.buf.len_total, fp);
oem_debug_print("find extra data, size=%d\n",oem_tool.buf.len_cut);
fwrite(oem_tool.buf.buf, sizeof(uint8_t), oem_tool.buf.len_cut, fp);
if (oem_tool.buf.len_total>oem_tool.buf.len_cut){
printf("have cut oem info, cut size=%ld, total size=%ld\n",
oem_tool.buf.len_cut+sizeof(iot_oem_cfg_t),oem_tool.buf.len_total+sizeof(iot_oem_cfg_t));
save_ext_data_hw("oem_ext.bin",&oem_tool.buf.buf[oem_tool.buf.len_cut],
oem_tool.buf.len_total-oem_tool.buf.len_cut);
}
}
fclose(fp);

View File

@@ -160,7 +160,7 @@ CORE_TYPE_UPPER=$(echo $CORE_TYPE_LOWER | tr '[a-z]' '[A-Z]')
rm -f $CUR_DIR/sbl.bin
rm -f $CUR_DIR/pib.bin
rm -f $CUR_DIR/sp.bin
rm -f $CUR_DIR/oem.bin
rm -f $CUR_DIR/oem*.bin
rm -f $CUR_DIR/ht.bin
rm -f $CUR_DIR/ht_1p.bin
rm -f $CUR_DIR/ht*.fw