From 3d783074e1a965dcbcb8f7bb78caf0880b672ed0 Mon Sep 17 00:00:00 2001 From: oliviermartin Date: Sun, 14 Apr 2013 09:25:34 +0000 Subject: ArmPlatformPkg/NorFlashDxe: Make the driver more compliant with the UEFI specification Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Olivier Martin git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@14263 6f19259b-4bc3-4df7-8a09-765794883524 --- .../Drivers/NorFlashDxe/NorFlashBlockIoDxe.c | 18 ++++++++++++++---- ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashDxe.c | 15 +++++++-------- 2 files changed, 21 insertions(+), 12 deletions(-) (limited to 'ArmPlatformPkg') diff --git a/ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashBlockIoDxe.c b/ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashBlockIoDxe.c index 21fceac1dc..279b77c75e 100644 --- a/ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashBlockIoDxe.c +++ b/ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashBlockIoDxe.c @@ -1,6 +1,6 @@ /** @file NorFlashBlockIoDxe.c - Copyright (c) 2011-2012, ARM Ltd. All rights reserved.
+ Copyright (c) 2011-2013, ARM Ltd. All rights reserved.
This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License @@ -51,17 +51,27 @@ NorFlashBlockIoReadBlocks ( { NOR_FLASH_INSTANCE *Instance; EFI_STATUS Status; + EFI_BLOCK_IO_MEDIA *Media; + + if (This == NULL) { + return EFI_INVALID_PARAMETER; + } Instance = INSTANCE_FROM_BLKIO_THIS(This); + Media = This->Media; DEBUG ((DEBUG_BLKIO, "NorFlashBlockIoReadBlocks(MediaId=0x%x, Lba=%ld, BufferSize=0x%x bytes (%d kB), BufferPtr @ 0x%08x)\n", MediaId, Lba, BufferSizeInBytes, Buffer)); - if( !This->Media->MediaPresent ) { + if (!Media) { + Status = EFI_INVALID_PARAMETER; + } else if (!Media->MediaPresent) { Status = EFI_NO_MEDIA; - } else if( This->Media->MediaId != MediaId ) { + } else if (Media->MediaId != MediaId) { Status = EFI_MEDIA_CHANGED; + } else if ((Media->IoAlign > 2) && (((UINTN)Buffer & (Media->IoAlign - 1)) != 0)) { + Status = EFI_INVALID_PARAMETER; } else { - Status = NorFlashReadBlocks (Instance,Lba,BufferSizeInBytes,Buffer); + Status = NorFlashReadBlocks (Instance, Lba, BufferSizeInBytes, Buffer); } return Status; diff --git a/ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashDxe.c b/ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashDxe.c index a9c589b744..7953b6c9f5 100644 --- a/ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashDxe.c +++ b/ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashDxe.c @@ -1,6 +1,6 @@ /** @file NorFlashDxe.c - Copyright (c) 2011-2012, ARM Ltd. All rights reserved.
+ Copyright (c) 2011-2013, ARM Ltd. All rights reserved.
This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License @@ -721,19 +721,20 @@ NorFlashReadBlocks ( UINT32 NumBlocks; UINTN StartAddress; + DEBUG((DEBUG_BLKIO, "NorFlashReadBlocks: BufferSize=0x%xB BlockSize=0x%xB LastBlock=%ld, Lba=%ld.\n", + BufferSizeInBytes, Instance->Media.BlockSize, Instance->Media.LastBlock, Lba)); + // The buffer must be valid if (Buffer == NULL) { return EFI_INVALID_PARAMETER; } - // We must have some bytes to read - DEBUG((DEBUG_BLKIO, "NorFlashReadBlocks: BufferSize=0x%x bytes.\n", BufferSizeInBytes)); - if(BufferSizeInBytes == 0) { - return EFI_BAD_BUFFER_SIZE; + // Return if we have not any byte to read + if (BufferSizeInBytes == 0) { + return EFI_SUCCESS; } // The size of the buffer must be a multiple of the block size - DEBUG((DEBUG_BLKIO, "NorFlashReadBlocks: BlockSize=0x%x bytes.\n", Instance->Media.BlockSize)); if ((BufferSizeInBytes % Instance->Media.BlockSize) != 0) { return EFI_BAD_BUFFER_SIZE; } @@ -741,8 +742,6 @@ NorFlashReadBlocks ( // All blocks must be within the device NumBlocks = ((UINT32)BufferSizeInBytes) / Instance->Media.BlockSize ; - DEBUG((DEBUG_BLKIO, "NorFlashReadBlocks: NumBlocks=%d, LastBlock=%ld, Lba=%ld\n", NumBlocks, Instance->Media.LastBlock, Lba)); - if ((Lba + NumBlocks) > (Instance->Media.LastBlock + 1)) { DEBUG((EFI_D_ERROR, "NorFlashReadBlocks: ERROR - Read will exceed last block\n")); return EFI_INVALID_PARAMETER; -- cgit v1.2.3