From a15be0b47694eec5349f686c1ca6d6c9f251d0ba Mon Sep 17 00:00:00 2001 From: andy <1414772332@qq.com> Date: Sat, 26 Oct 2024 23:44:55 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=A7=E4=BA=8E=E9=99=90=E5=88=B6=E7=9A=84oe?= =?UTF-8?q?m=E5=8F=82=E6=95=B0=E5=8D=95=E7=8B=AC=E4=BF=9D=E5=AD=98?= =?UTF-8?q?=E5=88=B0=E4=B8=80=E4=B8=AA=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mfgtool/ah/add_header_v1.c | 2 + .../cmd_line/src/iot_bootram_command_line.c | 18 ++--- mfgtool/oem_tool/hw3/oem_tool_hw.c | 80 +++++++++++++++---- tools/gen_img/gen_img.sh | 2 +- 4 files changed, 77 insertions(+), 25 deletions(-) diff --git a/mfgtool/ah/add_header_v1.c b/mfgtool/ah/add_header_v1.c index a261881..8e047a5 100644 --- a/mfgtool/ah/add_header_v1.c +++ b/mfgtool/ah/add_header_v1.c @@ -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); diff --git a/mfgtool/bootram/bootram/shell/cmd_line/src/iot_bootram_command_line.c b/mfgtool/bootram/bootram/shell/cmd_line/src/iot_bootram_command_line.c index 285f3ae..a0e0be8 100644 --- a/mfgtool/bootram/bootram/shell/cmd_line/src/iot_bootram_command_line.c +++ b/mfgtool/bootram/bootram/shell/cmd_line/src/iot_bootram_command_line.c @@ -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; +// } diff --git a/mfgtool/oem_tool/hw3/oem_tool_hw.c b/mfgtool/oem_tool/hw3/oem_tool_hw.c index 41adef9..8d5039e 100644 --- a/mfgtool/oem_tool/hw3/oem_tool_hw.c +++ b/mfgtool/oem_tool/hw3/oem_tool_hw.c @@ -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); diff --git a/tools/gen_img/gen_img.sh b/tools/gen_img/gen_img.sh index 8b59991..ce71ad8 100755 --- a/tools/gen_img/gen_img.sh +++ b/tools/gen_img/gen_img.sh @@ -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