public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Chao Li" <lichao@loongson.cn>
To: devel@edk2.groups.io, lixianglai@loongson.cn
Cc: Andrea Bolognani <abologna@redhat.com>, Bibo Mao <maobibo@loongson.cn>
Subject: Re: [edk2-devel] [edk2-platforms 1/1] Platform/Loongson: loongarch supports parsing multi-chip flash
Date: Thu, 22 Feb 2024 09:48:40 +0800	[thread overview]
Message-ID: <877dbcc8-9054-406f-8785-289a21ab992f@loongson.cn> (raw)
In-Reply-To: <c0ec89b6d621a0eb0ebd51c416de69fce2f0863f.1708307996.git.lixianglai@loongson.cn>

[-- Attachment #1: Type: text/plain, Size: 6511 bytes --]

Reviewed-by: Chao Li <lichao@loongson.cn>


Thanks,
Chao
On 2024/2/19 10:03, xianglai wrote:
> The current implementation of loongarch NorFlashQemuLib is to
> parse fdt and think that the first flash address resolved to
> the NVRAM space, with the evolution of qemu code, loongarch
> uses the first flash to store UEFI code and the second flash
> as NVRAM space, so NorFlashQemuLib needs to be able to parse
> multiple flash base addresses. By default, the first piece of
> flash other than UEFI code is considered as NVRAM space.
>
> Cc: Andrea Bolognani<abologna@redhat.com>
> Cc: Bibo Mao<maobibo@loongson.cn>
> Cc: Chao Li<lichao@loongson.cn>
> Signed-off-by: Xianglai Li<lixianglai@loongson.cn>
> ---
>   .../Library/NorFlashQemuLib/NorFlashQemuLib.c | 75 ++++++++++++-------
>   .../NorFlashQemuLib/NorFlashQemuLib.inf       |  2 +
>   .../Loongson/LoongArchQemuPkg/Loongson.fdf    |  4 +-
>   3 files changed, 51 insertions(+), 30 deletions(-)
>
> diff --git a/Platform/Loongson/LoongArchQemuPkg/Library/NorFlashQemuLib/NorFlashQemuLib.c b/Platform/Loongson/LoongArchQemuPkg/Library/NorFlashQemuLib/NorFlashQemuLib.c
> index 2e0bf3cef0..1781c1c321 100644
> --- a/Platform/Loongson/LoongArchQemuPkg/Library/NorFlashQemuLib/NorFlashQemuLib.c
> +++ b/Platform/Loongson/LoongArchQemuPkg/Library/NorFlashQemuLib/NorFlashQemuLib.c
> @@ -84,34 +84,53 @@ VirtNorFlashPlatformGetDevices (
>       return EFI_NOT_FOUND;
>     }
>   
> -  Base = SwapBytes64 (ReadUnaligned64 ((VOID *)&Reg[0]));
> -  Size = SwapBytes64 (ReadUnaligned64 ((VOID *)&Reg[2]));
> -
> -  mNorFlashDevices.DeviceBaseAddress = (UINTN)Base;
> -  mNorFlashDevices.RegionBaseAddress = (UINTN)Base;
> -  mNorFlashDevices.Size              = (UINTN)Size;
> -  mNorFlashDevices.BlockSize         = QEMU_NOR_BLOCK_SIZE;
> -
> -  Status = PcdSet32S (PcdFlashNvStorageVariableBase, Base);
> -  ASSERT_EFI_ERROR (Status);
> -
> -  /*
> -   * Base is the value of PcdFlashNvStorageVariableBase,
> -   * PcdFlashNvStorageFtwWorkingBase can be got by
> -   *   PcdFlashNvStorageVariableBase + PcdFlashNvStorageVariableSize
> -   */
> -  Base += PcdGet32 (PcdFlashNvStorageVariableSize);
> -  Status = PcdSet32S (PcdFlashNvStorageFtwWorkingBase, Base);
> -  ASSERT_EFI_ERROR (Status);
> -
> -  /*
> -   * Now,Base is the value of PcdFlashNvStorageFtwWorkingBase,
> -   * PcdFlashNvStorageFtwSpareBase can be got by
> -   *   PcdFlashNvStorageFtwWorkingBase + PcdFlashNvStorageFtwWorkingSize.
> -   */
> -  Base += PcdGet32 (PcdFlashNvStorageFtwWorkingSize);
> -  Status = PcdSet32S (PcdFlashNvStorageFtwSpareBase, Base);
> -  ASSERT_EFI_ERROR (Status);
> +  while (PropSize >= (4 * sizeof (UINT32))) {
> +    Base = SwapBytes64 (ReadUnaligned64 ((VOID *)&Reg[0]));
> +    Size = SwapBytes64 (ReadUnaligned64 ((VOID *)&Reg[2]));
> +    Reg += 4;
> +
> +    PropSize -= 4 * sizeof (UINT32);
> +
> +    //
> +    // Disregard any flash devices that overlap with the primary FV.
> +    // The firmware is not updatable from inside the guest anyway.
> +    //
> +    if ((PcdGet32 (PcdOvmfFdBaseAddress) + PcdGet32 (PcdOvmfFirmwareFdSize) > Base) &&
> +        ((Base + Size) > PcdGet32 (PcdOvmfFdBaseAddress)))
> +    {
> +      continue;
> +    }
> +
> +    //
> +    //By default, the second available flash is stored as a non-volatile variable.
> +    //
> +    mNorFlashDevices.DeviceBaseAddress = (UINTN)Base;
> +    mNorFlashDevices.RegionBaseAddress = (UINTN)Base;
> +    mNorFlashDevices.Size              = (UINTN)Size;
> +    mNorFlashDevices.BlockSize         = QEMU_NOR_BLOCK_SIZE;
> +
> +    Status = PcdSet32S (PcdFlashNvStorageVariableBase, Base);
> +    ASSERT_EFI_ERROR (Status);
> +
> +    /*
> +     * Base is the value of PcdFlashNvStorageVariableBase,
> +     * PcdFlashNvStorageFtwWorkingBase can be got by
> +     *   PcdFlashNvStorageVariableBase + PcdFlashNvStorageVariableSize
> +     */
> +    Base += PcdGet32 (PcdFlashNvStorageVariableSize);
> +    Status = PcdSet32S (PcdFlashNvStorageFtwWorkingBase, Base);
> +    ASSERT_EFI_ERROR (Status);
> +
> +    /*
> +     * Now,Base is the value of PcdFlashNvStorageFtwWorkingBase,
> +     * PcdFlashNvStorageFtwSpareBase can be got by
> +     *   PcdFlashNvStorageFtwWorkingBase + PcdFlashNvStorageFtwWorkingSize.
> +     */
> +    Base += PcdGet32 (PcdFlashNvStorageFtwWorkingSize);
> +    Status = PcdSet32S (PcdFlashNvStorageFtwSpareBase, Base);
> +    ASSERT_EFI_ERROR (Status);
> +    break;
> +  }
>   
>     //
>     // UEFI takes ownership of the NOR flash, and exposes its functionality
> diff --git a/Platform/Loongson/LoongArchQemuPkg/Library/NorFlashQemuLib/NorFlashQemuLib.inf b/Platform/Loongson/LoongArchQemuPkg/Library/NorFlashQemuLib/NorFlashQemuLib.inf
> index da05ca0898..a9b6c38783 100644
> --- a/Platform/Loongson/LoongArchQemuPkg/Library/NorFlashQemuLib/NorFlashQemuLib.inf
> +++ b/Platform/Loongson/LoongArchQemuPkg/Library/NorFlashQemuLib/NorFlashQemuLib.inf
> @@ -35,6 +35,8 @@
>     gFdtClientProtocolGuid
>   
>   [Pcd]
> +gUefiOvmfPkgTokenSpaceGuid.PcdOvmfFdBaseAddress
> +gUefiOvmfPkgTokenSpaceGuid.PcdOvmfFirmwareFdSize
>   gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableSize
>   gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareSize
>   gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingSize
> diff --git a/Platform/Loongson/LoongArchQemuPkg/Loongson.fdf b/Platform/Loongson/LoongArchQemuPkg/Loongson.fdf
> index 8a759c0238..5af691c6af 100644
> --- a/Platform/Loongson/LoongArchQemuPkg/Loongson.fdf
> +++ b/Platform/Loongson/LoongArchQemuPkg/Loongson.fdf
> @@ -12,8 +12,8 @@
>   
>   #####################################################################################################
>   [FD.QEMU_EFI]
> -BaseAddress   = $(FD_BASE_ADDRESS)
> -Size          = $(FD_SIZE)
> +BaseAddress   = $(FD_BASE_ADDRESS)|gUefiOvmfPkgTokenSpaceGuid.PcdOvmfFdBaseAddress
> +Size          = $(FD_SIZE)|gUefiOvmfPkgTokenSpaceGuid.PcdOvmfFirmwareFdSize
>   ErasePolarity = 1
>   BlockSize     = $(BLOCK_SIZE)
>   NumBlocks     = $(FD_BLOCKS)


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#115767): https://edk2.groups.io/g/devel/message/115767
Mute This Topic: https://groups.io/mt/104439666/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-



[-- Attachment #2: Type: text/html, Size: 7771 bytes --]

      reply	other threads:[~2024-02-22  1:48 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-19  2:03 [edk2-devel] [edk2-platforms 0/1] loongarch supports parsing multi-chip flash xianglai
2024-02-19  2:03 ` [edk2-devel] [edk2-platforms 1/1] Platform/Loongson: " xianglai
2024-02-22  1:48   ` Chao Li [this message]

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=877dbcc8-9054-406f-8785-289a21ab992f@loongson.cn \
    --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