]> git.proxmox.com Git - mirror_edk2.git/commitdiff
Vlv2TbltDevicePkg/FlashDeviceLib: Add DXE flash device lib.
authorJiewen Yao <jiewen.yao@intel.com>
Wed, 21 Sep 2016 03:48:11 +0000 (11:48 +0800)
committerJiewen Yao <jiewen.yao@intel.com>
Tue, 8 Nov 2016 14:49:47 +0000 (22:49 +0800)
Previous FlashDeviceLib only supports DxeRuntime and Smm.
It cannot be linked with SystemBiosUpdateDxe driver.

So we separate DxeRuntime related code into a standalone file,
and create FlashDeviceLibDxe.inf.

Cc: David Wei <david.wei@intel.com>
Cc: Feng Tian <feng.tian@intel.com>
Cc: Star Zeng <star.zeng@intel.com>
Cc: Michael D Kinney <michael.d.kinney@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
Cc: Chao Zhang <chao.b.zhang@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jiewen Yao <jiewen.yao@intel.com>
Reviewed-by: David Wei <david.wei@intel.com>
Vlv2TbltDevicePkg/Library/FlashDeviceLib/FlashDeviceLib.c
Vlv2TbltDevicePkg/Library/FlashDeviceLib/FlashDeviceLib.inf
Vlv2TbltDevicePkg/Library/FlashDeviceLib/FlashDeviceLibDxe.c [new file with mode: 0644]
Vlv2TbltDevicePkg/Library/FlashDeviceLib/FlashDeviceLibDxe.inf [new file with mode: 0644]
Vlv2TbltDevicePkg/Library/FlashDeviceLib/FlashDeviceLibDxeRuntimeSmm.c [new file with mode: 0644]
Vlv2TbltDevicePkg/Library/FlashDeviceLib/SpiChipDefinitions.h

index afb12c90fbf5857bb3d7e3e69a5f0ea57b51dd26..8e6e5b47289bc49873192e93022e44e742d5ba78 100644 (file)
@@ -1,15 +1,15 @@
 /** @file\r
 \r
-  Copyright (c) 2004  - 2014, Intel Corporation. All rights reserved.<BR>\r
-                                                                                   \r\r
-  This program and the accompanying materials are licensed and made available under\r\r
-  the terms and conditions of the BSD License that accompanies this distribution.  \r\r
-  The full text of the license may be found at                                     \r\r
-  http://opensource.org/licenses/bsd-license.php.                                  \r\r
-                                                                                   \r\r
-  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,            \r\r
-  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.    \r\r
-                                                                                   \r\r
+  Copyright (c) 2004  - 2016, Intel Corporation. All rights reserved.<BR>\r
+\r
+  This program and the accompanying materials are licensed and made available under\r
+  the terms and conditions of the BSD License that accompanies this distribution.\r
+  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php.\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
 \r
 \r
 **/\r
 #include <Library/FlashDeviceLib.h>\r
 #include <Library/DebugLib.h>\r
 #include <Library/BaseLib.h>\r
-#include <Library/UefiBootServicesTableLib.h>\r
-#include <Library/UefiRuntimeServicesTableLib.h>\r
 #include <Library/BaseMemoryLib.h>\r
-#include <Library/UefiRuntimeLib.h>\r
-#include <Protocol/SmmBase2.h>\r
 #include <Guid/EventGroup.h>\r
-#include "SpiChipDefinitions.h"\r
+#include <Library/SpiFlash.H>\r
 \r
+#define FLASH_SIZE  0x400000\r
+\r
+#define FLASH_DEVICE_BASE_ADDRESS (0xFFFFFFFF-FLASH_SIZE+1)\r
 UINTN FlashDeviceBase = FLASH_DEVICE_BASE_ADDRESS;\r
 \r
 EFI_SPI_PROTOCOL *mSpiProtocol = NULL;\r
@@ -320,148 +319,3 @@ LibFvbFlashDeviceBlockLock (
   return Status;\r
 }\r
 \r
-VOID\r
-EFIAPI\r
-LibFvbFlashDeviceVirtualAddressChangeNotifyEvent (\r
-  IN EFI_EVENT        Event,\r
-  IN VOID             *Context\r
-  )\r
-{\r
-  gRT->ConvertPointer (0, (VOID **) &mSpiProtocol);\r
-  gRT->ConvertPointer (0, (VOID **) &FlashDeviceBase);\r
-}\r
-\r
-\r
-/**\r
-  The library constructuor.\r
-\r
-  The function does the necessary initialization work for this library\r
-  instance. Please put all initialization works in it.\r
-\r
-  @param[in]  ImageHandle       The firmware allocated handle for the UEFI image.\r
-  @param[in]  SystemTable       A pointer to the EFI system table.\r
-\r
-  @retval     EFI_SUCCESS       The function always return EFI_SUCCESS for now.\r
-                                It will ASSERT on error for debug version.\r
-  @retval     EFI_ERROR         Please reference LocateProtocol for error code details.\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-LibFvbFlashDeviceSupportInit (\r
-  IN EFI_HANDLE         ImageHandle,\r
-  IN EFI_SYSTEM_TABLE   *SystemTable\r
-  )\r
-{\r
-  EFI_STATUS Status;\r
-  EFI_EVENT  Event;\r
-  UINT8                         SfId[3];\r
-  UINT8                         FlashIndex;\r
-  UINT8                         SpiReadError;\r
-  UINT8                         SpiNotMatchError;\r
-  EFI_SMM_BASE2_PROTOCOL       *SmmBase;\r
-  BOOLEAN                       InSmm;\r
-\r
-  SpiReadError     = 0x00;\r
-  SpiNotMatchError = 0x00;\r
-\r
-  InSmm = FALSE;\r
-  Status = gBS->LocateProtocol (\r
-                  &gEfiSmmBase2ProtocolGuid,\r
-                  NULL,\r
-                  (void **)&SmmBase\r
-                  );\r
-  if (!EFI_ERROR(Status)) {\r
-    Status = SmmBase->InSmm(SmmBase, &InSmm);\r
-    if (EFI_ERROR(Status)) {\r
-      InSmm = FALSE;\r
-    }\r
-  }\r
-\r
-  if (!InSmm) {\r
-    Status = gBS->LocateProtocol (\r
-                  &gEfiSpiProtocolGuid,\r
-                  NULL,\r
-                  (VOID **)&mSpiProtocol\r
-                  );\r
-    ASSERT_EFI_ERROR (Status);\r
-\r
-    Status = gBS->CreateEventEx (\r
-                  EVT_NOTIFY_SIGNAL,\r
-                  TPL_NOTIFY,\r
-                  LibFvbFlashDeviceVirtualAddressChangeNotifyEvent,\r
-                  NULL,\r
-                  &gEfiEventVirtualAddressChangeGuid,\r
-                  &Event\r
-                  );\r
-    ASSERT_EFI_ERROR (Status);\r
-  } else {\r
-    Status = gBS->LocateProtocol (\r
-                    &gEfiSmmSpiProtocolGuid,\r
-                    NULL,\r
-                    (VOID **)&mSpiProtocol\r
-                    );\r
-    ASSERT_EFI_ERROR (Status);\r
-  }\r
-\r
-\r
-  for (FlashIndex = EnumSpiFlashW25Q64; FlashIndex < EnumSpiFlashMax; FlashIndex++) {\r
-    Status = mSpiProtocol->Init (mSpiProtocol, &(mInitTable[FlashIndex]));\r
-    if (!EFI_ERROR (Status)) {\r
-      //\r
-      // Read Vendor/Device IDs to check if the driver supports the Serial Flash device.\r
-      //\r
-      Status = mSpiProtocol->Execute (\r
-                               mSpiProtocol,\r
-                               SPI_READ_ID,\r
-                               SPI_WREN,\r
-                               TRUE,\r
-                               FALSE,\r
-                               FALSE,\r
-                               0,\r
-                               3,\r
-                               SfId,\r
-                               EnumSpiRegionAll\r
-                               );\r
-      if (!EFI_ERROR (Status)) {\r
-        if ((SfId[0] == mInitTable[FlashIndex].VendorId)  &&\r
-            (SfId[1] == mInitTable[FlashIndex].DeviceId0) &&\r
-            (SfId[2] == mInitTable[FlashIndex].DeviceId1)) {\r
-            //\r
-            // Found a matching SPI device, FlashIndex now contains flash device.\r
-            //\r
-            DEBUG ((EFI_D_ERROR, "OK - Found SPI Flash Type in SPI Flash Driver, Device Type ID 0 = 0x%02x!\n", mInitTable[FlashIndex].DeviceId0));\r
-            DEBUG ((EFI_D_ERROR, "Device Type ID 1 = 0x%02x!\n", mInitTable[FlashIndex].DeviceId1));\r
-\r
-            if (mInitTable[FlashIndex].BiosStartOffset == (UINTN) (-1)) {\r
-              DEBUG ((EFI_D_ERROR, "ERROR - The size of BIOS image is bigger than SPI Flash device!\n"));\r
-              CpuDeadLoop ();\r
-            }\r
-            break;\r
-        } else {\r
-          SpiNotMatchError++;\r
-        }\r
-      } else {\r
-        SpiReadError++;\r
-      }\r
-    }\r
-  }\r
-\r
-  DEBUG ((EFI_D_ERROR, "SPI flash chip VID = 0x%X, DID0 = 0x%X, DID1 = 0x%X\n", SfId[0], SfId[1], SfId[2]));\r
-\r
-  if (FlashIndex < EnumSpiFlashMax)  {\r
-    return EFI_SUCCESS;\r
-  } else {\r
-  if (SpiReadError != 0) {\r
-      DEBUG ((EFI_D_ERROR, "ERROR - SPI Read ID execution failed! Error Count = %d\n", SpiReadError));\r
-   }    \r
-    else {\r
-      if (SpiNotMatchError != 0) {\r
-        DEBUG ((EFI_D_ERROR, "ERROR - No supported SPI flash chip found! Error Count = %d\n", SpiNotMatchError));\r
-        DEBUG ((EFI_D_ERROR, "SPI flash chip VID = 0x%X, DID0 = 0x%X, DID1 = 0x%X\n", SfId[0], SfId[1], SfId[2]));\r
-      }\r
-    }\r
-    return EFI_UNSUPPORTED;\r
-  }\r
-}\r
-\r
index 423490ecc1fb59e8762f81bf0126d876d15e22e3..955b2479f6975282ffdbb38bdbc884633d69a65c 100644 (file)
@@ -1,27 +1,27 @@
 #\r
 #\r
-# Copyright (c)  1999  - 2014, Intel Corporation. All rights reserved\r
-#                                                                                  \r\r
-# This program and the accompanying materials are licensed and made available under\r\r
-# the terms and conditions of the BSD License that accompanies this distribution.  \r\r
-# The full text of the license may be found at                                     \r\r
-# http://opensource.org/licenses/bsd-license.php.                                  \r\r
-#                                                                                  \r\r
-# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,            \r\r
-# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.    \r\r
-#                                                                                  \r\r
+# Copyright (c)  1999  - 2016, Intel Corporation. All rights reserved\r
+#\r
+# This program and the accompanying materials are licensed and made available under\r
+# the terms and conditions of the BSD License that accompanies this distribution.\r
+# The full text of the license may be found at\r
+# http://opensource.org/licenses/bsd-license.php.\r
+#\r
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+#\r
 #\r
 #\r
 \r
 \r
 [Defines]\r
   INF_VERSION                    = 0x00010005\r
-  BASE_NAME                      = FlashDeviceLib\r
+  BASE_NAME                      = FlashDeviceLibRuntimeSmm\r
   FILE_GUID                      = E38A1C3C-928C-4bf7-B6C1-7F0EF163FAA5\r
   MODULE_TYPE                    = DXE_DRIVER\r
   VERSION_STRING                 = 1.0\r
   LIBRARY_CLASS                  = FlashDeviceLib | DXE_SMM_DRIVER DXE_RUNTIME_DRIVER\r
-  CONSTRUCTOR                               = LibFvbFlashDeviceSupportInit\r
+  CONSTRUCTOR                    = LibFvbFlashDeviceSupportInit\r
 \r
 \r
 #\r
@@ -32,6 +32,7 @@
 \r
 [Sources]\r
   FlashDeviceLib.c\r
+  FlashDeviceLibDxeRuntimeSmm.c\r
 \r
 \r
 [Packages]\r
@@ -43,6 +44,9 @@
 [LibraryClasses]\r
   DebugLib\r
 \r
+[Guids]\r
+  gEfiEventVirtualAddressChangeGuid\r
+\r
 [Protocols]\r
   gEfiSpiProtocolGuid\r
   gEfiSmmSpiProtocolGuid\r
diff --git a/Vlv2TbltDevicePkg/Library/FlashDeviceLib/FlashDeviceLibDxe.c b/Vlv2TbltDevicePkg/Library/FlashDeviceLib/FlashDeviceLibDxe.c
new file mode 100644 (file)
index 0000000..1601099
--- /dev/null
@@ -0,0 +1,62 @@
+/** @file\r
+\r
+  Copyright (c) 2004  - 2016, Intel Corporation. All rights reserved.<BR>\r
+\r
+  This program and the accompanying materials are licensed and made available under\r
+  the terms and conditions of the BSD License that accompanies this distribution.\r
+  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php.\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+\r
+\r
+**/\r
+\r
+#include <PiDxe.h>\r
+\r
+#include <Library/FlashDeviceLib.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/BaseLib.h>\r
+#include <Library/UefiBootServicesTableLib.h>\r
+#include <Library/BaseMemoryLib.h>\r
+#include "SpiChipDefinitions.h"\r
+\r
+extern UINTN FlashDeviceBase;\r
+\r
+extern EFI_SPI_PROTOCOL *mSpiProtocol;\r
+\r
+/**\r
+  The library constructuor.\r
+\r
+  The function does the necessary initialization work for this library\r
+  instance. Please put all initialization works in it.\r
+\r
+  @param[in]  ImageHandle       The firmware allocated handle for the UEFI image.\r
+  @param[in]  SystemTable       A pointer to the EFI system table.\r
+\r
+  @retval     EFI_SUCCESS       The function always return EFI_SUCCESS for now.\r
+                                It will ASSERT on error for debug version.\r
+  @retval     EFI_ERROR         Please reference LocateProtocol for error code details.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+LibFvbFlashDeviceSupportInit (\r
+  IN EFI_HANDLE         ImageHandle,\r
+  IN EFI_SYSTEM_TABLE   *SystemTable\r
+  )\r
+{\r
+  EFI_STATUS Status;\r
+  Status = gBS->LocateProtocol (\r
+                  &gEfiSpiProtocolGuid,\r
+                  NULL,\r
+                  (VOID **)&mSpiProtocol\r
+                  );\r
+  ASSERT_EFI_ERROR (Status);\r
+  // There is no need to call Init, because Runtime or SMM FVB already does that.\r
+  DEBUG((EFI_D_ERROR, "LibFvbFlashDeviceSupportInit - no init\n"));\r
+  return EFI_SUCCESS;\r
+}\r
+\r
diff --git a/Vlv2TbltDevicePkg/Library/FlashDeviceLib/FlashDeviceLibDxe.inf b/Vlv2TbltDevicePkg/Library/FlashDeviceLib/FlashDeviceLibDxe.inf
new file mode 100644 (file)
index 0000000..1260d0a
--- /dev/null
@@ -0,0 +1,49 @@
+#\r
+#\r
+# Copyright (c)  1999  - 2016, Intel Corporation. All rights reserved\r
+#\r
+# This program and the accompanying materials are licensed and made available under\r
+# the terms and conditions of the BSD License that accompanies this distribution.\r
+# The full text of the license may be found at\r
+# http://opensource.org/licenses/bsd-license.php.\r
+#\r
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+#\r
+#\r
+#\r
+\r
+\r
+[Defines]\r
+  INF_VERSION                    = 0x00010005\r
+  BASE_NAME                      = FlashDeviceLibDxe\r
+  FILE_GUID                      = F0D7222F-FD43-4A5D-B8BF-A259C87AE3B2\r
+  MODULE_TYPE                    = DXE_DRIVER\r
+  VERSION_STRING                 = 1.0\r
+  LIBRARY_CLASS                  = FlashDeviceLib | DXE_DRIVER\r
+  CONSTRUCTOR                    = LibFvbFlashDeviceSupportInit\r
+\r
+\r
+#\r
+# The following information is for reference only and not required by the build tools.\r
+#\r
+#  VALID_ARCHITECTURES           = IA32 X64\r
+#\r
+\r
+[Sources]\r
+  FlashDeviceLib.c\r
+  FlashDeviceLibDxe.c\r
+\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+  MdeModulePkg/MdeModulePkg.dec\r
+  Vlv2TbltDevicePkg/PlatformPkg.dec\r
+  Vlv2DeviceRefCodePkg/Vlv2DeviceRefCodePkg.dec\r
+\r
+[LibraryClasses]\r
+  DebugLib\r
+\r
+[Protocols]\r
+  gEfiSpiProtocolGuid\r
+\r
diff --git a/Vlv2TbltDevicePkg/Library/FlashDeviceLib/FlashDeviceLibDxeRuntimeSmm.c b/Vlv2TbltDevicePkg/Library/FlashDeviceLib/FlashDeviceLibDxeRuntimeSmm.c
new file mode 100644 (file)
index 0000000..842f0ce
--- /dev/null
@@ -0,0 +1,179 @@
+/** @file\r
+\r
+  Copyright (c) 2004  - 2016, Intel Corporation. All rights reserved.<BR>\r
+\r
+  This program and the accompanying materials are licensed and made available under\r
+  the terms and conditions of the BSD License that accompanies this distribution.\r
+  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php.\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+\r
+\r
+**/\r
+\r
+#include <PiDxe.h>\r
+\r
+#include <Library/FlashDeviceLib.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/BaseLib.h>\r
+#include <Library/UefiBootServicesTableLib.h>\r
+#include <Library/UefiRuntimeServicesTableLib.h>\r
+#include <Library/BaseMemoryLib.h>\r
+#include <Library/UefiRuntimeLib.h>\r
+#include <Protocol/SmmBase2.h>\r
+#include <Guid/EventGroup.h>\r
+#include "SpiChipDefinitions.h"\r
+\r
+extern UINTN FlashDeviceBase;\r
+\r
+extern EFI_SPI_PROTOCOL *mSpiProtocol;\r
+\r
+VOID\r
+EFIAPI\r
+LibFvbFlashDeviceVirtualAddressChangeNotifyEvent (\r
+  IN EFI_EVENT        Event,\r
+  IN VOID             *Context\r
+  )\r
+{\r
+  gRT->ConvertPointer (0, (VOID **) &mSpiProtocol);\r
+  gRT->ConvertPointer (0, (VOID **) &FlashDeviceBase);\r
+}\r
+\r
+\r
+/**\r
+  The library constructuor.\r
+\r
+  The function does the necessary initialization work for this library\r
+  instance. Please put all initialization works in it.\r
+\r
+  @param[in]  ImageHandle       The firmware allocated handle for the UEFI image.\r
+  @param[in]  SystemTable       A pointer to the EFI system table.\r
+\r
+  @retval     EFI_SUCCESS       The function always return EFI_SUCCESS for now.\r
+                                It will ASSERT on error for debug version.\r
+  @retval     EFI_ERROR         Please reference LocateProtocol for error code details.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+LibFvbFlashDeviceSupportInit (\r
+  IN EFI_HANDLE         ImageHandle,\r
+  IN EFI_SYSTEM_TABLE   *SystemTable\r
+  )\r
+{\r
+  EFI_STATUS Status;\r
+  EFI_EVENT  Event;\r
+  UINT8                         SfId[3];\r
+  UINT8                         FlashIndex;\r
+  UINT8                         SpiReadError;\r
+  UINT8                         SpiNotMatchError;\r
+  EFI_SMM_BASE2_PROTOCOL       *SmmBase;\r
+  BOOLEAN                       InSmm;\r
+\r
+  SpiReadError     = 0x00;\r
+  SpiNotMatchError = 0x00;\r
+\r
+  InSmm = FALSE;\r
+  Status = gBS->LocateProtocol (\r
+                  &gEfiSmmBase2ProtocolGuid,\r
+                  NULL,\r
+                  (void **)&SmmBase\r
+                  );\r
+  if (!EFI_ERROR(Status)) {\r
+    Status = SmmBase->InSmm(SmmBase, &InSmm);\r
+    if (EFI_ERROR(Status)) {\r
+      InSmm = FALSE;\r
+    }\r
+  }\r
+\r
+  if (!InSmm) {\r
+    Status = gBS->LocateProtocol (\r
+                  &gEfiSpiProtocolGuid,\r
+                  NULL,\r
+                  (VOID **)&mSpiProtocol\r
+                  );\r
+    ASSERT_EFI_ERROR (Status);\r
+\r
+    Status = gBS->CreateEventEx (\r
+                  EVT_NOTIFY_SIGNAL,\r
+                  TPL_NOTIFY,\r
+                  LibFvbFlashDeviceVirtualAddressChangeNotifyEvent,\r
+                  NULL,\r
+                  &gEfiEventVirtualAddressChangeGuid,\r
+                  &Event\r
+                  );\r
+    ASSERT_EFI_ERROR (Status);\r
+\r
+  } else {\r
+    Status = gBS->LocateProtocol (\r
+                    &gEfiSmmSpiProtocolGuid,\r
+                    NULL,\r
+                    (VOID **)&mSpiProtocol\r
+                    );\r
+    ASSERT_EFI_ERROR (Status);\r
+  }\r
+\r
+\r
+  for (FlashIndex = EnumSpiFlashW25Q64; FlashIndex < EnumSpiFlashMax; FlashIndex++) {\r
+    Status = mSpiProtocol->Init (mSpiProtocol, &(mInitTable[FlashIndex]));\r
+    if (!EFI_ERROR (Status)) {\r
+      //\r
+      // Read Vendor/Device IDs to check if the driver supports the Serial Flash device.\r
+      //\r
+      Status = mSpiProtocol->Execute (\r
+                               mSpiProtocol,\r
+                               SPI_READ_ID,\r
+                               SPI_WREN,\r
+                               TRUE,\r
+                               FALSE,\r
+                               FALSE,\r
+                               0,\r
+                               3,\r
+                               SfId,\r
+                               EnumSpiRegionAll\r
+                               );\r
+      if (!EFI_ERROR (Status)) {\r
+        if ((SfId[0] == mInitTable[FlashIndex].VendorId)  &&\r
+            (SfId[1] == mInitTable[FlashIndex].DeviceId0) &&\r
+            (SfId[2] == mInitTable[FlashIndex].DeviceId1)) {\r
+            //\r
+            // Found a matching SPI device, FlashIndex now contains flash device.\r
+            //\r
+            DEBUG ((EFI_D_ERROR, "OK - Found SPI Flash Type in SPI Flash Driver, Device Type ID 0 = 0x%02x!\n", mInitTable[FlashIndex].DeviceId0));\r
+            DEBUG ((EFI_D_ERROR, "Device Type ID 1 = 0x%02x!\n", mInitTable[FlashIndex].DeviceId1));\r
+\r
+            if (mInitTable[FlashIndex].BiosStartOffset == (UINTN) (-1)) {\r
+              DEBUG ((EFI_D_ERROR, "ERROR - The size of BIOS image is bigger than SPI Flash device!\n"));\r
+              CpuDeadLoop ();\r
+            }\r
+            break;\r
+        } else {\r
+          SpiNotMatchError++;\r
+        }\r
+      } else {\r
+        SpiReadError++;\r
+      }\r
+    }\r
+  }\r
+\r
+  DEBUG ((EFI_D_ERROR, "SPI flash chip VID = 0x%X, DID0 = 0x%X, DID1 = 0x%X\n", SfId[0], SfId[1], SfId[2]));\r
+\r
+  if (FlashIndex < EnumSpiFlashMax)  {\r
+    return EFI_SUCCESS;\r
+  } else {\r
+  if (SpiReadError != 0) {\r
+      DEBUG ((EFI_D_ERROR, "ERROR - SPI Read ID execution failed! Error Count = %d\n", SpiReadError));\r
+   }\r
+    else {\r
+      if (SpiNotMatchError != 0) {\r
+        DEBUG ((EFI_D_ERROR, "ERROR - No supported SPI flash chip found! Error Count = %d\n", SpiNotMatchError));\r
+        DEBUG ((EFI_D_ERROR, "SPI flash chip VID = 0x%X, DID0 = 0x%X, DID1 = 0x%X\n", SfId[0], SfId[1], SfId[2]));\r
+      }\r
+    }\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+}\r
+\r
index 15bd1e025405e9e262b99b6552bb6f3c859f0c5f..fdf742c1baf7beb39e1d5480bab4e0d689eab0d4 100644 (file)
@@ -1,23 +1,22 @@
-/*++\r
+/** @file\r
+\r
+  Copyright (c) 2004  - 2016, Intel Corporation. All rights reserved.<BR>\r
+\r
+  This program and the accompanying materials are licensed and made available under\r
+  the terms and conditions of the BSD License that accompanies this distribution.\r
+  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php.\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
 \r
-  Copyright (c) 2004  - 2014, Intel Corporation. All rights reserved.<BR>\r
-                                                                                   \r\r
-  This program and the accompanying materials are licensed and made available under\r\r
-  the terms and conditions of the BSD License that accompanies this distribution.  \r\r
-  The full text of the license may be found at                                     \r\r
-  http://opensource.org/licenses/bsd-license.php.                                  \r\r
-                                                                                   \r\r
-  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,            \r\r
-  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.    \r\r
-                                                                                   \r\r
 \r
 \r
 **/\r
 \r
 #include <Library/SpiFlash.H>\r
 \r
-#define FLASH_SIZE  0x300000\r
-#define FLASH_DEVICE_BASE_ADDRESS (0xFFFFFFFF-FLASH_SIZE+1)\r
+#define FLASH_SIZE  0x400000\r
 \r
 //\r
 // Serial Flash device initialization data table provided to the\r
@@ -838,3 +837,4 @@ SPI_INIT_TABLE  mInitTable[] = {
   FLASH_SIZE\r
   }\r
 };\r
+\r