mirror of
				https://git.proxmox.com/git/mirror_edk2
				synced 2025-10-31 17:09:09 +00:00 
			
		
		
		
	 5e27deed43
			
		
	
	
		5e27deed43
		
	
	
	
	
		
			
			The primary FV contains the firmware boot image, which is not runtime updatable in our case. So exposing it to the NOR flash driver is undesirable, since it may attempt to modify the NOR flash contents. It is also rather pointless, since we don't keep anything there that we care to expose. (the SEC and PEI phase modules are not executable from DXE context, and the contents of the embedded DXE phase FV are exposed by the DXE core directly via the FVB2 protocol) So let's disregard the NOR flash block that covers the primary FV. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org> Reviewed-by: Laszlo Ersek <lersek@redhat.com>
		
			
				
	
	
		
			102 lines
		
	
	
		
			3.1 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
			
		
		
	
	
			102 lines
		
	
	
		
			3.1 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
| /** @file
 | |
| 
 | |
|  Copyright (c) 2014-2018, Linaro Ltd. All rights reserved.<BR>
 | |
| 
 | |
|  This program and the accompanying materials
 | |
|  are licensed and made available under the terms and conditions of the BSD License
 | |
|  which accompanies this distribution.  The full text of the license may be found at
 | |
|  http://opensource.org/licenses/bsd-license.php
 | |
| 
 | |
|  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
 | |
|  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 | |
| 
 | |
|  **/
 | |
| 
 | |
| #include <Library/BaseLib.h>
 | |
| #include <Library/DebugLib.h>
 | |
| #include <Library/NorFlashPlatformLib.h>
 | |
| #include <Library/UefiBootServicesTableLib.h>
 | |
| 
 | |
| #include <Protocol/FdtClient.h>
 | |
| 
 | |
| #define QEMU_NOR_BLOCK_SIZE    SIZE_256KB
 | |
| 
 | |
| #define MAX_FLASH_BANKS        4
 | |
| 
 | |
| EFI_STATUS
 | |
| NorFlashPlatformInitialization (
 | |
|   VOID
 | |
|   )
 | |
| {
 | |
|   return EFI_SUCCESS;
 | |
| }
 | |
| 
 | |
| NOR_FLASH_DESCRIPTION mNorFlashDevices[MAX_FLASH_BANKS];
 | |
| 
 | |
| EFI_STATUS
 | |
| NorFlashPlatformGetDevices (
 | |
|   OUT NOR_FLASH_DESCRIPTION   **NorFlashDescriptions,
 | |
|   OUT UINT32                  *Count
 | |
|   )
 | |
| {
 | |
|   FDT_CLIENT_PROTOCOL         *FdtClient;
 | |
|   INT32                       Node;
 | |
|   EFI_STATUS                  Status;
 | |
|   EFI_STATUS                  FindNodeStatus;
 | |
|   CONST UINT32                *Reg;
 | |
|   UINT32                      PropSize;
 | |
|   UINT32                      Num;
 | |
|   UINT64                      Base;
 | |
|   UINT64                      Size;
 | |
| 
 | |
|   Status = gBS->LocateProtocol (&gFdtClientProtocolGuid, NULL,
 | |
|                   (VOID **)&FdtClient);
 | |
|   ASSERT_EFI_ERROR (Status);
 | |
| 
 | |
|   Num = 0;
 | |
|   for (FindNodeStatus = FdtClient->FindCompatibleNode (FdtClient,
 | |
|                                      "cfi-flash", &Node);
 | |
|        !EFI_ERROR (FindNodeStatus) && Num < MAX_FLASH_BANKS;
 | |
|        FindNodeStatus = FdtClient->FindNextCompatibleNode (FdtClient,
 | |
|                                      "cfi-flash", Node, &Node)) {
 | |
| 
 | |
|     Status = FdtClient->GetNodeProperty (FdtClient, Node, "reg",
 | |
|                           (CONST VOID **)&Reg, &PropSize);
 | |
|     if (EFI_ERROR (Status)) {
 | |
|       DEBUG ((DEBUG_ERROR, "%a: GetNodeProperty () failed (Status == %r)\n",
 | |
|         __FUNCTION__, Status));
 | |
|       continue;
 | |
|     }
 | |
| 
 | |
|     ASSERT ((PropSize % (4 * sizeof (UINT32))) == 0);
 | |
| 
 | |
|     while (PropSize >= (4 * sizeof (UINT32)) && Num < MAX_FLASH_BANKS) {
 | |
|       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 ((PcdGet64 (PcdFvBaseAddress) + PcdGet32 (PcdFvSize) > Base) &&
 | |
|           (Base + Size) > PcdGet64 (PcdFvBaseAddress)) {
 | |
|         continue;
 | |
|       }
 | |
| 
 | |
|       mNorFlashDevices[Num].DeviceBaseAddress = (UINTN)Base;
 | |
|       mNorFlashDevices[Num].RegionBaseAddress = (UINTN)Base;
 | |
|       mNorFlashDevices[Num].Size              = (UINTN)Size;
 | |
|       mNorFlashDevices[Num].BlockSize         = QEMU_NOR_BLOCK_SIZE;
 | |
|       Num++;
 | |
|     }
 | |
|   }
 | |
| 
 | |
|   *NorFlashDescriptions = mNorFlashDevices;
 | |
|   *Count = Num;
 | |
| 
 | |
|   return EFI_SUCCESS;
 | |
| }
 |