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 08AA87803CC for ; Mon, 19 Feb 2024 02:03:45 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=BzpbpEoXJedFpGsjz7OO87AH8eNxdFljg9RwtsDbcys=; c=relaxed/simple; d=groups.io; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References:MIME-Version:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Transfer-Encoding; s=20140610; t=1708308224; v=1; b=HvsQ0gQ0Owkhktz8HVm229K5JGBh5P83yDEjEnWL+1btLgxDYcBFs++uHqstWGeJ8tvV8MbR n1pumGFtJZ7gsRcmtEriXAZ8ObZSSnJ3UxqQUt7jn6IzByOVnBYiATu03/r+md4fsDzYVm0WErx 3LxZnt0KOsDPk8KzOk/7gMig= X-Received: by 127.0.0.2 with SMTP id NQT8YY7687511xWDTkfrLumR; Sun, 18 Feb 2024 18:03:44 -0800 X-Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by mx.groups.io with SMTP id smtpd.web10.32580.1708308223384793000 for ; Sun, 18 Feb 2024 18:03:43 -0800 X-Received: from loongson.cn (unknown [10.2.5.185]) by gateway (Coremail) with SMTP id _____8BxuvD8ttJlvy8OAA--.38022S3; Mon, 19 Feb 2024 10:03:40 +0800 (CST) X-Received: from localhost.localdomain (unknown [10.2.5.185]) by localhost.localdomain (Coremail) with SMTP id AQAAf8AxTs37ttJl+bY7AA--.19916S3; Mon, 19 Feb 2024 10:03:39 +0800 (CST) From: "xianglai" To: devel@edk2.groups.io Cc: Andrea Bolognani , Bibo Mao , Chao Li Subject: [edk2-devel] [edk2-platforms 1/1] Platform/Loongson: loongarch supports parsing multi-chip flash Date: Mon, 19 Feb 2024 10:03:37 +0800 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-CM-TRANSID: AQAAf8AxTs37ttJl+bY7AA--.19916S3 X-CM-SenderInfo: 5ol0xt5qjotxo6or00hjvr0hdfq/ X-Coremail-Antispam: 1Uk129KBjDUn29KB7ZKAUJUUUUU529EdanIXcx71UUUUU7KY7 ZEXasCq-sGcSsGvfJ3UbIjqfuFe4nvWSU5nxnvy29KBjDU0xBIdaVrnUUvcSsGvfC2Kfnx nUUI43ZEXa7xR_UUUUUUUUU== 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,lixianglai@loongson.cn List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: WHCuUwScza5KGW3P09i3jW5ex7686176AA= Content-Transfer-Encoding: quoted-printable X-GND-Status: LEGIT Authentication-Results: spool.mail.gandi.net; dkim=pass header.d=groups.io header.s=20140610 header.b=HvsQ0gQ0; 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 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/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;=0D }=0D =0D - Base =3D SwapBytes64 (ReadUnaligned64 ((VOID *)&Reg[0]));=0D - Size =3D SwapBytes64 (ReadUnaligned64 ((VOID *)&Reg[2]));=0D -=0D - mNorFlashDevices.DeviceBaseAddress =3D (UINTN)Base;=0D - mNorFlashDevices.RegionBaseAddress =3D (UINTN)Base;=0D - mNorFlashDevices.Size =3D (UINTN)Size;=0D - mNorFlashDevices.BlockSize =3D QEMU_NOR_BLOCK_SIZE;=0D -=0D - Status =3D PcdSet32S (PcdFlashNvStorageVariableBase, Base);=0D - ASSERT_EFI_ERROR (Status);=0D -=0D - /*=0D - * Base is the value of PcdFlashNvStorageVariableBase,=0D - * PcdFlashNvStorageFtwWorkingBase can be got by=0D - * PcdFlashNvStorageVariableBase + PcdFlashNvStorageVariableSize=0D - */=0D - Base +=3D PcdGet32 (PcdFlashNvStorageVariableSize);=0D - Status =3D PcdSet32S (PcdFlashNvStorageFtwWorkingBase, Base);=0D - ASSERT_EFI_ERROR (Status);=0D -=0D - /*=0D - * Now,Base is the value of PcdFlashNvStorageFtwWorkingBase,=0D - * PcdFlashNvStorageFtwSpareBase can be got by=0D - * PcdFlashNvStorageFtwWorkingBase + PcdFlashNvStorageFtwWorkingSize.= =0D - */=0D - Base +=3D PcdGet32 (PcdFlashNvStorageFtwWorkingSize);=0D - Status =3D PcdSet32S (PcdFlashNvStorageFtwSpareBase, Base);=0D - ASSERT_EFI_ERROR (Status);=0D + while (PropSize >=3D (4 * sizeof (UINT32))) {=0D + Base =3D SwapBytes64 (ReadUnaligned64 ((VOID *)&Reg[0]));=0D + Size =3D SwapBytes64 (ReadUnaligned64 ((VOID *)&Reg[2]));=0D + Reg +=3D 4;=0D +=0D + PropSize -=3D 4 * sizeof (UINT32);=0D +=0D + //=0D + // Disregard any flash devices that overlap with the primary FV.=0D + // The firmware is not updatable from inside the guest anyway.=0D + //=0D + if ((PcdGet32 (PcdOvmfFdBaseAddress) + PcdGet32 (PcdOvmfFirmwareFdSize= ) > Base) &&=0D + ((Base + Size) > PcdGet32 (PcdOvmfFdBaseAddress)))=0D + {=0D + continue;=0D + }=0D +=0D + //=0D + //By default, the second available flash is stored as a non-volatile v= ariable.=0D + //=0D + mNorFlashDevices.DeviceBaseAddress =3D (UINTN)Base;=0D + mNorFlashDevices.RegionBaseAddress =3D (UINTN)Base;=0D + mNorFlashDevices.Size =3D (UINTN)Size;=0D + mNorFlashDevices.BlockSize =3D QEMU_NOR_BLOCK_SIZE;=0D +=0D + Status =3D PcdSet32S (PcdFlashNvStorageVariableBase, Base);=0D + ASSERT_EFI_ERROR (Status);=0D +=0D + /*=0D + * Base is the value of PcdFlashNvStorageVariableBase,=0D + * PcdFlashNvStorageFtwWorkingBase can be got by=0D + * PcdFlashNvStorageVariableBase + PcdFlashNvStorageVariableSize=0D + */=0D + Base +=3D PcdGet32 (PcdFlashNvStorageVariableSize);=0D + Status =3D PcdSet32S (PcdFlashNvStorageFtwWorkingBase, Base);=0D + ASSERT_EFI_ERROR (Status);=0D +=0D + /*=0D + * Now,Base is the value of PcdFlashNvStorageFtwWorkingBase,=0D + * PcdFlashNvStorageFtwSpareBase can be got by=0D + * PcdFlashNvStorageFtwWorkingBase + PcdFlashNvStorageFtwWorkingSize= .=0D + */=0D + Base +=3D PcdGet32 (PcdFlashNvStorageFtwWorkingSize);=0D + Status =3D PcdSet32S (PcdFlashNvStorageFtwSpareBase, Base);=0D + ASSERT_EFI_ERROR (Status);=0D + break;=0D + }=0D =0D //=0D // UEFI takes ownership of the NOR flash, and exposes its functionality= =0D 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=0D =0D [Pcd]=0D +gUefiOvmfPkgTokenSpaceGuid.PcdOvmfFdBaseAddress=0D +gUefiOvmfPkgTokenSpaceGuid.PcdOvmfFirmwareFdSize=0D gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableSize=0D gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareSize=0D gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingSize=0D 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 @@ =0D ##########################################################################= ###########################=0D [FD.QEMU_EFI]=0D -BaseAddress =3D $(FD_BASE_ADDRESS)=0D -Size =3D $(FD_SIZE)=0D +BaseAddress =3D $(FD_BASE_ADDRESS)|gUefiOvmfPkgTokenSpaceGuid.PcdOvmfFdB= aseAddress=0D +Size =3D $(FD_SIZE)|gUefiOvmfPkgTokenSpaceGuid.PcdOvmfFirmwareFdS= ize=0D ErasePolarity =3D 1=0D BlockSize =3D $(BLOCK_SIZE)=0D NumBlocks =3D $(FD_BLOCKS)=0D --=20 2.39.1 -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#115574): https://edk2.groups.io/g/devel/message/115574 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] -=-=-=-=-=-=-=-=-=-=-=-