blob: ecaa6ee3931081d8ec02c82e3eab9d6ffa7bc374 [file] [log] [blame]
# Copyright Google LLC, 2022
# Licensed under the Apache License, Version 2.0, see LICENSE for details.
# SPDX-License-Identifier: Apache-2.0
"""Rules to automatically generate files with utility tools."""
def _autogen_top_gen_hjson(ctx):
""" Use topgen_matcha.py to generate top hjson file.
This rule assumes all input hjson files (top_{name}/**/data/**/*.hjson}) are
already up-to-date, and use util:topgen_matcha tool to generate the
top-level hjson description. It can be used to scramble the boot rom image.
Args:
srcs: Input top-level hjson file.
output: Generated top hjson file.
data: Files needed (template files, IP hjson files).
Output:
output hjson file. Note topgen_matcha always dump it at
{out_dir}/data/autogen.
It can be one of the following files:
data/autogen/top_{name}.gen.hjson
data/autogen/top_{name}.gen.rom_ctrl.hjson
"""
if not ctx.attr.output.startswith("data/autogen"):
fail("output must be pointed to data/autogen", [ctx.attr.output])
hjson = ctx.actions.declare_file("{}".format(ctx.attr.output))
ctx.actions.run(
mnemonic = "Topgen",
outputs = [hjson],
inputs = ctx.files.data + [ctx.file.srcs, ctx.executable._topgentool, ctx.file._util],
env = {
"OPENTITAN_TOP": "{}/../".format(ctx.file._util.dirname),
},
arguments = [
"-t",
"{}".format(ctx.file.srcs.path),
"-o",
"{}/../../".format(hjson.dirname),
"--no-top",
"--dump_gen_hjson",
],
executable = ctx.executable._topgentool,
)
return [
DefaultInfo(files = depset([hjson])),
OutputGroupInfo(
hjson = depset([hjson]),
),
]
autogen_top_gen_hjson = rule(
implementation = _autogen_top_gen_hjson,
attrs = {
"srcs": attr.label(
mandatory = True,
allow_single_file = True,
doc = "topgen input top-level hjson file",
),
"data": attr.label_list(
allow_files = True,
doc = "Files needed at runtime",
),
"output": attr.string(
mandatory = True,
doc = "Generated hjson file path",
),
"_topgentool": attr.label(
default = "@//util:topgen_matcha",
executable = True,
cfg = "exec",
),
"_util": attr.label(
default = "@lowrisc_opentitan//util:BUILD",
allow_single_file = True,
),
},
)