David Brazdil | 3f509e0 | 2019-07-01 12:42:25 +0100 | [diff] [blame] | 1 | # 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 Brazdil | b4802bc | 2019-07-30 12:39:41 +0100 | [diff] [blame] | 15 | template("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 Brazdil | e7a5a1f | 2019-08-09 18:48:38 +0100 | [diff] [blame^] | 31 | template("source_dir_copy") { |
| 32 | source_dir_target = "${target_name}__source_dir" |
| 33 | |
| 34 | source_dir(source_dir_target) { |
| 35 | path = invoker.path |
| 36 | } |
| 37 | |
| 38 | action("${target_name}") { |
| 39 | script = "//build/linux/copy_dirs.py" |
| 40 | outputs = [ |
| 41 | "$target_out_dir/${target_name}.script.stamp", |
| 42 | ] |
| 43 | args = [ |
| 44 | rebase_path(invoker.path), |
| 45 | rebase_path(target_out_dir), |
| 46 | rebase_path(outputs[0]), |
| 47 | ] |
| 48 | deps = [ |
| 49 | ":${source_dir_target}", |
| 50 | ] |
| 51 | } |
| 52 | } |
| 53 | |
David Brazdil | 3f509e0 | 2019-07-01 12:42:25 +0100 | [diff] [blame] | 54 | template("linux_kernel") { |
David Brazdil | b4802bc | 2019-07-30 12:39:41 +0100 | [diff] [blame] | 55 | source_target = "${target_name}__source" |
| 56 | defconfig_target = "${target_name}__defconfig" |
David Brazdil | 4b0e111 | 2019-07-30 18:28:01 +0100 | [diff] [blame] | 57 | prebuilt_target = "${target_name}__prebuilt" |
David Brazdil | 3f509e0 | 2019-07-01 12:42:25 +0100 | [diff] [blame] | 58 | |
| 59 | # Args to build/make.py to start the Linux build. |
| 60 | shared_args = [ |
| 61 | "--directory", |
| 62 | rebase_path(invoker.kernel_dir), |
| 63 | |
| 64 | # TODO: Build with toolchain cc instead of a hardcoded one. |
| 65 | "CC=" + rebase_path("//prebuilts/linux-x64/clang/bin/clang"), |
| 66 | "ARCH=arm64", |
| 67 | "CROSS_COMPILE=aarch64-linux-gnu-", |
| 68 | |
| 69 | # Build out-of-tree in `target_out_dir`. |
| 70 | "O=" + rebase_path(target_out_dir), |
| 71 | |
| 72 | # TODO: Remove/replace. |
| 73 | "-j24", |
| 74 | ] |
| 75 | |
David Brazdil | b4802bc | 2019-07-30 12:39:41 +0100 | [diff] [blame] | 76 | # Subtarget which generates a depfile with all files in the Linux tree |
| 77 | # and gets invalidated if any of them change. |
| 78 | source_dir(source_target) { |
| 79 | path = invoker.kernel_dir |
| 80 | } |
| 81 | |
David Brazdil | 3f509e0 | 2019-07-01 12:42:25 +0100 | [diff] [blame] | 82 | # Subtarget which runs `defconfig` and `modules_prepare`. Used by targets |
| 83 | # which do not require the whole kernel to have been built. |
David Brazdil | b4802bc | 2019-07-30 12:39:41 +0100 | [diff] [blame] | 84 | action(defconfig_target) { |
David Brazdil | 3f509e0 | 2019-07-01 12:42:25 +0100 | [diff] [blame] | 85 | script = "//build/make.py" |
| 86 | args = shared_args + [ |
| 87 | "defconfig", |
| 88 | "modules_prepare", |
| 89 | ] |
| 90 | |
| 91 | # We never use the output but GN requires each target to have one, and for |
| 92 | # its timestamp to change after a recompile. Use the .config file. |
| 93 | outputs = [ |
| 94 | "${target_out_dir}/.config", |
| 95 | ] |
David Brazdil | b4802bc | 2019-07-30 12:39:41 +0100 | [diff] [blame] | 96 | deps = [ |
| 97 | ":${source_target}", |
| 98 | ] |
David Brazdil | 3f509e0 | 2019-07-01 12:42:25 +0100 | [diff] [blame] | 99 | } |
| 100 | |
| 101 | action(target_name) { |
| 102 | script = "//build/make.py" |
| 103 | output_file = "${target_out_dir}/${target_name}.bin" |
| 104 | args = shared_args + [ |
| 105 | "--copy_out_file", |
| 106 | rebase_path("${target_out_dir}/arch/arm64/boot/Image"), |
| 107 | rebase_path(output_file), |
| 108 | ] |
| 109 | outputs = [ |
| 110 | output_file, |
| 111 | ] |
| 112 | deps = [ |
David Brazdil | b4802bc | 2019-07-30 12:39:41 +0100 | [diff] [blame] | 113 | ":${defconfig_target}", |
| 114 | ":${source_target}", |
David Brazdil | 3f509e0 | 2019-07-01 12:42:25 +0100 | [diff] [blame] | 115 | ] |
| 116 | } |
David Brazdil | 4b0e111 | 2019-07-30 18:28:01 +0100 | [diff] [blame] | 117 | |
| 118 | # Subtarget for a prebuilt image, if defined. |
| 119 | if (defined(invoker.prebuilt)) { |
| 120 | copy(prebuilt_target) { |
| 121 | sources = [ |
| 122 | invoker.prebuilt, |
| 123 | ] |
| 124 | outputs = [ |
| 125 | "${target_out_dir}/${prebuilt_target}.bin", |
| 126 | ] |
| 127 | } |
| 128 | } |
David Brazdil | 3f509e0 | 2019-07-01 12:42:25 +0100 | [diff] [blame] | 129 | } |
| 130 | |
| 131 | template("linux_kernel_module") { |
| 132 | # Out-of-tree modules cannot be built outside of their directory. |
| 133 | # So as to avoid parallel builds under different toolchains clashing, |
| 134 | # work around by copying source files to `target_out_dir`. |
David Brazdil | e7a5a1f | 2019-08-09 18:48:38 +0100 | [diff] [blame^] | 135 | |
| 136 | source_target = "${target_name}__source" |
| 137 | |
| 138 | source_dir_copy(source_target) { |
| 139 | path = invoker.module_dir |
David Brazdil | 3f509e0 | 2019-07-01 12:42:25 +0100 | [diff] [blame] | 140 | } |
| 141 | |
| 142 | action(target_name) { |
| 143 | forward_variables_from(invoker, [ "testonly" ]) |
| 144 | script = "//build/make.py" |
| 145 | args = [ |
| 146 | "--directory", |
| 147 | rebase_path(target_out_dir), |
| 148 | "HAFNIUM_PATH=" + rebase_path("//"), |
David Brazdil | e7a5a1f | 2019-08-09 18:48:38 +0100 | [diff] [blame^] | 149 | "KERNEL_PATH=" + rebase_path(invoker.kernel_dir), |
David Brazdil | 3f509e0 | 2019-07-01 12:42:25 +0100 | [diff] [blame] | 150 | "O=" + |
| 151 | rebase_path(get_label_info(invoker.kernel_target, "target_out_dir")), |
| 152 | "CC=" + rebase_path("//prebuilts/linux-x64/clang/bin/clang"), |
| 153 | "ARCH=arm64", |
| 154 | "CROSS_COMPILE=aarch64-linux-gnu-", |
| 155 | ] |
| 156 | outputs = [ |
| 157 | "${target_out_dir}/${invoker.module_name}.ko", |
| 158 | ] |
| 159 | deps = [ |
David Brazdil | e7a5a1f | 2019-08-09 18:48:38 +0100 | [diff] [blame^] | 160 | ":${source_target}", |
David Brazdil | 3f509e0 | 2019-07-01 12:42:25 +0100 | [diff] [blame] | 161 | "${invoker.kernel_target}__defconfig", |
| 162 | ] |
| 163 | } |
| 164 | } |