Mark serial port as fully initialized and always check that before printing anything to the serial console
All checks were successful
ci/woodpecker/push/build Pipeline was successful

This commit is contained in:
Rafal Kupiec 2022-08-10 17:56:41 +02:00
parent a9171bd512
commit e6aaa1a83c
Signed by: belliash
GPG Key ID: 4E829243E0CFE6B4
3 changed files with 25 additions and 11 deletions

View File

@ -21,8 +21,9 @@
#define COMPORT_DIV_DLM 0x01 /* Divisor Latch Most */ #define COMPORT_DIV_DLM 0x01 /* Divisor Latch Most */
/* Serial port control flags */ /* Serial port control flags */
#define COMPORT_FLAG_DBR 0x01 /* Default Baud Rate */ #define COMPORT_FLAG_INIT 0x01 /* Port Initialized */
#define COMPORT_FLAG_MC 0x02 /* Modem Control */ #define COMPORT_FLAG_DBR 0x02 /* Default Baud Rate */
#define COMPORT_FLAG_MC 0x04 /* Modem Control */
/* Serial port Fifo Control Register (FCR) access masks */ /* Serial port Fifo Control Register (FCR) access masks */
#define COMPORT_FCR_DISABLE 0x00 /* Disable */ #define COMPORT_FCR_DISABLE 0x00 /* Disable */

View File

@ -212,6 +212,7 @@ HlInitializeComPort(IN OUT PCPPORT Port,
{ {
PUCHAR Address; PUCHAR Address;
UCHAR Byte = 0; UCHAR Byte = 0;
USHORT Flags = 0;
ULONG Mode; ULONG Mode;
/* Check if serial port is set */ /* Check if serial port is set */
@ -233,7 +234,7 @@ HlInitializeComPort(IN OUT PCPPORT Port,
{ {
/* Use default baud (clock) rate if not set */ /* Use default baud (clock) rate if not set */
BaudRate = COMPORT_CLOCK_RATE; BaudRate = COMPORT_CLOCK_RATE;
Port->Flags = COMPORT_FLAG_DBR; Flags |= COMPORT_FLAG_DBR;
} }
/* Store COM pointer */ /* Store COM pointer */
@ -288,10 +289,14 @@ HlInitializeComPort(IN OUT PCPPORT Port,
return STATUS_IO_DEVICE_ERROR; return STATUS_IO_DEVICE_ERROR;
} }
/* Mark port as fully initialized */
Flags |= COMPORT_FLAG_INIT;
/* Disable loopback mode and use port normally */ /* Disable loopback mode and use port normally */
HlIoPortOutByte(PtrToUshort(Address + (ULONG)COMPORT_REG_MCR), COMPORT_MCR_NOM); HlIoPortOutByte(PtrToUshort(Address + (ULONG)COMPORT_REG_MCR), COMPORT_MCR_NOM);
Port->Address = Address; Port->Address = Address;
Port->Baud = BaudRate; Port->Baud = BaudRate;
Port->Flags = Flags;
/* Return success */ /* Return success */
return STATUS_SUCCESS; return STATUS_SUCCESS;

View File

@ -28,14 +28,18 @@ BlDbgPrint(IN PUINT16 Format,
{ {
VA_LIST Arguments; VA_LIST Arguments;
/* Initialise the va_list */ /* Check if EFI serial port is fully initialized */
VA_START(Arguments, Format); if(EfiSerialPort.Flags & COMPORT_FLAG_INIT)
{
/* Initialise the va_list */
VA_START(Arguments, Format);
/* Format and print the string to the serial console */ /* Format and print the string to the serial console */
BlStringPrint(BlComPortPutChar, Format, Arguments); BlStringPrint(BlComPortPutChar, Format, Arguments);
/* Clean up the va_list */ /* Clean up the va_list */
VA_END(Arguments); VA_END(Arguments);
}
} }
/** /**
@ -65,8 +69,12 @@ BlEfiPrint(IN PUINT16 Format,
/* Format and print the string to the stdout */ /* Format and print the string to the stdout */
BlStringPrint(BlConsolePutChar, Format, Arguments); BlStringPrint(BlConsolePutChar, Format, Arguments);
/* Format and print the string to the serial console */ /* Check if EFI serial port is fully initialized */
BlStringPrint(BlComPortPutChar, Format, Arguments); if(EfiSerialPort.Flags & COMPORT_FLAG_INIT)
{
/* Format and print the string to the serial console */
BlStringPrint(BlComPortPutChar, Format, Arguments);
}
/* Clean up the va_list */ /* Clean up the va_list */
VA_END(Arguments); VA_END(Arguments);