blob: 6ac0b8a7fbef475c51de4070e421fdc345f804b8 [file] [log] [blame]
David Brazdil3f509e02019-07-01 12:42:25 +01001# Copyright 2019 The Hafnium Authors.
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# https://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
David Brazdilb4802bc2019-07-30 12:39:41 +010015template("source_dir") {
16 action("${target_name}") {
17 depfile = "${target_out_dir}/${target_name}.d"
18 outputs = [
19 "$target_out_dir/${target_name}.script.stamp",
20 ]
21
22 script = "//build/linux/gen_depfile.py"
23 args = [
24 rebase_path(invoker.path, root_build_dir),
25 rebase_path(outputs[0], root_build_dir),
26 rebase_path(depfile, root_build_dir),
27 ]
28 }
29}
30
David Brazdil3f509e02019-07-01 12:42:25 +010031template("linux_kernel") {
David Brazdilb4802bc2019-07-30 12:39:41 +010032 source_target = "${target_name}__source"
33 defconfig_target = "${target_name}__defconfig"
David Brazdil4b0e1112019-07-30 18:28:01 +010034 prebuilt_target = "${target_name}__prebuilt"
David Brazdil3f509e02019-07-01 12:42:25 +010035
36 # Args to build/make.py to start the Linux build.
37 shared_args = [
38 "--directory",
39 rebase_path(invoker.kernel_dir),
40
41 # TODO: Build with toolchain cc instead of a hardcoded one.
42 "CC=" + rebase_path("//prebuilts/linux-x64/clang/bin/clang"),
43 "ARCH=arm64",
44 "CROSS_COMPILE=aarch64-linux-gnu-",
45
46 # Build out-of-tree in `target_out_dir`.
47 "O=" + rebase_path(target_out_dir),
48
49 # TODO: Remove/replace.
50 "-j24",
51 ]
52
David Brazdilb4802bc2019-07-30 12:39:41 +010053 # Subtarget which generates a depfile with all files in the Linux tree
54 # and gets invalidated if any of them change.
55 source_dir(source_target) {
56 path = invoker.kernel_dir
57 }
58
David Brazdil3f509e02019-07-01 12:42:25 +010059 # Subtarget which runs `defconfig` and `modules_prepare`. Used by targets
60 # which do not require the whole kernel to have been built.
David Brazdilb4802bc2019-07-30 12:39:41 +010061 action(defconfig_target) {
David Brazdil3f509e02019-07-01 12:42:25 +010062 script = "//build/make.py"
63 args = shared_args + [
64 "defconfig",
65 "modules_prepare",
66 ]
67
68 # We never use the output but GN requires each target to have one, and for
69 # its timestamp to change after a recompile. Use the .config file.
70 outputs = [
71 "${target_out_dir}/.config",
72 ]
David Brazdilb4802bc2019-07-30 12:39:41 +010073 deps = [
74 ":${source_target}",
75 ]
David Brazdil3f509e02019-07-01 12:42:25 +010076 }
77
78 action(target_name) {
79 script = "//build/make.py"
80 output_file = "${target_out_dir}/${target_name}.bin"
81 args = shared_args + [
82 "--copy_out_file",
83 rebase_path("${target_out_dir}/arch/arm64/boot/Image"),
84 rebase_path(output_file),
85 ]
86 outputs = [
87 output_file,
88 ]
89 deps = [
David Brazdilb4802bc2019-07-30 12:39:41 +010090 ":${defconfig_target}",
91 ":${source_target}",
David Brazdil3f509e02019-07-01 12:42:25 +010092 ]
93 }
David Brazdil4b0e1112019-07-30 18:28:01 +010094
95 # Subtarget for a prebuilt image, if defined.
96 if (defined(invoker.prebuilt)) {
97 copy(prebuilt_target) {
98 sources = [
99 invoker.prebuilt,
100 ]
101 outputs = [
102 "${target_out_dir}/${prebuilt_target}.bin",
103 ]
104 }
105 }
David Brazdil3f509e02019-07-01 12:42:25 +0100106}
107
108template("linux_kernel_module") {
109 # Out-of-tree modules cannot be built outside of their directory.
110 # So as to avoid parallel builds under different toolchains clashing,
111 # work around by copying source files to `target_out_dir`.
112 copy("${target_name}__copy_source") {
113 forward_variables_from(invoker,
114 [
115 "sources",
116 "testonly",
117 ])
118 outputs = [
119 "${target_out_dir}/{{source_file_part}}",
120 ]
121 }
122
123 action(target_name) {
124 forward_variables_from(invoker, [ "testonly" ])
125 script = "//build/make.py"
126 args = [
127 "--directory",
128 rebase_path(target_out_dir),
129 "HAFNIUM_PATH=" + rebase_path("//"),
130 "KERNEL_PATH=" + rebase_path(invoker.kernel_src_dir),
131 "O=" +
132 rebase_path(get_label_info(invoker.kernel_target, "target_out_dir")),
133 "CC=" + rebase_path("//prebuilts/linux-x64/clang/bin/clang"),
134 "ARCH=arm64",
135 "CROSS_COMPILE=aarch64-linux-gnu-",
136 ]
137 outputs = [
138 "${target_out_dir}/${invoker.module_name}.ko",
139 ]
140 deps = [
141 ":${target_name}__copy_source",
142 "${invoker.kernel_target}__defconfig",
143 ]
144 }
145}