X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=EmbeddedPkg%2FUniversal%2FMmcDxe%2FDiagnostics.c;h=7d6a5a0dde01cf890a86773d3fbafb198f5508ff;hp=516c832bb58cae03baeb4537d3872cf30e6015b9;hb=76c09700edc67686b29662e81a3ca7d947594ce5;hpb=11c20f4e06d252feaa65aa5e526686baf015762d diff --git a/EmbeddedPkg/Universal/MmcDxe/Diagnostics.c b/EmbeddedPkg/Universal/MmcDxe/Diagnostics.c index 516c832bb5..7d6a5a0dde 100644 --- a/EmbeddedPkg/Universal/MmcDxe/Diagnostics.c +++ b/EmbeddedPkg/Universal/MmcDxe/Diagnostics.c @@ -1,15 +1,15 @@ /** @file Diagnostics Protocol implementation for the MMC DXE driver - Copyright (c) 2011, ARM Limited. All rights reserved. - - This program and the accompanying materials - are licensed and made available under the terms and conditions of the BSD License - which accompanies this distribution. The full text of the license may be found at - http://opensource.org/licenses/bsd-license.php + Copyright (c) 2011-2014, ARM Limited. All rights reserved. - THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, - WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. + This program and the accompanying materials + are licensed and made available under the terms and conditions of the BSD License + which accompanies this distribution. The full text of the license may be found at + http://opensource.org/licenses/bsd-license.php + + THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, + WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. **/ @@ -17,6 +17,7 @@ #include #include #include +#include #include "Mmc.h" @@ -31,7 +32,7 @@ DiagnosticInitLog ( ) { mLogRemainChar = MaxBufferChar; - mLogBuffer = AllocatePool ((UINTN)MaxBufferChar * sizeof(CHAR16)); + mLogBuffer = AllocatePool ((UINTN)MaxBufferChar * sizeof (CHAR16)); return mLogBuffer; } @@ -41,9 +42,9 @@ DiagnosticLog ( ) { UINTN len = StrLen (Str); - if (len <= mLogRemainChar) { + if (len < mLogRemainChar) { + StrCpyS (mLogBuffer, mLogRemainChar, Str); mLogRemainChar -= len; - StrCpy (mLogBuffer, Str); mLogBuffer += len; return len; } else { @@ -79,8 +80,8 @@ CompareBuffer ( for (i = 0; i < (BufferSize >> 3); i++) { if (*BufferA64 != *BufferB64) { - DEBUG((EFI_D_ERROR, "CompareBuffer: Error at %i", i)); - DEBUG((EFI_D_ERROR, "(0x%lX) != (0x%lX)\n", *BufferA64, *BufferB64)); + DEBUG ((EFI_D_ERROR, "CompareBuffer: Error at %i", i)); + DEBUG ((EFI_D_ERROR, "(0x%lX) != (0x%lX)\n", *BufferA64, *BufferB64)); return FALSE; } BufferA64++; @@ -192,6 +193,11 @@ MmcDriverDiagnosticsRunDiagnostics ( return EFI_INVALID_PARAMETER; } + // Check Language is supported (i.e. is "en-*" - only English is supported) + if (AsciiStrnCmp (Language, "en", 2) != 0) { + return EFI_UNSUPPORTED; + } + Status = EFI_SUCCESS; *ErrorType = NULL; *BufferSize = DIAGNOSTIC_LOGBUFFER_MAXCHAR; @@ -199,34 +205,43 @@ MmcDriverDiagnosticsRunDiagnostics ( DiagnosticLog (L"MMC Driver Diagnostics\n"); - // For each MMC instance + // Find the MMC Host instance on which we have been asked to run diagnostics + MmcHostInstance = NULL; CurrentLink = mMmcHostPool.ForwardLink; while (CurrentLink != NULL && CurrentLink != &mMmcHostPool && (Status == EFI_SUCCESS)) { MmcHostInstance = MMC_HOST_INSTANCE_FROM_LINK(CurrentLink); ASSERT(MmcHostInstance != NULL); + if (MmcHostInstance->MmcHandle == ControllerHandle) { + break; + } + CurrentLink = CurrentLink->ForwardLink; + } - // LBA=1 Size=BlockSize - DiagnosticLog (L"MMC Driver Diagnostics - Test: First Block\n"); - Status = MmcReadWriteDataTest (MmcHostInstance, 1, MmcHostInstance->BlockIo.Media->BlockSize); + // If we didn't find the controller, return EFI_UNSUPPORTED + if ((MmcHostInstance == NULL) + || (MmcHostInstance->MmcHandle != ControllerHandle)) { + return EFI_UNSUPPORTED; + } - // LBA=2 Size=BlockSize - DiagnosticLog (L"MMC Driver Diagnostics - Test: Second Block\n"); - Status = MmcReadWriteDataTest (MmcHostInstance, 2, MmcHostInstance->BlockIo.Media->BlockSize); + // LBA=1 Size=BlockSize + DiagnosticLog (L"MMC Driver Diagnostics - Test: First Block\n"); + Status = MmcReadWriteDataTest (MmcHostInstance, 1, MmcHostInstance->BlockIo.Media->BlockSize); - // LBA=10 Size=BlockSize - DiagnosticLog (L"MMC Driver Diagnostics - Test: Any Block\n"); - Status = MmcReadWriteDataTest (MmcHostInstance, MmcHostInstance->BlockIo.Media->LastBlock >> 1, MmcHostInstance->BlockIo.Media->BlockSize); + // LBA=2 Size=BlockSize + DiagnosticLog (L"MMC Driver Diagnostics - Test: Second Block\n"); + Status = MmcReadWriteDataTest (MmcHostInstance, 2, MmcHostInstance->BlockIo.Media->BlockSize); - // LBA=LastBlock Size=BlockSize - DiagnosticLog (L"MMC Driver Diagnostics - Test: Last Block\n"); - Status = MmcReadWriteDataTest (MmcHostInstance, MmcHostInstance->BlockIo.Media->LastBlock, MmcHostInstance->BlockIo.Media->BlockSize); + // LBA=10 Size=BlockSize + DiagnosticLog (L"MMC Driver Diagnostics - Test: Any Block\n"); + Status = MmcReadWriteDataTest (MmcHostInstance, MmcHostInstance->BlockIo.Media->LastBlock >> 1, MmcHostInstance->BlockIo.Media->BlockSize); - // LBA=1 Size=2*BlockSize - DiagnosticLog (L"MMC Driver Diagnostics - Test: First Block / 2 BlockSSize\n"); - Status = MmcReadWriteDataTest (MmcHostInstance, 1, 2*MmcHostInstance->BlockIo.Media->BlockSize); + // LBA=LastBlock Size=BlockSize + DiagnosticLog (L"MMC Driver Diagnostics - Test: Last Block\n"); + Status = MmcReadWriteDataTest (MmcHostInstance, MmcHostInstance->BlockIo.Media->LastBlock, MmcHostInstance->BlockIo.Media->BlockSize); - CurrentLink = CurrentLink->ForwardLink; - } + // LBA=1 Size=2*BlockSize + DiagnosticLog (L"MMC Driver Diagnostics - Test: First Block / 2 BlockSSize\n"); + Status = MmcReadWriteDataTest (MmcHostInstance, 1, 2 * MmcHostInstance->BlockIo.Media->BlockSize); return Status; }