changeset 10:0c55588d01b0

add get kernel name from option
author taiki
date Sun, 30 Mar 2014 03:37:30 +0900
parents d6a8d676a1ac
children 7d337b6fb379
files bootx64.c bootx64.c.0
diffstat 2 files changed, 47 insertions(+), 68 deletions(-) [+]
line wrap: on
line diff
--- a/bootx64.c	Sun Mar 30 01:41:35 2014 +0900
+++ b/bootx64.c	Sun Mar 30 03:37:30 2014 +0900
@@ -3,10 +3,42 @@
 
 #include "registers.h"
 
+CHAR16 *DEFAULT_KERNEL_NAME = L"my_kernel";
+CHAR16 SPACE = ' ';
+
+CHAR16*
+get_kernel_name(CHAR16 *options, UINT32 options_size)
+{
+    /* 
+     * skip first option,
+     * first option is file name of this efi executable.
+     */ 
+
+    UINT32 count = options_size;
+
+    while(options_size && (*options != SPACE)) {
+        options++;
+        count--;
+    }
+    if (options_size <=  0) {
+        return DEFAULT_KERNEL_NAME;
+    }
+
+    if (*options == SPACE) {
+        options++;
+    }
+    CHAR16 *kernel_name = (CHAR16 *)AllocatePool((options_size - count) * sizeof(CHAR16));
+
+    RtCopyMem(kernel_name, options, (options_size - count) * sizeof(CHAR16));
+
+    return kernel_name;
+    
+}
+
 EFI_STATUS
-load_kernel()
+load_kernel(CHAR16 *kernel_name)
 {
-    Print(L"Start load kernel.\n");
+    Print(L"Start load kernel: %s\n", kernel_name);
 
     EFI_STATUS status;
     UINTN handle_count;
@@ -31,7 +63,8 @@
     for (handle_idx = 0; handle_idx < handle_count; handle_idx++) {
         EFI_HANDLE device_handle;
 
-        //path = FileDevicePath(handle_buffer[handle_idx], kernel_image);
+        Print(L"handle_idx %d\n", handle_idx);
+        path = FileDevicePath(handle_buffer[handle_idx], kernel_name);
 
         if (!path) {
             status = EFI_NOT_FOUND;
@@ -40,11 +73,12 @@
 
         status = OpenSimpleReadFile(TRUE, NULL, 0, &path, &device_handle, &read_handle);
 
-        if (EFI_ERROR(status)) {
-            FreePool(path);
-            path = NULL;
+        if (!EFI_ERROR(status)) {
+            break;
         }
-        break;
+
+        FreePool(path);
+        path = NULL;
     }
 
     if (!EFI_ERROR(status)) {
@@ -55,10 +89,12 @@
         CloseSimpleReadFile(read_handle);
     }
 
+    Print(L"c\n");
     if (path) {
         FreePool(path);
     }
 
+    Print(L"d\n");
     FreePool(handle_buffer);
 
     return status;
@@ -94,8 +130,11 @@
 
     Print(L"%s\n", loaded_image->LoadOptions);
 
-    load_kernel();
+    CHAR16 *kernel_name = get_kernel_name(loaded_image->LoadOptions, loaded_image->LoadOptionsSize);
 
+    Print(L"%s\n", kernel_name);
+
+    load_kernel(kernel_name);
 
     Print(L"Close LoadedImage Protocol\n");
     status = uefi_call_wrapper(
--- a/bootx64.c.0	Sun Mar 30 01:41:35 2014 +0900
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,60 +0,0 @@
-#include <efi.h>
-#include <efilib.h>
-
-EFI_STATUS
-efi_main(EFI_HANDLE image, EFI_SYSTEM_TABLE *systab)
-{
-    InitializeLib(image, systab);
-
-    Print(L"test start.\n");
-
-    EFI_STATUS status = EFI_SUCCESS;
-    UINTN size = 0;
-
-    status = uefi_call_wrapper(BS->LocateHandle, 5, ByProtocol, &FileSystemProtocol, NULL, &size, NULL);
-    if (size == 0) return EFI_UNSUPPORTED;
-
-    VOID *tmp = 0;
-    size = 10 * sizeof(EFI_HANDLE);
-    status = uefi_call_wrapper(BS->AllocatePool, 3, EfiLoaderData, size, &tmp);
-
-    if (EFI_SUCCESS != status) {
-        Print(L"can not allocate. %r\n", status);
-        return status;
-    }
-    Print(L"===success allocate.\n");
-
-    EFI_HANDLE *buffer = tmp;
-
-    Print(L"size is %d\n", size);
-    Print(L"ByProtocol %d\n", ByProtocol);
-    Print(L"size %d\n", size);
-    Print(L"buffer %d\n", buffer);
-
-
-    status = uefi_call_wrapper(BS->LocateHandle, 5, ByProtocol, &FileSystemProtocol, NULL, &size, buffer);
-    if (status != EFI_SUCCESS) {
-        Print(L"can not get handler %r\n", status);
-    }
-    /*
-    status = LibLocateHandle(ByProtocol, &FileSystemProtocol, NULL, &size, buffer);
-    if (status != EFI_SUCCESS) {
-        Print(L"can not get handler %r\n", status);
-        return status;
-    }
-    */
-
-    EFI_FILE_IO_INTERFACE *volume;
-    status = uefi_call_wrapper(BS->HandleProtocol, 3, *buffer, &FileSystemProtocol, (VOID **)&volume);
-    if (EFI_ERROR(status)) {
-        Print(L"can not get handle protocol");
-        return EFI_INVALID_PARAMETER;
-    }
-
-
-    while(1) {
-    }
-
-
-    return EFI_SUCCESS;
-}