Bladeren bron

[efi] Add efi_strerror()

EFI_STATUS is defined as an INTN, which maps to UINT32 (i.e. unsigned
int) on i386 and UINT64 (i.e. unsigned long) on x86_64.  This would
require a cast each time the error status is printed.

Add efi_strerror() to avoid this ickiness and simultaneously enable
prettier reporting of EFI status codes.
tags/v0.9.6
Michael Brown 16 jaren geleden
bovenliggende
commit
3f85626fa9

+ 6
- 6
src/image/efi_image.c Bestand weergeven

@@ -43,16 +43,16 @@ static int efi_image_exec ( struct image *image ) {
43 43
 				       user_to_virt ( image->data, 0 ),
44 44
 				       image->len, &handle ) ) != 0 ) {
45 45
 		/* Not an EFI image */
46
-		DBGC ( image, "EFIIMAGE %p could not load: %x\n",
47
-		       image, efirc );
46
+		DBGC ( image, "EFIIMAGE %p could not load: %s\n",
47
+		       image, efi_strerror ( efirc ) );
48 48
 		return -ENOEXEC;
49 49
 	}
50 50
 
51 51
 	/* Start the image */
52 52
 	if ( ( efirc = bs->StartImage ( handle, &exit_data_size,
53 53
 					&exit_data ) ) != 0 ) {
54
-		DBGC ( image, "EFIIMAGE %p returned with status %x\n",
55
-		       image, efirc );
54
+		DBGC ( image, "EFIIMAGE %p returned with status %s\n",
55
+		       image, efi_strerror ( efirc ) );
56 56
 		goto done;
57 57
 	}
58 58
 
@@ -81,8 +81,8 @@ static int efi_image_load ( struct image *image ) {
81 81
 				       user_to_virt ( image->data, 0 ),
82 82
 				       image->len, &handle ) ) != 0 ) {
83 83
 		/* Not an EFI image */
84
-		DBGC ( image, "EFIIMAGE %p could not load: %x\n",
85
-		       image, efirc );
84
+		DBGC ( image, "EFIIMAGE %p could not load: %s\n",
85
+		       image, efi_strerror ( efirc ) );
86 86
 		return -ENOEXEC;
87 87
 	}
88 88
 

+ 2
- 0
src/include/gpxe/efi/efi.h Bestand weergeven

@@ -90,4 +90,6 @@ struct efi_protocol {
90 90
 extern EFI_HANDLE efi_image_handle;
91 91
 extern EFI_SYSTEM_TABLE *efi_systab;
92 92
 
93
+extern const char * efi_strerror ( EFI_STATUS efirc );
94
+
93 95
 #endif /* _EFI_H */

+ 2
- 1
src/interface/efi/efi_console.c Bestand weergeven

@@ -224,7 +224,8 @@ static int efi_getchar ( void ) {
224 224
 
225 225
 	/* Read key from real EFI console */
226 226
 	if ( ( efirc = conin->ReadKeyStroke ( conin, &key ) ) != 0 ) {
227
-		DBG ( "EFI could not read keystroke: %x\n", efirc );
227
+		DBG ( "EFI could not read keystroke: %s\n",
228
+		      efi_strerror ( efirc ) );
228 229
 		return 0;
229 230
 	}
230 231
 	DBG2 ( "EFI read key stroke with unicode %04x scancode %04x\n",

+ 8
- 6
src/interface/efi/efi_io.c Bestand weergeven

@@ -86,7 +86,8 @@ unsigned long long efi_ioread ( volatile void *io_addr, size_t size ) {
86 86
 	if ( ( efirc = read ( cpu_io, efi_width ( size ),
87 87
 			      ( intptr_t ) io_addr, 1,
88 88
 			      ( void * ) &data ) ) != 0 ) {
89
-		DBG ( "EFI I/O read at %p failed: %x\n", io_addr, efirc );
89
+		DBG ( "EFI I/O read at %p failed: %s\n",
90
+		      io_addr, efi_strerror ( efirc ) );
90 91
 		return -1ULL;
91 92
 	}
92 93
 
@@ -111,7 +112,8 @@ void efi_iowrite ( unsigned long long data, volatile void *io_addr,
111 112
 	if ( ( efirc = write ( cpu_io, efi_width ( size ),
112 113
 			       ( intptr_t ) io_addr, 1,
113 114
 			       ( void * ) &data ) ) != 0 ) {
114
-		DBG ( "EFI I/O write at %p failed: %x\n", io_addr, efirc );
115
+		DBG ( "EFI I/O write at %p failed: %s\n",
116
+		      io_addr, efi_strerror ( efirc ) );
115 117
 	}
116 118
 }
117 119
 
@@ -134,8 +136,8 @@ void efi_ioreads ( volatile void *io_addr, void *data,
134 136
 	if ( ( efirc = read ( cpu_io, efi_width ( size ),
135 137
 			      ( intptr_t ) io_addr, count,
136 138
 			      ( void * ) data ) ) != 0 ) {
137
-		DBG ( "EFI I/O string read at %p failed: %x\n",
138
-		      io_addr, efirc );
139
+		DBG ( "EFI I/O string read at %p failed: %s\n",
140
+		      io_addr, efi_strerror ( efirc ) );
139 141
 	}
140 142
 }
141 143
 
@@ -158,8 +160,8 @@ void efi_iowrites ( volatile void *io_addr, const void *data,
158 160
 	if ( ( efirc = write ( cpu_io, efi_width ( size ),
159 161
 			       ( intptr_t ) io_addr, count,
160 162
 			       ( void * ) data ) ) != 0 ) {
161
-		DBG ( "EFI I/O write at %p failed: %x\n",
162
-		      io_addr, efirc );
163
+		DBG ( "EFI I/O write at %p failed: %s\n",
164
+		      io_addr, efi_strerror ( efirc ) );
163 165
 	}
164 166
 }
165 167
 

+ 4
- 4
src/interface/efi/efi_pci.c Bestand weergeven

@@ -46,9 +46,9 @@ int efipci_read ( struct pci_device *pci, unsigned long location,
46 46
 					  efipci_address ( pci, location ), 1,
47 47
 					  value ) ) != 0 ) {
48 48
 		DBG ( "EFIPCI config read from %02x:%02x.%x offset %02lx "
49
-		      "failed: %x\n", pci->bus, PCI_SLOT ( pci->devfn ),
49
+		      "failed: %s\n", pci->bus, PCI_SLOT ( pci->devfn ),
50 50
 		      PCI_FUNC ( pci->devfn ), EFIPCI_OFFSET ( location ),
51
-		      efirc );
51
+		      efi_strerror ( efirc ) );
52 52
 		return -EIO;
53 53
 	}
54 54
 
@@ -63,9 +63,9 @@ int efipci_write ( struct pci_device *pci, unsigned long location,
63 63
 					   efipci_address ( pci, location ), 1,
64 64
 					   &value ) ) != 0 ) {
65 65
 		DBG ( "EFIPCI config write to %02x:%02x.%x offset %02lx "
66
-		      "failed: %x\n", pci->bus, PCI_SLOT ( pci->devfn ),
66
+		      "failed: %s\n", pci->bus, PCI_SLOT ( pci->devfn ),
67 67
 		      PCI_FUNC ( pci->devfn ), EFIPCI_OFFSET ( location ),
68
-		      efirc );
68
+		      efi_strerror ( efirc ) );
69 69
 		return -EIO;
70 70
 	}
71 71
 

+ 8
- 7
src/interface/efi/efi_snp.c Bestand weergeven

@@ -737,7 +737,8 @@ efi_snp_netdev ( EFI_DRIVER_BINDING_PROTOCOL *driver, EFI_HANDLE device ) {
737 737
 	if ( ( efirc = u.pci->GetLocation ( u.pci, &pci_segment, &pci_bus,
738 738
 					    &pci_dev, &pci_fn ) ) != 0 ) {
739 739
 		DBGC ( driver, "SNPDRV %p device %p could not get PCI "
740
-		       "location: %x\n", driver, device, efirc );
740
+		       "location: %s\n",
741
+		       driver, device, efi_strerror ( efirc ) );
741 742
 		goto out_no_pci_location;
742 743
 	}
743 744
 	DBGCP ( driver, "SNPDRV %p device %p is PCI %04x:%02x:%02x.%x\n",
@@ -786,7 +787,7 @@ efi_snp_snpdev ( EFI_DRIVER_BINDING_PROTOCOL *driver, EFI_HANDLE device ) {
786 787
 					  device,
787 788
 					  EFI_OPEN_PROTOCOL_GET_PROTOCOL))!=0){
788 789
 		DBGC ( driver, "SNPDRV %p device %p could not locate SNP: "
789
-		       "%x\n", driver, device, efirc );
790
+		       "%s\n", driver, device, efi_strerror ( efirc ) );
790 791
 		return NULL;
791 792
 	}
792 793
 
@@ -869,8 +870,8 @@ efi_snp_driver_start ( EFI_DRIVER_BINDING_PROTOCOL *driver,
869 870
 	if ( ( efirc = bs->CreateEvent ( EVT_NOTIFY_WAIT, TPL_NOTIFY,
870 871
 					 efi_snp_wait_for_packet, snpdev,
871 872
 					 &snpdev->snp.WaitForPacket ) ) != 0 ){
872
-		DBGC ( snpdev, "SNPDEV %p could not create event: %x\n",
873
-		       snpdev, efirc );
873
+		DBGC ( snpdev, "SNPDEV %p could not create event: %s\n",
874
+		       snpdev, efi_strerror ( efirc ) );
874 875
 		goto err_create_event;
875 876
 	}
876 877
 
@@ -882,8 +883,8 @@ efi_snp_driver_start ( EFI_DRIVER_BINDING_PROTOCOL *driver,
882 883
 	if ( ( efirc = bs->InstallProtocolInterface ( &device,
883 884
 				&efi_simple_network_protocol_guid,
884 885
 				EFI_NATIVE_INTERFACE, &snpdev->snp ) ) != 0 ) {
885
-		DBGC ( snpdev, "SNPDEV %p could not install protocol: %x\n",
886
-		       snpdev, efirc );
886
+		DBGC ( snpdev, "SNPDEV %p could not install protocol: %s\n",
887
+		       snpdev, efi_strerror ( efirc ) );
887 888
 		goto err_install_protocol_interface;
888 889
 	}
889 890
 
@@ -970,7 +971,7 @@ int efi_snp_install ( void ) {
970 971
 					EFI_NATIVE_INTERFACE,
971 972
 					driver ) ) != 0 ) {
972 973
 		DBGC ( driver, "SNPDRV %p could not install driver binding: "
973
-		       "%x\n", driver, efirc );
974
+		       "%s\n", driver, efi_strerror ( efirc ) );
974 975
 		return EFIRC_TO_RC ( efirc );
975 976
 	}
976 977
 

+ 43
- 0
src/interface/efi/efi_strerror.c Bestand weergeven

@@ -0,0 +1,43 @@
1
+/*
2
+ * Copyright (C) 2008 Michael Brown <mbrown@fensystems.co.uk>.
3
+ *
4
+ * This program is free software; you can redistribute it and/or
5
+ * modify it under the terms of the GNU General Public License as
6
+ * published by the Free Software Foundation; either version 2 of the
7
+ * License, or any later version.
8
+ *
9
+ * This program is distributed in the hope that it will be useful, but
10
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12
+ * General Public License for more details.
13
+ *
14
+ * You should have received a copy of the GNU General Public License
15
+ * along with this program; if not, write to the Free Software
16
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
+ */
18
+
19
+#include <stdio.h>
20
+#include <gpxe/efi/efi.h>
21
+
22
+/** @file
23
+ *
24
+ * gPXE error message formatting for EFI
25
+ *
26
+ */
27
+
28
+/**
29
+ * Format EFI status code
30
+ *
31
+ * @v efirc		EFI status code
32
+ * @v efi_strerror	EFI status code string
33
+ */
34
+const char * efi_strerror ( EFI_STATUS efirc ) {
35
+	static char errbuf[32];
36
+
37
+	if ( ! efirc )
38
+		return "No error";
39
+
40
+	snprintf ( errbuf, sizeof ( errbuf ), "Error %lld",
41
+		   ( unsigned long long ) ( efirc ^ MAX_BIT ) );
42
+	return errbuf;
43
+}

+ 4
- 3
src/interface/efi/efi_timer.c Bestand weergeven

@@ -53,8 +53,8 @@ static void efi_udelay ( unsigned long usecs ) {
53 53
 	EFI_STATUS efirc;
54 54
 
55 55
 	if ( ( efirc = bs->Stall ( usecs ) ) != 0 ) {
56
-		DBG ( "EFI could not delay for %ldus: %x\n",
57
-		      usecs, efirc );
56
+		DBG ( "EFI could not delay for %ldus: %s\n",
57
+		      usecs, efi_strerror ( efirc ) );
58 58
 		/* Probably screwed */
59 59
 	}
60 60
 }
@@ -71,7 +71,8 @@ static unsigned long efi_currticks ( void ) {
71 71
 	/* Read CPU timer 0 (TSC) */
72 72
 	if ( ( efirc = cpu_arch->GetTimerValue ( cpu_arch, 0, &time,
73 73
 						 NULL ) ) != 0 ) {
74
-		DBG ( "EFI could not read CPU timer: %x\n", efirc );
74
+		DBG ( "EFI could not read CPU timer: %s\n",
75
+		      efi_strerror ( efirc ) );
75 76
 		/* Probably screwed */
76 77
 		return -1UL;
77 78
 	}

+ 4
- 4
src/interface/efi/efi_umalloc.c Bestand weergeven

@@ -56,8 +56,8 @@ static userptr_t efi_urealloc ( userptr_t old_ptr, size_t new_size ) {
56 56
 						   EfiBootServicesData,
57 57
 						   new_pages,
58 58
 						   &phys_addr ) ) != 0 ) {
59
-			DBG ( "EFI could not allocate %d pages: %x\n",
60
-			      new_pages, efirc );
59
+			DBG ( "EFI could not allocate %d pages: %s\n",
60
+			      new_pages, efi_strerror ( efirc ) );
61 61
 			return UNULL;
62 62
 		}
63 63
 		assert ( phys_addr != 0 );
@@ -81,8 +81,8 @@ static userptr_t efi_urealloc ( userptr_t old_ptr, size_t new_size ) {
81 81
 		old_pages = ( EFI_SIZE_TO_PAGES ( old_size ) + 1 );
82 82
 		phys_addr = user_to_phys ( old_ptr, -EFI_PAGE_SIZE );
83 83
 		if ( ( efirc = bs->FreePages ( phys_addr, old_pages ) ) != 0 ){
84
-			DBG ( "EFI could not free %d pages at %llx: %x\n",
85
-			      old_pages, phys_addr, efirc );
84
+			DBG ( "EFI could not free %d pages at %llx: %s\n",
85
+			      old_pages, phys_addr, efi_strerror ( efirc ) );
86 86
 			/* Not fatal; we have leaked memory but successfully
87 87
 			 * allocated (if asked to do so).
88 88
 			 */

Laden…
Annuleren
Opslaan