blob: 33323d7ee5de09bfbebe2924379d77e78ddb969d [file] [log] [blame]
Lorenz Brun1dc60af2023-10-03 15:40:09 +02001def _node_image_impl(ctx):
2 img_file = ctx.actions.declare_file(ctx.label.name + ".img")
Tim Windelschmidt8e19fa42024-11-12 13:39:43 +00003
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 Brun1dc60af2023-10-03 15:40:09 +020019 ctx.actions.run(
20 mnemonic = "MkImage",
21 executable = ctx.executable._mkimage,
Tim Windelschmidt8e19fa42024-11-12 13:39:43 +000022 arguments = [arguments],
Lorenz Brun1dc60af2023-10-03 15:40:09 +020023 inputs = [
24 ctx.file.kernel,
25 ctx.file.system,
Tim Windelschmidt272c8302024-11-05 05:17:44 +010026 ctx.file.abloader,
Tim Windelschmidt8e19fa42024-11-12 13:39:43 +000027 ctx.file.bios_bootcode,
Lorenz Brun1dc60af2023-10-03 15:40:09 +020028 ],
29 outputs = [img_file],
30 )
31
32 return [DefaultInfo(files = depset([img_file]), runfiles = ctx.runfiles(files = [img_file]))]
33
34node_image = rule(
35 implementation = _node_image_impl,
36 doc = """
Tim Windelschmidt272c8302024-11-05 05:17:44 +010037 Build a disk image from an EFI kernel payload, ABLoader and system partition
Tim Windelschmidtc2290c22024-08-15 19:56:00 +020038 contents. See //osbase/build/mkimage for more information.
Lorenz Brun1dc60af2023-10-03 15:40:09 +020039 """,
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 Windelschmidt272c8302024-11-05 05:17:44 +010051 "abloader": attr.label(
52 doc = "ABLoader binary",
53 mandatory = True,
54 allow_single_file = True,
55 ),
Tim Windelschmidt8e19fa42024-11-12 13:39:43 +000056 "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 Brun1dc60af2023-10-03 15:40:09 +020064 "_mkimage": attr.label(
65 doc = "The mkimage executable.",
Tim Windelschmidtc2290c22024-08-15 19:56:00 +020066 default = "//osbase/build/mkimage",
Lorenz Brun1dc60af2023-10-03 15:40:09 +020067 allow_single_file = True,
68 executable = True,
69 cfg = "exec",
70 ),
71 },
72)