| 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([ |
| 6 | "-efi", |
| 7 | ctx.file.kernel.path, |
| 8 | "-system", |
| 9 | ctx.file.system.path, |
| 10 | "-abloader", |
| 11 | ctx.file.abloader.path, |
| 12 | "-out", |
| 13 | img_file.path, |
| 14 | ]) |
| 15 | |
| 16 | if len(ctx.files.bios_bootcode) != 0: |
| 17 | arguments.add_all(["-bios_bootcode", ctx.file.bios_bootcode.path]) |
| 18 | |
| Lorenz Brun | 1dc60af | 2023-10-03 15:40:09 +0200 | [diff] [blame] | 19 | ctx.actions.run( |
| 20 | mnemonic = "MkImage", |
| 21 | executable = ctx.executable._mkimage, |
| Tim Windelschmidt | 8e19fa4 | 2024-11-12 13:39:43 +0000 | [diff] [blame^] | 22 | arguments = [arguments], |
| Lorenz Brun | 1dc60af | 2023-10-03 15:40:09 +0200 | [diff] [blame] | 23 | inputs = [ |
| 24 | ctx.file.kernel, |
| 25 | ctx.file.system, |
| Tim Windelschmidt | 272c830 | 2024-11-05 05:17:44 +0100 | [diff] [blame] | 26 | ctx.file.abloader, |
| Tim Windelschmidt | 8e19fa4 | 2024-11-12 13:39:43 +0000 | [diff] [blame^] | 27 | ctx.file.bios_bootcode, |
| Lorenz Brun | 1dc60af | 2023-10-03 15:40:09 +0200 | [diff] [blame] | 28 | ], |
| 29 | outputs = [img_file], |
| 30 | ) |
| 31 | |
| 32 | return [DefaultInfo(files = depset([img_file]), runfiles = ctx.runfiles(files = [img_file]))] |
| 33 | |
| 34 | node_image = rule( |
| 35 | implementation = _node_image_impl, |
| 36 | doc = """ |
| Tim Windelschmidt | 272c830 | 2024-11-05 05:17:44 +0100 | [diff] [blame] | 37 | 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] | 38 | contents. See //osbase/build/mkimage for more information. |
| Lorenz Brun | 1dc60af | 2023-10-03 15:40:09 +0200 | [diff] [blame] | 39 | """, |
| 40 | attrs = { |
| 41 | "kernel": attr.label( |
| 42 | doc = "EFI binary containing a kernel.", |
| 43 | mandatory = True, |
| 44 | allow_single_file = True, |
| 45 | ), |
| 46 | "system": attr.label( |
| 47 | doc = "Contents of the system partition.", |
| 48 | mandatory = True, |
| 49 | allow_single_file = True, |
| 50 | ), |
| Tim Windelschmidt | 272c830 | 2024-11-05 05:17:44 +0100 | [diff] [blame] | 51 | "abloader": attr.label( |
| 52 | doc = "ABLoader binary", |
| 53 | mandatory = True, |
| 54 | allow_single_file = True, |
| 55 | ), |
| Tim Windelschmidt | 8e19fa4 | 2024-11-12 13:39:43 +0000 | [diff] [blame^] | 56 | "bios_bootcode": attr.label( |
| 57 | doc = """ |
| 58 | Optional label to the BIOS bootcode which gets placed at the start of the first block of the image. |
| 59 | Limited to 440 bytes, padding is not required. It is only used by legacy BIOS boot. |
| 60 | """, |
| 61 | mandatory = False, |
| 62 | allow_single_file = True, |
| 63 | ), |
| Lorenz Brun | 1dc60af | 2023-10-03 15:40:09 +0200 | [diff] [blame] | 64 | "_mkimage": attr.label( |
| 65 | doc = "The mkimage executable.", |
| Tim Windelschmidt | c2290c2 | 2024-08-15 19:56:00 +0200 | [diff] [blame] | 66 | default = "//osbase/build/mkimage", |
| Lorenz Brun | 1dc60af | 2023-10-03 15:40:09 +0200 | [diff] [blame] | 67 | allow_single_file = True, |
| 68 | executable = True, |
| 69 | cfg = "exec", |
| 70 | ), |
| 71 | }, |
| 72 | ) |