| import("//build/arch/common.gni") |
| |
| template("image_binary") { |
| assert(defined(invoker.image_name), |
| "image_binary() must specify a \"image_name\" value") |
| assert(defined(invoker.origin_address), |
| "image_binary() must specify a \"origin_address\" value") |
| |
| output_root = "" |
| if (defined(invoker.output_path)) { |
| output_root += "${invoker.output_path}/" |
| } |
| output_root += invoker.image_name |
| |
| # Link objects together |
| executable("${target_name}__elf") { |
| forward_variables_from(invoker, |
| [ |
| "cflags", |
| "cflags_c", |
| "defines", |
| "deps", |
| "public_deps", |
| "sources", |
| "testonly", |
| ]) |
| output_name = "${output_root}.elf" |
| inputs = [ |
| rebase_path("//build/image/image.ld"), |
| ] |
| ldflags = [ |
| "-pie", |
| "-T", |
| rebase_path("//build/image/image.ld"), |
| "--defsym=ORIGIN_ADDRESS=${invoker.origin_address}", |
| ] |
| visibility = [ ":${invoker.target_name}" ] |
| } |
| |
| action(target_name) { |
| forward_variables_from(invoker, [ "testonly" ]) |
| |
| file_root = "${root_out_dir}/${output_root}" |
| elf_file = "${file_root}.elf" |
| bin_file = "${file_root}.bin" |
| |
| script = "//build/image/convert_to_binary.py" |
| deps = [ |
| ":${target_name}__elf", |
| ] |
| args = [ |
| "--tool_prefix", |
| arch_tool_prefix, |
| "--input", |
| rebase_path(elf_file), |
| "--output", |
| rebase_path(bin_file), |
| ] |
| outputs = [ |
| bin_file, |
| ] |
| } |
| } |
| |
| # Helper to build a hypervisor image |
| template("hypervisor") { |
| image_binary(target_name) { |
| forward_variables_from(invoker, |
| [ |
| "cflags", |
| "cflags_c", |
| "defines", |
| "deps", |
| "public_deps", |
| "sources", |
| "testonly", |
| ]) |
| image_name = target_name |
| origin_address = arch_hypervisor_origin_address |
| } |
| } |
| |
| # Helper to build a virtual machine kernel |
| template("vm_kernel") { |
| image_binary(target_name) { |
| forward_variables_from(invoker, |
| [ |
| "cflags", |
| "cflags_c", |
| "defines", |
| "deps", |
| "public_deps", |
| "sources", |
| "testonly", |
| ]) |
| output_path = "vm" |
| image_name = target_name |
| origin_address = "0x1000" |
| } |
| } |