@@ -7,7 +7,6 @@
#include <xen/ctype.h>
#include <xen/dmi.h>
#include <xen/init.h>
-#include <xen/keyhandler.h>
#include <xen/lib.h>
#include <xen/mm.h>
#include <xen/multiboot.h>
@@ -70,7 +69,7 @@ static multiboot_info_t __initdata mbi = {
static module_t __initdata mb_modules[3];
-static void __init noreturn blexit(const CHAR16 *str)
+void __init noreturn blexit(const CHAR16 *str)
{
if ( str )
PrintStr((CHAR16 *)str);
@@ -91,56 +90,6 @@ static void __init noreturn blexit(const CHAR16 *str)
unreachable(); /* not reached */
}
-/* generic routine for printing error messages */
-static void __init PrintErrMesg(const CHAR16 *mesg, EFI_STATUS ErrCode)
-{
- StdOut = StdErr;
- PrintErr((CHAR16 *)mesg);
- PrintErr(L": ");
-
- switch (ErrCode)
- {
- case EFI_NOT_FOUND:
- mesg = L"Not found";
- break;
- case EFI_NO_MEDIA:
- mesg = L"The device has no media";
- break;
- case EFI_MEDIA_CHANGED:
- mesg = L"Media changed";
- break;
- case EFI_DEVICE_ERROR:
- mesg = L"Device error";
- break;
- case EFI_VOLUME_CORRUPTED:
- mesg = L"Volume corrupted";
- break;
- case EFI_ACCESS_DENIED:
- mesg = L"Access denied";
- break;
- case EFI_OUT_OF_RESOURCES:
- mesg = L"Out of resources";
- break;
- case EFI_VOLUME_FULL:
- mesg = L"Volume is full";
- break;
- case EFI_SECURITY_VIOLATION:
- mesg = L"Security violation";
- break;
- case EFI_CRC_ERROR:
- mesg = L"CRC error";
- break;
- case EFI_COMPROMISED_DATA:
- mesg = L"Compromised data";
- break;
- default:
- PrintErr(L"ErrCode: ");
- DisplayUint(ErrCode, 0);
- mesg = NULL;
- break;
- }
- blexit(mesg);
-}
static void __init place_string(u32 *addr, const char *s)
{
@@ -215,108 +164,6 @@ static unsigned int __init get_argv(unsigned int argc, CHAR16 **argv,
return argc;
}
-static EFI_FILE_HANDLE __init get_parent_handle(EFI_LOADED_IMAGE *loaded_image,
- CHAR16 **leaf)
-{
- static EFI_GUID __initdata fs_protocol = SIMPLE_FILE_SYSTEM_PROTOCOL;
- EFI_FILE_HANDLE dir_handle;
- EFI_DEVICE_PATH *dp;
- CHAR16 *pathend, *ptr;
- EFI_STATUS ret;
-
- do {
- EFI_FILE_IO_INTERFACE *fio;
-
- /* Get the file system interface. */
- ret = efi_bs->HandleProtocol(loaded_image->DeviceHandle,
- &fs_protocol, (void **)&fio);
- if ( EFI_ERROR(ret) )
- PrintErrMesg(L"Couldn't obtain the File System Protocol Interface",
- ret);
- ret = fio->OpenVolume(fio, &dir_handle);
- } while ( ret == EFI_MEDIA_CHANGED );
- if ( ret != EFI_SUCCESS )
- PrintErrMesg(L"OpenVolume failure", ret);
-
-#define buffer ((CHAR16 *)keyhandler_scratch)
-#define BUFFERSIZE sizeof(keyhandler_scratch)
- for ( dp = loaded_image->FilePath, *buffer = 0;
- DevicePathType(dp) != END_DEVICE_PATH_TYPE;
- dp = (void *)dp + DevicePathNodeLength(dp) )
- {
- FILEPATH_DEVICE_PATH *fp;
-
- if ( DevicePathType(dp) != MEDIA_DEVICE_PATH ||
- DevicePathSubType(dp) != MEDIA_FILEPATH_DP )
- blexit(L"Unsupported device path component");
-
- if ( *buffer )
- {
- EFI_FILE_HANDLE new_handle;
-
- ret = dir_handle->Open(dir_handle, &new_handle, buffer,
- EFI_FILE_MODE_READ, 0);
- if ( ret != EFI_SUCCESS )
- {
- PrintErr(L"Open failed for ");
- PrintErrMesg(buffer, ret);
- }
- dir_handle->Close(dir_handle);
- dir_handle = new_handle;
- }
- fp = (void *)dp;
- if ( BUFFERSIZE < DevicePathNodeLength(dp) -
- sizeof(*dp) + sizeof(*buffer) )
- blexit(L"Increase BUFFERSIZE");
- memcpy(buffer, fp->PathName, DevicePathNodeLength(dp) - sizeof(*dp));
- buffer[(DevicePathNodeLength(dp) - sizeof(*dp)) / sizeof(*buffer)] = 0;
- }
- for ( ptr = buffer, pathend = NULL; *ptr; ++ptr )
- if ( *ptr == L'\\' )
- pathend = ptr;
- if ( pathend )
- {
- *pathend = 0;
- *leaf = pathend + 1;
- if ( *buffer )
- {
- EFI_FILE_HANDLE new_handle;
-
- ret = dir_handle->Open(dir_handle, &new_handle, buffer,
- EFI_FILE_MODE_READ, 0);
- if ( ret != EFI_SUCCESS ) {
- PrintErr(L"Open failed for ");
- PrintErrMesg(buffer, ret);
- }
- dir_handle->Close(dir_handle);
- dir_handle = new_handle;
- }
- }
- else
- *leaf = buffer;
-#undef BUFFERSIZE
-#undef buffer
-
- return dir_handle;
-}
-
-static CHAR16 *__init point_tail(CHAR16 *fn)
-{
- CHAR16 *tail = NULL;
-
- for ( ; ; ++fn )
- switch ( *fn )
- {
- case 0:
- return tail;
- case L'.':
- case L'-':
- case L'_':
- tail = fn;
- break;
- }
-}
-
static bool_t __init read_file(EFI_FILE_HANDLE dir_handle, CHAR16 *name,
struct file *file)
{
@@ -393,63 +240,6 @@ static bool_t __init read_file(EFI_FILE_HANDLE dir_handle, CHAR16 *name,
return 1;
}
-static void __init pre_parse(const struct file *cfg)
-{
- char *ptr = cfg->ptr, *end = ptr + cfg->size;
- bool_t start = 1, comment = 0;
-
- for ( ; ptr < end; ++ptr )
- {
- if ( iscntrl(*ptr) )
- {
- comment = 0;
- start = 1;
- *ptr = 0;
- }
- else if ( comment || (start && isspace(*ptr)) )
- *ptr = 0;
- else if ( *ptr == '#' || (start && *ptr == ';') )
- {
- comment = 1;
- *ptr = 0;
- }
- else
- start = 0;
- }
- if ( cfg->size && end[-1] )
- PrintStr(L"No newline at end of config file,"
- " last line will be ignored.\r\n");
-}
-
-static char *__init get_value(const struct file *cfg, const char *section,
- const char *item)
-{
- char *ptr = cfg->ptr, *end = ptr + cfg->size;
- size_t slen = section ? strlen(section) : 0, ilen = strlen(item);
- bool_t match = !slen;
-
- for ( ; ptr < end; ++ptr )
- {
- switch ( *ptr )
- {
- case 0:
- continue;
- case '[':
- if ( !slen )
- break;
- if ( match )
- return NULL;
- match = strncmp(++ptr, section, slen) == 0 && ptr[slen] == ']';
- break;
- default:
- if ( match && strncmp(ptr, item, ilen) == 0 && ptr[ilen] == '=' )
- return ptr + ilen + 1;
- break;
- }
- ptr += strlen(ptr);
- }
- return NULL;
-}
static void __init split_value(char *s)
{
@@ -10,7 +10,7 @@
#include <xen/ctype.h>
#include <xen/init.h>
#include <asm/processor.h>
-
+#include <xen/keyhandler.h>
SIMPLE_TEXT_OUTPUT_INTERFACE *__initdata StdOut;
SIMPLE_TEXT_OUTPUT_INTERFACE *__initdata StdErr;
@@ -120,3 +120,215 @@ bool_t __init match_guid(const EFI_GUID *guid1, const EFI_GUID *guid2)
guid1->Data3 == guid2->Data3 &&
!memcmp(guid1->Data4, guid2->Data4, sizeof(guid1->Data4));
}
+
+
+/* generic routine for printing error messages */
+void __init PrintErrMesg(const CHAR16 *mesg, EFI_STATUS ErrCode)
+{
+ StdOut = StdErr;
+ PrintErr((CHAR16 *)mesg);
+ PrintErr(L": ");
+
+ switch (ErrCode)
+ {
+ case EFI_NOT_FOUND:
+ mesg = L"Not found";
+ break;
+ case EFI_NO_MEDIA:
+ mesg = L"The device has no media";
+ break;
+ case EFI_MEDIA_CHANGED:
+ mesg = L"Media changed";
+ break;
+ case EFI_DEVICE_ERROR:
+ mesg = L"Device error";
+ break;
+ case EFI_VOLUME_CORRUPTED:
+ mesg = L"Volume corrupted";
+ break;
+ case EFI_ACCESS_DENIED:
+ mesg = L"Access denied";
+ break;
+ case EFI_OUT_OF_RESOURCES:
+ mesg = L"Out of resources";
+ break;
+ case EFI_VOLUME_FULL:
+ mesg = L"Volume is full";
+ break;
+ case EFI_SECURITY_VIOLATION:
+ mesg = L"Security violation";
+ break;
+ case EFI_CRC_ERROR:
+ mesg = L"CRC error";
+ break;
+ case EFI_COMPROMISED_DATA:
+ mesg = L"Compromised data";
+ break;
+ default:
+ PrintErr(L"ErrCode: ");
+ DisplayUint(ErrCode, 0);
+ mesg = NULL;
+ break;
+ }
+ blexit(mesg);
+}
+
+EFI_FILE_HANDLE __init get_parent_handle(EFI_LOADED_IMAGE *loaded_image,
+ CHAR16 **leaf)
+{
+ static EFI_GUID __initdata fs_protocol = SIMPLE_FILE_SYSTEM_PROTOCOL;
+ EFI_FILE_HANDLE dir_handle;
+ EFI_DEVICE_PATH *dp;
+ CHAR16 *pathend, *ptr;
+ EFI_STATUS ret;
+
+ do {
+ EFI_FILE_IO_INTERFACE *fio;
+
+ /* Get the file system interface. */
+ ret = efi_bs->HandleProtocol(loaded_image->DeviceHandle,
+ &fs_protocol, (void **)&fio);
+ if ( EFI_ERROR(ret) )
+ PrintErrMesg(L"Couldn't obtain the File System Protocol Interface",
+ ret);
+ ret = fio->OpenVolume(fio, &dir_handle);
+ } while ( ret == EFI_MEDIA_CHANGED );
+ if ( ret != EFI_SUCCESS )
+ PrintErrMesg(L"OpenVolume failure", ret);
+
+#define buffer ((CHAR16 *)keyhandler_scratch)
+#define BUFFERSIZE sizeof(keyhandler_scratch)
+ for ( dp = loaded_image->FilePath, *buffer = 0;
+ DevicePathType(dp) != END_DEVICE_PATH_TYPE;
+ dp = (void *)dp + DevicePathNodeLength(dp) )
+ {
+ FILEPATH_DEVICE_PATH *fp;
+
+ if ( DevicePathType(dp) != MEDIA_DEVICE_PATH ||
+ DevicePathSubType(dp) != MEDIA_FILEPATH_DP )
+ blexit(L"Unsupported device path component");
+
+ if ( *buffer )
+ {
+ EFI_FILE_HANDLE new_handle;
+
+ ret = dir_handle->Open(dir_handle, &new_handle, buffer,
+ EFI_FILE_MODE_READ, 0);
+ if ( ret != EFI_SUCCESS )
+ {
+ PrintErr(L"Open failed for ");
+ PrintErrMesg(buffer, ret);
+ }
+ dir_handle->Close(dir_handle);
+ dir_handle = new_handle;
+ }
+ fp = (void *)dp;
+ if ( BUFFERSIZE < DevicePathNodeLength(dp) -
+ sizeof(*dp) + sizeof(*buffer) )
+ blexit(L"Increase BUFFERSIZE");
+ memcpy(buffer, fp->PathName, DevicePathNodeLength(dp) - sizeof(*dp));
+ buffer[(DevicePathNodeLength(dp) - sizeof(*dp)) / sizeof(*buffer)] = 0;
+ }
+ for ( ptr = buffer, pathend = NULL; *ptr; ++ptr )
+ if ( *ptr == L'\\' )
+ pathend = ptr;
+ if ( pathend )
+ {
+ *pathend = 0;
+ *leaf = pathend + 1;
+ if ( *buffer )
+ {
+ EFI_FILE_HANDLE new_handle;
+
+ ret = dir_handle->Open(dir_handle, &new_handle, buffer,
+ EFI_FILE_MODE_READ, 0);
+ if ( ret != EFI_SUCCESS ) {
+ PrintErr(L"Open failed for ");
+ PrintErrMesg(buffer, ret);
+ }
+ dir_handle->Close(dir_handle);
+ dir_handle = new_handle;
+ }
+ }
+ else
+ *leaf = buffer;
+#undef BUFFERSIZE
+#undef buffer
+
+ return dir_handle;
+}
+
+CHAR16 *__init point_tail(CHAR16 *fn)
+{
+ CHAR16 *tail = NULL;
+
+ for ( ; ; ++fn )
+ switch ( *fn )
+ {
+ case 0:
+ return tail;
+ case L'.':
+ case L'-':
+ case L'_':
+ tail = fn;
+ break;
+ }
+}
+
+void __init pre_parse(const struct file *cfg)
+{
+ char *ptr = cfg->ptr, *end = ptr + cfg->size;
+ bool_t start = 1, comment = 0;
+
+ for ( ; ptr < end; ++ptr )
+ {
+ if ( iscntrl(*ptr) )
+ {
+ comment = 0;
+ start = 1;
+ *ptr = 0;
+ }
+ else if ( comment || (start && isspace(*ptr)) )
+ *ptr = 0;
+ else if ( *ptr == '#' || (start && *ptr == ';') )
+ {
+ comment = 1;
+ *ptr = 0;
+ }
+ else
+ start = 0;
+ }
+ if ( cfg->size && end[-1] )
+ PrintStr(L"No newline at end of config file,"
+ " last line will be ignored.\r\n");
+}
+
+char *__init get_value(const struct file *cfg, const char *section,
+ const char *item)
+{
+ char *ptr = cfg->ptr, *end = ptr + cfg->size;
+ size_t slen = section ? strlen(section) : 0, ilen = strlen(item);
+ bool_t match = !slen;
+
+ for ( ; ptr < end; ++ptr )
+ {
+ switch ( *ptr )
+ {
+ case 0:
+ continue;
+ case '[':
+ if ( !slen )
+ break;
+ if ( match )
+ return NULL;
+ match = strncmp(++ptr, section, slen) == 0 && ptr[slen] == ']';
+ break;
+ default:
+ if ( match && strncmp(ptr, item, ilen) == 0 && ptr[ilen] == '=' )
+ return ptr + ilen + 1;
+ break;
+ }
+ ptr += strlen(ptr);
+ }
+ return NULL;
+}
@@ -2,6 +2,7 @@
#define __EFI_SHARED_H__
#include <efi/efidef.h>
+#include <efi/efiprot.h>
#include <xen/init.h>
@@ -36,4 +37,20 @@ CHAR16 *__init s2w(union string *str);
char *__init w2s(const union string *str);
bool_t __init match_guid(const EFI_GUID *guid1, const EFI_GUID *guid2);
+void __init PrintErrMesg(const CHAR16 *mesg, EFI_STATUS ErrCode);
+
+EFI_FILE_HANDLE __init get_parent_handle(EFI_LOADED_IMAGE *loaded_image,
+ CHAR16 **leaf);
+CHAR16 *__init point_tail(CHAR16 *fn);
+
+
+void __init pre_parse(const struct file *cfg);
+char *__init get_value(const struct file *cfg, const char *section,
+ const char *item);
+
+
+
+/* These functions need to be provided by the architecture's EFI code */
+void __init noreturn blexit(const CHAR16 *str);
+
#endif
Move the remainder of the functions that can be moved as is to efi-shared.c. This change is strictly moving of code without functional changes. Signed-off-by: Roy Franz <roy.franz@linaro.org> --- xen/arch/x86/efi/boot.c | 212 +---------------------------------------- xen/arch/x86/efi/efi-shared.c | 214 +++++++++++++++++++++++++++++++++++++++++- xen/include/efi/efi-shared.h | 17 ++++ 3 files changed, 231 insertions(+), 212 deletions(-)