openubmc-bingo 0.5.240__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of openubmc-bingo might be problematic. Click here for more details.

Files changed (242) hide show
  1. bmcgo/__init__.py +12 -0
  2. bmcgo/bmcgo.py +22 -0
  3. bmcgo/bmcgo_config.py +176 -0
  4. bmcgo/cli/__init__.py +10 -0
  5. bmcgo/cli/cli.py +584 -0
  6. bmcgo/codegen/__init__.py +14 -0
  7. bmcgo/codegen/c/__init__.py +9 -0
  8. bmcgo/codegen/c/annotation.py +52 -0
  9. bmcgo/codegen/c/argument.py +42 -0
  10. bmcgo/codegen/c/codegen.py +153 -0
  11. bmcgo/codegen/c/comment.py +22 -0
  12. bmcgo/codegen/c/ctype_defination.py +353 -0
  13. bmcgo/codegen/c/helper.py +87 -0
  14. bmcgo/codegen/c/interface.py +63 -0
  15. bmcgo/codegen/c/method.py +82 -0
  16. bmcgo/codegen/c/property.py +180 -0
  17. bmcgo/codegen/c/renderer.py +21 -0
  18. bmcgo/codegen/c/signal.py +64 -0
  19. bmcgo/codegen/c/template/client.c.mako +145 -0
  20. bmcgo/codegen/c/template/client.h.mako +36 -0
  21. bmcgo/codegen/c/template/interface.c.mako +0 -0
  22. bmcgo/codegen/c/template/interface.introspect.xml.mako +99 -0
  23. bmcgo/codegen/c/template/micro_component.c.mako +32 -0
  24. bmcgo/codegen/c/template/public.c.mako +228 -0
  25. bmcgo/codegen/c/template/public.h.mako +128 -0
  26. bmcgo/codegen/c/template/server.c.mako +104 -0
  27. bmcgo/codegen/c/template/server.h.mako +36 -0
  28. bmcgo/codegen/lua/.lua-format +7 -0
  29. bmcgo/codegen/lua/Makefile +101 -0
  30. bmcgo/codegen/lua/__init__.py +9 -0
  31. bmcgo/codegen/lua/codegen.py +171 -0
  32. bmcgo/codegen/lua/proto/Makefile +87 -0
  33. bmcgo/codegen/lua/proto/ipmi_types.proto +17 -0
  34. bmcgo/codegen/lua/proto/types.proto +52 -0
  35. bmcgo/codegen/lua/script/check_intfs.py +161 -0
  36. bmcgo/codegen/lua/script/dto/__init__.py +11 -0
  37. bmcgo/codegen/lua/script/dto/exception.py +53 -0
  38. bmcgo/codegen/lua/script/dto/kepler_abstract.py +47 -0
  39. bmcgo/codegen/lua/script/dto/options.py +33 -0
  40. bmcgo/codegen/lua/script/dto/print_simple.py +19 -0
  41. bmcgo/codegen/lua/script/dto/redfish_api.py +241 -0
  42. bmcgo/codegen/lua/script/dto/url_route.py +195 -0
  43. bmcgo/codegen/lua/script/gen_db_json.py +444 -0
  44. bmcgo/codegen/lua/script/gen_depends.py +89 -0
  45. bmcgo/codegen/lua/script/gen_entry.py +263 -0
  46. bmcgo/codegen/lua/script/gen_feature_json.py +156 -0
  47. bmcgo/codegen/lua/script/gen_historical_local_db_json.py +88 -0
  48. bmcgo/codegen/lua/script/gen_intf_json.py +261 -0
  49. bmcgo/codegen/lua/script/gen_intf_rpc_json.py +575 -0
  50. bmcgo/codegen/lua/script/gen_ipmi_json.py +485 -0
  51. bmcgo/codegen/lua/script/gen_mdb_json.py +117 -0
  52. bmcgo/codegen/lua/script/gen_rpc_msg_json.py +487 -0
  53. bmcgo/codegen/lua/script/gen_schema.py +302 -0
  54. bmcgo/codegen/lua/script/ipmi_types_pb2.py +135 -0
  55. bmcgo/codegen/lua/script/loader/__init__.py +11 -0
  56. bmcgo/codegen/lua/script/loader/file_utils.py +33 -0
  57. bmcgo/codegen/lua/script/loader/kepler_abstract_collect.py +79 -0
  58. bmcgo/codegen/lua/script/loader/kepler_abstract_loader.py +47 -0
  59. bmcgo/codegen/lua/script/loader/redfish_loader.py +127 -0
  60. bmcgo/codegen/lua/script/lua_format.py +62 -0
  61. bmcgo/codegen/lua/script/mds_util.py +385 -0
  62. bmcgo/codegen/lua/script/merge_model.py +330 -0
  63. bmcgo/codegen/lua/script/merge_proto_algo.py +85 -0
  64. bmcgo/codegen/lua/script/proto_loader.py +47 -0
  65. bmcgo/codegen/lua/script/proto_plugin.py +140 -0
  66. bmcgo/codegen/lua/script/redfish_source_tree.py +118 -0
  67. bmcgo/codegen/lua/script/render_utils/__init__.py +38 -0
  68. bmcgo/codegen/lua/script/render_utils/base.py +25 -0
  69. bmcgo/codegen/lua/script/render_utils/client_lua.py +98 -0
  70. bmcgo/codegen/lua/script/render_utils/controller_lua.py +71 -0
  71. bmcgo/codegen/lua/script/render_utils/db_lua.py +224 -0
  72. bmcgo/codegen/lua/script/render_utils/error_lua.py +185 -0
  73. bmcgo/codegen/lua/script/render_utils/factory.py +52 -0
  74. bmcgo/codegen/lua/script/render_utils/ipmi_lua.py +159 -0
  75. bmcgo/codegen/lua/script/render_utils/ipmi_message_lua.py +24 -0
  76. bmcgo/codegen/lua/script/render_utils/mdb_lua.py +177 -0
  77. bmcgo/codegen/lua/script/render_utils/mdb_register.py +215 -0
  78. bmcgo/codegen/lua/script/render_utils/message_lua.py +26 -0
  79. bmcgo/codegen/lua/script/render_utils/messages_lua.py +156 -0
  80. bmcgo/codegen/lua/script/render_utils/model_lua.py +485 -0
  81. bmcgo/codegen/lua/script/render_utils/old_model_lua.py +429 -0
  82. bmcgo/codegen/lua/script/render_utils/plugin_lua.py +38 -0
  83. bmcgo/codegen/lua/script/render_utils/redfish_proto.py +86 -0
  84. bmcgo/codegen/lua/script/render_utils/request_lua.py +76 -0
  85. bmcgo/codegen/lua/script/render_utils/service_lua.py +130 -0
  86. bmcgo/codegen/lua/script/render_utils/utils_message_lua.py +125 -0
  87. bmcgo/codegen/lua/script/render_utils/validate_lua.py +221 -0
  88. bmcgo/codegen/lua/script/sep_ipmi_message_cmds.py +217 -0
  89. bmcgo/codegen/lua/script/template.py +166 -0
  90. bmcgo/codegen/lua/script/types_pb2.py +516 -0
  91. bmcgo/codegen/lua/script/utils.py +663 -0
  92. bmcgo/codegen/lua/script/validate.py +80 -0
  93. bmcgo/codegen/lua/script/yaml_to_json.py +73 -0
  94. bmcgo/codegen/lua/templates/Makefile +114 -0
  95. bmcgo/codegen/lua/templates/apps/Makefile +261 -0
  96. bmcgo/codegen/lua/templates/apps/Makefile.mdb.mk +64 -0
  97. bmcgo/codegen/lua/templates/apps/app.lua.mako +19 -0
  98. bmcgo/codegen/lua/templates/apps/class.lua.mako +35 -0
  99. bmcgo/codegen/lua/templates/apps/client.lua.mako +429 -0
  100. bmcgo/codegen/lua/templates/apps/controller.lua.mako +276 -0
  101. bmcgo/codegen/lua/templates/apps/datas.lua.mako +8 -0
  102. bmcgo/codegen/lua/templates/apps/db.lua.mako +89 -0
  103. bmcgo/codegen/lua/templates/apps/entry.lua.mako +128 -0
  104. bmcgo/codegen/lua/templates/apps/feature.lua.mako +37 -0
  105. bmcgo/codegen/lua/templates/apps/generate_route.mako +25 -0
  106. bmcgo/codegen/lua/templates/apps/impl_feature.lua.mako +72 -0
  107. bmcgo/codegen/lua/templates/apps/ipmi.lua.mako +97 -0
  108. bmcgo/codegen/lua/templates/apps/ipmi_cmd.lua.mako +18 -0
  109. bmcgo/codegen/lua/templates/apps/ipmi_message.lua.mako +36 -0
  110. bmcgo/codegen/lua/templates/apps/local_db.lua.mako +263 -0
  111. bmcgo/codegen/lua/templates/apps/main.lua.mako +25 -0
  112. bmcgo/codegen/lua/templates/apps/mc.lua.mako +77 -0
  113. bmcgo/codegen/lua/templates/apps/mdb.lua.mako +45 -0
  114. bmcgo/codegen/lua/templates/apps/mdb_interface.lua.mako +73 -0
  115. bmcgo/codegen/lua/templates/apps/message.lua.mako +38 -0
  116. bmcgo/codegen/lua/templates/apps/model.lua.mako +239 -0
  117. bmcgo/codegen/lua/templates/apps/orm_classes.lua.mako +16 -0
  118. bmcgo/codegen/lua/templates/apps/plugin.lua.mako +8 -0
  119. bmcgo/codegen/lua/templates/apps/redfish.proto.mako +47 -0
  120. bmcgo/codegen/lua/templates/apps/service.lua.mako +440 -0
  121. bmcgo/codegen/lua/templates/apps/signal_listen.lua.mako +19 -0
  122. bmcgo/codegen/lua/templates/apps/utils/default_intf.lua.mako +41 -0
  123. bmcgo/codegen/lua/templates/apps/utils/enum.mako +10 -0
  124. bmcgo/codegen/lua/templates/apps/utils/imports.mako +13 -0
  125. bmcgo/codegen/lua/templates/apps/utils/mdb_intf.lua.mako +25 -0
  126. bmcgo/codegen/lua/templates/apps/utils/mdb_obj.lua.mako +23 -0
  127. bmcgo/codegen/lua/templates/apps/utils/message.mako +160 -0
  128. bmcgo/codegen/lua/templates/apps/utils/request.lua.mako +59 -0
  129. bmcgo/codegen/lua/templates/apps/utils/validate.mako +83 -0
  130. bmcgo/codegen/lua/templates/errors.lua.mako +36 -0
  131. bmcgo/codegen/lua/templates/messages.lua.mako +32 -0
  132. bmcgo/codegen/lua/templates/new_app/.clang-format.mako +170 -0
  133. bmcgo/codegen/lua/templates/new_app/.gitignore.mako +26 -0
  134. bmcgo/codegen/lua/templates/new_app/CHANGELOG.md.mako +0 -0
  135. bmcgo/codegen/lua/templates/new_app/CMakeLists.txt.mako +29 -0
  136. bmcgo/codegen/lua/templates/new_app/Makefile.mako +25 -0
  137. bmcgo/codegen/lua/templates/new_app/README.md.mako +0 -0
  138. bmcgo/codegen/lua/templates/new_app/conanfile.py.mako +7 -0
  139. bmcgo/codegen/lua/templates/new_app/config.cfg.mako +6 -0
  140. bmcgo/codegen/lua/templates/new_app/mds/model.json.mako +3 -0
  141. bmcgo/codegen/lua/templates/new_app/mds/service.json.mako +21 -0
  142. bmcgo/codegen/lua/templates/new_app/permissions.ini.mako +16 -0
  143. bmcgo/codegen/lua/templates/new_app/src/lualib/${project_name}_app.lua.mako +16 -0
  144. bmcgo/codegen/lua/templates/new_app/src/service/main.lua.mako +25 -0
  145. bmcgo/codegen/lua/templates/new_app/test/integration/test_${project_name}.conf.mako +9 -0
  146. bmcgo/codegen/lua/templates/new_app/test/integration/test_${project_name}.lua.mako +47 -0
  147. bmcgo/codegen/lua/templates/new_app/test/unit/test.lua.mako +23 -0
  148. bmcgo/codegen/lua/templates/new_app/user_conf/rootfs/etc/systemd/system/${project_name}.service.mako +18 -0
  149. bmcgo/codegen/lua/templates/new_app/user_conf/rootfs/etc/systemd/system/multi-user.target.wants/${project_name}.service.link +1 -0
  150. bmcgo/component/__init__.py +10 -0
  151. bmcgo/component/analysis/analysis.py +183 -0
  152. bmcgo/component/analysis/build_deps.py +165 -0
  153. bmcgo/component/analysis/data_deps.py +333 -0
  154. bmcgo/component/analysis/dep-rules.json +912 -0
  155. bmcgo/component/analysis/dep_node.py +110 -0
  156. bmcgo/component/analysis/intf_deps.py +163 -0
  157. bmcgo/component/analysis/intf_validation.py +254 -0
  158. bmcgo/component/analysis/rule.py +211 -0
  159. bmcgo/component/analysis/smc_dfx_whitelist.json +11 -0
  160. bmcgo/component/analysis/sr_validation.py +391 -0
  161. bmcgo/component/build.py +222 -0
  162. bmcgo/component/component_dt_version_parse.py +348 -0
  163. bmcgo/component/component_helper.py +114 -0
  164. bmcgo/component/coverage/__init__.py +11 -0
  165. bmcgo/component/coverage/c_incremental_cov_report.template +53 -0
  166. bmcgo/component/coverage/incremental_cov.py +464 -0
  167. bmcgo/component/deploy.py +110 -0
  168. bmcgo/component/gen.py +169 -0
  169. bmcgo/component/package_info.py +236 -0
  170. bmcgo/component/template/conanbase.py.mako +278 -0
  171. bmcgo/component/template/conanfile.deploy.py.mako +40 -0
  172. bmcgo/component/test.py +947 -0
  173. bmcgo/errors.py +119 -0
  174. bmcgo/frame.py +217 -0
  175. bmcgo/functional/__init__.py +10 -0
  176. bmcgo/functional/analysis.py +96 -0
  177. bmcgo/functional/bmc_studio_action.py +98 -0
  178. bmcgo/functional/check.py +185 -0
  179. bmcgo/functional/conan_index_build.py +251 -0
  180. bmcgo/functional/config.py +332 -0
  181. bmcgo/functional/csr_build.py +724 -0
  182. bmcgo/functional/deploy.py +263 -0
  183. bmcgo/functional/diff.py +235 -0
  184. bmcgo/functional/fetch.py +235 -0
  185. bmcgo/functional/full_component.py +391 -0
  186. bmcgo/functional/maintain.py +381 -0
  187. bmcgo/functional/new.py +166 -0
  188. bmcgo/functional/schema_valid.py +111 -0
  189. bmcgo/functional/simple_sign.py +104 -0
  190. bmcgo/functional/upgrade.py +78 -0
  191. bmcgo/ipmigen/__init__.py +13 -0
  192. bmcgo/ipmigen/ctype_defination.py +82 -0
  193. bmcgo/ipmigen/ipmigen.py +309 -0
  194. bmcgo/ipmigen/template/cmd.c.mako +366 -0
  195. bmcgo/ipmigen/template/ipmi.c.mako +25 -0
  196. bmcgo/ipmigen/template/ipmi.h.mako +51 -0
  197. bmcgo/logger.py +176 -0
  198. bmcgo/misc.py +117 -0
  199. bmcgo/target/app.yml +17 -0
  200. bmcgo/target/install_sdk.yml +15 -0
  201. bmcgo/target/personal.yml +53 -0
  202. bmcgo/target/publish.yml +45 -0
  203. bmcgo/tasks/__init__.py +11 -0
  204. bmcgo/tasks/download_buildtools_hm.py +124 -0
  205. bmcgo/tasks/misc.py +15 -0
  206. bmcgo/tasks/task.py +354 -0
  207. bmcgo/tasks/task_build_conan.py +714 -0
  208. bmcgo/tasks/task_build_rootfs_img.py +595 -0
  209. bmcgo/tasks/task_buildgppbin.py +88 -0
  210. bmcgo/tasks/task_buildhpm_ext4.py +82 -0
  211. bmcgo/tasks/task_create_interface_config.py +122 -0
  212. bmcgo/tasks/task_download_buildtools.py +99 -0
  213. bmcgo/tasks/task_download_dependency.py +72 -0
  214. bmcgo/tasks/task_hpm_envir_prepare.py +112 -0
  215. bmcgo/tasks/task_packet_to_supporte.py +87 -0
  216. bmcgo/tasks/task_prepare.py +105 -0
  217. bmcgo/tasks/task_sign_and_pack_hpm.py +42 -0
  218. bmcgo/utils/__init__.py +10 -0
  219. bmcgo/utils/buffer.py +128 -0
  220. bmcgo/utils/combine_json_schemas.py +170 -0
  221. bmcgo/utils/component_post.py +54 -0
  222. bmcgo/utils/component_version_check.py +86 -0
  223. bmcgo/utils/config.py +1067 -0
  224. bmcgo/utils/fetch_component_code.py +232 -0
  225. bmcgo/utils/install_manager.py +61 -0
  226. bmcgo/utils/installations/__init__.py +10 -0
  227. bmcgo/utils/installations/base_installer.py +70 -0
  228. bmcgo/utils/installations/install_consts.py +30 -0
  229. bmcgo/utils/installations/install_plans/bingo.yml +11 -0
  230. bmcgo/utils/installations/install_workflow.py +50 -0
  231. bmcgo/utils/installations/installers/apt_installer.py +177 -0
  232. bmcgo/utils/installations/installers/pip_installer.py +46 -0
  233. bmcgo/utils/installations/version_util.py +100 -0
  234. bmcgo/utils/mapping_config_patch.py +443 -0
  235. bmcgo/utils/perf_analysis.py +114 -0
  236. bmcgo/utils/tools.py +704 -0
  237. bmcgo/worker.py +417 -0
  238. openubmc_bingo-0.5.240.dist-info/METADATA +30 -0
  239. openubmc_bingo-0.5.240.dist-info/RECORD +242 -0
  240. openubmc_bingo-0.5.240.dist-info/WHEEL +5 -0
  241. openubmc_bingo-0.5.240.dist-info/entry_points.txt +2 -0
  242. openubmc_bingo-0.5.240.dist-info/top_level.txt +1 -0
@@ -0,0 +1,104 @@
1
+ #!/usr/bin/env python3
2
+ # -*- coding: utf-8 -*-
3
+ # Copyright (c) 2025 Huawei Technologies Co., Ltd.
4
+ # openUBMC is licensed under Mulan PSL v2.
5
+ # You can use this software according to the terms and conditions of the Mulan PSL v2.
6
+ # You may obtain a copy of Mulan PSL v2 at:
7
+ # http://license.coscl.org.cn/MulanPSL2
8
+ # THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
9
+ # EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
10
+ # MERCHANTABILITY OR FIT FOR A PARTICULAR
11
+ import argparse
12
+ import os
13
+ import json
14
+ from http import HTTPStatus
15
+
16
+ import requests
17
+
18
+ from bmcgo.utils.tools import Tools
19
+ from bmcgo.bmcgo_config import BmcgoConfig
20
+ from bmcgo import misc
21
+ from bmcgo.errors import BmcGoException, NotFoundException
22
+
23
+ tools = Tools()
24
+ log = tools.log
25
+
26
+ command_info: misc.CommandInfo = misc.CommandInfo(
27
+ group="Misc commands",
28
+ name="simple_sign",
29
+ description=["使用简易https签名服务器进行文件签名"],
30
+ hidden=True
31
+ )
32
+
33
+
34
+ def if_available(_: BmcgoConfig):
35
+ return True
36
+
37
+
38
+ class BmcgoCommand:
39
+ def __init__(self, bconfig: BmcgoConfig, *args):
40
+ self.bconfig = bconfig
41
+ parser = argparse.ArgumentParser(
42
+ prog="bingo simple_sign",
43
+ description="使用简易签名服务器(返回包含signed.cms和rootca.crl的zip包)进行签名",
44
+ add_help=True,
45
+ formatter_class=argparse.RawTextHelpFormatter,
46
+ )
47
+ parser.add_argument("-i", "--input", help="待签名文件", required=True)
48
+ parser.add_argument("-s", "--signer_id", help="签名证书ID", required=True)
49
+ parser.add_argument("-u", "--url", help="签名服务器签名POST接口url", required=True)
50
+ parser.add_argument("-v", "--verify", help="是否验证HTTPS证书有效性", action=misc.STORE_TRUE)
51
+ parsed_args, _ = parser.parse_known_args(*args)
52
+ self.input = os.path.realpath(os.path.join(os.getcwd(), parsed_args.input))
53
+ self.signer_id = parsed_args.signer_id
54
+ self.url = parsed_args.url
55
+ self.verify = parsed_args.verify
56
+ if not os.path.isfile(self.input):
57
+ raise NotFoundException(f"待签名文件{self.input}不存在")
58
+
59
+ def run(self):
60
+ signed_zip = self.sign_file()
61
+ tools.run_command(f"unzip -o {signed_zip}")
62
+ if not os.path.isfile("rootca.crl") or not os.path.isfile("signed.cms"):
63
+ raise NotFoundException("签名服务器返回的zip包中rootca.crl或signed.cms文件不存在。")
64
+
65
+ def get_sign_metadata(self):
66
+ token = os.environ.get("SIGN_TOKEN", "")
67
+ metadata = {
68
+ "FileName": os.path.basename(self.input),
69
+ "FileSha256": tools.sha256sum(self.input),
70
+ "CertId": self.signer_id,
71
+ "Token": token,
72
+ "Version": "0",
73
+ }
74
+ return metadata
75
+
76
+ def sign_file(self):
77
+ # 组装待签名文件
78
+ files = {"file": ("signed", open(self.input, "rb"), "text/plain")}
79
+ metadata = self.get_sign_metadata()
80
+ data = {"metadata": json.dumps(metadata)}
81
+ # 发起POST请求
82
+ try:
83
+ log.info({"metadata": json.dumps(metadata)})
84
+ response = requests.post(self.url, files=files, data=data, verify=self.verify)
85
+ response.raise_for_status()
86
+ except requests.exceptions.RequestException as e:
87
+ raise BmcGoException(f"签名服务器返回错误, 文件 {self.input} 签名失败") from e
88
+
89
+ # 接收文件
90
+ if response.status_code == HTTPStatus.OK:
91
+ log.info("签名服务接口返回成功, 正在保存文件...")
92
+ outfile = "signed.zip"
93
+ with open(outfile, "wb") as f:
94
+ f.write(response.content)
95
+ log.info(f"签名结果已保存为:{outfile}")
96
+ return outfile
97
+ else:
98
+ raise BmcGoException(f"签名POST请求失败, 文件 {self.input} 签名失败, 状态码:", response.status_code)
99
+
100
+
101
+ if __name__ == "__main__":
102
+ bconfig = BmcgoConfig()
103
+ sign = BmcgoCommand(bconfig=bconfig)
104
+ sign.run()
@@ -0,0 +1,78 @@
1
+ #!/usr/bin/env python3
2
+ # encoding=utf-8
3
+ # 描述:bingo 升级工具
4
+ # Copyright (c) 2025 Huawei Technologies Co., Ltd.
5
+ # openUBMC is licensed under Mulan PSL v2.
6
+ # You can use this software according to the terms and conditions of the Mulan PSL v2.
7
+ # You may obtain a copy of Mulan PSL v2 at:
8
+ # http://license.coscl.org.cn/MulanPSL2
9
+ # THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
10
+ # EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
11
+ # MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
12
+ # See the Mulan PSL v2 for more details.
13
+
14
+ import re
15
+ import argparse
16
+ from pathlib import Path
17
+ from bmcgo import misc
18
+ from bmcgo.logger import Logger
19
+ from bmcgo.bmcgo_config import BmcgoConfig
20
+ from bmcgo.utils.tools import Tools
21
+ from bmcgo.utils.install_manager import InstallManager
22
+ from bmcgo.utils.installations import install_consts
23
+
24
+ tools = Tools("bingo_upgrade")
25
+ log = Logger()
26
+
27
+ command_info: misc.CommandInfo = misc.CommandInfo(
28
+ group=misc.GRP_MISC,
29
+ name="upgrade",
30
+ description=["升级 bingo 版本"],
31
+ hidden=False
32
+ )
33
+
34
+
35
+ def if_available(bconfig: BmcgoConfig):
36
+ return True
37
+
38
+
39
+ _DESCRIPTION = """
40
+ bingo 升级工具
41
+ """
42
+
43
+
44
+ class BmcgoCommand:
45
+ VERSION_PATTERN = re.compile(
46
+ r"^([a-zA-Z0-9_-]+)\s*([<>]=?|[!~]?=)?\s*([a-zA-Z0-9._+-]*|"
47
+ rf"{install_consts.INSTALL_LATEST})$"
48
+ )
49
+
50
+ def __init__(self, bconfig: BmcgoConfig, *args):
51
+ parser = argparse.ArgumentParser(
52
+ prog="bingo upgrade",
53
+ description=_DESCRIPTION,
54
+ add_help=True,
55
+ formatter_class=argparse.RawTextHelpFormatter
56
+ )
57
+ parser.add_argument(
58
+ "-v",
59
+ "--version",
60
+ default=install_consts.INSTALL_DEFAULT,
61
+ help="列出所有配置"
62
+ )
63
+
64
+ args, _ = parser.parse_known_args()
65
+ self.version = args.version
66
+ self.installer = InstallManager()
67
+ self.plugin_path = Path(bconfig.bmcgo_config_list.get(misc.CUSTOM_PLUGINS, misc.DEFAULT_PLUGINS_PATH))
68
+
69
+ def run(self):
70
+ self.installer.install(*self._parse_version(), self.plugin_path)
71
+ return 0
72
+
73
+ def _parse_version(self):
74
+ match = re.search(self.VERSION_PATTERN, self.version)
75
+ if match:
76
+ return match.groups()
77
+ self.version = install_consts.INSTALL_DEFAULT
78
+ return self._parse_version()
@@ -0,0 +1,13 @@
1
+ # coding: utf-8
2
+ # Copyright (c) 2024 Huawei Technologies Co., Ltd.
3
+ # openUBMC is licensed under Mulan PSL v2.
4
+ # You can use this software according to the terms and conditions of the Mulan PSL v2.
5
+ # You may obtain a copy of Mulan PSL v2 at:
6
+ # http://license.coscl.org.cn/MulanPSL2
7
+ # THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
8
+ # EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
9
+ # MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
10
+ # See the Mulan PSL v2 for more details.
11
+
12
+ # 非常重要,修改bmcgo后如果自动生成代码有变更的,必须变更codegen目录下__init__.py的__version__字段
13
+ # 该版本号会传入mako渲染,在自动生成变更时需要做到向下兼容,确保代码自动生成功能OK
@@ -0,0 +1,82 @@
1
+ #!/usr/bin/python3
2
+ # coding: utf-8
3
+ # Copyright (c) 2024 Huawei Technologies Co., Ltd.
4
+ # openUBMC is licensed under Mulan PSL v2.
5
+ # You can use this software according to the terms and conditions of the Mulan PSL v2.
6
+ # You may obtain a copy of Mulan PSL v2 at:
7
+ # http://license.coscl.org.cn/MulanPSL2
8
+ # THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
9
+ # EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
10
+ # MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
11
+ # See the Mulan PSL v2 for more details.
12
+
13
+
14
+ class CTypeBase(object):
15
+ def __init__(self, c_type, c_len):
16
+ self.c_type = c_type
17
+ self.c_len = c_len
18
+ pass
19
+
20
+
21
+ class CTypes():
22
+ types: dict = {
23
+ "U8": CTypeBase(
24
+ c_type="guint8 <arg_name><bit_field>",
25
+ c_len=1),
26
+ "U8[]": CTypeBase(
27
+ c_type="guint8 <arg_name>[<type_len>]<bit_field>",
28
+ c_len=1),
29
+ "S16": CTypeBase(
30
+ c_len=2,
31
+ c_type="gint16 <arg_name><bit_field>"),
32
+ "S16[]": CTypeBase(
33
+ c_type="gint16 <arg_name>[<type_len>]<bit_field>",
34
+ c_len=2),
35
+ "U16": CTypeBase(
36
+ c_type="guint16 <arg_name><bit_field>",
37
+ c_len=2),
38
+ "U16[]": CTypeBase(
39
+ c_type="guint16 <arg_name>[<type_len>]<bit_field>",
40
+ c_len=2),
41
+ "S32": CTypeBase(
42
+ c_type="gint32 <arg_name><bit_field>",
43
+ c_len=4),
44
+ "S32[]": CTypeBase(
45
+ c_type="gint32 <arg_name>[<type_len>]<bit_field>",
46
+ c_len=4),
47
+ "U32": CTypeBase(
48
+ c_type="guint32 <arg_name><bit_field>",
49
+ c_len=4),
50
+ "U32[]": CTypeBase(
51
+ c_type="guint32 <arg_name>[<type_len>]<bit_field>",
52
+ c_len=4,
53
+ ),
54
+ "S64": CTypeBase(
55
+ c_type="gint64 <arg_name><bit_field>",
56
+ c_len=8),
57
+ "S64[]": CTypeBase(
58
+ c_type="gint64 <arg_name>[<type_len>]<bit_field>",
59
+ c_len=8,),
60
+ "U64": CTypeBase(
61
+ c_type="guint64 <arg_name><bit_field>",
62
+ c_len=8),
63
+ "U64[]": CTypeBase(
64
+ c_type="guint64 <arg_name>[<type_len>]<bit_field>",
65
+ c_len=8,
66
+ ),
67
+ "Double": CTypeBase(
68
+ c_type="gdouble <arg_name>",
69
+ c_len=8),
70
+ "Double[]": CTypeBase(
71
+ c_type="gdouble <arg_name>[<type_len>]",
72
+ c_len=8,),
73
+ "String": CTypeBase(
74
+ c_type="gchar <arg_name>[<type_len>]",
75
+ c_len=1),
76
+ "String *": CTypeBase(
77
+ c_type="gchar *<arg_name>",
78
+ c_len=1),
79
+ "U8 *": CTypeBase(
80
+ c_type="guint8 *<arg_name>",
81
+ c_len=1),
82
+ }
@@ -0,0 +1,309 @@
1
+ #!/usr/bin/python3
2
+ # coding: utf-8
3
+ # Copyright (c) 2024 Huawei Technologies Co., Ltd.
4
+ # openUBMC is licensed under Mulan PSL v2.
5
+ # You can use this software according to the terms and conditions of the Mulan PSL v2.
6
+ # You may obtain a copy of Mulan PSL v2 at:
7
+ # http://license.coscl.org.cn/MulanPSL2
8
+ # THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
9
+ # EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
10
+ # MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
11
+ # See the Mulan PSL v2 for more details.
12
+ import json
13
+ import math
14
+ import os
15
+ import re
16
+ import subprocess
17
+ import stat
18
+ import inflection
19
+ from mako.lookup import TemplateLookup
20
+ from bmcgo.ipmigen.ctype_defination import CTypes, CTypeBase
21
+ from bmcgo.codegen.c.helper import Helper
22
+ from bmcgo.codegen.c.renderer import Renderer
23
+ from bmcgo.logger import Logger
24
+
25
+ log = Logger("ipmi_gen")
26
+ cwd = os.path.split(os.path.realpath(__file__))[0]
27
+ FILTER_SPLIT = "*,"
28
+ U8_POINT = "U8 *"
29
+
30
+
31
+ class MdsFormatError(OSError):
32
+ """测试失败"""
33
+
34
+
35
+ def get_byte(obj, name, key):
36
+ val = obj.get(key)
37
+ if val is None:
38
+ raise MdsFormatError("获取属性 %s.%s 失败", name, key)
39
+ val = val.lower()
40
+ if not val.startswith("0x"):
41
+ raise MdsFormatError("无效的 16 进制字符串, 固定名: {}.{}}, 值: {}".format(name, key, val))
42
+ return val
43
+
44
+
45
+ class IpmiCmdArg(object):
46
+ def __init__(self, obj):
47
+ self.data = obj.get("data")
48
+ self.base_type = obj.get("baseType")
49
+ self.manufacturer = obj.get("customizedRule") == "Manufacturer"
50
+ if self.base_type is None:
51
+ raise MdsFormatError("获取基础类型失败")
52
+ self.base_type = self.base_type
53
+ self.ctype: CTypeBase = None
54
+ self.len = obj.get("len")
55
+ self.value = obj.get("value", None)
56
+ # 标记响应u8 *类型值的长度来自于请求
57
+ self.len_from_req = False;
58
+ if self.value is not None and self.value[0:2].lower() != "0x":
59
+ raise MdsFormatError("过滤器参数 {} 格式错误, 必须以 '0x' 开头, 但实际值为 {}"
60
+ .format(self.data, self.value))
61
+ self.filter = ""
62
+ # "*" 只适用于String,否则报错
63
+ if self.base_type == "Double":
64
+ if self.len != "8B":
65
+ raise MdsFormatError("数据: {} 长度错误: 基础类型 `Double` 长度必须为 8B, 当前长度: {}"
66
+ .format(self.data, self.len))
67
+ elif self.len == "*":
68
+ if self.base_type == "String":
69
+ self.base_type = "String *"
70
+ elif self.base_type == "U8[]":
71
+ self.base_type = U8_POINT
72
+ else:
73
+ raise MdsFormatError("数据: {} 基础类型错误: 仅 `String` 和 `U8[]` 支持基础类型 '*'"
74
+ .format(self.data))
75
+ elif re.match('^[1-9][0-9]*B$', self.len):
76
+ pass
77
+ elif self.base_type == "U8[]" and not re.match('^[1-9][0-9]*B$', self.len):
78
+ self.base_type = U8_POINT
79
+ elif self.len == "0b" or self.len == "0B":
80
+ raise MdsFormatError("数据: {} 长度错误: {}".format(self.data, self.len))
81
+ self._ctype_parse()
82
+
83
+ def _ctype_parse(self):
84
+ # 获取C类型定义
85
+ self.ctype = CTypes.types.get(self.base_type)
86
+ if self.ctype is None:
87
+ raise MdsFormatError("数据 {} 中有不支持的基础类型: {}".format(self.data, self.base_type))
88
+ log.debug("数据: %s, 基础类型: %s, 基础类型: %d, 值:%s", self.data, self.base_type, self.len, self.value)
89
+ if not self.base_type.endswith("[]") and not self.base_type.startswith("String") and self.base_type != U8_POINT:
90
+ val_len = int(self.len[:-1], 10)
91
+ if re.match('^[1-9][0-9]*B$', self.len) and val_len > self.ctype.c_len:
92
+ raise MdsFormatError("数据: {} 长度错误: 长度必须小于或者等于 {}B, 当前长度为: {}B"
93
+ .format(self.data, self.ctype.c_len, val_len))
94
+ elif re.match('^[1-9][0-9]*b$', self.len) and val_len > (self.ctype.c_len * 8):
95
+ max_len = self.ctype.c_len * 8
96
+ raise MdsFormatError("数据: {} 长度错误: 长度必须小于或者等于 {}b, 当前长度为: {}b"
97
+ .format(self.data, max_len, val_len))
98
+
99
+ if re.match('^[1-9][0-9]*B$', self.len) is not None:
100
+ # 如果是Byte,计算数组长度时需要除C元素大小并向上取整
101
+ self.bit_len = int(self.len[:-1], 10) * 8
102
+ self.type_len = math.ceil(self.bit_len / 8 / self.ctype.c_len)
103
+ self.bit_field = ""
104
+ elif re.match('^[1-9][0-9]*b$', self.len) is not None:
105
+ # 如果是位域
106
+ self.type_len = ""
107
+ self.bit_len = int(self.len[:-1], 10)
108
+ self.bit_field = ":" + str(self.bit_len)
109
+ else:
110
+ # 否则啥也不是
111
+ self.type_len = ""
112
+ self.bit_len = 0
113
+ self.bit_field = ""
114
+
115
+ self.c_declear_str = self.ctype.c_type.replace("<arg_name>", self.data)
116
+ self.c_declear_str = self.c_declear_str.replace("<type_len>", str(self.type_len))
117
+ self.c_declear_str = self.c_declear_str.replace("<bit_field>", self.bit_field)
118
+
119
+
120
+ class IpmiCmd(object):
121
+ def __init__(self, name, obj):
122
+ self.name = name
123
+ log.info("ipmi 命令名称: %s === >>>", name)
124
+ self.netfn = get_byte(obj, name, "netfn")
125
+ self.cmd = get_byte(obj, name, "cmd")
126
+ self.priority_str = obj.get("priority", "Default")
127
+ priority_map = {
128
+ "Default": 10, "Oem": 20, "OEM": 20, "Odm": 30, "ODM": 30, "OBM": 35, "EndUser": 40, "Max": 50
129
+ }
130
+ self.priority = priority_map.get(self.priority_str, None)
131
+ if self.priority is None:
132
+ raise MdsFormatError("{} 不支持的命令优先级 {}, 退出".format(name, self.priority_str))
133
+
134
+ self.role_str = obj.get("role", "None")
135
+ self.sensitive = obj.get("sensitive", False)
136
+
137
+ privilege_map = {
138
+ "OEM": 5, "Administrator": 4, "Operator": 3, "User": 2, "Callback": 1, "Unspecified": 0
139
+ }
140
+ self.role = privilege_map.get(self.role_str, 0)
141
+ if self.role is None:
142
+ raise MdsFormatError("命令 {} 不支持的规则 {}, 终止构建".format(name, self.role))
143
+ self.privilege_str = obj.get("privilege", [])
144
+ self.privilege = Helper.get_privilege(",".join(self.privilege_str))
145
+ self.req_args: list[IpmiCmdArg] = []
146
+ self.rsp_args: list[IpmiCmdArg] = []
147
+ self._arg_parse(obj)
148
+
149
+ @property
150
+ def filter(self):
151
+ filter_str = ""
152
+ bit_pos = 0
153
+ last_bit_type = None
154
+ for arg in self.req_args:
155
+ if re.match('^[1-9][0-9]*B$', arg.len):
156
+ # 如果之前有位域未处理的,生成过滤符
157
+ if bit_pos:
158
+ filter_str += FILTER_SPLIT.join("" for _ in range((bit_pos + 7) // 8 + 1))
159
+ bit_pos = 0
160
+ # 如果需要过滤的
161
+ if arg.value is not None:
162
+ hex_len = (arg.bit_len // 8) * 2
163
+ value = arg.value[2:].lower()
164
+ # 可能过长,需要截断
165
+ value = value[0:hex_len]
166
+ # 可能过短,需要补前零
167
+ value = value.rjust(hex_len, '0')
168
+ filter_str += ",".join(value[i - 2:i] for i in range(hex_len, 0, -2)) + ","
169
+ else:
170
+ filter_str += FILTER_SPLIT.join("" for _ in range(arg.bit_len // 8 + 1))
171
+ elif re.match('^[1-9][0-9]*b$', arg.len):
172
+ cross_type = (bit_pos + arg.bit_len - 1) // (arg.ctype.c_len * 8) != bit_pos // (arg.ctype.c_len * 8)
173
+ # 类型发生变更时重新计数或位域跨多个基础类型
174
+ if bit_pos != 0 and last_bit_type != arg.base_type and cross_type:
175
+ filter_str += FILTER_SPLIT.join("" for _ in range((bit_pos + 7) // 8 + 1))
176
+ bit_pos = 0
177
+ bit_pos += arg.bit_len
178
+ last_bit_type = arg.base_type
179
+ else:
180
+ # 跳过大小不明确的内容
181
+ break
182
+ if bit_pos:
183
+ filter_str += FILTER_SPLIT.join("" for _ in range((bit_pos + 7) // 8 + 1))
184
+ while filter_str.endswith(",") or filter_str.endswith("*"):
185
+ filter_str = filter_str[:-1]
186
+ return filter_str
187
+
188
+ def _req_arg_parse(self, obj):
189
+ req_name = []
190
+ last_dynamic_u8 = False
191
+ for arg in obj.get("req", []):
192
+ arg = IpmiCmdArg(arg)
193
+ self.req_args.append(arg)
194
+ # 检查类型为U8[]且长度为变量为*的场景
195
+ index = 0
196
+ req_manufacturer_index = -1
197
+ for arg in self.req_args:
198
+ if arg.manufacturer:
199
+ if req_manufacturer_index != -1:
200
+ raise Exception(f"{self.name}的请求中只允许一个参数配置Manufacturer")
201
+ req_manufacturer_index = index
202
+ index = index + 1
203
+ # 如果类型为U8[]且长度未在之前申明且不是最后一个参数的
204
+ if arg.base_type == U8_POINT and arg.len not in req_name and index != len(self.req_args):
205
+ raise MdsFormatError("数据 {}.{} 有无效长度".format(self.name, arg.data))
206
+ req_name.append(arg.data)
207
+ return req_name, req_manufacturer_index
208
+
209
+ def _arg_parse(self, obj):
210
+ req_name, req_manufacturer_index = self._req_arg_parse(obj)
211
+
212
+ log.debug("ipmi 响应:")
213
+ for arg in obj.get("rsp", []):
214
+ self.rsp_args.append(IpmiCmdArg(arg))
215
+
216
+ # 检查类型为U8[]且长度为变量为*的场景
217
+ index = 0
218
+ rsp_name = []
219
+ rsp_manufacturer_index = -1
220
+ for arg in self.rsp_args:
221
+ if arg.manufacturer:
222
+ if rsp_manufacturer_index != -1:
223
+ raise Exception(f"{self.name}的响应中只允许一个参数配置Manufacturer")
224
+ rsp_manufacturer_index = index
225
+ index = index + 1
226
+ # 如果类型为U8[]且长度未在之前申明的(也就是说响应字段必须申明长度,否则不能正确构造响应体)
227
+ if arg.base_type == U8_POINT:
228
+ if arg.len not in rsp_name and arg.len not in req_name:
229
+ raise MdsFormatError("数据 {}.{} 有无效长度".format(self.name, arg.data))
230
+ if arg.len in rsp_name:
231
+ pass
232
+ # U8 *类型的响应值长度来自于请求体
233
+ if arg.len in req_name:
234
+ arg.len_from_req = True
235
+ rsp_name.append(arg.data)
236
+ self.manufacturer = "{" + str(req_manufacturer_index) + ", " + str(rsp_manufacturer_index) + "}"
237
+ self.need_free_rsp = False
238
+ for arg in self.rsp_args:
239
+ if arg.base_type == "String *" or arg.base_type == U8_POINT:
240
+ self.need_free_rsp = True
241
+ break
242
+ if len(self.rsp_args) == 0:
243
+ raise MdsFormatError("IPMI命令{}的响应缺少完成码".format(self.name))
244
+ complete = self.rsp_args[0];
245
+ if complete.data != "CompletionCode":
246
+ log.warning(f"IPMI命令%s的响应第一个成员(%s)名称不是(CompletionCode),为增加可读性,建议改名", self.name, complete.data)
247
+
248
+ if complete.base_type != "U8":
249
+ log.error(f"IPMI命令%s的响应第一个成员(%s)必须是U8类型", self.name, complete.data)
250
+
251
+
252
+ class IpmiCmds(Renderer):
253
+ def __init__(self, lookup, ipmi_json, base_version):
254
+ super(Renderer, self).__init__()
255
+ self.base_version = base_version
256
+ self.lookup = lookup
257
+ with open(ipmi_json) as file_handler:
258
+ ipmi_cmds = json.load(file_handler)
259
+ self.package = ipmi_cmds.get("package")
260
+ self.name = inflection.underscore(self.package)
261
+ self.cmds: list[IpmiCmd] = []
262
+ for cmd, data in ipmi_cmds.get("cmds", {}).items():
263
+ self.cmds.append(IpmiCmd(cmd, data))
264
+
265
+ def render_ipmi(self, template, out_file):
266
+ file_handler = os.fdopen(os.open(out_file, os.O_WRONLY | os.O_CREAT | os.O_TRUNC,
267
+ stat.S_IWUSR | stat.S_IRUSR), 'w')
268
+ out = self.render(self.lookup, template, ipmi_cmds=self, version=self.base_version)
269
+ file_handler.write(out)
270
+ file_handler.close()
271
+ pass
272
+
273
+ def render_cmd(self, template, out_dir):
274
+ for cmd in self.cmds:
275
+ out_file = os.path.join(out_dir, "ipmi_cmd_" + inflection.underscore(cmd.name) + ".c")
276
+ file_handler = os.fdopen(os.open(out_file, os.O_WRONLY | os.O_CREAT | os.O_TRUNC,
277
+ stat.S_IWUSR | stat.S_IRUSR), 'w')
278
+ out = self.render(self.lookup, template, package_name=self.package, cmd=cmd, version=self.base_version)
279
+ file_handler.write(out)
280
+ file_handler.close()
281
+
282
+
283
+ class IpmiGen(object):
284
+ def __init__(self, base_version):
285
+ self.base_version = base_version
286
+
287
+ def format(self, out_file):
288
+ try:
289
+ Helper.run(["/usr/bin/clang-format", "--version"], stderr=subprocess.DEVNULL, stdout=subprocess.DEVNULL)
290
+ except Exception:
291
+ log.error("命令 clang-format 没找到, 跳过格式化 %s/%s", os.getcwd(), out_file)
292
+ return
293
+ if not os.path.isfile(".clang-format"):
294
+ log.error("样式文件 .clang-format 不存在, 跳过格式化 %s/%s", os.getcwd(), out_file)
295
+ return
296
+ log.info("格式化源: %s/%s", os.getcwd(), out_file)
297
+ Helper.run(["/usr/bin/clang-format", "--style=file", "-i", out_file])
298
+
299
+ def gen(self, json_file, directory="."):
300
+ os.makedirs(directory, exist_ok=True)
301
+ lookup = TemplateLookup(directories=os.path.join(cwd, "template"))
302
+ ipmi_cmds = IpmiCmds(lookup, json_file, self.base_version)
303
+ out_file = os.path.join(directory, ipmi_cmds.name + ".h")
304
+ ipmi_cmds.render_ipmi("ipmi.h.mako", out_file)
305
+ out_file = os.path.join(directory, ipmi_cmds.name + ".c")
306
+ ipmi_cmds.render_ipmi("ipmi.c.mako", out_file)
307
+ ipmi_cmds.render_cmd("cmd.c.mako", directory)
308
+ self.format(out_file)
309
+ log.success("Generate code successfully, interface: %s", json_file)