ArmPlatformPkg/BootMonFs: Use DiskIO to read image descriptions

Now that NorFlashDxe implements DiskIo directly and at a fine granularity
this significantly improves performance.

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@15512 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
Brendan Jackman 2014-05-08 15:02:18 +00:00 committed by oliviermartin
parent cc135144b9
commit a9185e7618
1 changed files with 42 additions and 43 deletions

View File

@ -89,56 +89,49 @@ BootMonFsComputeFooterChecksum (
} }
BOOLEAN BOOLEAN
BootMonFsImageInThisBlock ( BootMonFsIsImageValid (
IN VOID *Buf, IN HW_IMAGE_DESCRIPTION *Desc,
IN UINTN Size, IN EFI_LBA Lba
IN UINT32 Block,
OUT HW_IMAGE_DESCRIPTION *Image
) )
{ {
EFI_STATUS Status; EFI_STATUS Status;
HW_IMAGE_FOOTER *Ptr; HW_IMAGE_FOOTER *Footer;
HW_IMAGE_DESCRIPTION *Footer;
UINT32 Checksum; UINT32 Checksum;
// The footer is stored as the last thing in the block Footer = &Desc->Footer;
Ptr = (HW_IMAGE_FOOTER *)((UINT8 *)Buf + Size - sizeof (HW_IMAGE_FOOTER));
// Check that the verification bytes are present // Check that the verification bytes are present
if ((Ptr->FooterSignature1 != HW_IMAGE_FOOTER_SIGNATURE_1) || (Ptr->FooterSignature2 != HW_IMAGE_FOOTER_SIGNATURE_2)) { if ((Footer->FooterSignature1 != HW_IMAGE_FOOTER_SIGNATURE_1) ||
(Footer->FooterSignature2 != HW_IMAGE_FOOTER_SIGNATURE_2)) {
return FALSE; return FALSE;
} }
if (Ptr->Version == HW_IMAGE_FOOTER_VERSION) { if (Footer->Version == HW_IMAGE_FOOTER_VERSION) {
if (Ptr->Offset != HW_IMAGE_FOOTER_OFFSET) { if (Footer->Offset != HW_IMAGE_FOOTER_OFFSET) {
return FALSE; return FALSE;
} }
} else if (Ptr->Version == HW_IMAGE_FOOTER_VERSION2) { } else if (Footer->Version == HW_IMAGE_FOOTER_VERSION2) {
if (Ptr->Offset != HW_IMAGE_FOOTER_OFFSET2) { if (Footer->Offset != HW_IMAGE_FOOTER_OFFSET2) {
return FALSE; return FALSE;
} }
} else { } else {
return FALSE; return FALSE;
} }
Footer = (HW_IMAGE_DESCRIPTION *)(((UINT8 *)Buf + Size - sizeof (HW_IMAGE_DESCRIPTION))); Checksum = Desc->FooterChecksum;
Checksum = Footer->FooterChecksum; Status = BootMonFsComputeFooterChecksum (Desc);
Status = BootMonFsComputeFooterChecksum (Footer);
if (EFI_ERROR (Status)) { if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_ERROR, "Warning: failed to compute checksum for image '%a'\n", Footer->Footer.Filename)); DEBUG ((DEBUG_ERROR, "Warning: failed to compute checksum for image '%a'\n", Desc->Footer.Filename));
} }
if (Footer->FooterChecksum != Checksum) { if (Desc->FooterChecksum != Checksum) {
DEBUG ((DEBUG_ERROR, "Warning: image '%a' checksum mismatch.\n", Footer->Footer.Filename)); DEBUG ((DEBUG_ERROR, "Warning: image '%a' checksum mismatch.\n", Desc->Footer.Filename));
} }
if ((Footer->BlockEnd != Block) || (Footer->BlockStart > Footer->BlockEnd)) { if ((Desc->BlockEnd != Lba) || (Desc->BlockStart > Desc->BlockEnd)) {
return FALSE; return FALSE;
} }
// Copy the image out
CopyMem (Image, Footer, sizeof (HW_IMAGE_DESCRIPTION));
return TRUE; return TRUE;
} }
@ -146,33 +139,40 @@ EFI_STATUS
BootMonFsDiscoverNextImage ( BootMonFsDiscoverNextImage (
IN BOOTMON_FS_INSTANCE *Instance, IN BOOTMON_FS_INSTANCE *Instance,
IN EFI_LBA *LbaStart, IN EFI_LBA *LbaStart,
OUT HW_IMAGE_DESCRIPTION *Image OUT HW_IMAGE_DESCRIPTION *ImageDescription
) )
{ {
EFI_BLOCK_IO_PROTOCOL *Blocks; EFI_DISK_IO_PROTOCOL *DiskIo;
EFI_LBA CurrentLba; EFI_LBA CurrentLba;
VOID *Out; UINT64 DescOffset;
EFI_STATUS Status;
Blocks = Instance->BlockIo; DiskIo = Instance->DiskIo;
// Allocate an output buffer
Out = AllocatePool (Instance->Media->BlockSize);
if (Out == NULL) {
return EFI_OUT_OF_RESOURCES;
}
Blocks->Reset (Blocks, FALSE);
CurrentLba = *LbaStart; CurrentLba = *LbaStart;
// Look for images in the rest of this block // Look for images in the rest of this block
while (CurrentLba <= Instance->Media->LastBlock) { while (CurrentLba <= Instance->Media->LastBlock) {
// Read in the next block // Work out the byte offset into media of the image description in this block
Blocks->ReadBlocks (Blocks, Instance->Media->MediaId, CurrentLba, Instance->Media->BlockSize, Out); // If present, the image description is at the very end of the block.
// Check for an image in the current block DescOffset = ((CurrentLba + 1) * Instance->Media->BlockSize) - sizeof (HW_IMAGE_DESCRIPTION);
if (BootMonFsImageInThisBlock (Out, Instance->Media->BlockSize, (CurrentLba - Instance->Media->LowestAlignedLba), Image)) {
DEBUG ((EFI_D_ERROR, "Found image: %a in block %d.\n", &(Image->Footer.Filename), (UINTN)(CurrentLba - Instance->Media->LowestAlignedLba))); // Read the image description from media
FreePool (Out); Status = DiskIo->ReadDisk (DiskIo,
*LbaStart = Image->BlockEnd + 1; Instance->Media->MediaId,
DescOffset,
sizeof (HW_IMAGE_DESCRIPTION),
ImageDescription
);
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;
return EFI_SUCCESS; return EFI_SUCCESS;
} else { } else {
CurrentLba++; CurrentLba++;
@ -180,7 +180,6 @@ BootMonFsDiscoverNextImage (
} }
*LbaStart = CurrentLba; *LbaStart = CurrentLba;
FreePool (Out);
return EFI_NOT_FOUND; return EFI_NOT_FOUND;
} }