• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python3
2# coding=utf-8
3#   Copyright (c) 2020 HiSilicon (Shanghai) Technologies CO., LIMITED.
4#    Licensed under the Apache License, Version 2.0 (the "License");
5#    you may not use this file except in compliance with the License.
6#    You may obtain a copy of the License at
7#
8#        http://www.apache.org/licenses/LICENSE-2.0
9#
10#    Unless required by applicable law or agreed to in writing, software
11#    distributed under the License is distributed on an "AS IS" BASIS,
12#    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13#    See the License for the specific language governing permissions and
14#    limitations under the License.
15
16import os
17import sys
18import json
19import shutil
20
21XML_PATH="build/config/target_config/<chip>/hdb_config/database_cfg/mk_hdb_xml.json"
22G_PARAMS = {}
23
24# 生成database
25def database_create():
26    database_base = G_PARAMS["DATABASE_BASE"] # 获取database目录路径
27
28    # 判断对应版本,用于生成out下database目录后缀
29    target_cus = G_PARAMS.get("DATABASE_VERSION", "").split()
30    if not target_cus:
31        target_cus = [""]
32    for cus in set(target_cus):
33        if cus:
34            database_target_name = '_'.join(['database', cus])
35        else:
36            database_target_name = 'database'
37        database_target = os.path.join(G_PARAMS["OUT_DIR"], database_target_name)
38        # 生成database
39        shutil.rmtree(database_target, ignore_errors=True, onerror=None)
40        shutil.copytree(database_base, database_target)
41        mss_prim_path = G_PARAMS["DATABASE_MSS_PRIM_PATH"]
42        diag_dir_path = G_PARAMS["DATABASE_DIAG_DIR_PATH"]
43        cores = G_PARAMS["DATABASE_VERSION_CORE"].split()
44        for core in cores:
45            if os.path.exists(mss_prim_path):
46                shutil.copy(mss_prim_path, os.path.join(database_target, core, 'system', 'hdbcfg'))
47            if os.path.exists(diag_dir_path):
48                filelist = os.listdir(diag_dir_path)
49                for f in filelist:
50                    shutil.copy(os.path.join(diag_dir_path, f), os.path.join(database_target, core, 'system', 'diag'))
51            # 暂时修改out目录下生成的database的目录为cco
52            if core == 'acore':
53                try:
54                    os.rename(os.path.join(database_target, core), os.path.join(database_target, 'cco'))
55                except:
56                    print("[WARN] rename %s exception" % os.path.join(database_target, core))
57                    continue
58
59def create():
60    global G_PARAMS
61    root = sys.argv[1]
62    chip = sys.argv[2]
63    in_path = XML_PATH
64    in_path = in_path.replace('<chip>', chip)
65
66    db_conf = None
67    conf = os.path.join(root, in_path)
68    with open(conf, 'r') as f:
69        db_conf = json.load(f)
70
71    G_PARAMS["DATABASE_BASE"] = os.path.join(root, db_conf["DATABASE_BASE"])
72    G_PARAMS["DATABASE_MSS_PRIM_PATH"] = os.path.join(root, db_conf["DATABASE_MSS_PRIM_PATH"])
73    G_PARAMS["DATABASE_DIAG_DIR_PATH"] = os.path.join(root, db_conf["DATABASE_DIAG_DIR_PATH"])
74    G_PARAMS["OUT_DIR"] = os.path.join(root, db_conf["OUT_DIR"])
75    G_PARAMS["DATABASE_VERSION"] = db_conf["DATABASE_VERSION"]
76    G_PARAMS["DATABASE_VERSION_CORE"] = db_conf["DATABASE_VERSION_CORE"]
77
78    database_create()
79
80if __name__ == "__main__":
81    create()