• 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
22
23class HdiParser(object):
24    @staticmethod
25    def load(mgr, product_out_path):
26        # Decode hcb file to get hcs file
27        hdi_tool = os.path.join(product_out_path, "obj/drivers/hdf_core/framework/tools/hc-gen/hc-gen")
28        hcs_file = os.path.join(product_out_path, "packages/phone/vendor/etc/hdfconfig/hdf_default.hcb")
29        out_file = os.path.join(product_out_path, "device_info.hcs")
30        if os.path.exists(hcs_file) and os.path.exists(hdi_tool):
31            subprocess.Popen([hdi_tool, "-d", hcs_file, "-o", out_file]).wait()
32        else:
33            print("{} or {} not exist".format(hcs_file, hdi_tool))
34        try:
35            with open(out_file) as f:
36                lines = f.readlines()
37        except:
38            try:
39                out_file = os.path.join(product_out_path, "device_info.d.hcs")
40                with open(out_file) as f:
41                    lines = f.readlines()
42            except:
43                return
44
45        modules = []
46        for line in lines:
47            line = line.strip()
48            if line.find("moduleName") < 0:
49                continue
50            parts = line.split("=")
51            parts = [p.strip() for p in parts]
52            if len(parts) < 2:
53                continue
54            name = parts[1]
55            if name.endswith(";"):
56                name = name[:-1]
57            name = name.strip('"')
58            name = name.strip("'")
59            if name == "":
60                continue
61
62            if not name.endswith(".so"):
63                name = "lib%s.z.so" % name
64            modules.append(name)
65
66        if not mgr:
67            return
68
69        for elf in mgr.get_all():
70            if elf["name"] in modules:
71                elf["hdiType"] = "hdi_service"
72
73if __name__ == "__main__":
74    parser = HdiParser()
75    parser.load(None, "/home/ohos/vendor/hihope/rk3568/hdf_config/uhdf/device_info.hcs")
76