Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F157071926
D11820.id31464.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
16 KB
Referenced Files
None
Subscribers
None
D11820.id31464.diff
View Options
Index: sys/boot/efi/boot1/Makefile
===================================================================
--- sys/boot/efi/boot1/Makefile
+++ sys/boot/efi/boot1/Makefile
@@ -83,8 +83,9 @@
# __aeabi_* (arm) or __divdi3 (i386).
# as well as required string and memory functions for all platforms.
#
-DPADD+= ${LIBSTAND}
-LDADD+= -lstand
+LIBEFI= ${.OBJDIR}/../libefi/libefi.a
+DPADD+= ${LIBEFI} ${LIBSTAND}
+LDADD+= ${LIBEFI} -lstand
DPADD+= ${LDSCRIPT}
Index: sys/boot/efi/boot1/boot1.c
===================================================================
--- sys/boot/efi/boot1/boot1.c
+++ sys/boot/efi/boot1/boot1.c
@@ -142,178 +142,6 @@
}
/*
- * devpath_node_str is a basic output method for a devpath node which
- * only understands a subset of the available sub types.
- *
- * If we switch to UEFI 2.x then we should update it to use:
- * EFI_DEVICE_PATH_TO_TEXT_PROTOCOL.
- */
-static int
-devpath_node_str(char *buf, size_t size, EFI_DEVICE_PATH *devpath)
-{
-
- switch (devpath->Type) {
- case MESSAGING_DEVICE_PATH:
- switch (devpath->SubType) {
- case MSG_ATAPI_DP: {
- ATAPI_DEVICE_PATH *atapi;
-
- atapi = (ATAPI_DEVICE_PATH *)(void *)devpath;
- return snprintf(buf, size, "ata(%s,%s,0x%x)",
- (atapi->PrimarySecondary == 1) ? "Sec" : "Pri",
- (atapi->SlaveMaster == 1) ? "Slave" : "Master",
- atapi->Lun);
- }
- case MSG_USB_DP: {
- USB_DEVICE_PATH *usb;
-
- usb = (USB_DEVICE_PATH *)devpath;
- return snprintf(buf, size, "usb(0x%02x,0x%02x)",
- usb->ParentPortNumber, usb->InterfaceNumber);
- }
- case MSG_SCSI_DP: {
- SCSI_DEVICE_PATH *scsi;
-
- scsi = (SCSI_DEVICE_PATH *)(void *)devpath;
- return snprintf(buf, size, "scsi(0x%02x,0x%02x)",
- scsi->Pun, scsi->Lun);
- }
- case MSG_SATA_DP: {
- SATA_DEVICE_PATH *sata;
-
- sata = (SATA_DEVICE_PATH *)(void *)devpath;
- return snprintf(buf, size, "sata(0x%x,0x%x,0x%x)",
- sata->HBAPortNumber, sata->PortMultiplierPortNumber,
- sata->Lun);
- }
- default:
- return snprintf(buf, size, "msg(0x%02x)",
- devpath->SubType);
- }
- break;
- case HARDWARE_DEVICE_PATH:
- switch (devpath->SubType) {
- case HW_PCI_DP: {
- PCI_DEVICE_PATH *pci;
-
- pci = (PCI_DEVICE_PATH *)devpath;
- return snprintf(buf, size, "pci(0x%02x,0x%02x)",
- pci->Device, pci->Function);
- }
- default:
- return snprintf(buf, size, "hw(0x%02x)",
- devpath->SubType);
- }
- break;
- case ACPI_DEVICE_PATH: {
- ACPI_HID_DEVICE_PATH *acpi;
-
- acpi = (ACPI_HID_DEVICE_PATH *)(void *)devpath;
- if ((acpi->HID & PNP_EISA_ID_MASK) == PNP_EISA_ID_CONST) {
- switch (EISA_ID_TO_NUM(acpi->HID)) {
- case 0x0a03:
- return snprintf(buf, size, "pciroot(0x%x)",
- acpi->UID);
- case 0x0a08:
- return snprintf(buf, size, "pcieroot(0x%x)",
- acpi->UID);
- case 0x0604:
- return snprintf(buf, size, "floppy(0x%x)",
- acpi->UID);
- case 0x0301:
- return snprintf(buf, size, "keyboard(0x%x)",
- acpi->UID);
- case 0x0501:
- return snprintf(buf, size, "serial(0x%x)",
- acpi->UID);
- case 0x0401:
- return snprintf(buf, size, "parallelport(0x%x)",
- acpi->UID);
- default:
- return snprintf(buf, size, "acpi(pnp%04x,0x%x)",
- EISA_ID_TO_NUM(acpi->HID), acpi->UID);
- }
- }
-
- return snprintf(buf, size, "acpi(0x%08x,0x%x)", acpi->HID,
- acpi->UID);
- }
- case MEDIA_DEVICE_PATH:
- switch (devpath->SubType) {
- case MEDIA_CDROM_DP: {
- CDROM_DEVICE_PATH *cdrom;
-
- cdrom = (CDROM_DEVICE_PATH *)(void *)devpath;
- return snprintf(buf, size, "cdrom(%x)",
- cdrom->BootEntry);
- }
- case MEDIA_HARDDRIVE_DP: {
- HARDDRIVE_DEVICE_PATH *hd;
-
- hd = (HARDDRIVE_DEVICE_PATH *)(void *)devpath;
- return snprintf(buf, size, "hd(%x)",
- hd->PartitionNumber);
- }
- default:
- return snprintf(buf, size, "media(0x%02x)",
- devpath->SubType);
- }
- case BBS_DEVICE_PATH:
- return snprintf(buf, size, "bbs(0x%02x)", devpath->SubType);
- case END_DEVICE_PATH_TYPE:
- return (0);
- }
-
- return snprintf(buf, size, "type(0x%02x, 0x%02x)", devpath->Type,
- devpath->SubType);
-}
-
-/*
- * devpath_strlcat appends a text description of devpath to buf but not more
- * than size - 1 characters followed by NUL-terminator.
- */
-int
-devpath_strlcat(char *buf, size_t size, EFI_DEVICE_PATH *devpath)
-{
- size_t len, used;
- const char *sep;
-
- sep = "";
- used = 0;
- while (!IsDevicePathEnd(devpath)) {
- len = snprintf(buf, size - used, "%s", sep);
- used += len;
- if (used > size)
- return (used);
- buf += len;
-
- len = devpath_node_str(buf, size - used, devpath);
- used += len;
- if (used > size)
- return (used);
- buf += len;
- devpath = NextDevicePathNode(devpath);
- sep = ":";
- }
-
- return (used);
-}
-
-/*
- * devpath_str is convenience method which returns the text description of
- * devpath using a static buffer, so it isn't thread safe!
- */
-char *
-devpath_str(EFI_DEVICE_PATH *devpath)
-{
- static char buf[256];
-
- devpath_strlcat(buf, sizeof(buf), devpath);
-
- return buf;
-}
-
-/*
* load_loader attempts to load the loader image data.
*
* It tries each module and its respective devices, identified by mod->probe,
@@ -477,7 +305,15 @@
return (status);
}
- DPRINTF("probing: %s\n", devpath_str(devpath));
+#ifdef EFI_DEBUG
+ {
+ CHAR16 *text;
+
+ text = efi_devpath_name(devpath);
+ DPRINTF("probing: %S\n", text);
+ efi_free_devpath_name(text);
+ }
+#endif
status = bs->HandleProtocol(h, &BlockIoProtocolGUID, (void **)&blkio);
if (status == EFI_UNSUPPORTED)
@@ -651,7 +487,15 @@
if (status != EFI_SUCCESS)
DPRINTF("Failed to get image DevicePath (%lu)\n",
EFI_ERROR_CODE(status));
- DPRINTF("boot1 imagepath: %s\n", devpath_str(imgpath));
+#ifdef EFI_DEBUG
+ {
+ CHAR16 *text;
+
+ text = efi_devpath_name(imgpath);
+ DPRINTF("boot1 imagepath: %S\n", text);
+ efi_free_devpath_name(text);
+ }
+#endif
}
for (i = 0; i < nhandles; i++)
Index: sys/boot/efi/boot1/boot_module.h
===================================================================
--- sys/boot/efi/boot1/boot_module.h
+++ sys/boot/efi/boot1/boot_module.h
@@ -110,6 +110,4 @@
extern EFI_SYSTEM_TABLE *systab;
extern EFI_BOOT_SERVICES *bs;
-extern int devpath_strlcat(char *buf, size_t size, EFI_DEVICE_PATH *devpath);
-extern char *devpath_str(EFI_DEVICE_PATH *devpath);
#endif
Index: sys/boot/efi/boot1/ufs_module.c
===================================================================
--- sys/boot/efi/boot1/ufs_module.c
+++ sys/boot/efi/boot1/ufs_module.c
@@ -101,8 +101,15 @@
ssize_t read;
void *buf;
- DPRINTF("Loading '%s' from %s\n", filepath, devpath_str(dev->devpath));
+#ifdef EFI_DEBUG
+ {
+ CHAR16 *text;
+ text = efi_devpath_name(dev->devpath);
+ DPRINTF("Loading '%s' from %S\n", filepath, text);
+ efi_free_devpath_name(text);
+ }
+#endif
if (init_dev(dev) < 0) {
DPRINTF("Failed to init device\n");
return (EFI_UNSUPPORTED);
Index: sys/boot/efi/boot1/zfs_module.c
===================================================================
--- sys/boot/efi/boot1/zfs_module.c
+++ sys/boot/efi/boot1/zfs_module.c
@@ -150,8 +150,16 @@
spa = devinfo->devdata;
- DPRINTF("load: '%s' spa: '%s', devpath: %s\n", filepath, spa->spa_name,
- devpath_str(devinfo->devpath));
+#ifdef EFI_DEBUG
+ {
+ CHAR16 *text;
+
+ text = efi_devpath_name(devinfo->devpath);
+ DPRINTF("load: '%s' spa: '%s', devpath: %S\n", filepath,
+ spa->spa_name, text);
+ efi_free_devpath_name(text);
+ }
+#endif
if ((err = zfs_spa_init(spa)) != 0) {
DPRINTF("Failed to load pool '%s' (%d)\n", spa->spa_name, err);
Index: sys/boot/efi/libefi/libefi.c
===================================================================
--- sys/boot/efi/libefi/libefi.c
+++ sys/boot/efi/libefi/libefi.c
@@ -37,27 +37,6 @@
EFI_BOOT_SERVICES *BS;
EFI_RUNTIME_SERVICES *RS;
-static EFI_PHYSICAL_ADDRESS heap;
-static UINTN heapsize;
-
-static CHAR16 *
-arg_skipsep(CHAR16 *argp)
-{
-
- while (*argp == ' ' || *argp == '\t' || *argp == '\n')
- argp++;
- return (argp);
-}
-
-static CHAR16 *
-arg_skipword(CHAR16 *argp)
-{
-
- while (*argp && *argp != ' ' && *argp != '\t' && *argp != '\n')
- argp++;
- return (argp);
-}
-
void *
efi_get_table(EFI_GUID *tbl)
{
@@ -71,128 +50,3 @@
}
return (NULL);
}
-
-void exit(EFI_STATUS exit_code)
-{
-
- BS->FreePages(heap, EFI_SIZE_TO_PAGES(heapsize));
- BS->Exit(IH, exit_code, 0, NULL);
-}
-
-void
-efi_main(EFI_HANDLE image_handle, EFI_SYSTEM_TABLE *system_table)
-{
- static EFI_GUID image_protocol = LOADED_IMAGE_PROTOCOL;
- static EFI_GUID console_control_protocol =
- EFI_CONSOLE_CONTROL_PROTOCOL_GUID;
- EFI_CONSOLE_CONTROL_PROTOCOL *console_control = NULL;
- EFI_LOADED_IMAGE *img;
- CHAR16 *argp, *args, **argv;
- EFI_STATUS status;
- int argc, addprog;
-
- IH = image_handle;
- ST = system_table;
- BS = ST->BootServices;
- RS = ST->RuntimeServices;
-
- status = BS->LocateProtocol(&console_control_protocol, NULL,
- (VOID **)&console_control);
- if (status == EFI_SUCCESS)
- (void)console_control->SetMode(console_control,
- EfiConsoleControlScreenText);
-
- heapsize = 64 * 1024 * 1024;
- status = BS->AllocatePages(AllocateAnyPages, EfiLoaderData,
- EFI_SIZE_TO_PAGES(heapsize), &heap);
- if (status != EFI_SUCCESS)
- BS->Exit(IH, status, 0, NULL);
-
- setheap((void *)(uintptr_t)heap, (void *)(uintptr_t)(heap + heapsize));
-
- /* Use exit() from here on... */
-
- status = BS->HandleProtocol(IH, &image_protocol, (VOID**)&img);
- if (status != EFI_SUCCESS)
- exit(status);
-
- /*
- * Pre-process the (optional) load options. If the option string
- * is given as an ASCII string, we use a poor man's ASCII to
- * Unicode-16 translation. The size of the option string as given
- * to us includes the terminating null character. We assume the
- * string is an ASCII string if strlen() plus the terminating
- * '\0' is less than LoadOptionsSize. Even if all Unicode-16
- * characters have the upper 8 bits non-zero, the terminating
- * null character will cause a one-off.
- * If the string is already in Unicode-16, we make a copy so that
- * we know we can always modify the string.
- */
- if (img->LoadOptionsSize > 0 && img->LoadOptions != NULL) {
- if (img->LoadOptionsSize == strlen(img->LoadOptions) + 1) {
- args = malloc(img->LoadOptionsSize << 1);
- for (argc = 0; argc < img->LoadOptionsSize; argc++)
- args[argc] = ((char*)img->LoadOptions)[argc];
- } else {
- args = malloc(img->LoadOptionsSize);
- memcpy(args, img->LoadOptions, img->LoadOptionsSize);
- }
- } else
- args = NULL;
-
- /*
- * Use a quick and dirty algorithm to build the argv vector. We
- * first count the number of words. Then, after allocating the
- * vector, we split the string up. We don't deal with quotes or
- * other more advanced shell features.
- * The EFI shell will pass the name of the image as the first
- * word in the argument list. This does not happen if we're
- * loaded by the boot manager. This is not so easy to figure
- * out though. The ParentHandle is not always NULL, because
- * there can be a function (=image) that will perform the task
- * for the boot manager.
- */
- /* Part 1: Figure out if we need to add our program name. */
- addprog = (args == NULL || img->ParentHandle == NULL ||
- img->FilePath == NULL) ? 1 : 0;
- if (!addprog) {
- addprog =
- (DevicePathType(img->FilePath) != MEDIA_DEVICE_PATH ||
- DevicePathSubType(img->FilePath) != MEDIA_FILEPATH_DP ||
- DevicePathNodeLength(img->FilePath) <=
- sizeof(FILEPATH_DEVICE_PATH)) ? 1 : 0;
- if (!addprog) {
- /* XXX todo. */
- }
- }
- /* Part 2: count words. */
- argc = (addprog) ? 1 : 0;
- argp = args;
- while (argp != NULL && *argp != 0) {
- argp = arg_skipsep(argp);
- if (*argp == 0)
- break;
- argc++;
- argp = arg_skipword(argp);
- }
- /* Part 3: build vector. */
- argv = malloc((argc + 1) * sizeof(CHAR16*));
- argc = 0;
- if (addprog)
- argv[argc++] = (CHAR16 *)L"loader.efi";
- argp = args;
- while (argp != NULL && *argp != 0) {
- argp = arg_skipsep(argp);
- if (*argp == 0)
- break;
- argv[argc++] = argp;
- argp = arg_skipword(argp);
- /* Terminate the words. */
- if (*argp != 0)
- *argp++ = 0;
- }
- argv[argc] = NULL;
-
- status = main(argc, argv);
- exit(status);
-}
Index: sys/boot/efi/loader/main.c
===================================================================
--- sys/boot/efi/loader/main.c
+++ sys/boot/efi/loader/main.c
@@ -40,6 +40,7 @@
#include <efi.h>
#include <efilib.h>
+#include <eficonsctl.h>
#include <uuid.h>
@@ -935,3 +936,153 @@
return (size);
}
#endif
+
+
+static EFI_PHYSICAL_ADDRESS heap;
+static UINTN heapsize;
+
+static CHAR16 *
+arg_skipsep(CHAR16 *argp)
+{
+
+ while (*argp == ' ' || *argp == '\t' || *argp == '\n')
+ argp++;
+ return (argp);
+}
+
+static CHAR16 *
+arg_skipword(CHAR16 *argp)
+{
+
+ while (*argp && *argp != ' ' && *argp != '\t' && *argp != '\n')
+ argp++;
+ return (argp);
+}
+
+void exit(EFI_STATUS exit_code)
+{
+
+ BS->FreePages(heap, EFI_SIZE_TO_PAGES(heapsize));
+ BS->Exit(IH, exit_code, 0, NULL);
+}
+
+void efi_main(EFI_HANDLE image_handle, EFI_SYSTEM_TABLE *system_table);
+
+void
+efi_main(EFI_HANDLE image_handle, EFI_SYSTEM_TABLE *system_table)
+{
+ static EFI_GUID image_protocol = LOADED_IMAGE_PROTOCOL;
+ static EFI_GUID console_control_protocol =
+ EFI_CONSOLE_CONTROL_PROTOCOL_GUID;
+ EFI_CONSOLE_CONTROL_PROTOCOL *console_control = NULL;
+ EFI_LOADED_IMAGE *img;
+ CHAR16 *argp, *args, **argv;
+ EFI_STATUS status;
+ UINT32 argc;
+ int addprog;
+
+ IH = image_handle;
+ ST = system_table;
+ BS = ST->BootServices;
+ RS = ST->RuntimeServices;
+
+ status = BS->LocateProtocol(&console_control_protocol, NULL,
+ (VOID **)&console_control);
+ if (status == EFI_SUCCESS)
+ (void)console_control->SetMode(console_control,
+ EfiConsoleControlScreenText);
+
+ heapsize = 64 * 1024 * 1024;
+ status = BS->AllocatePages(AllocateAnyPages, EfiLoaderData,
+ EFI_SIZE_TO_PAGES(heapsize), &heap);
+ if (status != EFI_SUCCESS)
+ BS->Exit(IH, status, 0, NULL);
+
+ setheap((void *)(uintptr_t)heap, (void *)(uintptr_t)(heap + heapsize));
+
+ /* Use exit() from here on... */
+
+ status = BS->HandleProtocol(IH, &image_protocol, (VOID**)&img);
+ if (status != EFI_SUCCESS)
+ exit(status);
+
+ /*
+ * Pre-process the (optional) load options. If the option string
+ * is given as an ASCII string, we use a poor man's ASCII to
+ * Unicode-16 translation. The size of the option string as given
+ * to us includes the terminating null character. We assume the
+ * string is an ASCII string if strlen() plus the terminating
+ * '\0' is less than LoadOptionsSize. Even if all Unicode-16
+ * characters have the upper 8 bits non-zero, the terminating
+ * null character will cause a one-off.
+ * If the string is already in Unicode-16, we make a copy so that
+ * we know we can always modify the string.
+ */
+ if (img->LoadOptionsSize > 0 && img->LoadOptions != NULL) {
+ if (img->LoadOptionsSize == strlen(img->LoadOptions) + 1) {
+ args = malloc(img->LoadOptionsSize << 1);
+ for (argc = 0; argc < img->LoadOptionsSize; argc++)
+ args[argc] = ((char*)img->LoadOptions)[argc];
+ } else {
+ args = malloc(img->LoadOptionsSize);
+ memcpy(args, img->LoadOptions, img->LoadOptionsSize);
+ }
+ } else
+ args = NULL;
+
+ /*
+ * Use a quick and dirty algorithm to build the argv vector. We
+ * first count the number of words. Then, after allocating the
+ * vector, we split the string up. We don't deal with quotes or
+ * other more advanced shell features.
+ * The EFI shell will pass the name of the image as the first
+ * word in the argument list. This does not happen if we're
+ * loaded by the boot manager. This is not so easy to figure
+ * out though. The ParentHandle is not always NULL, because
+ * there can be a function (=image) that will perform the task
+ * for the boot manager.
+ */
+ /* Part 1: Figure out if we need to add our program name. */
+ addprog = (args == NULL || img->ParentHandle == NULL ||
+ img->FilePath == NULL) ? 1 : 0;
+ if (!addprog) {
+ addprog =
+ (DevicePathType(img->FilePath) != MEDIA_DEVICE_PATH ||
+ DevicePathSubType(img->FilePath) != MEDIA_FILEPATH_DP ||
+ (size_t)DevicePathNodeLength(img->FilePath) <=
+ sizeof(FILEPATH_DEVICE_PATH)) ? 1 : 0;
+ if (!addprog) {
+ /* XXX todo. */
+ }
+ }
+ /* Part 2: count words. */
+ argc = (addprog) ? 1 : 0;
+ argp = args;
+ while (argp != NULL && *argp != 0) {
+ argp = arg_skipsep(argp);
+ if (*argp == 0)
+ break;
+ argc++;
+ argp = arg_skipword(argp);
+ }
+ /* Part 3: build vector. */
+ argv = malloc((argc + 1) * sizeof(CHAR16*));
+ argc = 0;
+ if (addprog)
+ argv[argc++] = (CHAR16 *)L"loader.efi";
+ argp = args;
+ while (argp != NULL && *argp != 0) {
+ argp = arg_skipsep(argp);
+ if (*argp == 0)
+ break;
+ argv[argc++] = argp;
+ argp = arg_skipword(argp);
+ /* Terminate the words. */
+ if (*argp != 0)
+ *argp++ = 0;
+ }
+ argv[argc] = NULL;
+
+ status = main(argc, argv);
+ exit(status);
+}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Tue, May 19, 6:53 AM (8 h, 17 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
33270489
Default Alt Text
D11820.id31464.diff (16 KB)
Attached To
Mode
D11820: Minor code refactor
Attached
Detach File
Event Timeline
Log In to Comment