blob: 3faa7753ebb7a10b13e1500c74dea9b286b3004d [file] [log] [blame]
Lorenz Brun80deba52022-02-24 17:07:13 +01001def _cpio_ucode_impl(ctx):
2 ucode_spec = ctx.actions.declare_file(ctx.label.name + "_spec.prototxt")
3
4 vendors = []
5 inputs = []
6 for label, vendor in ctx.attr.ucode.items():
7 files = label[DefaultInfo].files.to_list()
8 inputs += files
9 vendors.append(struct(id = vendor, file = [f.path for f in files]))
10
11 ctx.actions.write(ucode_spec, proto.encode_text(struct(vendor = vendors)))
12
13 output_file = ctx.actions.declare_file(ctx.label.name + ".cpio")
14 ctx.actions.run(
15 outputs = [output_file],
16 inputs = [ucode_spec] + inputs,
17 tools = [ctx.executable._mkucode],
18 executable = ctx.executable._mkucode,
19 arguments = ["-out", output_file.path, "-spec", ucode_spec.path],
20 )
21 return [DefaultInfo(files = depset([output_file]))]
22
23cpio_ucode = rule(
24 implementation = _cpio_ucode_impl,
25 doc = """
26 Builds a cpio archive with microcode for the Linux early microcode loader.
27 """,
28 attrs = {
29 "ucode": attr.label_keyed_string_dict(
30 mandatory = True,
31 allow_files = True,
32 doc = """
33 Dictionary of Labels to String. Each label is a list of microcode files and the string label
34 is the vendor ID corresponding to that microcode.
35 """,
36 ),
37
38 # Tool
39 "_mkucode": attr.label(
40 default = Label("//metropolis/node/build/mkucode"),
41 executable = True,
42 cfg = "exec",
43 ),
44 },
45)