diff options
author | Heyi Guo <heyi.guo@linaro.org> | 2018-01-12 16:12:50 +0800 |
---|---|---|
committer | Leif Lindholm <leif.lindholm@linaro.org> | 2018-02-07 15:37:14 +0000 |
commit | ff11b46920c049bab80c0669a27e8edb4e21fa20 (patch) | |
tree | 643160276200c4c1a025df43fee298087216c263 /Silicon/Hisilicon/Library/PlatformFlashAccessLib | |
parent | 251a388105ef86136e443e2c95bc809861c0ff9f (diff) | |
download | edk2-platforms-ff11b46920c049bab80c0669a27e8edb4e21fa20.tar.xz |
Hisilicon D03/D05: Add capsule upgrade support
This module support updating the boot CPU firmware only.
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Jason Zhang <zhangjinsong2@huawei.com>
Signed-off-by: Ming Huang <huangming23@huawei.com>
Signed-off-by: Heyi Guo <heyi.guo@linaro.org>
Reviewed-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Reviewed-by: Leif Lindholm <leif.lindholm@linaro.org>
Diffstat (limited to 'Silicon/Hisilicon/Library/PlatformFlashAccessLib')
-rw-r--r-- | Silicon/Hisilicon/Library/PlatformFlashAccessLib/PlatformFlashAccessLibDxe.c | 123 | ||||
-rw-r--r-- | Silicon/Hisilicon/Library/PlatformFlashAccessLib/PlatformFlashAccessLibDxe.inf | 51 |
2 files changed, 174 insertions, 0 deletions
diff --git a/Silicon/Hisilicon/Library/PlatformFlashAccessLib/PlatformFlashAccessLibDxe.c b/Silicon/Hisilicon/Library/PlatformFlashAccessLib/PlatformFlashAccessLibDxe.c new file mode 100644 index 0000000000..62da61c79b --- /dev/null +++ b/Silicon/Hisilicon/Library/PlatformFlashAccessLib/PlatformFlashAccessLibDxe.c @@ -0,0 +1,123 @@ +/** @file
+ Platform Flash Access library.
+
+ Copyright (c) 2018, Hisilicon Limited. All rights reserved.
+ Copyright (c) 2018, Linaro Limited. All rights reserved.
+ Copyright (c) 2016, Intel Corporation. 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 <PiDxe.h>
+#include <Library/BaseLib.h>
+#include <Library/BaseMemoryLib.h>
+#include <Library/DebugLib.h>
+#include <Library/PcdLib.h>
+#include <Library/PlatformFlashAccessLib.h>
+#include <Library/UefiBootServicesTableLib.h>
+#include <Protocol/HisiSpiFlashProtocol.h>
+
+STATIC EFI_PHYSICAL_ADDRESS mInternalFdAddress;
+STATIC EFI_PHYSICAL_ADDRESS mSFCMEM0BaseAddress;
+
+STATIC HISI_SPI_FLASH_PROTOCOL *mSpiProtocol;
+
+/**
+ Perform flash write opreation.
+
+ @param[in] FirmwareType The type of firmware.
+ @param[in] FlashAddress The address of flash device to be accessed.
+ @param[in] FlashAddressType The type of flash device address.
+ @param[in] Buffer The pointer to the data buffer.
+ @param[in] Length The length of data buffer in bytes.
+
+ @retval EFI_SUCCESS The operation returns successfully.
+ @retval EFI_WRITE_PROTECTED The flash device is read only.
+ @retval EFI_UNSUPPORTED The flash device access is unsupported.
+ @retval EFI_INVALID_PARAMETER The input parameter is not valid.
+**/
+EFI_STATUS
+EFIAPI
+PerformFlashWrite (
+ IN PLATFORM_FIRMWARE_TYPE FirmwareType,
+ IN EFI_PHYSICAL_ADDRESS FlashAddress,
+ IN FLASH_ADDRESS_TYPE FlashAddressType,
+ IN VOID *Buffer,
+ IN UINTN Length
+ )
+{
+ UINT32 RomAddress;
+ EFI_STATUS Status;
+
+ DEBUG ((DEBUG_INFO,
+ "PerformFlashWrite - 0x%x(%x) - 0x%x\n",
+ (UINTN)FlashAddress,
+ (UINTN)FlashAddressType,
+ Length));
+
+ if (FlashAddressType == FlashAddressTypeAbsoluteAddress) {
+ FlashAddress = FlashAddress - mInternalFdAddress;
+ }
+
+ RomAddress = (UINT32)FlashAddress + (mInternalFdAddress - mSFCMEM0BaseAddress);
+
+ DEBUG ((DEBUG_INFO, "Erase and Write Flash Start\n"));
+
+ Status = mSpiProtocol->EraseWrite (
+ mSpiProtocol,
+ (UINT32) RomAddress,
+ (UINT8 *)Buffer,
+ (UINT32) Length
+ );
+ if (EFI_ERROR (Status)) {
+ DEBUG ((DEBUG_ERROR, "Erase and Write Status = %r \n", Status));
+ }
+
+ return Status;
+}
+
+/**
+ Platform Flash Access Lib Constructor.
+
+ @param[in] ImageHandle The firmware allocated handle for the EFI image.
+ @param[in] SystemTable A pointer to the EFI System Table.
+
+ @retval EFI_SUCCESS Constructor returns successfully.
+**/
+EFI_STATUS
+EFIAPI
+PerformFlashAccessLibConstructor (
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_SYSTEM_TABLE *SystemTable
+ )
+{
+ EFI_STATUS Status;
+
+ mInternalFdAddress = (EFI_PHYSICAL_ADDRESS) PcdGet64 (PcdFdBaseAddress);
+
+ mSFCMEM0BaseAddress = (EFI_PHYSICAL_ADDRESS) PcdGet64 (PcdSFCMEM0BaseAddress);
+
+ DEBUG ((DEBUG_INFO,
+ "PcdFlashAreaBaseAddress - 0x%x, PcdSFCMEM0BaseAddress - 0x%x \n",
+ mInternalFdAddress,
+ mSFCMEM0BaseAddress));
+
+ Status = gBS->LocateProtocol (
+ &gHisiSpiFlashProtocolGuid,
+ NULL,
+ (VOID **)&mSpiProtocol);
+ if (EFI_ERROR (Status)) {
+ DEBUG ((DEBUG_ERROR,
+ "LocateProtocol gHisiSpiFlashProtocolGuid Status = %r \n",
+ Status));
+ }
+
+ return Status;
+}
diff --git a/Silicon/Hisilicon/Library/PlatformFlashAccessLib/PlatformFlashAccessLibDxe.inf b/Silicon/Hisilicon/Library/PlatformFlashAccessLib/PlatformFlashAccessLibDxe.inf new file mode 100644 index 0000000000..ba209c9873 --- /dev/null +++ b/Silicon/Hisilicon/Library/PlatformFlashAccessLib/PlatformFlashAccessLibDxe.inf @@ -0,0 +1,51 @@ +## @file
+# Platform Flash Access library.
+#
+# Copyright (c) 2018, Hisilicon Limited. All rights reserved.
+# Copyright (c) 2018, Linaro Limited. All rights reserved.
+# Copyright (c) 2016, Intel Corporation. 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.
+#
+##
+
+[Defines]
+ INF_VERSION = 0x0001001A
+ BASE_NAME = PlatformFlashAccessLibDxe
+ FILE_GUID = c230e06c-c0d8-4935-8c23-9b8f7d33d1c4
+ MODULE_TYPE = DXE_DRIVER
+ VERSION_STRING = 1.0
+ LIBRARY_CLASS = PlatformFlashAccessLib|DXE_DRIVER
+ CONSTRUCTOR = PerformFlashAccessLibConstructor
+
+[Sources]
+ PlatformFlashAccessLibDxe.c
+
+[Packages]
+ ArmPkg/ArmPkg.dec
+ MdeModulePkg/MdeModulePkg.dec
+ MdePkg/MdePkg.dec
+ SignedCapsulePkg/SignedCapsulePkg.dec
+ Silicon/Hisilicon/HisiPkg.dec
+
+[LibraryClasses]
+ BaseMemoryLib
+ DebugLib
+ PcdLib
+ UefiBootServicesTableLib
+
+[Protocols]
+ gHisiSpiFlashProtocolGuid
+
+[FixedPcd]
+ gArmTokenSpaceGuid.PcdFdBaseAddress
+ gHisiTokenSpaceGuid.PcdSFCMEM0BaseAddress
+
+[Depex]
+ gHisiSpiFlashProtocolGuid
|