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
{
@@ -531,8 +551,10 @@ static efi_status_t handle_ramdisks(efi_loaded_image_t *image,
531
551
EFI_LOADER_DATA ,
532
552
nr_initrds * sizeof (* initrds ),
533
553
& initrds );
534
- if (status != EFI_SUCCESS )
554
+ if (status != EFI_SUCCESS ) {
555
+ efi_printk ("Failed to alloc mem for initrds\n" );
535
556
goto fail ;
557
+ }
536
558
537
559
str = (char * )(unsigned long )hdr -> cmd_line_ptr ;
538
560
for (i = 0 ; i < nr_initrds ; i ++ ) {
@@ -575,32 +597,42 @@ static efi_status_t handle_ramdisks(efi_loaded_image_t *image,
575
597
576
598
status = efi_call_phys3 (boottime -> handle_protocol ,
577
599
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" );
579
602
goto free_initrds ;
603
+ }
580
604
581
605
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" );
583
608
goto free_initrds ;
609
+ }
584
610
}
585
611
586
612
status = efi_call_phys5 (fh -> open , fh , & h , filename_16 ,
587
613
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" );
589
616
goto close_handles ;
617
+ }
590
618
591
619
initrd -> handle = h ;
592
620
593
621
info_sz = 0 ;
594
622
status = efi_call_phys4 (h -> get_info , h , & info_guid ,
595
623
& 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" );
597
626
goto close_handles ;
627
+ }
598
628
599
629
grow :
600
630
status = efi_call_phys3 (sys_table -> boottime -> allocate_pool ,
601
631
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" );
603
634
goto close_handles ;
635
+ }
604
636
605
637
status = efi_call_phys4 (h -> get_info , h , & info_guid ,
606
638
& info_sz , info );
@@ -612,8 +644,10 @@ static efi_status_t handle_ramdisks(efi_loaded_image_t *image,
612
644
file_sz = info -> file_size ;
613
645
efi_call_phys1 (sys_table -> boottime -> free_pool , info );
614
646
615
- if (status != EFI_SUCCESS )
647
+ if (status != EFI_SUCCESS ) {
648
+ efi_printk ("Failed to get initrd info\n" );
616
649
goto close_handles ;
650
+ }
617
651
618
652
initrd -> size = file_sz ;
619
653
initrd_total += file_sz ;
@@ -629,11 +663,14 @@ static efi_status_t handle_ramdisks(efi_loaded_image_t *image,
629
663
*/
630
664
status = high_alloc (initrd_total , 0x1000 ,
631
665
& 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" );
633
668
goto close_handles ;
669
+ }
634
670
635
671
/* We've run out of free low memory. */
636
672
if (initrd_addr > hdr -> initrd_addr_max ) {
673
+ efi_printk ("We've run out of free low memory\n" );
637
674
status = EFI_INVALID_PARAMETER ;
638
675
goto free_initrd_total ;
639
676
}
@@ -652,8 +689,10 @@ static efi_status_t handle_ramdisks(efi_loaded_image_t *image,
652
689
status = efi_call_phys3 (fh -> read ,
653
690
initrds [j ].handle ,
654
691
& chunksize , addr );
655
- if (status != EFI_SUCCESS )
692
+ if (status != EFI_SUCCESS ) {
693
+ efi_printk ("Failed to read initrd\n" );
656
694
goto free_initrd_total ;
695
+ }
657
696
addr += chunksize ;
658
697
size -= chunksize ;
659
698
}
@@ -732,8 +771,10 @@ static efi_status_t make_boot_params(struct boot_params *boot_params,
732
771
options_size ++ ; /* NUL termination */
733
772
734
773
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" );
736
776
goto fail ;
777
+ }
737
778
738
779
s1 = (u8 * )(unsigned long )cmdline ;
739
780
s2 = (u16 * )options ;
@@ -895,12 +936,16 @@ struct boot_params *efi_main(void *handle, efi_system_table_t *_table)
895
936
896
937
status = efi_call_phys3 (sys_table -> boottime -> handle_protocol ,
897
938
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" );
899
941
goto fail ;
942
+ }
900
943
901
944
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" );
903
947
goto fail ;
948
+ }
904
949
905
950
memset (boot_params , 0x0 , 0x4000 );
906
951
@@ -933,8 +978,10 @@ struct boot_params *efi_main(void *handle, efi_system_table_t *_table)
933
978
if (status != EFI_SUCCESS ) {
934
979
status = low_alloc (hdr -> init_size , hdr -> kernel_alignment ,
935
980
& start );
936
- if (status != EFI_SUCCESS )
981
+ if (status != EFI_SUCCESS ) {
982
+ efi_printk ("Failed to alloc mem for kernel\n" );
937
983
goto fail ;
984
+ }
938
985
}
939
986
940
987
hdr -> code32_start = (__u32 )start ;
@@ -945,19 +992,25 @@ struct boot_params *efi_main(void *handle, efi_system_table_t *_table)
945
992
status = efi_call_phys3 (sys_table -> boottime -> allocate_pool ,
946
993
EFI_LOADER_DATA , sizeof (* gdt ),
947
994
(void * * )& gdt );
948
- if (status != EFI_SUCCESS )
995
+ if (status != EFI_SUCCESS ) {
996
+ efi_printk ("Failed to alloc mem for gdt structure\n" );
949
997
goto fail ;
998
+ }
950
999
951
1000
gdt -> size = 0x800 ;
952
1001
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" );
954
1004
goto fail ;
1005
+ }
955
1006
956
1007
status = efi_call_phys3 (sys_table -> boottime -> allocate_pool ,
957
1008
EFI_LOADER_DATA , sizeof (* idt ),
958
1009
(void * * )& idt );
959
- if (status != EFI_SUCCESS )
1010
+ if (status != EFI_SUCCESS ) {
1011
+ efi_printk ("Failed to alloc mem for idt structure\n" );
960
1012
goto fail ;
1013
+ }
961
1014
962
1015
idt -> size = 0 ;
963
1016
idt -> address = 0 ;
0 commit comments