diff --git a/MODULE.bazel b/MODULE.bazel index 3fee2e7a4..4574b44d3 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -111,6 +111,18 @@ caliptra_repos_ext = use_extension( ) use_repo(caliptra_repos_ext, "caliptra_mcu_sw", "caliptra_sw") +# VCK190 subsystem bitstream matching the caliptra_mcu_sw pin above. URL and +# sha256 are copied from hw/fpga/bitstream_manifests/subsystem.toml at that +# commit; bump them together with the pin. +http_file = use_repo_rule("@bazel_tools//tools/build_defs/repo:http.bzl", "http_file") + +http_file( + name = "caliptra_fpga_bitstream", + downloaded_file_path = "caliptra-bitstream.pdi", + sha256 = "bb4892661af8769104694e5bd307a993264460a286437e0d8bc3b2f1de60173d", + urls = ["https://storage.googleapis.com/caliptra-github-ci-bitstreams/v1/a2cd177353b7f06170766f367743b98c900b1d7b/runtime_a2cd177.pdi"], +) + nonhermetic_repo = use_repo_rule("//target/earlgrey/tooling/signing:nonhermetic.bzl", "nonhermetic_repo") nonhermetic_repo(name = "nonhermetic") diff --git a/target/veer/tooling/BUILD.bazel b/target/veer/tooling/BUILD.bazel index 0d221bad3..62aa389d3 100644 --- a/target/veer/tooling/BUILD.bazel +++ b/target/veer/tooling/BUILD.bazel @@ -48,6 +48,7 @@ pw_py_importable_runfile( mcu_rom_wrapper( name = "mcu_rom_bin_transitioned", target = "//third_party/caliptra/caliptra-mcu-sw:mcu_rom_bin", + visibility = ["//target/veer:__subpackages__"], ) pw_py_importable_runfile( diff --git a/target/veer/tooling/caliptra_runner.bzl b/target/veer/tooling/caliptra_runner.bzl index 72a0a49fd..87a3b4623 100644 --- a/target/veer/tooling/caliptra_runner.bzl +++ b/target/veer/tooling/caliptra_runner.bzl @@ -6,17 +6,31 @@ load("@pigweed//pw_kernel/tooling:system_image.bzl", "SystemImageInfo") def _target_type_transition_impl(_, attr): + # target_type selects the image's memory map; //third_party/caliptra:platform + # selects the matching Caliptra ROM/FW and MCU ROM variants. if attr.interface == "fpga": - return {"//target/veer:target_type": "fpga"} + return { + "//target/veer:target_type": "fpga", + "//third_party/caliptra:platform": "fpga", + } if attr.interface == "emulator": - return {"//target/veer:target_type": "emulator"} + return { + "//target/veer:target_type": "emulator", + "//third_party/caliptra:platform": "emulator", + } - return {"//target/veer:target_type": "silicon"} + return { + "//target/veer:target_type": "emulator", + "//third_party/caliptra:platform": "emulator", + } _target_type_transition = transition( implementation = _target_type_transition_impl, inputs = [], - outputs = ["//target/veer:target_type"], + outputs = [ + "//target/veer:target_type", + "//third_party/caliptra:platform", + ], ) def _mcu_rom_transition_impl(settings, attr): @@ -29,11 +43,12 @@ _mcu_rom_transition = transition( ) def _caliptra_runner_impl(ctx): - system_image_info = ctx.attr.target[0][SystemImageInfo] + system_image_info = ctx.attr.target[SystemImageInfo] bin_file = system_image_info.bin elf_file = system_image_info.elf runner = ctx.executable._caliptra_runner + platform = "fpga" if ctx.attr.interface == "fpga" else "emulator" manifest = ctx.actions.declare_file("{}.manifest".format(ctx.attr.name)) ctx.actions.run( inputs = [ @@ -47,7 +62,8 @@ def _caliptra_runner_impl(ctx): arguments = [ "auth-manifest", "create", - "--mcu_image={},0x4000000,0,2,2".format(bin_file.path), + "--platform={}".format(platform), + "--mcu_image={}".format(bin_file.path), "--caliptra_rom={}".format(ctx.file.caliptra_rom.path), "--caliptra_firmware={}".format(ctx.file.caliptra_firmware.path), "--vendor_pk_hash={}".format(ctx.attr.vendor_pk_hash), @@ -57,19 +73,20 @@ def _caliptra_runner_impl(ctx): run_script = ctx.actions.declare_file(ctx.attr.name + ".sh") - # TODO: currently, the caliptra rom, firmware and mcu-rom are hardcoded in the runner python script. - # Perhaps these shoulc be arguments to the script instead. ctx.actions.write( output = run_script, is_executable = True, content = """#!/bin/bash -{runner} --interface {interface} --elf {elf} --bin {bin} --manifest {manifest} --vendor-pk-hash {vendor_pk_hash} {optional_args} +{runner} --interface {interface} --elf {elf} --bin {bin} --manifest {manifest} --caliptra-rom {caliptra_rom} --caliptra-firmware {caliptra_firmware} --mcu-rom {mcu_rom} --vendor-pk-hash {vendor_pk_hash} {optional_args} """.format( runner = runner.short_path, interface = ctx.attr.interface, elf = elf_file.short_path, bin = bin_file.short_path, manifest = manifest.short_path, + caliptra_rom = ctx.file.caliptra_rom.short_path, + caliptra_firmware = ctx.file.caliptra_firmware.short_path, + mcu_rom = ctx.file.mcu_rom.short_path, vendor_pk_hash = ctx.attr.vendor_pk_hash, optional_args = "", ), @@ -79,7 +96,14 @@ def _caliptra_runner_impl(ctx): return [DefaultInfo( runfiles = ctx.runfiles( - files = [manifest, bin_file, runner], + files = [ + manifest, + bin_file, + runner, + ctx.file.caliptra_rom, + ctx.file.caliptra_firmware, + ctx.file.mcu_rom, + ], transitive_files = runner_files_depset, ), executable = run_script, @@ -100,11 +124,15 @@ _BASE_ATTRS = { doc = "The interface to use.", mandatory = True, ), + "mcu_rom": attr.label( + allow_single_file = True, + default = "//target/veer/tooling:mcu_rom_bin_transitioned", + doc = "MCU ROM", + ), "target": attr.label( doc = "The system_image target to run.", mandatory = True, providers = [SystemImageInfo], - cfg = _target_type_transition, ), "vendor_pk_hash": attr.string( default = "b17ca877666657ccd100e6926c7206b60c995cb68992c6c9baefce728af05441dee1ff415adfc187e1e4edb4d3b2d909", @@ -128,12 +156,14 @@ caliptra_runner = rule( implementation = _caliptra_runner_impl, executable = True, attrs = _BASE_ATTRS, + cfg = _target_type_transition, ) caliptra_test = rule( implementation = _caliptra_runner_impl, test = True, attrs = _BASE_ATTRS, + cfg = _target_type_transition, ) def _mcu_rom_wrapper_impl(ctx): diff --git a/target/veer/tooling/caliptra_runner.py b/target/veer/tooling/caliptra_runner.py index 54dc67af0..06aef5175 100755 --- a/target/veer/tooling/caliptra_runner.py +++ b/target/veer/tooling/caliptra_runner.py @@ -86,6 +86,24 @@ def _parse_args(): type=pathlib.Path, help="authorization manifest", ) + parser.add_argument( + "--caliptra-rom", + type=pathlib.Path, + default=pathlib.Path(_CPTRA_ROM), + help="caliptra ROM binary", + ) + parser.add_argument( + "--caliptra-firmware", + type=pathlib.Path, + default=pathlib.Path(_CPTRA_FIRMWARE), + help="caliptra firmware bundle binary", + ) + parser.add_argument( + "--mcu-rom", + type=pathlib.Path, + default=pathlib.Path(_MCU_ROM), + help="MCU ROM binary", + ) parser.add_argument( "--vendor-pk-hash", type=str, @@ -142,15 +160,18 @@ def load_and_run( manifest: str, vendor_pk_hash: str, elf: Path | None = None, + caliptra_rom: Path | str = _CPTRA_ROM, + caliptra_firmware: Path | str = _CPTRA_FIRMWARE, + mcu_rom: Path | str = _MCU_ROM, ) -> list[str]: """Prepare arguments to load an image into a board and spawn a console.""" if interface == "emulator": cmd = [ _EMULATOR, - f"--rom={_MCU_ROM}", + f"--rom={mcu_rom}", f"--firmware={image}", - f"--caliptra-rom={_CPTRA_ROM}", - f"--caliptra-firmware={_CPTRA_FIRMWARE}", + f"--caliptra-rom={caliptra_rom}", + f"--caliptra-firmware={caliptra_firmware}", "--i3c-port=65534", "--rom-offset=0x80000000", "--rom-size=0x10000", @@ -296,6 +317,9 @@ def _main(args) -> int: args.manifest, args.vendor_pk_hash, elf=args.elf, + caliptra_rom=args.caliptra_rom, + caliptra_firmware=args.caliptra_firmware, + mcu_rom=args.mcu_rom, ) # TODO(cfrantz): add support for the tokenized console. return_code = simple_console(cmd) diff --git a/third_party/caliptra/BUILD.bazel b/third_party/caliptra/BUILD.bazel index 1866983d3..227e083b8 100644 --- a/third_party/caliptra/BUILD.bazel +++ b/third_party/caliptra/BUILD.bazel @@ -1,6 +1,7 @@ # Licensed under the Apache-2.0 license # SPDX-License-Identifier: Apache-2.0 +load("@bazel_skylib//rules:common_settings.bzl", "string_flag") load("@rules_python//python:defs.bzl", "py_binary", "py_library", "py_test") load("//third_party/caliptra:versions.bzl", "CALIPTRA_VERSIONS") @@ -13,6 +14,28 @@ load("//third_party/caliptra:versions.bzl", "CALIPTRA_VERSIONS") package(default_visibility = ["//visibility:public"]) +# Which Caliptra subsystem platform the boot components (Caliptra ROM/FW, MCU +# ROM) are built for. Rules that run an image on a given platform (e.g. +# //target/veer/tooling:caliptra_runner.bzl) set this with a transition. +string_flag( + name = "platform", + build_setting_default = "emulator", + values = [ + "emulator", + "fpga", + ], +) + +config_setting( + name = "platform_emulator", + flag_values = {":platform": "emulator"}, +) + +config_setting( + name = "platform_fpga", + flag_values = {":platform": "fpga"}, +) + config_setting( name = "is_riscv32imc", constraint_values = [ diff --git a/third_party/caliptra/caliptra-mcu-sw/BUILD.bazel b/third_party/caliptra/caliptra-mcu-sw/BUILD.bazel index 2cc8084d4..c5c600627 100644 --- a/third_party/caliptra/caliptra-mcu-sw/BUILD.bazel +++ b/third_party/caliptra/caliptra-mcu-sw/BUILD.bazel @@ -298,6 +298,8 @@ rust_binary( "@rust_caliptra_crates_host//:anyhow", "@rust_caliptra_crates_host//:caliptra-auth-man-types", "@rust_caliptra_crates_host//:caliptra-image-types", + "@rust_caliptra_crates_host//:caliptra-mcu-config-emulator", + "@rust_caliptra_crates_host//:caliptra-mcu-config-fpga", "@rust_caliptra_crates_host//:caliptra-mcu-firmware-bundler", "@rust_caliptra_crates_host//:clap", ], @@ -342,6 +344,7 @@ rust_binary( edition = "2021", deps = [ "@rust_caliptra_crates_host//:caliptra-mcu-config-emulator", + "@rust_caliptra_crates_host//:caliptra-mcu-config-fpga", "@rust_caliptra_crates_host//:subst", ], ) @@ -349,9 +352,47 @@ rust_binary( caliptra_linker_script( name = "emulator_rom_layout", out = "emulator-rom-layout.ld", + args = ["emulator"], generator = ":generate_rom_ld", ) +caliptra_linker_script( + name = "fpga_rom_layout", + out = "fpga-rom-layout.ld", + args = ["fpga"], + generator = ":generate_rom_ld", +) + +_MCU_ROM_RUSTC_FLAGS = [ + "-A", + "dead_code", + "--cap-lints=allow", + "--cfg", + 'target_arch="riscv32"', + "-C", + "panic=abort", + "-C", + "opt-level=z", + "-C", + "codegen-units=1", + "-C", + "lto=fat", + "-C", + "embed-bitcode=yes", + "-C", + "target-feature=+relax,+zba,+zbb,+zbc,+zbs", + "-C", + "force-frame-pointers=no", + "-C", + "relocation-model=static", + "-C", + "symbol-mangling-version=v0", + "-C", + "link-arg=-Wl,-nmagic", + "-C", + "link-arg=-Wl,--icf=all", +] + # NOTE: This target requires the caliptra RISC-V platform transition to build. # Build via //target/veer/tooling:mcu_rom_bin_transitioned instead of directly. rust_binary( @@ -360,36 +401,9 @@ rust_binary( compile_data = [":emulator-rom-layout.ld"], crate_root = "@caliptra_mcu_sw//:platforms/emulator/rom/src/main.rs", edition = "2021", - rustc_flags = [ - "-A", - "dead_code", + rustc_flags = _MCU_ROM_RUSTC_FLAGS + [ "-C", "link-arg=-T$(location :emulator-rom-layout.ld)", - "--cap-lints=allow", - "--cfg", - 'target_arch="riscv32"', - "-C", - "panic=abort", - "-C", - "opt-level=z", - "-C", - "codegen-units=1", - "-C", - "lto=fat", - "-C", - "embed-bitcode=yes", - "-C", - "target-feature=+relax,+zba,+zbb,+zbc,+zbs", - "-C", - "force-frame-pointers=no", - "-C", - "relocation-model=static", - "-C", - "symbol-mangling-version=v0", - "-C", - "link-arg=-Wl,-nmagic", - "-C", - "link-arg=-Wl,--icf=all", ], tags = ["manual"], deps = [ @@ -414,12 +428,50 @@ rust_binary( ], ) +# FPGA MCU ROM (upstream platforms/fpga/rom), linked against FPGA_MEMORY_MAP. +# Same transition requirement as :mcu_rom. +rust_binary( + name = "mcu_rom_fpga", + srcs = ["@caliptra_mcu_sw//:all_files"], + compile_data = [":fpga-rom-layout.ld"], + crate_root = "@caliptra_mcu_sw//:platforms/fpga/rom/src/main.rs", + edition = "2021", + rustc_flags = _MCU_ROM_RUSTC_FLAGS + [ + "-C", + "link-arg=-T$(location :fpga-rom-layout.ld)", + ], + tags = ["manual"], + deps = [ + ":mcu_rom_common", + ":romtime", + "//third_party/caliptra:crate_caliptra-mcu-registers-generated", + "//third_party/caliptra:crate_tock-registers", + "@rust_caliptra_crates//:caliptra-mcu-config", + "@rust_caliptra_crates//:caliptra-mcu-config-fpga", + "@rust_caliptra_crates//:riscv-csr", + "@rust_caliptra_crates//:rv32i", + ], +) + +# Selects the MCU ROM for //third_party/caliptra:platform. +alias( + name = "mcu_rom_for_platform", + actual = select({ + "//third_party/caliptra:platform_fpga": ":mcu_rom_fpga", + "//conditions:default": ":mcu_rom", + }), + tags = ["manual"], +) + caliptra_objcopy( name = "mcu_rom_bin", - src = ":mcu_rom", + src = ":mcu_rom_for_platform", out = "mcu_rom.bin", - # Must match `EMULATOR_MEMORY_MAP.rom_size` in `caliptra_mcu_config_emulator`. - rom_size = 65536, + # Must match `FPGA_MEMORY_MAP.rom_size` / `EMULATOR_MEMORY_MAP.rom_size`. + rom_size = select({ + "//third_party/caliptra:platform_fpga": "131072", + "//conditions:default": "65536", + }), tags = [ "manual", "no-sandbox", diff --git a/third_party/caliptra/caliptra-mcu-sw/overlay.BUILD b/third_party/caliptra/caliptra-mcu-sw/overlay.BUILD index 9e84d0ccd..7bfef65f8 100644 --- a/third_party/caliptra/caliptra-mcu-sw/overlay.BUILD +++ b/third_party/caliptra/caliptra-mcu-sw/overlay.BUILD @@ -20,6 +20,7 @@ exports_files( "emulator/consts/src/lib.rs", "caliptra-util-host/apps/mailbox/server/src/lib.rs", "platforms/emulator/rom/src/main.rs", + "platforms/fpga/rom/src/main.rs", "romtime/src/lib.rs", ], visibility = ["//visibility:public"], diff --git a/third_party/caliptra/caliptra-mcu-sw/src/generate_rom_ld.rs b/third_party/caliptra/caliptra-mcu-sw/src/generate_rom_ld.rs index f058396a1..fcf563b6a 100644 --- a/third_party/caliptra/caliptra-mcu-sw/src/generate_rom_ld.rs +++ b/third_party/caliptra/caliptra-mcu-sw/src/generate_rom_ld.rs @@ -1,8 +1,10 @@ // Licensed under the Apache-2.0 license // SPDX-License-Identifier: Apache-2.0 // -// Host tool that emits the MCU ROM linker script for the emulator platform -// by substituting the `EMULATOR_MEMORY_MAP` values into a template. +// Host tool that emits the MCU ROM linker script for a platform by +// substituting that platform's memory map into a template. +// +// Usage: generate_rom_ld // // # Upstream cross-reference // @@ -11,6 +13,7 @@ // `firmware-bundler/data/default-rom-layout.ld`. use caliptra_mcu_config_emulator::EMULATOR_MEMORY_MAP; +use caliptra_mcu_config_fpga::FPGA_MEMORY_MAP; const ROM_LD_TEMPLATE: &str = r#" /* Licensed under the Apache-2.0 license. */ @@ -28,7 +31,7 @@ ROM_DIGEST_SIZE = 48; MEMORY { ROM (rx) : ORIGIN = $ROM_OFFSET, LENGTH = $ROM_SIZE - ROM_DIGEST_SIZE - RAM (rwx) : ORIGIN = $DCCM_OFFSET, LENGTH = $DCCM_SIZE /* dedicated SRAM for the ROM stack */ + RAM (rwx) : ORIGIN = $DCCM_OFFSET, LENGTH = $DCCM_SIZE - $HANDOFF_SIZE /* dedicated SRAM for the ROM stack */ HANDOFF (rw) : ORIGIN = $HANDOFF_OFFSET, LENGTH = $HANDOFF_SIZE } @@ -107,6 +110,14 @@ ESTACK_SIZE = $ROM_ESTACK_SIZE; "#; fn main() { - let ld_script = subst::substitute(ROM_LD_TEMPLATE, &EMULATOR_MEMORY_MAP.hash_map()).unwrap(); + let platform = std::env::args() + .nth(1) + .expect("usage: generate_rom_ld "); + let memory_map = match platform.as_str() { + "emulator" => &EMULATOR_MEMORY_MAP, + "fpga" => &FPGA_MEMORY_MAP, + other => panic!("unknown platform {other:?}; expected emulator or fpga"), + }; + let ld_script = subst::substitute(ROM_LD_TEMPLATE, &memory_map.hash_map()).unwrap(); println!("{ld_script}"); } diff --git a/third_party/caliptra/caliptra-mcu-sw/src/signer_main.rs b/third_party/caliptra/caliptra-mcu-sw/src/signer_main.rs index 53954c908..76198eba3 100644 --- a/third_party/caliptra/caliptra-mcu-sw/src/signer_main.rs +++ b/third_party/caliptra/caliptra-mcu-sw/src/signer_main.rs @@ -13,6 +13,8 @@ use caliptra_image_crypto::RustCrypto as Crypto; use caliptra_image_fake_keys::*; use caliptra_image_gen::{from_hw_format, ImageGeneratorCrypto}; use caliptra_image_types::FwVerificationPqcKeyType; +use caliptra_mcu_config_emulator::EMULATOR_MEMORY_MAP; +use caliptra_mcu_config_fpga::FPGA_MEMORY_MAP; use clap::{Parser, Subcommand}; use std::path::PathBuf; use zerocopy::IntoBytes; @@ -41,10 +43,16 @@ enum Commands { enum AuthManifestCommands { /// Create an Authentication Manifest (SoC manifest) Create { - /// MCU Image: ,,,, + /// MCU Image: either (requires --platform) or + /// ,,,,[,] #[arg(long = "mcu_image")] mcu_image: String, + /// Platform ("emulator" or "fpga") used to derive default MCU image + /// load/staging addresses when --mcu_image only specifies a path. + #[arg(long = "platform")] + platform: Option, + /// Path to caliptra ROM binary (accepted for compatibility, not used in manifest) #[arg(long = "caliptra_rom")] caliptra_rom: Option, @@ -63,12 +71,51 @@ enum AuthManifestCommands { }, } -/// Parse an image config string: "path,load_addr,staging_addr,image_id,exec_bit[,component_id]" -fn parse_image_cfg(s: &str) -> Result<(PathBuf, u64, u64, u32, u32, u32)> { +/// Default `(load_addr, staging_addr)` for a platform, mirroring upstream +/// `CaliptraBuilder::get_mcu_manifest_metadata` (`builder/src/caliptra.rs`). +fn default_mcu_image_addrs(platform: &str) -> Result<(u64, u64)> { + match platform { + "emulator" => Ok((EMULATOR_MEMORY_MAP.sram_offset as u64, 0)), + "fpga" => { + // FPGA uses external staging SRAM; mirrors upstream + // `CaliptraBuilder::get_mcu_manifest_metadata`. + const STAGING_MEMORY_MAP: u64 = 0xB00C_0000; + const STAGING_MEMORY_SIZE: u64 = 0x0004_0000; // 256 KB + const MAX_MCU_FW_SIZE: u64 = 0x3EC00; + let staging_addr = STAGING_MEMORY_MAP + STAGING_MEMORY_SIZE - MAX_MCU_FW_SIZE; + let load_addr = FPGA_MEMORY_MAP.sram_offset as u64; + Ok((load_addr, staging_addr)) + } + other => bail!("unknown platform {other:?}; expected emulator or fpga"), + } +} + +/// Parse an image config string: either "" (using `platform` defaults) or +/// ",,,,[,]". +fn parse_image_cfg(s: &str, platform: Option<&str>) -> Result<(PathBuf, u64, u64, u32, u32, u32)> { + const MCU_RT_IDENTIFIER: u32 = 2; + const DEFAULT_EXEC_BIT: u32 = 2; + let parts: Vec<&str> = s.split(',').collect(); + if parts.len() == 1 { + let platform = platform.ok_or_else(|| { + anyhow::anyhow!( + "--platform () is required when --mcu_image only specifies a path" + ) + })?; + let (load_addr, staging_addr) = default_mcu_image_addrs(platform)?; + return Ok(( + PathBuf::from(parts[0]), + load_addr, + staging_addr, + MCU_RT_IDENTIFIER, + DEFAULT_EXEC_BIT, + MCU_RT_IDENTIFIER, + )); + } if parts.len() < 5 { bail!( - "Expected at least 5 comma-separated fields (path,load_addr,staging_addr,image_id,exec_bit), got {}", + "Expected either (with --platform) or at least 5 comma-separated fields (path,load_addr,staging_addr,image_id,exec_bit), got {}", parts.len() ); } @@ -212,10 +259,13 @@ fn main() -> Result<()> { Commands::Experimental(cmd) => firmware_bundler::execute(cmd), Commands::AuthManifest { subcommand } => match subcommand { AuthManifestCommands::Create { - mcu_image, output, .. + mcu_image, + platform, + output, + .. } => { let (path, load_addr, staging_addr, image_id, exec_bit, component_id) = - parse_image_cfg(&mcu_image)?; + parse_image_cfg(&mcu_image, platform.as_deref())?; let metadata = create_image_metadata( &path, diff --git a/third_party/caliptra/caliptra-sw/BUILD.bazel b/third_party/caliptra/caliptra-sw/BUILD.bazel index fd417bbdf..70fb9d489 100644 --- a/third_party/caliptra/caliptra-sw/BUILD.bazel +++ b/third_party/caliptra/caliptra-sw/BUILD.bazel @@ -215,10 +215,15 @@ _FIRMWARE_LIB_RUSTC_FLAGS = [ rust_library( name = "caliptra_drivers", srcs = ["@caliptra_sw//:all_files"], + # Upstream's FPGA Caliptra ROM/FW builds enable `fpga_realtime`, which only + # switches the DMA path in drivers/src/dma.rs. crate_features = [ "cfi", "rom", - ], + ] + select({ + "//third_party/caliptra:platform_fpga": ["fpga_realtime"], + "//conditions:default": [], + }), crate_root = "@caliptra_sw//:drivers/src/lib.rs", edition = "2021", proc_macro_deps = [ @@ -252,7 +257,10 @@ rust_library( crate_features = [ "cfi", "fmc", - ], + ] + select({ + "//third_party/caliptra:platform_fpga": ["fpga_realtime"], + "//conditions:default": [], + }), crate_name = "caliptra_drivers", crate_root = "@caliptra_sw//:drivers/src/lib.rs", edition = "2021", @@ -290,7 +298,10 @@ rust_library( crate_features = [ "cfi", "runtime", - ], + ] + select({ + "//third_party/caliptra:platform_fpga": ["fpga_realtime"], + "//conditions:default": [], + }), crate_name = "caliptra_drivers", crate_root = "@caliptra_sw//:drivers/src/lib.rs", edition = "2021", diff --git a/third_party/caliptra/caliptra_build.bzl b/third_party/caliptra/caliptra_build.bzl index e2133ee1e..de649d2b0 100644 --- a/third_party/caliptra/caliptra_build.bzl +++ b/third_party/caliptra/caliptra_build.bzl @@ -79,13 +79,12 @@ def caliptra_objcopy(name, src, out = None, format = "binary", rom_size = None, "d.extend(b\"\\x00\" * (sz - len(d))); " + "d[doff:] = hashlib.sha384(d[:doff]).digest(); " + "open(dst_p, \"wb\").write(d)" + - "' $@.tmp $@ {rom_size}" + "' $@.tmp $@ " ).format( objcopy = _LLVM_OBJCOPY, fmt = format, src = src, - rom_size = rom_size, - ) + ) + (str(rom_size) if type(rom_size) == "int" else rom_size) else: cmd = "$(execpath {objcopy}) -O {fmt} $(location {src}) $@".format( objcopy = _LLVM_OBJCOPY, @@ -181,7 +180,7 @@ def caliptra_firmware_bundle(name, fmc, runtime, out = None, bundler = None, **k # caliptra_linker_script # --------------------------------------------------------------------------- -def caliptra_linker_script(name, generator, out, **kwargs): +def caliptra_linker_script(name, generator, out, args = [], **kwargs): """Generate a linker script using a Rust host binary. Runs a host tool that writes a linker script to stdout, capturing the @@ -191,12 +190,13 @@ def caliptra_linker_script(name, generator, out, **kwargs): name: Target name. generator: Label of the host binary that produces the linker script. out: Output filename for the linker script. + args: Command-line arguments passed to the generator. **kwargs: Extra arguments forwarded to genrule. """ native.genrule( name = name, outs = [out], - cmd = "$(location {gen}) > $@".format(gen = generator), + cmd = " ".join(["$(location {gen})".format(gen = generator)] + args + ["> $@"]), tools = [generator], **kwargs )