From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by spool.mail.gandi.net (Postfix) with ESMTPS id DBEF8AC09EF for ; Thu, 22 Feb 2024 01:48:46 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=PkRravrIJt2RZdfOAzwKEEoNOR3vmQZ+VNbmTfs1gIc=; c=relaxed/simple; d=groups.io; h=Message-ID:Date:MIME-Version:User-Agent:Subject:To:Cc:References:From:In-Reply-To:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Type; s=20140610; t=1708566525; v=1; b=neDl+t9IamsnADSqBqGch01Wa5l87BmqkllZXussr5U0MCz7BX0BgdIvBRY9r0kkTzfme7zX 8vDnDn10iHV3Uv+gh7IrqtmaCsUxika4nyXF+PZ0ZDX6PhlhNWeNxBU7eYmivFTv8LyvXyhGMUH /9miBgAtRDsURk0tqUemMwug= X-Received: by 127.0.0.2 with SMTP id Y0M3YY7687511xp0bz4pHer2; Wed, 21 Feb 2024 17:48:45 -0800 X-Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by mx.groups.io with SMTP id smtpd.web10.3835.1708566524112201992 for ; Wed, 21 Feb 2024 17:48:44 -0800 X-Received: from loongson.cn (unknown [10.40.24.149]) by gateway (Coremail) with SMTP id _____8BxOPD5p9ZlYwUQAA--.41894S3; Thu, 22 Feb 2024 09:48:41 +0800 (CST) X-Received: from [10.40.24.149] (unknown [10.40.24.149]) by localhost.localdomain (Coremail) with SMTP id AQAAf8Bx7c74p9ZljGU+AA--.31033S3; Thu, 22 Feb 2024 09:48:40 +0800 (CST) Message-ID: <877dbcc8-9054-406f-8785-289a21ab992f@loongson.cn> Date: Thu, 22 Feb 2024 09:48:40 +0800 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [edk2-devel] [edk2-platforms 1/1] Platform/Loongson: loongarch supports parsing multi-chip flash To: devel@edk2.groups.io, lixianglai@loongson.cn Cc: Andrea Bolognani , Bibo Mao References: From: "Chao Li" In-Reply-To: X-CM-TRANSID: AQAAf8Bx7c74p9ZljGU+AA--.31033S3 X-CM-SenderInfo: xolfxt3r6o00pqjv00gofq/1tbiAQAOCGXVtGQCLQAws4 X-Coremail-Antispam: 1Uk129KBj93XoW3JFyUXr1xXF47Jr13KF13WrX_yoW7tw47pa 1UXFs3tws8WFW5tw4DZwnrWr17AFWakas8Jrs8Xr1DKwnrJ3Za9w4jy3WrGFsrXr97XF1j q3y8ZayDu3WqqwcCm3ZEXasCq-sJn29KB7ZKAUJUUUUU529EdanIXcx71UUUUU7KY7ZEXa sCq-sGcSsGvfJ3UbIjqfuFe4nvWSU5nxnvy29KBjDU0xBIdaVrnRJUUUymb4IE77IF4wAF F20E14v26r1j6r4UM7CY07I20VC2zVCF04k26cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r 1j6r18M28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2z4x0Y4vE2Ix0cI8IcVAF wI0_Jr0_JF4l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Jr0_Gr1l84ACjcxK6I8E87Iv67 AKxVW8JVWxJwA2z4x0Y4vEx4A2jsIEc7CjxVAFwI0_Gr0_Gr1UM2AIxVAIcxkEcVAq07x2 0xvEncxIr21l57IF6xkI12xvs2x26I8E6xACxx1lYx0E2Ix0cI8IcVAFwI0_Jr0_Jr4lYx 0Ex4A2jsIE14v26r1j6r4UMcvjeVCFs4IE7xkEbVWUJVW8JwACjcxG0xvEwIxGrwCjr7xv wVCIw2I0I7xG6c02F41l42xK82IYc2Ij64vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1lx2 IqxVAqx4xG67AKxVWUGVWUWwC20s026x8GjcxK67AKxVWUGVWUWwC2zVAF1VAY17CE14v2 6r126r1DMIIYrxkI7VAKI48JMIIF0xvE2Ix0cI8IcVAFwI0_Jr0_JF4lIxAIcVC0I7IYx2 IY6xkF7I0E14v26r1j6r4UMIIF0xvE42xK8VAvwI8IcIk0rVWUJVWUCwCI42IY6I8E87Iv 67AKxVWUJVW8JwCI42IY6I8E87Iv6xkF7I0E14v26r1j6r4UYxBIdaVFxhVjvjDU0xZFpf 9x07UGD73UUUUU= Precedence: Bulk List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,lichao@loongson.cn List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: eb0xsRsihRT60NAcbVcaAfaRx7686176AA= Content-Type: multipart/alternative; boundary="------------G06YpBVS7YSrVxxVUJkCdKl8" X-GND-Status: LEGIT Authentication-Results: spool.mail.gandi.net; dkim=pass header.d=groups.io header.s=20140610 header.b=neDl+t9I; dmarc=none; spf=pass (spool.mail.gandi.net: domain of bounce@groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce@groups.io --------------G06YpBVS7YSrVxxVUJkCdKl8 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: quoted-printable Reviewed-by: Chao Li 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 > Cc: Bibo Mao > Cc: Chao Li > Signed-off-by: Xianglai Li > --- > .../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/N= orFlashQemuLib.c b/Platform/Loongson/LoongArchQemuPkg/Library/NorFlashQemuL= ib/NorFlashQemuLib.c > index 2e0bf3cef0..1781c1c321 100644 > --- a/Platform/Loongson/LoongArchQemuPkg/Library/NorFlashQemuLib/NorFlash= QemuLib.c > +++ b/Platform/Loongson/LoongArchQemuPkg/Library/NorFlashQemuLib/NorFlash= QemuLib.c > @@ -84,34 +84,53 @@ VirtNorFlashPlatformGetDevices ( > return EFI_NOT_FOUND; > } > =20 > - Base =3D SwapBytes64 (ReadUnaligned64 ((VOID *)&Reg[0])); > - Size =3D SwapBytes64 (ReadUnaligned64 ((VOID *)&Reg[2])); > - > - mNorFlashDevices.DeviceBaseAddress =3D (UINTN)Base; > - mNorFlashDevices.RegionBaseAddress =3D (UINTN)Base; > - mNorFlashDevices.Size =3D (UINTN)Size; > - mNorFlashDevices.BlockSize =3D QEMU_NOR_BLOCK_SIZE; > - > - Status =3D PcdSet32S (PcdFlashNvStorageVariableBase, Base); > - ASSERT_EFI_ERROR (Status); > - > - /* > - * Base is the value of PcdFlashNvStorageVariableBase, > - * PcdFlashNvStorageFtwWorkingBase can be got by > - * PcdFlashNvStorageVariableBase + PcdFlashNvStorageVariableSize > - */ > - Base +=3D PcdGet32 (PcdFlashNvStorageVariableSize); > - Status =3D PcdSet32S (PcdFlashNvStorageFtwWorkingBase, Base); > - ASSERT_EFI_ERROR (Status); > - > - /* > - * Now,Base is the value of PcdFlashNvStorageFtwWorkingBase, > - * PcdFlashNvStorageFtwSpareBase can be got by > - * PcdFlashNvStorageFtwWorkingBase + PcdFlashNvStorageFtwWorkingSize= . > - */ > - Base +=3D PcdGet32 (PcdFlashNvStorageFtwWorkingSize); > - Status =3D PcdSet32S (PcdFlashNvStorageFtwSpareBase, Base); > - ASSERT_EFI_ERROR (Status); > + while (PropSize >=3D (4 * sizeof (UINT32))) { > + Base =3D SwapBytes64 (ReadUnaligned64 ((VOID *)&Reg[0])); > + Size =3D SwapBytes64 (ReadUnaligned64 ((VOID *)&Reg[2])); > + Reg +=3D 4; > + > + PropSize -=3D 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 (PcdOvmfFirmwareFdSi= ze) > Base) && > + ((Base + Size) > PcdGet32 (PcdOvmfFdBaseAddress))) > + { > + continue; > + } > + > + // > + //By default, the second available flash is stored as a non-volatile= variable. > + // > + mNorFlashDevices.DeviceBaseAddress =3D (UINTN)Base; > + mNorFlashDevices.RegionBaseAddress =3D (UINTN)Base; > + mNorFlashDevices.Size =3D (UINTN)Size; > + mNorFlashDevices.BlockSize =3D QEMU_NOR_BLOCK_SIZE; > + > + Status =3D PcdSet32S (PcdFlashNvStorageVariableBase, Base); > + ASSERT_EFI_ERROR (Status); > + > + /* > + * Base is the value of PcdFlashNvStorageVariableBase, > + * PcdFlashNvStorageFtwWorkingBase can be got by > + * PcdFlashNvStorageVariableBase + PcdFlashNvStorageVariableSize > + */ > + Base +=3D PcdGet32 (PcdFlashNvStorageVariableSize); > + Status =3D PcdSet32S (PcdFlashNvStorageFtwWorkingBase, Base); > + ASSERT_EFI_ERROR (Status); > + > + /* > + * Now,Base is the value of PcdFlashNvStorageFtwWorkingBase, > + * PcdFlashNvStorageFtwSpareBase can be got by > + * PcdFlashNvStorageFtwWorkingBase + PcdFlashNvStorageFtwWorkingSi= ze. > + */ > + Base +=3D PcdGet32 (PcdFlashNvStorageFtwWorkingSize); > + Status =3D PcdSet32S (PcdFlashNvStorageFtwSpareBase, Base); > + ASSERT_EFI_ERROR (Status); > + break; > + } > =20 > // > // UEFI takes ownership of the NOR flash, and exposes its functionali= ty > diff --git a/Platform/Loongson/LoongArchQemuPkg/Library/NorFlashQemuLib/N= orFlashQemuLib.inf b/Platform/Loongson/LoongArchQemuPkg/Library/NorFlashQem= uLib/NorFlashQemuLib.inf > index da05ca0898..a9b6c38783 100644 > --- a/Platform/Loongson/LoongArchQemuPkg/Library/NorFlashQemuLib/NorFlash= QemuLib.inf > +++ b/Platform/Loongson/LoongArchQemuPkg/Library/NorFlashQemuLib/NorFlash= QemuLib.inf > @@ -35,6 +35,8 @@ > gFdtClientProtocolGuid > =20 > [Pcd] > +gUefiOvmfPkgTokenSpaceGuid.PcdOvmfFdBaseAddress > +gUefiOvmfPkgTokenSpaceGuid.PcdOvmfFirmwareFdSize > gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableSize > gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareSize > gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingSize > diff --git a/Platform/Loongson/LoongArchQemuPkg/Loongson.fdf b/Platform/L= oongson/LoongArchQemuPkg/Loongson.fdf > index 8a759c0238..5af691c6af 100644 > --- a/Platform/Loongson/LoongArchQemuPkg/Loongson.fdf > +++ b/Platform/Loongson/LoongArchQemuPkg/Loongson.fdf > @@ -12,8 +12,8 @@ > =20 > #######################################################################= ############################## > [FD.QEMU_EFI] > -BaseAddress =3D $(FD_BASE_ADDRESS) > -Size =3D $(FD_SIZE) > +BaseAddress =3D $(FD_BASE_ADDRESS)|gUefiOvmfPkgTokenSpaceGuid.PcdOvmfF= dBaseAddress > +Size =3D $(FD_SIZE)|gUefiOvmfPkgTokenSpaceGuid.PcdOvmfFirmwareF= dSize > ErasePolarity =3D 1 > BlockSize =3D $(BLOCK_SIZE) > NumBlocks =3D $(FD_BLOCKS) -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- 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] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- --------------G06YpBVS7YSrVxxVUJkCdKl8 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable

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/Nor=
FlashQemuLib.c b/Platform/Loongson/LoongArchQemuPkg/Library/NorFlashQemuLib=
/NorFlashQemuLib.c
index 2e0bf3cef0..1781c1c321 100644
--- a/Platform/Loongson/LoongArchQemuPkg/Library/NorFlashQemuLib/NorFlashQe=
muLib.c
+++ b/Platform/Loongson/LoongArchQemuPkg/Library/NorFlashQemuLib/NorFlashQe=
muLib.c
@@ -84,34 +84,53 @@ VirtNorFlashPlatformGetDevices (
     return EFI_NOT_FOUND;
   }
=20
-  Base =3D SwapBytes64 (ReadUnaligned64 ((VOID *)&Reg[0]));
-  Size =3D SwapBytes64 (ReadUnaligned64 ((VOID *)&Reg[2]));
-
-  mNorFlashDevices.DeviceBaseAddress =3D (UINTN)Base;
-  mNorFlashDevices.RegionBaseAddress =3D (UINTN)Base;
-  mNorFlashDevices.Size              =3D (UINTN)Size;
-  mNorFlashDevices.BlockSize         =3D QEMU_NOR_BLOCK_SIZE;
-
-  Status =3D PcdSet32S (PcdFlashNvStorageVariableBase, Base);
-  ASSERT_EFI_ERROR (Status);
-
-  /*
-   * Base is the value of PcdFlashNvStorageVariableBase,
-   * PcdFlashNvStorageFtwWorkingBase can be got by
-   *   PcdFlashNvStorageVariableBase + PcdFlashNvStorageVariableSize
-   */
-  Base +=3D PcdGet32 (PcdFlashNvStorageVariableSize);
-  Status =3D PcdSet32S (PcdFlashNvStorageFtwWorkingBase, Base);
-  ASSERT_EFI_ERROR (Status);
-
-  /*
-   * Now,Base is the value of PcdFlashNvStorageFtwWorkingBase,
-   * PcdFlashNvStorageFtwSpareBase can be got by
-   *   PcdFlashNvStorageFtwWorkingBase + PcdFlashNvStorageFtwWorkingSize.
-   */
-  Base +=3D PcdGet32 (PcdFlashNvStorageFtwWorkingSize);
-  Status =3D PcdSet32S (PcdFlashNvStorageFtwSpareBase, Base);
-  ASSERT_EFI_ERROR (Status);
+  while (PropSize >=3D (4 * sizeof (UINT32))) {
+    Base =3D SwapBytes64 (ReadUnaligned64 ((VOID *)&Reg[0]));
+    Size =3D SwapBytes64 (ReadUnaligned64 ((VOID *)&Reg[2]));
+    Reg +=3D 4;
+
+    PropSize -=3D 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 v=
ariable.
+    //
+    mNorFlashDevices.DeviceBaseAddress =3D (UINTN)Base;
+    mNorFlashDevices.RegionBaseAddress =3D (UINTN)Base;
+    mNorFlashDevices.Size              =3D (UINTN)Size;
+    mNorFlashDevices.BlockSize         =3D QEMU_NOR_BLOCK_SIZE;
+
+    Status =3D PcdSet32S (PcdFlashNvStorageVariableBase, Base);
+    ASSERT_EFI_ERROR (Status);
+
+    /*
+     * Base is the value of PcdFlashNvStorageVariableBase,
+     * PcdFlashNvStorageFtwWorkingBase can be got by
+     *   PcdFlashNvStorageVariableBase + PcdFlashNvStorageVariableSize
+     */
+    Base +=3D PcdGet32 (PcdFlashNvStorageVariableSize);
+    Status =3D PcdSet32S (PcdFlashNvStorageFtwWorkingBase, Base);
+    ASSERT_EFI_ERROR (Status);
+
+    /*
+     * Now,Base is the value of PcdFlashNvStorageFtwWorkingBase,
+     * PcdFlashNvStorageFtwSpareBase can be got by
+     *   PcdFlashNvStorageFtwWorkingBase + PcdFlashNvStorageFtwWorkingSize=
.
+     */
+    Base +=3D PcdGet32 (PcdFlashNvStorageFtwWorkingSize);
+    Status =3D PcdSet32S (PcdFlashNvStorageFtwSpareBase, Base);
+    ASSERT_EFI_ERROR (Status);
+    break;
+  }
=20
   //
   // UEFI takes ownership of the NOR flash, and exposes its functionality
diff --git a/Platform/Loongson/LoongArchQemuPkg/Library/NorFlashQemuLib/Nor=
FlashQemuLib.inf b/Platform/Loongson/LoongArchQemuPkg/Library/NorFlashQemuL=
ib/NorFlashQemuLib.inf
index da05ca0898..a9b6c38783 100644
--- a/Platform/Loongson/LoongArchQemuPkg/Library/NorFlashQemuLib/NorFlashQe=
muLib.inf
+++ b/Platform/Loongson/LoongArchQemuPkg/Library/NorFlashQemuLib/NorFlashQe=
muLib.inf
@@ -35,6 +35,8 @@
   gFdtClientProtocolGuid
=20
 [Pcd]
+gUefiOvmfPkgTokenSpaceGuid.PcdOvmfFdBaseAddress
+gUefiOvmfPkgTokenSpaceGuid.PcdOvmfFirmwareFdSize
 gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableSize
 gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareSize
 gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingSize
diff --git a/Platform/Loongson/LoongArchQemuPkg/Loongson.fdf b/Platform/Loo=
ngson/LoongArchQemuPkg/Loongson.fdf
index 8a759c0238..5af691c6af 100644
--- a/Platform/Loongson/LoongArchQemuPkg/Loongson.fdf
+++ b/Platform/Loongson/LoongArchQemuPkg/Loongson.fdf
@@ -12,8 +12,8 @@
=20
 ##########################################################################=
###########################
 [FD.QEMU_EFI]
-BaseAddress   =3D $(FD_BASE_ADDRESS)
-Size          =3D $(FD_SIZE)
+BaseAddress   =3D $(FD_BASE_ADDRESS)|gUefiOvmfPkgTokenSpaceGuid.PcdOvmfFdB=
aseAddress
+Size          =3D $(FD_SIZE)|gUefiOvmfPkgTokenSpaceGuid.PcdOvmfFirmwareFdS=
ize
 ErasePolarity =3D 1
 BlockSize     =3D $(BLOCK_SIZE)
 NumBlocks     =3D $(FD_BLOCKS)
_._,_._,_

Groups.io Links:

=20 You receive all messages sent to this group. =20 =20

View/Reply Online (#115767) | =20 | Mute= This Topic | New Topic
Your Subscriptio= n | Contact Group Owner | Unsubscribe [rebecca@openfw.io]

_._,_._,_
--------------G06YpBVS7YSrVxxVUJkCdKl8--