| # Copyright 2025 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("//build/compiled_action.gni") |
| import("//build/zbi/zbi_input.gni") |
| |
| # ZBI item generation. |
| # |
| # Provides a target compatible with `zbi()` that will generate the proper |
| # ZBI item for the provided information. |
| # |
| # Parameters: |
| # |
| # * type |
| # - Required: name of the item type, in the form of `ZBI_TYPE....`. |
| # - Type: string |
| # |
| # * extra |
| # - Optional: name of the item extra enum in the form of `ZBI_KERNEL_DRIVER.....` |
| # - Type: string |
| # - Default: "" - zeroed extra field. |
| # |
| # * contents |
| # - Required: contents of the object, parsing is tied to the specific item type. |
| # For single objects (read C-struct) field name is mapped to contents. |
| # For collections of objects (read variadic size struct) |
| # a collection of single objects is expected. |
| # - Type: list or scope |
| # |
| template("zbi_item") { |
| assert(defined(invoker.type), "`type` parameter is required.") |
| assert(defined(invoker.contents), "`content` paremeter is required") |
| |
| labels = { |
| contents_json = "_$target_name.contents.json" |
| zbi_item_go = "$target_name" |
| } |
| |
| files = { |
| contents_json = "$target_gen_dir/${target_name}.contents.json" |
| zbi_bin = "$target_out_dir/${target_name}.zbi" |
| zbi_item_depfile = "$target_out_dir/${target_name}.d" |
| } |
| |
| generated_file(labels.contents_json) { |
| visibility = [ ":${labels.zbi_item_go}" ] |
| forward_variables_from(invoker, |
| [ |
| "testonly", |
| "visibility", |
| ]) |
| contents = { |
| type = invoker.type |
| if (defined(invoker.extra)) { |
| extra = invoker.extra |
| } |
| contents = invoker.contents |
| } |
| outputs = [ files.contents_json ] |
| output_conversion = "json" |
| } |
| |
| # Call `zbi_item.go` to generate the binary blob |
| compiled_action(labels.zbi_item_go) { |
| forward_variables_from(invoker, |
| [ |
| "testonly", |
| "visibility", |
| ]) |
| tool = "//zircon/tools/zbi:make_single_item_zbi" |
| inputs = [ files.contents_json ] |
| outputs = [ files.zbi_bin ] |
| depfile = files.zbi_item_depfile |
| args = [ |
| "--item-path", |
| rebase_path(files.contents_json, root_build_dir), |
| "--output", |
| rebase_path(files.zbi_bin, root_build_dir), |
| "--depfile", |
| rebase_path(files.zbi_item_depfile, root_build_dir), |
| ] |
| |
| deps = [ ":${labels.contents_json}" ] |
| |
| # This allows it to be "zbi_input"-like and be taken into account by `zbi()` |
| metadata = { |
| zbi_input_barrier = [] |
| zbi_input_args = [] |
| |
| if (defined(invoker.metadata)) { |
| forward_variables_from(invoker.metadata, "*") |
| } |
| |
| zbi_input_args += [ |
| "--type=container", |
| rebase_path(files.zbi_bin, root_build_dir), |
| ] |
| } |
| } |
| } |