From nobody Sat Nov 2 12:18:08 2024 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Authentication-Results: mx.zoho.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org; Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1490169635130180.32315307765498; Wed, 22 Mar 2017 01:00:35 -0700 (PDT) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id EB831803D2; Wed, 22 Mar 2017 01:00:32 -0700 (PDT) Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 27623803D1 for ; Wed, 22 Mar 2017 01:00:31 -0700 (PDT) Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga104.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 22 Mar 2017 01:00:30 -0700 Received: from ray-dev.ccr.corp.intel.com ([10.239.9.25]) by orsmga003.jf.intel.com with ESMTP; 22 Mar 2017 01:00:28 -0700 X-Original-To: edk2-devel@lists.01.org DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=intel.com; i=@intel.com; q=dns/txt; s=intel; t=1490169631; x=1521705631; h=from:to:cc:subject:date:message-id; bh=Z4mAHUoA+16ue8sGiskRosHLo8WccyrHl6k4LPqDubE=; b=QxirTENYJgJmA9V7+vTRnINiDBSgE0UXkar9cDhvvsLR7Ny8Pao1SacI mPWiOUbglZVdJ2hnWyev+MknbJurgg==; X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.36,204,1486454400"; d="scan'208";a="946932778" From: Ruiyu Ni To: edk2-devel@lists.01.org Date: Wed, 22 Mar 2017 16:00:25 +0800 Message-Id: <20170322080025.678456-1-ruiyu.ni@intel.com> X-Mailer: git-send-email 2.9.0.windows.1 Subject: [edk2] [PATCH] ShellPkg: Fix shell not able to run startup.nsh X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Chen A Chen , Vladimir Olovyannikov MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" From: Chen A Chen Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Chen A Chen Reviewed-by: Ruiyu Ni Reviewed-by: Jaben Carsey Cc: Vladimir Olovyannikov Cc: Jim Dailey --- ShellPkg/Application/Shell/Shell.c | 114 ++++++++++++++++++---------------= ---- 1 file changed, 56 insertions(+), 58 deletions(-) diff --git a/ShellPkg/Application/Shell/Shell.c b/ShellPkg/Application/Shel= l/Shell.c index 731ba18..350d7ff 100644 --- a/ShellPkg/Application/Shell/Shell.c +++ b/ShellPkg/Application/Shell/Shell.c @@ -1132,6 +1132,58 @@ ProcessCommandLine( } =20 /** + Function try to find location of the Startup.nsh file. + =20 + The buffer is callee allocated and should be freed by the caller. + + @param ImagePath The path to the image for shell. first = place to look for the startup script + @param FilePath The path to the file for shell. second = place to look for the startup script. + + @retval NULL No Startup.nsh file was found. + @return !=3DNULL Pointer to NULL-terminated path. +**/ +CHAR16 * +LocateStartupScript ( + IN EFI_DEVICE_PATH_PROTOCOL *ImageDevicePath, + IN EFI_DEVICE_PATH_PROTOCOL *FileDevicePath + ) +{ + CHAR16 *StartupScriptPath; + CHAR16 *TempSpot; + CONST CHAR16 *MapName; + UINTN Size; + + StartupScriptPath =3D NULL; + Size =3D 0; + + // + // Try to find 'Startup.nsh' in the directory where the shell itself was= launched. + // + MapName =3D ShellInfoObject.NewEfiShellProtocol->GetMapFromDevicePath (&= ImageDevicePath); + if (MapName !=3D NULL) { =20 + StartupScriptPath =3D StrnCatGrow (&StartupScriptPath, &Size, MapName,= 0); + TempSpot =3D StrStr (StartupScriptPath, L";"); + if (TempSpot !=3D NULL) { + *TempSpot =3D CHAR_NULL; + } + + StartupScriptPath =3D StrnCatGrow (&StartupScriptPath, &Size, ((FILEPA= TH_DEVICE_PATH *)FileDevicePath)->PathName, 0); + PathRemoveLastItem (StartupScriptPath); + StartupScriptPath =3D StrnCatGrow (&StartupScriptPath, &Size, mStartup= Script, 0); + } + + // + // Try to find 'Startup.nsh' in the execution path defined by the envrio= nment variable PATH. + // + if ((StartupScriptPath =3D=3D NULL) || EFI_ERROR (ShellIsFile (StartupSc= riptPath))) { + SHELL_FREE_NON_NULL (StartupScriptPath); + StartupScriptPath =3D ShellFindFilePath (mStartupScript); + } + + return StartupScriptPath; +} + +/** Handles all interaction with the default startup script. =20 this will check that the correct command line parameters were passed, ha= ndle the delay, and then start running the script. @@ -1151,17 +1203,11 @@ DoStartupScript( EFI_STATUS CalleeStatus; UINTN Delay; EFI_INPUT_KEY Key; - SHELL_FILE_HANDLE FileHandle; - EFI_DEVICE_PATH_PROTOCOL *NewPath; - EFI_DEVICE_PATH_PROTOCOL *NamePath; CHAR16 *FileStringPath; - CHAR16 *TempSpot; UINTN NewSize; - CONST CHAR16 *MapName; =20 Key.UnicodeChar =3D CHAR_NULL; Key.ScanCode =3D 0; - FileHandle =3D NULL; =20 if (!ShellInfoObject.ShellInitSettings.BitUnion.Bits.Startup && ShellInf= oObject.ShellInitSettings.FileName !=3D NULL) { // @@ -1223,59 +1269,11 @@ DoStartupScript( return (EFI_SUCCESS); } =20 - // - // Try the first location (must be file system) - // - MapName =3D ShellInfoObject.NewEfiShellProtocol->GetMapFromDevicePath(&I= magePath); - if (MapName !=3D NULL) { - FileStringPath =3D NULL; - NewSize =3D 0; - FileStringPath =3D StrnCatGrow(&FileStringPath, &NewSize, MapName, 0); - if (FileStringPath =3D=3D NULL) { - Status =3D EFI_OUT_OF_RESOURCES; - } else { - TempSpot =3D StrStr(FileStringPath, L";"); - if (TempSpot !=3D NULL) { - *TempSpot =3D CHAR_NULL; - } - FileStringPath =3D StrnCatGrow(&FileStringPath, &NewSize, ((FILEPATH= _DEVICE_PATH*)FilePath)->PathName, 0); - PathRemoveLastItem(FileStringPath); - FileStringPath =3D StrnCatGrow(&FileStringPath, &NewSize, mStartupSc= ript, 0); - Status =3D ShellInfoObject.NewEfiShellProtocol->OpenFileByName(FileS= tringPath, &FileHandle, EFI_FILE_MODE_READ); - FreePool(FileStringPath); - } - } - if (EFI_ERROR(Status)) { - NamePath =3D FileDevicePath (NULL, mStartupScript); - NewPath =3D AppendDevicePathNode (ImagePath, NamePath); - FreePool(NamePath); - - // - // Try the location - // - Status =3D InternalOpenFileDevicePath(NewPath, &FileHandle, EFI_FILE_M= ODE_READ, 0); - FreePool(NewPath); + FileStringPath =3D LocateStartupScript (ImagePath, FilePath); + if (FileStringPath !=3D NULL) { + Status =3D RunScriptFile (FileStringPath, NULL, L"", ShellInfoObject.N= ewShellParametersProtocol); + FreePool (FileStringPath); } - // - // If we got a file, run it - // - if (!EFI_ERROR(Status) && FileHandle !=3D NULL) { - Status =3D RunScriptFile (mStartupScript, FileHandle, L"", ShellInfoOb= ject.NewShellParametersProtocol); - ShellInfoObject.NewEfiShellProtocol->CloseFile(FileHandle); - } else { - FileStringPath =3D ShellFindFilePath(mStartupScript); - if (FileStringPath =3D=3D NULL) { - // - // we return success since we don't need to have a startup script - // - Status =3D EFI_SUCCESS; - ASSERT(FileHandle =3D=3D NULL); - } else { - Status =3D RunScriptFile(FileStringPath, NULL, L"", ShellInfoObject.= NewShellParametersProtocol); - FreePool(FileStringPath); - } - } - =20 return (Status); } --=20 2.9.0.windows.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel