mirror of
https://github.com/xcat2/xNBA.git
synced 2025-04-11 10:15:27 +00:00
[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.
This commit is contained in:
parent
d9b3d09910
commit
3f85626fa9
@ -43,16 +43,16 @@ static int efi_image_exec ( struct image *image ) {
|
||||
user_to_virt ( image->data, 0 ),
|
||||
image->len, &handle ) ) != 0 ) {
|
||||
/* Not an EFI image */
|
||||
DBGC ( image, "EFIIMAGE %p could not load: %x\n",
|
||||
image, efirc );
|
||||
DBGC ( image, "EFIIMAGE %p could not load: %s\n",
|
||||
image, efi_strerror ( efirc ) );
|
||||
return -ENOEXEC;
|
||||
}
|
||||
|
||||
/* Start the image */
|
||||
if ( ( efirc = bs->StartImage ( handle, &exit_data_size,
|
||||
&exit_data ) ) != 0 ) {
|
||||
DBGC ( image, "EFIIMAGE %p returned with status %x\n",
|
||||
image, efirc );
|
||||
DBGC ( image, "EFIIMAGE %p returned with status %s\n",
|
||||
image, efi_strerror ( efirc ) );
|
||||
goto done;
|
||||
}
|
||||
|
||||
@ -81,8 +81,8 @@ static int efi_image_load ( struct image *image ) {
|
||||
user_to_virt ( image->data, 0 ),
|
||||
image->len, &handle ) ) != 0 ) {
|
||||
/* Not an EFI image */
|
||||
DBGC ( image, "EFIIMAGE %p could not load: %x\n",
|
||||
image, efirc );
|
||||
DBGC ( image, "EFIIMAGE %p could not load: %s\n",
|
||||
image, efi_strerror ( efirc ) );
|
||||
return -ENOEXEC;
|
||||
}
|
||||
|
||||
|
@ -90,4 +90,6 @@ struct efi_protocol {
|
||||
extern EFI_HANDLE efi_image_handle;
|
||||
extern EFI_SYSTEM_TABLE *efi_systab;
|
||||
|
||||
extern const char * efi_strerror ( EFI_STATUS efirc );
|
||||
|
||||
#endif /* _EFI_H */
|
||||
|
@ -224,7 +224,8 @@ static int efi_getchar ( void ) {
|
||||
|
||||
/* Read key from real EFI console */
|
||||
if ( ( efirc = conin->ReadKeyStroke ( conin, &key ) ) != 0 ) {
|
||||
DBG ( "EFI could not read keystroke: %x\n", efirc );
|
||||
DBG ( "EFI could not read keystroke: %s\n",
|
||||
efi_strerror ( efirc ) );
|
||||
return 0;
|
||||
}
|
||||
DBG2 ( "EFI read key stroke with unicode %04x scancode %04x\n",
|
||||
|
@ -86,7 +86,8 @@ unsigned long long efi_ioread ( volatile void *io_addr, size_t size ) {
|
||||
if ( ( efirc = read ( cpu_io, efi_width ( size ),
|
||||
( intptr_t ) io_addr, 1,
|
||||
( void * ) &data ) ) != 0 ) {
|
||||
DBG ( "EFI I/O read at %p failed: %x\n", io_addr, efirc );
|
||||
DBG ( "EFI I/O read at %p failed: %s\n",
|
||||
io_addr, efi_strerror ( efirc ) );
|
||||
return -1ULL;
|
||||
}
|
||||
|
||||
@ -111,7 +112,8 @@ void efi_iowrite ( unsigned long long data, volatile void *io_addr,
|
||||
if ( ( efirc = write ( cpu_io, efi_width ( size ),
|
||||
( intptr_t ) io_addr, 1,
|
||||
( void * ) &data ) ) != 0 ) {
|
||||
DBG ( "EFI I/O write at %p failed: %x\n", io_addr, efirc );
|
||||
DBG ( "EFI I/O write at %p failed: %s\n",
|
||||
io_addr, efi_strerror ( efirc ) );
|
||||
}
|
||||
}
|
||||
|
||||
@ -134,8 +136,8 @@ void efi_ioreads ( volatile void *io_addr, void *data,
|
||||
if ( ( efirc = read ( cpu_io, efi_width ( size ),
|
||||
( intptr_t ) io_addr, count,
|
||||
( void * ) data ) ) != 0 ) {
|
||||
DBG ( "EFI I/O string read at %p failed: %x\n",
|
||||
io_addr, efirc );
|
||||
DBG ( "EFI I/O string read at %p failed: %s\n",
|
||||
io_addr, efi_strerror ( efirc ) );
|
||||
}
|
||||
}
|
||||
|
||||
@ -158,8 +160,8 @@ void efi_iowrites ( volatile void *io_addr, const void *data,
|
||||
if ( ( efirc = write ( cpu_io, efi_width ( size ),
|
||||
( intptr_t ) io_addr, count,
|
||||
( void * ) data ) ) != 0 ) {
|
||||
DBG ( "EFI I/O write at %p failed: %x\n",
|
||||
io_addr, efirc );
|
||||
DBG ( "EFI I/O write at %p failed: %s\n",
|
||||
io_addr, efi_strerror ( efirc ) );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -46,9 +46,9 @@ int efipci_read ( struct pci_device *pci, unsigned long location,
|
||||
efipci_address ( pci, location ), 1,
|
||||
value ) ) != 0 ) {
|
||||
DBG ( "EFIPCI config read from %02x:%02x.%x offset %02lx "
|
||||
"failed: %x\n", pci->bus, PCI_SLOT ( pci->devfn ),
|
||||
"failed: %s\n", pci->bus, PCI_SLOT ( pci->devfn ),
|
||||
PCI_FUNC ( pci->devfn ), EFIPCI_OFFSET ( location ),
|
||||
efirc );
|
||||
efi_strerror ( efirc ) );
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
@ -63,9 +63,9 @@ int efipci_write ( struct pci_device *pci, unsigned long location,
|
||||
efipci_address ( pci, location ), 1,
|
||||
&value ) ) != 0 ) {
|
||||
DBG ( "EFIPCI config write to %02x:%02x.%x offset %02lx "
|
||||
"failed: %x\n", pci->bus, PCI_SLOT ( pci->devfn ),
|
||||
"failed: %s\n", pci->bus, PCI_SLOT ( pci->devfn ),
|
||||
PCI_FUNC ( pci->devfn ), EFIPCI_OFFSET ( location ),
|
||||
efirc );
|
||||
efi_strerror ( efirc ) );
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
|
@ -737,7 +737,8 @@ efi_snp_netdev ( EFI_DRIVER_BINDING_PROTOCOL *driver, EFI_HANDLE device ) {
|
||||
if ( ( efirc = u.pci->GetLocation ( u.pci, &pci_segment, &pci_bus,
|
||||
&pci_dev, &pci_fn ) ) != 0 ) {
|
||||
DBGC ( driver, "SNPDRV %p device %p could not get PCI "
|
||||
"location: %x\n", driver, device, efirc );
|
||||
"location: %s\n",
|
||||
driver, device, efi_strerror ( efirc ) );
|
||||
goto out_no_pci_location;
|
||||
}
|
||||
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 ) {
|
||||
device,
|
||||
EFI_OPEN_PROTOCOL_GET_PROTOCOL))!=0){
|
||||
DBGC ( driver, "SNPDRV %p device %p could not locate SNP: "
|
||||
"%x\n", driver, device, efirc );
|
||||
"%s\n", driver, device, efi_strerror ( efirc ) );
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@ -869,8 +870,8 @@ efi_snp_driver_start ( EFI_DRIVER_BINDING_PROTOCOL *driver,
|
||||
if ( ( efirc = bs->CreateEvent ( EVT_NOTIFY_WAIT, TPL_NOTIFY,
|
||||
efi_snp_wait_for_packet, snpdev,
|
||||
&snpdev->snp.WaitForPacket ) ) != 0 ){
|
||||
DBGC ( snpdev, "SNPDEV %p could not create event: %x\n",
|
||||
snpdev, efirc );
|
||||
DBGC ( snpdev, "SNPDEV %p could not create event: %s\n",
|
||||
snpdev, efi_strerror ( efirc ) );
|
||||
goto err_create_event;
|
||||
}
|
||||
|
||||
@ -882,8 +883,8 @@ efi_snp_driver_start ( EFI_DRIVER_BINDING_PROTOCOL *driver,
|
||||
if ( ( efirc = bs->InstallProtocolInterface ( &device,
|
||||
&efi_simple_network_protocol_guid,
|
||||
EFI_NATIVE_INTERFACE, &snpdev->snp ) ) != 0 ) {
|
||||
DBGC ( snpdev, "SNPDEV %p could not install protocol: %x\n",
|
||||
snpdev, efirc );
|
||||
DBGC ( snpdev, "SNPDEV %p could not install protocol: %s\n",
|
||||
snpdev, efi_strerror ( efirc ) );
|
||||
goto err_install_protocol_interface;
|
||||
}
|
||||
|
||||
@ -970,7 +971,7 @@ int efi_snp_install ( void ) {
|
||||
EFI_NATIVE_INTERFACE,
|
||||
driver ) ) != 0 ) {
|
||||
DBGC ( driver, "SNPDRV %p could not install driver binding: "
|
||||
"%x\n", driver, efirc );
|
||||
"%s\n", driver, efi_strerror ( efirc ) );
|
||||
return EFIRC_TO_RC ( efirc );
|
||||
}
|
||||
|
||||
|
43
src/interface/efi/efi_strerror.c
Normal file
43
src/interface/efi/efi_strerror.c
Normal file
@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Copyright (C) 2008 Michael Brown <mbrown@fensystems.co.uk>.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of the
|
||||
* License, or any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <gpxe/efi/efi.h>
|
||||
|
||||
/** @file
|
||||
*
|
||||
* gPXE error message formatting for EFI
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* Format EFI status code
|
||||
*
|
||||
* @v efirc EFI status code
|
||||
* @v efi_strerror EFI status code string
|
||||
*/
|
||||
const char * efi_strerror ( EFI_STATUS efirc ) {
|
||||
static char errbuf[32];
|
||||
|
||||
if ( ! efirc )
|
||||
return "No error";
|
||||
|
||||
snprintf ( errbuf, sizeof ( errbuf ), "Error %lld",
|
||||
( unsigned long long ) ( efirc ^ MAX_BIT ) );
|
||||
return errbuf;
|
||||
}
|
@ -53,8 +53,8 @@ static void efi_udelay ( unsigned long usecs ) {
|
||||
EFI_STATUS efirc;
|
||||
|
||||
if ( ( efirc = bs->Stall ( usecs ) ) != 0 ) {
|
||||
DBG ( "EFI could not delay for %ldus: %x\n",
|
||||
usecs, efirc );
|
||||
DBG ( "EFI could not delay for %ldus: %s\n",
|
||||
usecs, efi_strerror ( efirc ) );
|
||||
/* Probably screwed */
|
||||
}
|
||||
}
|
||||
@ -71,7 +71,8 @@ static unsigned long efi_currticks ( void ) {
|
||||
/* Read CPU timer 0 (TSC) */
|
||||
if ( ( efirc = cpu_arch->GetTimerValue ( cpu_arch, 0, &time,
|
||||
NULL ) ) != 0 ) {
|
||||
DBG ( "EFI could not read CPU timer: %x\n", efirc );
|
||||
DBG ( "EFI could not read CPU timer: %s\n",
|
||||
efi_strerror ( efirc ) );
|
||||
/* Probably screwed */
|
||||
return -1UL;
|
||||
}
|
||||
|
@ -56,8 +56,8 @@ static userptr_t efi_urealloc ( userptr_t old_ptr, size_t new_size ) {
|
||||
EfiBootServicesData,
|
||||
new_pages,
|
||||
&phys_addr ) ) != 0 ) {
|
||||
DBG ( "EFI could not allocate %d pages: %x\n",
|
||||
new_pages, efirc );
|
||||
DBG ( "EFI could not allocate %d pages: %s\n",
|
||||
new_pages, efi_strerror ( efirc ) );
|
||||
return UNULL;
|
||||
}
|
||||
assert ( phys_addr != 0 );
|
||||
@ -81,8 +81,8 @@ static userptr_t efi_urealloc ( userptr_t old_ptr, size_t new_size ) {
|
||||
old_pages = ( EFI_SIZE_TO_PAGES ( old_size ) + 1 );
|
||||
phys_addr = user_to_phys ( old_ptr, -EFI_PAGE_SIZE );
|
||||
if ( ( efirc = bs->FreePages ( phys_addr, old_pages ) ) != 0 ){
|
||||
DBG ( "EFI could not free %d pages at %llx: %x\n",
|
||||
old_pages, phys_addr, efirc );
|
||||
DBG ( "EFI could not free %d pages at %llx: %s\n",
|
||||
old_pages, phys_addr, efi_strerror ( efirc ) );
|
||||
/* Not fatal; we have leaked memory but successfully
|
||||
* allocated (if asked to do so).
|
||||
*/
|
||||
|
Loading…
x
Reference in New Issue
Block a user