Skip to content

Instantly share code, notes, and snippets.

@pamaury
Created May 9, 2023 14:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pamaury/9816cee44496f647574314580b5ae5de to your computer and use it in GitHub Desktop.
Save pamaury/9816cee44496f647574314580b5ae5de to your computer and use it in GitHub Desktop.
# Copyright lowRISC contributors.
# Licensed under the Apache License, Version 2.0, see LICENSE for details.
# SPDX-License-Identifier: Apache-2.0
load("//rules:splice.bzl", "bitstream_splice")
load("//rules:otp.bzl", "get_otp_images")
package(default_visibility = ["//visibility:public"])
# By default, targets in this file will use cached artifacts from the GCP bucket
# instead of building them from scratch.
#
# You can control GCP bitstream selection with the BITSTREAM environment
# variable. See //rules:bitstreams.bzl for more information.
#
# Alternatively, you can disable or alter this caching behavior with the
# "bitstream" config setting.
#
# * `--define bitstream=skip` skips loading a bitstream into the FPGA. This is
# useful if you already have a bitstream loaded into the FPGA and you don't
# want the GCP cache manager to do anything unexpected.
#
# * `--define bitstream=vivado` causes these targets to build from scratch with
# Vivado. You'll need to have Xilinx Vivado installed and have properly
# configured access to a license or license server.
#
# * `--define bitstream=gcp_splice` causes these targets to use a cached
# bitstream, but splice in a locally-built ROM image or OTP.
#
# Downstream targets will see the effects of this caching logic. For example,
# specifying `--define bitstream=vivado` when testing
# //sw/device/silicon_creator/lib/drivers:hmac_functest_fpga_cw310 will turn
# `:test_rom` into a full Vivado bitstream build.
config_setting(
name = "bitstream_skip",
define_values = {
"bitstream": "skip",
},
)
config_setting(
name = "bitstream_vivado",
define_values = {
"bitstream": "vivado",
},
)
config_setting(
name = "bitstream_gcp_splice",
define_values = {
"bitstream": "gcp_splice",
},
)
config_setting(
name = "bitstream_custom",
define_values = {
"bitstream": "custom",
},
)
filegroup(
name = "the_bitstream",
srcs = select({
"bitstream_custom": ["mybistream.bit"],
"//conditions:default": ["@bitstreams//:chip_earlgrey_cw310_bitstream"],
}),
tags = ["manual"],
)
filegroup(
name = "test_rom",
testonly = True,
srcs = select({
"bitstream_skip": ["skip.bit"],
"bitstream_vivado": ["//hw/bitstream/vivado:fpga_cw310_test_rom"],
"bitstream_gcp_splice": [":gcp_spliced_test_rom"],
"//conditions:default": [":gcp_spliced_test_rom"],
}),
tags = ["manual"],
)
filegroup(
name = "rom",
testonly = True,
srcs = select({
"bitstream_skip": ["skip.bit"],
"bitstream_vivado": ["//hw/bitstream/vivado:fpga_cw310_rom"],
"bitstream_gcp_splice": [":gcp_spliced_rom"],
"//conditions:default": [":gcp_spliced_rom"],
}),
tags = ["manual"],
)
filegroup(
name = "rom_mmi",
testonly = True,
srcs = select({
"bitstream_skip": ["skip.bit"],
"bitstream_vivado": ["//hw/bitstream/vivado:rom_mmi"],
"//conditions:default": ["@bitstreams//:chip_earlgrey_cw310_rom_mmi"],
}),
tags = ["manual"],
)
filegroup(
name = "otp_mmi",
testonly = True,
srcs = select({
"bitstream_skip": ["skip.bit"],
"bitstream_vivado": ["//hw/bitstream/vivado:otp_mmi"],
"//conditions:default": ["@bitstreams//:chip_earlgrey_cw310_otp_mmi"],
}),
tags = ["manual"],
)
[
filegroup(
name = "rom_otp_" + otp_name,
testonly = True,
srcs = select({
"bitstream_skip": ["skip.bit"],
"bitstream_vivado": ["//hw/bitstream/vivado:fpga_cw310_rom_otp_" + otp_name],
"bitstream_gcp_splice": [":gcp_spliced_rom_otp_" + otp_name],
"//conditions:default": [":gcp_spliced_rom_otp_" + otp_name],
}),
tags = ["manual"],
)
for (otp_name, _) in get_otp_images()
]
# Build the Test ROM and splice it into a cached bitstream.
bitstream_splice(
name = "gcp_spliced_test_rom",
testonly = True,
src = ":the_bitstream",
data = "//sw/device/lib/testing/test_rom:test_rom_fpga_cw310_scr_vmem",
meminfo = ":rom_mmi",
tags = ["manual"],
update_usr_access = True,
visibility = ["//visibility:private"],
)
# Build the ROM and splice it into a cached bitstream.
bitstream_splice(
name = "gcp_spliced_rom",
testonly = True,
src = ":the_bitstream",
data = "//sw/device/silicon_creator/rom:rom_with_fake_keys_fpga_cw310_scr_vmem",
meminfo = ":rom_mmi",
tags = ["manual"],
update_usr_access = True,
visibility = ["//visibility:private"],
)
# Splice OTP images into the locally-spliced ROM bitstream.
[
bitstream_splice(
name = "gcp_spliced_rom_otp_" + otp_name,
testonly = True,
src = ":gcp_spliced_rom",
data = img_target,
meminfo = ":otp_mmi",
tags = ["manual"],
update_usr_access = True,
visibility = ["//visibility:private"],
)
for (otp_name, img_target) in get_otp_images()
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment