summaryrefslogtreecommitdiff
path: root/ArmPlatformPkg
diff options
context:
space:
mode:
authorBrendan Jackman <brendan.jackman@arm.com>2014-05-08 15:08:39 +0000
committeroliviermartin <oliviermartin@6f19259b-4bc3-4df7-8a09-765794883524>2014-05-08 15:08:39 +0000
commit79e12331ef1e7c24b5be70d7bc79977ca103bab4 (patch)
treed9c61da702499937e1e4fdca5cf8b2023abf8254 /ArmPlatformPkg
parente29771bb6e896d212f92ea32e67deacbecb51bea (diff)
downloadedk2-platforms-79e12331ef1e7c24b5be70d7bc79977ca103bab4.tar.xz
ArmPlatformPkg/BootMonFs: Cache the HW Description address
This fixes a bug whereby the image description is written over file data when the file's size is close to a multiple of the block size. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Brendan Jackman <brendan.jackman@arm.com> Reviewed-by: Olivier Martin <olivier.martin@arm.com> git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@15517 6f19259b-4bc3-4df7-8a09-765794883524
Diffstat (limited to 'ArmPlatformPkg')
-rw-r--r--ArmPlatformPkg/FileSystem/BootMonFs/BootMonFsApi.h7
-rw-r--r--ArmPlatformPkg/FileSystem/BootMonFs/BootMonFsImages.c23
-rw-r--r--ArmPlatformPkg/FileSystem/BootMonFs/BootMonFsInternal.h1
-rw-r--r--ArmPlatformPkg/FileSystem/BootMonFs/BootMonFsOpenClose.c19
4 files changed, 22 insertions, 28 deletions
diff --git a/ArmPlatformPkg/FileSystem/BootMonFs/BootMonFsApi.h b/ArmPlatformPkg/FileSystem/BootMonFs/BootMonFsApi.h
index 4f0122e32b..9c1daa523b 100644
--- a/ArmPlatformPkg/FileSystem/BootMonFs/BootMonFsApi.h
+++ b/ArmPlatformPkg/FileSystem/BootMonFs/BootMonFsApi.h
@@ -18,13 +18,6 @@
#include <Protocol/SimpleFileSystem.h>
EFI_STATUS
-BootMonFsDiscoverNextImage (
- IN BOOTMON_FS_INSTANCE *Flash,
- IN EFI_LBA *LbaStart,
- OUT HW_IMAGE_DESCRIPTION *Image
- );
-
-EFI_STATUS
BootMonFsInitialize (
IN BOOTMON_FS_INSTANCE *Instance
);
diff --git a/ArmPlatformPkg/FileSystem/BootMonFs/BootMonFsImages.c b/ArmPlatformPkg/FileSystem/BootMonFs/BootMonFsImages.c
index c362b384f2..346c360292 100644
--- a/ArmPlatformPkg/FileSystem/BootMonFs/BootMonFsImages.c
+++ b/ArmPlatformPkg/FileSystem/BootMonFs/BootMonFsImages.c
@@ -135,11 +135,12 @@ BootMonFsIsImageValid (
return TRUE;
}
+STATIC
EFI_STATUS
BootMonFsDiscoverNextImage (
- IN BOOTMON_FS_INSTANCE *Instance,
- IN EFI_LBA *LbaStart,
- OUT HW_IMAGE_DESCRIPTION *ImageDescription
+ IN BOOTMON_FS_INSTANCE *Instance,
+ IN OUT EFI_LBA *LbaStart,
+ IN OUT BOOTMON_FS_FILE *File
)
{
EFI_DISK_IO_PROTOCOL *DiskIo;
@@ -162,17 +163,21 @@ BootMonFsDiscoverNextImage (
Instance->Media->MediaId,
DescOffset,
sizeof (HW_IMAGE_DESCRIPTION),
- ImageDescription
+ &File->HwDescription
);
if (EFI_ERROR (Status)) {
return Status;
}
// If we found a valid image description...
- if (BootMonFsIsImageValid (ImageDescription, (CurrentLba - Instance->Media->LowestAlignedLba))) {
- DEBUG ((EFI_D_ERROR, "Found image: %a in block %d.\n", &(ImageDescription->Footer.Filename), (UINTN)(CurrentLba - Instance->Media->LowestAlignedLba)));
-
- *LbaStart = ImageDescription->BlockEnd + 1;
+ if (BootMonFsIsImageValid (&File->HwDescription, (CurrentLba - Instance->Media->LowestAlignedLba))) {
+ DEBUG ((EFI_D_ERROR, "Found image: %a in block %d.\n",
+ &(File->HwDescription.Footer.Filename),
+ (UINTN)(CurrentLba - Instance->Media->LowestAlignedLba)
+ ));
+ File->HwDescAddress = DescOffset;
+
+ *LbaStart = CurrentLba + 1;
return EFI_SUCCESS;
} else {
CurrentLba++;
@@ -202,7 +207,7 @@ BootMonFsInitialize (
return Status;
}
- Status = BootMonFsDiscoverNextImage (Instance, &Lba, &(NewFile->HwDescription));
+ Status = BootMonFsDiscoverNextImage (Instance, &Lba, NewFile);
if (EFI_ERROR (Status)) {
// Free NewFile allocated by BootMonFsCreateFile ()
FreePool (NewFile);
diff --git a/ArmPlatformPkg/FileSystem/BootMonFs/BootMonFsInternal.h b/ArmPlatformPkg/FileSystem/BootMonFs/BootMonFsInternal.h
index 8bcbac6433..3167bba00a 100644
--- a/ArmPlatformPkg/FileSystem/BootMonFs/BootMonFsInternal.h
+++ b/ArmPlatformPkg/FileSystem/BootMonFs/BootMonFsInternal.h
@@ -48,6 +48,7 @@ typedef struct {
LIST_ENTRY Link;
BOOTMON_FS_INSTANCE *Instance;
+ UINTN HwDescAddress;
HW_IMAGE_DESCRIPTION HwDescription;
EFI_FILE_PROTOCOL File;
diff --git a/ArmPlatformPkg/FileSystem/BootMonFs/BootMonFsOpenClose.c b/ArmPlatformPkg/FileSystem/BootMonFs/BootMonFsOpenClose.c
index 7025389714..6616b4f694 100644
--- a/ArmPlatformPkg/FileSystem/BootMonFs/BootMonFsOpenClose.c
+++ b/ArmPlatformPkg/FileSystem/BootMonFs/BootMonFsOpenClose.c
@@ -29,24 +29,18 @@ InvalidateImageDescription (
EFI_DISK_IO_PROTOCOL *DiskIo;
EFI_BLOCK_IO_PROTOCOL *BlockIo;
UINT32 MediaId;
- UINT32 BlockSize;
VOID *Buffer;
EFI_STATUS Status;
- UINT64 DescriptionAddress;
DiskIo = File->Instance->DiskIo;
BlockIo = File->Instance->BlockIo;
MediaId = BlockIo->Media->MediaId;
- BlockSize = BlockIo->Media->BlockSize;
-
- DescriptionAddress = (File->HwDescription.BlockEnd * BlockSize)
- - sizeof (HW_IMAGE_DESCRIPTION);
Buffer = AllocateZeroPool (sizeof (HW_IMAGE_DESCRIPTION));
Status = DiskIo->WriteDisk (DiskIo,
MediaId,
- DescriptionAddress,
+ File->HwDescAddress,
sizeof (HW_IMAGE_DESCRIPTION),
Buffer
);
@@ -86,7 +80,7 @@ FlushAppendRegion (
// Only invalidate the Image Description of files that have already been
// written in Flash
- if (File->HwDescription.RegionCount > 0) {
+ if (File->HwDescAddress != 0) {
Status = InvalidateImageDescription (File);
ASSERT_EFI_ERROR (Status);
}
@@ -131,11 +125,14 @@ FlushAppendRegion (
if ((NewFileSize % BlockSize) > 0) {
NewFileSize += BlockSize - (NewFileSize % BlockSize);
}
+
+ File->HwDescAddress = (FileStart + NewFileSize) - sizeof (HW_IMAGE_DESCRIPTION);
+
// Update the file description on the media
Status = DiskIo->WriteDisk (
DiskIo,
File->Instance->Media->MediaId,
- (FileStart + NewFileSize) - sizeof (HW_IMAGE_DESCRIPTION),
+ File->HwDescAddress,
sizeof (HW_IMAGE_DESCRIPTION),
Description
);
@@ -585,7 +582,6 @@ BootMonFsDelete (
BOOTMON_FS_FILE *File;
LIST_ENTRY *RegionToFlushLink;
BOOTMON_FS_FILE_REGION *Region;
- HW_IMAGE_DESCRIPTION *Description;
EFI_BLOCK_IO_PROTOCOL *BlockIo;
UINT8 *EmptyBuffer;
@@ -613,7 +609,6 @@ BootMonFsDelete (
// If (RegionCount is greater than 0) then the file already exists
if (File->HwDescription.RegionCount > 0) {
- Description = &File->HwDescription;
BlockIo = File->Instance->BlockIo;
// Create an empty buffer
@@ -624,7 +619,7 @@ BootMonFsDelete (
}
// Invalidate the last Block
- Status = BlockIo->WriteBlocks (BlockIo, BlockIo->Media->MediaId, Description->BlockEnd, BlockIo->Media->BlockSize, EmptyBuffer);
+ Status = InvalidateImageDescription (File);
ASSERT_EFI_ERROR (Status);
FreePool (EmptyBuffer);