Changeset View
Changeset View
Standalone View
Standalone View
sys/boot/efi/loader/bootinfo.c
Show First 20 Lines • Show All 284 Lines • ▼ Show 20 Lines | for (retry = 2; retry > 0; retry--) { | ||||
BS->GetMemoryMap(&sz, NULL, &efi_mapkey, &mmsz, &mmver); | BS->GetMemoryMap(&sz, NULL, &efi_mapkey, &mmsz, &mmver); | ||||
sz += mmsz; | sz += mmsz; | ||||
sz = (sz + 0xf) & ~0xf; | sz = (sz + 0xf) & ~0xf; | ||||
pages = EFI_SIZE_TO_PAGES(sz + efisz); | pages = EFI_SIZE_TO_PAGES(sz + efisz); | ||||
status = BS->AllocatePages(AllocateAnyPages, EfiLoaderData, | status = BS->AllocatePages(AllocateAnyPages, EfiLoaderData, | ||||
pages, &addr); | pages, &addr); | ||||
if (EFI_ERROR(status)) { | if (EFI_ERROR(status)) { | ||||
printf("%s: AllocatePages error %lu\n", __func__, | printf("%s: AllocatePages error %lu\n", __func__, | ||||
(unsigned long)(status & ~EFI_ERROR_MASK)); | EFI_ERROR_CODE(status)); | ||||
return (ENOMEM); | return (ENOMEM); | ||||
} | } | ||||
/* | /* | ||||
* Read the memory map and stash it after bootinfo. Align the | * Read the memory map and stash it after bootinfo. Align the | ||||
* memory map on a 16-byte boundary (the bootinfo block is page | * memory map on a 16-byte boundary (the bootinfo block is page | ||||
* aligned). | * aligned). | ||||
*/ | */ | ||||
efihdr = (struct efi_map_header *)addr; | efihdr = (struct efi_map_header *)addr; | ||||
mm = (void *)((uint8_t *)efihdr + efisz); | mm = (void *)((uint8_t *)efihdr + efisz); | ||||
sz = (EFI_PAGE_SIZE * pages) - efisz; | sz = (EFI_PAGE_SIZE * pages) - efisz; | ||||
status = BS->GetMemoryMap(&sz, mm, &efi_mapkey, &mmsz, &mmver); | status = BS->GetMemoryMap(&sz, mm, &efi_mapkey, &mmsz, &mmver); | ||||
if (EFI_ERROR(status)) { | if (EFI_ERROR(status)) { | ||||
printf("%s: GetMemoryMap error %lu\n", __func__, | printf("%s: GetMemoryMap error %lu\n", __func__, | ||||
(unsigned long)(status & ~EFI_ERROR_MASK)); | EFI_ERROR_CODE(status)); | ||||
return (EINVAL); | return (EINVAL); | ||||
} | } | ||||
status = BS->ExitBootServices(IH, efi_mapkey); | status = BS->ExitBootServices(IH, efi_mapkey); | ||||
if (EFI_ERROR(status) == 0) { | if (EFI_ERROR(status) == 0) { | ||||
efihdr->memory_size = sz; | efihdr->memory_size = sz; | ||||
efihdr->descriptor_size = mmsz; | efihdr->descriptor_size = mmsz; | ||||
efihdr->descriptor_version = mmver; | efihdr->descriptor_version = mmver; | ||||
file_addmetadata(kfp, MODINFOMD_EFI_MAP, efisz + sz, | file_addmetadata(kfp, MODINFOMD_EFI_MAP, efisz + sz, | ||||
efihdr); | efihdr); | ||||
return (0); | return (0); | ||||
} | } | ||||
BS->FreePages(addr, pages); | BS->FreePages(addr, pages); | ||||
} | } | ||||
printf("ExitBootServices error %lu\n", | printf("ExitBootServices error %lu\n", EFI_ERROR_CODE(status)); | ||||
(unsigned long)(status & ~EFI_ERROR_MASK)); | |||||
return (EINVAL); | return (EINVAL); | ||||
} | } | ||||
/* | /* | ||||
* Load the information expected by an amd64 kernel. | * Load the information expected by an amd64 kernel. | ||||
* | * | ||||
* - The 'boothowto' argument is constructed. | * - The 'boothowto' argument is constructed. | ||||
* - The 'bootdev' argument is constructed. | * - The 'bootdev' argument is constructed. | ||||
▲ Show 20 Lines • Show All 130 Lines • Show Last 20 Lines |