阅读oem部分代码 添加一些注释
This commit is contained in:
@@ -433,6 +433,7 @@ uint32_t dev_get_part_size(uint8_t part)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/************************ file system basics functions ************************/
|
/************************ file system basics functions ************************/
|
||||||
|
// num: flash分区 part
|
||||||
int dev_open(int num, uint32_t flags)
|
int dev_open(int num, uint32_t flags)
|
||||||
{
|
{
|
||||||
int fd;
|
int fd;
|
||||||
|
@@ -67,6 +67,8 @@ typedef struct _iot_oem_rc_hdr_v1_t {
|
|||||||
resv : 13;
|
resv : 13;
|
||||||
} iot_oem_rc_hdr_v1_t;
|
} iot_oem_rc_hdr_v1_t;
|
||||||
|
|
||||||
|
|
||||||
|
// 差分模式的差异 是对比的二进制差异
|
||||||
typedef struct _iot_oem_rc_diff_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 offset; //diff beginning offset, respect to iot_board_info_v1_t
|
||||||
uint16_t length; //current diff block length
|
uint16_t length; //current diff block length
|
||||||
|
@@ -1202,6 +1202,7 @@ void save_database_hw(const char *filename)
|
|||||||
|
|
||||||
fwrite(buf, sizeof(iot_oem_cfg_t), 1, fp);
|
fwrite(buf, sizeof(iot_oem_cfg_t), 1, fp);
|
||||||
if (oem_tool.buf.len_total) {
|
if (oem_tool.buf.len_total) {
|
||||||
|
// oem_tool.buf中存储的是差分后的配置信息 每个差分都是原配置的一个副本修改差异值
|
||||||
oem_debug_print("find diff data, write to file\n");
|
oem_debug_print("find diff data, write to file\n");
|
||||||
fwrite(oem_tool.buf.buf, sizeof(uint8_t), oem_tool.buf.len_total, fp);
|
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",
|
"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.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);
|
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),
|
crc = iot_getcrc32((uint8_t *)&ptr_rc->hdr + sizeof(uint32_t),
|
||||||
sizeof(iot_board_info_v1_t) - sizeof(uint32_t));
|
sizeof(iot_board_info_v1_t) - sizeof(uint32_t));
|
||||||
if (crc != ptr_rc->hdr.crc) {
|
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);
|
memcpy(diff_buf, &oem_tool.buf.buf[oem_tool.buf.len_total], diff_data_len);
|
||||||
oem_tool.buf.len_total += diff_data_len;
|
oem_tool.buf.len_total += diff_data_len;
|
||||||
/* restore differential data */
|
/* restore differential data */
|
||||||
|
// 这里可以支持多个差异二进制片段
|
||||||
i = 0;
|
i = 0;
|
||||||
while (i < diff_data_len) {
|
while (i < diff_data_len) {
|
||||||
iot_oem_rc_diff_v1_t *diff_temp =
|
iot_oem_rc_diff_v1_t *diff_temp =
|
||||||
@@ -1519,6 +1522,7 @@ dump:
|
|||||||
oem_resource_info_dump(&rc_info);
|
oem_resource_info_dump(&rc_info);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 读取bin文件并解析
|
||||||
void oem_bin_file_parse_hw(const char *filename)
|
void oem_bin_file_parse_hw(const char *filename)
|
||||||
{
|
{
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
@@ -1535,11 +1539,14 @@ void oem_bin_file_parse_hw(const char *filename)
|
|||||||
printf("open oem bin file(%s) succeed\n", filename);
|
printf("open oem bin file(%s) succeed\n", filename);
|
||||||
|
|
||||||
/* read oem bin file all data */
|
/* read oem bin file all data */
|
||||||
|
// 读取4k个字节的oem数据
|
||||||
fread(oem_tool.buf.buf, sizeof(oem_tool.buf.buf), 1, fp);
|
fread(oem_tool.buf.buf, sizeof(oem_tool.buf.buf), 1, fp);
|
||||||
/* not include image header information by default */
|
/* not include image header information by default */
|
||||||
|
// 把第一个配置信息复制到oemcfg结构体
|
||||||
memcpy((void*)&oemcfg, oem_tool.buf.buf, sizeof(iot_oem_cfg_t));
|
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);
|
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),
|
crc = iot_getcrc8((uint8_t*)&oemcfg + sizeof(uint8_t),
|
||||||
sizeof(iot_oem_cfg_t) - sizeof(uint8_t));
|
sizeof(iot_oem_cfg_t) - sizeof(uint8_t));
|
||||||
if (crc != oemcfg.base_cfg.oem_crc) {
|
if (crc != oemcfg.base_cfg.oem_crc) {
|
||||||
|
@@ -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 };
|
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 iot_oem_read_mtd(uint8_t *buf, uint32_t size, uint32_t offset)
|
||||||
{
|
{
|
||||||
uint32_t ret = ERR_FAIL;
|
uint32_t ret = ERR_FAIL;
|
||||||
|
Reference in New Issue
Block a user