[haiku-commits] BRANCH xyzzy-github.x86_64 - src/system/boot/loader

  • From: xyzzy-github.x86_64 <community@xxxxxxxxxxxx>
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Wed, 20 Jun 2012 11:49:02 +0200 (CEST)

added 1 changeset to branch 'refs/remotes/xyzzy-github/x86_64'
old head: cfd1c1802f3c3250f96a14db3c65eed4667f09db
new head: 7417d5ed8deef641a6941e5a17a47781b8f8959c

----------------------------------------------------------------------------

7417d5e: Made the bootloader search for both kernel_x86 and kernel_x86_64 when 
built for x86 or x86_64.

                                      [ Alex Smith <alex@xxxxxxxxxxxxxxxx> ]

----------------------------------------------------------------------------

Commit:      7417d5ed8deef641a6941e5a17a47781b8f8959c

Author:      Alex Smith <alex@xxxxxxxxxxxxxxxx>
Date:        Wed Jun 20 09:44:38 2012 UTC

----------------------------------------------------------------------------

2 files changed, 55 insertions(+), 13 deletions(-)
src/system/boot/loader/Jamfile    |   12 +++++++
src/system/boot/loader/loader.cpp |   56 +++++++++++++++++++++++++--------

----------------------------------------------------------------------------

diff --git a/src/system/boot/loader/Jamfile b/src/system/boot/loader/Jamfile
index 1cb962c..00135e2 100644
--- a/src/system/boot/loader/Jamfile
+++ b/src/system/boot/loader/Jamfile
@@ -38,6 +38,18 @@ UsePrivateHeaders shared storage ;
                case "x86" :
                {
                        defines +=
+                               ALTERNATE_BOOT_ARCH=\\\"x86_64\\\"
+
+                               BOOT_SUPPORT_PARTITION_EFI
+
+                               #BOOT_SUPPORT_FILE_SYSTEM_FAT
+                       ;
+               }
+               case "x86_64" :
+               {
+                       defines +=
+                               ALTERNATE_BOOT_ARCH=\\\"x86\\\"
+
                                BOOT_SUPPORT_PARTITION_EFI
 
                                #BOOT_SUPPORT_FILE_SYSTEM_FAT
diff --git a/src/system/boot/loader/loader.cpp 
b/src/system/boot/loader/loader.cpp
index fb5c2b4..7fd888b 100644
--- a/src/system/boot/loader/loader.cpp
+++ b/src/system/boot/loader/loader.cpp
@@ -24,11 +24,24 @@
 #      error BOOT_ARCH has to be defined to differentiate the kernel per 
platform
 #endif
 
-#define KERNEL_IMAGE   "kernel_" BOOT_ARCH
-#define KERNEL_PATH            "system/" KERNEL_IMAGE
+#define KERNEL_IMAGE                   "kernel_" BOOT_ARCH
+#define KERNEL_PATH                            "system/" KERNEL_IMAGE
 
+#ifdef ALTERNATE_BOOT_ARCH
+# define ALTERNATE_KERNEL_IMAGE        "kernel_" ALTERNATE_BOOT_ARCH
+# define ALTERNATE_KERNEL_PATH "system/" ALTERNATE_KERNEL_IMAGE
+#endif
+
+
+static const char *sKernelPaths[][2] = {
+       { KERNEL_PATH, KERNEL_IMAGE },
+#ifdef ALTERNATE_BOOT_ARCH
+       { ALTERNATE_KERNEL_PATH, ALTERNATE_KERNEL_IMAGE },
+#endif
+       { NULL, NULL },
+};
 
-static const char *sPaths[] = {
+static const char *sAddonPaths[] = {
        kVolumeLocalSystemKernelAddonsDirectory,
        kVolumeLocalCommonKernelAddonsDirectory,
        kVolumeLocalUserKernelAddonsDirectory,
@@ -36,6 +49,22 @@ static const char *sPaths[] = {
 };
 
 
+static int
+find_kernel(Directory *volume, const char **name = NULL)
+{
+       for (int32 i = 0; sKernelPaths[i][0] != NULL; i++) {
+               int fd = open_from(volume, sKernelPaths[i][0], O_RDONLY);
+               if (fd >= 0) {
+                       if (name)
+                               *name = sKernelPaths[i][1];
+
+                       return fd;
+               }
+       }
+
+       return B_ENTRY_NOT_FOUND;
+}
+
 bool
 is_bootable(Directory *volume)
 {
@@ -43,7 +72,7 @@ is_bootable(Directory *volume)
                return false;
 
        // check for the existance of a kernel (for our platform)
-       int fd = open_from(volume, KERNEL_PATH, O_RDONLY);
+       int fd = find_kernel(volume);
        if (fd < B_OK)
                return false;
 
@@ -56,11 +85,12 @@ is_bootable(Directory *volume)
 status_t
 load_kernel(stage2_args *args, Directory *volume)
 {
-       int fd = open_from(volume, KERNEL_PATH, O_RDONLY);
+       const char *name;
+       int fd = find_kernel(volume, &name);
        if (fd < B_OK)
                return fd;
 
-       dprintf("load kernel...\n");
+       dprintf("load kernel %s...\n", name);
 
        elf_init();
        status_t status = elf_load_image(fd, &gKernelArgs.kernel_image);
@@ -78,7 +108,7 @@ load_kernel(stage2_args *args, Directory *volume)
                return status;
        }
 
-       gKernelArgs.kernel_image.name = kernel_args_strdup(KERNEL_IMAGE);
+       gKernelArgs.kernel_image.name = kernel_args_strdup(name);
 
        return B_OK;
 }
@@ -129,9 +159,9 @@ load_module(Directory *volume, const char *name)
        if (strlcpy(moduleName, name, sizeof(moduleName)) > sizeof(moduleName))
                return B_NAME_TOO_LONG;
 
-       for (int32 i = 0; sPaths[i]; i++) {
+       for (int32 i = 0; sAddonPaths[i]; i++) {
                // get base path
-               int baseFD = open_from(volume, sPaths[i], O_RDONLY);
+               int baseFD = open_from(volume, sAddonPaths[i], O_RDONLY);
                if (baseFD < B_OK)
                        continue;
 
@@ -179,9 +209,9 @@ load_modules(stage2_args *args, Directory *volume)
        // ToDo: this should be mostly replaced by a hardware oriented 
detection mechanism
 
        int32 i = 0;
-       for (; sPaths[i]; i++) {
+       for (; sAddonPaths[i]; i++) {
                char path[B_FILE_NAME_LENGTH];
-               snprintf(path, sizeof(path), "%s/boot", sPaths[i]);
+               snprintf(path, sizeof(path), "%s/boot", sAddonPaths[i]);
 
                if (load_modules_from(volume, path) != B_OK)
                        failed++;
@@ -195,7 +225,7 @@ load_modules(stage2_args *args, Directory *volume)
 
                for (int32 i = 0; paths[i]; i++) {
                        char path[B_FILE_NAME_LENGTH];
-                       snprintf(path, sizeof(path), "%s/%s", sPaths[0], 
paths[i]);
+                       snprintf(path, sizeof(path), "%s/%s", sAddonPaths[0], 
paths[i]);
                        load_modules_from(volume, path);
                }
        }
@@ -220,7 +250,7 @@ load_modules(stage2_args *args, Directory *volume)
                //      as this piece will survive a more intelligent module
                //      loading approach...
                char path[B_FILE_NAME_LENGTH];
-               snprintf(path, sizeof(path), "%s/%s", sPaths[0], 
"file_systems");
+               snprintf(path, sizeof(path), "%s/%s", sAddonPaths[0], 
"file_systems");
                load_modules_from(volume, path);
        }
 


Other related posts:

  • » [haiku-commits] BRANCH xyzzy-github.x86_64 - src/system/boot/loader - xyzzy-github . x86_64