blob: 154009ee33ac8672274e3e41263eb5986b3e000c [file] [log] [blame]
Lorenz Brun17c4c8b2022-02-01 12:59:47 +01001load("//metropolis/node/build:def.bzl", "FSSpecInfo")
2
3def _fsspec_linux_firmware(ctx):
4 fsspec_out = ctx.actions.declare_file(ctx.label.name + ".prototxt")
5
6 fwlist = ctx.actions.declare_file(ctx.label.name + "-fwlist.txt")
7 ctx.actions.write(
8 output = fwlist,
9 content = "\n".join([f.path for f in ctx.files.firmware_files]),
10 )
11
12 modinfo = ctx.attr.kernel[OutputGroupInfo].modinfo.to_list()[0]
Lorenz Brun6c454342023-06-01 12:23:38 +020013 modules = ctx.attr.kernel[OutputGroupInfo].modules.to_list()[0]
14
15 meta_out = ctx.actions.declare_file(ctx.label.name + "-meta.pb")
Lorenz Brun17c4c8b2022-02-01 12:59:47 +010016
17 ctx.actions.run(
Lorenz Brun6c454342023-06-01 12:23:38 +020018 outputs = [fsspec_out, meta_out],
19 inputs = [fwlist, modinfo, modules, ctx.file.metadata] + ctx.files.firmware_files,
Lorenz Brun17c4c8b2022-02-01 12:59:47 +010020 tools = [ctx.executable._fwprune],
21 executable = ctx.executable._fwprune,
Lorenz Brun6c454342023-06-01 12:23:38 +020022 arguments = [
23 "-modinfo",
24 modinfo.path,
25 "-modules",
26 modules.path,
27 "-firmware-file-list",
28 fwlist.path,
29 "-firmware-whence",
30 ctx.file.metadata.path,
31 "-out-meta",
32 meta_out.path,
33 "-out-fsspec",
34 fsspec_out.path,
35 ],
Lorenz Brun17c4c8b2022-02-01 12:59:47 +010036 )
37
Lorenz Brun6c454342023-06-01 12:23:38 +020038 return [DefaultInfo(files = depset([fsspec_out])), FSSpecInfo(spec = fsspec_out, referenced = ctx.files.firmware_files + [modules, meta_out])]
Lorenz Brun17c4c8b2022-02-01 12:59:47 +010039
40fsspec_linux_firmware = rule(
41 implementation = _fsspec_linux_firmware,
42 doc = """
43 Generates a partial filesystem spec containing all firmware files required by a given kernel at the
44 default firmware load path (/lib/firmware).
45 """,
46 attrs = {
47 "firmware_files": attr.label_list(
48 mandatory = True,
49 allow_files = True,
50 doc = """
51 List of firmware files. Generally at least a filegroup of the linux-firmware repository should
52 be in here.
53 """,
54 ),
Lorenz Brund3ce0ac2022-03-03 12:51:21 +010055 "metadata": attr.label(
56 mandatory = True,
57 allow_single_file = True,
58 doc = """
59 The metadata file for the Linux firmware. Currently this is the WHENCE file at the root of the
60 linux-firmware repository. Used for resolving additional links.
61 """,
62 ),
Lorenz Brun17c4c8b2022-02-01 12:59:47 +010063 "kernel": attr.label(
64 doc = """
65 Kernel for which firmware should be selected. Needs to have a modinfo OutputGroup.
66 """,
67 ),
68
69 # Tool
70 "_fwprune": attr.label(
71 default = Label("//metropolis/node/build/fwprune"),
72 executable = True,
73 cfg = "exec",
74 ),
75 },
76)