From 29e987e536e9f651684fae056b1763670863cc3d Mon Sep 17 00:00:00 2001 From: andy <1414772332@qq.com> Date: Tue, 22 Oct 2024 14:20:46 +0800 Subject: [PATCH] =?UTF-8?q?=E9=98=85=E8=AF=BBoem=E9=83=A8=E5=88=86?= =?UTF-8?q?=E4=BB=A3=E7=A0=81=20=E6=B7=BB=E5=8A=A0=E4=B8=80=E4=BA=9B?= =?UTF-8?q?=E6=B3=A8=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- driver/src/hal/mtd.c | 1 + inc/pib/iot_oem_struct_v1.h | 2 ++ mfgtool/oem_tool/hw3/oem_tool_hw.c | 9 ++++++++- pib/src/iot_oem.c | 1 + 4 files changed, 12 insertions(+), 1 deletion(-) diff --git a/driver/src/hal/mtd.c b/driver/src/hal/mtd.c index 855b0f4..de5637a 100644 --- a/driver/src/hal/mtd.c +++ b/driver/src/hal/mtd.c @@ -433,6 +433,7 @@ uint32_t dev_get_part_size(uint8_t part) } /************************ file system basics functions ************************/ +// num: flash分区 part int dev_open(int num, uint32_t flags) { int fd; diff --git a/inc/pib/iot_oem_struct_v1.h b/inc/pib/iot_oem_struct_v1.h index cad7a59..eff0216 100644 --- a/inc/pib/iot_oem_struct_v1.h +++ b/inc/pib/iot_oem_struct_v1.h @@ -67,6 +67,8 @@ typedef struct _iot_oem_rc_hdr_v1_t { resv : 13; } iot_oem_rc_hdr_v1_t; + +// 差分模式的差异 是对比的二进制差异 typedef struct _iot_oem_rc_diff_v1_t { uint16_t offset; //diff beginning offset, respect to iot_board_info_v1_t uint16_t length; //current diff block length diff --git a/mfgtool/oem_tool/hw3/oem_tool_hw.c b/mfgtool/oem_tool/hw3/oem_tool_hw.c index f85c48f..04feb33 100644 --- a/mfgtool/oem_tool/hw3/oem_tool_hw.c +++ b/mfgtool/oem_tool/hw3/oem_tool_hw.c @@ -1202,6 +1202,7 @@ void save_database_hw(const char *filename) fwrite(buf, sizeof(iot_oem_cfg_t), 1, fp); if (oem_tool.buf.len_total) { + // 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); } @@ -1218,6 +1219,7 @@ void oem_resource_info_dump(iot_board_info_v1_t *ptr_rc) "diff hw_ver:0x%08x, length:%d, have next:%d\n", ptr_rc->hdr.crc, ptr_rc->hdr.hw_version, ptr_rc->hdr.mode, ptr_rc->hdr.diff_hw_ver, ptr_rc->hdr.length, ptr_rc->hdr.have_next); + // 计算 iot_board_info_v1_t 结构体除crc字段其他部分的crc32 crc = iot_getcrc32((uint8_t *)&ptr_rc->hdr + sizeof(uint32_t), sizeof(iot_board_info_v1_t) - sizeof(uint32_t)); if (crc != ptr_rc->hdr.crc) { @@ -1382,6 +1384,7 @@ again: memcpy(diff_buf, &oem_tool.buf.buf[oem_tool.buf.len_total], diff_data_len); oem_tool.buf.len_total += diff_data_len; /* restore differential data */ + // 这里可以支持多个差异二进制片段 i = 0; while (i < diff_data_len) { iot_oem_rc_diff_v1_t *diff_temp = @@ -1519,6 +1522,7 @@ dump: oem_resource_info_dump(&rc_info); } +// 读取bin文件并解析 void oem_bin_file_parse_hw(const char *filename) { FILE *fp; @@ -1535,11 +1539,14 @@ void oem_bin_file_parse_hw(const char *filename) printf("open oem bin file(%s) succeed\n", filename); /* read oem bin file all data */ + // 读取4k个字节的oem数据 fread(oem_tool.buf.buf, sizeof(oem_tool.buf.buf), 1, fp); /* not include image header information by default */ + // 把第一个配置信息复制到oemcfg结构体 memcpy((void*)&oemcfg, oem_tool.buf.buf, sizeof(iot_oem_cfg_t)); + // 修改当前指针为 iot_oem_cfg_t 结构体的长度 oem_tool.buf.len_total += sizeof(iot_oem_cfg_t); - + // 计算 iot_oem_cfg_t 结构体的crc8 此结构体的第一个字节为crc值 crc = iot_getcrc8((uint8_t*)&oemcfg + sizeof(uint8_t), sizeof(iot_oem_cfg_t) - sizeof(uint8_t)); if (crc != oemcfg.base_cfg.oem_crc) { diff --git a/pib/src/iot_oem.c b/pib/src/iot_oem.c index 671b79e..a2b56a7 100644 --- a/pib/src/iot_oem.c +++ b/pib/src/iot_oem.c @@ -66,6 +66,7 @@ const uint8_t g_iot_sec_root_sm2_pub_v1[IOT_SEC_ROOT_SM2_PUB_LEN] = { const uint8_t bcast_mac[IOT_MAC_ADDR_LEN] = { 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF }; +// 在偏移 offset 字节之后读取 uint32_t iot_oem_read_mtd(uint8_t *buf, uint32_t size, uint32_t offset) { uint32_t ret = ERR_FAIL;