Lorenz Brun | 17c4c8b | 2022-02-01 12:59:47 +0100 | [diff] [blame] | 1 | load("//metropolis/node/build:def.bzl", "FSSpecInfo") |
| 2 | |
| 3 | def _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 Brun | 6c45434 | 2023-06-01 12:23:38 +0200 | [diff] [blame^] | 13 | modules = ctx.attr.kernel[OutputGroupInfo].modules.to_list()[0] |
| 14 | |
| 15 | meta_out = ctx.actions.declare_file(ctx.label.name + "-meta.pb") |
Lorenz Brun | 17c4c8b | 2022-02-01 12:59:47 +0100 | [diff] [blame] | 16 | |
| 17 | ctx.actions.run( |
Lorenz Brun | 6c45434 | 2023-06-01 12:23:38 +0200 | [diff] [blame^] | 18 | outputs = [fsspec_out, meta_out], |
| 19 | inputs = [fwlist, modinfo, modules, ctx.file.metadata] + ctx.files.firmware_files, |
Lorenz Brun | 17c4c8b | 2022-02-01 12:59:47 +0100 | [diff] [blame] | 20 | tools = [ctx.executable._fwprune], |
| 21 | executable = ctx.executable._fwprune, |
Lorenz Brun | 6c45434 | 2023-06-01 12:23:38 +0200 | [diff] [blame^] | 22 | 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 Brun | 17c4c8b | 2022-02-01 12:59:47 +0100 | [diff] [blame] | 36 | ) |
| 37 | |
Lorenz Brun | 6c45434 | 2023-06-01 12:23:38 +0200 | [diff] [blame^] | 38 | return [DefaultInfo(files = depset([fsspec_out])), FSSpecInfo(spec = fsspec_out, referenced = ctx.files.firmware_files + [modules, meta_out])] |
Lorenz Brun | 17c4c8b | 2022-02-01 12:59:47 +0100 | [diff] [blame] | 39 | |
| 40 | fsspec_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 Brun | d3ce0ac | 2022-03-03 12:51:21 +0100 | [diff] [blame] | 55 | "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 Brun | 17c4c8b | 2022-02-01 12:59:47 +0100 | [diff] [blame] | 63 | "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 | ) |