1 // 2 // Copyright (C) 2022 The Android Open Source Project 3 // 4 // Licensed under the Apache License, Version 2.0 (the "License"); 5 // you may not use this file except in compliance with the License. 6 // You may obtain a copy of the License at 7 // 8 // http://www.apache.org/licenses/LICENSE-2.0 9 // 10 // Unless required by applicable law or agreed to in writing, software 11 // distributed under the License is distributed on an "AS IS" BASIS, 12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 // See the License for the specific language governing permissions and 14 // limitations under the License. 15 16 #pragma once 17 18 #include <optional> 19 #include <string> 20 #include <utility> 21 #include <vector> 22 23 #include "common/libs/utils/environment.h" 24 25 namespace cuttlefish { 26 27 class AndroidEfiLoaderEspBuilder final { 28 public: 29 AndroidEfiLoaderEspBuilder() = delete; AndroidEfiLoaderEspBuilder(std::string image_path)30 AndroidEfiLoaderEspBuilder(std::string image_path) 31 : image_path_(std::move(image_path)) {} 32 33 AndroidEfiLoaderEspBuilder& EfiLoaderPath(std::string efi_loader_path) &; 34 AndroidEfiLoaderEspBuilder& Architecture(Arch arch) &; 35 36 bool Build() const; 37 38 private: 39 const std::string image_path_; 40 std::string efi_loader_path_; 41 Arch arch_; 42 }; 43 44 class LinuxEspBuilder final { 45 public: 46 LinuxEspBuilder() = delete; LinuxEspBuilder(std::string image_path)47 LinuxEspBuilder(std::string image_path): image_path_(std::move(image_path)) {} 48 49 LinuxEspBuilder& Argument(std::string key, std::string value) &; 50 LinuxEspBuilder& Argument(std::string value) &; 51 LinuxEspBuilder& Root(std::string root) &; 52 LinuxEspBuilder& Kernel(std::string kernel) &; 53 LinuxEspBuilder& Initrd(std::string initrd) &; 54 LinuxEspBuilder& Architecture(Arch arch) &; 55 56 bool Build() const; 57 58 private: 59 std::string DumpConfig() const; 60 61 const std::string image_path_; 62 std::vector<std::pair<std::string, std::string>> arguments_; 63 std::vector<std::string> single_arguments_; 64 std::string root_; 65 std::string kernel_; 66 std::string initrd_; 67 std::optional<Arch> arch_; 68 }; 69 70 class FuchsiaEspBuilder { 71 public: 72 FuchsiaEspBuilder() = delete; FuchsiaEspBuilder(std::string image_path)73 FuchsiaEspBuilder(std::string image_path): image_path_(std::move(image_path)) {} 74 75 FuchsiaEspBuilder& MultibootBinary(std::string multiboot) &; 76 FuchsiaEspBuilder& Zedboot(std::string zedboot) &; 77 FuchsiaEspBuilder& Architecture(Arch arch) &; 78 79 bool Build() const; 80 81 private: 82 std::string DumpConfig() const; 83 84 const std::string image_path_; 85 std::string multiboot_bin_; 86 std::string zedboot_; 87 std::optional<Arch> arch_; 88 }; 89 90 bool NewfsMsdos(const std::string& data_image, int data_image_mb, 91 int offset_num_mb); 92 93 bool CanGenerateEsp(Arch arch); 94 95 } // namespace cuttlefish 96