diff --git a/build/build_flash_kl3.sh b/build/build_flash_kl3.sh index 652f665..c2c6ee3 100755 --- a/build/build_flash_kl3.sh +++ b/build/build_flash_kl3.sh @@ -741,10 +741,10 @@ build_obj_func() { export smart_cco_sta=1 . ${SRC_ENV_FILE} ${IMG_TYPE} ${APP_SELECTION} ${DEF_REL} ${DEF_FLASH} ${DEF_PSRAM} if [ "${DEF_CLEANUP}" == "true" ]; then - make -j APP=${APP_SELECTION} -C .. clobber + ./make.py -j APP=${APP_SELECTION} -C .. clobber fi if [ "${APP_SELECTION}" == "${DEF_CUS_APP}" ]; then - make -j PLATFORM=${DEF_PLATFORM_TYPE} cco=1 APP=${APP_SELECTION} FLASH_SIZE=${FLASH_SIZE_nM} PLC_SUPPORT_3_PHASE=0 -C .. + ./make.py -j PLATFORM=${DEF_PLATFORM_TYPE} cco=1 APP=${APP_SELECTION} FLASH_SIZE=${FLASH_SIZE_nM} PLC_SUPPORT_3_PHASE=0 -C .. #kl3 cus_core file. cp ../ap/.output/cus/lib/ht_cco.bin ../tools/gen_img/ht_cus.bin cp ../ap/.output/cus/lib/ht_cco.out ../tools/gen_img/ht_cus.out @@ -754,14 +754,14 @@ build_obj_func() { else #kl3 plc_core file. if [ "${DEF_FLASH}" == "4m" ] && [ "${DEF_PSRAM}" == "8m" ]; then - make -j PLATFORM=${DEF_PLATFORM_TYPE} cco=1 APP=${APP_SELECTION} FLASH_SIZE=${FLASH_SIZE_nM} -C .. + ./make.py -j PLATFORM=${DEF_PLATFORM_TYPE} cco=1 APP=${APP_SELECTION} FLASH_SIZE=${FLASH_SIZE_nM} -C .. cp ../ap/.output/plc/lib/ht_cco.bin ../tools/gen_img/iot_ht_3p.bin cp ../ap/.output/plc/lib/ht_cco.out ../tools/gen_img/ht_3p.out cp ../ap/.output/plc/lib/ht_cco.map ../tools/gen_img/ht_3p.map cp ../export/lib/libht_cco.a ${taget_cco_source_dir}/libht_plc_${plc_lib_kw}_3p.a - make -j APP=${APP_SELECTION} -C .. clobber + ./make.py -j APP=${APP_SELECTION} -C .. clobber fi - make -j PLATFORM=${DEF_PLATFORM_TYPE} cco=1 APP=${APP_SELECTION} FLASH_SIZE=${FLASH_SIZE_nM} PLC_SUPPORT_3_PHASE=0 -C .. + ./make.py -j PLATFORM=${DEF_PLATFORM_TYPE} cco=1 APP=${APP_SELECTION} FLASH_SIZE=${FLASH_SIZE_nM} PLC_SUPPORT_3_PHASE=0 -C .. cp ../ap/.output/plc/lib/ht_cco.bin ../tools/gen_img/iot_ht_1p.bin cp ../ap/.output/plc/lib/ht_cco.out ../tools/gen_img/ht_1p.out cp ../ap/.output/plc/lib/ht_cco.map ../tools/gen_img/ht_1p.map @@ -788,9 +788,9 @@ build_obj_func() { export cco=1 . ${SRC_ENV_FILE} if [ "${DEF_CLEANUP}" == "true" ]; then - make -j APP=${APP_SELECTION} -C .. clobber + ./make.py -j APP=${APP_SELECTION} -C .. clobber fi - make -j PLATFORM=${DEF_PLATFORM_TYPE} cco=1 APP=${APP_SELECTION} FLASH_SIZE=${FLASH_SIZE_nM} -C .. + ./make.py -j PLATFORM=${DEF_PLATFORM_TYPE} cco=1 APP=${APP_SELECTION} FLASH_SIZE=${FLASH_SIZE_nM} -C .. if [ "${APP_SELECTION}" == "${DEF_CUS_APP}" ]; then #kl3 customer demo, cus_core. cp ../ap/.output/cus/lib/ht_cco.bin ../tools/gen_img/ht_cus.bin @@ -837,17 +837,17 @@ build_obj_func() { export smart_cco_sta=2 . ${SRC_ENV_FILE} ${IMG_TYPE} ${APP_SELECTION} ${DEF_REL} ${DEF_FLASH} ${DEF_PSRAM} if [ "${DEF_CLEANUP}" == "true" ]; then - make -j APP=${APP_SELECTION} -C .. clobber + ./make.py -j APP=${APP_SELECTION} -C .. clobber fi - make -j PLATFORM=${DEF_PLATFORM_TYPE} cco=0 APP=${APP_SELECTION} FLASH_SIZE=${FLASH_SIZE_nM} -C .. + ./make.py -j PLATFORM=${DEF_PLATFORM_TYPE} cco=0 APP=${APP_SELECTION} FLASH_SIZE=${FLASH_SIZE_nM} -C .. . clean_env_flash_smart.sh ${IMG_TYPE} ${APP_SELECTION} else export cco=0 . ${SRC_ENV_FILE} if [ "${DEF_CLEANUP}" == "true" ]; then - make -j APP=${APP_SELECTION} -C .. clobber + ./make.py -j APP=${APP_SELECTION} -C .. clobber fi - make -j PLATFORM=${DEF_PLATFORM_TYPE} cco=0 APP=${APP_SELECTION} FLASH_SIZE=${FLASH_SIZE_nM} -C .. + ./make.py -j PLATFORM=${DEF_PLATFORM_TYPE} cco=0 APP=${APP_SELECTION} FLASH_SIZE=${FLASH_SIZE_nM} -C .. fi if [ "${APP_SELECTION}" == "${DEF_CUS_APP}" ]; then @@ -887,10 +887,10 @@ build_obj_func() { . ${SRC_ENV_FILE} if [ "${DEF_CLEANUP}" == "true" ]; then - make -j APP=${APP_SELECTION} -C .. clobber + ./make.py -j APP=${APP_SELECTION} -C .. clobber fi - make -j PLATFORM=${DEF_PLATFORM_TYPE} cco=0 APP=${APP_SELECTION} FLASH_SIZE=${FLASH_SIZE_nM} -C .. + ./make.py -j PLATFORM=${DEF_PLATFORM_TYPE} cco=0 APP=${APP_SELECTION} FLASH_SIZE=${FLASH_SIZE_nM} -C .. cp ../ap/.output/plc/lib/ht_ftm.bin ../tools/gen_img/ht.bin cp ../ap/.output/plc/lib/ht_ftm.out ../tools/gen_img/ht.out @@ -903,10 +903,10 @@ build_obj_func() { . ${SRC_ENV_FILE} if [ "${DEF_CLEANUP}" == "true" ]; then - make -j APP=${APP_SELECTION} -C .. clobber + ./make.py -j APP=${APP_SELECTION} -C .. clobber fi - make -j PLATFORM=${DEF_PLATFORM_TYPE} cco=0 APP=${APP_SELECTION} FLASH_SIZE=${FLASH_SIZE_nM} -C .. + ./make.py -j PLATFORM=${DEF_PLATFORM_TYPE} cco=0 APP=${APP_SELECTION} FLASH_SIZE=${FLASH_SIZE_nM} -C .. cp ../ap/.output/plc/lib/ht_sta.bin ../tools/gen_img/ht.bin cp ../ap/.output/plc/lib/ht_sta.out ../tools/gen_img/ht.out diff --git a/build/make.py b/build/make.py new file mode 100755 index 0000000..5fc9e7c --- /dev/null +++ b/build/make.py @@ -0,0 +1,59 @@ +#!/usr/bin/python3 +# -*- coding: utf-8 -*- + + +import os +import sys + + + + +env_dict=os.environ.copy() + + +env_dict.pop('SHELL',None) +env_dict.pop('COLORTERM',None) +env_dict.pop('TERM_PROGRAM_VERSION',None) +env_dict.pop('LANGUAGE',None) +env_dict.pop('XDG_SESSION_TYPE',None) +env_dict.pop('VSCODE_GIT_ASKPASS_NODE',None) +env_dict.pop('MOTD_SHOWN',None) +env_dict.pop('HOME',None) +env_dict.pop('LANG',None) +env_dict.pop('LS_COLORS',None) +env_dict.pop('SSL_CERT_DIR',None) +env_dict.pop('GIT_ASKPASS',None) +env_dict.pop('SSH_CONNECTION',None) +env_dict.pop('VSCODE_GIT_ASKPASS_EXTRA_ARGS',None) +env_dict.pop('LESSCLOSE',None) +env_dict.pop('XDG_SESSION_CLASS',None) +env_dict.pop('TERM',None) +env_dict.pop('LESSOPEN',None) +env_dict.pop('USER',None) +env_dict.pop('VSCODE_GIT_IPC_HANDLE',None) +env_dict.pop('SHLVL',None) +env_dict.pop('XDG_SESSION_ID',None) +env_dict.pop('XDG_RUNTIME_DIR',None) +env_dict.pop('SSL_CERT_FILE',None) +env_dict.pop('SSH_CLIENT',None) +env_dict.pop('VSCODE_GIT_ASKPASS_MAIN',None) +env_dict.pop('XDG_DATA_DIRS',None) +env_dict.pop('BROWSER',None) +env_dict.pop('PATH',None) +env_dict.pop('DBUS_SESSION_BUS_ADDRESS',None) +env_dict.pop('OLDPWD',None) +env_dict.pop('TERM_PROGRAM',None) +env_dict.pop('VSCODE_IPC_HOOK_CLI',None) +env_dict.pop('aaaaaaa',None) + + + +# print("环境变量") +# for key in env_dict: +# print(f"{key}:{env_dict[key]}") +# print("命令行参数") +# for item in sys.argv: +# print(f"{item}") +os.system(f"make {' '.join(sys.argv[1:])}") + + diff --git a/driver/src/hw3/board_info_hw.c b/driver/src/hw3/board_info_hw.c index 77b8ced..2ade79d 100644 --- a/driver/src/hw3/board_info_hw.c +++ b/driver/src/hw3/board_info_hw.c @@ -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)); diff --git a/inc/utils/iot_img_hdr.h b/inc/utils/iot_img_hdr.h index 8be81f0..054a42c 100644 --- a/inc/utils/iot_img_hdr.h +++ b/inc/utils/iot_img_hdr.h @@ -305,7 +305,7 @@ typedef struct #define HEADER_TOLTAL_SIZE 64 #define IMAGE_ALIGNED_SIZE 32 - +// 如果没有32字节对齐 把大小扩展至32字节对齐 #define IMAGE_LEN_FOR_CRC(l) ((((l)&(IMAGE_ALIGNED_SIZE-1)) ?\ (IMAGE_ALIGNED_SIZE-((l)&(IMAGE_ALIGNED_SIZE-1))) :0) + (l)) diff --git a/mfgtool/ah/add_header_v1.c b/mfgtool/ah/add_header_v1.c index 2981dd5..de6d016 100644 --- a/mfgtool/ah/add_header_v1.c +++ b/mfgtool/ah/add_header_v1.c @@ -949,6 +949,7 @@ int ah_funConstruct(char argc, char *argv[]) p_saved_buf = p_buf; if((cfg.image[cnt].image_type == imgV1OEM) || (cfg.image[cnt].image_type == imgV1CFG)) { + // OEM 和 CFG 分区强行扩展至 cfg文件指定的大小 //printf(NEW_LINE" add size :%d"NEW_LINE, fileSize); if(cfg.image[cnt].length%IMAGE_ALIGNED_SIZE) { diff --git a/pib/src/iot_oem.c b/pib/src/iot_oem.c index a2b56a7..3deb682 100644 --- a/pib/src/iot_oem.c +++ b/pib/src/iot_oem.c @@ -107,6 +107,42 @@ uint32_t iot_oem_read_mtd(uint8_t *buf, uint32_t size, uint32_t offset) return ret; } + + +// 抓取额外的差分oem数据 +uint32_t iot_oem_read_mtd_ext(uint8_t *buff,size_t buff_size) +{ + int fd; + int ret; + int offset; + int status; + int fw_prtition=PART_NUM_FW1; + do { + fd = dev_open(fw_prtition, 0); + if (fd < 0) { + fd = 0; + break; + } + status = dev_seek(fd, offset, DEV_SEEK_SET); + if (status < 0) { + break; + } + status = dev_read(fd, buff, buff_size); + if (status < 0) { + break; + } + ret = ERR_OK; + } while(0); + if (fd) { + dev_close(fd); + } + return ret; + +} + + + + static uint32_t iot_oem_write_mtd(uint8_t *buf, uint32_t size, uint32_t offset) { uint32_t ret = ERR_FAIL; @@ -230,6 +266,7 @@ uint32_t iot_oem_get_cfg_ext(iot_oem_obj_t** oem_obj) #endif if (gbl_oemcfg.ready != 1) { + // 这里只是读取基础oem配置 没有读取差分配置 ret = iot_oem_read_mtd((uint8_t*)&gbl_oemcfg.oemcfg, sizeof(iot_oem_cfg_t), IOT_OEM_SECTION_START_ADDR); diff --git a/tools/gen_img/gen_img.sh b/tools/gen_img/gen_img.sh index bf6dee5..8b59991 100755 --- a/tools/gen_img/gen_img.sh +++ b/tools/gen_img/gen_img.sh @@ -358,6 +358,7 @@ if [ "x${CHIP_VER_UPPER}" == "x3" ]; then fi # 这个部分的代码用于 给各个img.bin生成img_header + # 虽然配置文件中给每个部分得img都添加了配置 但ah中只会对fw部分的img添加img_header if [ "x${CORE_TYPE_UPPER}" == "xAMPPLC" ]; then # add run addr # 这个链接文件由 ap文件夹中的Makefile复制过来