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 | |
| 15 | template("linux_kernel") { |
| 16 | # TODO: target has no "sources" |
| 17 | |
| 18 | # Args to build/make.py to start the Linux build. |
| 19 | shared_args = [ |
| 20 | "--directory", |
| 21 | rebase_path(invoker.kernel_dir), |
| 22 | |
| 23 | # TODO: Build with toolchain cc instead of a hardcoded one. |
| 24 | "CC=" + rebase_path("//prebuilts/linux-x64/clang/bin/clang"), |
| 25 | "ARCH=arm64", |
| 26 | "CROSS_COMPILE=aarch64-linux-gnu-", |
| 27 | |
| 28 | # Build out-of-tree in `target_out_dir`. |
| 29 | "O=" + rebase_path(target_out_dir), |
| 30 | |
| 31 | # TODO: Remove/replace. |
| 32 | "-j24", |
| 33 | ] |
| 34 | |
| 35 | # Subtarget which runs `defconfig` and `modules_prepare`. Used by targets |
| 36 | # which do not require the whole kernel to have been built. |
| 37 | action("${target_name}__defconfig") { |
| 38 | script = "//build/make.py" |
| 39 | args = shared_args + [ |
| 40 | "defconfig", |
| 41 | "modules_prepare", |
| 42 | ] |
| 43 | |
| 44 | # We never use the output but GN requires each target to have one, and for |
| 45 | # its timestamp to change after a recompile. Use the .config file. |
| 46 | outputs = [ |
| 47 | "${target_out_dir}/.config", |
| 48 | ] |
| 49 | } |
| 50 | |
| 51 | action(target_name) { |
| 52 | script = "//build/make.py" |
| 53 | output_file = "${target_out_dir}/${target_name}.bin" |
| 54 | args = shared_args + [ |
| 55 | "--copy_out_file", |
| 56 | rebase_path("${target_out_dir}/arch/arm64/boot/Image"), |
| 57 | rebase_path(output_file), |
| 58 | ] |
| 59 | outputs = [ |
| 60 | output_file, |
| 61 | ] |
| 62 | deps = [ |
| 63 | ":${target_name}__defconfig", |
| 64 | ] |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | template("linux_kernel_module") { |
| 69 | # Out-of-tree modules cannot be built outside of their directory. |
| 70 | # So as to avoid parallel builds under different toolchains clashing, |
| 71 | # work around by copying source files to `target_out_dir`. |
| 72 | copy("${target_name}__copy_source") { |
| 73 | forward_variables_from(invoker, |
| 74 | [ |
| 75 | "sources", |
| 76 | "testonly", |
| 77 | ]) |
| 78 | outputs = [ |
| 79 | "${target_out_dir}/{{source_file_part}}", |
| 80 | ] |
| 81 | } |
| 82 | |
| 83 | action(target_name) { |
| 84 | forward_variables_from(invoker, [ "testonly" ]) |
| 85 | script = "//build/make.py" |
| 86 | args = [ |
| 87 | "--directory", |
| 88 | rebase_path(target_out_dir), |
| 89 | "HAFNIUM_PATH=" + rebase_path("//"), |
| 90 | "KERNEL_PATH=" + rebase_path(invoker.kernel_src_dir), |
| 91 | "O=" + |
| 92 | rebase_path(get_label_info(invoker.kernel_target, "target_out_dir")), |
| 93 | "CC=" + rebase_path("//prebuilts/linux-x64/clang/bin/clang"), |
| 94 | "ARCH=arm64", |
| 95 | "CROSS_COMPILE=aarch64-linux-gnu-", |
| 96 | ] |
| 97 | outputs = [ |
| 98 | "${target_out_dir}/${invoker.module_name}.ko", |
| 99 | ] |
| 100 | deps = [ |
| 101 | ":${target_name}__copy_source", |
| 102 | "${invoker.kernel_target}__defconfig", |
| 103 | ] |
| 104 | } |
| 105 | } |