+/**\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 ImageDevicePath The path to the image for shell. first place to look for the startup script\r
+ @param FileDevicePath 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
+ if (StartupScriptPath == NULL) {\r
+ //\r
+ // Do not locate the startup script in sys path when out of resource.\r
+ //\r
+ return NULL;\r
+ }\r
+ TempSpot = StrStr (StartupScriptPath, L";");\r
+ if (TempSpot != NULL) {\r
+ *TempSpot = CHAR_NULL;\r
+ }\r
+\r
+ InternalEfiShellSetEnv(L"homefilesystem", StartupScriptPath, TRUE);\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