• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright (c) 2022-2022 Huawei Technologies Co., Ltd. All rights reserved.
2#
3# UniProton 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# Create: 2022-09-21
12# Description: UniProton内核配置开关编译脚本。
13import("//build/lite/config/component/lite_component.gni")
14
15product_config_file = "${ohos_build_type}.config"
16product_config_file =
17    rebase_path(product_config_file, "", "$product_path/kernel_configs")
18print("product_config_file:", product_config_file)
19
20MENUCONFIG_H = rebase_path("$root_out_dir/config.h")
21exec_script(
22    "//build/lite/run_shell_cmd.py",
23    [ "env" + " CONFIG_=" + " KCONFIG_CONFIG_HEADER='y=true'" +
24          " KCONFIG_CONFIG=$product_config_file" +
25          " BOARD_COMPANY=$device_company" + " DEVICE_PATH=$device_path" +
26          " srctree=" + rebase_path("./src") + " genconfig" +
27          " --header-path $MENUCONFIG_H" + " --file-list kconfig_files.txt" +
28          " --env-list kconfig_env.txt" + " --config-out config.gni" ],
29    "",
30    [ product_config_file ])
31
32import("$root_out_dir/config.gni")
33
34OSTOPDIR = "//kernel/uniproton/src"
35OSTHIRDPARTY = "//third_party"
36
37HDFTOPDIR = "//drivers/hdf_core/adapter/khdf/uniproton"
38
39template("kernel_module") {
40  build_gn = rebase_path("BUILD.gn")
41  print("build_gn is $build_gn")
42  cmd = "grep -c '^\s*\(kernel_module\|hdf_driver\)\s*(\s*\S*\s*)\s*{\s*\$' $build_gn"
43  modules_count = exec_script("//build/lite/run_shell_cmd.py", [ cmd ], "value")
44  if (modules_count == 1) {
45    auto_config = true
46  }
47
48  cmd = "if grep -q '^\s*\(config\s*(\s*\"public\"\s*)\|module_group\s*(\s*\"\S*\"\s*)\)\s*{\s*\$' $build_gn; then echo true; else echo false; fi"
49  has_public_config =
50      exec_script("//build/lite/run_shell_cmd.py", [ cmd ], "value")
51  if (!has_public_config && defined(auto_config)) {
52    config("public") {
53      configs = []
54    }
55  }
56
57  current_dir_name = get_path_info(rebase_path("."), "file")
58  if (target_name != current_dir_name) {
59    cmd = "if grep -q '^\s*\(module_group\|group\)\s*(\s*\"$current_dir_name\"\s*)\s*{\s*\$' $build_gn; then echo true; else echo false; fi"
60    has_current_dir_group =
61        exec_script("//build/lite/run_shell_cmd.py", [ cmd ], "value")
62    if (!has_current_dir_group && defined(auto_config)) {
63      module_name = target_name
64      group(current_dir_name) {
65        public_deps = [ ":$module_name" ]
66      }
67    }
68  }
69
70  if (defined(invoker.module_switch) && !invoker.module_switch) {
71    group(target_name) {
72      not_needed(invoker, "*")
73    }
74  } else {
75    source_set(target_name) {
76      public_configs = []
77      forward_variables_from(invoker, "*", [ "configs" ])
78      configs += invoker.configs
79      if (has_public_config) {
80        included_public_config = false
81        foreach(cfg, public_configs) {
82          what = "label_no_toolchain"
83          if (get_label_info(cfg, what) == get_label_info(":public", what)) {
84            included_public_config = true
85            included_public_config = false
86          }
87        }
88        if (!included_public_config) {
89          public_configs += [ ":public" ]
90        }
91      }
92    }
93  }
94  not_needed([ "auto_config" ])
95}
96
97template("config") {
98  config(target_name) {
99    if (defined(invoker.module_switch) && !invoker.module_switch &&
100        target_name == "public") {
101      not_needed(invoker, "*")
102      forward_variables_from(invoker, [ "configs" ])
103    } else {
104      forward_variables_from(invoker, "*")
105    }
106  }
107}
108
109template("module_group") {
110  assert(defined(invoker.modules), "modules are must")
111  group(target_name) {
112    deps = []
113    foreach(m, invoker.modules) {
114      deps += [ m ]
115    }
116    if (defined(invoker.deps)) {
117      deps += invoker.deps
118    }
119  }
120  config("public") {
121    configs = []
122    foreach(m, invoker.modules) {
123      configs += [ "$m:public" ]
124    }
125    if (defined(invoker.configs)) {
126      configs += invoker.configs
127    }
128  }
129}
130
131KERNEL_BASE_INCLUDE_DIRS = [
132  "$OSTOPDIR/arch/include",
133  "$OSTOPDIR/config",
134  "$OSTOPDIR/core/ipc/include",
135  "$OSTOPDIR/core/kernel/include",
136  "$OSTOPDIR/mem/include",
137  "$OSTOPDIR/om/include",
138  "$OSTOPDIR/utility/lib/include",
139]
140
141KERNEL_BASE_SOURCES = [
142  "$OSTOPDIR/config/prt_config.c",
143  "$OSTOPDIR/core/kernel/irq/prt_irq.c",
144  "$OSTOPDIR/core/kernel/kexc/prt_kexc.c",
145  "$OSTOPDIR/core/kernel/sys/prt_sys.c",
146  "$OSTOPDIR/core/kernel/sys/prt_sys_init.c",
147  "$OSTOPDIR/core/kernel/sys/prt_sys_time.c",
148  "$OSTOPDIR/core/kernel/task/prt_amp_task.c",
149  "$OSTOPDIR/core/kernel/task/prt_amp_task_del.c",
150  "$OSTOPDIR/core/kernel/task/prt_amp_task_init.c",
151  "$OSTOPDIR/core/kernel/task/prt_amp_task_minor.c",
152  "$OSTOPDIR/core/kernel/task/prt_task.c",
153  "$OSTOPDIR/core/kernel/task/prt_task_attrib.c",
154  "$OSTOPDIR/core/kernel/task/prt_task_del.c",
155  "$OSTOPDIR/core/kernel/task/prt_task_global.c",
156  "$OSTOPDIR/core/kernel/task/prt_task_info.c",
157  "$OSTOPDIR/core/kernel/task/prt_task_init.c",
158  "$OSTOPDIR/core/kernel/task/prt_task_minor.c",
159  "$OSTOPDIR/core/kernel/task/prt_task_priority.c",
160  "$OSTOPDIR/core/kernel/task/prt_task_sem.c",
161  "$OSTOPDIR/core/kernel/task/prt_taskself_id.c",
162  "$OSTOPDIR/core/kernel/tick/prt_tick.c",
163  "$OSTOPDIR/core/kernel/tick/prt_tick_init.c",
164  "$OSTOPDIR/core/kernel/timer/prt_timer.c",
165  "$OSTOPDIR/core/kernel/timer/prt_timer_minor.c",
166]
167
168KERNEL_SWTMR_SOURCES = [
169  "$OSTOPDIR/core/kernel/timer/swtmr/prt_swtmr.c",
170  "$OSTOPDIR/core/kernel/timer/swtmr/prt_swtmr_init.c",
171  "$OSTOPDIR/core/kernel/timer/swtmr/prt_swtmr_minor.c",
172]
173
174KERNEL_IPC_EVENT_SOURCES = [ "$OSTOPDIR/core/ipc/event/prt_event.c" ]
175
176KERNEL_IPC_QUEUE_SOURCES = [
177  "$OSTOPDIR/core/ipc/queue/prt_queue.c",
178  "$OSTOPDIR/core/ipc/queue/prt_queue_del.c",
179  "$OSTOPDIR/core/ipc/queue/prt_queue_init.c",
180  "$OSTOPDIR/core/ipc/queue/prt_queue_minor.c",
181]
182
183KERNEL_IPC_SEM_SOURCES = [
184  "$OSTOPDIR/core/ipc/sem/prt_sem.c",
185  "$OSTOPDIR/core/ipc/sem/prt_sem_init.c",
186  "$OSTOPDIR/core/ipc/sem/prt_sem_minor.c",
187]
188
189KERNEL_MEM_SOURCES = [
190  "$OSTOPDIR/mem/prt_mem.c",
191  "$OSTOPDIR/mem/fsc/prt_fscmem.c",
192]
193
194KERNEL_OM_SOURCES = [
195  "$OSTOPDIR/om/err/prt_err.c",
196  "$OSTOPDIR/om/err/prt_err_init.c",
197  "$OSTOPDIR/om/hook/prt_hook_init.c",
198]
199
200KERNEL_OM_CPUP_SOURCES = [
201  "$OSTOPDIR/om/cpup/prt_cpup.c",
202  "$OSTOPDIR/om/cpup/prt_cpup_minor.c",
203  "$OSTOPDIR/om/cpup/prt_cpup_thread.c",
204  "$OSTOPDIR/om/cpup/prt_cpup_thread_64.c",
205  "$OSTOPDIR/om/cpup/prt_cpup_thread_init.c",
206  "$OSTOPDIR/om/cpup/prt_cpup_warn.c",
207]
208
209KERNEL_SECURITY_SOURCES = [ "$OSTOPDIR/security/rnd/prt_rnd_set.c" ]
210
211KERNEL_UTILITY_SOURCES = [
212  "$OSTOPDIR/utility/lib/prt_lib_math64.c",
213  "$OSTOPDIR/utility/lib/prt_lib_version.c",
214]
215
216KERNEL_FS_INCLUDE_DIRS = [
217  "$OSTOPDIR/fs/porting",
218  "$OSTOPDIR/fs/vfs",
219  "$OSTOPDIR/fs/littlefs",
220]
221
222KERNEL_FS_SOURCES = [
223  "$OSTOPDIR/fs/fs.c",
224  "$OSTOPDIR/fs/vfs/vfs_files.c",
225  "$OSTOPDIR/fs/vfs/vfs_fs.c",
226  "$OSTOPDIR/fs/vfs/vfs_init.c",
227  "$OSTOPDIR/fs/vfs/vfs_maps.c",
228  "$OSTOPDIR/fs/vfs/vfs_mount.c",
229  "$OSTOPDIR/fs/vfs/vfs_partition.c",
230  "$OSTOPDIR/fs/littlefs/lfs_adapter.c",
231]
232
233KERNEL_LWIP_INCLUDE_DIRS = [ "$OSTOPDIR/net/lwip-2.1/include" ]
234
235KERNEL_LWIP_SOURCES = [
236  "$OSTOPDIR/net/lwip-2.1/src/driverif.c",
237  "$OSTOPDIR/net/lwip-2.1/src/netdb.c",
238  "$OSTOPDIR/net/lwip-2.1/src/sockets.c",
239  "$OSTOPDIR/net/lwip-2.1/src/sys_arch.c",
240  "$OSTOPDIR/net/lwip-2.1/enhancement/src/fixme.c",
241  "$OSTOPDIR/net/lwip-2.1/enhancement/src/lwip_ifaddrs.c",
242]
243
244ARCH_ARMVM7_M_SOURCES = [
245  "$OSTOPDIR/arch/cpu/armv7-m/common/boot/prt_hw_boot.c",
246  "$OSTOPDIR/arch/cpu/armv7-m/common/exc/prt_exc.c",
247  "$OSTOPDIR/arch/cpu/armv7-m/common/hwi/prt_hwi.c",
248  "$OSTOPDIR/arch/cpu/armv7-m/common/hwi/prt_vi_dispatch.c",
249  "$OSTOPDIR/arch/cpu/armv7-m/common/tick/prt_hw_tick.c",
250  "$OSTOPDIR/arch/cpu/armv7-m/common/tick/prt_hw_tick_minor.c",
251  "$OSTOPDIR/arch/cpu/armv7-m/common/prt_port.c",
252]
253
254ARCH_ARMVM7_M_INCLUDE_DIRS = [ "$OSTOPDIR/arch/cpu/armv7-m/common" ]
255
256ARCH_CORTEX_M4_SOURCES = [
257  "$OSTOPDIR/arch/cpu/armv7-m/cortex-m4/prt_dispatch.S",
258  "$OSTOPDIR/arch/cpu/armv7-m/cortex-m4/prt_div64.c",
259  "$OSTOPDIR/arch/cpu/armv7-m/cortex-m4/prt_hw.S",
260  "$OSTOPDIR/arch/cpu/armv7-m/cortex-m4/prt_hw_exc.S",
261  "$OSTOPDIR/arch/cpu/armv7-m/cortex-m4/prt_vector.S",
262]
263
264ARCH_CORTEX_M4_INCLUDE_DIRS = [ "$OSTOPDIR/arch/cpu/armv7-m/cortex-m4" ]
265
266set_defaults("kernel_module") {
267  configs = [
268    "//kernel/uniproton:os_config",
269    "//kernel/uniproton:kernel_config",
270    "//kernel/uniproton:public",
271  ]
272  visibility = [
273    ":*",
274    "..:*",
275    "../..:*",
276    "//kernel/uniproton:*",
277  ]
278}
279