David Brazdil | 3f509e0 | 2019-07-01 12:42:25 +0100 | [diff] [blame] | 1 | # Copyright 2019 The Hafnium Authors. |
| 2 | # |
Andrew Walbran | e959ec1 | 2020-06-17 15:01:09 +0100 | [diff] [blame] | 3 | # Use of this source code is governed by a BSD-style |
| 4 | # license that can be found in the LICENSE file or at |
| 5 | # https://opensource.org/licenses/BSD-3-Clause. |
David Brazdil | 3f509e0 | 2019-07-01 12:42:25 +0100 | [diff] [blame] | 6 | |
David Brazdil | b4802bc | 2019-07-30 12:39:41 +0100 | [diff] [blame] | 7 | template("source_dir") { |
| 8 | action("${target_name}") { |
| 9 | depfile = "${target_out_dir}/${target_name}.d" |
Olivier Deprez | 306d781 | 2023-02-02 09:51:10 +0100 | [diff] [blame] | 10 | outputs = [ "$target_out_dir/${target_name}.script.stamp" ] |
David Brazdil | b4802bc | 2019-07-30 12:39:41 +0100 | [diff] [blame] | 11 | |
| 12 | script = "//build/linux/gen_depfile.py" |
| 13 | args = [ |
| 14 | rebase_path(invoker.path, root_build_dir), |
| 15 | rebase_path(outputs[0], root_build_dir), |
| 16 | rebase_path(depfile, root_build_dir), |
| 17 | ] |
| 18 | } |
| 19 | } |
| 20 | |
David Brazdil | e7a5a1f | 2019-08-09 18:48:38 +0100 | [diff] [blame] | 21 | template("source_dir_copy") { |
| 22 | source_dir_target = "${target_name}__source_dir" |
| 23 | |
| 24 | source_dir(source_dir_target) { |
| 25 | path = invoker.path |
| 26 | } |
| 27 | |
| 28 | action("${target_name}") { |
| 29 | script = "//build/linux/copy_dirs.py" |
Olivier Deprez | 306d781 | 2023-02-02 09:51:10 +0100 | [diff] [blame] | 30 | outputs = [ "$target_out_dir/${target_name}.script.stamp" ] |
David Brazdil | e7a5a1f | 2019-08-09 18:48:38 +0100 | [diff] [blame] | 31 | args = [ |
| 32 | rebase_path(invoker.path), |
| 33 | rebase_path(target_out_dir), |
| 34 | rebase_path(outputs[0]), |
| 35 | ] |
Olivier Deprez | 306d781 | 2023-02-02 09:51:10 +0100 | [diff] [blame] | 36 | deps = [ ":${source_dir_target}" ] |
David Brazdil | e7a5a1f | 2019-08-09 18:48:38 +0100 | [diff] [blame] | 37 | } |
| 38 | } |
| 39 | |
David Brazdil | 3f509e0 | 2019-07-01 12:42:25 +0100 | [diff] [blame] | 40 | template("linux_kernel") { |
David Brazdil | b4802bc | 2019-07-30 12:39:41 +0100 | [diff] [blame] | 41 | source_target = "${target_name}__source" |
| 42 | defconfig_target = "${target_name}__defconfig" |
David Brazdil | 4b0e111 | 2019-07-30 18:28:01 +0100 | [diff] [blame] | 43 | prebuilt_target = "${target_name}__prebuilt" |
David Brazdil | 3f509e0 | 2019-07-01 12:42:25 +0100 | [diff] [blame] | 44 | |
David Brazdil | 33cc5c0 | 2019-12-10 10:44:14 +0000 | [diff] [blame] | 45 | kernel_dir = "./" |
| 46 | |
David Brazdil | 3f509e0 | 2019-07-01 12:42:25 +0100 | [diff] [blame] | 47 | # Args to build/make.py to start the Linux build. |
| 48 | shared_args = [ |
| 49 | "--directory", |
David Brazdil | 33cc5c0 | 2019-12-10 10:44:14 +0000 | [diff] [blame] | 50 | rebase_path(kernel_dir), |
David Brazdil | 3f509e0 | 2019-07-01 12:42:25 +0100 | [diff] [blame] | 51 | |
| 52 | # TODO: Build with toolchain cc instead of a hardcoded one. |
David Brazdil | 3f509e0 | 2019-07-01 12:42:25 +0100 | [diff] [blame] | 53 | "ARCH=arm64", |
Olivier Deprez | c16b0ec | 2021-09-23 11:39:39 +0200 | [diff] [blame] | 54 | "LLVM=1", |
| 55 | "LLVM_IAS=1", |
David Brazdil | 3f509e0 | 2019-07-01 12:42:25 +0100 | [diff] [blame] | 56 | "CROSS_COMPILE=aarch64-linux-gnu-", |
| 57 | |
| 58 | # Build out-of-tree in `target_out_dir`. |
| 59 | "O=" + rebase_path(target_out_dir), |
| 60 | |
Olivier Deprez | c16b0ec | 2021-09-23 11:39:39 +0200 | [diff] [blame] | 61 | # TODO: assess if this setting is really required because the ninja |
| 62 | # top level invocation already cares about parallel build. |
David Brazdil | 3f509e0 | 2019-07-01 12:42:25 +0100 | [diff] [blame] | 63 | "-j24", |
| 64 | ] |
| 65 | |
David Brazdil | b4802bc | 2019-07-30 12:39:41 +0100 | [diff] [blame] | 66 | # Subtarget which generates a depfile with all files in the Linux tree |
| 67 | # and gets invalidated if any of them change. |
| 68 | source_dir(source_target) { |
David Brazdil | 33cc5c0 | 2019-12-10 10:44:14 +0000 | [diff] [blame] | 69 | path = kernel_dir |
David Brazdil | b4802bc | 2019-07-30 12:39:41 +0100 | [diff] [blame] | 70 | } |
| 71 | |
David Brazdil | 3f509e0 | 2019-07-01 12:42:25 +0100 | [diff] [blame] | 72 | # Subtarget which runs `defconfig` and `modules_prepare`. Used by targets |
| 73 | # which do not require the whole kernel to have been built. |
David Brazdil | b4802bc | 2019-07-30 12:39:41 +0100 | [diff] [blame] | 74 | action(defconfig_target) { |
David Brazdil | 3f509e0 | 2019-07-01 12:42:25 +0100 | [diff] [blame] | 75 | script = "//build/make.py" |
| 76 | args = shared_args + [ |
| 77 | "defconfig", |
| 78 | "modules_prepare", |
| 79 | ] |
| 80 | |
| 81 | # We never use the output but GN requires each target to have one, and for |
| 82 | # its timestamp to change after a recompile. Use the .config file. |
Olivier Deprez | 306d781 | 2023-02-02 09:51:10 +0100 | [diff] [blame] | 83 | outputs = [ "${target_out_dir}/.config" ] |
| 84 | deps = [ ":${source_target}" ] |
David Brazdil | 3f509e0 | 2019-07-01 12:42:25 +0100 | [diff] [blame] | 85 | } |
| 86 | |
| 87 | action(target_name) { |
| 88 | script = "//build/make.py" |
| 89 | output_file = "${target_out_dir}/${target_name}.bin" |
| 90 | args = shared_args + [ |
| 91 | "--copy_out_file", |
| 92 | rebase_path("${target_out_dir}/arch/arm64/boot/Image"), |
| 93 | rebase_path(output_file), |
| 94 | ] |
Olivier Deprez | 306d781 | 2023-02-02 09:51:10 +0100 | [diff] [blame] | 95 | outputs = [ output_file ] |
David Brazdil | 3f509e0 | 2019-07-01 12:42:25 +0100 | [diff] [blame] | 96 | deps = [ |
David Brazdil | b4802bc | 2019-07-30 12:39:41 +0100 | [diff] [blame] | 97 | ":${defconfig_target}", |
| 98 | ":${source_target}", |
David Brazdil | 3f509e0 | 2019-07-01 12:42:25 +0100 | [diff] [blame] | 99 | ] |
| 100 | } |
David Brazdil | 4b0e111 | 2019-07-30 18:28:01 +0100 | [diff] [blame] | 101 | |
| 102 | # Subtarget for a prebuilt image, if defined. |
| 103 | if (defined(invoker.prebuilt)) { |
| 104 | copy(prebuilt_target) { |
Olivier Deprez | 306d781 | 2023-02-02 09:51:10 +0100 | [diff] [blame] | 105 | sources = [ invoker.prebuilt ] |
| 106 | outputs = [ "${target_out_dir}/${prebuilt_target}.bin" ] |
David Brazdil | 4b0e111 | 2019-07-30 18:28:01 +0100 | [diff] [blame] | 107 | } |
| 108 | } |
David Brazdil | 3f509e0 | 2019-07-01 12:42:25 +0100 | [diff] [blame] | 109 | } |
| 110 | |
| 111 | template("linux_kernel_module") { |
| 112 | # Out-of-tree modules cannot be built outside of their directory. |
| 113 | # So as to avoid parallel builds under different toolchains clashing, |
| 114 | # work around by copying source files to `target_out_dir`. |
David Brazdil | e7a5a1f | 2019-08-09 18:48:38 +0100 | [diff] [blame] | 115 | |
| 116 | source_target = "${target_name}__source" |
| 117 | |
David Brazdil | cb92ba1 | 2019-12-23 14:15:08 +0000 | [diff] [blame] | 118 | module_dir = "./" |
| 119 | |
David Brazdil | e7a5a1f | 2019-08-09 18:48:38 +0100 | [diff] [blame] | 120 | source_dir_copy(source_target) { |
David Brazdil | cb92ba1 | 2019-12-23 14:15:08 +0000 | [diff] [blame] | 121 | path = module_dir |
David Brazdil | 3f509e0 | 2019-07-01 12:42:25 +0100 | [diff] [blame] | 122 | } |
| 123 | |
| 124 | action(target_name) { |
| 125 | forward_variables_from(invoker, [ "testonly" ]) |
| 126 | script = "//build/make.py" |
| 127 | args = [ |
| 128 | "--directory", |
| 129 | rebase_path(target_out_dir), |
| 130 | "HAFNIUM_PATH=" + rebase_path("//"), |
David Brazdil | e7a5a1f | 2019-08-09 18:48:38 +0100 | [diff] [blame] | 131 | "KERNEL_PATH=" + rebase_path(invoker.kernel_dir), |
David Brazdil | 3f509e0 | 2019-07-01 12:42:25 +0100 | [diff] [blame] | 132 | "O=" + |
| 133 | rebase_path(get_label_info(invoker.kernel_target, "target_out_dir")), |
David Brazdil | 3f509e0 | 2019-07-01 12:42:25 +0100 | [diff] [blame] | 134 | "ARCH=arm64", |
Olivier Deprez | c16b0ec | 2021-09-23 11:39:39 +0200 | [diff] [blame] | 135 | "LLVM=1", |
| 136 | "LLVM_IAS=1", |
David Brazdil | 3f509e0 | 2019-07-01 12:42:25 +0100 | [diff] [blame] | 137 | "CROSS_COMPILE=aarch64-linux-gnu-", |
| 138 | ] |
Olivier Deprez | 306d781 | 2023-02-02 09:51:10 +0100 | [diff] [blame] | 139 | outputs = [ "${target_out_dir}/${invoker.module_name}.ko" ] |
David Brazdil | 3f509e0 | 2019-07-01 12:42:25 +0100 | [diff] [blame] | 140 | deps = [ |
David Brazdil | e7a5a1f | 2019-08-09 18:48:38 +0100 | [diff] [blame] | 141 | ":${source_target}", |
David Brazdil | 3f509e0 | 2019-07-01 12:42:25 +0100 | [diff] [blame] | 142 | "${invoker.kernel_target}__defconfig", |
| 143 | ] |
| 144 | } |
| 145 | } |