阅读oem部分代码 添加一些注释

This commit is contained in:
2024-10-22 14:20:46 +08:00
parent e8adba1df2
commit 29e987e536
4 changed files with 12 additions and 1 deletions

View File

@@ -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) {