| # Copyright 2019 The Fuchsia Authors. All rights reserved. |
| # Use of this source code is governed by a BSD-style license that can be |
| # found in the LICENSE file. |
| |
| import("$zx/public/gn/toolchain/c_utils.gni") |
| import("$zx/public/gn/toolchain/environment_redirect.gni") |
| |
| assert(current_cpu == "arm64") |
| |
| # The boot shims need to be compiled in the special environment for running |
| # in physical memory with the MMU disabled. |
| if (toolchain.environment == "physmem") { |
| source_set("common") { |
| visibility = [ ":*" ] |
| sources = [ |
| "boot-shim.S", |
| "debug.c", |
| "devicetree.c", |
| "util.c", |
| ] |
| deps = [ |
| "$zx/kernel/lib/libc/string", |
| ] |
| } |
| |
| config("boot_shim_config") { |
| visibility = [ ":*" ] |
| defines = [ "KERNEL_ALIGN=0x10000" ] |
| inputs = [ |
| "boot-shim.ld", |
| ] |
| ldflags = [ |
| "-Wl,--build-id=none", |
| "-Wl,-T," + rebase_path("boot-shim.ld", root_build_dir), |
| "-Wl,-defsym," + defines[0], |
| ] |
| } |
| } |
| |
| template("boot_shim") { |
| board = target_name |
| |
| if (toolchain.environment == "physmem") { |
| shim_name = "${board}-boot-shim" |
| |
| executable(shim_name) { |
| output_extension = "elf" |
| configs += [ ":boot_shim_config" ] |
| deps = [ |
| ":common", |
| "$zx/system/ulib/ddk:headers", |
| "$zx/system/ulib/libzbi", |
| ] |
| sources = [ |
| "${board}-uart.c", |
| "boot-shim.c", |
| ] |
| |
| # TODO(mcgrathr): Move these to ./$board-config.h and use a -D. |
| include_dirs = [ "$zx/kernel/target/arm64/board/$board" ] |
| } |
| |
| shim_rspfile = "$target_gen_dir/$shim_name.elf.rsp" |
| link_output_rspfile("$shim_name.elf.rsp") { |
| deps = [ |
| ":$shim_name", |
| ] |
| outputs = [ |
| shim_rspfile, |
| ] |
| } |
| |
| # The shim code should be purely position-independent code. |
| toolchain_utils_action("$shim_name-pure-check") { |
| visibility = [ ":*" ] |
| deps = [ |
| ":$shim_name", |
| ":$shim_name.elf.rsp", |
| ] |
| sources = [ |
| shim_rspfile, |
| ] |
| outputs = [ |
| "$target_out_dir/$shim_name.pure-stamp", |
| ] |
| script = "$zx/scripts/gen-kaslr-fixups.sh" |
| utils = [ |
| "readelf", |
| "objdump", |
| ] |
| args = [ |
| "--pure", |
| "@" + rebase_path(shim_rspfile, root_build_dir), |
| rebase_path(outputs[0], root_build_dir), |
| ] |
| } |
| |
| image_binary(board) { |
| forward_variables_from(invoker, |
| [ |
| "testonly", |
| "visibility", |
| ]) |
| deps = [ |
| ":$shim_name", |
| ":$shim_name-pure-check", |
| ] |
| output_dir = root_build_dir |
| output_name = shim_name |
| output_extension = "bin" |
| metadata = { |
| # For the //:images build_api_module(). |
| images = [ |
| { |
| label = get_label_info(":$target_name", "label_with_toolchain") |
| if (defined(invoker.image_metadata)) { |
| forward_variables_from(invoker.image_metadata, "*") |
| } |
| if (!defined(name)) { |
| name = output_name |
| } |
| if (!defined(type)) { |
| # TODO(mcgrathr): This isn't usefully descriptive but it's not |
| # clear what other generic string to use for these. They might |
| # be what some boot loader calls the "kernel", or they might be |
| # pasted on the front of the image by some script (perhaps |
| # before more stages of board-specific image packing). Refine |
| # this part of the "images" build API when consumer needs for |
| # making use of the shims becomes more clear. |
| type = "bin" |
| } |
| path = rebase_path("$output_dir/$output_name.$output_extension", |
| root_build_dir) |
| cpu = current_cpu |
| }, |
| ] |
| } |
| } |
| } else { |
| environment_redirect(board) { |
| environment_label = "$zx/kernel/arch/arm64:physmem" |
| deps = [ |
| ":$board", |
| ] |
| } |
| not_needed(invoker, "*") |
| } |
| } |
| |
| boot_shim("hikey960") { |
| } |
| |
| boot_shim("imx8mevk") { |
| } |
| |
| boot_shim("imx8mmevk") { |
| } |
| |
| boot_shim("mt8167s_ref") { |
| } |
| |
| boot_shim("qemu") { |
| image_metadata = { |
| name = "qemu-kernel" |
| type = "kernel" |
| } |
| } |
| |
| boot_shim("sherlock") { |
| } |
| |
| boot_shim("msm8x53-som") { |
| } |