UefiPayloadPkg: Add library for logging to EC

Make use of the SMFI command interface to forward logs from edk2 to
System76 EC.

Signed-off-by: Jeremy Soller <jeremy@system76.com>
Signed-off-by: Tim Crawford <tcrawford@system76.com>
This commit is contained in:
Jeremy Soller
2020-04-17 10:45:17 -06:00
committed by Tim Crawford
parent 9030464a1b
commit 9daa69a59e
4 changed files with 199 additions and 4 deletions

View File

@@ -0,0 +1,144 @@
/** @file
System76 EC logging
Copyright (c) 2020 System76, Inc.
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
#include <Library/IoLib.h>
// From coreboot/src/drivers/system76_ec/system76_ec.c {
#define SYSTEM76_EC_BASE 0x0E00
static inline UINT8 system76_ec_read(UINT8 addr) {
return IoRead8(SYSTEM76_EC_BASE + (UINT16)addr);
}
static inline void system76_ec_write(UINT8 addr, UINT8 data) {
IoWrite8(SYSTEM76_EC_BASE + (UINT16)addr, data);
}
void system76_ec_init(void) {
// Clear entire command region
for (int i = 0; i < 256; i++) {
system76_ec_write((UINT8)i, 0);
}
}
void system76_ec_flush(void) {
// Send command
system76_ec_write(0, 4);
// Wait for command completion
while (system76_ec_read(0) != 0) {}
// Clear length
system76_ec_write(3, 0);
}
void system76_ec_print(UINT8 byte) {
// Read length
UINT8 len = system76_ec_read(3);
// Write data at offset
system76_ec_write(len + 4, byte);
// Update length
system76_ec_write(3, len + 1);
// If we hit the end of the buffer, or were given a newline, flush
if (byte == '\n' || len >= 128) {
system76_ec_flush();
}
}
// } From coreboot/src/drivers/system76_ec/system76_ec.c
// Implement SerialPortLib {
#include <Library/SerialPortLib.h>
RETURN_STATUS
EFIAPI
SerialPortInitialize (
VOID
)
{
system76_ec_init();
return RETURN_SUCCESS;
}
UINTN
EFIAPI
SerialPortWrite (
IN UINT8 *Buffer,
IN UINTN NumberOfBytes
)
{
if (Buffer == NULL) {
return 0;
}
if (NumberOfBytes == 0) {
system76_ec_flush();
return 0;
}
for(UINTN i = 0; i < NumberOfBytes; i++) {
system76_ec_print(Buffer[i]);
}
return NumberOfBytes;
}
BOOLEAN
EFIAPI
SerialPortPoll (
VOID
)
{
return FALSE;
}
RETURN_STATUS
EFIAPI
SerialPortGetControl (
OUT UINT32 *Control
)
{
return RETURN_UNSUPPORTED;
}
RETURN_STATUS
EFIAPI
SerialPortSetControl (
IN UINT32 Control
)
{
return RETURN_UNSUPPORTED;
}
RETURN_STATUS
EFIAPI
SerialPortSetAttributes (
IN OUT UINT64 *BaudRate,
IN OUT UINT32 *ReceiveFifoDepth,
IN OUT UINT32 *Timeout,
IN OUT EFI_PARITY_TYPE *Parity,
IN OUT UINT8 *DataBits,
IN OUT EFI_STOP_BITS_TYPE *StopBits
)
{
return RETURN_UNSUPPORTED;
}
// } Implement SerialPortLib
// Implement PlatformHookLib {
#include <Library/PlatformHookLib.h>
RETURN_STATUS
EFIAPI
PlatformHookSerialPortInitialize (
VOID
)
{
return RETURN_SUCCESS;
}
// } Implement PlatformHookLib

View File

@@ -0,0 +1,28 @@
## @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
[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

@@ -32,6 +32,11 @@
DEFINE PLATFORM_BOOT_TIMEOUT = 2
#
# Send logs to System76 EC
#
DEFINE SYSTEM76_EC_LOGGING = FALSE
#
# SBL: UEFI payload for Slim Bootloader
# COREBOOT: UEFI payload for coreboot
@@ -220,11 +225,16 @@
#
TimerLib|UefiPayloadPkg/Library/AcpiTimerLib/AcpiTimerLib.inf
ResetSystemLib|UefiPayloadPkg/Library/ResetSystemLib/ResetSystemLib.inf
SerialPortLib|MdeModulePkg/Library/BaseSerialPortLib16550/BaseSerialPortLib16550.inf
!if $(UNIVERSAL_PAYLOAD) == TRUE
PlatformHookLib|UefiPayloadPkg/Library/UniversalPayloadPlatformHookLib/PlatformHookLib.inf
!if $(SYSTEM76_EC_LOGGING) == TRUE
SerialPortLib|UefiPayloadPkg/Library/System76EcLib/System76EcLib.inf
PlatformHookLib|UefiPayloadPkg/Library/System76EcLib/System76EcLib.inf
!else
PlatformHookLib|UefiPayloadPkg/Library/PlatformHookLib/PlatformHookLib.inf
SerialPortLib|MdeModulePkg/Library/BaseSerialPortLib16550/BaseSerialPortLib16550.inf
!if $(UNIVERSAL_PAYLOAD) == TRUE
PlatformHookLib|UefiPayloadPkg/Library/UniversalPayloadPlatformHookLib/PlatformHookLib.inf
!else
PlatformHookLib|UefiPayloadPkg/Library/PlatformHookLib/PlatformHookLib.inf
!endif
!endif
PlatformBootManagerLib|UefiPayloadPkg/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf
IoApicLib|PcAtChipsetPkg/Library/BaseIoApicLib/BaseIoApicLib.inf