Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 8 Dec 2002 20:23:49 -0800 (PST)
From:      Marcel Moolenaar <marcel@FreeBSD.org>
To:        Perforce Change Reviews <perforce@freebsd.org>
Subject:   PERFORCE change 22096 for review
Message-ID:  <200212090423.gB94Nnnm008083@repoman.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=22096

Change 22096 by marcel@marcel_nfs on 2002/12/08 20:22:56

	Tune the argument handling: apparently, the EFI shell passes
	the command as the first word in the option string. This is
	like Unix, but unlike the EFI boot manager. Thus, we need a
	way to determine if we're run from the EFI shell so that we
	can avoid adding the program name. This, however, is not a
	trivial thing to get right. The current change will make most
	of the cases work. One particular case that we miss is a
	boot option that loads an EFI image from disk and has options
	(arguments). This looks pretty much like how the shell would
	call us. At this time the first argument will not be our
	program name.
	
	There's a bug in the HP EFI implementation: when a program is
	run from the shell prompt (ie Shell>), the option list has
	some garbage at the end. For example:
	
		Shell> fs0:\boot\loader
	
	The Itaniium shell does not allow this (read: has a bug that
	causes it to not find the program).

Affected files ...

.. //depot/projects/ia64/sys/boot/efi/libefi/libefi.c#4 edit

Differences ...

==== //depot/projects/ia64/sys/boot/efi/libefi/libefi.c#4 (text+ko) ====

@@ -87,7 +87,7 @@
 	EFI_LOADED_IMAGE *img;
 	CHAR16 *argp, *args, **argv;
 	EFI_STATUS status;
-	int argc;
+	int argc, addprog;
 
 	IH = image_handle;
 	ST = system_table;
@@ -137,9 +137,28 @@
 	 * 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
+	 * 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: count words. */
-	argc = 1;	/* The EFI program name. */
+	/* 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);
@@ -148,10 +167,11 @@
 		argc++;
 		argp = arg_skipword(argp);
 	}
-	/* Part 2: build vector. */
+	/* Part 3: build vector. */
 	argv = malloc((argc + 1) * sizeof(CHAR16*));
-	argv[0] = L"loader.efi";		/* XXX kludge. */
-	argc = 1;
+	argc = 0;
+	if (addprog)
+		argv[argc++] = L"loader.efi";
 	argp = args;
 	while (argp != NULL && *argp != 0) {
 		argp = arg_skipsep(argp);

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe p4-projects" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200212090423.gB94Nnnm008083>