[Midnightbsd-cvs] src [10207] trunk/sys/boot/efi/libefi: update libefi

laffer1 at midnightbsd.org laffer1 at midnightbsd.org
Sat Jun 2 08:40:32 EDT 2018


Revision: 10207
          http://svnweb.midnightbsd.org/src/?rev=10207
Author:   laffer1
Date:     2018-06-02 08:40:31 -0400 (Sat, 02 Jun 2018)
Log Message:
-----------
update libefi

Modified Paths:
--------------
    trunk/sys/boot/efi/libefi/Makefile
    trunk/sys/boot/efi/libefi/delay.c
    trunk/sys/boot/efi/libefi/efi_console.c
    trunk/sys/boot/efi/libefi/efifs.c
    trunk/sys/boot/efi/libefi/efinet.c
    trunk/sys/boot/efi/libefi/efipart.c
    trunk/sys/boot/efi/libefi/errno.c
    trunk/sys/boot/efi/libefi/handles.c
    trunk/sys/boot/efi/libefi/libefi.c

Modified: trunk/sys/boot/efi/libefi/Makefile
===================================================================
--- trunk/sys/boot/efi/libefi/Makefile	2018-06-02 12:39:13 UTC (rev 10206)
+++ trunk/sys/boot/efi/libefi/Makefile	2018-06-02 12:40:31 UTC (rev 10207)
@@ -1,16 +1,32 @@
 # $MidnightBSD$
+# $FreeBSD: stable/10/sys/boot/efi/libefi/Makefile 295538 2016-02-11 17:56:09Z smh $
 
+.include <bsd.own.mk>
+
 LIB=	efi
 INTERNALLIB=
+WARNS?=	2
 
 SRCS=	delay.c efi_console.c efinet.c efipart.c errno.c handles.c \
 	libefi.c time.c
 
+.if ${MACHINE_CPUARCH} == "ia64"
+IGNORE_PRAGMA=	1
+.endif
+
+.if ${MACHINE_ARCH} == "amd64"
+CFLAGS+= -fPIC -mno-red-zone
+.endif
 CFLAGS+= -I${.CURDIR}/../include
-CFLAGS+= -I${.CURDIR}/../include/${MACHINE_CPUARCH:S/amd64/i386/}
+CFLAGS+= -I${.CURDIR}/../include/${MACHINE}
 CFLAGS+= -I${.CURDIR}/../../../../lib/libstand
 
 # Pick up the bootstrap header for some interface items
 CFLAGS+= -I${.CURDIR}/../../common
 
+ 
+# Suppress warning from clang for FreeBSD %b and %D formats
+CFLAGS+= -fformat-extensions
+CFLAGS+= -DTERM_EMU
+
 .include <bsd.lib.mk>

Modified: trunk/sys/boot/efi/libefi/delay.c
===================================================================
--- trunk/sys/boot/efi/libefi/delay.c	2018-06-02 12:39:13 UTC (rev 10206)
+++ trunk/sys/boot/efi/libefi/delay.c	2018-06-02 12:40:31 UTC (rev 10207)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 2001 Doug Rabson
  * All rights reserved.
@@ -25,7 +26,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/boot/efi/libefi/delay.c 113038 2003-04-03 21:36:33Z obrien $");
 
 #include <efi.h>
 #include <efilib.h>

Modified: trunk/sys/boot/efi/libefi/efi_console.c
===================================================================
--- trunk/sys/boot/efi/libefi/efi_console.c	2018-06-02 12:39:13 UTC (rev 10206)
+++ trunk/sys/boot/efi/libefi/efi_console.c	2018-06-02 12:40:31 UTC (rev 10207)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 2000 Doug Rabson
  * All rights reserved.
@@ -25,7 +26,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/boot/efi/libefi/efi_console.c 294981 2016-01-28 12:11:42Z smh $");
 
 #include <efi.h>
 #include <efilib.h>
@@ -35,6 +36,71 @@
 static SIMPLE_TEXT_OUTPUT_INTERFACE	*conout;
 static SIMPLE_INPUT_INTERFACE		*conin;
 
+#ifdef TERM_EMU
+#define	DEFAULT_FGCOLOR	EFI_LIGHTGRAY
+#define	DEFAULT_BGCOLOR	EFI_BLACK
+
+#define	MAXARGS	8
+static int args[MAXARGS], argc;
+static int fg_c, bg_c, curx, cury;
+static int esc;
+
+void get_pos(int *x, int *y);
+void curs_move(int *_x, int *_y, int x, int y);
+static void CL(int);
+void HO(void);
+void end_term(void);
+#endif
+
+static void efi_cons_probe(struct console *);
+static int efi_cons_init(int);
+void efi_cons_putchar(int);
+int efi_cons_getchar(void);
+void efi_cons_efiputchar(int);
+int efi_cons_poll(void);
+
+struct console efi_console = {
+	"efi",
+	"EFI console",
+	0,
+	efi_cons_probe,
+	efi_cons_init,
+	efi_cons_putchar,
+	efi_cons_getchar,
+	efi_cons_poll
+};
+
+#ifdef TERM_EMU
+
+/* Get cursor position. */
+void
+get_pos(int *x, int *y)
+{
+	*x = conout->Mode->CursorColumn;
+	*y = conout->Mode->CursorRow;
+}
+
+/* Move cursor to x rows and y cols (0-based). */
+void
+curs_move(int *_x, int *_y, int x, int y)
+{
+	conout->SetCursorPosition(conout, x, y);
+	if (_x != NULL)
+		*_x = conout->Mode->CursorColumn;
+	if (_y != NULL)
+		*_y = conout->Mode->CursorRow;
+}
+
+/* Clear internal state of the terminal emulation code. */
+void
+end_term(void)
+{
+	esc = 0;
+	argc = -1;
+}
+
+#endif
+
 static void
 efi_cons_probe(struct console *cp)
 {
@@ -46,24 +112,316 @@
 static int
 efi_cons_init(int arg)
 {
-	conout->SetAttribute(conout, EFI_TEXT_ATTR(EFI_LIGHTGRAY, EFI_BLACK));
+	conout->SetAttribute(conout, EFI_TEXT_ATTR(DEFAULT_FGCOLOR,
+	    DEFAULT_BGCOLOR));
+#ifdef TERM_EMU
+	end_term();
+	get_pos(&curx, &cury);
+	curs_move(&curx, &cury, curx, cury);
+	fg_c = DEFAULT_FGCOLOR;
+	bg_c = DEFAULT_BGCOLOR;
+#endif
+	conout->EnableCursor(conout, TRUE);
 	return 0;
 }
 
+static void
+efi_cons_rawputchar(int c)
+{
+	int i;
+	UINTN x, y;
+	conout->QueryMode(conout, conout->Mode->Mode, &x, &y);
+
+	if (c == '\t')
+		/* XXX lame tab expansion */
+		for (i = 0; i < 8; i++)
+			efi_cons_rawputchar(' ');
+	else {
+#ifndef	TERM_EMU
+		if (c == '\n')
+			efi_cons_efiputchar('\r');
+		else
+			efi_cons_efiputchar(c);
+#else
+		switch (c) {
+		case '\r':
+			curx = 0;
+			curs_move(&curx, &cury, curx, cury);
+			return;
+		case '\n':
+			cury++;
+			if (cury >= y) {
+				efi_cons_efiputchar('\n');
+				cury--;
+			} else
+				curs_move(&curx, &cury, curx, cury);
+			return;
+		case '\b':
+			if (curx > 0) {
+				curx--;
+				curs_move(&curx, &cury, curx, cury);
+			}
+			return;
+		default:
+			efi_cons_efiputchar(c);
+			curx++;
+			if (curx > x-1) {
+				curx = 0;
+				cury++;
+			}
+			if (cury > y-1) {
+				curx = 0;
+				cury--;
+			}
+		}
+		curs_move(&curx, &cury, curx, cury);
+#endif
+	}
+}
+
+/* Gracefully exit ESC-sequence processing in case of misunderstanding. */
+static void
+bail_out(int c)
+{
+	char buf[16], *ch;
+	int i;
+
+	if (esc) {
+		efi_cons_rawputchar('\033');
+		if (esc != '\033')
+			efi_cons_rawputchar(esc);
+		for (i = 0; i <= argc; ++i) {
+			sprintf(buf, "%d", args[i]);
+			ch = buf;
+			while (*ch)
+				efi_cons_rawputchar(*ch++);
+		}
+	}
+	efi_cons_rawputchar(c);
+	end_term();
+}
+
+/* Clear display from current position to end of screen. */
+static void
+CD(void) {
+	int i;
+	UINTN x, y;
+
+	get_pos(&curx, &cury);
+	if (curx == 0 && cury == 0) {
+		conout->ClearScreen(conout);
+		end_term();
+		return;
+	}
+
+	conout->QueryMode(conout, conout->Mode->Mode, &x, &y);
+	CL(0);  /* clear current line from cursor to end */
+	for (i = cury + 1; i < y-1; i++) {
+		curs_move(NULL, NULL, 0, i);
+		CL(0);
+	}
+	curs_move(NULL, NULL, curx, cury);
+	end_term();
+}
+
+/*
+ * Absolute cursor move to args[0] rows and args[1] columns
+ * (the coordinates are 1-based).
+ */
+static void
+CM(void)
+{
+	if (args[0] > 0)
+		args[0]--;
+	if (args[1] > 0)
+		args[1]--;
+	curs_move(&curx, &cury, args[1], args[0]);
+	end_term();
+}
+
+/* Home cursor (left top corner), also called from mode command. */
 void
-efi_cons_putchar(int c)
+HO(void)
 {
-	CHAR16 buf[2];
+	argc = 1;
+	args[0] = args[1] = 1;
+	CM();
+}
 
-	if (c == '\n')
-		efi_cons_putchar('\r');
+/* Clear line from current position to end of line */
+static void
+CL(int direction)
+{
+	int i, len;
+	UINTN x, y;
+	CHAR16 *line;
 
-	buf[0] = c;
-	buf[1] = 0;
+	conout->QueryMode(conout, conout->Mode->Mode, &x, &y);
+	switch (direction) {
+	case 0:         /* from cursor to end */
+		len = x - curx + 1;
+		break;
+	case 1:         /* from beginning to cursor */
+		len = curx;
+		break;
+	case 2:         /* entire line */
+		len = x;
+		break;
+	}
 
-	conout->OutputString(conout, buf);
+	if (cury == y - 1)
+		len--;
+
+	line = malloc(len * sizeof (CHAR16));
+	if (line == NULL) {
+		printf("out of memory\n");
+		return;
+	}
+	for (i = 0; i < len; i++)
+		line[i] = ' ';
+	line[len-1] = 0;
+
+	if (direction != 0)
+		curs_move(NULL, NULL, 0, cury);
+
+	conout->OutputString(conout, line);
+	/* restore cursor position */
+	curs_move(NULL, NULL, curx, cury);
+	free(line);
+	end_term();
 }
 
+static void
+get_arg(int c)
+{
+	if (argc < 0)
+		argc = 0;
+	args[argc] *= 10;
+	args[argc] += c - '0';
+}
+
+/* Emulate basic capabilities of cons25 terminal */
+static void
+efi_term_emu(int c)
+{
+	static int ansi_col[] = {
+		0, 4, 2, 6, 1, 5, 3, 7
+	};
+	int t, i;
+
+	switch (esc) {
+	case 0:
+		switch (c) {
+		case '\033':
+			esc = c;
+			break;
+		default:
+			efi_cons_rawputchar(c);
+			break;
+		}
+		break;
+	case '\033':
+		switch (c) {
+		case '[':
+			esc = c;
+			args[0] = 0;
+			argc = -1;
+			break;
+		default:
+			bail_out(c);
+			break;
+		}
+		break;
+	case '[':
+		switch (c) {
+		case ';':
+			if (argc < 0)
+				argc = 0;
+			else if (argc + 1 >= MAXARGS)
+				bail_out(c);
+			else
+				args[++argc] = 0;
+			break;
+		case 'H':               /* ho = \E[H */
+			if (argc < 0)
+				HO();
+			else if (argc == 1)
+				CM();
+			else
+				bail_out(c);
+			break;
+		case 'J':               /* cd = \E[J */
+			if (argc < 0)
+				CD();
+			else
+				bail_out(c);
+			break;
+		case 'm':
+			if (argc < 0) {
+				fg_c = DEFAULT_FGCOLOR;
+				bg_c = DEFAULT_BGCOLOR;
+			}
+			for (i = 0; i <= argc; ++i) {
+				switch (args[i]) {
+				case 0:         /* back to normal */
+					fg_c = DEFAULT_FGCOLOR;
+					bg_c = DEFAULT_BGCOLOR;
+					break;
+				case 1:         /* bold */
+					fg_c |= 0x8;
+					break;
+				case 4:         /* underline */
+				case 5:         /* blink */
+					bg_c |= 0x8;
+					break;
+				case 7:         /* reverse */
+					t = fg_c;
+					fg_c = bg_c;
+					bg_c = t;
+					break;
+				case 30: case 31: case 32: case 33:
+				case 34: case 35: case 36: case 37:
+					fg_c = ansi_col[args[i] - 30];
+					break;
+				case 39:        /* normal */
+					fg_c = DEFAULT_FGCOLOR;
+					break;
+				case 40: case 41: case 42: case 43:
+				case 44: case 45: case 46: case 47:
+					bg_c = ansi_col[args[i] - 40];
+					break;
+				case 49:        /* normal */
+					bg_c = DEFAULT_BGCOLOR;
+					break;
+				}
+			}
+			conout->SetAttribute(conout, EFI_TEXT_ATTR(fg_c, bg_c));
+			end_term();
+			break;
+		default:
+			if (isdigit(c))
+				get_arg(c);
+			else
+				bail_out(c);
+			break;
+		}
+		break;
+	default:
+		bail_out(c);
+		break;
+	}
+}
+
+void
+efi_cons_putchar(int c)
+{
+#ifdef TERM_EMU
+	efi_term_emu(c);
+#else
+	efi_cons_rawputchar(c);
+#endif
+}
+
 int
 efi_cons_getchar()
 {
@@ -77,6 +435,12 @@
 		BS->WaitForEvent(1, &conin->WaitForKey, &junk);
 		status = conin->ReadKeyStroke(conin, &key);
 	}
+	switch (key.ScanCode) {
+	case 0x17: /* ESC */
+		return (0x1b);  /* esc */
+	}
+
+	/* this can return  */
 	return (key.UnicodeChar);
 }
 
@@ -87,13 +451,36 @@
 	return (BS->CheckEvent(conin->WaitForKey) == EFI_SUCCESS);
 }
 
-struct console efi_console = {
-	"efi",
-	"EFI console",
-	0,
-	efi_cons_probe,
-	efi_cons_init,
-	efi_cons_putchar,
-	efi_cons_getchar,
-	efi_cons_poll
-};
+/* Plain direct access to EFI OutputString(). */
+void
+efi_cons_efiputchar(int c)
+{
+	CHAR16 buf[2];
+
+	/*
+	 * translate box chars to unicode
+	 */
+	switch (c) {
+	/* single frame */
+	case 0xb3: buf[0] = BOXDRAW_VERTICAL; break;
+	case 0xbf: buf[0] = BOXDRAW_DOWN_LEFT; break;
+	case 0xc0: buf[0] = BOXDRAW_UP_RIGHT; break;
+	case 0xc4: buf[0] = BOXDRAW_HORIZONTAL; break;
+	case 0xda: buf[0] = BOXDRAW_DOWN_RIGHT; break;
+	case 0xd9: buf[0] = BOXDRAW_UP_LEFT; break;
+
+	/* double frame */
+	case 0xba: buf[0] = BOXDRAW_DOUBLE_VERTICAL; break;
+	case 0xbb: buf[0] = BOXDRAW_DOUBLE_DOWN_LEFT; break;
+	case 0xbc: buf[0] = BOXDRAW_DOUBLE_UP_LEFT; break;
+	case 0xc8: buf[0] = BOXDRAW_DOUBLE_UP_RIGHT; break;
+	case 0xc9: buf[0] = BOXDRAW_DOUBLE_DOWN_RIGHT; break;
+	case 0xcd: buf[0] = BOXDRAW_DOUBLE_HORIZONTAL; break;
+
+	default:
+		buf[0] = c;
+	}
+        buf[1] = 0;     /* terminate string */
+
+	conout->OutputString(conout, buf);
+}

Modified: trunk/sys/boot/efi/libefi/efifs.c
===================================================================
--- trunk/sys/boot/efi/libefi/efifs.c	2018-06-02 12:39:13 UTC (rev 10206)
+++ trunk/sys/boot/efi/libefi/efifs.c	2018-06-02 12:40:31 UTC (rev 10207)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 2001 Doug Rabson
  * Copyright (c) 2006 Marcel Moolenaar

Modified: trunk/sys/boot/efi/libefi/efinet.c
===================================================================
--- trunk/sys/boot/efi/libefi/efinet.c	2018-06-02 12:39:13 UTC (rev 10206)
+++ trunk/sys/boot/efi/libefi/efinet.c	2018-06-02 12:40:31 UTC (rev 10207)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 2001 Doug Rabson
  * Copyright (c) 2002, 2006 Marcel Moolenaar
@@ -26,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/boot/efi/libefi/efinet.c 271135 2014-09-04 21:01:10Z emaste $");
 
 #include <sys/param.h>
 #include <netinet/in.h>
@@ -274,7 +275,7 @@
 	if (EFI_ERROR(status))
 		return (efi_status_to_errno(status));
 	nifs = sz / sizeof(EFI_HANDLE);
-	err = efi_register_handles(&efinet_dev, handles, nifs);
+	err = efi_register_handles(&efinet_dev, handles, NULL, nifs);
 	free(handles);
 	if (err != 0)
 		return (err);

Modified: trunk/sys/boot/efi/libefi/efipart.c
===================================================================
--- trunk/sys/boot/efi/libefi/efipart.c	2018-06-02 12:39:13 UTC (rev 10206)
+++ trunk/sys/boot/efi/libefi/efipart.c	2018-06-02 12:40:31 UTC (rev 10207)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 2010 Marcel Moolenaar
  * All rights reserved.
@@ -25,7 +26,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/boot/efi/libefi/efipart.c 294981 2016-01-28 12:11:42Z smh $");
 
 #include <sys/param.h>
 #include <sys/time.h>
@@ -39,6 +40,7 @@
 #include <efiprot.h>
 
 static EFI_GUID blkio_guid = BLOCK_IO_PROTOCOL;
+static EFI_GUID devpath_guid = DEVICE_PATH_PROTOCOL;
 
 static int efipart_init(void);
 static int efipart_strategy(void *, int, daddr_t, size_t, char *, size_t *);
@@ -62,17 +64,19 @@
 efipart_init(void) 
 {
 	EFI_BLOCK_IO *blkio;
-	EFI_HANDLE *hin, *hout;
+	EFI_DEVICE_PATH *devpath, *devpathcpy, *tmpdevpath, *node;
+	EFI_HANDLE *hin, *hout, *aliases, handle;
 	EFI_STATUS status;
 	UINTN sz;
 	u_int n, nin, nout;
 	int err;
+	size_t devpathlen;
 
 	sz = 0;
 	hin = NULL;
 	status = BS->LocateHandle(ByProtocol, &blkio_guid, 0, &sz, 0);
 	if (status == EFI_BUFFER_TOO_SMALL) {
-		hin = (EFI_HANDLE *)malloc(sz * 2);
+		hin = (EFI_HANDLE *)malloc(sz * 3);
 		status = BS->LocateHandle(ByProtocol, &blkio_guid, 0, &sz,
 		    hin);
 		if (EFI_ERROR(status))
@@ -84,19 +88,62 @@
 	/* Filter handles to only include FreeBSD partitions. */
 	nin = sz / sizeof(EFI_HANDLE);
 	hout = hin + nin;
+	aliases = hout + nin;
 	nout = 0;
 
+	bzero(aliases, nin * sizeof(EFI_HANDLE));
+
 	for (n = 0; n < nin; n++) {
-		status = BS->HandleProtocol(hin[n], &blkio_guid, &blkio);
+		status = BS->HandleProtocol(hin[n], &devpath_guid,
+		    (void **)&devpath);
+		if (EFI_ERROR(status)) {
+			continue;
+		}
+
+		node = devpath;
+		devpathlen = DevicePathNodeLength(node);
+		while (!IsDevicePathEnd(NextDevicePathNode(node))) {
+			node = NextDevicePathNode(node);
+			devpathlen += DevicePathNodeLength(node);
+		}
+		devpathlen += DevicePathNodeLength(NextDevicePathNode(node));
+
+		status = BS->HandleProtocol(hin[n], &blkio_guid,
+		    (void**)&blkio);
 		if (EFI_ERROR(status))
 			continue;
 		if (!blkio->Media->LogicalPartition)
 			continue;
-		hout[nout] = hin[n];
+
+		/*
+		 * If we come across a logical partition of subtype CDROM
+		 * it doesn't refer to the CD filesystem itself, but rather
+		 * to any usable El Torito boot image on it. In this case
+		 * we try to find the parent device and add that instead as
+		 * that will be the CD filesystem.
+		 */
+		if (DevicePathType(node) == MEDIA_DEVICE_PATH &&
+		    DevicePathSubType(node) == MEDIA_CDROM_DP) {
+			devpathcpy = malloc(devpathlen);
+			memcpy(devpathcpy, devpath, devpathlen);
+			node = devpathcpy;
+			while (!IsDevicePathEnd(NextDevicePathNode(node)))
+				node = NextDevicePathNode(node);
+			SetDevicePathEndNode(node);
+			tmpdevpath = devpathcpy;
+			status = BS->LocateDevicePath(&blkio_guid, &tmpdevpath,
+			    &handle);
+			free(devpathcpy);
+			if (EFI_ERROR(status))
+				continue;
+			hout[nout] = handle;
+			aliases[nout] = hin[n];
+		} else
+			hout[nout] = hin[n];
 		nout++;
 	}
 
-	err = efi_register_handles(&efipart_dev, hout, nout);
+	err = efi_register_handles(&efipart_dev, hout, aliases, nout);
 	free(hin);
 	return (err);
 }
@@ -115,7 +162,7 @@
 		sprintf(line, "    %s%d:", efipart_dev.dv_name, unit);
 		pager_output(line);
 
-		status = BS->HandleProtocol(h, &blkio_guid, &blkio);
+		status = BS->HandleProtocol(h, &blkio_guid, (void **)&blkio);
 		if (!EFI_ERROR(status)) {
 			sprintf(line, "    %llu blocks",
 			    (unsigned long long)(blkio->Media->LastBlock + 1));
@@ -144,7 +191,7 @@
 	if (h == NULL)
 		return (EINVAL);
 
-	status = BS->HandleProtocol(h, &blkio_guid, &blkio);
+	status = BS->HandleProtocol(h, &blkio_guid, (void **)&blkio);
 	if (EFI_ERROR(status))
 		return (efi_status_to_errno(status));
 

Modified: trunk/sys/boot/efi/libefi/errno.c
===================================================================
--- trunk/sys/boot/efi/libefi/errno.c	2018-06-02 12:39:13 UTC (rev 10206)
+++ trunk/sys/boot/efi/libefi/errno.c	2018-06-02 12:40:31 UTC (rev 10207)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 2006 Marcel Moolenaar
  * All rights reserved.
@@ -25,7 +26,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/boot/efi/libefi/errno.c 164010 2006-11-05 22:03:04Z marcel $");
 
 #include <efi.h>
 #include <efilib.h>

Modified: trunk/sys/boot/efi/libefi/handles.c
===================================================================
--- trunk/sys/boot/efi/libefi/handles.c	2018-06-02 12:39:13 UTC (rev 10206)
+++ trunk/sys/boot/efi/libefi/handles.c	2018-06-02 12:40:31 UTC (rev 10207)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 2006 Marcel Moolenaar
  * All rights reserved.
@@ -25,7 +26,7 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/boot/efi/libefi/handles.c 294999 2016-01-28 17:24:40Z smh $");
 
 #include <efi.h>
 #include <efilib.h>
@@ -32,8 +33,10 @@
 
 struct entry {
 	EFI_HANDLE handle;
+	EFI_HANDLE alias;
 	struct devsw *dev;
 	int unit;
+	uint64_t extra;
 };
 
 struct entry *entry;
@@ -40,7 +43,8 @@
 int nentries;
 
 int
-efi_register_handles(struct devsw *sw, EFI_HANDLE *handles, int count)
+efi_register_handles(struct devsw *sw, EFI_HANDLE *handles,
+    EFI_HANDLE *aliases, int count)
 {
 	size_t sz;
 	int idx, unit;
@@ -51,6 +55,10 @@
 	entry = (entry == NULL) ? malloc(sz) : realloc(entry, sz);
 	for (unit = 0; idx < nentries; idx++, unit++) {
 		entry[idx].handle = handles[unit];
+		if (aliases != NULL)
+			entry[idx].alias = aliases[unit];
+		else
+			entry[idx].alias = NULL;
 		entry[idx].dev = sw;
 		entry[idx].unit = unit;
 	}
@@ -73,18 +81,39 @@
 }
 
 int
-efi_handle_lookup(EFI_HANDLE h, struct devsw **dev, int *unit)
+efi_handle_lookup(EFI_HANDLE h, struct devsw **dev, int *unit, uint64_t *extra)
 {
 	int idx;
 
 	for (idx = 0; idx < nentries; idx++) {
-		if (entry[idx].handle != h)
+		if (entry[idx].handle != h && entry[idx].alias != h)
 			continue;
 		if (dev != NULL)
 			*dev = entry[idx].dev;
 		if (unit != NULL)
 			*unit = entry[idx].unit;
+		if (extra != NULL)
+			*extra = entry[idx].extra;
 		return (0);
 	}
 	return (ENOENT);
 }
+
+int
+efi_handle_update_dev(EFI_HANDLE h, struct devsw *dev, int unit,
+    uint64_t guid)
+{
+	int idx;
+
+	for (idx = 0; idx < nentries; idx++) {
+		if (entry[idx].handle != h)
+			continue;
+		entry[idx].dev = dev;
+		entry[idx].unit = unit;
+		entry[idx].alias = NULL;
+		entry[idx].extra = guid;
+		return (0);
+	}
+
+	return (ENOENT);
+}

Modified: trunk/sys/boot/efi/libefi/libefi.c
===================================================================
--- trunk/sys/boot/efi/libefi/libefi.c	2018-06-02 12:39:13 UTC (rev 10206)
+++ trunk/sys/boot/efi/libefi/libefi.c	2018-06-02 12:40:31 UTC (rev 10207)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 2000 Doug Rabson
  * All rights reserved.
@@ -25,9 +26,10 @@
  */
 
 #include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/boot/efi/libefi/libefi.c 295551 2016-02-11 23:43:27Z imp $");
 
 #include <efi.h>
+#include <eficonsctl.h>
 #include <efilib.h>
 #include <stand.h>
 
@@ -43,7 +45,7 @@
 arg_skipsep(CHAR16 *argp)
 {
 
-	while (*argp == ' ' || *argp == '\t')
+	while (*argp == ' ' || *argp == '\t' || *argp == '\n')
 		argp++;
 	return (argp);
 }
@@ -52,7 +54,7 @@
 arg_skipword(CHAR16 *argp)
 {
 
-	while (*argp && *argp != ' ' && *argp != '\t')
+	while (*argp && *argp != ' ' && *argp != '\t' && *argp != '\n')
 		argp++;
 	return (argp);
 }
@@ -82,6 +84,9 @@
 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;
@@ -92,7 +97,13 @@
 	BS = ST->BootServices;
 	RS = ST->RuntimeServices;
 
-	heapsize = 2 * 1024 * 1024;
+	status = BS->LocateProtocol(&console_control_protocol, NULL,
+	    (VOID **)&console_control);
+	if (status == EFI_SUCCESS)
+		(void)console_control->SetMode(console_control,
+		    EfiConsoleControlScreenText);
+
+	heapsize = 3 * 1024 * 1024;
 	status = BS->AllocatePages(AllocateAnyPages, EfiLoaderData,
 	    EFI_SIZE_TO_PAGES(heapsize), &heap);
 	if (status != EFI_SUCCESS)
@@ -135,7 +146,7 @@
 	 * 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 pas the name of the image as the first
+	 * 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
@@ -169,7 +180,7 @@
 	argv = malloc((argc + 1) * sizeof(CHAR16*));
 	argc = 0;
 	if (addprog)
-		argv[argc++] = L"loader.efi";
+		argv[argc++] = (CHAR16 *)L"loader.efi";
 	argp = args;
 	while (argp != NULL && *argp != 0) {
 		argp = arg_skipsep(argp);



More information about the Midnightbsd-cvs mailing list