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 | 3f509e0 | 2019-07-01 12:42:25 +0100 | [diff] [blame] | 31 | template("linux_kernel") { |
David Brazdil | b4802bc | 2019-07-30 12:39:41 +0100 | [diff] [blame] | 32 | source_target = "${target_name}__source" |
| 33 | defconfig_target = "${target_name}__defconfig" |
David Brazdil | 4b0e111 | 2019-07-30 18:28:01 +0100 | [diff] [blame^] | 34 | prebuilt_target = "${target_name}__prebuilt" |
David Brazdil | 3f509e0 | 2019-07-01 12:42:25 +0100 | [diff] [blame] | 35 | |
| 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 Brazdil | b4802bc | 2019-07-30 12:39:41 +0100 | [diff] [blame] | 53 | # 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 Brazdil | 3f509e0 | 2019-07-01 12:42:25 +0100 | [diff] [blame] | 59 | # Subtarget which runs `defconfig` and `modules_prepare`. Used by targets |
| 60 | # which do not require the whole kernel to have been built. |
David Brazdil | b4802bc | 2019-07-30 12:39:41 +0100 | [diff] [blame] | 61 | action(defconfig_target) { |
David Brazdil | 3f509e0 | 2019-07-01 12:42:25 +0100 | [diff] [blame] | 62 | 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 Brazdil | b4802bc | 2019-07-30 12:39:41 +0100 | [diff] [blame] | 73 | deps = [ |
| 74 | ":${source_target}", |
| 75 | ] |
David Brazdil | 3f509e0 | 2019-07-01 12:42:25 +0100 | [diff] [blame] | 76 | } |
| 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 Brazdil | b4802bc | 2019-07-30 12:39:41 +0100 | [diff] [blame] | 90 | ":${defconfig_target}", |
| 91 | ":${source_target}", |
David Brazdil | 3f509e0 | 2019-07-01 12:42:25 +0100 | [diff] [blame] | 92 | ] |
| 93 | } |
David Brazdil | 4b0e111 | 2019-07-30 18:28:01 +0100 | [diff] [blame^] | 94 | |
| 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 Brazdil | 3f509e0 | 2019-07-01 12:42:25 +0100 | [diff] [blame] | 106 | } |
| 107 | |
| 108 | template("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 | } |