Ext4Pkg: Move unicode collation initialization to Start()

There have been reports[1] of failures to boot due to unicode collation
protocols not being available at Ext4Dxe load time. Therefore, attempt
to initialize unicode collation at Start() time, like done previously in
FatPkg/EnhancedFatDxe. By doing so, we move collation initialization
to BDS, where the module responsible for protocol installation should
have already been loaded and ran.

[1]: https://edk2.groups.io/g/devel/message/100312

Cc: Ard Biesheuvel <ardb@kernel.org>
Cc: Marvin Häuser <mhaeuser@posteo.de>
Fixes: d9ceedca6c8f ("Ext4Pkg: Add Ext4Dxe driver.")
Signed-off-by: Pedro Falcato <pedro.falcato@gmail.com>
Acked-by: Ard Biesheuvel <ardb@kernel.org>
Reviewed-by: Marvin Häuser <mhaeuser@posteo.de>
This commit is contained in:
Pedro Falcato 2023-02-17 19:46:29 +00:00 committed by Savva Mitrofanov
parent c546b66aa4
commit 10ad1cf2c6
No known key found for this signature in database
GPG Key ID: 774924031750BF64
2 changed files with 49 additions and 24 deletions

View File

@ -1,7 +1,7 @@
/** @file /** @file
Unicode collation routines Unicode collation routines
Copyright (c) 2021 Pedro Falcato All rights reserved. Copyright (c) 2021 - 2023 Pedro Falcato All rights reserved.
Copyright (c) 2005 - 2017, Intel Corporation. All rights reserved. Copyright (c) 2005 - 2017, Intel Corporation. All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent SPDX-License-Identifier: BSD-2-Clause-Patent
@ -9,6 +9,7 @@
#include <Uefi.h> #include <Uefi.h>
#include <Library/DebugLib.h>
#include <Library/UefiLib.h> #include <Library/UefiLib.h>
#include <Library/UefiBootServicesTableLib.h> #include <Library/UefiBootServicesTableLib.h>
#include <Library/MemoryAllocationLib.h> #include <Library/MemoryAllocationLib.h>
@ -23,6 +24,21 @@ STATIC EFI_UNICODE_COLLATION_PROTOCOL *gUnicodeCollationInterface = NULL;
* PS: Maybe all this code could be put in a library? It looks heavily shareable. * PS: Maybe all this code could be put in a library? It looks heavily shareable.
**/ **/
/**
Check if unicode collation is initialized
@retval TRUE if Ext4InitialiseUnicodeCollation() was already called successfully
@retval FALSE if Ext4InitialiseUnicodeCollation() was not yet called successfully
**/
STATIC
BOOLEAN
Ext4IsCollationInitialized (
VOID
)
{
return gUnicodeCollationInterface != NULL;
}
/** /**
Worker function to initialize Unicode Collation support. Worker function to initialize Unicode Collation support.
@ -127,6 +143,11 @@ Ext4InitialiseUnicodeCollation (
Status = EFI_UNSUPPORTED; Status = EFI_UNSUPPORTED;
// If already done, just return success.
if (Ext4IsCollationInitialized ()) {
return EFI_SUCCESS;
}
// //
// First try to use RFC 4646 Unicode Collation 2 Protocol. // First try to use RFC 4646 Unicode Collation 2 Protocol.
// //
@ -169,5 +190,6 @@ Ext4StrCmpInsensitive (
IN CHAR16 *Str2 IN CHAR16 *Str2
) )
{ {
ASSERT (gUnicodeCollationInterface != NULL);
return gUnicodeCollationInterface->StriColl (gUnicodeCollationInterface, Str1, Str2); return gUnicodeCollationInterface->StriColl (gUnicodeCollationInterface, Str1, Str2);
} }

View File

@ -1,7 +1,7 @@
/** @file /** @file
Driver entry point Driver entry point
Copyright (c) 2021 Pedro Falcato All rights reserved. Copyright (c) 2021 - 2023 Pedro Falcato All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent SPDX-License-Identifier: BSD-2-Clause-Patent
**/ **/
@ -513,26 +513,18 @@ Ext4EntryPoint (
IN EFI_SYSTEM_TABLE *SystemTable IN EFI_SYSTEM_TABLE *SystemTable
) )
{ {
EFI_STATUS Status; return EfiLibInstallAllDriverProtocols2 (
ImageHandle,
Status = EfiLibInstallAllDriverProtocols2 ( SystemTable,
ImageHandle, &gExt4BindingProtocol,
SystemTable, ImageHandle,
&gExt4BindingProtocol, &gExt4ComponentName,
ImageHandle, &gExt4ComponentName2,
&gExt4ComponentName, NULL,
&gExt4ComponentName2, NULL,
NULL, NULL,
NULL, NULL
NULL, );
NULL
);
if (EFI_ERROR (Status)) {
return Status;
}
return Ext4InitialiseUnicodeCollation (ImageHandle);
} }
/** /**
@ -761,6 +753,17 @@ Ext4Bind (
BlockIo = NULL; BlockIo = NULL;
DiskIo = NULL; DiskIo = NULL;
// Note: We initialize collation here since this is called in BDS, when we are likely
// to have the Unicode Collation protocols available.
Status = Ext4InitialiseUnicodeCollation (BindingProtocol->ImageHandle);
if (EFI_ERROR (Status)) {
// Lets throw a loud error into the log
// It is very unlikely something like this may fire out of the blue. Chances are either
// the platform configuration is wrong, or we are.
DEBUG ((DEBUG_ERROR, "[ext4] Error: Unicode Collation not available - failure to Start() - error %r\n", Status));
goto Error;
}
Status = gBS->OpenProtocol ( Status = gBS->OpenProtocol (
ControllerHandle, ControllerHandle,
&gEfiDiskIoProtocolGuid, &gEfiDiskIoProtocolGuid,
@ -774,7 +777,7 @@ Ext4Bind (
goto Error; goto Error;
} }
DEBUG ((DEBUG_INFO, "[Ext4] Controller supports DISK_IO\n")); DEBUG ((DEBUG_INFO, "[ext4] Controller supports DISK_IO\n"));
Status = gBS->OpenProtocol ( Status = gBS->OpenProtocol (
ControllerHandle, ControllerHandle,
@ -787,7 +790,7 @@ Ext4Bind (
// It's okay to not support DISK_IO2 // It's okay to not support DISK_IO2
if (DiskIo2 != NULL) { if (DiskIo2 != NULL) {
DEBUG ((DEBUG_INFO, "[Ext4] Controller supports DISK_IO2\n")); DEBUG ((DEBUG_INFO, "[ext4] Controller supports DISK_IO2\n"));
} }
Status = gBS->OpenProtocol ( Status = gBS->OpenProtocol (