blob: b8239f544d5e3c5c07d6c03095ad7761f34cc811 [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([
Jan Schär4b888262025-05-13 09:12:03 +00006 "-architecture",
7 ctx.attr.architecture,
Tim Windelschmidt8e19fa42024-11-12 13:39:43 +00008 "-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 Brun1dc60af2023-10-03 15:40:09 +020021 ctx.actions.run(
22 mnemonic = "MkImage",
23 executable = ctx.executable._mkimage,
Tim Windelschmidt8e19fa42024-11-12 13:39:43 +000024 arguments = [arguments],
Lorenz Brun1dc60af2023-10-03 15:40:09 +020025 inputs = [
26 ctx.file.kernel,
27 ctx.file.system,
Tim Windelschmidt272c8302024-11-05 05:17:44 +010028 ctx.file.abloader,
Tim Windelschmidt8e19fa42024-11-12 13:39:43 +000029 ctx.file.bios_bootcode,
Lorenz Brun1dc60af2023-10-03 15:40:09 +020030 ],
31 outputs = [img_file],
32 )
33
34 return [DefaultInfo(files = depset([img_file]), runfiles = ctx.runfiles(files = [img_file]))]
35
Jan Schär4b888262025-05-13 09:12:03 +000036_node_image = rule(
Lorenz Brun1dc60af2023-10-03 15:40:09 +020037 implementation = _node_image_impl,
38 doc = """
Tim Windelschmidt272c8302024-11-05 05:17:44 +010039 Build a disk image from an EFI kernel payload, ABLoader and system partition
Tim Windelschmidtc2290c22024-08-15 19:56:00 +020040 contents. See //osbase/build/mkimage for more information.
Lorenz Brun1dc60af2023-10-03 15:40:09 +020041 """,
42 attrs = {
Jan Schär4b888262025-05-13 09:12:03 +000043 "architecture": attr.string(mandatory = True),
Lorenz Brun1dc60af2023-10-03 15:40:09 +020044 "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 Windelschmidt272c8302024-11-05 05:17:44 +010054 "abloader": attr.label(
55 doc = "ABLoader binary",
56 mandatory = True,
57 allow_single_file = True,
58 ),
Tim Windelschmidt8e19fa42024-11-12 13:39:43 +000059 "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 Brun1dc60af2023-10-03 15:40:09 +020067 "_mkimage": attr.label(
68 doc = "The mkimage executable.",
Tim Windelschmidtc2290c22024-08-15 19:56:00 +020069 default = "//osbase/build/mkimage",
Lorenz Brun1dc60af2023-10-03 15:40:09 +020070 allow_single_file = True,
71 executable = True,
72 cfg = "exec",
73 ),
74 },
75)
Jan Schär4b888262025-05-13 09:12:03 +000076
77def _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
86node_image = macro(
87 inherit_attrs = _node_image,
88 attrs = {"architecture": None},
89 implementation = _node_image_macro_impl,
90)