Skip to content

Commit bd1f0d3

Browse files
pamaurycfrantz
authored andcommitted
[bazel,manuf] New architecture for provisioning extensions
Signed-off-by: Amaury Pouly <amaury.pouly@opentitan.org>
1 parent f2ad308 commit bd1f0d3

13 files changed

Lines changed: 158 additions & 43 deletions

File tree

MODULE.bazel

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -346,18 +346,37 @@ hooks.repo(
346346
dummy = "@lowrisc_opentitan//:sw/device/tests/closed_source",
347347
env = "SECURE_MANUFACTURER_HOOKS_DIR",
348348
)
349-
hooks.repo(
350-
name = "provisioning_exts",
351-
dummy = "@lowrisc_opentitan//:sw/device/silicon_creator/manuf/extensions",
352-
env = "PROV_EXTS_DIR",
353-
)
354349
use_repo(
355350
hooks,
356351
"manufacturer_test_hooks",
357-
"provisioning_exts",
358352
"secure_manufacturer_test_hooks",
359353
)
360354

355+
# Provisioning extension module, use --override_module to point to the non-dummy implementation.
356+
# Note: downstream infrastructure searches for this bazel_dep by regex to determine if we're
357+
# using the legacy PROV_EXTS_DIR environment variable or the new override commandline flag.
358+
bazel_dep(name = "ot_provisioning_exts", version = "1.0.1")
359+
360+
# Dummy repository, can be overriden on the command-line to point to ot-sku
361+
local_path_override(
362+
module_name = "ot_provisioning_exts",
363+
path = "sw/device/silicon_creator/manuf/extensions",
364+
)
365+
366+
# We import an extension of the repository so that it can define extra repositories.
367+
provisioning_exts_extra = use_extension("@ot_provisioning_exts//:extension.bzl", "extra")
368+
369+
# We always import the provisioning_exts_extra repository so that it can be refered to by
370+
# the provisioning_exts repo defined below.
371+
use_repo(provisioning_exts_extra, "provisioning_exts_extra")
372+
373+
# We import the repo rule.
374+
provisioning_exts_hook = use_repo_rule("@ot_provisioning_exts//:hook.bzl", "hook")
375+
376+
# Crucially, this repository is injected into the OT module so it can freely depend on everything the OT repo depends on.
377+
# At the same time, it can also depend on everything in @ot_provisioning_exts, which can contain arbitrary stuff.
378+
provisioning_exts_hook(name = "provisioning_exts")
379+
361380
register_toolchains("//rules/opentitan:localtools")
362381

363382
register_toolchains("//toolchain:cc_toolchain_opentitan")

MODULE.bazel.lock

Lines changed: 42 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sw/device/silicon_creator/manuf/extensions/BUILD.bazel

Lines changed: 4 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,7 @@
22
# Licensed under the Apache License, Version 2.0, see LICENSE for details.
33
# SPDX-License-Identifier: Apache-2.0
44

5-
load("@rules_rust//rust:defs.bzl", "rust_library")
6-
7-
package(default_visibility = ["//visibility:public"])
8-
9-
cc_library(
10-
name = "default_perso_fw_ext",
11-
srcs = ["default_personalize_ext.c"],
12-
deps = [
13-
"@//sw/device/lib/dif:flash_ctrl",
14-
"@//sw/device/lib/testing/json:provisioning_data",
15-
"@//sw/device/lib/testing/test_framework:status",
16-
"@//sw/device/lib/testing/test_framework:ujson_ottf",
17-
"@//sw/device/silicon_creator/lib/cert",
18-
"@//sw/device/silicon_creator/manuf/base:personalize_ext",
19-
"@//sw/device/silicon_creator/manuf/lib:flash_info_fields",
20-
],
21-
)
22-
23-
rust_library(
24-
name = "default_ft_ext_lib",
25-
srcs = ["default_ft_ext_lib.rs"],
26-
crate_name = "ft_ext_lib",
27-
deps = [
28-
"@//sw/host/provisioning/util_lib",
29-
"@crate_index//:anyhow",
30-
"@crate_index//:arrayvec",
31-
],
32-
)
5+
exports_files([
6+
"hook.bzl",
7+
"extension.bzl",
8+
])

sw/device/silicon_creator/manuf/extensions/WORKSPACE.bazel renamed to sw/device/silicon_creator/manuf/extensions/MODULE.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# Licensed under the Apache License, Version 2.0, see LICENSE for details.
33
# SPDX-License-Identifier: Apache-2.0
44

5-
workspace(name = "provisioning_exts")
5+
module(name = "ot_provisioning_exts")
66

77
# This is a sample workspace to demonstrate how to write custom provisioning
88
# flow extensions. This bazel repository is not stand-alone project: it must
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Copyright lowRISC contributors (OpenTitan project).
2+
# Licensed under the Apache License, Version 2.0, see LICENSE for details.
3+
# SPDX-License-Identifier: Apache-2.0
4+
5+
# Make sure that the directories below are not considered part
6+
# of the repository. They are made available # to the OT repository
7+
# by the `hook` repository rule and the `extra` extension.
8+
ignore_directories(["repo", "extra"])
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Copyright lowRISC contributors (OpenTitan project).
2+
# Licensed under the Apache License, Version 2.0, see LICENSE for details.
3+
# SPDX-License-Identifier: Apache-2.0
4+
5+
load("@bazel_tools//tools/build_defs/repo:local.bzl", "local_repository")
6+
7+
def _extra_repo_impl(rctx):
8+
# This is basically a reimplementation of local_repository but doing
9+
# so avoids crafting paths manually in the extension which end up putting
10+
# absolute paths in the lock file. The issue fundamentally boils down to
11+
# the fact that when a repository extension executes, local_repository
12+
# treats path as relative to the *root* MODULE.bazel and not the extension's
13+
# MODULE.bazel
14+
src_dir = rctx.path(Label("@ot_provisioning_exts//:extra"))
15+
for p in src_dir.readdir():
16+
rctx.symlink(p, p.basename)
17+
18+
_extra_repo = repository_rule(
19+
implementation = _extra_repo_impl,
20+
)
21+
22+
def _extra_impl(mctx):
23+
_extra_repo(name = "provisioning_exts_extra")
24+
25+
extra = module_extension(
26+
implementation = _extra_impl,
27+
)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Copyright lowRISC contributors (OpenTitan project).
2+
# Licensed under the Apache License, Version 2.0, see LICENSE for details.
3+
# SPDX-License-Identifier: Apache-2.0
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Copyright lowRISC contributors (OpenTitan project).
2+
# Licensed under the Apache License, Version 2.0, see LICENSE for details.
3+
# SPDX-License-Identifier: Apache-2.0
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Copyright lowRISC contributors (OpenTitan project).
2+
# Licensed under the Apache License, Version 2.0, see LICENSE for details.
3+
# SPDX-License-Identifier: Apache-2.0
4+
5+
def _hook_impl(rctx):
6+
# This is basically a reimplementation of local_repository
7+
src_dir = rctx.path(Label("@ot_provisioning_exts//:repo"))
8+
for p in src_dir.readdir():
9+
rctx.symlink(p, p.basename)
10+
11+
hook = repository_rule(
12+
implementation = _hook_impl,
13+
)
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Copyright lowRISC contributors (OpenTitan project).
2+
# Licensed under the Apache License, Version 2.0, see LICENSE for details.
3+
# SPDX-License-Identifier: Apache-2.0
4+
5+
load("@rules_rust//rust:defs.bzl", "rust_library")
6+
7+
package(default_visibility = ["//visibility:public"])
8+
9+
cc_library(
10+
name = "default_perso_fw_ext",
11+
srcs = ["default_personalize_ext.c"],
12+
deps = [
13+
"@lowrisc_opentitan//sw/device/lib/dif:flash_ctrl",
14+
"@lowrisc_opentitan//sw/device/lib/testing/json:provisioning_data",
15+
"@lowrisc_opentitan//sw/device/lib/testing/test_framework:status",
16+
"@lowrisc_opentitan//sw/device/lib/testing/test_framework:ujson_ottf",
17+
"@lowrisc_opentitan//sw/device/silicon_creator/lib/cert",
18+
"@lowrisc_opentitan//sw/device/silicon_creator/manuf/base:personalize_ext",
19+
"@lowrisc_opentitan//sw/device/silicon_creator/manuf/lib:flash_info_fields",
20+
],
21+
)
22+
23+
rust_library(
24+
name = "default_ft_ext_lib",
25+
srcs = ["default_ft_ext_lib.rs"],
26+
crate_name = "ft_ext_lib",
27+
deps = [
28+
"@crate_index//:anyhow",
29+
"@crate_index//:arrayvec",
30+
"@lowrisc_opentitan//sw/host/provisioning/util_lib",
31+
],
32+
)

0 commit comments

Comments
 (0)