初始提交

This commit is contained in:
2025-05-13 22:00:58 +08:00
commit e4c030b0c0
564 changed files with 78858 additions and 0 deletions

View File

@ -0,0 +1,189 @@
#!/usr/bin/env python3
# encoding=utf-8
# =========================================================================
# @brief Project genarator, parse compiler info & generate IAR/Makefile... project file
# Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2022-2022. All rights reserved.
# =========================================================================
import copy
import os
import json
import re
import shutil
import sys
script_dir = os.path.split(os.path.normpath(__file__))[0]
makefile_template = os.path.join(script_dir, "sdk_template", "makefile")
def load_json(json_file):
with open(json_file, 'r') as f:
temp = f.read()
return json.loads(temp)
class CompileCommandParser:
def __init__(self, cc_file):
temp = load_json(cc_file)
self.compile_info = {}
for item in temp:
self.compile_info[item['file']] = {
'command': item['command'],
'directory': item['directory'],
}
def get_src_compile_info(self, src_name):
command = self.compile_info[src_name]['command']
defines = re.findall(r"-D([^ ]*)", command)
includes = re.findall(r"-I([^ ]*)", command)
ccflags = list(set(re.findall(r" (-[^ID][^ ]*)", command)))
ccflags.remove('-c')
ccflags.remove('-o')
pre_include = []
if '-include' in ccflags:
ccflags.remove('-include')
pre_include = list(set(re.findall(r" -include ([^ ]*)", command)))
ccflags.extend(['-include ' + x for x in pre_include])
return {
"DEFINES": list(set(defines)),
"INCLUDES": list(set(includes)),
"CCFLAGS": ccflags,
"PRE_INCLUDE": pre_include,
}
class ComponentParser(CompileCommandParser):
def __init__(self, component_info_file, compile_command_file):
super(ComponentParser, self).__init__(compile_command_file)
with open(component_info_file, 'r') as fp:
data = fp.read()
data = data.replace('="', r'=\\\"')
data = data.replace('";', r'\\\";')
data = data.replace(r' \\\";', r' ";')
info = json.loads(data)
self.component_info = info.pop("COMPONENTS")
self.public_info = copy.deepcopy(info)
self.public_info["COMPONENT_LIST"] = list(self.component_info.keys())
self.public_info["CHIP"] = chip
self.public_info["CORE"] = core
self.public_info["ARCH"] = arch
self.public_info["TARGET_NAME"] = application_name
self.public_info["PKG_TARGET_NAME"] = pkg_target_name
for item, value in self.public_info.items():
if isinstance(value, str):
self.public_info[item] = [i for i in value.split(";") if i != '']
for component, value in self.component_info.items():
if not value["SOURCES"]:
continue
for component_items in value:
if isinstance(value[component_items], str):
value[component_items] = [i for i in value[component_items].split(";") if i != '']
src = value["SOURCES"]
class MakefileGenerator(ComponentParser):
def __init__(self, component_info_file, compile_command_file, project_file_dir, project_folder):
super(MakefileGenerator, self).__init__(component_info_file, compile_command_file)
self.replace_map = {}
# self.replace_map.update(toolchain)
self.project_file_dir = project_file_dir
self.project_folder = project_folder
self.make_dir = os.path.join(project_file_dir, project_folder, 'makefile')
if not os .path.exists(self.make_dir):
os.makedirs(self.make_dir)
self.gen_toolchain_file()
for component_name in self.component_info:
self.gen_component_file(component_name)
self.gen_root_file()
self.gen_makefile_cmd()
def gen_makefile_cmd(self):
with open(os.path.join(sdk_output_dir, f'make.cmd'), 'a+') as f:
f.writelines(self.make_dir + '\n')
def gen_toolchain_file(self):
with open(os.path.join(makefile_template, 'toolchain.make'), 'r') as f:
lines = f.readlines()
toolchain = load_json(toolchain_file)
for i, line in enumerate(lines):
lines[i] = self.deal_replace(line, toolchain)
with open(os.path.join(self.make_dir, f'toolchains.make'), 'w') as f:
f.writelines(lines)
def gen_component_file(self, component_name):
compile_info = self.component_info[component_name]
template = os.path.join(makefile_template, 'component_template.make')
out_path = 'components'
if "THIRD_PARTY" in compile_info:
print(compile_info["SOURCES"])
if "THIRD_PARTY" in compile_info and compile_info["THIRD_PARTY"][0] == "true":
template = os.path.join(makefile_template, 'third_party_template.make')
index = compile_info['COMPONENT_CUSTOM_CCFLAGS'].index("-include")
if index >= 0:
compile_info['COMPONENT_CUSTOM_CCFLAGS'][index] = "-include$(LITEOS_PLATFORM_MENUCONFIG_H)"
compile_info['COMPONENT_CUSTOM_CCFLAGS'].pop(index+1)
compile_info["COMPONENT_NAME"] = component_name
with open(template, 'r') as f:
lines = f.readlines()
for i, line in enumerate(lines):
lines[i] = self.deal_replace(line, compile_info)
if not os.path.exists(os.path.join(self.make_dir, out_path)):
os.makedirs(os.path.join(self.make_dir, out_path))
with open(os.path.join(self.make_dir, out_path, f'{component_name}.make'), 'w') as f:
f.writelines(lines)
def gen_root_file(self):
with open(os.path.join(makefile_template, 'template.mk'), 'r') as f:
lines = f.readlines()
for i, line in enumerate(lines):
lines[i] = self.deal_replace(line, self.public_info)
# if not os.path.exists(os.path.join(self.make_dir, 'components')):
# os.makedirs(os.path.join(self.make_dir, 'components'))
with open(os.path.join(self.make_dir, 'Makefile'), 'w') as f:
f.writelines(lines)
def join_by_clum_num(self, lst, word, clum_num):
res = []
if not lst:
return res
c_word = lst[0]
for item in lst:
if item == "":
continue
if c_word == 0:
c_word = item
continue
if len(c_word) + len(word) + len(item) <= clum_num:
c_word = f"{c_word}{word}{item}"
continue
res.append(c_word)
c_word = item
return res
def deal_replace(self, line, replace_map):
l = re.findall("REPLACE_(\w*)", line)
for item in l:
if isinstance(replace_map[item], list):
replace_str = " \\\n ".join(replace_map[item])
if replace_str:
replace_str = " \\\n %s" % (replace_str.strip())
replace_str = replace_str.replace(root_dir, "$(SDK_ROOT)")
elif isinstance(replace_map[item], str):
replace_str = replace_map[item].replace(root_dir, "$(SDK_ROOT)")
else:
print(replace_map[item])
line = line.replace(f"REPLACE_{item}", replace_str)
return line
if __name__ == "__main__":
project_type = sys.argv[1]
application_name = sys.argv[2]
cc_json = sys.argv[3]
project_file_dir = sys.argv[4]
root_dir = sys.argv[5]
sdk_output_dir = sys.argv[6]
chip, core, board, arch, os_kernel, pkg_target_name = sys.argv[7].split(",")
toolchain_file = sys.argv[8]
component_info_file = sys.argv[9]
project_folder = f"{chip}_{core}_{board}_{os_kernel}_{pkg_target_name}"
project_type_list = project_type.split(",")
if 'makefile' in project_type_list:
MakefileGenerator(component_info_file, cc_json, project_file_dir, project_folder)

View File

@ -0,0 +1,323 @@
#!/usr/bin/env python3
# coding=utf-8
# Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2022-2022. All rights reserved.
import json
import os
import sys
import time
import re
from utils.build_utils import root_path, script_path, target_config_path, output_root
from utils.build_utils import pkg_tools_path, jlink_tools_path, lzma_tools_path, sign_tools_path, derived_tools_path, radar_tools_path
from utils.build_utils import CopyModule, exec_shell, cmp_file, rm_pyc, rm_all, fn_get_subdirs
from enviroment import TargetEnvironment
from sdk_generator.target_config_genarator import genarate_reserve_config
sdk_copy_common_files = [
os.path.join(script_path),
os.path.join(root_path, 'build.py'),
os.path.join(target_config_path),
os.path.join(pkg_tools_path),
os.path.join(jlink_tools_path),
os.path.join(lzma_tools_path),
os.path.join(sign_tools_path),
os.path.join(derived_tools_path),
os.path.join(radar_tools_path),
]
sdk_close_components = [
]
def compare_path_bin(path1, path2):
for file in os.listdir(path1):
if not file.endswith('.bin'):
continue
if file.endswith('sign.bin'):
continue
f1 = os.path.join(path1, file)
f2 = os.path.join(path2, file)
print("Comparing:")
print(f1)
print(f2)
if not cmp_file(f1, f2):
print("DIFF")
return False
print("SAME")
return True
class SdkGenerator:
def __init__(self, env: TargetEnvironment, sdk_root_path: str):
self.env = env
self.sdk_root_path = sdk_root_path
replace_suffix = ['.srcrelease']
if self.env.get('replace_suffix', False):
replace_suffix = self.env.get('replace_suffix', False)
print(replace_suffix)
self.copy_module = CopyModule(replace_root=sdk_root_path, replace_suffix=replace_suffix, copy_header = False)
self.org_target_output_path = []
self.rm_line_map = {}
self.sub_cmake = {}
self.all_cmake = {}
chip = self.env.get("chip", False)
if not isinstance(chip, list):
self.chip = [chip]
else:
self.chip = chip
self.sdk_copy_module_mask_add()
self.copy_module.append_mask('.srcrelease')
def parse_depend_cmake_files(self, cmake_trace_file):
with open(cmake_trace_file, 'r') as fp:
lines = fp.readlines()
sdk_cmake_dict = {}
depend_cmake_files = []
for line in lines:
dict_ = json.loads(line)
if 'file' not in dict_:
continue
f = dict_['file']
if not f.startswith(root_path) or f.startswith(output_root):
continue
if 'cmd' in dict_ and dict_['cmd'] == 'add_subdirectory':
if f not in self.sub_cmake:
self.sub_cmake[f] = set()
file_path = os.path.dirname(f)
if "$" in dict_['args'][0]:
continue
depend_cmake = os.path.join(file_path, dict_['args'][0], "CMakeLists.txt")
self.sub_cmake[f].add((int(dict_['line']), depend_cmake))
if f in sdk_cmake_dict:
continue
sdk_cmake_dict[f] = None
self.all_cmake[f] = None
tmp = f.replace(root_path, self.sdk_root_path)
if self.is_close_component(tmp) == False:
if tmp.endswith("CMakeLists.txt"):
if os.path.exists(os.path.dirname(tmp)):
depend_cmake_files.append(f)
else:
depend_cmake_files.append(f)
return depend_cmake_files
def copy_menuconfig(self):
for chip in self.chip:
if os.path.exists(os.path.join(root_path, 'build', 'config', 'target_config', chip, 'menuconfig')):
self.copy_srcs([os.path.join(root_path, 'build', 'config', 'target_config', chip, 'menuconfig')])
self.copy_srcs([os.path.join(root_path, 'config.in')])
def copy_kconfig(self, cmake_trace_file):
depend_cmake_files = self.parse_depend_cmake_files(cmake_trace_file)
kconfig_fils = []
for f in depend_cmake_files:
tmp = f.replace("CMakeLists.txt", 'Kconfig')
if os.path.exists(tmp):
kconfig_fils.append(tmp)
self.copy_srcs(kconfig_fils)
def copy_depends(self, cmake_trace_file):
depend_cmake_files = self.parse_depend_cmake_files(cmake_trace_file)
cmake_dest = self.copy_srcs(depend_cmake_files)
for path in sdk_copy_common_files:
if not os.path.exists(path):
sdk_copy_common_files.remove(path)
self.copy_srcs(sdk_copy_common_files)
if self.env.get('use_memuconfig') != False:
self.copy_menuconfig()
self.copy_kconfig(cmake_trace_file)
if self.env.get('auto_gen_config'):
self.genarate_sdk_target_config(self.env.get('pkg_target_name', False))
def genarate_sdk_target_config(self, targets):
reserve = {}
for target in targets:
env = TargetEnvironment(target)
chip = env.get('chip')
if chip not in reserve:
reserve[chip] = {'target': [], 'template': []}
reserve[chip]['target'].append(target)
reserve[chip]['template'].append(env.get_target_template())
print(reserve)
for chip in reserve:
path = os.path.join(self.sdk_root_path, 'build', 'config', 'target_config', chip)
config_path = os.path.join(path, 'config.py')
template_path = os.path.join(path, 'target_config.py')
genarate_reserve_config(reserve[chip]['target'], config_path)
genarate_reserve_config(reserve[chip]['template'], template_path)
def rm_lines_in_file(self, _file, lines):
with open(_file, 'r') as fp_read:
text = fp_read.readlines()
lines = sorted(list(set(lines)), reverse=True)
for idx in lines:
text.pop(idx - 1)
with open(_file, 'w') as fp_write:
fp_write.write("".join(text))
def copy_srcs(self, file_list):
dest_src = []
for file in file_list:
if not os.path.exists(file):
print("SDK GENERATE ERROR!!")
print("FILE: %s is not exists!!" % file)
raise
dest = self.copy_module.copy(file)
if dest is not None:
dest_src.append(dest)
return dest_src
def register_org_target_path(self, path):
self.org_target_output_path.append(path)
def rm_cmake_lines(self):
rm_lines = {}
for f, line_dep in self.sub_cmake.items():
for line, dep_cmake in line_dep:
if dep_cmake in self.all_cmake:
continue
if f not in rm_lines:
rm_lines[f] = []
rm_lines[f].append(line)
for f, lines in rm_lines.items():
sdk_file = f.replace(root_path, self.sdk_root_path)
self.rm_lines_in_file(sdk_file, lines)
def sdk_copy_module_mask_add(self):
chip_mask = []
path_list = [target_config_path]
for path_mask in path_list:
for name in fn_get_subdirs(path_mask):
if name not in self.chip and name not in chip_mask:
chip_mask.append(name)
self.copy_module.append_mask(chip_mask)
def is_closed_component(self, component_name):
closed_components = self.env.get('closed_components', cmake_type=False)
open_components = self.env.get('open_components', cmake_type=False)
if isinstance(closed_components, list) and component_name in closed_components:
return True
elif isinstance(open_components, list) and component_name not in open_components:
return True
return False
def sdk_delete_tmp_files(self):
delete_files = []
delete_files.append(os.path.join(output_root, 'sdk', 'output'))
delete_files.append(os.path.join(output_root, 'sdk', 'make.cmd'))
for dir_path, dir_names, file_names in os.walk(os.path.join(output_root, 'sdk', 'interim_binary', self.env.get('chip'), 'libs'), topdown=False):
for name in file_names:
if name.endswith('.a'):
if not self.is_closed_component(name[3:-2]):
delete_files.append(os.path.join(dir_path, name))
for dir_path, dir_names, file_names in os.walk(os.path.join(output_root, 'sdk', 'build', 'config', 'target_config', self.env.get('chip')), topdown=False):
for name in file_names:
if name.endswith('.srcrelease'):
delete_files.append(os.path.join(dir_path, name))
rm_all(delete_files)
rm_pyc(os.path.join(output_root, 'sdk', 'build'))
rm_pyc(os.path.join(output_root, 'sdk', 'tools', 'pkg'))
def sdk_build(self, build_time, nhso, build_level):
org_pwd = os.getcwd()
os.chdir(self.sdk_root_path)
self.close_sdk_mem_limit()
self.change_sdk_version()
build_targets = self.env.get('pkg_target_name', cmake_type=False)
print(build_targets)
sdk_type_list = self.env.get('sdk_type').split(';')
for idx, target in enumerate(build_targets):
sdk_build_cmd = ['./build.py', target]
if build_time != '':
sdk_build_cmd.append("-build_time=%s" %build_time)
if nhso == True:
sdk_build_cmd.append("-nhso")
if build_level == 'release':
sdk_build_cmd.append("-release")
ret_code = exec_shell(sdk_build_cmd)
if ret_code:
sys.exit(1)
org_output_path = self.org_target_output_path[idx]
sdk_output_path = org_output_path.replace(root_path, self.sdk_root_path)
if not compare_path_bin(sdk_output_path, org_output_path):
print("sdk build failed")
sys.exit(1)
os.chdir(org_pwd)
if "makefile" in sdk_type_list:
self.sdk_makefile_build(nhso, build_level)
self.sdk_delete_tmp_files()
def close_sdk_mem_limit(self):
if "SDK_NOT_MEM_LIMIT" not in self.env.config.get("defines", []):
return
chip_config_path = os.path.join('build', 'config', 'target_config', self.env.get('chip'), 'target_config.py')
with open(chip_config_path, "r") as f:
config_content = f.read()
print("new defines: SDK_NOT_MEM_LIMI, do not limit the memory size of the target in sdk")
with open(chip_config_path, "w") as f:
config_content = re.sub(r"'defines'\s?:\s?\[", r"'defines': [" + "'SDK_NOT_MEM_LIMIT', ", config_content)
f.write(config_content)
return
def change_sdk_version(self):
sdk_version_cmd_define = ""
for build_def in self.env.config.get("defines", []):
if "SDK_VERSION=" not in build_def:
continue
sdk_version_cmd_define = build_def
break
if not sdk_version_cmd_define:
return
chip_config_path = os.path.join('build', 'config', 'target_config', self.env.get('chip'), 'target_config.py')
with open(chip_config_path, "r") as f:
config_content = f.read()
print(config_content)
print(f"change defines: {sdk_version_cmd_define}, change the version of sdk")
with open(chip_config_path, "w") as f:
sdk_version_cmd_define = sdk_version_cmd_define.replace("\"", "\\\"")
config_content = re.sub("SDK_VERSION" + r'''=.*?",''', sdk_version_cmd_define + '''",''', config_content)
print(config_content)
f.write(config_content)
return
def is_close_component(self, path):
for f in sdk_close_components:
tmp = f.replace(root_path, self.sdk_root_path)
if path.startswith(tmp):
return True
return False
def sdk_makefile_build(self, nhso, build_level):
with open(os.path.join(self.sdk_root_path, 'make.cmd'), 'r') as fp:
lines = fp.readlines()
idx = 0
for line in lines:
org_pwd = os.getcwd()
start_time = time.time()
line = line.replace('\n', '')
os.chdir(line)
sdk_build_cmd = ['make', '-j48']
if nhso == True:
sdk_build_cmd.append("nhso=true")
if build_level == 'release':
sdk_build_cmd.append("build_level=release")
ret_code = exec_shell(sdk_build_cmd)
if ret_code:
sys.exit(1)
end_time = time.time()
print("build %s takes %f s" % (line, end_time - start_time))
org_output_path = self.org_target_output_path[idx]
sdk_output_path_makefile = "%s-makefile" % org_output_path.replace(root_path, self.sdk_root_path)
if not compare_path_bin(sdk_output_path_makefile, org_output_path):
print("sdk build failed")
sys.exit(1)
os.chdir(org_pwd)
idx = idx + 1

View File

@ -0,0 +1,91 @@
SRC_REPLACE_COMPONENT_NAME=REPLACE_SOURCES
C_OBJ_REPLACE_COMPONENT_NAME = $(subst $(SDK_ROOT),$(OUTPUT_DIR),$(patsubst %,%.obj,$(filter %.c,$(SRC_REPLACE_COMPONENT_NAME))))
CPP_OBJ_REPLACE_COMPONENT_NAME = $(subst $(SDK_ROOT),$(OUTPUT_DIR),$(patsubst %,%.obj,$(filter %.cpp,$(SRC_REPLACE_COMPONENT_NAME))))
CPP_OBJ_REPLACE_COMPONENT_NAME += $(subst $(SDK_ROOT),$(OUTPUT_DIR),$(patsubst %,%.obj,$(filter %.cc,$(SRC_REPLACE_COMPONENT_NAME))))
S_OBJ_REPLACE_COMPONENT_NAME = $(subst $(SDK_ROOT),$(OUTPUT_DIR),$(patsubst %,%.obj,$(filter %.S,$(SRC_REPLACE_COMPONENT_NAME))))
s_OBJ_REPLACE_COMPONENT_NAME = $(subst $(SDK_ROOT),$(OUTPUT_DIR),$(patsubst %,%.obj,$(filter %.s,$(SRC_REPLACE_COMPONENT_NAME))))
ALL_OBJ_REPLACE_COMPONENT_NAME = $(subst $(SDK_ROOT),$(OUTPUT_DIR),$(patsubst %,%.obj,$(SRC_REPLACE_COMPONENT_NAME)))
INCLUDES_TEMP_REPLACE_COMPONENT_NAME = REPLACE_PRIVATE_INCLUDE
INCLUDES_REPLACE_COMPONENT_NAME = $(patsubst %,-I%,$(INCLUDES_TEMP_REPLACE_COMPONENT_NAME))
INCLUDES_REPLACE_COMPONENT_NAME += $(PUBLIC_INCLUDES)
CCFLAGS_REPLACE_COMPONENT_NAME = $(PUBLIC_CCFLAGS)
CCFLAGS_REPLACE_COMPONENT_NAME += REPLACE_PRIVATE_CCFLAGS
DEFINES_REPLACE_COMPONENT_NAME = $(PUBLIC_DEFINES)
DEFINES_TEMP_REPLACE_COMPONENT_NAME = REPLACE_PRIVATE_DEFINES
DEFINES_REPLACE_COMPONENT_NAME += $(patsubst %,-D%,$(DEFINES_TEMP_REPLACE_COMPONENT_NAME))
LIBS_REPLACE_COMPONENT_NAME = REPLACE_LIBS
WHOLE_LINK_REPLACE_COMPONENT_NAME = REPLACE_WHOLE_LINK
ifeq ("$(WHOLE_LINK_REPLACE_COMPONENT_NAME)", "true")
WHOLE_LINK_LIBS += REPLACE_COMPONENT_NAME
WHOLE_EXTERN_LINK_LIBS += $(LIBS_REPLACE_COMPONENT_NAME)
else
NORMAL_LINK_LIBS += REPLACE_COMPONENT_NAME
NORMAL_EXTERN_LINK_LIBS += $(LIBS_REPLACE_COMPONENT_NAME)
endif
COMPONENT_NAME_REPLACE_COMPONENT_NAME=REPLACE_COMPONENT_NAME
LIB_DIR_TEMP_REPLACE_COMPONENT_NAME = REPLACE_LIB_DIR
LIB_DIR_REPLACE_COMPONENT_NAME = $(subst $(SDK_ROOT),$(OUTPUT_DIR),$(LIB_DIR_TEMP_REPLACE_COMPONENT_NAME))
LIB_DIR += $(LIB_DIR_REPLACE_COMPONENT_NAME)
LIB_EXIST := $(shell if [ -e "$(LIB_DIR_TEMP_REPLACE_COMPONENT_NAME)/lib$(COMPONENT_NAME_REPLACE_COMPONENT_NAME).a" ]; then echo "exist"; else echo "noexist"; fi )
MODULE_NAME_TEMP_REPLACE_COMPONENT_NAME = REPLACE_MODULE_NAME
AUTO_DEF_TEMP_REPLACE_COMPONENT_NAME = REPLACE_AUTO_DEF
lib$(COMPONENT_NAME_REPLACE_COMPONENT_NAME).a:$(ALL_OBJ_REPLACE_COMPONENT_NAME) HSO_DB_$(COMPONENT_NAME_REPLACE_COMPONENT_NAME)
@mkdir -p $(LIB_DIR_REPLACE_COMPONENT_NAME)
@$(RM) $(LIB_DIR_REPLACE_COMPONENT_NAME)/lib$(COMPONENT_NAME_REPLACE_COMPONENT_NAME).a
ifeq ("$(LIB_EXIST)", "noexist")
@echo building $(LIB_DIR_REPLACE_COMPONENT_NAME)/lib$(COMPONENT_NAME_REPLACE_COMPONENT_NAME).a
@$(AR) -rc $(LIB_DIR_REPLACE_COMPONENT_NAME)/lib$(COMPONENT_NAME_REPLACE_COMPONENT_NAME).a $(ALL_OBJ_REPLACE_COMPONENT_NAME)
else
@echo copy $(LIB_DIR_REPLACE_COMPONENT_NAME)/lib$(COMPONENT_NAME_REPLACE_COMPONENT_NAME).a
@cp $(LIB_DIR_TEMP_REPLACE_COMPONENT_NAME)/lib$(COMPONENT_NAME_REPLACE_COMPONENT_NAME).a $(LIB_DIR_REPLACE_COMPONENT_NAME)
endif
$(C_OBJ_REPLACE_COMPONENT_NAME): $(OUTPUT_DIR)/%.obj : $(SDK_ROOT)/%
@echo Building $<
@mkdir -p $(dir $@)
@${CCACHE} $(CC) -c $(INCLUDES_REPLACE_COMPONENT_NAME) $(DEFINES_REPLACE_COMPONENT_NAME) $(CCFLAGS_REPLACE_COMPONENT_NAME) -DTHIS_FILE_ID=$(shell echo $(patsubst %.c, %_c, $(notdir $<)) | tr '[a-z]' '[A-Z]') -DTHIS_MOD_ID=$(shell echo LOG_$(MODULE_NAME_TEMP_REPLACE_COMPONENT_NAME)MODULE | tr '[a-z]' '[A-Z]') $< -o $@;
$(CPP_OBJ_REPLACE_COMPONENT_NAME): $(OUTPUT_DIR)/%.obj : $(SDK_ROOT)/%
@echo Building $<
@mkdir -p $(dir $@)
@${CCACHE} $(CXX) -c $(INCLUDES_REPLACE_COMPONENT_NAME) $(DEFINES_REPLACE_COMPONENT_NAME) $(CCFLAGS_REPLACE_COMPONENT_NAME) -DTHIS_FILE_ID=$(shell echo $(patsubst %.cpp, %_cpp, $(notdir $<)) | tr '[a-z]' '[A-Z]') -DTHIS_MOD_ID=$(shell echo LOG_$(MODULE_NAME_TEMP_REPLACE_COMPONENT_NAME)MODULE | tr '[a-z]' '[A-Z]') $< -o $@;
$(s_OBJ_REPLACE_COMPONENT_NAME): $(OUTPUT_DIR)/%.obj : $(SDK_ROOT)/%
@echo Building $<
@mkdir -p $(dir $@)
@$(AS) -c $(INCLUDES_REPLACE_COMPONENT_NAME) $(DEFINES_REPLACE_COMPONENT_NAME) $(CCFLAGS_REPLACE_COMPONENT_NAME) -DTHIS_FILE_ID=$(shell echo $(patsubst %.c, %_c, $(notdir $<)) | tr '[a-z]' '[A-Z]') -DTHIS_MOD_ID=$(shell echo LOG_$(MODULE_NAME_TEMP_REPLACE_COMPONENT_NAME)MODULE | tr '[a-z]' '[A-Z]') $< -o $@;
$(S_OBJ_REPLACE_COMPONENT_NAME): $(OUTPUT_DIR)/%.obj : $(SDK_ROOT)/%
@echo Building $<
@mkdir -p $(dir $@)
@$(AS) -c $(INCLUDES_REPLACE_COMPONENT_NAME) $(DEFINES_REPLACE_COMPONENT_NAME) $(CCFLAGS_REPLACE_COMPONENT_NAME) -DTHIS_FILE_ID=$(shell echo $(patsubst %.c, %_c, $(notdir $<)) | tr '[a-z]' '[A-Z]') -DTHIS_MOD_ID=$(shell echo LOG_$(MODULE_NAME_TEMP_REPLACE_COMPONENT_NAME)MODULE | tr '[a-z]' '[A-Z]') $< -o $@;
HSO_DB_$(COMPONENT_NAME_REPLACE_COMPONENT_NAME):
ifneq ("$(BIN_NAME).bin", "ssb.bin")
ifneq ("$(words $(SRC_REPLACE_COMPONENT_NAME))", "0")
ifneq ($(nhso), true)
ifeq ("$(LIB_EXIST)", "noexist")
@echo building $(COMPONENT_NAME_REPLACE_COMPONENT_NAME) HSO DB
@echo -n $(LOG_DEF_LIST) | sed 's/ /,/g' > $(HSO_TMP)/$(COMPONENT_NAME_REPLACE_COMPONENT_NAME).txt
@echo -n "####" >> $(HSO_TMP)/$(COMPONENT_NAME_REPLACE_COMPONENT_NAME).txt
@echo -n $(SRC_REPLACE_COMPONENT_NAME) | sed 's/ /,/g' >> $(HSO_TMP)/$(COMPONENT_NAME_REPLACE_COMPONENT_NAME).txt
@python3 $(HSO_MK_XML_PY) ${SDK_ROOT}/ ${CHIP} ${CORE} ${ARCH} ${AUTO_DEF_TEMP_REPLACE_COMPONENT_NAME} ${MODULE_NAME_TEMP_REPLACE_COMPONENT_NAME} FALSE $(HSO_TMP)/$(COMPONENT_NAME_REPLACE_COMPONENT_NAME).txt
endif
endif
else
@echo "skip building $(COMPONENT_NAME_REPLACE_COMPONENT_NAME) HSO DB"
endif
endif
include ./toolchains.make

View File

@ -0,0 +1,93 @@
export SDK_ROOT:=$(abspath $(shell pwd)/../../../../..)
export CHIP=REPLACE_CHIP
export CORE=REPLACE_CORE
export ARCH=REPLACE_ARCH
export ARCH_FAMILY=REPLACE_ARCH_FAMILY
export TARGET_NAME=REPLACE_TARGET_NAME
export KERNEL=REPLACE_KERNEL
export LOG_DEF_LIST=REPLACE_LOG_DEF_LIST
export PKG_TARGET_NAME=REPLACE_PKG_TARGET_NAME
export OUTPUT_DIR:=$(SDK_ROOT)/output/$(CHIP)/$(CORE)/$(PKG_TARGET_NAME)-makefile
export HSO_TMP:=$(SDK_ROOT)/output/hso_temp
export HSO_MK_XML_PY:= $(SDK_ROOT)/build/script/hdbxml/mk_hso_prim_xml.py
export HSO_XML_PRE_PROCESS_PY:= $(SDK_ROOT)/build/script/hdbxml/process_pregenerated_xml.py
export HSO_XML_MERGE_PY:= $(SDK_ROOT)/build/script/hdbxml/hso_prim_xml_merge.py
export HSO_XML_DB_CREATE_PY:= $(SDK_ROOT)/build/script/hdbxml/database_create.py
export BUILD_UTILS_PY:=$(SDK_ROOT)/build/script/utils/build_utils.py
export CCACHE := ccache
ifeq ("$(KERNEL)", "liteos")
export LOS_PUB_CCFLAGS=REPLACE_LOS_PUB_CCFLAGS
export LOS_ROOT=REPLACE_LOS_ROOT
export LITEOS_PLATFORM_MENUCONFIG_H=$(OUTPUT_DIR)/menuconfig/menuconfig.h
endif
export COMPONENT_LIST=REPLACE_COMPONENT_LIST
export BIN_NAME=REPLACE_BIN_NAME
LINKFLAGS=REPLACE_LINKFLAGS
LINK_SCRIPT=REPLACE_LINK_SCRIPT
PUBLIC_INCLUDES_TEMP=REPLACE_PUBLIC_INCLUDES
export PUBLIC_INCLUDES = $(patsubst %,-I%,$(PUBLIC_INCLUDES_TEMP))
export PUBLIC_CCFLAGS=REPLACE_PUBLIC_CCFLAGS
PUBLIC_DEFINES_TEMP=REPLACE_PUBLIC_DEFINES
export PUBLIC_DEFINES = $(patsubst %,-D%,$(PUBLIC_DEFINES_TEMP))
export LIB_DIR = $(OUTPUT_DIR)/libs
export WHOLE_LINK_LIBS =
export NORMAL_LINK_LIBS =
export WHOLE_EXTERN_LINK_LIBS =
export NORMAL_EXTERN_LINK_LIBS =
-include ./toolchains.make
ELF_FILE=$(OUTPUT_DIR)/$(BIN_NAME).elf
MAP_FILE=$(OUTPUT_DIR)/$(BIN_NAME).map
all: pre_build $(ELF_FILE) post_build
COMPONENT_LIST_LIB = $(patsubst %,lib%.a,$(COMPONENT_LIST))
pre_build:
@rm -fr ${OUTPUT_DIR}
@mkdir -p $(OUTPUT_DIR)/libs
@mkdir -p $(HSO_TMP)
ifeq ("$(KERNEL)", "liteos")
@mkdir -p $(dir $(LITEOS_PLATFORM_MENUCONFIG_H))
@$(LOS_ROOT)/Huawei_LiteOS/build/make/make_menuconfig_headfile.sh $(LOS_ROOT)/Huawei_LiteOS/tools/build/config/$(CHIP).config $(LITEOS_PLATFORM_MENUCONFIG_H)
endif
@python3 $(HSO_MK_XML_PY) mkdir ${SDK_ROOT}/ ${CHIP} ${CORE}
@$(CC) -P -xc -E -o $(OUTPUT_DIR)/linker.lds $(PUBLIC_INCLUDES) $(PUBLIC_CCFLAGS) $(PUBLIC_DEFINES) $(LINK_SCRIPT)
@echo built $(OUTPUT_DIR)/linker.lds
@echo pre_build
post_build:$(ELF_FILE)
ifneq ($(build_level), release)
$(OBJDUMP) -x -S -l $(ELF_FILE) > $(OUTPUT_DIR)/$(BIN_NAME).lst
$(OBJDUMP) -d -m $(ARCH_FAMILY) $(ELF_FILE) > $(OUTPUT_DIR)/$(BIN_NAME).asm
$(NM) -S -n --format=sysv $(ELF_FILE) > $(OUTPUT_DIR)/$(BIN_NAME).nm
$(OBJDUMP) -Wi $(ELF_FILE) > $(OUTPUT_DIR)/$(BIN_NAME).info
endif
$(OBJCOPY) --gap-fill 0xFF -O binary -R .logstr -R .ARM -R .ARM $(ELF_FILE) $(OUTPUT_DIR)/$(BIN_NAME).bin
ifeq ("$(BIN_NAME).bin", "ssb.bin")
@python3 $(BUILD_UTILS_PY) add_len_and_sha256_info_to_ssb $(OUTPUT_DIR)/$(BIN_NAME).bin $(CHIP)
else
ifneq ($(nhso), true)
@echo "Merge HSO_XML & Create HSO_DB"
@python3 ${HSO_XML_PRE_PROCESS_PY} ${SDK_ROOT}/ ${CHIP} ${CORE}
@python3 ${HSO_XML_MERGE_PY} ${SDK_ROOT}/ ${CHIP} ${CORE}
@python3 ${HSO_XML_MERGE_PY} ${SDK_ROOT}/ ${CHIP} "dsp_core"
@python3 ${HSO_XML_MERGE_PY} ${SDK_ROOT}/ ${CHIP} "bt_core"
@python3 ${HSO_XML_DB_CREATE_PY} ${SDK_ROOT}/ ${CHIP}
endif
endif
@rm $(HSO_TMP) -fr
@echo post_build
STD_LIB_DIR = REPLACE_STD_LIB_DIR
STD_LIBS = REPLACE_STD_LIBS
-include $(patsubst %,./components/%.make,$(COMPONENT_LIST))
$(ELF_FILE):pre_build $(COMPONENT_LIST_LIB)
@echo buiilding $(ELF_FILE)
@$(CC) $(LINKFLAGS) -Wl,-T$(OUTPUT_DIR)/linker.lds $(patsubst %,-L%,$(LIB_DIR)) -Wl,--whole-archive $(patsubst %,-l%,$(WHOLE_LINK_LIBS)) $(WHOLE_EXTERN_LINK_LIBS) -Wl,--no-whole-archive $(NORMAL_EXTERN_LINK_LIBS) $(patsubst %,-l%,$(NORMAL_LINK_LIBS)) $(patsubst %,-L%,$(STD_LIB_DIR)) -Wl,--start-group $(patsubst %,-l%,$(STD_LIBS)) -Wl,--end-group -Wl,-Map=$(MAP_FILE) -o $(ELF_FILE)

View File

@ -0,0 +1,73 @@
SRC_REPLACE_COMPONENT_NAME=REPLACE_SOURCES
C_OBJ_REPLACE_COMPONENT_NAME = $(subst $(SDK_ROOT),$(OUTPUT_DIR),$(patsubst %,%.obj,$(filter %.c,$(SRC_REPLACE_COMPONENT_NAME))))
CPP_OBJ_REPLACE_COMPONENT_NAME = $(subst $(SDK_ROOT),$(OUTPUT_DIR),$(patsubst %,%.obj,$(filter %.cpp,$(SRC_REPLACE_COMPONENT_NAME))))
CPP_OBJ_REPLACE_COMPONENT_NAME += $(subst $(SDK_ROOT),$(OUTPUT_DIR),$(patsubst %,%.obj,$(filter %.cc,$(SRC_REPLACE_COMPONENT_NAME))))
S_OBJ_REPLACE_COMPONENT_NAME = $(subst $(SDK_ROOT),$(OUTPUT_DIR),$(patsubst %,%.obj,$(filter %.S,$(SRC_REPLACE_COMPONENT_NAME))))
s_OBJ_REPLACE_COMPONENT_NAME = $(subst $(SDK_ROOT),$(OUTPUT_DIR),$(patsubst %,%.obj,$(filter %.s,$(SRC_REPLACE_COMPONENT_NAME))))
ALL_OBJ_REPLACE_COMPONENT_NAME = $(subst $(SDK_ROOT),$(OUTPUT_DIR),$(patsubst %,%.obj,$(SRC_REPLACE_COMPONENT_NAME)))
INCLUDES_TEMP_REPLACE_COMPONENT_NAME = REPLACE_COMPONENT_CUSTOM_INCLUDE
INCLUDES_REPLACE_COMPONENT_NAME = $(patsubst %,-I%,$(INCLUDES_TEMP_REPLACE_COMPONENT_NAME))
CCFLAGS_REPLACE_COMPONENT_NAME = $(LOS_PUB_CCFLAGS)
CCFLAGS_REPLACE_COMPONENT_NAME += REPLACE_COMPONENT_CUSTOM_CCFLAGS
DEFINES_TEMP_REPLACE_COMPONENT_NAME = REPLACE_COMPONENT_CUSTOM_DEFINES
DEFINES_REPLACE_COMPONENT_NAME += $(patsubst %,-D%,$(DEFINES_TEMP_REPLACE_COMPONENT_NAME))
LIBS_REPLACE_COMPONENT_NAME = REPLACE_LIBS
WHOLE_LINK_REPLACE_COMPONENT_NAME = REPLACE_WHOLE_LINK
ifeq ("$(WHOLE_LINK_REPLACE_COMPONENT_NAME)", "true")
WHOLE_LINK_LIBS += REPLACE_COMPONENT_NAME
WHOLE_EXTERN_LINK_LIBS += $(LIBS_REPLACE_COMPONENT_NAME)
else
NORMAL_LINK_LIBS += REPLACE_COMPONENT_NAME
NORMAL_EXTERN_LINK_LIBS += $(LIBS_REPLACE_COMPONENT_NAME)
endif
COMPONENT_NAME_REPLACE_COMPONENT_NAME=REPLACE_COMPONENT_NAME
LIB_DIR_TEMP_REPLACE_COMPONENT_NAME = REPLACE_LIB_DIR
LIB_DIR_REPLACE_COMPONENT_NAME = $(subst $(SDK_ROOT),$(OUTPUT_DIR),$(LIB_DIR_TEMP_REPLACE_COMPONENT_NAME))
LIB_DIR += $(LIB_DIR_REPLACE_COMPONENT_NAME)
LIB_EXIST := $(shell if [ -e "$(LIB_DIR_TEMP_REPLACE_COMPONENT_NAME)/lib$(COMPONENT_NAME_REPLACE_COMPONENT_NAME).a" ]; then echo "exist"; else echo "noexist"; fi )
lib$(COMPONENT_NAME_REPLACE_COMPONENT_NAME).a:$(ALL_OBJ_REPLACE_COMPONENT_NAME) HSO_DB_$(COMPONENT_NAME_REPLACE_COMPONENT_NAME)
@mkdir -p $(LIB_DIR_REPLACE_COMPONENT_NAME)
@$(RM) $(LIB_DIR_REPLACE_COMPONENT_NAME)/lib$(COMPONENT_NAME_REPLACE_COMPONENT_NAME).a
ifeq ("$(LIB_EXIST)", "noexist")
@echo building $(LIB_DIR_REPLACE_COMPONENT_NAME)/lib$(COMPONENT_NAME_REPLACE_COMPONENT_NAME).a
@$(AR) -rc $(LIB_DIR_REPLACE_COMPONENT_NAME)/lib$(COMPONENT_NAME_REPLACE_COMPONENT_NAME).a $(ALL_OBJ_REPLACE_COMPONENT_NAME)
else
@echo copy $(LIB_DIR_REPLACE_COMPONENT_NAME)/lib$(COMPONENT_NAME_REPLACE_COMPONENT_NAME).a
@cp $(LIB_DIR_TEMP_REPLACE_COMPONENT_NAME)/lib$(COMPONENT_NAME_REPLACE_COMPONENT_NAME).a $(LIB_DIR_REPLACE_COMPONENT_NAME)
endif
$(C_OBJ_REPLACE_COMPONENT_NAME): $(OUTPUT_DIR)/%.obj : $(SDK_ROOT)/%
@echo Building $<
@mkdir -p $(dir $@)
@${CCACHE} $(CC) -c $(INCLUDES_REPLACE_COMPONENT_NAME) $(DEFINES_REPLACE_COMPONENT_NAME) $(CCFLAGS_REPLACE_COMPONENT_NAME) $< -o $@;
$(CPP_OBJ_REPLACE_COMPONENT_NAME): $(OUTPUT_DIR)/%.obj : $(SDK_ROOT)/%
@echo Building $<
@mkdir -p $(dir $@)
@${CCACHE} $(CXX) -c $(INCLUDES_REPLACE_COMPONENT_NAME) $(DEFINES_REPLACE_COMPONENT_NAME) $(CCFLAGS_REPLACE_COMPONENT_NAME) $< -o $@;
$(s_OBJ_REPLACE_COMPONENT_NAME): $(OUTPUT_DIR)/%.obj : $(SDK_ROOT)/%
@echo Building $<
@mkdir -p $(dir $@)
@$(AS) -c $(INCLUDES_REPLACE_COMPONENT_NAME) $(DEFINES_REPLACE_COMPONENT_NAME) $(CCFLAGS_REPLACE_COMPONENT_NAME) $< -o $@;
$(S_OBJ_REPLACE_COMPONENT_NAME): $(OUTPUT_DIR)/%.obj : $(SDK_ROOT)/%
@echo Building $<
@mkdir -p $(dir $@)
@$(AS) -c $(INCLUDES_REPLACE_COMPONENT_NAME) $(DEFINES_REPLACE_COMPONENT_NAME) $(CCFLAGS_REPLACE_COMPONENT_NAME) $< -o $@;
HSO_DB_$(COMPONENT_NAME_REPLACE_COMPONENT_NAME):
@echo "skip building $(COMPONENT_NAME_REPLACE_COMPONENT_NAME) HSO DB"
include ./toolchains.make

View File

@ -0,0 +1,11 @@
CC := REPLACE_CC
AS := REPLACE_AS
CXX := REPLACE_CXX
AR := REPLACE_AR
NM := REPLACE_NM
LD := REPLACE_LD
STRIP := REPLACE_STRIP
OBJCOPY := REPLACE_OBJCOPY
OBJDUMP := REPLACE_OBJDUMP
READELF := REPLACE_READELF
RANLIB := REPLACE_RANLIB

View File

@ -0,0 +1,13 @@
CC=REPLACE_CC
AS=REPLACE_AS
CXX=REPLACE_CXX
AR=REPLACE_AR
NM=REPLACE_NM
LINK=REPLACE_LINK
STRIP=REPLACE_STRIP
OBJCOPY=REPLACE_OBJCOPY
OBJDUMP=REPLACE_OBJDUMP
READELF=REPLACE_READELF
RANLIB=REPLACE_RANLIB
REPLACE

View File

@ -0,0 +1,23 @@
#!/usr/bin/env python3
# coding=utf-8
# Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2022-2022. All rights reserved.
import os
import re
def genarate_reserve_config(reserve_config, file_path):
with open(file_path, 'r') as fp:
lines = fp.read()
reserve_lines = ""
for config in reserve_config:
r = re.search("['\"]%s['\"](\s*):[\d\D\r\n]*?\}(\s*)," % config, lines)
reserve_lines += " %s\n" % r.group()
# 替换([\w\W]*?\n)里匹配的内容为reserve_lines
lines = re.sub("(target|target_template) = \{\n([\w\W]*?\n)\}",
lambda x: x.group().replace(x.group(2), reserve_lines), lines)
lines = re.sub("target_copy = \{\n([\w\W]*?\n)\}",
lambda x: x.group().replace(x.group(1), "\n"), lines)
lines = re.sub("target_group = \{\n([\w\W]*?\n)\}",
lambda x: x.group().replace(x.group(1), "\n"), lines)
with open(file_path, 'w') as fp:
fp.write(lines)

View File

@ -0,0 +1,75 @@
#!/usr/bin/env python3
# coding=utf-8
# Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2022-2022. All rights reserved.
import os
from xml.etree import cElementTree as ElementTree
class XmlParser:
def __init__(self):
self.d2xml_level = 0
self.indent = ' '
def _dict_to_xml(self, data, root='object'):
if isinstance(data, dict):
xml_ret = ' ' * self.d2xml_level + f'<{root}>\n'
self.d2xml_level += 1
for key, value in data.items():
xml_ret += self._dict_to_xml(value, key)
self.d2xml_level -= 1
xml_ret += ' ' * self.d2xml_level + f'</{root}>\n'
return xml_ret
if isinstance(data, (list, tuple, set)):
xml_ret = ''
for item in data:
xml_ret += self._dict_to_xml(item, root)
return xml_ret
if data is None:
data = ''
xml_ret = ' ' * self.d2xml_level + f'<{root}>'
xml_ret += str(data)
xml_ret += f'</{root}>\n'
return xml_ret
def dict_to_xml(self, data, root='object'):
self.d2xml_level = 0
xml_str = '<?xml version="1.0" encoding="UTF-8"?>\n'
xml_str += self._dict_to_xml(data, root)
return xml_str
def et2dict(self, root):
xml_dict = {}
if root.items():
xml_dict.update(dict(root.items()))
for element in root:
if element:
key = element.tag
val = self.et2dict(element)
else:
key = element.tag
val = element.text
if key not in xml_dict:
xml_dict[key] = val
continue
if not isinstance(xml_dict[key], list):
xml_dict[key] = [xml_dict[key]]
temp = xml_dict[key]
temp.append(val)
xml_dict[key] = temp
return xml_dict
def xml2dict(self, xml_file):
tree = ElementTree.parse(xml_file)
root = tree.getroot()
return self.et2dict(root)
if __name__ == "__main__":
script_dir = os.path.split(os.path.realpath(__file__))[0]
file = os.path.join(script_dir, 'sdk_template', 'template.ewp')
test = XmlParser()
dict_ = test.xml2dict(file)
xml = test.dict_to_xml(dict_, root='project')
print(xml)