Skip to content

Commit

Permalink
[bazel] Build non-scrambled VMEM images
Browse files Browse the repository at this point in the history
1. Define a basic CW305 exec_env.The build/release pipeline expects to
   find cw305 artifacts for the test_rom.
2. The englishbreakfast verilator model does not understand ROM scrambling,
   so we also create a non-scrambled VMEM file.

Signed-off-by: Chris Frantz <[email protected]>
  • Loading branch information
cfrantz committed Oct 5, 2023
1 parent b2cf961 commit 2161256
Show file tree
Hide file tree
Showing 9 changed files with 85 additions and 4 deletions.
7 changes: 5 additions & 2 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -351,9 +351,12 @@ jobs:
- bash: |
. util/build_consts.sh
mkdir -p "$BIN_DIR/sw/device/lib/testing/test_rom"
cp $(ci/scripts/target-location.sh //sw/device/lib/testing/test_rom:test_rom_fpga_cw305_vmem) \
cp $(ci/scripts/target-location.sh \
//sw/device/lib/testing/test_rom:test_rom_fpga_cw305 \
--features=-rv32_bitmanip \
--copt=-DOT_IS_ENGLISH_BREAKFAST_REDUCED_SUPPORT_FOR_INTERNAL_USE_ONLY_) \
"$BIN_DIR/sw/device/lib/testing/test_rom"
displayName: Copy test_rom_fpga_cw305_vmem to $BIN_DIR
displayName: Copy test_rom_fpga_cw305 to $BIN_DIR
- template: ci/upload-artifacts-template.yml
parameters:
includePatterns:
Expand Down
18 changes: 18 additions & 0 deletions hw/top_earlgrey/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ load(
"//rules/opentitan:defs.bzl",
"DEFAULT_TEST_FAILURE_MSG",
"DEFAULT_TEST_SUCCESS_MSG",
"fpga_cw305",
"fpga_cw310",
"fpga_cw340",
"sim_dv",
Expand Down Expand Up @@ -90,6 +91,23 @@ fpga_cw310(
rsa_key = {"//sw/device/silicon_creator/rom/keys/fake/rsa:test_private_key_0": "test_key_0"},
)

###########################################################################
# FPGA CW305 Environments
#
# TODO(opentitan#19493): Determine whether the `fpga_cw310` infrastructure
# should become a more generic `fpga_chipwhisperer` infrastruture able to
# handle multiple CW-type boards.
###########################################################################
fpga_cw305(
name = "fpga_cw305",
design = "earlgrey",
exec_env = "fpga_cw305",
lib = "//sw/device/lib/arch:fpga_cw305",
linker_script = "//sw/device/lib/testing/test_framework:ottf_ld_silicon_creator_slot_a",
rom_scramble_config = "//hw/top_earlgrey/data:autogen/top_earlgrey.gen.hjson",
test_cmd = "testing-not-supported",
)

###########################################################################
# FPGA CW340 Environments
#
Expand Down
6 changes: 6 additions & 0 deletions rules/opentitan/cc.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,12 @@ def _opentitan_binary(ctx):
# the DefaultInfo provider.
if "logs" in provides:
default_info.extend(provides["logs"])

# FIXME(cfrantz): Special case: The englishbreakfast verilator model
# requires a non-scrambled ROM image.
if provides.get("rom32"):
default_info.append(provides["rom32"])

groups.update(_as_group_info(exec_env.exec_env, signed))
groups.update(_as_group_info(exec_env.exec_env, provides))

Expand Down
2 changes: 2 additions & 0 deletions rules/opentitan/defs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ load(
load(
"@lowrisc_opentitan//rules/opentitan:fpga_cw310.bzl",
_cw310_params = "cw310_params",
_fpga_cw305 = "fpga_cw305",
_fpga_cw310 = "fpga_cw310",
_fpga_cw340 = "fpga_cw340",
)
Expand All @@ -40,6 +41,7 @@ opentitan_transition = _opentitan_transition

opentitan_binary = _opentitan_binary
fpga_cw310 = _fpga_cw310
fpga_cw305 = _fpga_cw305
fpga_cw340 = _fpga_cw340
cw310_params = _cw310_params

Expand Down
34 changes: 33 additions & 1 deletion rules/opentitan/fpga_cw310.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@
# Licensed under the Apache License, Version 2.0, see LICENSE for details.
# SPDX-License-Identifier: Apache-2.0

load("@lowrisc_opentitan//rules/opentitan:providers.bzl", "Cw310BinaryInfo", "Cw340BinaryInfo", "get_one_binary_file")
load(
"@lowrisc_opentitan//rules/opentitan:providers.bzl",
"Cw305BinaryInfo",
"Cw310BinaryInfo",
"Cw340BinaryInfo",
"get_one_binary_file",
)
load("@lowrisc_opentitan//rules/opentitan:util.bzl", "get_fallback", "get_files")
load(
"//rules/opentitan:exec_env.bzl",
Expand All @@ -13,6 +19,7 @@ load(
load(
"@lowrisc_opentitan//rules/opentitan:transform.bzl",
"convert_to_scrambled_rom_vmem",
"convert_to_vmem",
)

_TEST_SCRIPT = """#!/bin/bash
Expand Down Expand Up @@ -47,10 +54,20 @@ def _transform(ctx, exec_env, name, elf, binary, signed_bin, disassembly, mapfil
rom_scramble_config = exec_env.rom_scramble_config,
rom_scramble_tool = ctx.executable.rom_scramble_tool,
)

# The englishbreakfast verilator model does not understand ROM
# scrambling, so we also create a non-scrambled VMEM file.
rom32 = convert_to_vmem(
ctx,
name = name,
src = binary,
word_size = 32,
)
default = rom
elif ctx.attr.kind == "flash":
default = signed_bin if signed_bin else binary
rom = None
rom32 = None
else:
fail("Not implemented: kind ==", ctx.attr.kind)

Expand All @@ -59,6 +76,7 @@ def _transform(ctx, exec_env, name, elf, binary, signed_bin, disassembly, mapfil
"binary": binary,
"default": default,
"rom": rom,
"rom32": rom32,
"signed_bin": signed_bin,
"disassembly": disassembly,
"mapfile": mapfile,
Expand Down Expand Up @@ -150,6 +168,20 @@ fpga_cw310 = rule(
attrs = exec_env_common_attrs(),
)

def _fpga_cw305(ctx):
fields = exec_env_as_dict(ctx)
return ExecEnvInfo(
provider = Cw305BinaryInfo,
test_dispatch = _test_dispatch,
transform = _transform,
**fields
)

fpga_cw305 = rule(
implementation = _fpga_cw305,
attrs = exec_env_common_attrs(),
)

def _fpga_cw340(ctx):
fields = exec_env_as_dict(ctx)
return ExecEnvInfo(
Expand Down
5 changes: 4 additions & 1 deletion rules/opentitan/legacy.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ def legacy_rom_targets(target, suffixes):
native.filegroup(
name = "{}_{}".format(target, suffix),
srcs = [":{}".format(target)],
output_group = "{}_rom".format(suffix),
output_group = select({
"//sw/device:is_english_breakfast": "{}_rom32".format(suffix),
"//conditions:default": "{}_rom".format(suffix),
}),
)
native.alias(
name = "{}_{}_scr_vmem".format(target, suffix),
Expand Down
4 changes: 4 additions & 0 deletions rules/opentitan/providers.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ Cw310BinaryInfo = provider(
doc = "CW310 Binary Info",
)

Cw305BinaryInfo = provider(
doc = "CW305 Binary Info",
)

Cw340BinaryInfo = provider(
doc = "CW340 Binary Info",
)
Expand Down
11 changes: 11 additions & 0 deletions rules/opentitan/sim_verilator.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,15 @@ def _transform(ctx, exec_env, name, elf, binary, signed_bin, disassembly, mapfil
rom_scramble_config = exec_env.rom_scramble_config,
rom_scramble_tool = ctx.executable.rom_scramble_tool,
)

# The englishbreakfast verilator model does not understand ROM
# scrambling, so we also create a non-scrambled VMEM file.
rom32 = convert_to_vmem(
ctx,
name = name,
src = binary,
word_size = 32,
)
default = rom
vmem = rom
elif ctx.attr.kind == "flash":
Expand All @@ -58,6 +67,7 @@ def _transform(ctx, exec_env, name, elf, binary, signed_bin, disassembly, mapfil
)
default = vmem
rom = None
rom32 = None
else:
fail("Not implemented: kind ==", ctx.attr.kind)

Expand All @@ -70,6 +80,7 @@ def _transform(ctx, exec_env, name, elf, binary, signed_bin, disassembly, mapfil
"disassembly": disassembly,
"mapfile": mapfile,
"vmem": vmem,
"rom32": rom32,
}

def _test_dispatch(ctx, exec_env, provider):
Expand Down
2 changes: 2 additions & 0 deletions sw/device/lib/testing/test_rom/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ opentitan_binary(
name = "test_rom",
exec_env = [
"//hw/top_earlgrey:fpga_cw310",
"//hw/top_earlgrey:fpga_cw305",
"//hw/top_earlgrey:fpga_cw340",
"//hw/top_earlgrey:sim_dv_base",
"//hw/top_earlgrey:sim_verilator_base",
Expand All @@ -46,6 +47,7 @@ opentitan_binary(
legacy_rom_targets(
suffixes = [
"fpga_cw310",
"fpga_cw305",
"fpga_cw340",
"sim_dv",
"sim_verilator",
Expand Down

0 comments on commit 2161256

Please sign in to comment.