• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python
2#coding=utf-8
3
4#
5# Copyright (c) 2022 Huawei Device Co., Ltd.
6# Licensed under the Apache License, Version 2.0 (the "License");
7# you may not use this file except in compliance with the License.
8# You may obtain a copy of the License at
9#
10#     http://www.apache.org/licenses/LICENSE-2.0
11#
12# Unless required by applicable law or agreed to in writing, software
13# distributed under the License is distributed on an "AS IS" BASIS,
14# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15# See the License for the specific language governing permissions and
16# limitations under the License.
17#
18
19import os
20import subprocess
21
22class HdiParser(object):
23	@staticmethod
24	def load(mgr, product_out_path):
25		# Decode hcb file to get hcs file
26		hdi_tool = os.path.join(product_out_path, "obj/drivers/hdf_core/framework/tools/hc-gen/hc-gen")
27		hcs_file = os.path.join(product_out_path, "packages/phone/vendor/etc/hdfconfig/hdf_default.hcb")
28		out_file = os.path.join(product_out_path, "device_info.hcs")
29		subprocess.Popen('%s -d "%s" -o "%s"' % (hdi_tool, hcs_file, out_file), shell=True).wait()
30		try:
31			with open(out_file) as f:
32				lines = f.readlines()
33		except:
34			try:
35				out_file = os.path.join(product_out_path, "device_info.d.hcs")
36				with open(out_file) as f:
37					lines = f.readlines()
38			except:
39				return
40
41		modules = []
42		for line in lines:
43			line = line.strip()
44			if line.find("moduleName") < 0:
45				continue
46			parts = line.split("=")
47			parts = [p.strip() for p in parts]
48			if len(parts) < 2:
49				continue
50			name = parts[1]
51			if name.endswith(";"):
52				name = name[:-1]
53			name=name.strip('"')
54			name=name.strip("'")
55			if name == "":
56				continue
57
58			if not name.endswith(".so"):
59				name = "lib%s.z.so" % name
60			modules.append(name)
61
62		if not mgr:
63			return
64
65		for elf in mgr.get_all():
66			if elf["name"] in modules:
67				elf["hdiType"] = "hdi_service"
68
69if __name__ == "__main__":
70	parser = HdiParser()
71	parser.load(None, "/home/z00325844/ohos/vendor/hihope/rk3568/hdf_config/uhdf/device_info.hcs")
72