/** @file\r
\r
- Copyright (c) 2014, Linaro Ltd. All rights reserved.<BR>\r
+ Copyright (c) 2014-2018, Linaro Ltd. All rights reserved.<BR>\r
\r
This program and the accompanying materials\r
are licensed and made available under the terms and conditions of the BSD License\r
\r
**/\r
\r
+#include <Library/BaseLib.h>\r
+#include <Library/DebugLib.h>\r
#include <Library/NorFlashPlatformLib.h>\r
+#include <Library/UefiBootServicesTableLib.h>\r
+\r
+#include <Protocol/FdtClient.h>\r
\r
#define QEMU_NOR_BLOCK_SIZE SIZE_256KB\r
-#define QEMU_NOR0_BASE 0x0\r
-#define QEMU_NOR0_SIZE SIZE_64MB\r
-#define QEMU_NOR1_BASE 0x04000000\r
-#define QEMU_NOR1_SIZE SIZE_64MB\r
+\r
+#define MAX_FLASH_BANKS 4\r
\r
EFI_STATUS\r
NorFlashPlatformInitialization (\r
return EFI_SUCCESS;\r
}\r
\r
-NOR_FLASH_DESCRIPTION mNorFlashDevices[] = {\r
- {\r
- QEMU_NOR0_BASE,\r
- QEMU_NOR0_BASE,\r
- QEMU_NOR0_SIZE,\r
- QEMU_NOR_BLOCK_SIZE,\r
- {0xF9B94AE2, 0x8BA6, 0x409B, {0x9D, 0x56, 0xB9, 0xB4, 0x17, 0xF5, 0x3C, 0xB3}}\r
- }, {\r
- QEMU_NOR1_BASE,\r
- QEMU_NOR1_BASE,\r
- QEMU_NOR1_SIZE,\r
- QEMU_NOR_BLOCK_SIZE,\r
- {0x8047DB4B, 0x7E9C, 0x4C0C, {0x8E, 0xBC, 0xDF, 0xBB, 0xAA, 0xCA, 0xCE, 0x8F}}\r
- }\r
-};\r
+NOR_FLASH_DESCRIPTION mNorFlashDevices[MAX_FLASH_BANKS];\r
\r
EFI_STATUS\r
NorFlashPlatformGetDevices (\r
OUT UINT32 *Count\r
)\r
{\r
+ FDT_CLIENT_PROTOCOL *FdtClient;\r
+ INT32 Node;\r
+ EFI_STATUS Status;\r
+ EFI_STATUS FindNodeStatus;\r
+ CONST UINT32 *Reg;\r
+ UINT32 PropSize;\r
+ UINT32 Num;\r
+ UINT64 Base;\r
+ UINT64 Size;\r
+\r
+ Status = gBS->LocateProtocol (&gFdtClientProtocolGuid, NULL,\r
+ (VOID **)&FdtClient);\r
+ ASSERT_EFI_ERROR (Status);\r
+\r
+ Num = 0;\r
+ for (FindNodeStatus = FdtClient->FindCompatibleNode (FdtClient,\r
+ "cfi-flash", &Node);\r
+ !EFI_ERROR (FindNodeStatus) && Num < MAX_FLASH_BANKS;\r
+ FindNodeStatus = FdtClient->FindNextCompatibleNode (FdtClient,\r
+ "cfi-flash", Node, &Node)) {\r
+\r
+ Status = FdtClient->GetNodeProperty (FdtClient, Node, "reg",\r
+ (CONST VOID **)&Reg, &PropSize);\r
+ if (EFI_ERROR (Status)) {\r
+ DEBUG ((DEBUG_ERROR, "%a: GetNodeProperty () failed (Status == %r)\n",\r
+ __FUNCTION__, Status));\r
+ continue;\r
+ }\r
+\r
+ ASSERT ((PropSize % (4 * sizeof (UINT32))) == 0);\r
+\r
+ while (PropSize >= (4 * sizeof (UINT32)) && Num < MAX_FLASH_BANKS) {\r
+ Base = SwapBytes64 (ReadUnaligned64 ((VOID *)&Reg[0]));\r
+ Size = SwapBytes64 (ReadUnaligned64 ((VOID *)&Reg[2]));\r
+ Reg += 4;\r
+\r
+ mNorFlashDevices[Num].DeviceBaseAddress = (UINTN)Base;\r
+ mNorFlashDevices[Num].RegionBaseAddress = (UINTN)Base;\r
+ mNorFlashDevices[Num].Size = (UINTN)Size;\r
+ mNorFlashDevices[Num].BlockSize = QEMU_NOR_BLOCK_SIZE;\r
+ Num++;\r
+\r
+ PropSize -= 4 * sizeof (UINT32);\r
+ }\r
+ }\r
+\r
*NorFlashDescriptions = mNorFlashDevices;\r
- *Count = ARRAY_SIZE (mNorFlashDevices);\r
+ *Count = Num;\r
+\r
return EFI_SUCCESS;\r
}\r