Skip to content

Commit

Permalink
JadePkg: Add Capsule Update support
Browse files Browse the repository at this point in the history
This adds the platform specific implemenation required for the capsule
update as follows:
  * SystemFirmwareDescriptor, to determine the current firmware version.
  * SystemFirmwareUpdateConfig, to provide the inventory of components
  in the capsule.
  * PlatformFlashAccessLib, to implement flash write functions via
  Firmware Update MM services provided by Arm Trusted Firmware.

Also, this connects the different modules to implement the signed
capsule update.

Below is the command to build capsule images:
build -a AARCH64 -t GCC -b RELEASE                      \
  -D SCP_IMAGE=path/to/the/jade_scp.slim                \
  -D UEFI_ATF_IMAGE=path/to/the/jade_tianocore_atf.img  \
  -p Platform/Ampere/JadePkg/JadeCapsule.dsc

Signed-off-by: Nhi Pham <[email protected]>
  • Loading branch information
nhivp committed Oct 11, 2024
1 parent 8f6b77e commit 535c3c0
Show file tree
Hide file tree
Showing 12 changed files with 853 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/** @file
System Firmware descriptor.

Copyright (c) 2024, Ampere Computing LLC. All rights reserved.<BR>

SPDX-License-Identifier: BSD-2-Clause-Patent

**/

#include <PiPei.h>

#include <Guid/EdkiiSystemFmpCapsule.h>
#include <Protocol/FirmwareManagement.h>

#define PACKAGE_VERSION 0xFFFFFFFF
#define PACKAGE_VERSION_STRING L"Unknown"

#define CURRENT_FIRMWARE_VERSION 0x00000001
#define CURRENT_FIRMWARE_VERSION_STRING L"0x00000001"
#define LOWEST_SUPPORTED_FIRMWARE_VERSION 0x00000001

#define IMAGE_ID SIGNATURE_64('J', 'A', 'D', 'E', '_', 'F', 'W', ' ')
#define IMAGE_ID_STRING L"Jade System Firmware"

// PcdSystemFmpCapsuleImageTypeIdGuid
#define IMAGE_TYPE_ID_GUID { 0xf08bca31, 0x542e, 0x4cea, { 0x8b, 0x48, 0x8e, 0x54, 0xf9, 0x42, 0x25, 0x94 } }

typedef struct {
EDKII_SYSTEM_FIRMWARE_IMAGE_DESCRIPTOR Descriptor;
// real string data
CHAR16 ImageIdNameStr[sizeof(IMAGE_ID_STRING)/sizeof(CHAR16)];
CHAR16 VersionNameStr[sizeof(CURRENT_FIRMWARE_VERSION_STRING)/sizeof(CHAR16)];
CHAR16 PackageVersionNameStr[sizeof(PACKAGE_VERSION_STRING)/sizeof(CHAR16)];
} IMAGE_DESCRIPTOR;

STATIC IMAGE_DESCRIPTOR mImageDescriptor =
{
{
EDKII_SYSTEM_FIRMWARE_IMAGE_DESCRIPTOR_SIGNATURE,
sizeof(EDKII_SYSTEM_FIRMWARE_IMAGE_DESCRIPTOR),
sizeof(IMAGE_DESCRIPTOR),
PACKAGE_VERSION, // PackageVersion
OFFSET_OF (IMAGE_DESCRIPTOR, PackageVersionNameStr), // PackageVersionName
1, // ImageIndex;
{0x0}, // Reserved
IMAGE_TYPE_ID_GUID, // ImageTypeId;
IMAGE_ID, // ImageId;
OFFSET_OF (IMAGE_DESCRIPTOR, ImageIdNameStr), // ImageIdName;
CURRENT_FIRMWARE_VERSION, // Version;
OFFSET_OF (IMAGE_DESCRIPTOR, VersionNameStr), // VersionName;
{0x0}, // Reserved2
0, // Size;
IMAGE_ATTRIBUTE_IMAGE_UPDATABLE |
IMAGE_ATTRIBUTE_RESET_REQUIRED |
IMAGE_ATTRIBUTE_AUTHENTICATION_REQUIRED |
IMAGE_ATTRIBUTE_IN_USE, // AttributesSupported;
IMAGE_ATTRIBUTE_IMAGE_UPDATABLE |
IMAGE_ATTRIBUTE_RESET_REQUIRED |
IMAGE_ATTRIBUTE_AUTHENTICATION_REQUIRED |
IMAGE_ATTRIBUTE_IN_USE, // AttributesSetting;
0x0, // Compatibilities;
LOWEST_SUPPORTED_FIRMWARE_VERSION, // LowestSupportedImageVersion;
0x00000000, // LastAttemptVersion;
0, // LastAttemptStatus;
{0x0}, // Reserved3
0, // HardwareInstance;
},
// real string data
IMAGE_ID_STRING,
CURRENT_FIRMWARE_VERSION_STRING,
PACKAGE_VERSION_STRING,
};

VOID* CONST ReferenceAcpiTable = &mImageDescriptor;
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
## @file
# System Firmware descriptor.
#
# Copyright (c) 2024, Ampere Computing LLC. All rights reserved.<BR>
#
# SPDX-License-Identifier: BSD-2-Clause-Patent
#
##

[Defines]
INF_VERSION = 0x0001001A
BASE_NAME = SystemFirmwareDescriptor
FILE_GUID = 90B2B846-CA6D-4D6E-A8D3-C140A8E110AC
MODULE_TYPE = PEIM
VERSION_STRING = 1.0
ENTRY_POINT = SystemFirmwareDescriptorPeimEntry

[Sources]
SystemFirmwareDescriptor.aslc
SystemFirmwareDescriptorPei.c

[Packages]
ArmPkg/ArmPkg.dec
MdeModulePkg/MdeModulePkg.dec
MdePkg/MdePkg.dec
SignedCapsulePkg/SignedCapsulePkg.dec

[LibraryClasses]
DebugLib
PcdLib
PeiServicesLib
PeimEntryPoint

[FixedPcd]

[Pcd]
gEfiSignedCapsulePkgTokenSpaceGuid.PcdEdkiiSystemFirmwareImageDescriptor

[Depex]
TRUE
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/** @file
System Firmware descriptor producer.
Copyright (c) 2024, Ampere Computing LLC. All rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent
**/

#include <PiPei.h>

#include <Guid/EdkiiSystemFmpCapsule.h>
#include <Library/DebugLib.h>
#include <Library/PcdLib.h>
#include <Library/PeiServicesLib.h>
#include <Protocol/FirmwareManagement.h>

/**
Entrypoint for SystemFirmwareDescriptor PEIM.
@param[in] FileHandle Handle of the file being invoked.
@param[in] PeiServices Describes the list of possible PEI Services.
@retval EFI_SUCCESS PPI successfully installed.
**/
EFI_STATUS
EFIAPI
SystemFirmwareDescriptorPeimEntry (
IN EFI_PEI_FILE_HANDLE FileHandle,
IN CONST EFI_PEI_SERVICES **PeiServices
)
{
EFI_STATUS Status;
EDKII_SYSTEM_FIRMWARE_IMAGE_DESCRIPTOR *Descriptor;
UINTN Size;
UINTN Index;
UINT32 AuthenticationStatus;

//
// Search RAW section.
//
Index = 0;
while (TRUE) {
Status = PeiServicesFfsFindSectionData3 (
EFI_SECTION_RAW,
Index,
FileHandle,
(VOID **)&Descriptor,
&AuthenticationStatus
);
if (EFI_ERROR (Status)) {
// Should not happen, must something wrong in FDF.
ASSERT (FALSE);
return EFI_NOT_FOUND;
}

if (Descriptor->Signature == EDKII_SYSTEM_FIRMWARE_IMAGE_DESCRIPTOR_SIGNATURE) {
break;
}

Index++;
}

DEBUG ((
DEBUG_INFO,
"EDKII_SYSTEM_FIRMWARE_IMAGE_DESCRIPTOR size - 0x%x\n",
Descriptor->Length
));

Size = Descriptor->Length;
PcdSetPtrS (PcdEdkiiSystemFirmwareImageDescriptor, &Size, Descriptor);

return EFI_SUCCESS;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
## @file
#
# Copyright (c) 2024, Ampere Computing LLC. All rights reserved.<BR>
#
# SPDX-License-Identifier: BSD-2-Clause-Patent
#
##

[Head]
NumOfUpdate = 1
NumOfRecovery = 0
Update0 = JadeSCP

[JadeSCP]
FirmwareType = 2147483649 # 0x80000001: SMpro/PMpro Firmware
AddressType = 1 # 0 - relative address, 1 - absolute address.
BaseAddress = 0x00000000 # Base address offset on flash
Length = 0x00050000 # Length
ImageOffset = 0x00000000 # Image offset of this SystemFirmware image
FileGuid = 431c06ed-4fe2-438f-98a3-a9b1fd923019 # PcdEdkiiSystemFirmwareFileGuid
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
## @file
#
# Copyright (c) 2024, Ampere Computing LLC. All rights reserved.<BR>
#
# SPDX-License-Identifier: BSD-2-Clause-Patent
#
##

[Head]
NumOfUpdate = 1
NumOfRecovery = 0
Update0 = JadeUEFIATF

[JadeUEFIATF]
FirmwareType = 2147483650 # SystemFirmware: 0x80000002 - OEM UEFI and ARM Trusted Firmware
AddressType = 1 # 0 - relative address, 1 - absolute address.
BaseAddress = 0x00000000 # Base address offset on flash
Length = 0x00D10000 # Length
ImageOffset = 0x00000000 # Image offset of this SystemFirmware image
FileGuid = 431c06ed-4fe2-438f-98a3-a9b1fd923019 # PcdEdkiiSystemFirmwareFileGuid
16 changes: 15 additions & 1 deletion Platform/Ampere/JadePkg/Jade.dsc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## @file
#
# Copyright (c) 2020 - 2023, Ampere Computing LLC. All rights reserved.<BR>
# Copyright (c) 2020 - 2024, Ampere Computing LLC. All rights reserved.<BR>
#
# SPDX-License-Identifier: BSD-2-Clause-Patent
#
Expand Down Expand Up @@ -195,6 +195,11 @@

[PcdsDynamicDefault.common.DEFAULT]

[PcdsDynamicExDefault.common.DEFAULT]
gEfiSignedCapsulePkgTokenSpaceGuid.PcdEdkiiSystemFirmwareImageDescriptor|{0x0}|VOID*|0x100
gEfiMdeModulePkgTokenSpaceGuid.PcdSystemFmpCapsuleImageTypeIdGuid|{0x31, 0xca, 0x8b, 0xf0, 0x2e, 0x54, 0xea, 0x4c, 0x8b, 0x48, 0x8e, 0x54, 0xf9, 0x42, 0x25, 0x94}
gEfiSignedCapsulePkgTokenSpaceGuid.PcdEdkiiSystemFirmwareFileGuid|{0xed, 0x06, 0x1c, 0x43, 0xe2, 0x4f, 0x8f, 0x43, 0x98, 0xa3, 0xa9, 0xb1, 0xfd, 0x92, 0x30, 0x19}

[PcdsPatchableInModule]
#
# Console Resolution (HD mode)
Expand Down Expand Up @@ -248,3 +253,12 @@
Silicon/Ampere/AmpereAltraPkg/Drivers/AcpiConfigDxe/AcpiConfigDxe.inf
Silicon/Ampere/AmpereAltraPkg/Drivers/RasConfigDxe/RasConfigDxe.inf
Silicon/Ampere/AmpereSiliconPkg/Drivers/BmcConfigDxe/BmcConfigDxe.inf

#
# Firmware Capsule Update
#
Platform/Ampere/JadePkg/Capsule/SystemFirmwareDescriptor/SystemFirmwareDescriptor.inf
MdeModulePkg/Universal/EsrtDxe/EsrtDxe.inf
SignedCapsulePkg/Universal/SystemFirmwareUpdate/SystemFirmwareReportDxe.inf
SignedCapsulePkg/Universal/SystemFirmwareUpdate/SystemFirmwareUpdateDxe.inf
MdeModulePkg/Application/CapsuleApp/CapsuleApp.inf
55 changes: 54 additions & 1 deletion Platform/Ampere/JadePkg/Jade.fdf
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## @file
#
# Copyright (c) 2020 - 2023, Ampere Computing LLC. All rights reserved.<BR>
# Copyright (c) 2020 - 2024, Ampere Computing LLC. All rights reserved.<BR>
#
# SPDX-License-Identifier: BSD-2-Clause-Patent
#
Expand Down Expand Up @@ -182,6 +182,8 @@ APRIORI PEI {

INF MdeModulePkg/Core/DxeIplPeim/DxeIpl.inf

INF RuleOverride = FMP_IMAGE_DESC Platform/Ampere/JadePkg/Capsule/SystemFirmwareDescriptor/SystemFirmwareDescriptor.inf

FILE FV_IMAGE = 9E21FD93-9C72-4c15-8C4B-E77F1DB2D792 {
SECTION GUIDED EE4E5898-3914-4259-9D6E-DC7BD79403CF PROCESSING_REQUIRED = TRUE {
SECTION FV_IMAGE = FVMAIN
Expand Down Expand Up @@ -383,4 +385,55 @@ APRIORI DXE {
INF Silicon/Ampere/AmpereSiliconPkg/Drivers/BmcConfigDxe/BmcConfigDxe.inf
INF EmbeddedPkg/Drivers/MemoryAttributeManagerDxe/MemoryAttributeManagerDxe.inf

#
# Firmware Capsule Update
#
INF MdeModulePkg/Universal/EsrtDxe/EsrtDxe.inf
INF SignedCapsulePkg/Universal/SystemFirmwareUpdate/SystemFirmwareReportDxe.inf

FILE FREEFORM = PCD(gEfiSignedCapsulePkgTokenSpaceGuid.PcdEdkiiPkcs7TestPublicKeyFileGuid) {
SECTION RAW = BaseTools/Source/Python/Pkcs7Sign/TestRoot.cer
SECTION UI = "Pkcs7TestRoot"
}

[FV.SystemFirmwareDescriptor]
FvAlignment = 8
ERASE_POLARITY = 1
MEMORY_MAPPED = TRUE
STICKY_WRITE = TRUE
LOCK_CAP = TRUE
LOCK_STATUS = TRUE
WRITE_DISABLED_CAP = TRUE
WRITE_ENABLED_CAP = TRUE
WRITE_STATUS = TRUE
WRITE_LOCK_CAP = TRUE
WRITE_LOCK_STATUS = TRUE
READ_DISABLED_CAP = TRUE
READ_ENABLED_CAP = TRUE
READ_STATUS = TRUE
READ_LOCK_CAP = TRUE
READ_LOCK_STATUS = TRUE

INF RuleOverride = FMP_IMAGE_DESC Platform/Ampere/JadePkg/Capsule/SystemFirmwareDescriptor/SystemFirmwareDescriptor.inf

[FV.CapsuleDispatchFv]
FvAlignment = 8
ERASE_POLARITY = 1
MEMORY_MAPPED = TRUE
STICKY_WRITE = TRUE
LOCK_CAP = TRUE
LOCK_STATUS = TRUE
WRITE_DISABLED_CAP = TRUE
WRITE_ENABLED_CAP = TRUE
WRITE_STATUS = TRUE
WRITE_LOCK_CAP = TRUE
WRITE_LOCK_STATUS = TRUE
READ_DISABLED_CAP = TRUE
READ_ENABLED_CAP = TRUE
READ_STATUS = TRUE
READ_LOCK_CAP = TRUE
READ_LOCK_STATUS = TRUE

INF SignedCapsulePkg/Universal/SystemFirmwareUpdate/SystemFirmwareUpdateDxe.inf

!include Silicon/Ampere/AmpereSiliconPkg/FvRules.fdf.inc
30 changes: 30 additions & 0 deletions Platform/Ampere/JadePkg/JadeCapsule.dsc
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
## @file
#
# Copyright (c) 2024, Ampere Computing LLC. All rights reserved.<BR>
#
# SPDX-License-Identifier: BSD-2-Clause-Patent
#
##

################################################################################
#
# Defines Section - statements that will be processed to create a Makefile.
#
################################################################################
[Defines]
PLATFORM_NAME = Jade
PLATFORM_GUID = 34C87B13-434A-4767-88FB-2D0CD2AED46F
PLATFORM_VERSION = 0.1
DSC_SPECIFICATION = 0x0001001B
OUTPUT_DIRECTORY = Build/Jade
SUPPORTED_ARCHITECTURES = AARCH64
BUILD_TARGETS = DEBUG|RELEASE
SKUID_IDENTIFIER = DEFAULT
FLASH_DEFINITION = Platform/Ampere/JadePkg/JadeCapsule.fdf

#
# Defines for default states. These can be changed on the command line.
# -D FLAG=VALUE
#
DEFINE UEFI_ATF_IMAGE = Build/Jade/jade_tianocore_atf.img
DEFINE SCP_IMAGE = Build/Jade/jade_scp.slim
Loading

0 comments on commit 535c3c0

Please sign in to comment.