UefiPayloadPkg: Add library for logging to EC

Make use of the SMFI command interface to forward logs from edk2 to
System76 EC.
This commit is contained in:
Tim Crawford
2020-04-17 10:45:17 -06:00
parent 331d92a8ba
commit 4984cdcb36
10 changed files with 250 additions and 0 deletions

View File

@@ -17,6 +17,7 @@
#include <Library/PciLib.h>
#include <Library/PlatformHookLib.h>
#include <Library/BaseLib.h>
#include <Library/System76EcLib.h>
//
// PCI Defintions.
@@ -601,6 +602,8 @@ SerialPortWrite (
UINTN Result;
UINTN Index;
UINTN FifoSize;
UINT8 *BufPtr = Buffer;
UINTN Bytes = NumberOfBytes;
if (Buffer == NULL) {
return 0;
@@ -663,6 +666,9 @@ SerialPortWrite (
SerialPortWriteRegister (SerialRegisterBase, R_UART_TXBUF, *Buffer);
}
}
System76EcWrite(BufPtr, Bytes);
return Result;
}

View File

@@ -18,12 +18,14 @@
[Packages]
MdePkg/MdePkg.dec
MdeModulePkg/MdeModulePkg.dec
UefiPayloadPkg/UefiPayloadPkg.dec
[LibraryClasses]
PcdLib
IoLib
PlatformHookLib
PciLib
System76EcLib
[Sources]
BaseSerialPortLib16550.c

View File

@@ -0,0 +1,26 @@
/** @file
System76 EC logging
Copyright (c) 2020 System76, Inc.
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
#ifndef __SYSTEM76_EC_LIB__
#define __SYSTEM76_EC_LIB__
/**
Write data to the embedded controller using SMFI command interface.
@param Buffer Pointer to the data buffer to be written.
@param NumberOfBytes Number of bytes to write.
@return -1 if the command failed, else the number of data bytes written.
**/
INTN
System76EcWrite (
IN UINT8 *Buffer,
IN UINTN NumberOfBytes
);
#endif /* __SYSTEM76_EC_LIB__ */

View File

@@ -0,0 +1,103 @@
/** @file
System76 EC logging
Copyright (c) 2020 System76, Inc.
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
#include <Library/System76EcLib.h>
#include <Library/IoLib.h>
#include <Library/TimerLib.h>
#define SYSTEM76_EC_BASE 0xE00
#define CMD_PRINT 0x4
/**
@param Offset The offset into the SFMI RAM window to read from.
@return The value read.
**/
STATIC
UINT8
System76EcReadByte (
UINT8 Offset
)
{
return IoRead8 (SYSTEM76_EC_BASE + Offset);
}
/**
@param Offset The offset into the SFMI RAM window to write to.
@param Value The value to write.
@return The value written back to the I/O port.
**/
STATIC
UINT8
System76EcWriteByte (
UINT8 Offset,
UINT8 Value
)
{
return IoWrite8 (SYSTEM76_EC_BASE + Offset, Value);
}
/**
Write data to the embedded controller using SMFI command interface.
@param Buffer Pointer to the data buffer to be written.
@param NumberOfBytes Number of bytes to write.
@return -1 if the command failed, else the number of data bytes written.
**/
INTN
System76EcWrite (
IN UINT8 *Buffer,
IN UINTN NumberOfBytes
)
{
UINTN Index;
UINTN Index2;
UINTN Timeout;
if (Buffer == NULL) {
return 0;
}
for (Index = 0; Index < NumberOfBytes;) {
if (System76EcReadByte (0) == 0) {
// Can write 256 bytes of data at a time
for (Index2 = 0; (Index2 < NumberOfBytes) && ((Index2 + 4) < 256); Index++, Index2++) {
System76EcWriteByte ((Index + 4), Buffer[Index]);
}
// Flags
System76EcWriteByte (2, 0);
// Length
System76EcWriteByte (3, Index2);
// Command
System76EcWriteByte (0, CMD_PRINT);
// Wait for command completion, for up to 1 second
for (Timeout = 1000000; Timeout > 0; Timeout--) {
if (System76EcReadByte (0) == 0)
break;
MicroSecondDelay (1);
}
if (Timeout == 0) {
// Error: Timeout occured
return -1;
}
if (System76EcReadByte (1) != 0) {
// Error: Command failed
return -1;
}
} else {
// Error: Command already running
return -1;
}
}
return Index;
}

View File

@@ -0,0 +1,29 @@
## @file
# System76 EC logging.
#
# Copyright (c) 2020, System76, Inc.
# SPDX-License-Identifier: BSD-2-Clause-Patent
##
[Defines]
INF_VERSION = 0x00010005
BASE_NAME = System76EcLib
MODULE_UNI_FILE = System76EcLib.uni
FILE_GUID = 76ECF0DD-148B-4E48-8589-FC998823F8C2
MODULE_TYPE = BASE
VERSION_STRING = 0.1
LIBRARY_CLASS = System76EcLib
[Packages]
MdePkg/MdePkg.dec
MdeModulePkg/MdeModulePkg.dec
UefiPayloadPkg/UefiPayloadPkg.dec
[LibraryClasses]
IoLib
TimerLib
[Sources]
System76EcLib.c
[Pcd]

View File

@@ -0,0 +1,13 @@
// /** @file
// System76 EC logging.
//
// Copyright (c) 2020, System76, Inc.
// SPDX-License-Identifier: BSD-2-Clause-Patent
//
// **/
#string STR_MODULE_ABSTRACT #language en-US "System76 EC logging"
#string STR_MODULE_DESCRIPTION #language en-US "System76 EC logging."

View File

@@ -0,0 +1,18 @@
/** @file
System76 EC logging
Copyright (c) 2020 System76, Inc.
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
#include <Library/System76EcLib.h>
INTN
System76EcWrite (
IN UINT8 *Buffer,
IN UINTN NumberOfBytes
)
{
return 0;
}

View File

@@ -0,0 +1,27 @@
## @file
# System76 EC logging.
#
# Copyright (c) 2020, System76, Inc.
# SPDX-License-Identifier: BSD-2-Clause-Patent
##
[Defines]
INF_VERSION = 0x00010005
BASE_NAME = System76EcLibNull
MODULE_UNI_FILE = System76EcLibNull.uni
FILE_GUID = 76ECF0DD-148B-4E48-8589-FC998823F8C2
MODULE_TYPE = BASE
VERSION_STRING = 0.1
LIBRARY_CLASS = System76EcLibNull
[Packages]
MdePkg/MdePkg.dec
MdeModulePkg/MdeModulePkg.dec
UefiPayloadPkg/UefiPayloadPkg.dec
[LibraryClasses]
[Sources]
System76EcLibNull.c
[Pcd]

View File

@@ -0,0 +1,13 @@
// /** @file
// System76 EC logging.
//
// Copyright (c) 2020, System76, Inc.
// SPDX-License-Identifier: BSD-2-Clause-Patent
//
// **/
#string STR_MODULE_ABSTRACT #language en-US "System76 EC logging"
#string STR_MODULE_DESCRIPTION #language en-US "System76 EC logging."

View File

@@ -27,6 +27,11 @@
DEFINE SOURCE_DEBUG_ENABLE = FALSE
DEFINE PS2_KEYBOARD_ENABLE = TRUE
#
# Send logs to System76 EC
#
DEFINE SYSTEM76_EC_LOGGING = FALSE
#
# SBL: UEFI payload for Slim Bootloader
# COREBOOT: UEFI payload for coreboot
@@ -207,6 +212,12 @@
TpmMeasurementLib|MdeModulePkg/Library/TpmMeasurementLibNull/TpmMeasurementLibNull.inf
VarCheckLib|MdeModulePkg/Library/VarCheckLib/VarCheckLib.inf
!if $(SYSTEM76_EC_LOGGING) == TRUE
System76EcLib|UefiPayloadPkg/Library/System76EcLib/System76EcLib.inf
!else
System76EcLib|UefiPayloadPkg/Library/System76EcLibNull/System76EcLibNull.inf
!endif
[LibraryClasses.IA32.SEC]
DebugLib|MdePkg/Library/BaseDebugLibNull/BaseDebugLibNull.inf
PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf
@@ -225,6 +236,8 @@
DebugAgentLib|SourceLevelDebugPkg/Library/DebugAgent/SecPeiDebugAgentLib.inf
!endif
System76EcLib|UefiPayloadPkg/Library/System76EcLibNull/System76EcLibNull.inf
[LibraryClasses.common.DXE_CORE]
PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf
HobLib|MdePkg/Library/DxeCoreHobLib/DxeCoreHobLib.inf