Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
fork

Configure Feed

Select the types of activity you want to include in your feed.

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>

authored by

Matt Fleming and committed by
H. Peter Anvin
9fa7deda 30dc0d0f

+75 -16
+69 -16
arch/x86/boot/compressed/eboot.c
··· 16 16 17 17 static efi_system_table_t *sys_table; 18 18 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 + 19 39 static efi_status_t __get_map(efi_memory_desc_t **map, unsigned long *map_size, 20 40 unsigned long *desc_size) 21 41 { ··· 551 531 EFI_LOADER_DATA, 552 532 nr_initrds * sizeof(*initrds), 553 533 &initrds); 554 - if (status != EFI_SUCCESS) 534 + if (status != EFI_SUCCESS) { 535 + efi_printk("Failed to alloc mem for initrds\n"); 555 536 goto fail; 537 + } 556 538 557 539 str = (char *)(unsigned long)hdr->cmd_line_ptr; 558 540 for (i = 0; i < nr_initrds; i++) { ··· 597 575 598 576 status = efi_call_phys3(boottime->handle_protocol, 599 577 image->device_handle, &fs_proto, &io); 600 - if (status != EFI_SUCCESS) 578 + if (status != EFI_SUCCESS) { 579 + efi_printk("Failed to handle fs_proto\n"); 601 580 goto free_initrds; 581 + } 602 582 603 583 status = efi_call_phys2(io->open_volume, io, &fh); 604 - if (status != EFI_SUCCESS) 584 + if (status != EFI_SUCCESS) { 585 + efi_printk("Failed to open volume\n"); 605 586 goto free_initrds; 587 + } 606 588 } 607 589 608 590 status = efi_call_phys5(fh->open, fh, &h, filename_16, 609 591 EFI_FILE_MODE_READ, (u64)0); 610 - if (status != EFI_SUCCESS) 592 + if (status != EFI_SUCCESS) { 593 + efi_printk("Failed to open initrd file\n"); 611 594 goto close_handles; 595 + } 612 596 613 597 initrd->handle = h; 614 598 615 599 info_sz = 0; 616 600 status = efi_call_phys4(h->get_info, h, &info_guid, 617 601 &info_sz, NULL); 618 - if (status != EFI_BUFFER_TOO_SMALL) 602 + if (status != EFI_BUFFER_TOO_SMALL) { 603 + efi_printk("Failed to get initrd info size\n"); 619 604 goto close_handles; 605 + } 620 606 621 607 grow: 622 608 status = efi_call_phys3(sys_table->boottime->allocate_pool, 623 609 EFI_LOADER_DATA, info_sz, &info); 624 - if (status != EFI_SUCCESS) 610 + if (status != EFI_SUCCESS) { 611 + efi_printk("Failed to alloc mem for initrd info\n"); 625 612 goto close_handles; 613 + } 626 614 627 615 status = efi_call_phys4(h->get_info, h, &info_guid, 628 616 &info_sz, info); ··· 644 612 file_sz = info->file_size; 645 613 efi_call_phys1(sys_table->boottime->free_pool, info); 646 614 647 - if (status != EFI_SUCCESS) 615 + if (status != EFI_SUCCESS) { 616 + efi_printk("Failed to get initrd info\n"); 648 617 goto close_handles; 618 + } 649 619 650 620 initrd->size = file_sz; 651 621 initrd_total += file_sz; ··· 663 629 */ 664 630 status = high_alloc(initrd_total, 0x1000, 665 631 &initrd_addr, hdr->initrd_addr_max); 666 - if (status != EFI_SUCCESS) 632 + if (status != EFI_SUCCESS) { 633 + efi_printk("Failed to alloc highmem for initrds\n"); 667 634 goto close_handles; 635 + } 668 636 669 637 /* We've run out of free low memory. */ 670 638 if (initrd_addr > hdr->initrd_addr_max) { 639 + efi_printk("We've run out of free low memory\n"); 671 640 status = EFI_INVALID_PARAMETER; 672 641 goto free_initrd_total; 673 642 } ··· 689 652 status = efi_call_phys3(fh->read, 690 653 initrds[j].handle, 691 654 &chunksize, addr); 692 - if (status != EFI_SUCCESS) 655 + if (status != EFI_SUCCESS) { 656 + efi_printk("Failed to read initrd\n"); 693 657 goto free_initrd_total; 658 + } 694 659 addr += chunksize; 695 660 size -= chunksize; 696 661 } ··· 771 732 options_size++; /* NUL termination */ 772 733 773 734 status = low_alloc(options_size, 1, &cmdline); 774 - if (status != EFI_SUCCESS) 735 + if (status != EFI_SUCCESS) { 736 + efi_printk("Failed to alloc mem for cmdline\n"); 775 737 goto fail; 738 + } 776 739 777 740 s1 = (u8 *)(unsigned long)cmdline; 778 741 s2 = (u16 *)options; ··· 936 895 937 896 status = efi_call_phys3(sys_table->boottime->handle_protocol, 938 897 handle, &proto, (void *)&image); 939 - if (status != EFI_SUCCESS) 898 + if (status != EFI_SUCCESS) { 899 + efi_printk("Failed to get handle for LOADED_IMAGE_PROTOCOL\n"); 940 900 goto fail; 901 + } 941 902 942 903 status = low_alloc(0x4000, 1, (unsigned long *)&boot_params); 943 - if (status != EFI_SUCCESS) 904 + if (status != EFI_SUCCESS) { 905 + efi_printk("Failed to alloc lowmem for boot params\n"); 944 906 goto fail; 907 + } 945 908 946 909 memset(boot_params, 0x0, 0x4000); 947 910 ··· 978 933 if (status != EFI_SUCCESS) { 979 934 status = low_alloc(hdr->init_size, hdr->kernel_alignment, 980 935 &start); 981 - if (status != EFI_SUCCESS) 936 + if (status != EFI_SUCCESS) { 937 + efi_printk("Failed to alloc mem for kernel\n"); 982 938 goto fail; 939 + } 983 940 } 984 941 985 942 hdr->code32_start = (__u32)start; ··· 992 945 status = efi_call_phys3(sys_table->boottime->allocate_pool, 993 946 EFI_LOADER_DATA, sizeof(*gdt), 994 947 (void **)&gdt); 995 - if (status != EFI_SUCCESS) 948 + if (status != EFI_SUCCESS) { 949 + efi_printk("Failed to alloc mem for gdt structure\n"); 996 950 goto fail; 951 + } 997 952 998 953 gdt->size = 0x800; 999 954 status = low_alloc(gdt->size, 8, (unsigned long *)&gdt->address); 1000 - if (status != EFI_SUCCESS) 955 + if (status != EFI_SUCCESS) { 956 + efi_printk("Failed to alloc mem for gdt\n"); 1001 957 goto fail; 958 + } 1002 959 1003 960 status = efi_call_phys3(sys_table->boottime->allocate_pool, 1004 961 EFI_LOADER_DATA, sizeof(*idt), 1005 962 (void **)&idt); 1006 - if (status != EFI_SUCCESS) 963 + if (status != EFI_SUCCESS) { 964 + efi_printk("Failed to alloc mem for idt structure\n"); 1007 965 goto fail; 966 + } 1008 967 1009 968 idt->size = 0; 1010 969 idt->address = 0;
+6
arch/x86/boot/compressed/eboot.h
··· 58 58 void *blt; 59 59 }; 60 60 61 + struct efi_simple_text_output_protocol { 62 + void *reset; 63 + void *output_string; 64 + void *test_string; 65 + }; 66 + 61 67 #endif /* BOOT_COMPRESSED_EBOOT_H */