添加oem解析相关 注释

This commit is contained in:
2024-10-25 19:37:32 +08:00
parent 0e2871e95d
commit 1a60d3f171
7 changed files with 148 additions and 16 deletions

View File

@@ -385,6 +385,21 @@ void board_oem_signal_mtx_binding(iot_board_info_v1_t *rc_info)
#endif
}
// 抓取额外的差分oem数据
static uint32_t board_load_oem_cfg_ext(uint8_t *buff,uint32_t buff_size)
{
return 0;
}
uint32_t board_load_oem_cfg()
{
iot_oem_cfg_t *oemcfg;
@@ -428,6 +443,7 @@ uint32_t board_load_oem_cfg()
ret = ERR_FAIL;
goto out;
}
// 读取oem的差分部分
ret = iot_oem_read_mtd(buf_oem, oem_part_size - oem_diff_offset,
oem_diff_offset);
if (ret != ERR_OK) {
@@ -440,31 +456,39 @@ uint32_t board_load_oem_cfg()
if (hw_ver_cal == 0xffffffff) {
hw_ver_cal = 0;
}
// ptr_rc 是 iot_board_info_v1_t 类型的指针
ptr_hdr = &ptr_rc->hdr;
hw_ver_rc = ptr_hdr->hw_version;
/* fund the matching resource table */
// 找到 硬件识别码匹配的 rc table ,找到时退出
hdr_check:
if (hw_ver_cal != hw_ver_rc) {
if (ptr_hdr->have_next == 0) {
goto out;
}
// 统计有多少个rc table
cnt_rc++;
ptr_hdr = (iot_oem_rc_hdr_v1_t *)&buf_oem[offset];
// offset 是下一个差分 rc table的偏移
offset += ptr_hdr->length + sizeof(iot_oem_rc_hdr_v1_t);
// 当前rc table 的硬件识别码
hw_ver_rc = ptr_hdr->hw_version;
goto hdr_check;
}
/* prevent array out of bounds */
// 最多只支持63个硬件识别码
if (cnt_rc >= BOARD_RESOURCE_NUM_MAX) {
IOT_ASSERT(0);
}
/* gets information about all matched headers */
// 如果rc table 大于一个 ,则需要做差分
if (cnt_rc >= 2) {
uint8_t cnt_diff_deep = 0;
/* Not differential mode, but full resource table */
// 如果不是差分模式 则直接填充
if (ptr_hdr->mode == 0) {
os_mem_cpy(&g_board_rc_info, ptr_hdr, sizeof(iot_board_info_v1_t));
ret = ERR_OK;
@@ -472,31 +496,40 @@ hdr_check:
}
/* differential mode */
// 差分模式
offset = 0;
/* get resource header information offset in diff data buffer */
// 填充 offset_array 这里跳过第0个成员
for (i = 1; i < cnt_rc; i++) { //skip the first full resource table
offset_array[i] = offset;
ptr_hdr = (iot_oem_rc_hdr_v1_t *)&buf_oem[offset];
// ptr_hdr->length 是指 负载数据的长度 不包含 hdr自己的大小
offset += ptr_hdr->length + sizeof(iot_oem_rc_hdr_v1_t);
}
/* get the difference mapping table */
// 从最后一个差分 rc table 开始,最后一个一定是当前设备使用的硬件识别码
for (i = cnt_rc - 1; i > 0;) {
uint8_t j;
uint32_t hw_ver_diff;
ptr_hdr = (iot_oem_rc_hdr_v1_t *)&buf_oem[offset_array[i]];
hw_ver_diff = ptr_hdr->diff_hw_ver;
// 记录差分深度
diff_idx_array[cnt_diff_deep] = i;
cnt_diff_deep++;
/* find father resource table */
// 从当前 rc table 的前一个开始递减
for (j = i - 1; j > 0; j--) {
ptr_hdr = (iot_oem_rc_hdr_v1_t *)&buf_oem[offset_array[j]];
if (ptr_hdr->hw_version == hw_ver_diff) {
// 如果 硬件识别码与当前rc table 的差分相等时 更新当前 rc table 序号
i = j;
// 如果某个 rc table 不是差分模式 则直接复制过来
if (ptr_hdr->mode == 0) {
/* father rc table is full rc table */
os_mem_cpy(&g_board_rc_info, ptr_hdr,
sizeof(iot_board_info_v1_t));
// 循环变量设为0 直接跳出两层循环
j = 0;
}
break;
@@ -512,6 +545,7 @@ hdr_check:
uint16_t offset_temp;
iot_oem_rc_diff_v1_t *ptr_diff;
uint8_t diff_idx = diff_idx_array[i];
//
ptr_hdr = (iot_oem_rc_hdr_v1_t *)&buf_oem[offset_array[diff_idx]];
/* copy header info */
os_mem_cpy(&g_board_rc_info, ptr_hdr, sizeof(iot_oem_rc_hdr_v1_t));