public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: Laszlo Ersek <lersek@redhat.com>
To: Ard Biesheuvel <ard.biesheuvel@linaro.org>,
	Marcin Wojtas <mw@semihalf.com>
Cc: Hua Jing <jinghua@marvell.com>,
	Grzegorz Jaszczyk <jaz@semihalf.com>,
	"edk2-devel@lists.01.org" <edk2-devel@lists.01.org>,
	Leif Lindholm <leif.lindholm@linaro.org>,
	Nadav Haklai <nadavh@marvell.com>,
	Neta Zur Hershkovits <neta@marvell.com>
Subject: Re: [platforms PATCH 1/2] Marvell/Drivers: MvFvbDxe: Adjust to new dependencies
Date: Mon, 16 Apr 2018 21:41:06 +0200	[thread overview]
Message-ID: <487cbdc8-72f7-e990-f53b-354c88370ba8@redhat.com> (raw)
In-Reply-To: <CAKv+Gu-qCDRtjMMOkNazn3xQusCxFvc+X+nRsHROQCesunGW1w@mail.gmail.com>

On 04/16/18 07:40, Ard Biesheuvel wrote:
> (+ Laszlo)
> 
> On 16 April 2018 at 07:09, Marcin Wojtas <mw@semihalf.com> wrote:
>> Recent changes in the EDK2 mainline resulted in breaking
>> of compilation and booting of Armada platforms.
>> This patch adjust the MvFvbDxe driver by:
>>
>>  * installation of gEdkiiNvVarStoreFormattedGuid in order to signal
>>    NvVarStoreFormattedLib to the generic variable runtime driver
>>
> 
> Hello Marcin,
> 
> Installing this GUID is only necessary if you update your platform
> .DSC to make the generic variable runtime driver depend on it by
> adding a NULL library class resolution using NvVarStoreFormattedLib.
> So I think this patch is correct, but you'll need an additional change
> to make it work as expected. (Otherwise, the variable runtime driver
> could still be dispatched early and invoked for read access before the
> variable store is reformatted)

I agree.

I'd also like to point out another frequent pitfall in this patch:

>>  * making explicit dependency to ArmPkg/Drivers/CpuDxe drivers in order
>>    to enable successful calling of gDS->SetMemorySpaceAttributes
>>
>> Contributed-under: TianoCore Contribution Agreement 1.1
>> Signed-off-by: Marcin Wojtas <mw@semihalf.com>
>> ---
>>  Silicon/Marvell/Drivers/Spi/MvFvbDxe/MvFvbDxe.c   | 21 ++++++++++++++++++++
>>  Silicon/Marvell/Drivers/Spi/MvFvbDxe/MvFvbDxe.inf |  7 ++-----
>>  2 files changed, 23 insertions(+), 5 deletions(-)
>>
>> diff --git a/Silicon/Marvell/Drivers/Spi/MvFvbDxe/MvFvbDxe.c b/Silicon/Marvell/Drivers/Spi/MvFvbDxe/MvFvbDxe.c
>> index 252ef67..6e583a3 100644
>> --- a/Silicon/Marvell/Drivers/Spi/MvFvbDxe/MvFvbDxe.c
>> +++ b/Silicon/Marvell/Drivers/Spi/MvFvbDxe/MvFvbDxe.c
>> @@ -26,6 +26,7 @@
>>  #include <Library/UefiLib.h>
>>  #include <Library/UefiRuntimeLib.h>
>>
>> +#include <Guid/NvVarStoreFormatted.h>
>>  #include <Guid/SystemNvDataGuid.h>
>>  #include <Guid/VariableFormat.h>
>>
>> @@ -1076,6 +1077,21 @@ MvFvbEntryPoint (
>>    }
>>
>>    //
>> +  // The driver implementing the variable read service can now be dispatched;
>> +  // the varstore headers are in place.
>> +  //
>> +  Status = gBS->InstallProtocolInterface (&gImageHandle,
>> +                  &gEdkiiNvVarStoreFormattedGuid,
>> +                  EFI_NATIVE_INTERFACE,
>> +                  NULL);
>> +  if (EFI_ERROR (Status)) {
>> +    DEBUG ((DEBUG_ERROR,
>> +      "%a: Failed to install gEdkiiNvVarStoreFormattedGuid\n",
>> +      __FUNCTION__));
>> +    goto ErrorInstallNvVarStoreFormatted;
>> +  }
>> +
>> +  //
>>    // Declare the Non-Volatile storage as EFI_MEMORY_RUNTIME
>>    //
>>    RuntimeMmioRegionSize = mFvbDevice->FvbSize;
>> @@ -1126,6 +1142,11 @@ ErrorSetMemAttr:
>>    gDS->RemoveMemorySpace (RegionBaseAddress, RuntimeMmioRegionSize);
>>
>>  ErrorAddSpace:
>> +  gBS->UninstallProtocolInterface (&gImageHandle,
>> +                  &gEdkiiNvVarStoreFormattedGuid,
>> +                  NULL);
>> +

While gBS->InstallProtocolInterface() takes a *pointer* to a handle
(because it can *create* a handle, if the handle is NULL on input, and
the first protocol interface is installed on it),
gBS->UninstallProtocolInterface() takes the handle *itself*. If the last
protocol interface is uninstalled from the handle, then the handle is
destroyed, but gBS->UninstallProtocolInterface() does not attempt to
NULL the handle itself. So, here you should pass "gImageHandle", not
"&gImageHandle".

There's also a bit of whitespace mangling here that's not compatible
with either multiline function call style that we like in edk2, but
perhaps edk2-platforms treats that more laxly.

Thanks
Laszlo

>> +ErrorInstallNvVarStoreFormatted:
>>    gBS->UninstallMultipleProtocolInterfaces (&mFvbDevice->Handle,
>>           &gEfiDevicePathProtocolGuid,
>>           &gEfiFirmwareVolumeBlockProtocolGuid,
>> diff --git a/Silicon/Marvell/Drivers/Spi/MvFvbDxe/MvFvbDxe.inf b/Silicon/Marvell/Drivers/Spi/MvFvbDxe/MvFvbDxe.inf
>> index 117fe8b..fd3f2f7 100644
>> --- a/Silicon/Marvell/Drivers/Spi/MvFvbDxe/MvFvbDxe.inf
>> +++ b/Silicon/Marvell/Drivers/Spi/MvFvbDxe/MvFvbDxe.inf
>> @@ -63,6 +63,7 @@
>>    UefiRuntimeServicesTableLib
>>
>>  [Guids]
>> +  gEdkiiNvVarStoreFormattedGuid
>>    gEfiAuthenticatedVariableGuid
>>    gEfiEventVirtualAddressChangeGuid
>>    gEfiSystemNvDataFvGuid
>> @@ -84,8 +85,4 @@
>>    gMarvellTokenSpaceGuid.PcdSpiMemoryBase
>>
>>  [Depex]
>> -  #
>> -  # MvFvbDxe must be loaded before VariableRuntimeDxe in case empty
>> -  # flash needs populating with default values.
>> -  #
>> -  BEFORE gVariableRuntimeDxeFileGuid
>> +  gEfiCpuArchProtocolGuid
>> --
>> 2.7.4
>>
> _______________________________________________
> edk2-devel mailing list
> edk2-devel@lists.01.org
> https://lists.01.org/mailman/listinfo/edk2-devel
> 



  parent reply	other threads:[~2018-04-16 19:41 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-04-16  5:09 [platforms PATCH 0/2] Armada7k8k adjustments to EDK2 Marcin Wojtas
2018-04-16  5:09 ` [platforms PATCH 1/2] Marvell/Drivers: MvFvbDxe: Adjust to new dependencies Marcin Wojtas
2018-04-16  5:40   ` Ard Biesheuvel
2018-04-16  6:13     ` Marcin Wojtas
2018-04-16 19:41     ` Laszlo Ersek [this message]
2018-04-17  5:15       ` Marcin Wojtas
2018-04-17  5:32         ` Ard Biesheuvel
2018-04-17  6:04           ` Marcin Wojtas
2018-04-17  6:05             ` Ard Biesheuvel
2018-04-17  7:20         ` Laszlo Ersek
2018-04-16  5:09 ` [platforms PATCH 2/2] Marvell/Armada: RealTimeClockLib: Depend on gEfiCpuArchProtocolGuid Marcin Wojtas
2018-04-16  5:40   ` Ard Biesheuvel
2018-04-16 19:43   ` Laszlo Ersek

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=487cbdc8-72f7-e990-f53b-354c88370ba8@redhat.com \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox