blob: 11760607a30a7dbe3c227580e5aeb9763901ad23 [file] [log] [blame]
Tim Windelschmidtbed76d92025-02-18 03:04:14 +01001# VerityInfo is emitted by verity_image, and contains a file enclosing a
2# singular dm-verity target table.
3VerityInfo = provider(
4 "Information necessary to mount a single dm-verity target.",
5 fields = {
6 "table": "A file containing the dm-verity target table. See: https://www.kernel.org/doc/html/latest/admin-guide/device-mapper/verity.html",
7 },
8)
9
10def _verity_image_impl(ctx):
11 """
12 Create a new file containing the source image data together with the Verity
13 metadata appended to it, and provide an associated DeviceMapper Verity target
14 table in a separate file, through VerityInfo provider.
15 """
16
17 # Run mkverity.
18 image = ctx.actions.declare_file(ctx.attr.name + ".img")
19 table = ctx.actions.declare_file(ctx.attr.name + ".dmt")
Jan Schär2add1cb2025-07-14 09:26:18 +000020 inputs = [ctx.file.source]
21 args = ctx.actions.args()
22 args.add("-input", ctx.file.source)
23 args.add("-output", image)
24 if ctx.file.salt:
25 args.add("-salt", ctx.file.salt)
26 inputs.append(ctx.file.salt)
27 args.add("-table", table)
28 args.add("-data_alias", ctx.attr.rootfs_partlabel)
29 args.add("-hash_alias", ctx.attr.rootfs_partlabel)
Tim Windelschmidtbed76d92025-02-18 03:04:14 +010030 ctx.actions.run(
31 mnemonic = "GenVerityImage",
32 progress_message = "Generating a dm-verity image: {}".format(image.short_path),
Jan Schär2add1cb2025-07-14 09:26:18 +000033 inputs = inputs,
34 outputs = [image, table],
Tim Windelschmidtbed76d92025-02-18 03:04:14 +010035 executable = ctx.file._mkverity,
Jan Schär2add1cb2025-07-14 09:26:18 +000036 arguments = [args],
Tim Windelschmidtbed76d92025-02-18 03:04:14 +010037 )
38
39 return [
40 DefaultInfo(
41 files = depset([image]),
42 runfiles = ctx.runfiles(files = [image]),
43 ),
44 VerityInfo(
45 table = table,
46 ),
47 ]
48
49verity_image = rule(
Tim Windelschmidtbed76d92025-02-18 03:04:14 +010050 implementation = _verity_image_impl,
51 doc = """
52 Build a dm-verity target image by appending Verity metadata to the source
53 image. A corresponding dm-verity target table will be made available
54 through VerityInfo provider.
55 """,
56 attrs = {
57 "source": attr.label(
58 doc = "A source image.",
59 allow_single_file = True,
Jan Schär2add1cb2025-07-14 09:26:18 +000060 mandatory = True,
61 ),
62 "salt": attr.label(
63 doc = """
64 A file which will be hashed to generate the salt.
65 This should be a small file which is different for each
66 released image, but which only changes when the source also
67 changes. The product info file is a good choice for this.
68 """,
69 allow_single_file = True,
Tim Windelschmidtbed76d92025-02-18 03:04:14 +010070 ),
71 "rootfs_partlabel": attr.string(
72 doc = "GPT partition label of the rootfs to be used with dm-mod.create.",
73 default = "PARTLABEL=METROPOLIS-SYSTEM-X",
74 ),
75 "_mkverity": attr.label(
76 doc = "The mkverity executable needed to generate the image.",
77 default = "//osbase/build/mkverity",
78 allow_single_file = True,
79 executable = True,
80 cfg = "exec",
81 ),
82 },
83)