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:
committed by
Tim Crawford
parent
648620d59d
commit
c418d4eb9e
144
UefiPayloadPkg/Library/System76EcLib/System76EcLib.c
Normal file
144
UefiPayloadPkg/Library/System76EcLib/System76EcLib.c
Normal 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
|
28
UefiPayloadPkg/Library/System76EcLib/System76EcLib.inf
Normal file
28
UefiPayloadPkg/Library/System76EcLib/System76EcLib.inf
Normal 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]
|
13
UefiPayloadPkg/Library/System76EcLib/System76EcLib.uni
Normal file
13
UefiPayloadPkg/Library/System76EcLib/System76EcLib.uni
Normal 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."
|
||||||
|
|
@@ -37,6 +37,11 @@
|
|||||||
DEFINE ABOVE_4G_MEMORY = TRUE
|
DEFINE ABOVE_4G_MEMORY = TRUE
|
||||||
DEFINE BOOT_MANAGER_ESCAPE = FALSE
|
DEFINE BOOT_MANAGER_ESCAPE = FALSE
|
||||||
DEFINE SD_MMC_TIMEOUT = 1000000
|
DEFINE SD_MMC_TIMEOUT = 1000000
|
||||||
|
#
|
||||||
|
# Send logs to System76 EC
|
||||||
|
#
|
||||||
|
DEFINE SYSTEM76_EC_LOGGING = FALSE
|
||||||
|
|
||||||
#
|
#
|
||||||
# SBL: UEFI payload for Slim Bootloader
|
# SBL: UEFI payload for Slim Bootloader
|
||||||
# COREBOOT: UEFI payload for coreboot
|
# COREBOOT: UEFI payload for coreboot
|
||||||
@@ -232,8 +237,13 @@
|
|||||||
TimerLib|UefiPayloadPkg/Library/AcpiTimerLib/AcpiTimerLib.inf
|
TimerLib|UefiPayloadPkg/Library/AcpiTimerLib/AcpiTimerLib.inf
|
||||||
!endif
|
!endif
|
||||||
ResetSystemLib|UefiPayloadPkg/Library/ResetSystemLib/ResetSystemLib.inf
|
ResetSystemLib|UefiPayloadPkg/Library/ResetSystemLib/ResetSystemLib.inf
|
||||||
|
!if $(SYSTEM76_EC_LOGGING) == TRUE
|
||||||
|
SerialPortLib|UefiPayloadPkg/Library/System76EcLib/System76EcLib.inf
|
||||||
|
PlatformHookLib|UefiPayloadPkg/Library/System76EcLib/System76EcLib.inf
|
||||||
|
!else
|
||||||
SerialPortLib|MdeModulePkg/Library/BaseSerialPortLib16550/BaseSerialPortLib16550.inf
|
SerialPortLib|MdeModulePkg/Library/BaseSerialPortLib16550/BaseSerialPortLib16550.inf
|
||||||
PlatformHookLib|UefiPayloadPkg/Library/PlatformHookLib/PlatformHookLib.inf
|
PlatformHookLib|UefiPayloadPkg/Library/PlatformHookLib/PlatformHookLib.inf
|
||||||
|
!endif
|
||||||
PlatformBootManagerLib|UefiPayloadPkg/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf
|
PlatformBootManagerLib|UefiPayloadPkg/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf
|
||||||
IoApicLib|PcAtChipsetPkg/Library/BaseIoApicLib/BaseIoApicLib.inf
|
IoApicLib|PcAtChipsetPkg/Library/BaseIoApicLib/BaseIoApicLib.inf
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user