Browse Source

[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 years ago
parent
commit
3f85626fa9

+ 6
- 6
src/image/efi_image.c View File

43
 				       user_to_virt ( image->data, 0 ),
43
 				       user_to_virt ( image->data, 0 ),
44
 				       image->len, &handle ) ) != 0 ) {
44
 				       image->len, &handle ) ) != 0 ) {
45
 		/* Not an EFI image */
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
 		return -ENOEXEC;
48
 		return -ENOEXEC;
49
 	}
49
 	}
50
 
50
 
51
 	/* Start the image */
51
 	/* Start the image */
52
 	if ( ( efirc = bs->StartImage ( handle, &exit_data_size,
52
 	if ( ( efirc = bs->StartImage ( handle, &exit_data_size,
53
 					&exit_data ) ) != 0 ) {
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
 		goto done;
56
 		goto done;
57
 	}
57
 	}
58
 
58
 
81
 				       user_to_virt ( image->data, 0 ),
81
 				       user_to_virt ( image->data, 0 ),
82
 				       image->len, &handle ) ) != 0 ) {
82
 				       image->len, &handle ) ) != 0 ) {
83
 		/* Not an EFI image */
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
 		return -ENOEXEC;
86
 		return -ENOEXEC;
87
 	}
87
 	}
88
 
88
 

+ 2
- 0
src/include/gpxe/efi/efi.h View File

90
 extern EFI_HANDLE efi_image_handle;
90
 extern EFI_HANDLE efi_image_handle;
91
 extern EFI_SYSTEM_TABLE *efi_systab;
91
 extern EFI_SYSTEM_TABLE *efi_systab;
92
 
92
 
93
+extern const char * efi_strerror ( EFI_STATUS efirc );
94
+
93
 #endif /* _EFI_H */
95
 #endif /* _EFI_H */

+ 2
- 1
src/interface/efi/efi_console.c View File

224
 
224
 
225
 	/* Read key from real EFI console */
225
 	/* Read key from real EFI console */
226
 	if ( ( efirc = conin->ReadKeyStroke ( conin, &key ) ) != 0 ) {
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
 		return 0;
229
 		return 0;
229
 	}
230
 	}
230
 	DBG2 ( "EFI read key stroke with unicode %04x scancode %04x\n",
231
 	DBG2 ( "EFI read key stroke with unicode %04x scancode %04x\n",

+ 8
- 6
src/interface/efi/efi_io.c View File

86
 	if ( ( efirc = read ( cpu_io, efi_width ( size ),
86
 	if ( ( efirc = read ( cpu_io, efi_width ( size ),
87
 			      ( intptr_t ) io_addr, 1,
87
 			      ( intptr_t ) io_addr, 1,
88
 			      ( void * ) &data ) ) != 0 ) {
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
 		return -1ULL;
91
 		return -1ULL;
91
 	}
92
 	}
92
 
93
 
111
 	if ( ( efirc = write ( cpu_io, efi_width ( size ),
112
 	if ( ( efirc = write ( cpu_io, efi_width ( size ),
112
 			       ( intptr_t ) io_addr, 1,
113
 			       ( intptr_t ) io_addr, 1,
113
 			       ( void * ) &data ) ) != 0 ) {
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
 	if ( ( efirc = read ( cpu_io, efi_width ( size ),
136
 	if ( ( efirc = read ( cpu_io, efi_width ( size ),
135
 			      ( intptr_t ) io_addr, count,
137
 			      ( intptr_t ) io_addr, count,
136
 			      ( void * ) data ) ) != 0 ) {
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
 	if ( ( efirc = write ( cpu_io, efi_width ( size ),
160
 	if ( ( efirc = write ( cpu_io, efi_width ( size ),
159
 			       ( intptr_t ) io_addr, count,
161
 			       ( intptr_t ) io_addr, count,
160
 			       ( void * ) data ) ) != 0 ) {
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 View File

46
 					  efipci_address ( pci, location ), 1,
46
 					  efipci_address ( pci, location ), 1,
47
 					  value ) ) != 0 ) {
47
 					  value ) ) != 0 ) {
48
 		DBG ( "EFIPCI config read from %02x:%02x.%x offset %02lx "
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
 		      PCI_FUNC ( pci->devfn ), EFIPCI_OFFSET ( location ),
50
 		      PCI_FUNC ( pci->devfn ), EFIPCI_OFFSET ( location ),
51
-		      efirc );
51
+		      efi_strerror ( efirc ) );
52
 		return -EIO;
52
 		return -EIO;
53
 	}
53
 	}
54
 
54
 
63
 					   efipci_address ( pci, location ), 1,
63
 					   efipci_address ( pci, location ), 1,
64
 					   &value ) ) != 0 ) {
64
 					   &value ) ) != 0 ) {
65
 		DBG ( "EFIPCI config write to %02x:%02x.%x offset %02lx "
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
 		      PCI_FUNC ( pci->devfn ), EFIPCI_OFFSET ( location ),
67
 		      PCI_FUNC ( pci->devfn ), EFIPCI_OFFSET ( location ),
68
-		      efirc );
68
+		      efi_strerror ( efirc ) );
69
 		return -EIO;
69
 		return -EIO;
70
 	}
70
 	}
71
 
71
 

+ 8
- 7
src/interface/efi/efi_snp.c View File

737
 	if ( ( efirc = u.pci->GetLocation ( u.pci, &pci_segment, &pci_bus,
737
 	if ( ( efirc = u.pci->GetLocation ( u.pci, &pci_segment, &pci_bus,
738
 					    &pci_dev, &pci_fn ) ) != 0 ) {
738
 					    &pci_dev, &pci_fn ) ) != 0 ) {
739
 		DBGC ( driver, "SNPDRV %p device %p could not get PCI "
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
 		goto out_no_pci_location;
742
 		goto out_no_pci_location;
742
 	}
743
 	}
743
 	DBGCP ( driver, "SNPDRV %p device %p is PCI %04x:%02x:%02x.%x\n",
744
 	DBGCP ( driver, "SNPDRV %p device %p is PCI %04x:%02x:%02x.%x\n",
786
 					  device,
787
 					  device,
787
 					  EFI_OPEN_PROTOCOL_GET_PROTOCOL))!=0){
788
 					  EFI_OPEN_PROTOCOL_GET_PROTOCOL))!=0){
788
 		DBGC ( driver, "SNPDRV %p device %p could not locate SNP: "
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
 		return NULL;
791
 		return NULL;
791
 	}
792
 	}
792
 
793
 
869
 	if ( ( efirc = bs->CreateEvent ( EVT_NOTIFY_WAIT, TPL_NOTIFY,
870
 	if ( ( efirc = bs->CreateEvent ( EVT_NOTIFY_WAIT, TPL_NOTIFY,
870
 					 efi_snp_wait_for_packet, snpdev,
871
 					 efi_snp_wait_for_packet, snpdev,
871
 					 &snpdev->snp.WaitForPacket ) ) != 0 ){
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
 		goto err_create_event;
875
 		goto err_create_event;
875
 	}
876
 	}
876
 
877
 
882
 	if ( ( efirc = bs->InstallProtocolInterface ( &device,
883
 	if ( ( efirc = bs->InstallProtocolInterface ( &device,
883
 				&efi_simple_network_protocol_guid,
884
 				&efi_simple_network_protocol_guid,
884
 				EFI_NATIVE_INTERFACE, &snpdev->snp ) ) != 0 ) {
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
 		goto err_install_protocol_interface;
888
 		goto err_install_protocol_interface;
888
 	}
889
 	}
889
 
890
 
970
 					EFI_NATIVE_INTERFACE,
971
 					EFI_NATIVE_INTERFACE,
971
 					driver ) ) != 0 ) {
972
 					driver ) ) != 0 ) {
972
 		DBGC ( driver, "SNPDRV %p could not install driver binding: "
973
 		DBGC ( driver, "SNPDRV %p could not install driver binding: "
973
-		       "%x\n", driver, efirc );
974
+		       "%s\n", driver, efi_strerror ( efirc ) );
974
 		return EFIRC_TO_RC ( efirc );
975
 		return EFIRC_TO_RC ( efirc );
975
 	}
976
 	}
976
 
977
 

+ 43
- 0
src/interface/efi/efi_strerror.c View File

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 View File

53
 	EFI_STATUS efirc;
53
 	EFI_STATUS efirc;
54
 
54
 
55
 	if ( ( efirc = bs->Stall ( usecs ) ) != 0 ) {
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
 		/* Probably screwed */
58
 		/* Probably screwed */
59
 	}
59
 	}
60
 }
60
 }
71
 	/* Read CPU timer 0 (TSC) */
71
 	/* Read CPU timer 0 (TSC) */
72
 	if ( ( efirc = cpu_arch->GetTimerValue ( cpu_arch, 0, &time,
72
 	if ( ( efirc = cpu_arch->GetTimerValue ( cpu_arch, 0, &time,
73
 						 NULL ) ) != 0 ) {
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
 		/* Probably screwed */
76
 		/* Probably screwed */
76
 		return -1UL;
77
 		return -1UL;
77
 	}
78
 	}

+ 4
- 4
src/interface/efi/efi_umalloc.c View File

56
 						   EfiBootServicesData,
56
 						   EfiBootServicesData,
57
 						   new_pages,
57
 						   new_pages,
58
 						   &phys_addr ) ) != 0 ) {
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
 			return UNULL;
61
 			return UNULL;
62
 		}
62
 		}
63
 		assert ( phys_addr != 0 );
63
 		assert ( phys_addr != 0 );
81
 		old_pages = ( EFI_SIZE_TO_PAGES ( old_size ) + 1 );
81
 		old_pages = ( EFI_SIZE_TO_PAGES ( old_size ) + 1 );
82
 		phys_addr = user_to_phys ( old_ptr, -EFI_PAGE_SIZE );
82
 		phys_addr = user_to_phys ( old_ptr, -EFI_PAGE_SIZE );
83
 		if ( ( efirc = bs->FreePages ( phys_addr, old_pages ) ) != 0 ){
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
 			/* Not fatal; we have leaked memory but successfully
86
 			/* Not fatal; we have leaked memory but successfully
87
 			 * allocated (if asked to do so).
87
 			 * allocated (if asked to do so).
88
 			 */
88
 			 */

Loading…
Cancel
Save