• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright (C) 2023 The Android Open Source Project
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7#     http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15load("@gbl//toolchain:gbl_toolchain.bzl", "build_with_platform")
16load("@gbl_llvm_prebuilts//:info.bzl", "gbl_llvm_tool_path")
17load("@rules_rust//rust:defs.bzl", "rust_binary")
18
19package(
20    default_visibility = ["//visibility:public"],
21)
22
23rust_binary(
24    name = "main",
25    srcs = [
26        "src/android_boot.rs",
27        "src/avb.rs",
28        "src/error.rs",
29        "src/fastboot.rs",
30        "src/fuchsia_boot.rs",
31        "src/main.rs",
32        "src/net.rs",
33        "src/riscv64.rs",
34        "src/utils.rs",
35    ],
36    linker_script = select({
37        "@gbl//toolchain:gbl_rust_elf_riscv64": "@gbl//efi/arch/riscv64:riscv64_efi.lds",
38        "//conditions:default": None,
39    }),
40    rustc_flags = [
41        "-C",
42        "panic=abort",
43    ],
44    deps = [
45        "@avb",
46        "@avb//:avb_crypto_ops_sha_impl_staticlib",
47        "@gbl//libavb:sysdeps",
48        "@gbl//libboot",
49        "@gbl//libbootconfig",
50        "@gbl//libbootimg",
51        "@gbl//libefi",
52        "@gbl//libfastboot",
53        "@gbl//libfdt",
54        "@gbl//libgbl",
55        "@gbl//libmisc",
56        "@gbl//libstorage",
57        "@gbl//third_party/libzbi",
58        "@smoltcp",
59        "@uuid",
60        "@zerocopy",
61    ] + select({
62        "@gbl//toolchain:gbl_rust_elf_riscv64": ["@gbl//efi/arch/riscv64:efi_arch_deps_riscv64"],
63        "@gbl//toolchain:gbl_rust_uefi_x86_64": ["@gbl//efi/arch/x86_64:efi_arch_deps_x86_64"],
64        "@gbl//toolchain:gbl_rust_uefi_x86_32": ["@gbl//efi/arch/x86:efi_arch_deps_x86"],
65        "//conditions:default": [],
66    }),
67)
68
69genrule(
70    name = "gbl_efi",
71    srcs = [":main"],
72    outs = ["gbl.efi"],
73    cmd = select({
74        # For RISCV target, existing toolchain can only generate ELF format image.
75        # The current solution is to manually add a PE/COFF header at image
76        # start and use objcopy to remove the ELF header to make it a PE/COFF image.
77        # Also use `elf_static_relocation_checker` to check that our relocation library
78        # can handle all the generated relocation types. The following expands to two commands:
79        #
80        # 1. `llvm-objcopy <elf image> -O binary <efi image>`
81        # 2. `elf_static_relocation_checker <elf image> <efi image>`
82        "@gbl//toolchain:gbl_rust_elf_riscv64": """
83            {} -O binary $(location @gbl//efi:main) $(OUTS) && \\
84            $(location @gbl//libelf:elf_static_relocation_checker) $(SRCS) $(OUTS)
85        """.format(gbl_llvm_tool_path("llvm-objcopy")),
86        "//conditions:default": "cp $(SRCS) $(OUTS)",
87    }),
88    tools = select({
89        "@gbl//toolchain:gbl_rust_elf_riscv64": ["@gbl//libelf:elf_static_relocation_checker"],
90        "//conditions:default": [],
91    }),
92)
93
94build_with_platform(
95    name = "x86_64",
96    platform = "@gbl//toolchain:gbl_uefi_x86_64",
97    deps = [":gbl_efi"],
98)
99
100build_with_platform(
101    name = "x86_32",
102    platform = "@gbl//toolchain:gbl_uefi_x86_32",
103    deps = [":gbl_efi"],
104)
105
106build_with_platform(
107    name = "aarch64",
108    platform = "@gbl//toolchain:gbl_uefi_aarch64",
109    deps = [":gbl_efi"],
110)
111
112build_with_platform(
113    name = "riscv64",
114    platform = "@gbl//toolchain:gbl_elf_riscv64",
115    deps = [":gbl_efi"],
116)
117
118filegroup(
119    name = "all_platforms",
120    srcs = [
121        ":aarch64",
122        ":riscv64",
123        ":x86_32",
124        ":x86_64",
125    ],
126)
127