From 97e2194e44fa8bb6164226fe36a526fe684a65b9 Mon Sep 17 00:00:00 2001 From: chenpan0560 Date: Fri, 5 Nov 2021 17:37:02 +0800 Subject: [PATCH 1/2] Delete the Chinese comments in the code and add the corresponding interface code Signed-off-by: chenpan0560 --- .idea/.gitignore | 8 + .idea/drivers_framework.iml | 15 ++ .idea/inspectionProfiles/Project_Default.xml | 7 + .../inspectionProfiles/profiles_settings.xml | 6 + .idea/misc.xml | 4 + .idea/modules.xml | 8 + .idea/vcs.xml | 6 + .../command_line/hdf_add_handler.py | 197 +++++++++--------- .../command_line/hdf_defconfig_patch.py | 4 +- .../command_line/hdf_get_handler.py | 13 ++ .../command_line/hdf_linux_scann.py | 110 ++++++++++ .../command_line/hdf_liteos_scann.py | 120 +++++++++++ .../hdf_model_enable_operation.py | 193 +++++++++++++++++ .../command_line/hdf_set_handler.py | 22 +- .../command_line/hdf_vendor_kconfig_file.py | 2 +- tools/hdf_dev_eco_tool/hdf_tool_settings.py | 4 + tools/hdf_dev_eco_tool/hdf_utils.py | 2 +- .../resources/create_model.config | 2 +- .../hdf_dev_eco_tool/resources/settings.json | 5 - 19 files changed, 618 insertions(+), 110 deletions(-) create mode 100755 .idea/.gitignore create mode 100755 .idea/drivers_framework.iml create mode 100755 .idea/inspectionProfiles/Project_Default.xml create mode 100755 .idea/inspectionProfiles/profiles_settings.xml create mode 100755 .idea/misc.xml create mode 100755 .idea/modules.xml create mode 100755 .idea/vcs.xml create mode 100755 tools/hdf_dev_eco_tool/command_line/hdf_linux_scann.py create mode 100755 tools/hdf_dev_eco_tool/command_line/hdf_liteos_scann.py create mode 100755 tools/hdf_dev_eco_tool/command_line/hdf_model_enable_operation.py diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100755 index 000000000..1c2fda565 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/drivers_framework.iml b/.idea/drivers_framework.iml new file mode 100755 index 000000000..d888fca69 --- /dev/null +++ b/.idea/drivers_framework.iml @@ -0,0 +1,15 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml new file mode 100755 index 000000000..9c6941105 --- /dev/null +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,7 @@ + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml new file mode 100755 index 000000000..105ce2da2 --- /dev/null +++ b/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100755 index 000000000..b534b8974 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100755 index 000000000..4e7c49967 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100755 index 000000000..9661ac713 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/tools/hdf_dev_eco_tool/command_line/hdf_add_handler.py b/tools/hdf_dev_eco_tool/command_line/hdf_add_handler.py index 7aeb77e81..a65b90bf2 100755 --- a/tools/hdf_dev_eco_tool/command_line/hdf_add_handler.py +++ b/tools/hdf_dev_eco_tool/command_line/hdf_add_handler.py @@ -63,12 +63,12 @@ class HdfAddHandler(HdfCommandHandlerBase): self.parser.add_argument("--action_type", help=' '.join(self.handlers.keys()), required=True) - self.parser.add_argument("--root_dir", required=True) # 路径 - self.parser.add_argument("--vendor_name") # 厂商 - self.parser.add_argument("--module_name") # 模块名 - self.parser.add_argument("--driver_name") # 驱动名称 - self.parser.add_argument("--board_name") # 板子名称 - self.parser.add_argument("--kernel_name") # 内核名称 + self.parser.add_argument("--root_dir", required=True) + self.parser.add_argument("--vendor_name") + self.parser.add_argument("--module_name") + self.parser.add_argument("--driver_name") + self.parser.add_argument("--board_name") + self.parser.add_argument("--kernel_name") self.args = self.parser.parse_args(args) @staticmethod @@ -114,90 +114,95 @@ class HdfAddHandler(HdfCommandHandlerBase): args_tuple = self.get_args() root, vendor, module, driver, board, kernel = args_tuple - converter = hdf_utils.WordsConverter(self.args.module_name) - driver_name_converter = hdf_utils.WordsConverter(self.args.driver_name) - framework_hdf = hdf_utils.get_vendor_hdf_dir_framework(root) - if not os.path.exists(framework_hdf): - raise HdfToolException( - ' framework model path "%s" not exist' % - framework_hdf, CommandErrorCode.TARGET_NOT_EXIST) - # 在 framework 目录下创建对应的 module 的文件目录用于存放 .c 驱动文件 - framework_drv_root_dir = hdf_utils.get_drv_root_dir( - root, vendor, module) - if os.path.exists(framework_drv_root_dir): - raise HdfToolException('module "%s" already exist' % module, - CommandErrorCode.TARGET_ALREADY_EXIST) - os.makedirs(framework_drv_root_dir) - - # 创建 .c 模板驱动 - state, driver_file_path = self._add_driver_handler(*args_tuple) - if not state: - raise HdfToolException( - 'create drivers file fail "%s" ' % - driver_file_path.split("\\")[-1]) - adapter_hdf = hdf_utils.get_vendor_hdf_dir_adapter(root, kernel) - if not os.path.exists(adapter_hdf): - raise HdfToolException( - ' adapter model path "%s" not exist' % - adapter_hdf, CommandErrorCode.TARGET_NOT_EXIST) + board_list = HdfToolSettings().get_board_list() + if board in board_list: + converter = hdf_utils.WordsConverter(self.args.module_name) + driver_name_converter = hdf_utils.WordsConverter( + self.args.driver_name) + framework_hdf = hdf_utils.get_vendor_hdf_dir_framework(root) + if not os.path.exists(framework_hdf): + raise HdfToolException( + ' framework model path "%s" not exist' % + framework_hdf, CommandErrorCode.TARGET_NOT_EXIST) - # 创建 adapter 路径下的 module 文件夹 - adapter_model_path = os.path.join(adapter_hdf, 'model', module) - if not os.path.exists(adapter_model_path): - os.makedirs(adapter_model_path) + framework_drv_root_dir = hdf_utils.get_drv_root_dir( + root, vendor, module) + if os.path.exists(framework_drv_root_dir): + raise HdfToolException('module "%s" already exist' % module, + CommandErrorCode.TARGET_ALREADY_EXIST) + os.makedirs(framework_drv_root_dir) - data_model = { - "module_upper_case": converter.upper_case(), - "module_lower_case": converter.lower_case(), - "driver_file_name": ("%s_driver.c" % - driver_name_converter.lower_case()), - "driver_name": driver_name_converter.lower_case() - } - # 创建 adapter 下的 module中的三个文件 - if kernel == 'liteos': - file_path, model_level_config_file_path = \ - self._add_module_handler_liteos( - framework_hdf, adapter_model_path, - data_model, converter, *args_tuple) - elif kernel == "linux": - file_path, model_level_config_file_path = \ - self._add_module_handler_linux( - framework_hdf, adapter_model_path, - data_model, *args_tuple) + state, driver_file_path = self._add_driver_handler(*args_tuple) + if not state: + raise HdfToolException( + 'create drivers file fail "%s" ' % + driver_file_path.split("\\")[-1]) + adapter_hdf = hdf_utils.get_vendor_hdf_dir_adapter(root, kernel) + if not os.path.exists(adapter_hdf): + raise HdfToolException( + ' adapter model path "%s" not exist' % + adapter_hdf, CommandErrorCode.TARGET_NOT_EXIST) + + adapter_model_path = os.path.join(adapter_hdf, 'model', module) + if not os.path.exists(adapter_model_path): + os.makedirs(adapter_model_path) + + data_model = { + "module_upper_case": converter.upper_case(), + "module_lower_case": converter.lower_case(), + "driver_file_name": ("%s_driver.c" % + driver_name_converter.lower_case()), + "driver_name": driver_name_converter.lower_case() + } + + if kernel == 'liteos': + file_path, model_level_config_file_path = \ + self._add_module_handler_liteos( + framework_hdf, adapter_model_path, + data_model, converter, *args_tuple) + + elif kernel == "linux": + file_path, model_level_config_file_path = \ + self._add_module_handler_linux( + framework_hdf, adapter_model_path, + data_model, *args_tuple) + else: + file_path = {} + model_level_config_file_path = {} + config_item = { + 'module_name': module, + 'module_path': file_path, + 'driver_name': "%s_driver.c" % driver, + 'driver_file_path': driver_file_path, + 'enabled': True + } + config_file_out = { + 'module_name': module, + 'module_path': file_path, + 'driver_name': "%s_driver.c" % driver, + 'driver_file_path': driver_file_path, + 'module_level_config_path': model_level_config_file_path + } + config_file = hdf_utils.read_file( + os.path.join('resources', 'create_model.config')) + config_file_json = json.loads(config_file) + config_file_json[module] = config_file_out + if platform.system() == "Windows": + config_file_replace = json.dumps(config_file_json, indent=4).\ + replace(root.replace('\\', '\\\\') + '\\\\', "") + hdf_utils.write_file( + os.path.join('resources', 'create_model.config'), + config_file_replace.replace('\\\\', '/')) + if platform.system() == "Linux": + config_file_replace = json.dumps(config_file_json, indent=4).\ + replace(root + '/', "") + hdf_utils.write_file( + os.path.join('resources', 'create_model.config'), + config_file_replace) + return json.dumps(config_item) else: - file_path = {} - model_level_config_file_path = {} - config_item = { - 'module_name': module, - 'module_path': file_path, - 'driver_name': "%s_driver.c" % driver, - 'driver_file_path': driver_file_path, - 'enabled': True - } - config_file_out = { - 'module_name': module, - 'module_path': file_path, - 'driver_name': driver_file_path.split("\\")[-1], - 'driver_file_path': driver_file_path, - 'module_level_config_path': model_level_config_file_path - } - config_file = hdf_utils.read_file( - os.path.join('resources', 'create_model.config')) - config_file_json = json.loads(config_file) - config_file_json[module] = config_file_out - if platform.system() == "Windows": - config_file_replace = json.dumps(config_file_json, indent=4).\ - replace(root.replace('\\', '\\\\') + '\\\\', "") - hdf_utils.write_file( - os.path.join('resources', 'create_model.config'), - config_file_replace.replace('\\\\', '/')) - if platform.system() == "Linux": - config_file_replace = json.dumps(config_file_json, indent=4).\ - replace(root + '/', "") - hdf_utils.write_file( - os.path.join('resources', 'create_model.config'), - config_file_replace) - return json.dumps(config_item) + raise HdfToolException( + 'supported boards name : %s not exits ' % board) def _add_module_handler_liteos(self, framework_hdf, adapter_model_path, data_model, converter, *args_tuple): @@ -205,8 +210,9 @@ class HdfAddHandler(HdfCommandHandlerBase): liteos_file_path = {} liteos_level_config_file_path = {} liteos_file_name = ['BUILD.gn', 'Kconfig', 'Makefile'] - template_path = "/".join([framework_hdf] + ["tools", - "hdf_dev_eco_tool", "resources", "templates", "lite"]) + template_path = "/".join([framework_hdf] + + ["tools", "hdf_dev_eco_tool", + "resources", "templates", "lite"]) for file_name in liteos_file_name: for i in os.listdir(template_path): if i.find(file_name.split(".")[0]) > 0: @@ -214,29 +220,24 @@ class HdfAddHandler(HdfCommandHandlerBase): self._render(os.path.join(template_path, i), out_path, data_model) liteos_file_path[file_name] = out_path - # 修改 liteos 下的 Kconfig 文件 + vendor_k = HdfVendorKconfigFile(root, vendor, kernel, path="") vendor_k_path = vendor_k.add_module([module, 'Kconfig']) liteos_level_config_file_path[module+"_Kconfig"] = vendor_k_path - # 修改 liteos 下的 hdf_lite.mk 文件 vendor_mk = HdfVendorMkFile(root, vendor) vendor_mk_path = vendor_mk.add_module(module) liteos_level_config_file_path[module + "_hdf_lite"] = vendor_mk_path - # 修改 liteos 下的 Build.gn 文件 vendor_gn = HdfVendorBuildFile(root, vendor) vendor_gn_path = vendor_gn.add_module(module) liteos_level_config_file_path[module + "Build"] = vendor_gn_path - # 修改 vendor/hisilicon/hispark_taurus/hdf_config/ - # device_info 下的 device_info.hcs 文件 device_info = HdfDeviceInfoHcsFile( root, vendor, module, board, driver, path="") hcs_file_path = device_info.add_model_hcs_file_config() liteos_file_path["devices_info.hcs"] = hcs_file_path - # 修改 dot_configs 的配置文件 dot_file_list = hdf_utils.get_dot_configs_path(root, vendor, board) template_string = "LOSCFG_DRIVERS_HDF_${module_upper_case}=y\n" new_demo_config = Template(template_string).substitute( @@ -267,24 +268,20 @@ class HdfAddHandler(HdfCommandHandlerBase): self._render(os.path.join(template_path, i), out_path, data_model) linux_file_path[file_name] = out_path - # 修改 linux 下的 Kconfig 文件 + vendor_k = HdfVendorKconfigFile(root, vendor, kernel, path="") vendor_k_path = vendor_k.add_module([module, 'Kconfig']) linux_level_config_file_path[module + "_Kconfig"] = vendor_k_path - # 修改 linux 下的 Makefile 文件 vendor_mk = HdfVendorMakeFile(root, vendor, kernel, path='') vendor_mk_path = vendor_mk.add_module(data_model) linux_level_config_file_path[module + "_Makefile"] = vendor_mk_path - # 修改 vendor/hisilicon/hispark_taurus_linux/ - # hdf_config/device_info 下的 device_info.hcs 文件 device_info = HdfDeviceInfoHcsFile( root, vendor, module, board, driver, path="") hcs_file_path = device_info.add_model_hcs_file_config() linux_file_path["devices_info.hcs"] = hcs_file_path - # 修改 dot_configs 的配置文件 template_string = "CONFIG_DRIVERS_HDF_${module_upper_case}=y\n" new_demo_config = Template(template_string).substitute(data_model) defconfig_patch = HdfDefconfigAndPatch( diff --git a/tools/hdf_dev_eco_tool/command_line/hdf_defconfig_patch.py b/tools/hdf_dev_eco_tool/command_line/hdf_defconfig_patch.py index e0d1cdb0c..4e33656f0 100755 --- a/tools/hdf_dev_eco_tool/command_line/hdf_defconfig_patch.py +++ b/tools/hdf_dev_eco_tool/command_line/hdf_defconfig_patch.py @@ -66,7 +66,7 @@ class HdfDefconfigAndPatch(object): if not os.path.isdir(new_path): self.find_file(new_path, files) else: - self.add_module(new_path, files=[]) + self.add_module(new_path, files=files) return files def delete_module(self, path): @@ -98,6 +98,7 @@ class HdfDefconfigAndPatch(object): if line.find("CONFIG_DRIVERS_HDF_INPUT=y") >= 0: insert_index = index elif line.find(self.new_demo_config) >= 0: + files.remove(path) state = True if not state: if path.split(".")[-1] != "patch": @@ -108,3 +109,4 @@ class HdfDefconfigAndPatch(object): "+" + self.new_demo_config) with open(path, "w", encoding=codetype) as fwrite: fwrite.writelines(data) + return files diff --git a/tools/hdf_dev_eco_tool/command_line/hdf_get_handler.py b/tools/hdf_dev_eco_tool/command_line/hdf_get_handler.py index e12ca7798..9309be4b6 100755 --- a/tools/hdf_dev_eco_tool/command_line/hdf_get_handler.py +++ b/tools/hdf_dev_eco_tool/command_line/hdf_get_handler.py @@ -35,7 +35,9 @@ import os import json from .hdf_command_handler_base import HdfCommandHandlerBase +from .hdf_linux_scann import HdfLinuxScan from .hdf_lite_mk_file import HdfLiteMkFile +from .hdf_liteos_scann import HdfLiteScan from .hdf_vendor_kconfig_file import HdfVendorKconfigFile from .hdf_module_kconfig_file import HdfModuleKconfigFile from .hdf_driver_config_file import HdfDriverConfigFile @@ -64,6 +66,7 @@ class HdfGetHandler(HdfCommandHandlerBase): 'drv_config_file': self._get_drv_config_file_handler, 'hdf_tool_core_version': self._get_version_handler, 'model_list': self._get_model_dict, + 'model_scan': self._mode_scan, 'version': self.__get_version, } self.parser.add_argument("--action_type", @@ -213,3 +216,13 @@ class HdfGetHandler(HdfCommandHandlerBase): else: model_file_path[key] = path_dict return model_file_path + + def _mode_scan(self): + self.check_arg_raise_if_not_exist("root_dir") + self.check_arg_raise_if_not_exist("vendor_name") + self.check_arg_raise_if_not_exist("board_name") + root, vendor, _, _, board, _ = self.get_args() + if board.split("_")[-1] != "linux": + return HdfLiteScan(root=root, vendor=vendor, board=board).get_model_scan() + else: + return HdfLinuxScan(root=root, vendor=vendor, board=board).get_model_scan() \ No newline at end of file diff --git a/tools/hdf_dev_eco_tool/command_line/hdf_linux_scann.py b/tools/hdf_dev_eco_tool/command_line/hdf_linux_scann.py new file mode 100755 index 000000000..1033a214f --- /dev/null +++ b/tools/hdf_dev_eco_tool/command_line/hdf_linux_scann.py @@ -0,0 +1,110 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +# +# Copyright (c) 2021, Huawei Device Co., Ltd. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following +# disclaimer in the documentation and/or other materials provided +# with the distribution. +# * Neither the name of Willow Garage, Inc. nor the names of its +# contributors may be used to endorse or promote products derived +# from this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# 'AS IS' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +import json +import os +import re + +from .hdf_command_error_code import CommandErrorCode +from hdf_tool_exception import HdfToolException +import hdf_utils + + +class HdfLinuxScan(object): + def __init__(self, root, vendor, board): + self.root = root + self.vendor = vendor + self.board = board + self.kernel = "linux" + + self.Makefile_path = hdf_utils.get_vendor_makefile_path( + root, kernel="linux") + if not os.path.exists(self.Makefile_path): + raise HdfToolException('Makefile: %s not exist' % self.Makefile_path, + CommandErrorCode.TARGET_NOT_EXIST) + + self.framework_dir = hdf_utils.get_module_dir(self.root, vendor) + if not os.path.exists(self.framework_dir): + raise HdfToolException('file: %s not exist' % self.framework_dir, + CommandErrorCode.TARGET_NOT_EXIST) + + self.hcs_path = hdf_utils.get_hcs_file_path( + self.root, self.vendor, self.board) + if not os.path.exists(self.hcs_path): + raise HdfToolException('file: %s not exist' % self.hcs_path, + CommandErrorCode.TARGET_NOT_EXIST) + self.contents = hdf_utils.read_file_lines(self.Makefile_path) + self.re_temp2 = r'model/[a-z 0-9]+' + + def scan_makefile(self): + model_list = [] + for i in self.contents: + result = re.search(self.re_temp2, i) + if result: + model_name = result.group().split('/')[-1] + if model_name not in model_list: + model_list.append(model_name) + return list(set(model_list)) + + def _get_model_file_dict(self): + model_file_dict = {} + for model_name in self.scan_makefile(): + model_file_dict[model_name] = [] + path = os.path.join(self.framework_dir, model_name) + for root_path, dirs, files in os.walk(path): + for file in files: + model_file_dict[model_name].append( + os.path.join(root_path, file)) + return model_file_dict + + def get_model_scan(self): + model_dict = {} + linux_model_info = {} + model_list = self.scan_makefile() + for model_name in model_list: + adapter_model_path = os.path.join( + hdf_utils.get_vendor_hdf_dir_adapter( + self.root, self.kernel), 'model', model_name) + if os.path.exists(adapter_model_path): + model_dict[model_name] = {} + model_config_list = [] + for roots, dirs, files in os.walk(adapter_model_path): + for file in files: + model_config_list.append(os.path.join(roots, file)) + model_dict[model_name]["model_configs"] = model_config_list + model_dict[model_name]['model_drivers'] = \ + self._get_model_file_dict()[model_name] + + linux_model_info["model_dict"] = model_dict + linux_model_info["linux_hcs"] = self.hcs_path + + return json.dumps(linux_model_info, indent=4) \ No newline at end of file diff --git a/tools/hdf_dev_eco_tool/command_line/hdf_liteos_scann.py b/tools/hdf_dev_eco_tool/command_line/hdf_liteos_scann.py new file mode 100755 index 000000000..473a36f57 --- /dev/null +++ b/tools/hdf_dev_eco_tool/command_line/hdf_liteos_scann.py @@ -0,0 +1,120 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +# +# Copyright (c) 2021, Huawei Device Co., Ltd. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following +# disclaimer in the documentation and/or other materials provided +# with the distribution. +# * Neither the name of Willow Garage, Inc. nor the names of its +# contributors may be used to endorse or promote products derived +# from this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# 'AS IS' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +import json +import os +import re + +from .hdf_command_error_code import CommandErrorCode +from hdf_tool_exception import HdfToolException +import hdf_utils + + +class HdfLiteScan(object): + def __init__(self, root, vendor, board): + self.root = root + self.vendor = vendor + self.board = board + + self.build_path = hdf_utils.get_vendor_gn_path(self.root) + if not os.path.exists(self.build_path): + raise HdfToolException('file: %s not exist' % self.build_path, + CommandErrorCode.TARGET_NOT_EXIST) + + self.framework_dir = hdf_utils.get_module_dir(self.root, vendor) + if not os.path.exists(self.framework_dir): + raise HdfToolException('file: %s not exist' % self.framework_dir, + CommandErrorCode.TARGET_NOT_EXIST) + + self.hcs_path = hdf_utils.get_hcs_file_path(self.root, vendor, board) + if not os.path.exists(self.hcs_path): + raise HdfToolException('file: %s not exist' % self.hcs_path, + CommandErrorCode.TARGET_NOT_EXIST) + self.contents = hdf_utils.read_file_lines(self.build_path) + self.re_temp = r"^group" + self.re_temp2 = r'"model/[a-z 0-9]+' + + def scan_build(self): + start_index = 0 + end_index = 0 + state = 0 + for index, line in enumerate(self.contents): + if re.compile(self.re_temp).match(line): + start_index = index + state += 1 + elif line.strip() == "{" and start_index > 0: + state += 1 + elif line.strip() == "}" and start_index > 0: + state -= 1 + if state == 0: + end_index = index + 1 + + model_list = [] + for i in self.contents[start_index: end_index]: + model_name = re.compile(self.re_temp2).match(i.strip()) + if model_name: + model_list.append(model_name.group().split('/')[-1]) + return list(set(model_list)) + + def _get_model_file_dict(self): + model_file_dict = {} + for model_name in self.scan_build(): + model_file_dict[model_name] = [] + path = os.path.join(self.framework_dir, model_name) + for root_path, dirs, files in os.walk(path): + for file in files: + model_file_dict[model_name].append( + os.path.join(root_path, file)) + return model_file_dict + + def get_model_scan(self): + model_dict = {} + liteos_model_info = {} + model_list = self.scan_build() + for model_name in model_list: + adapter_model_path = os.path.join( + hdf_utils.get_vendor_hdf_dir_adapter(root=self.root), + 'model', model_name) + if os.path.exists(adapter_model_path): + model_dict[model_name] = {} + model_config_list = [] + for roots, dirs, files in os.walk(adapter_model_path): + for file in files: + model_config_list.append(os.path.join(roots, file)) + model_dict[model_name]["model_configs"] = model_config_list + model_dict[model_name]['model_drivers'] = \ + self._get_model_file_dict()[model_name] + + liteos_model_info["model_dict"] = model_dict + liteos_model_info["liteos_hcs"] = self.hcs_path + + return json.dumps(liteos_model_info, indent=4) \ No newline at end of file diff --git a/tools/hdf_dev_eco_tool/command_line/hdf_model_enable_operation.py b/tools/hdf_dev_eco_tool/command_line/hdf_model_enable_operation.py new file mode 100755 index 000000000..6e5d37e74 --- /dev/null +++ b/tools/hdf_dev_eco_tool/command_line/hdf_model_enable_operation.py @@ -0,0 +1,193 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +# +# Copyright (c) 2021, Huawei Device Co., Ltd. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following +# disclaimer in the documentation and/or other materials provided +# with the distribution. +# * Neither the name of Willow Garage, Inc. nor the names of its +# contributors may be used to endorse or promote products derived +# from this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# 'AS IS' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +import os +from string import Template +import hdf_utils + +from .hdf_linux_scann import HdfLinuxScan +from .hdf_liteos_scann import HdfLiteScan + + +class EnableOperation(object): + def __init__(self, root, vendor, board, model): + self.root = root + self.vendor = vendor + self.board = board + self.model = model + self.liteos_model_name = HdfLiteScan(self.root, self.vendor, self.board).scan_build() + self.linux_model_name = HdfLinuxScan(self.root, self.vendor, self.board).scan_makefile() + + def disable_model_liteos(self): + dot_file_list = hdf_utils.get_dot_configs_path(self.root, self.vendor, self.board) + old_template_string = "LOSCFG_DRIVERS_HDF_${module_upper_case}=y" + new_template_string = "LOSCFG_DRIVERS_HDF_${module_upper_case} is not set\n" + new_demo_config = Template(new_template_string).substitute( + {"module_upper_case": self.model.upper()}) + old_demo_config = Template(old_template_string).substitute( + {"module_upper_case": self.model.upper()}) + + if self.model not in self.liteos_model_name: + return False + for dot_file in dot_file_list: + file_lines = hdf_utils.read_file_lines(dot_file) + for index, line in enumerate(file_lines): + if old_demo_config == line.strip(): + file_lines[index] = new_demo_config + hdf_utils.write_file_lines(dot_file, file_lines) + return True + + def enable_model_liteos(self): + dot_file_list = hdf_utils.get_dot_configs_path(self.root, self.vendor, self.board) + new_template_string = "LOSCFG_DRIVERS_HDF_${module_upper_case}=y\n" + old_template_string = "LOSCFG_DRIVERS_HDF_${module_upper_case} is not set" + new_demo_config = Template(new_template_string).substitute( + {"module_upper_case": self.model.upper()}) + old_demo_config = Template(old_template_string).substitute( + {"module_upper_case": self.model.upper()}) + + if self.model not in self.liteos_model_name: + return False + for dot_file in dot_file_list: + file_lines = hdf_utils.read_file_lines(dot_file) + for index, line in enumerate(file_lines): + if old_demo_config == line.strip(): + file_lines[index] = new_demo_config + hdf_utils.write_file_lines(dot_file, file_lines) + return True + + def operation_enable(self): + if self.board.split("_")[-1] != "linux": + try: + if self.enable_model_liteos(): + return "success(liteos) enable %s" % self.model + else: + return "%s model_name is not liteos type" % self.model + except Exception: + raise "failure(liteos) enable %s" % self.model + + else: + try: + if self.enable_model_linux(): + return "success(linux) enable %s" % self.model + else: + return "%s model_name is not linux type" % self.model + except Exception: + raise "failure(linux) enable %s" % self.model + + def operation_disable(self): + if self.board.split("_")[-1] != "linux": + try: + if self.disable_model_liteos(): + return "success(liteos) disable %s" % self.model + else: + return "%s model_name is not liteos type" % self.model + except Exception: + raise "failure(liteos) disable %s" % self.model + else: + try: + if self.disable_model_linux(): + return "success(linux) enable %s" % self.model + else: + return "%s model_name is not linux type" % self.model + except Exception: + raise "failure(linux) disable %s" % self.model + + def get_config_config(self, kernel): + return os.path.join(self.root, "kernel", kernel, "config") + + def get_config_patch(self, kernel): + return os.path.join(self.root, "kernel", kernel, "patches") + + def _get_file_patch(self, patch, endswitch, split_sign): + file_path = [] + for roots, dirs, files in os.walk(patch): + if endswitch == "defconfig": + files_list = list(filter(lambda x: x.split(split_sign)[-1] == endswitch, files)) + else: + files_list = list(filter(lambda x: x == endswitch, files)) + for file in files_list: + file_path.append(os.path.join(roots, file)) + return file_path + + def _get_config_linux(self): + config_path = self.get_config_config(kernel="linux") + config_path_list = self._get_file_patch(patch=config_path, endswitch="defconfig", split_sign="_") + + patch_path = self.get_config_patch(kernel="linux") + patch_path_list = self._get_file_patch(patch=patch_path, endswitch="hi3516dv300.patch", split_sign=".") + config_path_list.extend(patch_path_list) + + return config_path_list + + def _replace_operation(self, new_string, old_string, file_path): + new_demo_config = Template(new_string).substitute( + {"module_upper_case": self.model.upper()}) + old_demo_config = Template(old_string).substitute( + {"module_upper_case": self.model.upper()}) + + file_lines = hdf_utils.read_file_lines(file_path) + for index, line in enumerate(file_lines): + if old_demo_config == line.strip(): + file_lines[index] = new_demo_config + hdf_utils.write_file_lines(file_path, file_lines) + return True + + def disable_model_linux(self): + if self.model not in self.linux_model_name: + return False + file_path_list = self._get_config_linux() + for file_path in file_path_list: + if file_path.split("_")[-1] == "defconfig": + old_template_string = "CONFIG_DRIVERS_HDF_${module_upper_case}=y" + new_template_string = "CONFIG_DRIVERS_HDF_${module_upper_case} is not set\n" + else: + old_template_string = "+CONFIG_DRIVERS_HDF_${module_upper_case}=y" + new_template_string = "+CONFIG_DRIVERS_HDF_${module_upper_case} is not set\n" + self._replace_operation(new_string=new_template_string, old_string=old_template_string, + file_path=file_path) + return True + + def enable_model_linux(self): + if self.model not in self.linux_model_name: + return False + file_path_list = self._get_config_linux() + for file_path in file_path_list: + if file_path.split("_")[-1] == "defconfig": + new_template_string = "CONFIG_DRIVERS_HDF_${module_upper_case}=y\n" + old_template_string = "CONFIG_DRIVERS_HDF_${module_upper_case} is not set" + else: + new_template_string = "+CONFIG_DRIVERS_HDF_${module_upper_case}=y\n" + old_template_string = "+CONFIG_DRIVERS_HDF_${module_upper_case} is not set" + self._replace_operation(new_string=new_template_string, old_string=old_template_string, + file_path=file_path) + return True diff --git a/tools/hdf_dev_eco_tool/command_line/hdf_set_handler.py b/tools/hdf_dev_eco_tool/command_line/hdf_set_handler.py index 5e296978c..a06ff1b46 100755 --- a/tools/hdf_dev_eco_tool/command_line/hdf_set_handler.py +++ b/tools/hdf_dev_eco_tool/command_line/hdf_set_handler.py @@ -38,6 +38,7 @@ import argparse from .hdf_command_handler_base import HdfCommandHandlerBase from .hdf_command_error_code import CommandErrorCode from .hdf_dot_config_file import HdfDotConfigFile +from .hdf_model_enable_operation import EnableOperation from .hdf_vendor_kconfig_file import HdfVendorKconfigFile from .hdf_vendor_mk_file import HdfVendorMkFile from .hdf_lite_mk_file import HdfLiteMkFile @@ -60,7 +61,9 @@ class HdfSetHandler(HdfCommandHandlerBase): 'current_vendor': self._set_current_vendor_handler, 'current_board': self._set_current_board_handler, 'vendor_new_name': self._set_vendor_new_name_handler, - 'drivers_state': self._set_drivers_state_handler + 'drivers_state': self._set_drivers_state_handler, + 'model_enable': self._enable_operation, + 'model_disable': self._disable_operation, } self.parser.add_argument("--action_type", help=' '.join(self.handlers.keys()), @@ -68,6 +71,7 @@ class HdfSetHandler(HdfCommandHandlerBase): self.parser.add_argument("--root_dir", required=True) self.parser.add_argument("--vendor_name") self.parser.add_argument("--board_name") + self.parser.add_argument("--module_name") self.parser.add_argument("--new_vendor_name") self.parser.add_argument("--all_drivers", nargs='*', action=ConfigItemsAction) @@ -142,3 +146,19 @@ class HdfSetHandler(HdfCommandHandlerBase): dot_config.save() for orig_dot_config_ in orig_dot_configs: orig_dot_config_.save() + + def _enable_operation(self): + self.check_arg_raise_if_not_exist("root_dir") + self.check_arg_raise_if_not_exist("vendor_name") + self.check_arg_raise_if_not_exist("board_name") + self.check_arg_raise_if_not_exist("module_name") + root, vendor, model, _, board, _ = self.get_args() + return EnableOperation(root=root, vendor=vendor, board=board, model=model).operation_enable() + + def _disable_operation(self): + self.check_arg_raise_if_not_exist("root_dir") + self.check_arg_raise_if_not_exist("vendor_name") + self.check_arg_raise_if_not_exist("board_name") + self.check_arg_raise_if_not_exist("module_name") + root, vendor, model, _, board, _ = self.get_args() + return EnableOperation(root=root, vendor=vendor, board=board, model=model).operation_disable() \ No newline at end of file diff --git a/tools/hdf_dev_eco_tool/command_line/hdf_vendor_kconfig_file.py b/tools/hdf_dev_eco_tool/command_line/hdf_vendor_kconfig_file.py index 2359dab2c..a7071413d 100755 --- a/tools/hdf_dev_eco_tool/command_line/hdf_vendor_kconfig_file.py +++ b/tools/hdf_dev_eco_tool/command_line/hdf_vendor_kconfig_file.py @@ -91,7 +91,7 @@ class HdfVendorKconfigFile(object): def add_module(self, module_to_k_path_parts): module_k_part = '/'.join(module_to_k_path_parts) - index, line = self._find_line(module_k_part) + index, line = self._find_line("model/"+module_k_part) if line: return line = '\n%s/%s"\n' % (self.line_prefix, module_k_part) diff --git a/tools/hdf_dev_eco_tool/hdf_tool_settings.py b/tools/hdf_dev_eco_tool/hdf_tool_settings.py index d1f72412a..fff1c21a4 100755 --- a/tools/hdf_dev_eco_tool/hdf_tool_settings.py +++ b/tools/hdf_dev_eco_tool/hdf_tool_settings.py @@ -122,3 +122,7 @@ class HdfToolSettings(object): if board_name in self.settings[key]: return self.settings[key][board_name]["patch_and_config"] return '' + + def get_board_list(self): + key = self.supported_boards_key + return list(self.settings[key].keys()) diff --git a/tools/hdf_dev_eco_tool/hdf_utils.py b/tools/hdf_dev_eco_tool/hdf_utils.py index b7efd6473..58c098e4b 100755 --- a/tools/hdf_dev_eco_tool/hdf_utils.py +++ b/tools/hdf_dev_eco_tool/hdf_utils.py @@ -240,7 +240,7 @@ def get_dot_configs_path(root, vendor, board): return [os.path.join(path, i) for i in os.listdir(path)] -def get_module_dir(root, vendor, module): +def get_module_dir(root, vendor, module=""): return os.path.join(get_vendor_hdf_dir_framework(root), 'model', module) diff --git a/tools/hdf_dev_eco_tool/resources/create_model.config b/tools/hdf_dev_eco_tool/resources/create_model.config index 9e26dfeeb..0967ef424 100755 --- a/tools/hdf_dev_eco_tool/resources/create_model.config +++ b/tools/hdf_dev_eco_tool/resources/create_model.config @@ -1 +1 @@ -{} \ No newline at end of file +{} diff --git a/tools/hdf_dev_eco_tool/resources/settings.json b/tools/hdf_dev_eco_tool/resources/settings.json index ecbf0e137..c38733ee5 100755 --- a/tools/hdf_dev_eco_tool/resources/settings.json +++ b/tools/hdf_dev_eco_tool/resources/settings.json @@ -10,11 +10,6 @@ "hispark_taurus_linux": { "patch_and_config": ["hi3516dv300.patch", "hi3516dv300_small_defconfig", "hi3516dv300_standard_defconfig", "small_common_defconfig", "standard_common_defconfig"] - }, - "hispark_aries": { - "board_parent_path": "vendor/hisilicon/hispark_aries", - "dot_config_path": "kernel/liteos_a/tools/build/config", - "dot_configs": ["hispark_aries_clang_release.config", "hispark_aries_release.config", "hispark_aries_debug_shell.config"] } }, "drivers_path_relative_to_vendor": "drivers/framework", -- Gitee From b018d20a997b2f19d583df503c2c477de30b558f Mon Sep 17 00:00:00 2001 From: chenpan0560 Date: Thu, 11 Nov 2021 10:00:08 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=B3=A8=E9=87=8A?= =?UTF-8?q?=E9=97=AE=E9=A2=98=EF=BC=8C=E6=8F=90=E4=BA=A4=E6=89=AB=E6=8F=8F?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E5=92=8C=E4=BD=BF=E8=83=BD=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: chenpan0560 --- .idea/.gitignore | 8 ------- .idea/drivers_framework.iml | 15 ------------- .idea/inspectionProfiles/Project_Default.xml | 7 ------ .../inspectionProfiles/profiles_settings.xml | 6 ----- .idea/misc.xml | 4 ---- .idea/modules.xml | 8 ------- .idea/vcs.xml | 6 ----- .../command_line/hdf_add_handler.py | 13 ++++++++++- .../resources/create_model.config | 2 +- .../templates/lite/device_info_hcs.template | 22 +++++++++---------- .../templates/lite/hdf_driver.c.template | 22 +++++++++---------- 11 files changed, 34 insertions(+), 79 deletions(-) delete mode 100755 .idea/.gitignore delete mode 100755 .idea/drivers_framework.iml delete mode 100755 .idea/inspectionProfiles/Project_Default.xml delete mode 100755 .idea/inspectionProfiles/profiles_settings.xml delete mode 100755 .idea/misc.xml delete mode 100755 .idea/modules.xml delete mode 100755 .idea/vcs.xml diff --git a/.idea/.gitignore b/.idea/.gitignore deleted file mode 100755 index 1c2fda565..000000000 --- a/.idea/.gitignore +++ /dev/null @@ -1,8 +0,0 @@ -# Default ignored files -/shelf/ -/workspace.xml -# Editor-based HTTP Client requests -/httpRequests/ -# Datasource local storage ignored files -/dataSources/ -/dataSources.local.xml diff --git a/.idea/drivers_framework.iml b/.idea/drivers_framework.iml deleted file mode 100755 index d888fca69..000000000 --- a/.idea/drivers_framework.iml +++ /dev/null @@ -1,15 +0,0 @@ - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml deleted file mode 100755 index 9c6941105..000000000 --- a/.idea/inspectionProfiles/Project_Default.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - \ No newline at end of file diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml deleted file mode 100755 index 105ce2da2..000000000 --- a/.idea/inspectionProfiles/profiles_settings.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml deleted file mode 100755 index b534b8974..000000000 --- a/.idea/misc.xml +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml deleted file mode 100755 index 4e7c49967..000000000 --- a/.idea/modules.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml deleted file mode 100755 index 9661ac713..000000000 --- a/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/tools/hdf_dev_eco_tool/command_line/hdf_add_handler.py b/tools/hdf_dev_eco_tool/command_line/hdf_add_handler.py index a65b90bf2..b4ac9059a 100755 --- a/tools/hdf_dev_eco_tool/command_line/hdf_add_handler.py +++ b/tools/hdf_dev_eco_tool/command_line/hdf_add_handler.py @@ -124,7 +124,7 @@ class HdfAddHandler(HdfCommandHandlerBase): raise HdfToolException( ' framework model path "%s" not exist' % framework_hdf, CommandErrorCode.TARGET_NOT_EXIST) - + # framework create file .c framework_drv_root_dir = hdf_utils.get_drv_root_dir( root, vendor, module) if os.path.exists(framework_drv_root_dir): @@ -132,6 +132,7 @@ class HdfAddHandler(HdfCommandHandlerBase): CommandErrorCode.TARGET_ALREADY_EXIST) os.makedirs(framework_drv_root_dir) + # create .c template driver file state, driver_file_path = self._add_driver_handler(*args_tuple) if not state: raise HdfToolException( @@ -143,6 +144,7 @@ class HdfAddHandler(HdfCommandHandlerBase): ' adapter model path "%s" not exist' % adapter_hdf, CommandErrorCode.TARGET_NOT_EXIST) + # create module folder under the adapter path adapter_model_path = os.path.join(adapter_hdf, 'model', module) if not os.path.exists(adapter_model_path): os.makedirs(adapter_model_path) @@ -155,6 +157,7 @@ class HdfAddHandler(HdfCommandHandlerBase): "driver_name": driver_name_converter.lower_case() } + # create files in the module under the adapter if kernel == 'liteos': file_path, model_level_config_file_path = \ self._add_module_handler_liteos( @@ -221,18 +224,22 @@ class HdfAddHandler(HdfCommandHandlerBase): out_path, data_model) liteos_file_path[file_name] = out_path + # Modify Kconfig file vendor_k = HdfVendorKconfigFile(root, vendor, kernel, path="") vendor_k_path = vendor_k.add_module([module, 'Kconfig']) liteos_level_config_file_path[module+"_Kconfig"] = vendor_k_path + # Modify hdf_lite.mk file vendor_mk = HdfVendorMkFile(root, vendor) vendor_mk_path = vendor_mk.add_module(module) liteos_level_config_file_path[module + "_hdf_lite"] = vendor_mk_path + # Modify Build.gn file vendor_gn = HdfVendorBuildFile(root, vendor) vendor_gn_path = vendor_gn.add_module(module) liteos_level_config_file_path[module + "Build"] = vendor_gn_path + # Modify config file device_info = HdfDeviceInfoHcsFile( root, vendor, module, board, driver, path="") hcs_file_path = device_info.add_model_hcs_file_config() @@ -269,19 +276,23 @@ class HdfAddHandler(HdfCommandHandlerBase): out_path, data_model) linux_file_path[file_name] = out_path + # Modify Kconfig file vendor_k = HdfVendorKconfigFile(root, vendor, kernel, path="") vendor_k_path = vendor_k.add_module([module, 'Kconfig']) linux_level_config_file_path[module + "_Kconfig"] = vendor_k_path + # Modify Makefile file vendor_mk = HdfVendorMakeFile(root, vendor, kernel, path='') vendor_mk_path = vendor_mk.add_module(data_model) linux_level_config_file_path[module + "_Makefile"] = vendor_mk_path + # device_info.hcs device_info = HdfDeviceInfoHcsFile( root, vendor, module, board, driver, path="") hcs_file_path = device_info.add_model_hcs_file_config() linux_file_path["devices_info.hcs"] = hcs_file_path + # dot_configs config file template_string = "CONFIG_DRIVERS_HDF_${module_upper_case}=y\n" new_demo_config = Template(template_string).substitute(data_model) defconfig_patch = HdfDefconfigAndPatch( diff --git a/tools/hdf_dev_eco_tool/resources/create_model.config b/tools/hdf_dev_eco_tool/resources/create_model.config index 0967ef424..9e26dfeeb 100755 --- a/tools/hdf_dev_eco_tool/resources/create_model.config +++ b/tools/hdf_dev_eco_tool/resources/create_model.config @@ -1 +1 @@ -{} +{} \ No newline at end of file diff --git a/tools/hdf_dev_eco_tool/resources/templates/lite/device_info_hcs.template b/tools/hdf_dev_eco_tool/resources/templates/lite/device_info_hcs.template index edf95d033..edcb42bc5 100755 --- a/tools/hdf_dev_eco_tool/resources/templates/lite/device_info_hcs.template +++ b/tools/hdf_dev_eco_tool/resources/templates/lite/device_info_hcs.template @@ -1,15 +1,15 @@ ${model_name} :: host{ - hostName = "${model_name}_host"; - priority = 100; - device_${model_name} :: device { - device0 :: deviceNode { - policy = 2; - priority= 100; - preload = 0; - permission = 0664; - moduleName = "${driver_name}_driver"; - serviceName = "${driver_name}_service"; - deviceMatchAttr = ""; + hostName = "${model_name}_host"; // Host name. The host node is used to store a certain type of drivers. + priority = 100; //Host startup priority (0-200). A larger value indicates a lower priority. The default value 100 is recommended. If the priorities are the same, the host loading sequence is random. + device_${model_name} :: device { // Device node of sample + device0 :: deviceNode { // DeviceNode of the sample driver + policy = 2; // Driver service release policy. For details, see section Driver Service Management. + priority= 100; // Driver startup priority (0-200). A larger value indicates a lower priority. The default value 100 is recommended. If the priorities are the same, the device loading sequence is random. + preload = 0; // On-demand loading of the driver. For details, see "NOTE" at the end of this section. + permission = 0664; // Permission for the driver to create device nodes. + moduleName = "${driver_name}_driver"; // Driver name. The value of this field must be the same as the value of moduleName in the driver entry structure. + serviceName = "${driver_name}_service"; // Name of the service released by the driver. The name must be unique. + deviceMatchAttr = ""; // Keyword matching the private data of the driver. The value must be the same as that of match_attr in the private data configuration table of the driver. } } } diff --git a/tools/hdf_dev_eco_tool/resources/templates/lite/hdf_driver.c.template b/tools/hdf_dev_eco_tool/resources/templates/lite/hdf_driver.c.template index 9d890166d..3ec5439c8 100755 --- a/tools/hdf_dev_eco_tool/resources/templates/lite/hdf_driver.c.template +++ b/tools/hdf_dev_eco_tool/resources/templates/lite/hdf_driver.c.template @@ -1,34 +1,32 @@ -#include "hdf_device_desc.h" // HDF框架对驱动开放相关能力接口的头文件 -#include "hdf_log.h" // HDF 框架提供的日志接口头文件 +#include "hdf_device_desc.h" // Header file that describes the APIs provided by the HDF to the driver. +#include "hdf_log.h" // Header file that describes the log APIs provided by the HDF. -#define HDF_LOG_TAG ${driver_lower_case}_driver // 打印日志所包含的标签,如果不定义则用默认定义的HDF_TAG标签 +#define HDF_LOG_TAG ${driver_lower_case}_driver // Tag contained in logs. If no tag is not specified, the default HDF_TAG is used. -//驱动服务结构的定义 +// The driver service struct definition struct ITestDriverService { - struct IDeviceIoService ioService; // 服务结构的首个成员必须是IDeviceIoService类型的成员 - //以下可添加自定义的驱动的服务接口 + struct IDeviceIoService ioService; // The first member of the service structure must be a member of type IDeviceIoService }; -//驱动对外提供的服务能力,将相关的服务接口绑定到HDF框架 +// The driver service interface must be bound to the HDF for you to use the service capability. static int32_t Hdf${driver_upper_camel_case}DriverBind(struct HdfDeviceObject *deviceObject) { - // deviceObject为HDF框架给每一个驱动创建的设备对象,用来保存设备相关的私有数据和服务接口 HDF_LOGI("${driver_lower_case} driver bind success"); return 0; } -// 驱动自身业务初始的接口 +// Initialize the driver service. static int32_t Hdf${driver_upper_camel_case}DriverInit(struct HdfDeviceObject *deviceObject) { HDF_LOGI("Hello world"); return 0; } -// 驱动资源释放的接口 +// Release the driver resources. static void Hdf${driver_upper_camel_case}DriverRelease(struct HdfDeviceObject *deviceObject) { HDF_LOGI("${driver_lower_case} driver Release success"); return; } -// 定义驱动入口的对象,必须为HdfDriverEntry(在hdf_device_desc.h中定义)类型的全局变量 +// Define the object of the driver entry. The object must be a global variable of the HdfDriverEntry type (defined in hdf_device_desc.h). struct HdfDriverEntry g_${driver_lower_case}DriverEntry = { .moduleVersion = 1, .moduleName = "${driver_lower_case}_driver", @@ -37,5 +35,5 @@ struct HdfDriverEntry g_${driver_lower_case}DriverEntry = { .Release = Hdf${driver_upper_camel_case}DriverRelease, }; -// 调用HDF_INIT将驱动入口注册到HDF框架中,在加载驱动时HDF框架会先调用Bind函数,再调用Init函数加载该驱动,当Init调用异常时,HDF框架会调用Release释放驱动资源并退出。 +// Call HDF_INIT to register the driver entry with the HDF framework. When loading the driver, call the Bind function and then the Init function. If the Init function fails to be called, the HDF will call Release to release the driver resource and exit. HDF_INIT(g_${driver_lower_case}DriverEntry); -- Gitee