blob: b6758131e560ea42b24428749184ef240faeff1d [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 Brazdil3f509e02019-07-01 12:42:25 +010034
35 # Args to build/make.py to start the Linux build.
36 shared_args = [
37 "--directory",
38 rebase_path(invoker.kernel_dir),
39
40 # TODO: Build with toolchain cc instead of a hardcoded one.
41 "CC=" + rebase_path("//prebuilts/linux-x64/clang/bin/clang"),
42 "ARCH=arm64",
43 "CROSS_COMPILE=aarch64-linux-gnu-",
44
45 # Build out-of-tree in `target_out_dir`.
46 "O=" + rebase_path(target_out_dir),
47
48 # TODO: Remove/replace.
49 "-j24",
50 ]
51
David Brazdilb4802bc2019-07-30 12:39:41 +010052 # Subtarget which generates a depfile with all files in the Linux tree
53 # and gets invalidated if any of them change.
54 source_dir(source_target) {
55 path = invoker.kernel_dir
56 }
57
David Brazdil3f509e02019-07-01 12:42:25 +010058 # Subtarget which runs `defconfig` and `modules_prepare`. Used by targets
59 # which do not require the whole kernel to have been built.
David Brazdilb4802bc2019-07-30 12:39:41 +010060 action(defconfig_target) {
David Brazdil3f509e02019-07-01 12:42:25 +010061 script = "//build/make.py"
62 args = shared_args + [
63 "defconfig",
64 "modules_prepare",
65 ]
66
67 # We never use the output but GN requires each target to have one, and for
68 # its timestamp to change after a recompile. Use the .config file.
69 outputs = [
70 "${target_out_dir}/.config",
71 ]
David Brazdilb4802bc2019-07-30 12:39:41 +010072 deps = [
73 ":${source_target}",
74 ]
David Brazdil3f509e02019-07-01 12:42:25 +010075 }
76
77 action(target_name) {
78 script = "//build/make.py"
79 output_file = "${target_out_dir}/${target_name}.bin"
80 args = shared_args + [
81 "--copy_out_file",
82 rebase_path("${target_out_dir}/arch/arm64/boot/Image"),
83 rebase_path(output_file),
84 ]
85 outputs = [
86 output_file,
87 ]
88 deps = [
David Brazdilb4802bc2019-07-30 12:39:41 +010089 ":${defconfig_target}",
90 ":${source_target}",
David Brazdil3f509e02019-07-01 12:42:25 +010091 ]
92 }
93}
94
95template("linux_kernel_module") {
96 # Out-of-tree modules cannot be built outside of their directory.
97 # So as to avoid parallel builds under different toolchains clashing,
98 # work around by copying source files to `target_out_dir`.
99 copy("${target_name}__copy_source") {
100 forward_variables_from(invoker,
101 [
102 "sources",
103 "testonly",
104 ])
105 outputs = [
106 "${target_out_dir}/{{source_file_part}}",
107 ]
108 }
109
110 action(target_name) {
111 forward_variables_from(invoker, [ "testonly" ])
112 script = "//build/make.py"
113 args = [
114 "--directory",
115 rebase_path(target_out_dir),
116 "HAFNIUM_PATH=" + rebase_path("//"),
117 "KERNEL_PATH=" + rebase_path(invoker.kernel_src_dir),
118 "O=" +
119 rebase_path(get_label_info(invoker.kernel_target, "target_out_dir")),
120 "CC=" + rebase_path("//prebuilts/linux-x64/clang/bin/clang"),
121 "ARCH=arm64",
122 "CROSS_COMPILE=aarch64-linux-gnu-",
123 ]
124 outputs = [
125 "${target_out_dir}/${invoker.module_name}.ko",
126 ]
127 deps = [
128 ":${target_name}__copy_source",
129 "${invoker.kernel_target}__defconfig",
130 ]
131 }
132}