* [edk2-devel] [edk2-platforms 0/1] loongarch supports parsing multi-chip flash @ 2024-02-19 2:03 xianglai 2024-02-19 2:03 ` [edk2-devel] [edk2-platforms 1/1] Platform/Loongson: " xianglai 0 siblings, 1 reply; 3+ messages in thread From: xianglai @ 2024-02-19 2:03 UTC (permalink / raw) To: devel; +Cc: Andrea Bolognani, Bibo Mao, Chao Li 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> Xianglai Li (1): Platform/Loongson: loongarch supports parsing multi-chip flash .../Library/NorFlashQemuLib/NorFlashQemuLib.c | 75 ++++++++++++------- .../NorFlashQemuLib/NorFlashQemuLib.inf | 2 + .../Loongson/LoongArchQemuPkg/Loongson.fdf | 4 +- 3 files changed, 51 insertions(+), 30 deletions(-) -- 2.39.1 -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#115573): https://edk2.groups.io/g/devel/message/115573 Mute This Topic: https://groups.io/mt/104439665/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io] -=-=-=-=-=-=-=-=-=-=-=- ^ permalink raw reply [flat|nested] 3+ messages in thread
* [edk2-devel] [edk2-platforms 1/1] Platform/Loongson: loongarch supports parsing multi-chip flash 2024-02-19 2:03 [edk2-devel] [edk2-platforms 0/1] loongarch supports parsing multi-chip flash xianglai @ 2024-02-19 2:03 ` xianglai 2024-02-22 1:48 ` Chao Li 0 siblings, 1 reply; 3+ messages in thread From: xianglai @ 2024-02-19 2:03 UTC (permalink / raw) To: devel; +Cc: Andrea Bolognani, Bibo Mao, Chao Li 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) -- 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] -=-=-=-=-=-=-=-=-=-=-=- ^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [edk2-devel] [edk2-platforms 1/1] Platform/Loongson: loongarch supports parsing multi-chip flash 2024-02-19 2:03 ` [edk2-devel] [edk2-platforms 1/1] Platform/Loongson: " xianglai @ 2024-02-22 1:48 ` Chao Li 0 siblings, 0 replies; 3+ messages in thread From: Chao Li @ 2024-02-22 1:48 UTC (permalink / raw) To: devel, lixianglai; +Cc: Andrea Bolognani, Bibo Mao [-- 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 --] ^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-02-22 1:48 UTC | newest] Thread overview: 3+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 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 is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox