• 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")
14import("//build/ohos.gni")
15import("//third_party/littlefs/littlefs.gni")
16import("//third_party/lwip/lwip.gni")
17import("uniproton.gni")
18
19declare_args() {
20  uniproton_name = "OHOS_Image"
21  HAVE_DEVICE_SDK = true
22}
23
24arch_cflags = []
25cc = "$ohos_current_cc_command " + string_join(" ", arch_cflags)
26
27config("arch_config") {
28  cflags = arch_cflags
29  ldflags = cflags
30  asmflags = cflags
31}
32
33config("kconfig_config") {
34  cflags = [
35    "-imacros",
36    "$MENUCONFIG_H",
37  ]
38  asmflags = cflags
39  cflags_cc = cflags
40}
41
42config("kernel_config") {
43  include_dirs = [
44    "$OSTOPDIR/include/uapi",
45    "//third_party/bounds_checking_function/include",
46  ]
47  if (defined(OS_ARCH_ARMV7_M)) {
48    include_dirs += ARCH_ARMVM7_M_INCLUDE_DIRS
49  }
50}
51
52config("strong_waring_flag") {
53  base_flags = [
54    "-Wunused",
55    "-Wredundant-decls",
56    "-Wfloat-conversion",
57    "-Wwrite-strings",
58    "-Wunused-macros",
59    "-Wswitch-default",
60    "-Wshift-overflow=2",
61    "-Wmissing-include-dirs",
62    "-Wlogical-op",
63    "-Wformat-security",
64    "-Wvla",
65    "-Wframe-larger-than=4096",
66    "-Wduplicated-cond",
67    "-Wdisabled-optimization",
68    "-Wduplicated-branches",
69    "-Wignored-qualifiers",
70    "-Wimplicit-fallthrough=3",
71    "-Wpointer-arith",
72    "-Wshift-negative-value",
73    "-Wsign-compare",
74    "-Wtype-limits",
75    "-Wcast-qual",
76    "-Wundef",
77    "-Wpacked",
78    "-Wstack-usage=2048",
79  ]
80
81  cflags = base_flags
82  cflags += [
83    "-Wnested-externs",
84    "-Wjump-misses-init",
85    "-Wbad-function-cast",
86    "-Wold-style-definition",
87    "-Wstrict-prototypes",
88  ]
89  cflags_cc = base_flags
90}
91
92config("warn_config") {
93  cflags = [
94    "-Wall",
95    "-Werror",
96    "-Wextra",
97    "-Wformat=2",
98    "-Wfloat-equal",
99    "-Wshadow",
100    "-Wtrampolines",
101    "-Wdate-time",
102  ]
103
104  cflags_cc = cflags
105}
106
107config("stdinc_config") {
108  std_include = exec_script("//build/lite/run_shell_cmd.py",
109                            [ "$cc -print-file-name=include" ],
110                            "trim string")
111  cflags = [
112    "-isystem",
113    std_include,
114  ]
115  asmflags = cflags
116}
117
118config("ssp_config") {
119  cflags = []
120  if (defined(CC_STACKPROTECTOR_ALL)) {
121    cflags += [ "-fstack-protector-all" ]
122  } else if (defined(CC_STACKPROTECTOR_STRONG)) {
123    cflags += [ "-fstack-protector-strong" ]
124  } else if (defined(CC_STACKPROTECTOR)) {
125    cflags += [
126      "-fstack-protector",
127      "--param",
128      "ssp-buffer-size=4",
129    ]
130  } else {
131    cflags += [ "-fno-stack-protector" ]
132  }
133  asmflags = cflags
134}
135
136config("misc_config") {
137  cflags = [
138    "-fno-pic",
139    "-fno-builtin",
140    "-fms-extensions",
141    "-fno-strict-aliasing",
142    "-fno-common",
143    "-fsigned-char",
144    "-ffunction-sections",
145    "-fdata-sections",
146    "-fno-exceptions",
147    "-fno-omit-frame-pointer",
148  ]
149
150  asmflags = cflags
151  asmflags += [ "-DCLZ=CLZ" ]
152}
153
154config("os_config") {
155  configs = [
156    ":arch_config",
157    ":stdinc_config",
158    ":ssp_config",
159
160    #":warn_config",
161    #":strong_waring_flag",
162    ":misc_config",
163  ]
164
165  configs += [ ":kernel_config" ]
166  if (HAVE_DEVICE_SDK) {
167    configs += [ "$device_path:public" ]
168  }
169}
170
171config("public") {
172  include_dirs = [
173    "src/arch/include",
174    "src/core/kernel/include",
175  ]
176}
177
178ohos_static_library("notice") {
179  license_file = "./NOTICE"
180
181  subsystem_name = "kernel"
182  part_name = "uniproton"
183}
184
185static_library("libkernel") {
186  include_dirs = KERNEL_BASE_INCLUDE_DIRS
187  sources = KERNEL_BASE_SOURCES
188
189  if (defined(OS_OPTION_EVENT)) {
190    sources += KERNEL_IPC_EVENT_SOURCES
191  }
192  if (defined(OS_OPTION_QUEUE)) {
193    sources += KERNEL_IPC_QUEUE_SOURCES
194  }
195  if (defined(INTERNAL_OS_SWTMR)) {
196    sources += KERNEL_SWTMR_SOURCES
197  }
198  sources += KERNEL_IPC_SEM_SOURCES
199  sources += KERNEL_MEM_SOURCES
200  sources += KERNEL_OM_SOURCES
201  if (defined(OS_OPTION_CPUP)) {
202    sources += KERNEL_OM_CPUP_SOURCES
203  }
204  sources += KERNEL_SECURITY_SOURCES
205  sources += KERNEL_UTILITY_SOURCES
206
207  if (defined(OS_SUPPORT_FS)) {
208    sources += KERNEL_FS_SOURCES + LITTLEFS_SRC_FILES_FOR_KERNEL_MODULE
209    include_dirs += KERNEL_FS_INCLUDE_DIRS + LITTLEFS_INCLUDE_DIRS
210  }
211
212  if (defined(OS_SUPPORT_NET)) {
213    sources += KERNEL_LWIP_SOURCES + LWIPNOAPPSFILES
214    include_dirs += KERNEL_LWIP_INCLUDE_DIRS + LWIP_INCLUDE_DIRS
215  }
216
217  if (defined(OS_ARCH_ARMV7_M)) {
218    sources += ARCH_ARMVM7_M_SOURCES
219    if ("$board_cpu" == "cortex-m4") {
220      sources += ARCH_CORTEX_M4_SOURCES
221      include_dirs += ARCH_CORTEX_M4_INCLUDE_DIRS
222    }
223  }
224
225  configs += [ ":os_config" ]
226
227  deps = [ "//third_party/bounds_checking_function:libsec_static" ]
228  deps += [ "//third_party/musl/porting/uniproton/kernel:kernel" ]
229  if (defined(DRIVERS_HDF)) {
230    deps += [ HDFTOPDIR ]
231  }
232}
233
234group("kernel") {
235  deps = [
236    ":libkernel",
237    ":notice",
238  ]
239}
240
241executable("uniproton") {
242  configs += [ ":os_config" ]
243
244  ldflags = [
245    "-static",
246    "-Wl,--gc-sections",
247    "-Wl,-Map=$uniproton_name.map",
248  ]
249
250  output_dir = target_out_dir
251
252  deps = [ "//build/lite:ohos" ]
253
254  if (HAVE_DEVICE_SDK) {
255    deps += [
256      "$device_path:device",
257      "$product_path:$product",
258    ]
259  }
260}
261
262copy("copy_image") {
263  deps = [ ":uniproton" ]
264  sources = [ "$target_out_dir/unstripped/bin/uniproton" ]
265  outputs = [ "$root_out_dir/$uniproton_name" ]
266}
267
268build_ext_component("build_kernel_image") {
269  deps = [ ":copy_image" ]
270  exec_path = rebase_path(root_out_dir)
271
272  objcopy = "${compile_prefix}objcopy$toolchain_cmd_suffix"
273  objdump = "${compile_prefix}objdump$toolchain_cmd_suffix"
274
275  command = "$objcopy -O binary $uniproton_name $uniproton_name.bin"
276  command += " && sh -c '$objdump -t $uniproton_name | sort >$uniproton_name.sym.sorted'"
277  command += " && sh -c '$objdump -d $uniproton_name >$uniproton_name.asm'"
278}
279