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

This commit is contained in:
Alex Smith 2012-06-20 10:44:38 +01:00
parent cfd1c1802f
commit 7417d5ed8d
2 changed files with 55 additions and 13 deletions

View File

@ -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

View File

@ -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 *sPaths[] = {
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 *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);
}