Skip to content

Commit 9fa7ded

Browse files
Matt FlemingH. Peter Anvin
authored andcommitted
x86, efi; Add EFI boot stub console support
We need a way of printing useful messages to the user, for example when we fail to open an initrd file, instead of just hanging the machine without giving the user any indication of what went wrong. So sprinkle some error messages throughout the EFI boot stub code to make it easier for users to diagnose/report problems. Reported-by: Keshav P R <the.ridikulus.rat@gmail.com> Cc: Matthew Garrett <mjg@redhat.com> Signed-off-by: Matt Fleming <matt.fleming@intel.com> Link: http://lkml.kernel.org/r/1331907517-3985-3-git-send-email-matt@console-pimps.org Signed-off-by: H. Peter Anvin <hpa@zytor.com>
1 parent 30dc0d0 commit 9fa7ded

File tree

2 files changed

+75
-16
lines changed

2 files changed

+75
-16
lines changed

arch/x86/boot/compressed/eboot.c

Lines changed: 69 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,26 @@
1616

1717
static efi_system_table_t *sys_table;
1818

19+
static void efi_printk(char *str)
20+
{
21+
char *s8;
22+
23+
for (s8 = str; *s8; s8++) {
24+
struct efi_simple_text_output_protocol *out;
25+
efi_char16_t ch[2] = { 0 };
26+
27+
ch[0] = *s8;
28+
out = (struct efi_simple_text_output_protocol *)sys_table->con_out;
29+
30+
if (*s8 == '\n') {
31+
efi_char16_t nl[2] = { '\r', 0 };
32+
efi_call_phys2(out->output_string, out, nl);
33+
}
34+
35+
efi_call_phys2(out->output_string, out, ch);
36+
}
37+
}
38+
1939
static efi_status_t __get_map(efi_memory_desc_t **map, unsigned long *map_size,
2040
unsigned long *desc_size)
2141
{
@@ -531,8 +551,10 @@ static efi_status_t handle_ramdisks(efi_loaded_image_t *image,
531551
EFI_LOADER_DATA,
532552
nr_initrds * sizeof(*initrds),
533553
&initrds);
534-
if (status != EFI_SUCCESS)
554+
if (status != EFI_SUCCESS) {
555+
efi_printk("Failed to alloc mem for initrds\n");
535556
goto fail;
557+
}
536558

537559
str = (char *)(unsigned long)hdr->cmd_line_ptr;
538560
for (i = 0; i < nr_initrds; i++) {
@@ -575,32 +597,42 @@ static efi_status_t handle_ramdisks(efi_loaded_image_t *image,
575597

576598
status = efi_call_phys3(boottime->handle_protocol,
577599
image->device_handle, &fs_proto, &io);
578-
if (status != EFI_SUCCESS)
600+
if (status != EFI_SUCCESS) {
601+
efi_printk("Failed to handle fs_proto\n");
579602
goto free_initrds;
603+
}
580604

581605
status = efi_call_phys2(io->open_volume, io, &fh);
582-
if (status != EFI_SUCCESS)
606+
if (status != EFI_SUCCESS) {
607+
efi_printk("Failed to open volume\n");
583608
goto free_initrds;
609+
}
584610
}
585611

586612
status = efi_call_phys5(fh->open, fh, &h, filename_16,
587613
EFI_FILE_MODE_READ, (u64)0);
588-
if (status != EFI_SUCCESS)
614+
if (status != EFI_SUCCESS) {
615+
efi_printk("Failed to open initrd file\n");
589616
goto close_handles;
617+
}
590618

591619
initrd->handle = h;
592620

593621
info_sz = 0;
594622
status = efi_call_phys4(h->get_info, h, &info_guid,
595623
&info_sz, NULL);
596-
if (status != EFI_BUFFER_TOO_SMALL)
624+
if (status != EFI_BUFFER_TOO_SMALL) {
625+
efi_printk("Failed to get initrd info size\n");
597626
goto close_handles;
627+
}
598628

599629
grow:
600630
status = efi_call_phys3(sys_table->boottime->allocate_pool,
601631
EFI_LOADER_DATA, info_sz, &info);
602-
if (status != EFI_SUCCESS)
632+
if (status != EFI_SUCCESS) {
633+
efi_printk("Failed to alloc mem for initrd info\n");
603634
goto close_handles;
635+
}
604636

605637
status = efi_call_phys4(h->get_info, h, &info_guid,
606638
&info_sz, info);
@@ -612,8 +644,10 @@ static efi_status_t handle_ramdisks(efi_loaded_image_t *image,
612644
file_sz = info->file_size;
613645
efi_call_phys1(sys_table->boottime->free_pool, info);
614646

615-
if (status != EFI_SUCCESS)
647+
if (status != EFI_SUCCESS) {
648+
efi_printk("Failed to get initrd info\n");
616649
goto close_handles;
650+
}
617651

618652
initrd->size = file_sz;
619653
initrd_total += file_sz;
@@ -629,11 +663,14 @@ static efi_status_t handle_ramdisks(efi_loaded_image_t *image,
629663
*/
630664
status = high_alloc(initrd_total, 0x1000,
631665
&initrd_addr, hdr->initrd_addr_max);
632-
if (status != EFI_SUCCESS)
666+
if (status != EFI_SUCCESS) {
667+
efi_printk("Failed to alloc highmem for initrds\n");
633668
goto close_handles;
669+
}
634670

635671
/* We've run out of free low memory. */
636672
if (initrd_addr > hdr->initrd_addr_max) {
673+
efi_printk("We've run out of free low memory\n");
637674
status = EFI_INVALID_PARAMETER;
638675
goto free_initrd_total;
639676
}
@@ -652,8 +689,10 @@ static efi_status_t handle_ramdisks(efi_loaded_image_t *image,
652689
status = efi_call_phys3(fh->read,
653690
initrds[j].handle,
654691
&chunksize, addr);
655-
if (status != EFI_SUCCESS)
692+
if (status != EFI_SUCCESS) {
693+
efi_printk("Failed to read initrd\n");
656694
goto free_initrd_total;
695+
}
657696
addr += chunksize;
658697
size -= chunksize;
659698
}
@@ -732,8 +771,10 @@ static efi_status_t make_boot_params(struct boot_params *boot_params,
732771
options_size++; /* NUL termination */
733772

734773
status = low_alloc(options_size, 1, &cmdline);
735-
if (status != EFI_SUCCESS)
774+
if (status != EFI_SUCCESS) {
775+
efi_printk("Failed to alloc mem for cmdline\n");
736776
goto fail;
777+
}
737778

738779
s1 = (u8 *)(unsigned long)cmdline;
739780
s2 = (u16 *)options;
@@ -895,12 +936,16 @@ struct boot_params *efi_main(void *handle, efi_system_table_t *_table)
895936

896937
status = efi_call_phys3(sys_table->boottime->handle_protocol,
897938
handle, &proto, (void *)&image);
898-
if (status != EFI_SUCCESS)
939+
if (status != EFI_SUCCESS) {
940+
efi_printk("Failed to get handle for LOADED_IMAGE_PROTOCOL\n");
899941
goto fail;
942+
}
900943

901944
status = low_alloc(0x4000, 1, (unsigned long *)&boot_params);
902-
if (status != EFI_SUCCESS)
945+
if (status != EFI_SUCCESS) {
946+
efi_printk("Failed to alloc lowmem for boot params\n");
903947
goto fail;
948+
}
904949

905950
memset(boot_params, 0x0, 0x4000);
906951

@@ -933,8 +978,10 @@ struct boot_params *efi_main(void *handle, efi_system_table_t *_table)
933978
if (status != EFI_SUCCESS) {
934979
status = low_alloc(hdr->init_size, hdr->kernel_alignment,
935980
&start);
936-
if (status != EFI_SUCCESS)
981+
if (status != EFI_SUCCESS) {
982+
efi_printk("Failed to alloc mem for kernel\n");
937983
goto fail;
984+
}
938985
}
939986

940987
hdr->code32_start = (__u32)start;
@@ -945,19 +992,25 @@ struct boot_params *efi_main(void *handle, efi_system_table_t *_table)
945992
status = efi_call_phys3(sys_table->boottime->allocate_pool,
946993
EFI_LOADER_DATA, sizeof(*gdt),
947994
(void **)&gdt);
948-
if (status != EFI_SUCCESS)
995+
if (status != EFI_SUCCESS) {
996+
efi_printk("Failed to alloc mem for gdt structure\n");
949997
goto fail;
998+
}
950999

9511000
gdt->size = 0x800;
9521001
status = low_alloc(gdt->size, 8, (unsigned long *)&gdt->address);
953-
if (status != EFI_SUCCESS)
1002+
if (status != EFI_SUCCESS) {
1003+
efi_printk("Failed to alloc mem for gdt\n");
9541004
goto fail;
1005+
}
9551006

9561007
status = efi_call_phys3(sys_table->boottime->allocate_pool,
9571008
EFI_LOADER_DATA, sizeof(*idt),
9581009
(void **)&idt);
959-
if (status != EFI_SUCCESS)
1010+
if (status != EFI_SUCCESS) {
1011+
efi_printk("Failed to alloc mem for idt structure\n");
9601012
goto fail;
1013+
}
9611014

9621015
idt->size = 0;
9631016
idt->address = 0;

arch/x86/boot/compressed/eboot.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,10 @@ struct efi_uga_draw_protocol {
5858
void *blt;
5959
};
6060

61+
struct efi_simple_text_output_protocol {
62+
void *reset;
63+
void *output_string;
64+
void *test_string;
65+
};
66+
6167
#endif /* BOOT_COMPRESSED_EBOOT_H */

0 commit comments

Comments
 (0)