return EFI_SUCCESS;\r
}\r
\r
+/**\r
+ Function try to find location of the Startup.nsh file.\r
+ \r
+ The buffer is callee allocated and should be freed by the caller.\r
+\r
+ @param ImagePath The path to the image for shell. first place to look for the startup script\r
+ @param FilePath The path to the file for shell. second place to look for the startup script.\r
+\r
+ @retval NULL No Startup.nsh file was found.\r
+ @return !=NULL Pointer to NULL-terminated path.\r
+**/\r
+CHAR16 *\r
+LocateStartupScript (\r
+ IN EFI_DEVICE_PATH_PROTOCOL *ImageDevicePath,\r
+ IN EFI_DEVICE_PATH_PROTOCOL *FileDevicePath\r
+ )\r
+{\r
+ CHAR16 *StartupScriptPath;\r
+ CHAR16 *TempSpot;\r
+ CONST CHAR16 *MapName;\r
+ UINTN Size;\r
+\r
+ StartupScriptPath = NULL;\r
+ Size = 0;\r
+\r
+ //\r
+ // Try to find 'Startup.nsh' in the directory where the shell itself was launched.\r
+ //\r
+ MapName = ShellInfoObject.NewEfiShellProtocol->GetMapFromDevicePath (&ImageDevicePath);\r
+ if (MapName != NULL) { \r
+ StartupScriptPath = StrnCatGrow (&StartupScriptPath, &Size, MapName, 0);\r
+ TempSpot = StrStr (StartupScriptPath, L";");\r
+ if (TempSpot != NULL) {\r
+ *TempSpot = CHAR_NULL;\r
+ }\r
+\r
+ StartupScriptPath = StrnCatGrow (&StartupScriptPath, &Size, ((FILEPATH_DEVICE_PATH *)FileDevicePath)->PathName, 0);\r
+ PathRemoveLastItem (StartupScriptPath);\r
+ StartupScriptPath = StrnCatGrow (&StartupScriptPath, &Size, mStartupScript, 0);\r
+ }\r
+\r
+ //\r
+ // Try to find 'Startup.nsh' in the execution path defined by the envrionment variable PATH.\r
+ //\r
+ if ((StartupScriptPath == NULL) || EFI_ERROR (ShellIsFile (StartupScriptPath))) {\r
+ SHELL_FREE_NON_NULL (StartupScriptPath);\r
+ StartupScriptPath = ShellFindFilePath (mStartupScript);\r
+ }\r
+\r
+ return StartupScriptPath;\r
+}\r
+\r
/**\r
Handles all interaction with the default startup script.\r
\r
EFI_STATUS CalleeStatus;\r
UINTN Delay;\r
EFI_INPUT_KEY Key;\r
- SHELL_FILE_HANDLE FileHandle;\r
- EFI_DEVICE_PATH_PROTOCOL *NewPath;\r
- EFI_DEVICE_PATH_PROTOCOL *NamePath;\r
CHAR16 *FileStringPath;\r
- CHAR16 *TempSpot;\r
UINTN NewSize;\r
- CONST CHAR16 *MapName;\r
\r
Key.UnicodeChar = CHAR_NULL;\r
Key.ScanCode = 0;\r
- FileHandle = NULL;\r
\r
if (!ShellInfoObject.ShellInitSettings.BitUnion.Bits.Startup && ShellInfoObject.ShellInitSettings.FileName != NULL) {\r
//\r
return (EFI_SUCCESS);\r
}\r
\r
- //\r
- // Try the first location (must be file system)\r
- //\r
- MapName = ShellInfoObject.NewEfiShellProtocol->GetMapFromDevicePath(&ImagePath);\r
- if (MapName != NULL) {\r
- FileStringPath = NULL;\r
- NewSize = 0;\r
- FileStringPath = StrnCatGrow(&FileStringPath, &NewSize, MapName, 0);\r
- if (FileStringPath == NULL) {\r
- Status = EFI_OUT_OF_RESOURCES;\r
- } else {\r
- TempSpot = StrStr(FileStringPath, L";");\r
- if (TempSpot != NULL) {\r
- *TempSpot = CHAR_NULL;\r
- }\r
- FileStringPath = StrnCatGrow(&FileStringPath, &NewSize, ((FILEPATH_DEVICE_PATH*)FilePath)->PathName, 0);\r
- PathRemoveLastItem(FileStringPath);\r
- FileStringPath = StrnCatGrow(&FileStringPath, &NewSize, mStartupScript, 0);\r
- Status = ShellInfoObject.NewEfiShellProtocol->OpenFileByName(FileStringPath, &FileHandle, EFI_FILE_MODE_READ);\r
- FreePool(FileStringPath);\r
- }\r
- }\r
- if (EFI_ERROR(Status)) {\r
- NamePath = FileDevicePath (NULL, mStartupScript);\r
- NewPath = AppendDevicePathNode (ImagePath, NamePath);\r
- FreePool(NamePath);\r
-\r
- //\r
- // Try the location\r
- //\r
- Status = InternalOpenFileDevicePath(NewPath, &FileHandle, EFI_FILE_MODE_READ, 0);\r
- FreePool(NewPath);\r
+ FileStringPath = LocateStartupScript (ImagePath, FilePath);\r
+ if (FileStringPath != NULL) {\r
+ Status = RunScriptFile (FileStringPath, NULL, L"", ShellInfoObject.NewShellParametersProtocol);\r
+ FreePool (FileStringPath);\r
}\r
- //\r
- // If we got a file, run it\r
- //\r
- if (!EFI_ERROR(Status) && FileHandle != NULL) {\r
- Status = RunScriptFile (mStartupScript, FileHandle, L"", ShellInfoObject.NewShellParametersProtocol);\r
- ShellInfoObject.NewEfiShellProtocol->CloseFile(FileHandle);\r
- } else {\r
- FileStringPath = ShellFindFilePath(mStartupScript);\r
- if (FileStringPath == NULL) {\r
- //\r
- // we return success since we don't need to have a startup script\r
- //\r
- Status = EFI_SUCCESS;\r
- ASSERT(FileHandle == NULL);\r
- } else {\r
- Status = RunScriptFile(FileStringPath, NULL, L"", ShellInfoObject.NewShellParametersProtocol);\r
- FreePool(FileStringPath);\r
- }\r
- }\r
-\r
\r
return (Status);\r
}\r