Changeset View
Changeset View
Standalone View
Standalone View
sys/boot/efi/boot1/boot1.c
Show First 20 Lines • Show All 47 Lines • ▼ Show 20 Lines | |||||
#define DSTALL(d) bs->Stall(d) | #define DSTALL(d) bs->Stall(d) | ||||
#else | #else | ||||
#define DPRINTF(fmt, ...) {} | #define DPRINTF(fmt, ...) {} | ||||
#define DSTALL(d) {} | #define DSTALL(d) {} | ||||
#endif | #endif | ||||
struct arch_switch archsw; /* MI/MD interface boundary */ | struct arch_switch archsw; /* MI/MD interface boundary */ | ||||
static const efi_driver_t *efi_drivers[] = { | const efi_driver_t *efi_drivers[] = { | ||||
&key_inject_driver, | |||||
&geli_driver, | |||||
NULL | NULL | ||||
}; | }; | ||||
extern struct console efi_console; | extern struct console efi_console; | ||||
#if defined(__amd64__) || defined(__i386__) | #if defined(__amd64__) || defined(__i386__) | ||||
extern struct console comconsole; | extern struct console comconsole; | ||||
extern struct console nullconsole; | extern struct console nullconsole; | ||||
#endif | #endif | ||||
▲ Show 20 Lines • Show All 428 Lines • ▼ Show 20 Lines | if (pool_guid != 0) { | ||||
struct zfs_devdesc *currdev = malloc(sizeof (struct zfs_devdesc)); | struct zfs_devdesc *currdev = malloc(sizeof (struct zfs_devdesc)); | ||||
currdev->d_dev = &zfs_dev; | currdev->d_dev = &zfs_dev; | ||||
currdev->d_unit = 0; | currdev->d_unit = 0; | ||||
currdev->d_type = currdev->d_dev->dv_type; | currdev->d_type = currdev->d_dev->dv_type; | ||||
currdev->d_opendata = NULL; | currdev->d_opendata = NULL; | ||||
currdev->pool_guid = pool_guid; | currdev->pool_guid = pool_guid; | ||||
currdev->root_guid = 0; | currdev->root_guid = 0; | ||||
imp: style changes should be separated out.
| |||||
if (probe_fs((struct devdesc *)currdev, filepath) == 0 && | if (probe_fs((struct devdesc *)currdev, filepath) == 0 && | ||||
do_load(filepath, bufp, bufsize) == EFI_SUCCESS) { | do_load(filepath, bufp, bufsize) == EFI_SUCCESS) { | ||||
*handlep = img->DeviceHandle; | *handlep = img->DeviceHandle; | ||||
return (0); | return (0); | ||||
} | } | ||||
free(currdev); | free(currdev); | ||||
} | } | ||||
#endif /* EFI_ZFS_BOOT */ | #endif /* EFI_ZFS_BOOT */ | ||||
/* We have device lists for hd, cd, fd, walk them all. */ | /* We have device lists for hd, cd, fd, walk them all. */ | ||||
pdi_list = efiblk_get_pdinfo_list(&efipart_hddev); | pdi_list = efiblk_get_pdinfo_list(&efipart_hddev); | ||||
STAILQ_FOREACH(dp, pdi_list, pd_link) { | STAILQ_FOREACH(dp, pdi_list, pd_link) { | ||||
struct disk_devdesc *currdev = malloc(sizeof (struct disk_devdesc)); | struct disk_devdesc *currdev = malloc(sizeof (struct disk_devdesc)); | ||||
currdev->d_dev = &efipart_hddev; | currdev->d_dev = &efipart_hddev; | ||||
currdev->d_type = currdev->d_dev->dv_type; | currdev->d_type = currdev->d_dev->dv_type; | ||||
currdev->d_unit = dp->pd_unit; | currdev->d_unit = dp->pd_unit; | ||||
currdev->d_opendata = NULL; | currdev->d_opendata = NULL; | ||||
currdev->d_slice = -1; | currdev->d_slice = -1; | ||||
currdev->d_partition = -1; | currdev->d_partition = -1; | ||||
Not Done Inline Actionsstyle change imp: style change | |||||
if (dp->pd_handle == img->DeviceHandle && | if (dp->pd_handle == img->DeviceHandle && | ||||
probe_fs((struct devdesc *)currdev, filepath) == 0 && | probe_fs((struct devdesc *)currdev, filepath) == 0 && | ||||
do_load(filepath, bufp, bufsize) == EFI_SUCCESS) { | do_load(filepath, bufp, bufsize) == EFI_SUCCESS) { | ||||
*handlep = img->DeviceHandle; | *handlep = img->DeviceHandle; | ||||
return (0); | return (0); | ||||
} | } | ||||
/* Assuming GPT partitioning. */ | /* Assuming GPT partitioning. */ | ||||
STAILQ_FOREACH(pp, &dp->pd_part, pd_link) { | STAILQ_FOREACH(pp, &dp->pd_part, pd_link) { | ||||
if (pp->pd_handle == img->DeviceHandle) { | if (pp->pd_handle == img->DeviceHandle) { | ||||
currdev->d_slice = pp->pd_unit; | currdev->d_slice = pp->pd_unit; | ||||
currdev->d_partition = 255; | currdev->d_partition = 255; | ||||
Not Done Inline Actionsstyle change imp: style change
| |||||
if (probe_fs((struct devdesc *)currdev, | if (probe_fs((struct devdesc *)currdev, | ||||
filepath) == 0 && | filepath) == 0 && | ||||
do_load(filepath, bufp, bufsize) == | do_load(filepath, bufp, bufsize) == | ||||
EFI_SUCCESS) { | EFI_SUCCESS) { | ||||
*handlep = img->DeviceHandle; | *handlep = img->DeviceHandle; | ||||
return (0); | return (0); | ||||
} | } | ||||
} | } | ||||
▲ Show 20 Lines • Show All 79 Lines • ▼ Show 20 Lines | STAILQ_FOREACH(zi, zfsi_list, zi_link) { | ||||
struct zfs_devdesc *currdev = malloc(sizeof (struct zfs_devdesc)); | struct zfs_devdesc *currdev = malloc(sizeof (struct zfs_devdesc)); | ||||
currdev->d_dev = &zfs_dev; | currdev->d_dev = &zfs_dev; | ||||
currdev->d_unit = 0; | currdev->d_unit = 0; | ||||
currdev->d_type = currdev->d_dev->dv_type; | currdev->d_type = currdev->d_dev->dv_type; | ||||
currdev->d_opendata = NULL; | currdev->d_opendata = NULL; | ||||
currdev->pool_guid = pool_guid; | currdev->pool_guid = pool_guid; | ||||
currdev->root_guid = 0; | currdev->root_guid = 0; | ||||
Not Done Inline Actionsstyle change imp: style change
| |||||
if (probe_fs((struct devdesc *)currdev, filepath) == 0 && | if (probe_fs((struct devdesc *)currdev, filepath) == 0 && | ||||
do_load(filepath, bufp, bufsize) == EFI_SUCCESS) { | do_load(filepath, bufp, bufsize) == EFI_SUCCESS) { | ||||
*handlep = zi->zi_handle; | *handlep = zi->zi_handle; | ||||
Not Done Inline Actionsdebug change should be separate. imp: debug change should be separate. | |||||
return (0); | return (0); | ||||
} | } | ||||
free(currdev); | free(currdev); | ||||
} | } | ||||
#endif /* EFI_ZFS_BOOT */ | #endif /* EFI_ZFS_BOOT */ | ||||
/* We have device lists for hd, cd, fd, walk them all. */ | /* We have device lists for hd, cd, fd, walk them all. */ | ||||
pdi_list = efiblk_get_pdinfo_list(&efipart_hddev); | pdi_list = efiblk_get_pdinfo_list(&efipart_hddev); | ||||
STAILQ_FOREACH(dp, pdi_list, pd_link) { | STAILQ_FOREACH(dp, pdi_list, pd_link) { | ||||
struct disk_devdesc *currdev = malloc(sizeof (struct disk_devdesc)); | struct disk_devdesc *currdev = malloc(sizeof (struct disk_devdesc)); | ||||
currdev->d_dev = &efipart_hddev; | currdev->d_dev = &efipart_hddev; | ||||
currdev->d_type = currdev->d_dev->dv_type; | currdev->d_type = currdev->d_dev->dv_type; | ||||
currdev->d_unit = dp->pd_unit; | currdev->d_unit = dp->pd_unit; | ||||
currdev->d_opendata = NULL; | currdev->d_opendata = NULL; | ||||
currdev->d_slice = -1; | currdev->d_slice = -1; | ||||
currdev->d_partition = -1; | currdev->d_partition = -1; | ||||
Not Done Inline Actionsstyle change imp: style change | |||||
if (probe_fs((struct devdesc *)currdev, filepath) == 0 && | if (probe_fs((struct devdesc *)currdev, filepath) == 0 && | ||||
do_load(filepath, bufp, bufsize) == EFI_SUCCESS) { | do_load(filepath, bufp, bufsize) == EFI_SUCCESS) { | ||||
*handlep = dp->pd_handle; | *handlep = dp->pd_handle; | ||||
return (0); | return (0); | ||||
} | } | ||||
/* Assuming GPT partitioning. */ | /* Assuming GPT partitioning. */ | ||||
STAILQ_FOREACH(pp, &dp->pd_part, pd_link) { | STAILQ_FOREACH(pp, &dp->pd_part, pd_link) { | ||||
currdev->d_slice = pp->pd_unit; | currdev->d_slice = pp->pd_unit; | ||||
Not Done Inline Actionsdon't use magic numbers, define a constant. imp: don't use magic numbers, define a constant. | |||||
currdev->d_partition = 255; | currdev->d_partition = 255; | ||||
if (probe_fs((struct devdesc *)currdev, | if (probe_fs((struct devdesc *)currdev, | ||||
filepath) == 0 && | filepath) == 0 && | ||||
do_load(filepath, bufp, bufsize) == EFI_SUCCESS) { | do_load(filepath, bufp, bufsize) == EFI_SUCCESS) { | ||||
*handlep = pp->pd_handle; | *handlep = pp->pd_handle; | ||||
return (0); | return (0); | ||||
▲ Show 20 Lines • Show All 63 Lines • ▼ Show 20 Lines | try_boot(void) | ||||
void *buf, *loaderbuf; | void *buf, *loaderbuf; | ||||
char *cmd; | char *cmd; | ||||
EFI_HANDLE fshandle; | EFI_HANDLE fshandle; | ||||
EFI_HANDLE loaderhandle; | EFI_HANDLE loaderhandle; | ||||
EFI_LOADED_IMAGE *loaded_image; | EFI_LOADED_IMAGE *loaded_image; | ||||
EFI_STATUS status; | EFI_STATUS status; | ||||
EFI_DEVICE_PATH *fspath; | EFI_DEVICE_PATH *fspath; | ||||
printf("Starting boot process\n"); | |||||
status = load_loader(&fshandle, &loaderbuf, &loadersize); | status = load_loader(&fshandle, &loaderbuf, &loadersize); | ||||
printf("Got loader, setting up to boot\n"); | |||||
if (status != EFI_SUCCESS) { | if (status != EFI_SUCCESS) { | ||||
return (status); | return (status); | ||||
} | } | ||||
fspath = NULL; | fspath = NULL; | ||||
if (status == EFI_SUCCESS) { | if (status == EFI_SUCCESS) { | ||||
status = BS->OpenProtocol(fshandle, &DevicePathGUID, | status = BS->OpenProtocol(fshandle, &DevicePathGUID, | ||||
Show All 10 Lines | try_boot(void) | ||||
* if present. We'll pass it the next stage via a simple ASCII | * if present. We'll pass it the next stage via a simple ASCII | ||||
* string. loader.efi has a hack for ASCII strings, so we'll use that to | * string. loader.efi has a hack for ASCII strings, so we'll use that to | ||||
* keep the size down here. We only try to read the alternate file if | * keep the size down here. We only try to read the alternate file if | ||||
* we get EFI_NOT_FOUND because all other errors mean that the boot_module | * we get EFI_NOT_FOUND because all other errors mean that the boot_module | ||||
* had troubles with the filesystem. We could return early, but we'll let | * had troubles with the filesystem. We could return early, but we'll let | ||||
* loading the actual kernel sort all that out. Since these files are | * loading the actual kernel sort all that out. Since these files are | ||||
* optional, we don't report errors in trying to read them. | * optional, we don't report errors in trying to read them. | ||||
*/ | */ | ||||
printf("Loading config files\n"); | |||||
cmd = NULL; | cmd = NULL; | ||||
cmdsize = 0; | cmdsize = 0; | ||||
status = do_load(PATH_DOTCONFIG, &buf, &bufsize); | status = do_load(PATH_DOTCONFIG, &buf, &bufsize); | ||||
if (status == EFI_NOT_FOUND) | if (status == EFI_NOT_FOUND) | ||||
status = do_load(PATH_CONFIG, &buf, &bufsize); | status = do_load(PATH_CONFIG, &buf, &bufsize); | ||||
if (status == EFI_SUCCESS) { | if (status == EFI_SUCCESS) { | ||||
cmdsize = bufsize + 1; | cmdsize = bufsize + 1; | ||||
cmd = malloc(cmdsize); | cmd = malloc(cmdsize); | ||||
if (cmd == NULL) | if (cmd == NULL) | ||||
goto errout; | goto errout; | ||||
memcpy(cmd, buf, bufsize); | memcpy(cmd, buf, bufsize); | ||||
cmd[bufsize] = '\0'; | cmd[bufsize] = '\0'; | ||||
free(buf); | free(buf); | ||||
buf = NULL; | buf = NULL; | ||||
} | } | ||||
printf("Preparing image\n"); | |||||
if ((status = BS->LoadImage(TRUE, IH, devpath_last(fspath), | if ((status = BS->LoadImage(TRUE, IH, devpath_last(fspath), | ||||
loaderbuf, loadersize, &loaderhandle)) != EFI_SUCCESS) { | loaderbuf, loadersize, &loaderhandle)) != EFI_SUCCESS) { | ||||
printf("Failed to load image, size: %zu, (%lu)\n", | printf("Failed to load image, size: %zu, (%lu)\n", | ||||
loadersize, EFI_ERROR_CODE(status)); | loadersize, EFI_ERROR_CODE(status)); | ||||
goto errout; | goto errout; | ||||
} | } | ||||
if ((status = BS->OpenProtocol(loaderhandle, &LoadedImageGUID, | if ((status = BS->OpenProtocol(loaderhandle, &LoadedImageGUID, | ||||
Show All 18 Lines | try_boot(void) | ||||
DPRINTF("."); | DPRINTF("."); | ||||
DSTALL(1000000); | DSTALL(1000000); | ||||
DPRINTF("."); | DPRINTF("."); | ||||
DSTALL(1000000); | DSTALL(1000000); | ||||
DPRINTF("."); | DPRINTF("."); | ||||
DSTALL(1000000); | DSTALL(1000000); | ||||
DPRINTF(".\n"); | DPRINTF(".\n"); | ||||
printf("Booting\n"); | |||||
if ((status = BS->StartImage(loaderhandle, NULL, NULL)) != | if ((status = BS->StartImage(loaderhandle, NULL, NULL)) != | ||||
EFI_SUCCESS) { | EFI_SUCCESS) { | ||||
printf("Failed to start image (%lu)\n", | printf("Failed to start image (%lu)\n", | ||||
EFI_ERROR_CODE(status)); | EFI_ERROR_CODE(status)); | ||||
loaded_image->LoadOptionsSize = 0; | loaded_image->LoadOptionsSize = 0; | ||||
loaded_image->LoadOptions = NULL; | loaded_image->LoadOptions = NULL; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 60 Lines • ▼ Show 20 Lines | #endif | ||||
archsw.arch_autoload = efi_autoload; | archsw.arch_autoload = efi_autoload; | ||||
archsw.arch_getdev = efi_getdev; | archsw.arch_getdev = efi_getdev; | ||||
archsw.arch_copyin = efi_copyin; | archsw.arch_copyin = efi_copyin; | ||||
archsw.arch_copyout = efi_copyout; | archsw.arch_copyout = efi_copyout; | ||||
archsw.arch_readin = efi_readin; | archsw.arch_readin = efi_readin; | ||||
printf(" Loader path: %s\n\n", PATH_LOADER_EFI); | printf(" Loader path: %s\n\n", PATH_LOADER_EFI); | ||||
printf(" Initializing modules:"); | |||||
bcache_init(32768, 512); | |||||
for (i = 0; efi_drivers[i] != NULL; i++) { | for (i = 0; efi_drivers[i] != NULL; i++) { | ||||
printf(" %s", efi_drivers[i]->name); | |||||
if (efi_drivers[i]->init != NULL) | if (efi_drivers[i]->init != NULL) | ||||
efi_drivers[i]->init(); | efi_drivers[i]->init(); | ||||
} | } | ||||
printf("Probing devices:"); | |||||
for (i = 0; devsw[i] != NULL; i++) { | for (i = 0; devsw[i] != NULL; i++) { | ||||
if (devsw[i]->dv_init != NULL) { | |||||
printf(" %s", devsw[i]->dv_name); | printf(" %s", devsw[i]->dv_name); | ||||
if (devsw[i]->dv_init != NULL) { | |||||
(devsw[i]->dv_init)(); | (devsw[i]->dv_init)(); | ||||
Not Done Inline ActionsThis change should be separate. imp: This change should be separate. | |||||
} | } | ||||
} | } | ||||
printf("\nDone\n"); | |||||
putchar('\n'); | putchar('\n'); | ||||
try_boot(); | try_boot(); | ||||
/* If we get here, we're out of luck... */ | /* If we get here, we're out of luck... */ | ||||
panic("No bootable partitions found!"); | panic("No bootable partitions found!"); | ||||
} | } |
style changes should be separated out.