• 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
171ohos_static_library("notice") {
172  license_file = "./NOTICE"
173}
174
175static_library("libkernel") {
176  include_dirs = KERNEL_BASE_INCLUDE_DIRS
177  sources = KERNEL_BASE_SOURCES
178
179  if (defined(OS_OPTION_EVENT)) {
180    sources += KERNEL_IPC_EVENT_SOURCES
181  }
182  if (defined(OS_OPTION_QUEUE)) {
183    sources += KERNEL_IPC_QUEUE_SOURCES
184  }
185  if (defined(INTERNAL_OS_SWTMR)) {
186    sources += KERNEL_SWTMR_SOURCES
187  }
188  sources += KERNEL_IPC_SEM_SOURCES
189  sources += KERNEL_MEM_SOURCES
190  sources += KERNEL_OM_SOURCES
191  if (defined(OS_OPTION_CPUP)) {
192    sources += KERNEL_OM_CPUP_SOURCES
193  }
194  sources += KERNEL_SECURITY_SOURCES
195  sources += KERNEL_UTILITY_SOURCES
196
197  if (defined(OS_SUPPORT_FS)) {
198    sources += KERNEL_FS_SOURCES + LITTLEFS_SRC_FILES_FOR_KERNEL_MODULE
199    include_dirs += KERNEL_FS_INCLUDE_DIRS + LITTLEFS_INCLUDE_DIRS
200  }
201
202  if (defined(OS_SUPPORT_NET)) {
203    sources += KERNEL_LWIP_SOURCES + LWIPNOAPPSFILES
204    include_dirs += KERNEL_LWIP_INCLUDE_DIRS + LWIP_INCLUDE_DIRS
205  }
206
207  if (defined(OS_ARCH_ARMV7_M)) {
208    sources += ARCH_ARMVM7_M_SOURCES
209    if ("$board_cpu" == "cortex-m4") {
210      sources += ARCH_CORTEX_M4_SOURCES
211      include_dirs += ARCH_CORTEX_M4_INCLUDE_DIRS
212    }
213  }
214
215  configs += [ ":os_config" ]
216
217  deps = [ "//third_party/bounds_checking_function:libsec_static" ]
218  deps += [ "//third_party/musl/porting/uniproton/kernel:kernel" ]
219}
220
221group("kernel") {
222  deps = [
223    ":libkernel",
224    ":notice",
225  ]
226}
227
228executable("uniproton") {
229  configs += [ ":os_config" ]
230
231  ldflags = [
232    "-static",
233    "-Wl,--gc-sections",
234    "-Wl,-Map=$uniproton_name.map",
235  ]
236
237  output_dir = target_out_dir
238
239  deps = [ "//build/lite:ohos" ]
240
241  if (HAVE_DEVICE_SDK) {
242    deps += [
243      "$device_path:device",
244      "$product_path:$product",
245    ]
246  }
247}
248
249copy("copy_image") {
250  deps = [ ":uniproton" ]
251  sources = [ "$target_out_dir/unstripped/bin/uniproton" ]
252  outputs = [ "$root_out_dir/$uniproton_name" ]
253}
254
255build_ext_component("build_kernel_image") {
256  deps = [ ":copy_image" ]
257  exec_path = rebase_path(root_out_dir)
258
259  objcopy = "${compile_prefix}objcopy$toolchain_cmd_suffix"
260  objdump = "${compile_prefix}objdump$toolchain_cmd_suffix"
261
262  command = "$objcopy -O binary $uniproton_name $uniproton_name.bin"
263  command += " && sh -c '$objdump -t $uniproton_name | sort >$uniproton_name.sym.sorted'"
264  command += " && sh -c '$objdump -d $uniproton_name >$uniproton_name.asm'"
265}
266