在BdsEntry->BdsBootDeviceSelect->BdsLibBootViaBootOption 这个函数中下面这段code
Handle = BdsLibGetBootableHandle(DevicePath);
if (Handle != NULL) {
//
// Load the default boot file \EFI\BOOT\boot{machinename}.EFI from removable Media
// machinename is ia32, ia64, x64, …
//
FilePath = FileDevicePath (Handle, EFI_REMOVABLE_MEDIA_FILE_NAME);
if (FilePath != NULL) {
REPORT_STATUS_CODE (EFI_PROGRESS_CODE, PcdGet32 (PcdProgressCodeOsLoaderLoad));
Status = gBS->LoadImage (
TRUE,
gImageHandle,
FilePath,
NULL,
0,
&ImageHandle
);
}
}
}
这里的filepath是通过EFI_REMOVABLE_MEDIA_FILE_NAME 这个变量来找到的
#define EFI_REMOVABLE_MEDIA_FILE_NAME_IA32 L”\\EFI\\BOOT\\BOOTIA32.EFI”
#define EFI_REMOVABLE_MEDIA_FILE_NAME_IA64 L”\\EFI\\BOOT\\BOOTIA64.EFI”
#define EFI_REMOVABLE_MEDIA_FILE_NAME_X64 L”\\EFI\\BOOT\\BOOTX64.EFI”
#define EFI_REMOVABLE_MEDIA_FILE_NAME_ARM L”\\EFI\\BOOT\\BOOTARM.EFI”
#define EFI_REMOVABLE_MEDIA_FILE_NAME_AARCH64 L”\\EFI\\GRUB2\\grubaa64.efi”
#if defined (MDE_CPU_IA32)
#define EFI_REMOVABLE_MEDIA_FILE_NAME EFI_REMOVABLE_MEDIA_FILE_NAME_IA32
#elif defined (MDE_CPU_IPF)
#define EFI_REMOVABLE_MEDIA_FILE_NAME EFI_REMOVABLE_MEDIA_FILE_NAME_IA64
#elif defined (MDE_CPU_X64)
#define EFI_REMOVABLE_MEDIA_FILE_NAME EFI_REMOVABLE_MEDIA_FILE_NAME_X64
#elif defined (MDE_CPU_EBC)
#elif defined (MDE_CPU_ARM)
#define EFI_REMOVABLE_MEDIA_FILE_NAME EFI_REMOVABLE_MEDIA_FILE_NAME_ARM
#elif defined (MDE_CPU_AARCH64)
#define EFI_REMOVABLE_MEDIA_FILE_NAME EFI_REMOVABLE_MEDIA_FILE_NAME_AARCH64
#else
#error Unknown Processor Type
#endif
由于我们是MDE_CPU_AARCH64,因此EFI_REMOVABLE_MEDIA_FILE_NAME 就等于L”\\EFI\\GRUB2\\grubaa64.efi”
因此在BdsLibBootViaBootOption 中通过gBS->LoadImage 来找到grubaa64.efi,最后还是在BdsLibBootViaBootOption 中通过下面的code Status = gBS->StartImage (ImageHandle, ExitDataSize, ExitData);来跳转到grub的第一行代码。