Skip to content

Commit

Permalink
OcMainLib: Read and set serial PCD values from config (#330)
Browse files Browse the repository at this point in the history
  • Loading branch information
PMheart authored Apr 4, 2022
1 parent 6974c1f commit 6825e9a
Show file tree
Hide file tree
Showing 10 changed files with 397 additions and 29 deletions.
149 changes: 128 additions & 21 deletions Docs/Configuration.tex
Original file line number Diff line number Diff line change
Expand Up @@ -3157,6 +3157,17 @@ \subsection{Properties}\label{miscprops}
\textbf{Description}: Apply the security configuration described in the
\hyperref[miscsecurityprops]{Security Properties} section below.

\item
\texttt{Serial}\\
\textbf{Type}: \texttt{plist\ dict}\\
\textbf{Description}: Configure PCD values required by \texttt{BaseSerialPortLib16550}
for serial ports to properly function. Values are listed and described in the
\hyperref[miscserialprops]{Serial Properties} section below.

This section overrides the PCD values listed in
\href{https://github.com/acidanthera/audk/blob/master/MdeModulePkg/Library/BaseSerialPortLib16550/BaseSerialPortLib16550.inf}{BaseSerialPortLib16550.inf}.
Refer to \href{https://github.com/acidanthera/audk/blob/master/MdeModulePkg/MdeModulePkg.dec}{MdeModulePkg.dec} for the explanations of each key.

\item
\texttt{Tools}\label{misctools}\\
\textbf{Type}: \texttt{plist\ array}\\
Expand Down Expand Up @@ -3744,26 +3755,6 @@ \subsection{Debug Properties}\label{miscdebugprops}
\emph{Note 2}: Messages printed before the configuration of log protocol
cannot be filtered.

\item
\texttt{SerialInit}\\
\textbf{Type}: \texttt{plist\ boolean}\\
\textbf{Failsafe}: \texttt{false}\\
\textbf{Description}: Perform serial port initialisation.

This option will perform serial port initialisation within OpenCore prior to enabling
(any) debug logging. Serial port configuration is defined via PCDs at compile time
in \texttt{gEfiMdeModulePkgTokenSpaceGuid} GUID.

Default values as found in \texttt{MdeModulePkg.dec} are as follows:

\begin{itemize}
\tightlist
\item \texttt{PcdSerialBaudRate} --- Baud rate: \texttt{115200}.
\item \texttt{PcdSerialLineControl} --- Line control: no parity, 8 data bits, 1 stop bit.
\end{itemize}

Refer to the \hyperref[troubleshootingdebug]{\texttt{Debugging}} section for details.

\item
\texttt{SysReport}\\
\textbf{Type}: \texttt{plist\ boolean}\\
Expand Down Expand Up @@ -4425,6 +4416,122 @@ \subsection{Security Properties}\label{miscsecurityprops}

\end{enumerate}

\subsection{Serial Properties}\label{miscserialprops}

\begin{enumerate}
\item
\texttt{BaudRate}\\
\textbf{Type}: \texttt{plist\ integer}\\
\textbf{Failsafe}: \texttt{115200}\\
\textbf{Description}: Set the baud rate for serial port.

This option will override the value of \texttt{gEfiMdeModulePkgTokenSpaceGuid.PcdSerialBaudRate}
defined in \href{https://github.com/acidanthera/audk/blob/master/MdeModulePkg/MdeModulePkg.dec}{MdeModulePkg.dec}.

\item
\texttt{ClockRate}\\
\textbf{Type}: \texttt{plist\ integer}\\
\textbf{Failsafe}: \texttt{1843200}\\
\textbf{Description}: Set the clock rate for serial port.

This option will override the value of \texttt{gEfiMdeModulePkgTokenSpaceGuid.PcdSerialClockRate}
defined in \href{https://github.com/acidanthera/audk/blob/master/MdeModulePkg/MdeModulePkg.dec}{MdeModulePkg.dec}.

\item
\texttt{ExtendedTxFifoSize}\\
\textbf{Type}: \texttt{plist\ integer}\\
\textbf{Failsafe}: \texttt{64}\\
\textbf{Description}: Set the extended transmit FIFO size for serial port.

This option will override the value of \texttt{gEfiMdeModulePkgTokenSpaceGuid.PcdSerialExtendedTxFifoSize}
defined in \href{https://github.com/acidanthera/audk/blob/master/MdeModulePkg/MdeModulePkg.dec}{MdeModulePkg.dec}.

\item
\texttt{FifoControl}\\
\textbf{Type}: \texttt{plist\ integer}\\
\textbf{Failsafe}: \texttt{0x07}\\
\textbf{Description}: Configure serial port FIFO Control settings.

This option will override the value of \texttt{gEfiMdeModulePkgTokenSpaceGuid.PcdSerialFifoControl}
defined in \href{https://github.com/acidanthera/audk/blob/master/MdeModulePkg/MdeModulePkg.dec}{MdeModulePkg.dec}.

\item
\texttt{Init}\\
\textbf{Type}: \texttt{plist\ boolean}\\
\textbf{Failsafe}: \texttt{false}\\
\textbf{Description}: Perform serial port initialisation.
When this option is set to \texttt{false}, no keys from this section will be overridden.

This option will perform serial port initialisation within OpenCore prior to enabling
(any) debug logging.

Refer to the \hyperref[troubleshootingdebug]{\texttt{Debugging}} section for details.

\item
\texttt{LineControl}\\
\textbf{Type}: \texttt{plist\ integer}\\
\textbf{Failsafe}: \texttt{0x07}\\
\textbf{Description}: Configure serial port Line Control settings.

This option will override the value of \texttt{gEfiMdeModulePkgTokenSpaceGuid.PcdSerialLineControl}
defined in \href{https://github.com/acidanthera/audk/blob/master/MdeModulePkg/MdeModulePkg.dec}{MdeModulePkg.dec}.

\item
\texttt{PciDeviceInfo}\\
\textbf{Type}: \texttt{plist\ data}\\
\textbf{Failsafe}: \texttt{0xFF}\\
\textbf{Description}: Set PCI serial device information.

This option will override the value of \texttt{gEfiMdeModulePkgTokenSpaceGuid.PcdSerialPciDeviceInfo}
defined in \href{https://github.com/acidanthera/audk/blob/master/MdeModulePkg/MdeModulePkg.dec}{MdeModulePkg.dec}.

\item
\texttt{RegisterAccessWidth}\\
\textbf{Type}: \texttt{plist\ integer}\\
\textbf{Failsafe}: \texttt{8}\\
\textbf{Description}: Set serial port register access width.

This option will override the value of \texttt{gEfiMdeModulePkgTokenSpaceGuid.PcdSerialRegisterAccessWidth}
defined in \href{https://github.com/acidanthera/audk/blob/master/MdeModulePkg/MdeModulePkg.dec}{MdeModulePkg.dec}.

\item
\texttt{RegisterBase}\\
\textbf{Type}: \texttt{plist\ integer}\\
\textbf{Failsafe}: \texttt{0x03F8}\\
\textbf{Description}: Set the base address of serial port registers.

This option will override the value of \texttt{gEfiMdeModulePkgTokenSpaceGuid.PcdSerialRegisterBase}
defined in \href{https://github.com/acidanthera/audk/blob/master/MdeModulePkg/MdeModulePkg.dec}{MdeModulePkg.dec}.

\item
\texttt{RegisterStride}\\
\textbf{Type}: \texttt{plist\ integer}\\
\textbf{Failsafe}: \texttt{1}\\
\textbf{Description}: Set the serial port register stride in bytes.

This option will override the value of \texttt{gEfiMdeModulePkgTokenSpaceGuid.PcdSerialRegisterStride}
defined in \href{https://github.com/acidanthera/audk/blob/master/MdeModulePkg/MdeModulePkg.dec}{MdeModulePkg.dec}.

\item
\texttt{UseHardwareFlowControl}\\
\textbf{Type}: \texttt{plist\ boolean}\\
\textbf{Failsafe}: \texttt{false}\\
\textbf{Description}: Enable serial port hardware flow control.

This option will override the value of \texttt{gEfiMdeModulePkgTokenSpaceGuid.PcdSerialUseHardwareFlowControl}
defined in \href{https://github.com/acidanthera/audk/blob/master/MdeModulePkg/MdeModulePkg.dec}{MdeModulePkg.dec}.

\item
\texttt{UseMmio}\\
\textbf{Type}: \texttt{plist\ boolean}\\
\textbf{Failsafe}: \texttt{false}\\
\textbf{Description}: Indicate whether the serial port registers are in MMIO space.

This option will override the value of \texttt{gEfiMdeModulePkgTokenSpaceGuid.PcdSerialUseMmio}
defined in \href{https://github.com/acidanthera/audk/blob/master/MdeModulePkg/MdeModulePkg.dec}{MdeModulePkg.dec}.

\end{enumerate}

\subsection{Entry Properties}\label{miscentryprops}

\begin{enumerate}
Expand Down Expand Up @@ -8615,7 +8722,7 @@ \subsection{Debugging}\label{troubleshootingdebug}

To obtain the log during boot serial port debugging can be used. Serial port
debugging is enabled in \texttt{Target}, e.g. \texttt{0xB} for onscreen with serial. To
initialise serial within OpenCore use \texttt{SerialInit} configuration option.
initialise serial within OpenCore use \texttt{Init} configuration option under \texttt{Misc->Serial} with other values properly set.
For macOS the best choice is CP2102-based UART devices. Connect motherboard \texttt{TX}
to USB UART \texttt{RX}, and motherboard \texttt{GND} to USB UART \texttt{GND}. Use
\texttt{screen} utility to get the output, or download GUI software, such as
Expand Down
31 changes: 29 additions & 2 deletions Docs/Sample.plist
Original file line number Diff line number Diff line change
Expand Up @@ -1095,8 +1095,6 @@
<integer>2147483650</integer>
<key>LogModules</key>
<string>*</string>
<key>SerialInit</key>
<false/>
<key>SysReport</key>
<false/>
<key>Target</key>
Expand Down Expand Up @@ -1156,6 +1154,35 @@
<key>Vault</key>
<string>Secure</string>
</dict>
<key>Serial</key>
<dict>
<key>BaudRate</key>
<integer>115200</integer>
<key>ClockRate</key>
<integer>1843200</integer>
<key>DetectCable</key>
<false/>
<key>ExtendedTxFifoSize</key>
<integer>64</integer>
<key>FifoControl</key>
<integer>7</integer>
<key>Init</key>
<false/>
<key>LineControl</key>
<integer>3</integer>
<key>PciDeviceInfo</key>
<data>/w==</data>
<key>RegisterAccessWidth</key>
<integer>8</integer>
<key>RegisterBase</key>
<integer>1016</integer>
<key>RegisterStride</key>
<integer>1</integer>
<key>UseHardwareFlowControl</key>
<false/>
<key>UseMmio</key>
<false/>
</dict>
<key>Tools</key>
<array>
<dict>
Expand Down
31 changes: 29 additions & 2 deletions Docs/SampleCustom.plist
Original file line number Diff line number Diff line change
Expand Up @@ -1095,8 +1095,6 @@
<integer>2147483650</integer>
<key>LogModules</key>
<string>*</string>
<key>SerialInit</key>
<false/>
<key>SysReport</key>
<false/>
<key>Target</key>
Expand Down Expand Up @@ -1156,6 +1154,35 @@
<key>Vault</key>
<string>Secure</string>
</dict>
<key>Serial</key>
<dict>
<key>BaudRate</key>
<integer>115200</integer>
<key>ClockRate</key>
<integer>1843200</integer>
<key>DetectCable</key>
<false/>
<key>ExtendedTxFifoSize</key>
<integer>64</integer>
<key>FifoControl</key>
<integer>7</integer>
<key>Init</key>
<false/>
<key>LineControl</key>
<integer>3</integer>
<key>PciDeviceInfo</key>
<data>/w==</data>
<key>RegisterAccessWidth</key>
<integer>8</integer>
<key>RegisterBase</key>
<integer>1016</integer>
<key>RegisterStride</key>
<integer>1</integer>
<key>UseHardwareFlowControl</key>
<false/>
<key>UseMmio</key>
<false/>
</dict>
<key>Tools</key>
<array>
<dict>
Expand Down
29 changes: 28 additions & 1 deletion Include/Acidanthera/Library/OcConfigurationLib.h
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,6 @@
_(BOOLEAN , AppleDebug , , FALSE , ()) \
_(BOOLEAN , ApplePanic , , FALSE , ()) \
_(BOOLEAN , DisableWatchDog , , FALSE , ()) \
_(BOOLEAN , SerialInit , , FALSE , ()) \
_(BOOLEAN , SysReport , , FALSE , ()) \
_(OC_STRING , LogModules , , OC_STRING_CONSTR ("*", _, __) , OC_DESTR (OC_STRING))
OC_DECLARE (OC_MISC_DEBUG)
Expand Down Expand Up @@ -407,11 +406,39 @@ typedef enum {
OC_ARRAY (OC_MISC_TOOLS_ENTRY, _, __)
OC_DECLARE (OC_MISC_TOOLS_ARRAY)

///
/// Reference:
/// https://github.com/acidanthera/bugtracker/issues/1954#issuecomment-1084220743
///
#define OC_SERIAL_PCI_DEVICE_INFO_MAX_SIZE 41U

///
/// Reference:
/// https://github.com/acidanthera/audk/blob/master/MdeModulePkg/Library/BaseSerialPortLib16550/BaseSerialPortLib16550.inf
/// https://github.com/acidanthera/audk/blob/master/MdeModulePkg/MdeModulePkg.dec
///
#define OC_MISC_SERIAL_FIELDS(_, __) \
_(UINT32 , BaudRate , , 115200 , ()) \
_(UINT32 , ClockRate , , 1843200 , ()) \
_(BOOLEAN , DetectCable , , FALSE , ()) \
_(UINT32 , ExtendedTxFifoSize , , 64 , ()) \
_(UINT8 , FifoControl , , 7 , ()) \
_(BOOLEAN , Init , , FALSE , ()) \
_(UINT8 , LineControl , , 3 , ()) \
_(OC_DATA , PciDeviceInfo , , OC_DATA_CONSTR ({0xFF}, _, __) , OC_DESTR (OC_DATA)) \
_(UINT8 , RegisterAccessWidth , , 8 , ()) \
_(UINT64 , RegisterBase , , 0x03F8 , ()) \
_(UINT32 , RegisterStride , , 1 , ()) \
_(BOOLEAN , UseHardwareFlowControl , , FALSE , ()) \
_(BOOLEAN , UseMmio , , FALSE , ())
OC_DECLARE (OC_MISC_SERIAL)

#define OC_MISC_CONFIG_FIELDS(_, __) \
_(OC_MISC_BLESS_ARRAY , BlessOverride , , OC_CONSTR2 (OC_MISC_BLESS_ARRAY, _, __) , OC_DESTR (OC_MISC_BLESS_ARRAY)) \
_(OC_MISC_BOOT , Boot , , OC_CONSTR2 (OC_MISC_BOOT, _, __) , OC_DESTR (OC_MISC_BOOT)) \
_(OC_MISC_DEBUG , Debug , , OC_CONSTR2 (OC_MISC_DEBUG, _, __) , OC_DESTR (OC_MISC_DEBUG)) \
_(OC_MISC_SECURITY , Security , , OC_CONSTR2 (OC_MISC_SECURITY, _, __) , OC_DESTR (OC_MISC_SECURITY)) \
_(OC_MISC_SERIAL , Serial , , OC_CONSTR2 (OC_MISC_SERIAL, _, __) , OC_DESTR (OC_MISC_SERIAL)) \
_(OC_MISC_TOOLS_ARRAY , Entries , , OC_CONSTR2 (OC_MISC_TOOLS_ARRAY, _, __) , OC_DESTR (OC_MISC_TOOLS_ARRAY)) \
_(OC_MISC_TOOLS_ARRAY , Tools , , OC_CONSTR2 (OC_MISC_TOOLS_ARRAY, _, __) , OC_DESTR (OC_MISC_TOOLS_ARRAY))
OC_DECLARE (OC_MISC_CONFIG)
Expand Down
21 changes: 20 additions & 1 deletion Library/OcConfigurationLib/OcConfigurationLib.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ OC_ARRAY_STRUCTORS (OC_MISC_BLESS_ARRAY)
OC_STRUCTORS (OC_MISC_BOOT, ())
OC_STRUCTORS (OC_MISC_DEBUG, ())
OC_STRUCTORS (OC_MISC_SECURITY, ())
OC_STRUCTORS (OC_MISC_SERIAL, ())
OC_STRUCTORS (OC_MISC_TOOLS_ENTRY, ())
OC_ARRAY_STRUCTORS (OC_MISC_TOOLS_ARRAY)
OC_STRUCTORS (OC_MISC_CONFIG, ())
Expand Down Expand Up @@ -428,7 +429,6 @@ mMiscConfigurationDebugSchema[] = {
OC_SCHEMA_INTEGER_IN ("DisplayDelay", OC_GLOBAL_CONFIG, Misc.Debug.DisplayDelay),
OC_SCHEMA_INTEGER_IN ("DisplayLevel", OC_GLOBAL_CONFIG, Misc.Debug.DisplayLevel),
OC_SCHEMA_STRING_IN ("LogModules", OC_GLOBAL_CONFIG, Misc.Debug.LogModules),
OC_SCHEMA_BOOLEAN_IN ("SerialInit", OC_GLOBAL_CONFIG, Misc.Debug.SerialInit),
OC_SCHEMA_BOOLEAN_IN ("SysReport", OC_GLOBAL_CONFIG, Misc.Debug.SysReport),
OC_SCHEMA_INTEGER_IN ("Target", OC_GLOBAL_CONFIG, Misc.Debug.Target)
};
Expand All @@ -453,6 +453,24 @@ mMiscConfigurationSecuritySchema[] = {
OC_SCHEMA_STRING_IN ("Vault", OC_GLOBAL_CONFIG, Misc.Security.Vault),
};

STATIC
OC_SCHEMA
mMiscConfigurationSerialSchema[] = {
OC_SCHEMA_INTEGER_IN ("BaudRate", OC_GLOBAL_CONFIG, Misc.Serial.BaudRate),
OC_SCHEMA_INTEGER_IN ("ClockRate", OC_GLOBAL_CONFIG, Misc.Serial.ClockRate),
OC_SCHEMA_BOOLEAN_IN ("DetectCable", OC_GLOBAL_CONFIG, Misc.Serial.DetectCable),
OC_SCHEMA_INTEGER_IN ("ExtendedTxFifoSize", OC_GLOBAL_CONFIG, Misc.Serial.ExtendedTxFifoSize),
OC_SCHEMA_INTEGER_IN ("FifoControl", OC_GLOBAL_CONFIG, Misc.Serial.FifoControl),
OC_SCHEMA_BOOLEAN_IN ("Init", OC_GLOBAL_CONFIG, Misc.Serial.Init),
OC_SCHEMA_INTEGER_IN ("LineControl", OC_GLOBAL_CONFIG, Misc.Serial.LineControl),
OC_SCHEMA_DATA_IN ("PciDeviceInfo", OC_GLOBAL_CONFIG, Misc.Serial.PciDeviceInfo),
OC_SCHEMA_INTEGER_IN ("RegisterAccessWidth", OC_GLOBAL_CONFIG, Misc.Serial.RegisterAccessWidth),
OC_SCHEMA_INTEGER_IN ("RegisterBase", OC_GLOBAL_CONFIG, Misc.Serial.RegisterBase),
OC_SCHEMA_INTEGER_IN ("RegisterStride", OC_GLOBAL_CONFIG, Misc.Serial.RegisterStride),
OC_SCHEMA_BOOLEAN_IN ("UseHardwareFlowControl", OC_GLOBAL_CONFIG, Misc.Serial.UseHardwareFlowControl),
OC_SCHEMA_BOOLEAN_IN ("UseMmio", OC_GLOBAL_CONFIG, Misc.Serial.UseMmio),
};

STATIC
OC_SCHEMA
mMiscEntriesSchemaEntry[] = {
Expand Down Expand Up @@ -496,6 +514,7 @@ mMiscConfigurationSchema[] = {
OC_SCHEMA_DICT ("Debug", mMiscConfigurationDebugSchema),
OC_SCHEMA_ARRAY_IN ("Entries", OC_GLOBAL_CONFIG, Misc.Entries, &mMiscEntriesSchema),
OC_SCHEMA_DICT ("Security", mMiscConfigurationSecuritySchema),
OC_SCHEMA_DICT ("Serial", mMiscConfigurationSerialSchema),
OC_SCHEMA_ARRAY_IN ("Tools", OC_GLOBAL_CONFIG, Misc.Tools, &mMiscToolsSchema),
};

Expand Down
15 changes: 15 additions & 0 deletions Library/OcMainLib/OcMainLib.inf
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
UefiCpuPkg/UefiCpuPkg.dec

[Guids]
gEfiMdeModulePkgTokenSpaceGuid
gOcVendorVariableGuid

[Protocols]
Expand All @@ -53,6 +54,20 @@
gEfiSecurityArchProtocolGuid ## SOMETIMES_CONSUMES
gEfiSecurity2ArchProtocolGuid ## SOMETIMES_CONSUMES

[Pcd]
gEfiMdeModulePkgTokenSpaceGuid.PcdSerialRegisterAccessWidth ## SOMETIMES_CONSUMES
gEfiMdeModulePkgTokenSpaceGuid.PcdSerialUseMmio ## CONSUMES
gEfiMdeModulePkgTokenSpaceGuid.PcdSerialUseHardwareFlowControl ## CONSUMES
gEfiMdeModulePkgTokenSpaceGuid.PcdSerialDetectCable ## SOMETIMES_CONSUMES
gEfiMdeModulePkgTokenSpaceGuid.PcdSerialRegisterBase ## CONSUMES
gEfiMdeModulePkgTokenSpaceGuid.PcdSerialBaudRate ## CONSUMES
gEfiMdeModulePkgTokenSpaceGuid.PcdSerialLineControl ## CONSUMES
gEfiMdeModulePkgTokenSpaceGuid.PcdSerialFifoControl ## CONSUMES
gEfiMdeModulePkgTokenSpaceGuid.PcdSerialClockRate ## CONSUMES
gEfiMdeModulePkgTokenSpaceGuid.PcdSerialPciDeviceInfo ## CONSUMES
gEfiMdeModulePkgTokenSpaceGuid.PcdSerialExtendedTxFifoSize ## CONSUMES
gEfiMdeModulePkgTokenSpaceGuid.PcdSerialRegisterStride ## CONSUMES

[LibraryClasses]
DevicePathLib
IoLib
Expand Down
Loading

0 comments on commit 6825e9a

Please sign in to comment.