Skip to content

Commit c3e057a

Browse files
sungminwonrmuthiah
authored andcommitted
Cuttlefish host : Add x86-64 EFI boot support
Support booting Linux with x86-64 EFI by adding handling for bootx64.efi and related GRUB modules. This change updates boot configuration and ESP image generation to properly support x86-64 architecture, enabling improved compatibility for x86-64 virtual devices. Bug: N/A Test: Verified x86-64 boot sequence with new EFI binaries Change-Id: Ifcbc5d5224ae2644253dc5519de523fbc0fccee4 Signed-off-by: sungmin.won <[email protected]>
1 parent 1cd77ae commit c3e057a

File tree

2 files changed

+34
-10
lines changed

2 files changed

+34
-10
lines changed

base/cvd/cuttlefish/host/commands/assemble_cvd/boot_config.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,10 @@ void WriteEFIEnvironment(const CuttlefishConfig::InstanceSpecific& instance,
7979
partition_str +
8080
"load virtio 0:${devplist} ${loadaddr} efi/boot/bootaa64.efi "
8181
"&& bootefi ${loadaddr} ${fdtcontroladdr}; "
82+
"load virtio 0:${devplist} ${loadaddr} efi/boot/bootx64.efi && "
83+
"bootefi ${loadaddr} ${fdtcontroladdr}; "
8284
"load virtio 0:${devplist} ${loadaddr} efi/boot/bootia32.efi && "
83-
"bootefi ${loadaddr} ${fdtcontroladdr};"
85+
"bootefi ${loadaddr} ${fdtcontroladdr}; "
8486
"load virtio 0:${devplist} ${loadaddr} efi/boot/bootriscv64.efi && "
8587
"bootefi ${loadaddr} ${fdtcontroladdr}",
8688
instance, env);

base/cvd/cuttlefish/host/libs/config/esp.cpp

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ static constexpr char kBootSrcPathIA32[] =
6262
"/usr/lib/grub/i386-efi/monolithic/grubia32.efi";
6363
static constexpr char kBootDestPathIA32[] = "/EFI/BOOT/BOOTIA32.EFI";
6464

65+
static constexpr char kBootSrcPathX64[] =
66+
"/usr/lib/grub/x86_64-efi/monolithic/grubx64.efi";
67+
static constexpr char kBootDestPathX64[] = "/EFI/BOOT/BOOTX64.EFI";
68+
6569
static constexpr char kBootSrcPathAA64[] =
6670
"/usr/lib/grub/arm64-efi/monolithic/grubaa64.efi";
6771
static constexpr char kBootDestPathAA64[] = "/EFI/BOOT/BOOTAA64.EFI";
@@ -73,6 +77,11 @@ static constexpr char kMultibootModuleSrcPathIA32[] =
7377
static constexpr char kMultibootModuleDestPathIA32[] =
7478
"/EFI/modules/multiboot.mod";
7579

80+
static constexpr char kMultibootModuleSrcPathX64[] =
81+
"/usr/lib/grub/x86_64-efi/multiboot.mod";
82+
static constexpr char kMultibootModuleDestPathX64[] =
83+
"/EFI/modules/multiboot.mod";
84+
7685
static constexpr char kMultibootModuleSrcPathAA64[] =
7786
"/usr/lib/grub/arm64-efi/multiboot.mod";
7887
static constexpr char kMultibootModuleDestPathAA64[] =
@@ -95,6 +104,7 @@ static constexpr std::array kGrubModulesX86{
95104
"cat", "help", "fat", "part_msdos", "part_gpt"};
96105
static constexpr char kGrubModulesPath[] = "/usr/lib/grub/";
97106
static constexpr char kGrubModulesX86Name[] = "i386-efi";
107+
static constexpr char kGrubModulesX64Name[] = "x86_64-efi";
98108

99109
Result<void> MakeFatImage(const std::string& data_image, int data_image_mb,
100110
int offset_num_mb) {
@@ -318,22 +328,36 @@ EspBuilder PrepareESP(const std::string& image_path, Arch arch) {
318328
case Arch::RiscV64:
319329
// FIXME: Implement
320330
break;
321-
case Arch::X86:
322-
case Arch::X86_64: {
331+
case Arch::X86: {
323332
const auto x86_modules = std::string(kGrubModulesPath) + std::string(kGrubModulesX86Name);
324333

325334
if (GrubMakeImage(kGrubConfigDestDirectoryPath, kGrubModulesX86Name,
326335
x86_modules, efi_path, kGrubModulesX86)) {
327-
LOG(INFO) << "Loading grub_mkimage generated EFI binary";
336+
LOG(INFO) << "Loading grub_mkimage generated EFI binary for X86";
328337
builder.File(efi_path, kBootDestPathIA32, /* required */ true);
329338
} else {
330-
LOG(INFO) << "Loading prebuilt monolith EFI binary";
339+
LOG(INFO) << "Loading prebuilt monolith EFI binary for X86";
331340
builder.File(kBootSrcPathIA32, kBootDestPathIA32, /* required */ true);
332341
builder.File(kMultibootModuleSrcPathIA32, kMultibootModuleDestPathIA32,
333342
/* required */ true);
334343
}
335344
break;
336345
}
346+
case Arch::X86_64: {
347+
const auto x64_modules = std::string(kGrubModulesPath) + std::string(kGrubModulesX64Name);
348+
349+
if (GrubMakeImage(kGrubConfigDestDirectoryPath, kGrubModulesX64Name,
350+
x64_modules, efi_path, kGrubModulesX86)) {
351+
LOG(INFO) << "Loading grub_mkimage generated EFI binary for X86_64";
352+
builder.File(efi_path, kBootDestPathX64, /* required */ true);
353+
} else {
354+
LOG(INFO) << "Loading prebuilt monolith EFI binary for X86_64";
355+
builder.File(kBootSrcPathX64, kBootDestPathX64, /* required */ true);
356+
builder.File(kMultibootModuleSrcPathX64, kMultibootModuleDestPathX64,
357+
/* required */ true);
358+
}
359+
break;
360+
}
337361
}
338362

339363
return builder;
@@ -386,13 +410,11 @@ bool AndroidEfiLoaderEspBuilder::Build() const {
386410
dest_path = kBootDestPathRiscV64;
387411
break;
388412
case Arch::X86:
389-
case Arch::X86_64: {
390413
dest_path = kBootDestPathIA32;
391414
break;
392-
default:
393-
LOG(ERROR) << "Unknown architecture";
394-
return false;
395-
}
415+
case Arch::X86_64:
416+
dest_path = kBootDestPathX64;
417+
break;
396418
}
397419
builder.File(efi_loader_path_, dest_path, /* required */ true);
398420
return builder.Build();

0 commit comments

Comments
 (0)