[PATCH] UefiPayloadPkg: Add support for logging to CBMEM console


Benjamin Doron
 

Hi,
Thanks for looking at my patch.

I probably need to refine the library before it's ready to be upstreamed. Two items on my list were finally debugging how to make `FindCbTag()` work, and using `CopyMem()` instead of byte-assignment.

This commit is missing my follow-up: We must not define MDEPKG_NDEBUG or the messages are stripped. We must not make asserts fatal, because then they cannot be seen; we must try to continue anyways. PlatformHookLibNull must be used, or asserts occur when UefiPayload's instance cannot find the serial table in CBMEM. See https://github.com/MrChromebox/edk2/commit/5fec6d995cc2f453d4b580e941fca6662e2ed367 for the updated commit, I don't believe it ever made it to my GitHub. However, I now know that the Status Code stuff is irrelevant, because we aren't logging through its infrastructure.

That should be it, I suppose? I'll get back to it when I can if upstream/coreboot's fork wants.

Regards,
Benjamin

On Fri., Jan. 28, 2022, 4:38 p.m. Sean Rhodes, <sean@...> wrote:
From: Benjamin Doron <benjamin.doron00@...>

Tested on QEMU, dumping the appropriate memory region in UEFI shell
shows the TianoCore log. `find_cb_subtable` is sourced from STM/SeaBIOS.

Signed-off-by: Benjamin Doron <benjamin.doron00@...>
---
 UefiPayloadPkg/Include/Coreboot.h             |  14 +
 .../Library/CbSerialPortLib/CbSerialPortLib.c | 272 ++++++++++++++++++
 .../CbSerialPortLib/CbSerialPortLib.inf       |  27 ++
 UefiPayloadPkg/UefiPayloadPkg.dsc             |   5 +
 UefiPayloadPkg/UefiPayloadPkg.fdf             |   6 +-
 5 files changed, 323 insertions(+), 1 deletion(-)
 create mode 100644 UefiPayloadPkg/Library/CbSerialPortLib/CbSerialPortLib.c
 create mode 100644 UefiPayloadPkg/Library/CbSerialPortLib/CbSerialPortLib.inf

diff --git a/UefiPayloadPkg/Include/Coreboot.h b/UefiPayloadPkg/Include/Coreboot.h
index a3e1109fe8..f2f577a02e 100644
--- a/UefiPayloadPkg/Include/Coreboot.h
+++ b/UefiPayloadPkg/Include/Coreboot.h
@@ -199,7 +199,14 @@ struct cb_forward {
   UINT64    forward;
 };

+struct cb_cbmem_ref {
+  UINT32 tag;
+  UINT32 size;
+  UINT64 cbmem_addr;
+};
+
 #define CB_TAG_FRAMEBUFFER  0x0012
+
 struct cb_framebuffer {
   UINT32    tag;
   UINT32    size;
@@ -230,6 +237,13 @@ struct cb_vdat {
 #define CB_TAG_TIMESTAMPS     0x0016
 #define CB_TAG_CBMEM_CONSOLE  0x0017
 #define CB_TAG_MRC_CACHE      0x0018
+
+struct cbmem_console {
+  UINT32 size;
+  UINT32 cursor;
+  UINT8  body[0];
+} __attribute__((packed));
+
 struct cb_cbmem_tab {
   UINT32    tag;
   UINT32    size;
diff --git a/UefiPayloadPkg/Library/CbSerialPortLib/CbSerialPortLib.c b/UefiPayloadPkg/Library/CbSerialPortLib/CbSerialPortLib.c
new file mode 100644
index 0000000000..7b26c08dd7
--- /dev/null
+++ b/UefiPayloadPkg/Library/CbSerialPortLib/CbSerialPortLib.c
@@ -0,0 +1,272 @@
+/** @file
+  CBMEM console SerialPortLib instance
+
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include <Base.h>
+#include <Coreboot.h>
+
+#include <Library/BaseLib.h>
+#include <Library/BlParseLib.h>
+#include <Library/SerialPortLib.h>
+
+//
+// We can't use DebugLib due to a constructor dependency cycle between DebugLib
+// and ourselves.
+//
+#define ASSERT(Expression)      \
+  do {                          \
+    if (!(Expression)) {        \
+      CpuDeadLoop ();           \
+    }                           \
+  } while (FALSE)
+
+#define CBMC_CURSOR_MASK ((1 << 28) - 1)
+#define CBMC_OVERFLOW (1 << 31)
+
+STATIC struct cbmem_console  *gCbConsole = NULL;
+STATIC UINT32 STM_cursor = 0;
+
+// Try to find the coreboot memory table in the given coreboot table.
+static void *
+find_cb_subtable(struct cb_header *cbh, UINT32 tag)
+{
+  char *tbl = (char *)cbh + sizeof(*cbh);
+  UINT32 count = cbh->table_entries;
+  int i;
+  for (i=0; i<count; i++) {
+    struct cb_memory *cbm = (void*)tbl;
+    tbl += cbm->size;
+    if (cbm->tag == tag)
+      return cbm;
+  }
+    return NULL;
+}
+
+/**
+  Initialize the serial device hardware.
+
+  If no initialization is required, then return RETURN_SUCCESS.
+  If the serial device was successfully initialized, then return RETURN_SUCCESS.
+  If the serial device could not be initialized, then return RETURN_DEVICE_ERROR.
+
+  @retval RETURN_SUCCESS        The serial device was initialized.
+  @retval RETURN_DEVICE_ERROR   The serial device could not be initialized.
+
+**/
+RETURN_STATUS
+EFIAPI
+SerialPortInitialize (
+  VOID
+  )
+{
+  /* `FindCbTag` doesn't work because we need direct access to the memory addresses? */
+  struct cb_header *cbh = GetParameterBase();
+  if (!cbh) {
+    return RETURN_DEVICE_ERROR;
+  }
+
+  struct cb_cbmem_ref *cbref = find_cb_subtable(cbh, CB_TAG_CBMEM_CONSOLE);
+  if (!cbref) {
+    return RETURN_DEVICE_ERROR;
+  }
+
+  gCbConsole = (void *)(UINTN)cbref->cbmem_addr;       // Support PEI and DXE
+  if (gCbConsole == NULL) {
+    return RETURN_DEVICE_ERROR;
+  }
+
+  // set the cursor such that the STM console will not overwrite the
+  // coreboot console output
+  STM_cursor = gCbConsole->cursor & CBMC_CURSOR_MASK;
+
+  return RETURN_SUCCESS;
+}
+
+/**
+  Write data from buffer to serial device.
+
+  Writes NumberOfBytes data bytes from Buffer to the serial device.
+  The number of bytes actually written to the serial device is returned.
+  If the return value is less than NumberOfBytes, then the write operation failed.
+  If Buffer is NULL, then ASSERT().
+  If NumberOfBytes is zero, then return 0.
+
+  @param  Buffer           Pointer to the data buffer to be written.
+  @param  NumberOfBytes    Number of bytes to written to the serial device.
+
+  @retval 0                NumberOfBytes is 0.
+  @retval >0               The number of bytes written to the serial device.
+                           If this value is less than NumberOfBytes, then the write operation failed.
+
+**/
+UINTN
+EFIAPI
+SerialPortWrite (
+  IN UINT8     *Buffer,
+  IN UINTN     NumberOfBytes
+  )
+{
+  UINTN             Sent;
+  UINT32            cursor;
+  UINT32            flags;
+
+  ASSERT (Buffer != NULL);
+
+  if (NumberOfBytes == 0) {
+    return 0;
+  }
+
+  if (!gCbConsole) {
+    return 0;
+  }
+
+  Sent = 0;
+  do {
+    cursor = gCbConsole->cursor & CBMC_CURSOR_MASK;
+    flags = gCbConsole->cursor & ~CBMC_CURSOR_MASK;
+
+    if (cursor >= gCbConsole->size) {
+      return 0;        // Old coreboot version with legacy overflow mechanism.
+    }
+
+    gCbConsole->body[cursor++] = Buffer[Sent++];
+
+    if (cursor >= gCbConsole->size) {
+      cursor = STM_cursor;
+      flags |= CBMC_OVERFLOW;
+    }
+
+    gCbConsole->cursor = flags | cursor;
+  } while (Sent < NumberOfBytes);
+
+  return Sent;
+}
+
+/**
+  Read data from serial device and save the datas in buffer.
+
+  Reads NumberOfBytes data bytes from a serial device into the buffer
+  specified by Buffer. The number of bytes actually read is returned.
+  If Buffer is NULL, then ASSERT().
+  If NumberOfBytes is zero, then return 0.
+
+  @param  Buffer           Pointer to the data buffer to store the data read from the serial device.
+  @param  NumberOfBytes    Number of bytes which will be read.
+
+  @retval 0                Read data failed, no data is to be read.
+  @retval >0               Actual number of bytes read from serial device.
+
+**/
+UINTN
+EFIAPI
+SerialPortRead (
+  OUT UINT8     *Buffer,
+  IN  UINTN     NumberOfBytes
+)
+{
+  return 0;
+}
+
+/**
+  Polls a serial device to see if there is any data waiting to be read.
+
+  @retval TRUE             Data is waiting to be read from the serial device.
+  @retval FALSE            There is no data waiting to be read from the serial device.
+
+**/
+BOOLEAN
+EFIAPI
+SerialPortPoll (
+  VOID
+  )
+{
+  return FALSE;
+}
+
+/**
+  Sets the control bits on a serial device.
+
+  @param Control                Sets the bits of Control that are settable.
+
+  @retval RETURN_SUCCESS        The new control bits were set on the serial device.
+  @retval RETURN_UNSUPPORTED    The serial device does not support this operation.
+  @retval RETURN_DEVICE_ERROR   The serial device is not functioning correctly.
+
+**/
+RETURN_STATUS
+EFIAPI
+SerialPortSetControl (
+  IN UINT32 Control
+  )
+{
+  return RETURN_UNSUPPORTED;
+}
+
+/**
+  Retrieve the status of the control bits on a serial device.
+
+  @param Control                A pointer to return the current control signals from the serial device.
+
+  @retval RETURN_SUCCESS        The control bits were read from the serial device.
+  @retval RETURN_UNSUPPORTED    The serial device does not support this operation.
+  @retval RETURN_DEVICE_ERROR   The serial device is not functioning correctly.
+
+**/
+RETURN_STATUS
+EFIAPI
+SerialPortGetControl (
+  OUT UINT32 *Control
+  )
+{
+  return RETURN_UNSUPPORTED;
+}
+
+/**
+  Sets the baud rate, receive FIFO depth, transmit/receive time out, parity,
+  data bits, and stop bits on a serial device.
+
+  @param BaudRate           The requested baud rate. A BaudRate value of 0 will use the
+                            device's default interface speed.
+                            On output, the value actually set.
+  @param ReceiveFifoDepth   The requested depth of the FIFO on the receive side of the
+                            serial interface. A ReceiveFifoDepth value of 0 will use
+                            the device's default FIFO depth.
+                            On output, the value actually set.
+  @param Timeout            The requested time out for a single character in microseconds.
+                            This timeout applies to both the transmit and receive side of the
+                            interface. A Timeout value of 0 will use the device's default time
+                            out value.
+                            On output, the value actually set.
+  @param Parity             The type of parity to use on this serial device. A Parity value of
+                            DefaultParity will use the device's default parity value.
+                            On output, the value actually set.
+  @param DataBits           The number of data bits to use on the serial device. A DataBits
+                            value of 0 will use the device's default data bit setting.
+                            On output, the value actually set.
+  @param StopBits           The number of stop bits to use on this serial device. A StopBits
+                            value of DefaultStopBits will use the device's default number of
+                            stop bits.
+                            On output, the value actually set.
+
+  @retval RETURN_SUCCESS            The new attributes were set on the serial device.
+  @retval RETURN_UNSUPPORTED        The serial device does not support this operation.
+  @retval RETURN_INVALID_PARAMETER  One or more of the attributes has an unsupported value.
+  @retval RETURN_DEVICE_ERROR       The serial device is not functioning correctly.
+
+**/
+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;
+}
diff --git a/UefiPayloadPkg/Library/CbSerialPortLib/CbSerialPortLib.inf b/UefiPayloadPkg/Library/CbSerialPortLib/CbSerialPortLib.inf
new file mode 100644
index 0000000000..37b33c24ad
--- /dev/null
+++ b/UefiPayloadPkg/Library/CbSerialPortLib/CbSerialPortLib.inf
@@ -0,0 +1,27 @@
+## @file
+#  Component description file for CbSerialPortLib module.
+#
+#  SPDX-License-Identifier: BSD-2-Clause-Patent
+#
+##
+
+[Defines]
+  INF_VERSION                    = 0x00010005
+  BASE_NAME                      = CbSerialPortLib
+  FILE_GUID                      = 0DB3EF12-1426-4086-B012-113184C4CE11
+  MODULE_TYPE                    = BASE
+  VERSION_STRING                 = 0.5
+  LIBRARY_CLASS                  = SerialPortLib
+  CONSTRUCTOR                    = SerialPortInitialize
+
+[Sources]
+  CbSerialPortLib.c
+
+[Packages]
+  MdeModulePkg/MdeModulePkg.dec
+  MdePkg/MdePkg.dec
+  UefiPayloadPkg/UefiPayloadPkg.dec
+
+[LibraryClasses]
+  BaseLib
+  BlParseLib
diff --git a/UefiPayloadPkg/UefiPayloadPkg.dsc b/UefiPayloadPkg/UefiPayloadPkg.dsc
index 3d08edfe31..b3770b9be6 100644
--- a/UefiPayloadPkg/UefiPayloadPkg.dsc
+++ b/UefiPayloadPkg/UefiPayloadPkg.dsc
@@ -33,6 +33,7 @@
   DEFINE UNIVERSAL_PAYLOAD            = FALSE
   DEFINE SECURITY_STUB_ENABLE         = TRUE
   DEFINE SMM_SUPPORT                  = FALSE
+  DEFINE USE_CBMEM_FOR_CONSOLE        = FALSE
   #
   # SBL:      UEFI payload for Slim Bootloader
   # COREBOOT: UEFI payload for coreboot
@@ -223,7 +224,11 @@
   TimerLib|UefiPayloadPkg/Library/AcpiTimerLib/AcpiTimerLib.inf
 !endif
   ResetSystemLib|UefiPayloadPkg/Library/ResetSystemLib/ResetSystemLib.inf
+!if $(USE_CBMEM_FOR_CONSOLE) == TRUE
+  SerialPortLib|UefiPayloadPkg/Library/CbSerialPortLib/CbSerialPortLib.inf
+!else
   SerialPortLib|MdeModulePkg/Library/BaseSerialPortLib16550/BaseSerialPortLib16550.inf
+!endif
   PlatformHookLib|UefiPayloadPkg/Library/PlatformHookLib/PlatformHookLib.inf
   PlatformBootManagerLib|UefiPayloadPkg/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf
   IoApicLib|PcAtChipsetPkg/Library/BaseIoApicLib/BaseIoApicLib.inf
diff --git a/UefiPayloadPkg/UefiPayloadPkg.fdf b/UefiPayloadPkg/UefiPayloadPkg.fdf
index f619a23139..0df8342252 100644
--- a/UefiPayloadPkg/UefiPayloadPkg.fdf
+++ b/UefiPayloadPkg/UefiPayloadPkg.fdf
@@ -15,8 +15,12 @@ DEFINE FD_BLOCK_SIZE = 0x00001000
 !if $(TARGET) == "NOOPT"
 DEFINE FD_SIZE     = 0x00850000
 DEFINE NUM_BLOCKS  = 0x850
-!else

+!elseif $(USE_CBMEM_FOR_CONSOLE) == TRUE
+DEFINE FD_SIZE     = 0x00600000
+DEFINE NUM_BLOCKS  = 0x600
+
+!else
 DEFINE FD_SIZE     = 0x00590000
 DEFINE NUM_BLOCKS  = 0x590
 !endif
--
2.32.0


Sean Rhodes
 

From: Benjamin Doron <benjamin.doron00@gmail.com>

Tested on QEMU, dumping the appropriate memory region in UEFI shell
shows the TianoCore log. `find_cb_subtable` is sourced from STM/SeaBIOS.

Signed-off-by: Benjamin Doron <benjamin.doron00@gmail.com>
---
UefiPayloadPkg/Include/Coreboot.h | 14 +
.../Library/CbSerialPortLib/CbSerialPortLib.c | 272 ++++++++++++++++++
.../CbSerialPortLib/CbSerialPortLib.inf | 27 ++
UefiPayloadPkg/UefiPayloadPkg.dsc | 5 +
UefiPayloadPkg/UefiPayloadPkg.fdf | 6 +-
5 files changed, 323 insertions(+), 1 deletion(-)
create mode 100644 UefiPayloadPkg/Library/CbSerialPortLib/CbSerialPortLib.c
create mode 100644 UefiPayloadPkg/Library/CbSerialPortLib/CbSerialPortLib.=
inf

diff --git a/UefiPayloadPkg/Include/Coreboot.h b/UefiPayloadPkg/Include/Cor=
eboot.h
index a3e1109fe8..f2f577a02e 100644
--- a/UefiPayloadPkg/Include/Coreboot.h
+++ b/UefiPayloadPkg/Include/Coreboot.h
@@ -199,7 +199,14 @@ struct cb_forward {
UINT64 forward;=0D
};=0D
=0D
+struct cb_cbmem_ref {=0D
+ UINT32 tag;=0D
+ UINT32 size;=0D
+ UINT64 cbmem_addr;=0D
+};=0D
+=0D
#define CB_TAG_FRAMEBUFFER 0x0012=0D
+=0D
struct cb_framebuffer {=0D
UINT32 tag;=0D
UINT32 size;=0D
@@ -230,6 +237,13 @@ struct cb_vdat {
#define CB_TAG_TIMESTAMPS 0x0016=0D
#define CB_TAG_CBMEM_CONSOLE 0x0017=0D
#define CB_TAG_MRC_CACHE 0x0018=0D
+=0D
+struct cbmem_console {=0D
+ UINT32 size;=0D
+ UINT32 cursor;=0D
+ UINT8 body[0];=0D
+} __attribute__((packed));=0D
+=0D
struct cb_cbmem_tab {=0D
UINT32 tag;=0D
UINT32 size;=0D
diff --git a/UefiPayloadPkg/Library/CbSerialPortLib/CbSerialPortLib.c b/Uef=
iPayloadPkg/Library/CbSerialPortLib/CbSerialPortLib.c
new file mode 100644
index 0000000000..7b26c08dd7
--- /dev/null
+++ b/UefiPayloadPkg/Library/CbSerialPortLib/CbSerialPortLib.c
@@ -0,0 +1,272 @@
+/** @file=0D
+ CBMEM console SerialPortLib instance=0D
+=0D
+ SPDX-License-Identifier: BSD-2-Clause-Patent=0D
+=0D
+**/=0D
+=0D
+#include <Base.h>=0D
+#include <Coreboot.h>=0D
+=0D
+#include <Library/BaseLib.h>=0D
+#include <Library/BlParseLib.h>=0D
+#include <Library/SerialPortLib.h>=0D
+=0D
+//=0D
+// We can't use DebugLib due to a constructor dependency cycle between Deb=
ugLib=0D
+// and ourselves.=0D
+//=0D
+#define ASSERT(Expression) \=0D
+ do { \=0D
+ if (!(Expression)) { \=0D
+ CpuDeadLoop (); \=0D
+ } \=0D
+ } while (FALSE)=0D
+=0D
+#define CBMC_CURSOR_MASK ((1 << 28) - 1)=0D
+#define CBMC_OVERFLOW (1 << 31)=0D
+=0D
+STATIC struct cbmem_console *gCbConsole =3D NULL;=0D
+STATIC UINT32 STM_cursor =3D 0;=0D
+=0D
+// Try to find the coreboot memory table in the given coreboot table.=0D
+static void *=0D
+find_cb_subtable(struct cb_header *cbh, UINT32 tag)=0D
+{=0D
+ char *tbl =3D (char *)cbh + sizeof(*cbh);=0D
+ UINT32 count =3D cbh->table_entries;=0D
+ int i;=0D
+ for (i=3D0; i<count; i++) {=0D
+ struct cb_memory *cbm =3D (void*)tbl;=0D
+ tbl +=3D cbm->size;=0D
+ if (cbm->tag =3D=3D tag)=0D
+ return cbm;=0D
+ }=0D
+ return NULL;=0D
+}=0D
+=0D
+/**=0D
+ Initialize the serial device hardware.=0D
+=0D
+ If no initialization is required, then return RETURN_SUCCESS.=0D
+ If the serial device was successfully initialized, then return RETURN_SU=
CCESS.=0D
+ If the serial device could not be initialized, then return RETURN_DEVICE=
_ERROR.=0D
+=0D
+ @retval RETURN_SUCCESS The serial device was initialized.=0D
+ @retval RETURN_DEVICE_ERROR The serial device could not be initialized=
.=0D
+=0D
+**/=0D
+RETURN_STATUS=0D
+EFIAPI=0D
+SerialPortInitialize (=0D
+ VOID=0D
+ )=0D
+{=0D
+ /* `FindCbTag` doesn't work because we need direct access to the memory =
addresses? */=0D
+ struct cb_header *cbh =3D GetParameterBase();=0D
+ if (!cbh) {=0D
+ return RETURN_DEVICE_ERROR;=0D
+ }=0D
+=0D
+ struct cb_cbmem_ref *cbref =3D find_cb_subtable(cbh, CB_TAG_CBMEM_CONSOL=
E);=0D
+ if (!cbref) {=0D
+ return RETURN_DEVICE_ERROR;=0D
+ }=0D
+=0D
+ gCbConsole =3D (void *)(UINTN)cbref->cbmem_addr; // Support PEI and DXE=
=0D
+ if (gCbConsole =3D=3D NULL) {=0D
+ return RETURN_DEVICE_ERROR;=0D
+ }=0D
+=0D
+ // set the cursor such that the STM console will not overwrite the=0D
+ // coreboot console output=0D
+ STM_cursor =3D gCbConsole->cursor & CBMC_CURSOR_MASK;=0D
+=0D
+ return RETURN_SUCCESS;=0D
+}=0D
+=0D
+/**=0D
+ Write data from buffer to serial device.=0D
+=0D
+ Writes NumberOfBytes data bytes from Buffer to the serial device.=0D
+ The number of bytes actually written to the serial device is returned.=0D
+ If the return value is less than NumberOfBytes, then the write operation=
failed.=0D
+ If Buffer is NULL, then ASSERT().=0D
+ If NumberOfBytes is zero, then return 0.=0D
+=0D
+ @param Buffer Pointer to the data buffer to be written.=0D
+ @param NumberOfBytes Number of bytes to written to the serial device=
.=0D
+=0D
+ @retval 0 NumberOfBytes is 0.=0D
+ @retval >0 The number of bytes written to the serial devic=
e.=0D
+ If this value is less than NumberOfBytes, then =
the write operation failed.=0D
+=0D
+**/=0D
+UINTN=0D
+EFIAPI=0D
+SerialPortWrite (=0D
+ IN UINT8 *Buffer,=0D
+ IN UINTN NumberOfBytes=0D
+ )=0D
+{=0D
+ UINTN Sent;=0D
+ UINT32 cursor;=0D
+ UINT32 flags;=0D
+=0D
+ ASSERT (Buffer !=3D NULL);=0D
+=0D
+ if (NumberOfBytes =3D=3D 0) {=0D
+ return 0;=0D
+ }=0D
+=0D
+ if (!gCbConsole) {=0D
+ return 0;=0D
+ }=0D
+=0D
+ Sent =3D 0;=0D
+ do {=0D
+ cursor =3D gCbConsole->cursor & CBMC_CURSOR_MASK;=0D
+ flags =3D gCbConsole->cursor & ~CBMC_CURSOR_MASK;=0D
+=0D
+ if (cursor >=3D gCbConsole->size) {=0D
+ return 0; // Old coreboot version with legacy overflow mechanism.=0D
+ }=0D
+=0D
+ gCbConsole->body[cursor++] =3D Buffer[Sent++];=0D
+=0D
+ if (cursor >=3D gCbConsole->size) {=0D
+ cursor =3D STM_cursor;=0D
+ flags |=3D CBMC_OVERFLOW;=0D
+ }=0D
+=0D
+ gCbConsole->cursor =3D flags | cursor;=0D
+ } while (Sent < NumberOfBytes);=0D
+=0D
+ return Sent;=0D
+}=0D
+=0D
+/**=0D
+ Read data from serial device and save the datas in buffer.=0D
+=0D
+ Reads NumberOfBytes data bytes from a serial device into the buffer=0D
+ specified by Buffer. The number of bytes actually read is returned.=0D
+ If Buffer is NULL, then ASSERT().=0D
+ If NumberOfBytes is zero, then return 0.=0D
+=0D
+ @param Buffer Pointer to the data buffer to store the data re=
ad from the serial device.=0D
+ @param NumberOfBytes Number of bytes which will be read.=0D
+=0D
+ @retval 0 Read data failed, no data is to be read.=0D
+ @retval >0 Actual number of bytes read from serial device.=
=0D
+=0D
+**/=0D
+UINTN=0D
+EFIAPI=0D
+SerialPortRead (=0D
+ OUT UINT8 *Buffer,=0D
+ IN UINTN NumberOfBytes=0D
+)=0D
+{=0D
+ return 0;=0D
+}=0D
+=0D
+/**=0D
+ Polls a serial device to see if there is any data waiting to be read.=0D
+=0D
+ @retval TRUE Data is waiting to be read from the serial devi=
ce.=0D
+ @retval FALSE There is no data waiting to be read from the se=
rial device.=0D
+=0D
+**/=0D
+BOOLEAN=0D
+EFIAPI=0D
+SerialPortPoll (=0D
+ VOID=0D
+ )=0D
+{=0D
+ return FALSE;=0D
+}=0D
+=0D
+/**=0D
+ Sets the control bits on a serial device.=0D
+=0D
+ @param Control Sets the bits of Control that are settable=
.=0D
+=0D
+ @retval RETURN_SUCCESS The new control bits were set on the seria=
l device.=0D
+ @retval RETURN_UNSUPPORTED The serial device does not support this op=
eration.=0D
+ @retval RETURN_DEVICE_ERROR The serial device is not functioning corre=
ctly.=0D
+=0D
+**/=0D
+RETURN_STATUS=0D
+EFIAPI=0D
+SerialPortSetControl (=0D
+ IN UINT32 Control=0D
+ )=0D
+{=0D
+ return RETURN_UNSUPPORTED;=0D
+}=0D
+=0D
+/**=0D
+ Retrieve the status of the control bits on a serial device.=0D
+=0D
+ @param Control A pointer to return the current control si=
gnals from the serial device.=0D
+=0D
+ @retval RETURN_SUCCESS The control bits were read from the serial=
device.=0D
+ @retval RETURN_UNSUPPORTED The serial device does not support this op=
eration.=0D
+ @retval RETURN_DEVICE_ERROR The serial device is not functioning corre=
ctly.=0D
+=0D
+**/=0D
+RETURN_STATUS=0D
+EFIAPI=0D
+SerialPortGetControl (=0D
+ OUT UINT32 *Control=0D
+ )=0D
+{=0D
+ return RETURN_UNSUPPORTED;=0D
+}=0D
+=0D
+/**=0D
+ Sets the baud rate, receive FIFO depth, transmit/receive time out, parit=
y,=0D
+ data bits, and stop bits on a serial device.=0D
+=0D
+ @param BaudRate The requested baud rate. A BaudRate value of 0=
will use the=0D
+ device's default interface speed.=0D
+ On output, the value actually set.=0D
+ @param ReceiveFifoDepth The requested depth of the FIFO on the receive=
side of the=0D
+ serial interface. A ReceiveFifoDepth value of =
0 will use=0D
+ the device's default FIFO depth.=0D
+ On output, the value actually set.=0D
+ @param Timeout The requested time out for a single character =
in microseconds.=0D
+ This timeout applies to both the transmit and =
receive side of the=0D
+ interface. A Timeout value of 0 will use the d=
evice's default time=0D
+ out value.=0D
+ On output, the value actually set.=0D
+ @param Parity The type of parity to use on this serial devic=
e. A Parity value of=0D
+ DefaultParity will use the device's default pa=
rity value.=0D
+ On output, the value actually set.=0D
+ @param DataBits The number of data bits to use on the serial d=
evice. A DataBits=0D
+ value of 0 will use the device's default data =
bit setting.=0D
+ On output, the value actually set.=0D
+ @param StopBits The number of stop bits to use on this serial =
device. A StopBits=0D
+ value of DefaultStopBits will use the device's=
default number of=0D
+ stop bits.=0D
+ On output, the value actually set.=0D
+=0D
+ @retval RETURN_SUCCESS The new attributes were set on the ser=
ial device.=0D
+ @retval RETURN_UNSUPPORTED The serial device does not support thi=
s operation.=0D
+ @retval RETURN_INVALID_PARAMETER One or more of the attributes has an u=
nsupported value.=0D
+ @retval RETURN_DEVICE_ERROR The serial device is not functioning c=
orrectly.=0D
+=0D
+**/=0D
+RETURN_STATUS=0D
+EFIAPI=0D
+SerialPortSetAttributes (=0D
+ IN OUT UINT64 *BaudRate,=0D
+ IN OUT UINT32 *ReceiveFifoDepth,=0D
+ IN OUT UINT32 *Timeout,=0D
+ IN OUT EFI_PARITY_TYPE *Parity,=0D
+ IN OUT UINT8 *DataBits,=0D
+ IN OUT EFI_STOP_BITS_TYPE *StopBits=0D
+ )=0D
+{=0D
+ return RETURN_UNSUPPORTED;=0D
+}=0D
diff --git a/UefiPayloadPkg/Library/CbSerialPortLib/CbSerialPortLib.inf b/U=
efiPayloadPkg/Library/CbSerialPortLib/CbSerialPortLib.inf
new file mode 100644
index 0000000000..37b33c24ad
--- /dev/null
+++ b/UefiPayloadPkg/Library/CbSerialPortLib/CbSerialPortLib.inf
@@ -0,0 +1,27 @@
+## @file=0D
+# Component description file for CbSerialPortLib module.=0D
+#=0D
+# SPDX-License-Identifier: BSD-2-Clause-Patent=0D
+#=0D
+##=0D
+=0D
+[Defines]=0D
+ INF_VERSION =3D 0x00010005=0D
+ BASE_NAME =3D CbSerialPortLib=0D
+ FILE_GUID =3D 0DB3EF12-1426-4086-B012-113184C4CE11=
=0D
+ MODULE_TYPE =3D BASE=0D
+ VERSION_STRING =3D 0.5=0D
+ LIBRARY_CLASS =3D SerialPortLib=0D
+ CONSTRUCTOR =3D SerialPortInitialize=0D
+=0D
+[Sources]=0D
+ CbSerialPortLib.c=0D
+=0D
+[Packages]=0D
+ MdeModulePkg/MdeModulePkg.dec=0D
+ MdePkg/MdePkg.dec=0D
+ UefiPayloadPkg/UefiPayloadPkg.dec=0D
+=0D
+[LibraryClasses]=0D
+ BaseLib=0D
+ BlParseLib=0D
diff --git a/UefiPayloadPkg/UefiPayloadPkg.dsc b/UefiPayloadPkg/UefiPayload=
Pkg.dsc
index 3d08edfe31..b3770b9be6 100644
--- a/UefiPayloadPkg/UefiPayloadPkg.dsc
+++ b/UefiPayloadPkg/UefiPayloadPkg.dsc
@@ -33,6 +33,7 @@
DEFINE UNIVERSAL_PAYLOAD =3D FALSE=0D
DEFINE SECURITY_STUB_ENABLE =3D TRUE=0D
DEFINE SMM_SUPPORT =3D FALSE=0D
+ DEFINE USE_CBMEM_FOR_CONSOLE =3D FALSE=0D
#=0D
# SBL: UEFI payload for Slim Bootloader=0D
# COREBOOT: UEFI payload for coreboot=0D
@@ -223,7 +224,11 @@
TimerLib|UefiPayloadPkg/Library/AcpiTimerLib/AcpiTimerLib.inf=0D
!endif=0D
ResetSystemLib|UefiPayloadPkg/Library/ResetSystemLib/ResetSystemLib.inf=
=0D
+!if $(USE_CBMEM_FOR_CONSOLE) =3D=3D TRUE=0D
+ SerialPortLib|UefiPayloadPkg/Library/CbSerialPortLib/CbSerialPortLib.inf=
=0D
+!else=0D
SerialPortLib|MdeModulePkg/Library/BaseSerialPortLib16550/BaseSerialPort=
Lib16550.inf=0D
+!endif=0D
PlatformHookLib|UefiPayloadPkg/Library/PlatformHookLib/PlatformHookLib.i=
nf=0D
PlatformBootManagerLib|UefiPayloadPkg/Library/PlatformBootManagerLib/Pla=
tformBootManagerLib.inf=0D
IoApicLib|PcAtChipsetPkg/Library/BaseIoApicLib/BaseIoApicLib.inf=0D
diff --git a/UefiPayloadPkg/UefiPayloadPkg.fdf b/UefiPayloadPkg/UefiPayload=
Pkg.fdf
index f619a23139..0df8342252 100644
--- a/UefiPayloadPkg/UefiPayloadPkg.fdf
+++ b/UefiPayloadPkg/UefiPayloadPkg.fdf
@@ -15,8 +15,12 @@ DEFINE FD_BLOCK_SIZE =3D 0x00001000
!if $(TARGET) =3D=3D "NOOPT"=0D
DEFINE FD_SIZE =3D 0x00850000=0D
DEFINE NUM_BLOCKS =3D 0x850=0D
-!else=0D
=0D
+!elseif $(USE_CBMEM_FOR_CONSOLE) =3D=3D TRUE=0D
+DEFINE FD_SIZE =3D 0x00600000=0D
+DEFINE NUM_BLOCKS =3D 0x600=0D
+=0D
+!else=0D
DEFINE FD_SIZE =3D 0x00590000=0D
DEFINE NUM_BLOCKS =3D 0x590=0D
!endif=0D
--=20
2.32.0


Sean Rhodes
 

Hey Benjamin

The commit has been around for a while now and is perfectly functional. Why don't we upstream it and then `FindCbTag()` and `CopyMem()` can be a follow-up patch when/if time allows?

Cheers
Sean

Squashing that commit in:
[PATCH] UefiPayloadPkg: Add support for logging to CBMEM console
 
Tested on QEMU, dumping the appropriate memory region in UEFI shell
shows the TianoCore log. `find_cb_subtable` is sourced from STM/SeaBIOS.
 
Signed-off-by: Benjamin Doron <benjamin.doron00@...>
---
 UefiPayloadPkg/Include/Coreboot.h             |  14 +
 .../Library/CbSerialPortLib/CbSerialPortLib.c | 272 ++++++++++++++++++
 .../CbSerialPortLib/CbSerialPortLib.inf       |  27 ++
 UefiPayloadPkg/UefiPayloadPkg.dsc             |   5 +
 UefiPayloadPkg/UefiPayloadPkg.fdf             |   6 +-
 5 files changed, 323 insertions(+), 1 deletion(-)
 create mode 100644 UefiPayloadPkg/Library/CbSerialPortLib/CbSerialPortLib.c
 create mode 100644 UefiPayloadPkg/Library/CbSerialPortLib/CbSerialPortLib.inf
 
diff --git a/UefiPayloadPkg/Include/Coreboot.h b/UefiPayloadPkg/Include/Coreboot.h
index a3e1109fe8..f2f577a02e 100644
--- a/UefiPayloadPkg/Include/Coreboot.h
+++ b/UefiPayloadPkg/Include/Coreboot.h
@@ -199,7 +199,14 @@ struct cb_forward {
   UINT64    forward;
 };
 
+struct cb_cbmem_ref {
+  UINT32 tag;
+  UINT32 size;
+  UINT64 cbmem_addr;
+};
+
 #define CB_TAG_FRAMEBUFFER  0x0012
+
 struct cb_framebuffer {
   UINT32    tag;
   UINT32    size;
@@ -230,6 +237,13 @@ struct cb_vdat {
 #define CB_TAG_TIMESTAMPS     0x0016
 #define CB_TAG_CBMEM_CONSOLE  0x0017
 #define CB_TAG_MRC_CACHE      0x0018
+
+struct cbmem_console {
+  UINT32 size;
+  UINT32 cursor;
+  UINT8  body[0];
+} __attribute__((packed));
+
 struct cb_cbmem_tab {
   UINT32    tag;
   UINT32    size;
diff --git a/UefiPayloadPkg/Library/CbSerialPortLib/CbSerialPortLib.c b/UefiPayloadPkg/Library/CbSerialPortLib/CbSerialPortLib.c
new file mode 100644
index 0000000000..7b26c08dd7
--- /dev/null
+++ b/UefiPayloadPkg/Library/CbSerialPortLib/CbSerialPortLib.c
@@ -0,0 +1,272 @@
+/** @file
+  CBMEM console SerialPortLib instance
+
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include <Base.h>
+#include <Coreboot.h>
+
+#include <Library/BaseLib.h>
+#include <Library/BlParseLib.h>
+#include <Library/SerialPortLib.h>
+
+//
+// We can't use DebugLib due to a constructor dependency cycle between DebugLib
+// and ourselves.
+//
+#define ASSERT(Expression)      \
+  do {                          \
+    if (!(Expression)) {        \
+      CpuDeadLoop ();           \
+    }                           \
+  } while (FALSE)
+
+#define CBMC_CURSOR_MASK ((1 << 28) - 1)
+#define CBMC_OVERFLOW (1 << 31)
+
+STATIC struct cbmem_console  *gCbConsole = NULL;
+STATIC UINT32 STM_cursor = 0;
+
+// Try to find the coreboot memory table in the given coreboot table.
+static void *
+find_cb_subtable(struct cb_header *cbh, UINT32 tag)
+{
+  char *tbl = (char *)cbh + sizeof(*cbh);
+  UINT32 count = cbh->table_entries;
+  int i;
+  for (i=0; i<count; i++) {
+    struct cb_memory *cbm = (void*)tbl;
+    tbl += cbm->size;
+    if (cbm->tag == tag)
+      return cbm;
+  }
+    return NULL;
+}
+
+/**
+  Initialize the serial device hardware.
+
+  If no initialization is required, then return RETURN_SUCCESS.
+  If the serial device was successfully initialized, then return RETURN_SUCCESS.
+  If the serial device could not be initialized, then return RETURN_DEVICE_ERROR.
+
+  @retval RETURN_SUCCESS        The serial device was initialized.
+  @retval RETURN_DEVICE_ERROR   The serial device could not be initialized.
+
+**/
+RETURN_STATUS
+EFIAPI
+SerialPortInitialize (
+  VOID
+  )
+{
+  /* `FindCbTag` doesn't work because we need direct access to the memory addresses? */
+  struct cb_header *cbh = GetParameterBase();
+  if (!cbh) {
+    return RETURN_DEVICE_ERROR;
+  }
+
+  struct cb_cbmem_ref *cbref = find_cb_subtable(cbh, CB_TAG_CBMEM_CONSOLE);
+  if (!cbref) {
+    return RETURN_DEVICE_ERROR;
+  }
+
+  gCbConsole = (void *)(UINTN)cbref->cbmem_addr; // Support PEI and DXE
+  if (gCbConsole == NULL) {
+    return RETURN_DEVICE_ERROR;
+  }
+
+  // set the cursor such that the STM console will not overwrite the
+  // coreboot console output
+  STM_cursor = gCbConsole->cursor & CBMC_CURSOR_MASK;
+
+  return RETURN_SUCCESS;
+}
+
+/**
+  Write data from buffer to serial device.
+
+  Writes NumberOfBytes data bytes from Buffer to the serial device.
+  The number of bytes actually written to the serial device is returned.
+  If the return value is less than NumberOfBytes, then the write operation failed.
+  If Buffer is NULL, then ASSERT().
+  If NumberOfBytes is zero, then return 0.
+
+  @param  Buffer           Pointer to the data buffer to be written.
+  @param  NumberOfBytes    Number of bytes to written to the serial device.
+
+  @retval 0                NumberOfBytes is 0.
+  @retval >0               The number of bytes written to the serial device.
+                           If this value is less than NumberOfBytes, then the write operation failed.
+
+**/
+UINTN
+EFIAPI
+SerialPortWrite (
+  IN UINT8     *Buffer,
+  IN UINTN     NumberOfBytes
+  )
+{
+  UINTN             Sent;
+  UINT32            cursor;
+  UINT32            flags;
+
+  ASSERT (Buffer != NULL);
+
+  if (NumberOfBytes == 0) {
+    return 0;
+  }
+
+  if (!gCbConsole) {
+    return 0;
+  }
+
+  Sent = 0;
+  do {
+    cursor = gCbConsole->cursor & CBMC_CURSOR_MASK;
+    flags = gCbConsole->cursor & ~CBMC_CURSOR_MASK;
+
+    if (cursor >= gCbConsole->size) {
+      return 0; // Old coreboot version with legacy overflow mechanism.
+    }
+
+    gCbConsole->body[cursor++] = Buffer[Sent++];
+
+    if (cursor >= gCbConsole->size) {
+      cursor = STM_cursor;
+      flags |= CBMC_OVERFLOW;
+    }
+
+    gCbConsole->cursor = flags | cursor;
+  } while (Sent < NumberOfBytes);
+
+  return Sent;
+}
+
+/**
+  Read data from serial device and save the datas in buffer.
+
+  Reads NumberOfBytes data bytes from a serial device into the buffer
+  specified by Buffer. The number of bytes actually read is returned.
+  If Buffer is NULL, then ASSERT().
+  If NumberOfBytes is zero, then return 0.
+
+  @param  Buffer           Pointer to the data buffer to store the data read from the serial device.
+  @param  NumberOfBytes    Number of bytes which will be read.
+
+  @retval 0                Read data failed, no data is to be read.
+  @retval >0               Actual number of bytes read from serial device.
+
+**/
+UINTN
+EFIAPI
+SerialPortRead (
+  OUT UINT8     *Buffer,
+  IN  UINTN     NumberOfBytes
+)
+{
+  return 0;
+}
+
+/**
+  Polls a serial device to see if there is any data waiting to be read.
+
+  @retval TRUE             Data is waiting to be read from the serial device.
+  @retval FALSE            There is no data waiting to be read from the serial device.
+
+**/
+BOOLEAN
+EFIAPI
+SerialPortPoll (
+  VOID
+  )
+{
+  return FALSE;
+}
+
+/**
+  Sets the control bits on a serial device.
+
+  @param Control                Sets the bits of Control that are settable.
+
+  @retval RETURN_SUCCESS        The new control bits were set on the serial device.
+  @retval RETURN_UNSUPPORTED    The serial device does not support this operation.
+  @retval RETURN_DEVICE_ERROR   The serial device is not functioning correctly.
+
+**/
+RETURN_STATUS
+EFIAPI
+SerialPortSetControl (
+  IN UINT32 Control
+  )
+{
+  return RETURN_UNSUPPORTED;
+}
+
+/**
+  Retrieve the status of the control bits on a serial device.
+
+  @param Control                A pointer to return the current control signals from the serial device.
+
+  @retval RETURN_SUCCESS        The control bits were read from the serial device.
+  @retval RETURN_UNSUPPORTED    The serial device does not support this operation.
+  @retval RETURN_DEVICE_ERROR   The serial device is not functioning correctly.
+
+**/
+RETURN_STATUS
+EFIAPI
+SerialPortGetControl (
+  OUT UINT32 *Control
+  )
+{
+  return RETURN_UNSUPPORTED;
+}
+
+/**
+  Sets the baud rate, receive FIFO depth, transmit/receive time out, parity,
+  data bits, and stop bits on a serial device.
+
+  @param BaudRate           The requested baud rate. A BaudRate value of 0 will use the
+                            device's default interface speed.
+                            On output, the value actually set.
+  @param ReceiveFifoDepth   The requested depth of the FIFO on the receive side of the
+                            serial interface. A ReceiveFifoDepth value of 0 will use
+                            the device's default FIFO depth.
+                            On output, the value actually set.
+  @param Timeout            The requested time out for a single character in microseconds.
+                            This timeout applies to both the transmit and receive side of the
+                            interface. A Timeout value of 0 will use the device's default time
+                            out value.
+                            On output, the value actually set.
+  @param Parity             The type of parity to use on this serial device. A Parity value of
+                            DefaultParity will use the device's default parity value.
+                            On output, the value actually set.
+  @param DataBits           The number of data bits to use on the serial device. A DataBits
+                            value of 0 will use the device's default data bit setting.
+                            On output, the value actually set.
+  @param StopBits           The number of stop bits to use on this serial device. A StopBits
+                            value of DefaultStopBits will use the device's default number of
+                            stop bits.
+                            On output, the value actually set.
+
+  @retval RETURN_SUCCESS            The new attributes were set on the serial device.
+  @retval RETURN_UNSUPPORTED        The serial device does not support this operation.
+  @retval RETURN_INVALID_PARAMETER  One or more of the attributes has an unsupported value.
+  @retval RETURN_DEVICE_ERROR       The serial device is not functioning correctly.
+
+**/
+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;
+}
diff --git a/UefiPayloadPkg/Library/CbSerialPortLib/CbSerialPortLib.inf b/UefiPayloadPkg/Library/CbSerialPortLib/CbSerialPortLib.inf
new file mode 100644
index 0000000000..37b33c24ad
--- /dev/null
+++ b/UefiPayloadPkg/Library/CbSerialPortLib/CbSerialPortLib.inf
@@ -0,0 +1,27 @@
+## @file
+#  Component description file for CbSerialPortLib module.
+#
+#  SPDX-License-Identifier: BSD-2-Clause-Patent
+#
+##
+
+[Defines]
+  INF_VERSION                    = 0x00010005
+  BASE_NAME                      = CbSerialPortLib
+  FILE_GUID                      = 0DB3EF12-1426-4086-B012-113184C4CE11
+  MODULE_TYPE                    = BASE
+  VERSION_STRING                 = 0.5
+  LIBRARY_CLASS                  = SerialPortLib
+  CONSTRUCTOR                    = SerialPortInitialize
+
+[Sources]
+  CbSerialPortLib.c
+
+[Packages]
+  MdeModulePkg/MdeModulePkg.dec
+  MdePkg/MdePkg.dec
+  UefiPayloadPkg/UefiPayloadPkg.dec
+
+[LibraryClasses]
+  BaseLib
+  BlParseLib
diff --git a/UefiPayloadPkg/UefiPayloadPkg.dsc b/UefiPayloadPkg/UefiPayloadPkg.dsc
index 3d08edfe31..b3770b9be6 100644
--- a/UefiPayloadPkg/UefiPayloadPkg.dsc
+++ b/UefiPayloadPkg/UefiPayloadPkg.dsc
@@ -33,6 +33,7 @@
   DEFINE UNIVERSAL_PAYLOAD            = FALSE
   DEFINE SECURITY_STUB_ENABLE         = TRUE
   DEFINE SMM_SUPPORT                  = FALSE
+  DEFINE USE_CBMEM_FOR_CONSOLE        = FALSE
   #
   # SBL:      UEFI payload for Slim Bootloader
   # COREBOOT: UEFI payload for coreboot
@@ -223,7 +224,11 @@
   TimerLib|UefiPayloadPkg/Library/AcpiTimerLib/AcpiTimerLib.inf
 !endif
   ResetSystemLib|UefiPayloadPkg/Library/ResetSystemLib/ResetSystemLib.inf
+!if $(USE_CBMEM_FOR_CONSOLE) == TRUE
+  SerialPortLib|UefiPayloadPkg/Library/CbSerialPortLib/CbSerialPortLib.inf
+!else
   SerialPortLib|MdeModulePkg/Library/BaseSerialPortLib16550/BaseSerialPortLib16550.inf
+!endif
   PlatformHookLib|UefiPayloadPkg/Library/PlatformHookLib/PlatformHookLib.inf
   PlatformBootManagerLib|UefiPayloadPkg/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf
   IoApicLib|PcAtChipsetPkg/Library/BaseIoApicLib/BaseIoApicLib.inf
diff --git a/UefiPayloadPkg/UefiPayloadPkg.fdf b/UefiPayloadPkg/UefiPayloadPkg.fdf
index f619a23139..0df8342252 100644
--- a/UefiPayloadPkg/UefiPayloadPkg.fdf
+++ b/UefiPayloadPkg/UefiPayloadPkg.fdf
@@ -15,8 +15,12 @@ DEFINE FD_BLOCK_SIZE = 0x00001000
 !if $(TARGET) == "NOOPT"
 DEFINE FD_SIZE     = 0x00850000
 DEFINE NUM_BLOCKS  = 0x850
-!else
 
+!elseif $(USE_CBMEM_FOR_CONSOLE) == TRUE
+DEFINE FD_SIZE     = 0x00600000
+DEFINE NUM_BLOCKS  = 0x600
+
+!else
 DEFINE FD_SIZE     = 0x00590000
 DEFINE NUM_BLOCKS  = 0x590
 !endif
-- 
2.32.0
 


Sheng Lean Tan
 

Hi Ray,
Could you help to review this?