public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "xianglai" <lixianglai@loongson.cn>
To: devel@edk2.groups.io
Cc: maobibo@loongson.cn
Subject: [edk2-platforms][PATCH V2 16/16] Platform/Loongson: Support for saving variables to flash.
Date: Fri, 25 Mar 2022 10:51:13 +0800	[thread overview]
Message-ID: <868cc62825c2aca1ebf04931b97b3f1206ac97de.1648171285.git.lixianglai@loongson.cn> (raw)
In-Reply-To: <cover.1648171285.git.lixianglai@loongson.cn>

Added the function of saving non-volatile variables.

Signed-off-by: xianglai li <lixianglai@loongson.cn>
---
 Platform/Loongson/LoongArchQemuPkg/Loongson.dec  |  6 ++++++
 Platform/Loongson/LoongArchQemuPkg/Loongson.dsc  |  2 +-
 Platform/Loongson/LoongArchQemuPkg/Loongson.fdf  | 16 +++++++++++++++-
 .../Loongson/LoongArchQemuPkg/Loongson.fdf.inc   | 11 +++++++++++
 .../Loongson/LoongArchQemuPkg/VarStore.fdf.inc   | 10 +++++-----
 5 files changed, 38 insertions(+), 7 deletions(-)

diff --git a/Platform/Loongson/LoongArchQemuPkg/Loongson.dec b/Platform/Loongson/LoongArchQemuPkg/Loongson.dec
index 508a770a22..c3e523b39b 100644
--- a/Platform/Loongson/LoongArchQemuPkg/Loongson.dec
+++ b/Platform/Loongson/LoongArchQemuPkg/Loongson.dec
@@ -32,6 +32,8 @@
 [Protocols]
 
 [PcdsFixedAtBuild, PcdsDynamic]
+  gLoongArchQemuPkgTokenSpaceGuid.PcdFlashFdBase|0x0|UINT64|0
+  gLoongArchQemuPkgTokenSpaceGuid.PcdFlashBlockSize|0x0|UINT32|2
   gLoongArchQemuPkgTokenSpaceGuid.PcdFlashPeiFvBase|0x0|UINT64|0x00000003
   gLoongArchQemuPkgTokenSpaceGuid.PcdFlashPeiFvSize|0x0|UINT32|0x00000004
   gLoongArchQemuPkgTokenSpaceGuid.PcdFlashDxeFvOffset|0x0|UINT64|0x00000007
@@ -50,6 +52,10 @@
   gLoongArchQemuPkgTokenSpaceGuid.PcdSecPeiTempRamSize|0|UINT32|0x0000001d
   gLoongArchQemuPkgTokenSpaceGuid.PcdUefiRamTop|0x0|UINT64|0x0000001e
   gLoongArchQemuPkgTokenSpaceGuid.PcdRamRegionsBottom|0x0|UINT64|0x00000022
+  gLoongArchQemuPkgTokenSpaceGuid.PcdOvmfFlashNvStorageVariableBase|0x0|UINT64|0x00000024
+  gLoongArchQemuPkgTokenSpaceGuid.PcdAllVarSize|0x0|UINT32|0x00000025
+  gLoongArchQemuPkgTokenSpaceGuid.PcdOvmfFlashNvStorageFtwSpareBase|0x0|UINT64|0x00000026
+  gLoongArchQemuPkgTokenSpaceGuid.PcdOvmfFlashNvStorageFtwWorkingBase|0x0|UINT64|0x00000027
   gLoongArchQemuPkgTokenSpaceGuid.PcdFlashSecFvBase|0x0|UINT64|0x00000028
   gLoongArchQemuPkgTokenSpaceGuid.PcdFlashSecFvSize|0x0|UINT32|0x00000029
 
diff --git a/Platform/Loongson/LoongArchQemuPkg/Loongson.dsc b/Platform/Loongson/LoongArchQemuPkg/Loongson.dsc
index 4707b6dc9b..adda94c755 100644
--- a/Platform/Loongson/LoongArchQemuPkg/Loongson.dsc
+++ b/Platform/Loongson/LoongArchQemuPkg/Loongson.dsc
@@ -437,7 +437,7 @@
   #
   # Variable
   #
-#  Platform/Loongson/LoongArchQemuPkg/Drivers/QemuFlashFvbServicesRuntimeDxe/FvbServicesRuntimeDxe.inf
+  Platform/Loongson/LoongArchQemuPkg/Drivers/QemuFlashFvbServicesRuntimeDxe/FvbServicesRuntimeDxe.inf
   OvmfPkg/EmuVariableFvbRuntimeDxe/Fvb.inf {
     <LibraryClasses>
       PlatformFvbLib|OvmfPkg/Library/EmuVariableFvbLib/EmuVariableFvbLib.inf
diff --git a/Platform/Loongson/LoongArchQemuPkg/Loongson.fdf b/Platform/Loongson/LoongArchQemuPkg/Loongson.fdf
index 7084c90c56..5a92f724a7 100644
--- a/Platform/Loongson/LoongArchQemuPkg/Loongson.fdf
+++ b/Platform/Loongson/LoongArchQemuPkg/Loongson.fdf
@@ -31,6 +31,19 @@ gLoongArchQemuPkgTokenSpaceGuid.PcdFlashDxeFvBase|gLoongArchQemuPkgTokenSpaceGui
 FV = FVMAIN_COMPACT
 
 !include VarStore.fdf.inc
+
+#####################################################################################################
+[FD.QEMU_EFI_VARS]
+BaseAddress   = $(VARIABLE_BASE_ADDRESS)
+Size          = $(VAR_ALL_SIZE)
+ErasePolarity = 1
+BlockSize     = $(BLOCK_SIZE)
+NumBlocks     = $(VAR_ALL_BLOCKS)
+
+DEFINE VARIABLE_OFFSET = 0
+!include VarStore.fdf.inc
+DEFINE VARIABLE_OFFSET = 0x003a0000
+
 #####################################################################################################
 [FV.SECFV]
 FvNameGuid         = 587d4265-5e71-41da-9c35-4258551f1e22
@@ -87,6 +100,7 @@ INF  MdeModulePkg/Core/Pei/PeiMain.inf
 INF  MdeModulePkg/Universal/PCD/Pei/Pcd.inf
 INF  MdeModulePkg/Core/DxeIplPeim/DxeIpl.inf
 INF  Platform/Loongson/LoongArchQemuPkg/PlatformPei/PlatformPei.inf
+
 #####################################################################################################
 [FV.DXEFV]
 FvNameGuid         = 5d19a5b3-130f-459b-a292-9270a9e6bc62
@@ -135,7 +149,7 @@ INF  MdeModulePkg/Universal/CapsuleRuntimeDxe/CapsuleRuntimeDxe.inf
 #
 # Variable
 #
-#INF  Platform/Loongson/LoongArchQemuPkg/Drivers/QemuFlashFvbServicesRuntimeDxe/FvbServicesRuntimeDxe.inf
+INF  Platform/Loongson/LoongArchQemuPkg/Drivers/QemuFlashFvbServicesRuntimeDxe/FvbServicesRuntimeDxe.inf
 INF  OvmfPkg/EmuVariableFvbRuntimeDxe/Fvb.inf
 INF  MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteDxe.inf
 INF  MdeModulePkg/Universal/Variable/RuntimeDxe/VariableRuntimeDxe.inf
diff --git a/Platform/Loongson/LoongArchQemuPkg/Loongson.fdf.inc b/Platform/Loongson/LoongArchQemuPkg/Loongson.fdf.inc
index 964d69ed44..4b926a85ff 100644
--- a/Platform/Loongson/LoongArchQemuPkg/Loongson.fdf.inc
+++ b/Platform/Loongson/LoongArchQemuPkg/Loongson.fdf.inc
@@ -34,6 +34,7 @@ DEFINE VAR_ALL_SIZE               = 0x60000
 
 ############################################################################
 #Set Var Flash layout
+DEFINE VARIABLE_BASE_ADDRESS      = 0x1c3a0000
 DEFINE VARIABLE_SIZE              = 0x00010000
 DEFINE VAR_ALL_BLOCKS             = 0x60
 
@@ -53,11 +54,21 @@ DEFINE EVENT_LOG_OFFSET           = $(FWTWORKING_OFFSET) + $(FWTWORKING_SIZE)
 DEFINE EVENT_LOG_SIZE             = 0x8000
 
 # Set Variable
+SET gLoongArchQemuPkgTokenSpaceGuid.PcdFlashFdBase = $(FD_BASE_ADDRESS)
+
+SET gLoongArchQemuPkgTokenSpaceGuid.PcdOvmfFlashNvStorageVariableBase = $(FD_BASE_ADDRESS) + $(VARIABLE_OFFSET)
+SET gLoongArchQemuPkgTokenSpaceGuid.PcdAllVarSize = $(VAR_ALL_SIZE)
+
+SET gLoongArchQemuPkgTokenSpaceGuid.PcdFlashBlockSize = $(BLOCK_SIZE)
 SET gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase64 = 0
 SET gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableSize = $(VARIABLE_SIZE)
 
 # Set FtwSpare
+SET gLoongArchQemuPkgTokenSpaceGuid.PcdOvmfFlashNvStorageFtwSpareBase  =  $(FD_BASE_ADDRESS) + $(SPARE_OFFSET)
+SET gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareBase64 = 0
 SET gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareSize = $(SPARE_SIZE)
 
 # Set FtwWorking
+SET gLoongArchQemuPkgTokenSpaceGuid.PcdOvmfFlashNvStorageFtwWorkingBase  =  $(FD_BASE_ADDRESS) + $(SPARE_OFFSET)  + $(SPARE_SIZE)
+SET gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingBase64 = 0
 SET gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingSize = $(FWTWORKING_SIZE)
diff --git a/Platform/Loongson/LoongArchQemuPkg/VarStore.fdf.inc b/Platform/Loongson/LoongArchQemuPkg/VarStore.fdf.inc
index 625fa23543..a4e0158cf8 100644
--- a/Platform/Loongson/LoongArchQemuPkg/VarStore.fdf.inc
+++ b/Platform/Loongson/LoongArchQemuPkg/VarStore.fdf.inc
@@ -38,16 +38,16 @@ DATA = {
   # FORMATTED: 0x5A #HEALTHY: 0xFE #Reserved: UINT16 #Reserved1: UINT32
   0x5a, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
 }
-$(RESERVE1_OFFSET)|$(RESERVE1_SIZE)
+$(VARIABLE_OFFSET) + $(VARIABLE_SIZE)|$(RESERVE1_SIZE)
 #NV_RESERVE1_STORE
 
-$(RESERVE2_OFFSET)|$(RESERVE2_SIZE)
+$(VARIABLE_OFFSET) + $(VARIABLE_SIZE) + $(RESERVE1_SIZE)|$(RESERVE2_SIZE)
 #NV_RESERVE2_STORE
 
-$(SPARE_OFFSET)|$(SPARE_SIZE)
+$(VARIABLE_OFFSET) + $(VARIABLE_SIZE) + $(RESERVE1_SIZE) + $(RESERVE2_SIZE)|$(SPARE_SIZE)
 #NV_FTW_SPARE
 
-$(FWTWORKING_OFFSET)|$(FWTWORKING_SIZE)
+$(VARIABLE_OFFSET) + $(VARIABLE_SIZE) + $(RESERVE1_SIZE) + $(RESERVE2_SIZE) + $(SPARE_SIZE)|$(FWTWORKING_SIZE)
 #NV_FTW_WORKING
 DATA = {
   # EFI_FAULT_TOLERANT_WORKING_BLOCK_HEADER->Signature = gEdkiiWorkingBlockSignatureGuid =
@@ -60,5 +60,5 @@ DATA = {
   0xe0, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
 }
 
-$(EVENT_LOG_OFFSET)|$(EVENT_LOG_SIZE)
+$(VARIABLE_OFFSET) + $(VARIABLE_SIZE) + $(RESERVE1_SIZE) + $(RESERVE2_SIZE) + $(SPARE_SIZE) + $(FWTWORKING_SIZE)|$(EVENT_LOG_SIZE)
 #NV_EVENT_LOG
-- 
2.31.1


  parent reply	other threads:[~2022-03-25  2:51 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-25  2:16 [edk2-platforms][PATCH V2 00/16] Platform: Add Loongson support xianglai
2022-03-25  2:16 ` [edk2-platforms][PATCH V2 01/16] Platform/Loongson: Add Serial Port library xianglai
2022-03-25  2:16 ` [edk2-platforms][PATCH V2 03/16] Platform/Loongson: Add PeiServicesTablePointerLib xianglai
2022-03-25  2:16 ` [edk2-platforms][PATCH V2 04/16] Platform/Loongson: Add QemuFwCfgLib xianglai
2022-03-25  2:16 ` [edk2-platforms][PATCH V2 05/16] Platform/Loongson: Add MmuLib xianglai
2022-03-25  2:16 ` [edk2-platforms][PATCH V2 06/16] Platform/Loongson: Add StableTimerLib xianglai
2022-03-25  2:16 ` [edk2-platforms][PATCH V2 07/16] Platform/Loongson: Support PEI phase xianglai
2022-03-25  2:16 ` [edk2-platforms][PATCH V2 08/16] Platform/Loongson: Add CPU DXE driver xianglai
2022-03-25  2:16 ` [edk2-platforms][PATCH V2 09/16] Platform/Loongson: Add PciCpuIoDxe driver xianglai
2022-03-25  2:16 ` [edk2-platforms][PATCH V2 10/16] Platform/Loongson: Add timer Dxe driver xianglai
2022-03-25  2:16 ` [edk2-platforms][PATCH V2 11/16] Platform/Loongson: Add RealTime Clock lib xianglai
2022-03-25  2:16 ` [edk2-platforms][PATCH V2 12/16] Platform/Loongson: Add Platform Boot Manager Lib xianglai
2022-03-25  2:16 ` [edk2-platforms][PATCH V2 13/16] Platform/Loongson: Add Reset System Lib xianglai
2022-03-25  2:16 ` [edk2-platforms][PATCH V2 14/16] Platform/Loongson: Support Dxe xianglai
2022-03-25  2:16 ` [edk2-platforms][PATCH V2 15/16] Platform/Loongson: Add QemuFlashFvbServicesRuntimeDxe driver xianglai
2022-03-25  2:51 ` xianglai [this message]
2022-03-25  3:37 ` [edk2-platforms][PATCH V2 02/16] Platform/Loongson: Support SEC And Add Readme.md xianglai
  -- strict thread matches above, loose matches on Subject: below --
2022-09-16  3:36 [edk2-platforms][PATCH V2 00/16] Platform: Add Loongson support xianglai
2022-09-16  3:36 ` [edk2-platforms][PATCH V2 16/16] Platform/Loongson: Support for saving variables to flash xianglai

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=868cc62825c2aca1ebf04931b97b3f1206ac97de.1648171285.git.lixianglai@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