ShellPkg: Update behavior for GetTime() errors.
Please find the attached patch that fixes the ShellPkg when gRT->GetTime() returns an error (eg: early UEFI platform bringup with a RTC controller that is not supported). On some platforms, gRT->GetTime() might not return EFI_SUCCESS. The Shell must check the return status before to assume the returned time is valid. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Olivier Martin <Olivier.Martin@arm.com> Reviewed-by: Jaben Carsey <Jaben.Carsey@intel.com> git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@14337 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
		@@ -221,7 +221,10 @@ ShellCommandRunDate (
 | 
				
			|||||||
        // get the current date
 | 
					        // get the current date
 | 
				
			||||||
        //
 | 
					        //
 | 
				
			||||||
        Status = gRT->GetTime(&TheTime, NULL);
 | 
					        Status = gRT->GetTime(&TheTime, NULL);
 | 
				
			||||||
        ASSERT_EFI_ERROR(Status);
 | 
					        if (EFI_ERROR(Status)) {
 | 
				
			||||||
 | 
					          ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_UEFI_FUNC_WARN), gShellLevel2HiiHandle, L"gRT->GetTime", Status);
 | 
				
			||||||
 | 
					          return (SHELL_DEVICE_ERROR);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        //
 | 
					        //
 | 
				
			||||||
        // ShellPrintEx the date in SFO or regular format
 | 
					        // ShellPrintEx the date in SFO or regular format
 | 
				
			||||||
@@ -312,7 +315,10 @@ CheckAndSetTime (
 | 
				
			|||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  Status = gRT->GetTime(&TheTime, NULL);
 | 
					  Status = gRT->GetTime(&TheTime, NULL);
 | 
				
			||||||
  ASSERT_EFI_ERROR(Status);
 | 
					  if (EFI_ERROR(Status)) {
 | 
				
			||||||
 | 
					    ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_UEFI_FUNC_WARN), gShellLevel2HiiHandle, L"gRT->GetTime", Status);
 | 
				
			||||||
 | 
					    return (SHELL_DEVICE_ERROR);
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  if (TimeString != NULL) {
 | 
					  if (TimeString != NULL) {
 | 
				
			||||||
    TimeStringCopy = NULL;
 | 
					    TimeStringCopy = NULL;
 | 
				
			||||||
@@ -420,7 +426,11 @@ ShellCommandRunTime (
 | 
				
			|||||||
    // check for "-?"
 | 
					    // check for "-?"
 | 
				
			||||||
    //
 | 
					    //
 | 
				
			||||||
    Status = gRT->GetTime(&TheTime, NULL);
 | 
					    Status = gRT->GetTime(&TheTime, NULL);
 | 
				
			||||||
    ASSERT_EFI_ERROR(Status);
 | 
					    if (EFI_ERROR(Status)) {
 | 
				
			||||||
 | 
					      ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_UEFI_FUNC_WARN), gShellLevel2HiiHandle, L"gRT->GetTime", Status);
 | 
				
			||||||
 | 
					      return (SHELL_DEVICE_ERROR);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (ShellCommandLineGetFlag(Package, L"-?")) {
 | 
					    if (ShellCommandLineGetFlag(Package, L"-?")) {
 | 
				
			||||||
      ASSERT(FALSE);
 | 
					      ASSERT(FALSE);
 | 
				
			||||||
    } else if (ShellCommandLineGetRawValue(Package, 2) != NULL) {
 | 
					    } else if (ShellCommandLineGetRawValue(Package, 2) != NULL) {
 | 
				
			||||||
@@ -640,6 +650,7 @@ CheckAndSetTimeZone (
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
  Status = gRT->GetTime(&TheTime, NULL);
 | 
					  Status = gRT->GetTime(&TheTime, NULL);
 | 
				
			||||||
  if (EFI_ERROR(Status)) {
 | 
					  if (EFI_ERROR(Status)) {
 | 
				
			||||||
 | 
					    ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_UEFI_FUNC_WARN), gShellLevel2HiiHandle, L"gRT->GetTime", Status);
 | 
				
			||||||
    return (SHELL_DEVICE_ERROR);
 | 
					    return (SHELL_DEVICE_ERROR);
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -785,7 +796,10 @@ ShellCommandRunTimeZone (
 | 
				
			|||||||
      // Get Current Time Zone Info
 | 
					      // Get Current Time Zone Info
 | 
				
			||||||
      //
 | 
					      //
 | 
				
			||||||
      Status = gRT->GetTime(&TheTime, NULL);
 | 
					      Status = gRT->GetTime(&TheTime, NULL);
 | 
				
			||||||
      ASSERT_EFI_ERROR(Status);
 | 
					      if (EFI_ERROR(Status)) {
 | 
				
			||||||
 | 
					        ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_UEFI_FUNC_WARN), gShellLevel2HiiHandle, L"gRT->GetTime", Status);
 | 
				
			||||||
 | 
					        return (SHELL_DEVICE_ERROR);
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      if (TheTime.TimeZone != EFI_UNSPECIFIED_TIMEZONE) {
 | 
					      if (TheTime.TimeZone != EFI_UNSPECIFIED_TIMEZONE) {
 | 
				
			||||||
        Found = FALSE;
 | 
					        Found = FALSE;
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -38,7 +38,11 @@ TouchFileByHandle (
 | 
				
			|||||||
    return (EFI_ACCESS_DENIED);
 | 
					    return (EFI_ACCESS_DENIED);
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  Status = gRT->GetTime(&FileInfo->ModificationTime, NULL);
 | 
					  Status = gRT->GetTime(&FileInfo->ModificationTime, NULL);
 | 
				
			||||||
  ASSERT_EFI_ERROR(Status);
 | 
					  if (EFI_ERROR(Status)) {
 | 
				
			||||||
 | 
					    ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel3HiiHandle, L"gRT->GetTime", Status);
 | 
				
			||||||
 | 
					    return (SHELL_DEVICE_ERROR);
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  CopyMem(&FileInfo->LastAccessTime, &FileInfo->ModificationTime, sizeof(EFI_TIME));
 | 
					  CopyMem(&FileInfo->LastAccessTime, &FileInfo->ModificationTime, sizeof(EFI_TIME));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  Status = gEfiShellProtocol->SetFileInfo(Handle, FileInfo);
 | 
					  Status = gEfiShellProtocol->SetFileInfo(Handle, FileInfo);
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user