| Lorenz Brun | 1dc60af | 2023-10-03 15:40:09 +0200 | [diff] [blame] | 1 | def _node_image_impl(ctx): |
| 2 | img_file = ctx.actions.declare_file(ctx.label.name + ".img") |
| Tim Windelschmidt | 8e19fa4 | 2024-11-12 13:39:43 +0000 | [diff] [blame] | 3 | |
| 4 | arguments = ctx.actions.args() |
| 5 | arguments.add_all([ |
| Jan Schär | 4b88826 | 2025-05-13 09:12:03 +0000 | [diff] [blame] | 6 | "-architecture", |
| 7 | ctx.attr.architecture, |
| Tim Windelschmidt | 8e19fa4 | 2024-11-12 13:39:43 +0000 | [diff] [blame] | 8 | "-efi", |
| 9 | ctx.file.kernel.path, |
| 10 | "-system", |
| 11 | ctx.file.system.path, |
| 12 | "-abloader", |
| 13 | ctx.file.abloader.path, |
| 14 | "-out", |
| 15 | img_file.path, |
| 16 | ]) |
| 17 | |
| 18 | if len(ctx.files.bios_bootcode) != 0: |
| 19 | arguments.add_all(["-bios_bootcode", ctx.file.bios_bootcode.path]) |
| 20 | |
| Lorenz Brun | 1dc60af | 2023-10-03 15:40:09 +0200 | [diff] [blame] | 21 | ctx.actions.run( |
| 22 | mnemonic = "MkImage", |
| 23 | executable = ctx.executable._mkimage, |
| Tim Windelschmidt | 8e19fa4 | 2024-11-12 13:39:43 +0000 | [diff] [blame] | 24 | arguments = [arguments], |
| Lorenz Brun | 1dc60af | 2023-10-03 15:40:09 +0200 | [diff] [blame] | 25 | inputs = [ |
| 26 | ctx.file.kernel, |
| 27 | ctx.file.system, |
| Tim Windelschmidt | 272c830 | 2024-11-05 05:17:44 +0100 | [diff] [blame] | 28 | ctx.file.abloader, |
| Tim Windelschmidt | 8e19fa4 | 2024-11-12 13:39:43 +0000 | [diff] [blame] | 29 | ctx.file.bios_bootcode, |
| Lorenz Brun | 1dc60af | 2023-10-03 15:40:09 +0200 | [diff] [blame] | 30 | ], |
| 31 | outputs = [img_file], |
| 32 | ) |
| 33 | |
| 34 | return [DefaultInfo(files = depset([img_file]), runfiles = ctx.runfiles(files = [img_file]))] |
| 35 | |
| Jan Schär | 4b88826 | 2025-05-13 09:12:03 +0000 | [diff] [blame] | 36 | _node_image = rule( |
| Lorenz Brun | 1dc60af | 2023-10-03 15:40:09 +0200 | [diff] [blame] | 37 | implementation = _node_image_impl, |
| 38 | doc = """ |
| Tim Windelschmidt | 272c830 | 2024-11-05 05:17:44 +0100 | [diff] [blame] | 39 | Build a disk image from an EFI kernel payload, ABLoader and system partition |
| Tim Windelschmidt | c2290c2 | 2024-08-15 19:56:00 +0200 | [diff] [blame] | 40 | contents. See //osbase/build/mkimage for more information. |
| Lorenz Brun | 1dc60af | 2023-10-03 15:40:09 +0200 | [diff] [blame] | 41 | """, |
| 42 | attrs = { |
| Jan Schär | 4b88826 | 2025-05-13 09:12:03 +0000 | [diff] [blame] | 43 | "architecture": attr.string(mandatory = True), |
| Lorenz Brun | 1dc60af | 2023-10-03 15:40:09 +0200 | [diff] [blame] | 44 | "kernel": attr.label( |
| 45 | doc = "EFI binary containing a kernel.", |
| 46 | mandatory = True, |
| 47 | allow_single_file = True, |
| 48 | ), |
| 49 | "system": attr.label( |
| 50 | doc = "Contents of the system partition.", |
| 51 | mandatory = True, |
| 52 | allow_single_file = True, |
| 53 | ), |
| Tim Windelschmidt | 272c830 | 2024-11-05 05:17:44 +0100 | [diff] [blame] | 54 | "abloader": attr.label( |
| 55 | doc = "ABLoader binary", |
| 56 | mandatory = True, |
| 57 | allow_single_file = True, |
| 58 | ), |
| Tim Windelschmidt | 8e19fa4 | 2024-11-12 13:39:43 +0000 | [diff] [blame] | 59 | "bios_bootcode": attr.label( |
| 60 | doc = """ |
| 61 | Optional label to the BIOS bootcode which gets placed at the start of the first block of the image. |
| 62 | Limited to 440 bytes, padding is not required. It is only used by legacy BIOS boot. |
| 63 | """, |
| 64 | mandatory = False, |
| 65 | allow_single_file = True, |
| 66 | ), |
| Lorenz Brun | 1dc60af | 2023-10-03 15:40:09 +0200 | [diff] [blame] | 67 | "_mkimage": attr.label( |
| 68 | doc = "The mkimage executable.", |
| Tim Windelschmidt | c2290c2 | 2024-08-15 19:56:00 +0200 | [diff] [blame] | 69 | default = "//osbase/build/mkimage", |
| Lorenz Brun | 1dc60af | 2023-10-03 15:40:09 +0200 | [diff] [blame] | 70 | allow_single_file = True, |
| 71 | executable = True, |
| 72 | cfg = "exec", |
| 73 | ), |
| 74 | }, |
| 75 | ) |
| Jan Schär | 4b88826 | 2025-05-13 09:12:03 +0000 | [diff] [blame] | 76 | |
| 77 | def _node_image_macro_impl(**kwargs): |
| 78 | _node_image( |
| 79 | architecture = select({ |
| 80 | "@platforms//cpu:x86_64": "x86_64", |
| 81 | "@platforms//cpu:aarch64": "aarch64", |
| 82 | }), |
| 83 | **kwargs |
| 84 | ) |
| 85 | |
| 86 | node_image = macro( |
| 87 | inherit_attrs = _node_image, |
| 88 | attrs = {"architecture": None}, |
| 89 | implementation = _node_image_macro_impl, |
| 90 | ) |