changeset 11:7d337b6fb379

fix get_kernel_name, correct get kernel name from options
author taiki
date Sun, 30 Mar 2014 19:15:20 +0900
parents 0c55588d01b0
children 56e8a3d49069
files bootx64.c
diffstat 1 files changed, 40 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/bootx64.c	Sun Mar 30 03:37:30 2014 +0900
+++ b/bootx64.c	Sun Mar 30 19:15:20 2014 +0900
@@ -4,7 +4,19 @@
 #include "registers.h"
 
 CHAR16 *DEFAULT_KERNEL_NAME = L"my_kernel";
-CHAR16 SPACE = ' ';
+
+EFI_STATUS
+load_image(SIMPLE_READ_FILE file)
+{
+    Print(L"Start load image.\n");
+    return EFI_SUCCESS;
+}
+
+UINTN
+is_space(CHAR16 c)
+{
+    return  c == L' ' || c == L'\t' || c == L'\r' || c == L'\n';
+}
 
 CHAR16*
 get_kernel_name(CHAR16 *options, UINT32 options_size)
@@ -16,20 +28,33 @@
 
     UINT32 count = options_size;
 
-    while(options_size && (*options != SPACE)) {
+    Print(L"Options size: %d\n", options_size);
+
+    while(count && !is_space(*options)) {
         options++;
         count--;
     }
-    if (options_size <=  0) {
-        return DEFAULT_KERNEL_NAME;
+
+    Print(L"Count size: %d\n", count);
+
+    while (is_space(*options)) {
+        options++;
     }
 
-    if (*options == SPACE) {
+    CHAR16 *start_ptr = options;
+
+    while(!is_space(*options)) {
         options++;
     }
-    CHAR16 *kernel_name = (CHAR16 *)AllocatePool((options_size - count) * sizeof(CHAR16));
+
+    Print(L"optioins -%s-, start_ptr -%s-\n", options, start_ptr);
+
+    CHAR16 *kernel_name = (CHAR16 *)AllocatePool((options - start_ptr + 1) * sizeof(CHAR16));
 
-    RtCopyMem(kernel_name, options, (options_size - count) * sizeof(CHAR16));
+    RtCopyMem(kernel_name, start_ptr, (options - start_ptr) * sizeof(CHAR16));
+    kernel_name[options - start_ptr] = 0;
+
+    Print(L"kernel name: -%s- name size: %d\n", kernel_name, (options - start_ptr));
 
     return kernel_name;
     
@@ -40,10 +65,9 @@
 {
     Print(L"Start load kernel: %s\n", kernel_name);
 
-    EFI_STATUS status;
+    EFI_STATUS status = EFI_SUCCESS;
     UINTN handle_count;
     EFI_HANDLE *handle_buffer;
-    SIMPLE_READ_FILE read_handle = NULL;
 
     status = uefi_call_wrapper(BS->LocateHandleBuffer,
                 5,
@@ -55,22 +79,25 @@
 
     if (EFI_ERROR(status)) {
         Print(L"LocateHandleBuffer is %r\n", status);
+        return status;
     }
 
-    EFI_DEVICE_PATH *path;
+    EFI_DEVICE_PATH *path = NULL;
     UINTN handle_idx = 0;
+    SIMPLE_READ_FILE read_handle;
 
     for (handle_idx = 0; handle_idx < handle_count; handle_idx++) {
         EFI_HANDLE device_handle;
 
-        Print(L"handle_idx %d\n", handle_idx);
         path = FileDevicePath(handle_buffer[handle_idx], kernel_name);
 
+        Print(L"Path Type %d\n", path->Type);
         if (!path) {
             status = EFI_NOT_FOUND;
             break;
         }
 
+        Print(L"OpenSimpleReadFile\n");
         status = OpenSimpleReadFile(TRUE, NULL, 0, &path, &device_handle, &read_handle);
 
         if (!EFI_ERROR(status)) {
@@ -82,19 +109,18 @@
     }
 
     if (!EFI_ERROR(status)) {
-        //status = LoadImage(read_handle);
+        status = load_image(read_handle);
     }
 
     if (read_handle) {
+        Print(L"CloseSimpleReadFile.\n");
         CloseSimpleReadFile(read_handle);
     }
 
-    Print(L"c\n");
     if (path) {
         FreePool(path);
     }
 
-    Print(L"d\n");
     FreePool(handle_buffer);
 
     return status;