Add FMP for System76 EC

Signed-off-by: Tim Crawford <tcrawford@system76.com>
This commit is contained in:
Tim Crawford 2023-10-27 11:12:48 -06:00
parent 045b938884
commit 102042deda
No known key found for this signature in database
GPG Key ID: 68E558D2BBD856E3
5 changed files with 300 additions and 3 deletions

View File

@ -0,0 +1,21 @@
# SPDX-License-Identifier: MPL-2.0
# SPDX-FileCopyrightText: 2023 System76, Inc.
FmpDevicePkg/FmpDxe/FmpDxe.inf {
<Defines>
FILE_GUID = $(EC_FMP_ESRT_GUID)
<PcdsFixedAtBuild>
gFmpDevicePkgTokenSpaceGuid.PcdFmpDeviceImageIdName|L"System76 EC"
gFmpDevicePkgTokenSpaceGuid.PcdFmpDeviceBuildTimeLowestSupportedVersion|0
gFmpDevicePkgTokenSpaceGuid.PcdFmpDeviceProgressWatchdogTimeInSeconds|0
gFmpDevicePkgTokenSpaceGuid.PcdFmpDeviceProgressColor|0x00FBB86C
<LibraryClasses>
FmpPayloadHeaderLib|FmpDevicePkg/Library/FmpPayloadHeaderLibV1/FmpPayloadHeaderLibV1.inf
FmpAuthenticationLib|MdeModulePkg/Library/FmpAuthenticationLibNull/FmpAuthenticationLibNull.inf
FmpDependencyLib|FmpDevicePkg/Library/FmpDependencyLib/FmpDependencyLib.inf
FmpDependencyCheckLib|FmpDevicePkg/Library/FmpDependencyCheckLibNull/FmpDependencyCheckLibNull.inf
FmpDependencyDeviceLib|FmpDevicePkg/Library/FmpDependencyDeviceLibNull/FmpDependencyDeviceLibNull.inf
CapsuleUpdatePolicyLib|FmpDevicePkg/Library/CapsuleUpdatePolicyLibNull/CapsuleUpdatePolicyLibNull.inf
FmpDeviceLib|System76Pkg/Ec/Fmp/EcFmpLib.inf
}

View File

@ -0,0 +1,241 @@
// SPDX-License-Identifier: MPL-2.0
// SPDX-FileCopyrightText: 2023 System76, Inc.
#include <Guid/SystemResourceTable.h>
#include <Library/BaseMemoryLib.h>
#include <Library/FmpDeviceLib.h>
#include <Library/MemoryAllocationLib.h>
#include <Library/UefiBootServicesTableLib.h>
#include <LastAttemptStatus.h>
#define US_PER_MS 1000
EFI_STATUS
EFIAPI
RegisterFmpInstaller(
IN FMP_DEVICE_LIB_REGISTER_FMP_INSTALLER FmpInstaller
) {
return EFI_UNSUPPORTED;
}
EFI_STATUS
EFIAPI
RegisterFmpUninstaller(
IN FMP_DEVICE_LIB_REGISTER_FMP_UNINSTALLER FmpUninstaller
) {
return EFI_UNSUPPORTED;
}
EFI_STATUS
EFIAPI
FmpDeviceSetContext(
IN EFI_HANDLE Handle,
IN OUT VOID **Context
) {
return EFI_UNSUPPORTED;
}
EFI_STATUS
EFIAPI
FmpDeviceGetSize(
OUT UINTN *Size
) {
if (!Size)
return EFI_INVALID_PARAMETER;
// TODO
*Size = 128 * 1024;
return EFI_SUCCESS;
}
EFI_STATUS
EFIAPI
FmpDeviceGetImageTypeIdGuidPtr(
OUT EFI_GUID **Guid
) {
if (!Guid)
return EFI_INVALID_PARAMETER;
return EFI_UNSUPPORTED;
}
EFI_STATUS
EFIAPI
FmpDeviceGetAttributes(
OUT UINT64 *Supported,
OUT UINT64 *Setting
) {
if (!Supported || !Setting)
return EFI_INVALID_PARAMETER;
*Supported = IMAGE_ATTRIBUTE_IMAGE_UPDATABLE
| IMAGE_ATTRIBUTE_RESET_REQUIRED
| IMAGE_ATTRIBUTE_IN_USE;
*Setting = IMAGE_ATTRIBUTE_IMAGE_UPDATABLE
| IMAGE_ATTRIBUTE_RESET_REQUIRED
| IMAGE_ATTRIBUTE_IN_USE;
return EFI_SUCCESS;
}
EFI_STATUS
EFIAPI
FmpDeviceGetLowestSupportedVersion(
OUT UINT32 *LowestSupportedVersion
) {
return EFI_UNSUPPORTED;
}
EFI_STATUS
EFIAPI
FmpDeviceGetVersionString(
OUT CHAR16 **VersionString
) {
if (!VersionString)
return EFI_INVALID_PARAMETER;
// TODO
*VersionString = AllocatePool(sizeof(L"0.3"));
if (!(*VersionString))
return EFI_OUT_OF_RESOURCES;
CopyMem(VersionString, L"0.3", sizeof(L"0.3"));
//*VersionString = NULL;
return EFI_SUCCESS;
}
EFI_STATUS
EFIAPI
FmpDeviceGetVersion(
OUT UINT32 *Version
) {
if (!Version)
return EFI_INVALID_PARAMETER;
// TODO
*Version = 3;
return EFI_SUCCESS;
}
EFI_STATUS
EFIAPI
FmpDeviceGetHardwareInstance(
OUT UINT64 *HardwareInstance
) {
return EFI_UNSUPPORTED;
}
EFI_STATUS
EFIAPI
FmpDeviceGetImage(
OUT VOID *Image,
IN OUT UINTN *ImageSize
) {
// TODO
return EFI_UNSUPPORTED;
}
EFI_STATUS
EFIAPI
FmpDeviceCheckImageWithStatus(
IN CONST VOID *Image,
IN UINTN ImageSize,
OUT UINT32 *ImageUpdatable,
OUT UINT32 *LastAttemptStatus
) {
if (!LastAttemptStatus)
return EFI_INVALID_PARAMETER;
*LastAttemptStatus = LAST_ATTEMPT_STATUS_DEVICE_LIBRARY_MIN_ERROR_CODE_VALUE;
if (!ImageUpdatable || !Image)
return EFI_INVALID_PARAMETER;
// TODO:
*LastAttemptStatus = LAST_ATTEMPT_STATUS_SUCCESS;
return EFI_SUCCESS;
}
EFI_STATUS
EFIAPI
FmpDeviceCheckImage(
IN CONST VOID *Image,
IN UINTN ImageSize,
OUT UINT32 *ImageUpdatable
) {
UINT32 LastAttemptStatus;
return FmpDeviceCheckImageWithStatus(Image, ImageSize, ImageUpdatable, &LastAttemptStatus);
}
EFI_STATUS
EFIAPI
FmpDeviceSetImageWithStatus (
IN CONST VOID *Image,
IN UINTN ImageSize,
IN CONST VOID *VendorCode, OPTIONAL
IN EFI_FIRMWARE_MANAGEMENT_UPDATE_IMAGE_PROGRESS Progress, OPTIONAL
IN UINT32 CapsuleFwVersion,
OUT CHAR16 **AbortReason,
OUT UINT32 *LastAttemptStatus
) {
// TODO
EFI_STATUS Status = EFI_SUCCESS;
UINT32 Updateable = 0;
Status = FmpDeviceCheckImageWithStatus(Image, ImageSize, &Updateable, LastAttemptStatus);
if (EFI_ERROR(Status)) {
goto cleanup;
}
if (Updateable != IMAGE_UPDATABLE_VALID) {
Status = EFI_ABORTED;
goto cleanup;
}
if (Progress == NULL) {
Status = EFI_INVALID_PARAMETER;
goto cleanup;
}
gBS->Stall (3000 * US_PER_MS);
Progress(15);
gBS->Stall (2000 * US_PER_MS);
for (int p = 20; p < 100; p++) {
gBS->Stall (100 * US_PER_MS);
Progress (p);
}
cleanup:
if (EFI_ERROR (Status)) {
*LastAttemptStatus = LAST_ATTEMPT_STATUS_DEVICE_LIBRARY_MIN_ERROR_CODE_VALUE;
}
return Status;
}
EFI_STATUS
EFIAPI
FmpDeviceSetImage(
IN CONST VOID *Image,
IN UINTN ImageSize,
IN CONST VOID *VendorCode, OPTIONAL
IN EFI_FIRMWARE_MANAGEMENT_UPDATE_IMAGE_PROGRESS Progress, OPTIONAL
IN UINT32 CapsuleFwVersion,
OUT CHAR16 **AbortReason
) {
UINT32 LastAttemptStatus;
return FmpDeviceSetImageWithStatus(Image, ImageSize, VendorCode, Progress, CapsuleFwVersion, AbortReason, &LastAttemptStatus);
}
EFI_STATUS
EFIAPI
FmpDeviceLock(
VOID
) {
return EFI_UNSUPPORTED;
}

View File

@ -0,0 +1,20 @@
# SPDX-License-Identifier: MPL-2.0
# SPDX-FileCopyrightText: 2023 System76, Inc.
[Defines]
INF_VERSION = 1.27
BASE_NAME = EcFmpLib
FILE_GUID = 760B7155-99F7-4E8E-8C07-D38A75F54C54
MODULE_TYPE = DXE_DRIVER
VERSION_STRING = 0.1
LIBRARY_CLASS = FmpDeviceLib|DXE_DRIVER
[Sources]
EcFmpLib.c
[Packages]
MdePkg/MdePkg.dec
FmpDevicePkg/FmpDevicePkg.dec
[LibraryClasses]
UefiBootServicesTableLib

View File

@ -112,6 +112,9 @@
DEFINE SECURE_BOOT_ENABLE = FALSE
DEFINE TPM_ENABLE = FALSE
# FMP
DEFINE EC_FMP_ESRT_GUID = 76FFAC81-FDE6-464D-A6D9-84BDD9EE522D
[BuildOptions]
*_*_*_CC_FLAGS = -D DISABLE_NEW_DEPRECATED_INTERFACES
GCC:*_UNIXGCC_*_CC_FLAGS = -DMDEPKG_NDEBUG
@ -206,13 +209,16 @@
UefiUsbLib|MdePkg/Library/UefiUsbLib/UefiUsbLib.inf
UefiScsiLib|MdePkg/Library/UefiScsiLib/UefiScsiLib.inf
OemHookStatusCodeLib|MdeModulePkg/Library/OemHookStatusCodeLibNull/OemHookStatusCodeLibNull.inf
CapsuleLib|MdeModulePkg/Library/DxeCapsuleLibNull/DxeCapsuleLibNull.inf
SecurityManagementLib|MdeModulePkg/Library/DxeSecurityManagementLib/DxeSecurityManagementLib.inf
UefiBootManagerLib|MdeModulePkg/Library/UefiBootManagerLib/UefiBootManagerLib.inf
BootLogoLib|MdeModulePkg/Library/BootLogoLib/BootLogoLib.inf
CustomizedDisplayLib|MdeModulePkg/Library/CustomizedDisplayLib/CustomizedDisplayLib.inf
FrameBufferBltLib|MdeModulePkg/Library/FrameBufferBltLib/FrameBufferBltLib.inf
# FMP Capsule
BmpSupportLib|MdeModulePkg/Library/BaseBmpSupportLib/BaseBmpSupportLib.inf
CapsuleLib|MdeModulePkg/Library/DxeCapsuleLibNull/DxeCapsuleLibNull.inf
#
# CPU
#
@ -346,6 +352,9 @@
Tpm2DeviceLib|SecurityPkg/Library/Tpm2DeviceLibTcg2/Tpm2DeviceLibTcg2.inf
!endif
# FMP Capsule
CapsuleLib|MdeModulePkg/Library/DxeCapsuleLibFmp/DxeCapsuleLib.inf
[LibraryClasses.common.DXE_RUNTIME_DRIVER]
PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf
MemoryAllocationLib|MdePkg/Library/UefiMemoryAllocationLib/UefiMemoryAllocationLib.inf
@ -364,6 +373,9 @@
AuthVariableLib|MdeModulePkg/Library/AuthVariableLibNull/AuthVariableLibNull.inf
!endif
# FMP Capsule
CapsuleLib|MdeModulePkg/Library/DxeCapsuleLibFmp/DxeRuntimeCapsuleLib.inf
[LibraryClasses.common.UEFI_DRIVER,LibraryClasses.common.UEFI_APPLICATION]
PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf
MemoryAllocationLib|MdePkg/Library/UefiMemoryAllocationLib/UefiMemoryAllocationLib.inf
@ -563,7 +575,6 @@
MdeModulePkg/Universal/Metronome/Metronome.inf
MdeModulePkg/Universal/WatchdogTimerDxe/WatchdogTimer.inf
MdeModulePkg/Core/RuntimeDxe/RuntimeDxe.inf
MdeModulePkg/Universal/CapsuleRuntimeDxe/CapsuleRuntimeDxe.inf
MdeModulePkg/Universal/MonotonicCounterRuntimeDxe/MonotonicCounterRuntimeDxe.inf
!if $(DISABLE_RESET_SYSTEM) == FALSE
MdeModulePkg/Universal/ResetSystemRuntimeDxe/ResetSystemRuntimeDxe.inf
@ -710,6 +721,9 @@
# Firmware update
#
MdeModulePkg/Universal/EsrtFmpDxe/EsrtFmpDxe.inf
MdeModulePkg/Universal/CapsuleRuntimeDxe/CapsuleRuntimeDxe.inf
!include System76Pkg/Ec/Fmp/EcFmp.dsc
#------------------------------
# Build the shell

View File

@ -113,7 +113,6 @@ INF PcAtChipsetPkg/HpetTimerDxe/HpetTimerDxe.inf
INF MdeModulePkg/Universal/Metronome/Metronome.inf
INF MdeModulePkg/Universal/WatchdogTimerDxe/WatchdogTimer.inf
INF MdeModulePkg/Core/RuntimeDxe/RuntimeDxe.inf
INF MdeModulePkg/Universal/CapsuleRuntimeDxe/CapsuleRuntimeDxe.inf
INF MdeModulePkg/Universal/MonotonicCounterRuntimeDxe/MonotonicCounterRuntimeDxe.inf
!if $(DISABLE_RESET_SYSTEM) == FALSE
@ -282,6 +281,8 @@ INF SecurityPkg/RandomNumberGenerator/RngDxe/RngDxe.inf
# Firmware update
#
INF MdeModulePkg/Universal/EsrtFmpDxe/EsrtFmpDxe.inf
INF MdeModulePkg/Universal/CapsuleRuntimeDxe/CapsuleRuntimeDxe.inf
INF FILE_GUID = $(EC_FMP_ESRT_GUID) FmpDevicePkg/FmpDxe/FmpDxe.inf
#
# Shell