OSDev.org
https://forum.osdev.org/

In EDK2: How to use the real Libraries (MdePkg)
https://forum.osdev.org/viewtopic.php?f=1&t=53936
Page 1 of 1

Author:  mattibendewald [ Tue Sep 21, 2021 1:12 am ]
Post subject:  In EDK2: How to use the real Libraries (MdePkg)

Hi everyone,
I recently started an EDK2 project for a little embedded board. Everything works fine so far, but now I struggle with the serial communication.

What I did:
I used this Introduction (step by step) to create my application: https://wiki.osdev.org/EDK2

Some additional functionality I added works so far:
  • I successfully jumped to 32 Bit mode and can execute stuff there
  • Printing stuff on the screen
  • Accessing files (reading and writing)


Now I wanted to use the serial communication. This is what I tried:
In my .dec file:
Adding following :
Code:
[Packages]
...
PcAtChipsetPkg/PcAtChipsetPkg.dec
UefiCpuPkg/UefiCpuPkg.dec
...
[LibraryClasses]
...
SerialPortLib|PcAtChipsetPkg/Library/SerialIoLib/SerialIoLib.inf


When calling SerialPortInitialize/...Send/...Receive in my main function, it executes those methods from MdePkg/Library/BaseSerialPortLibNull.c instead. (Obviously not sending anything on the serial bus)

How can I call the "correct" function instead of that stub/null thing? I tried to search in this forum, also in google for several hours now but can't find the answer yet.

Any help would be awesome, thank you for reading!!!

Author:  Ethin [ Wed Sep 22, 2021 2:03 am ]
Post subject:  Re: In EDK2: How to use the real Libraries (MdePkg)

You need to use the EFI Serial IO protocol, not the serial port library. In your [Protocols] section of your .INF file, add:
Code:
gEfiSerialIoProtocolGuid

And then use the Serial IO protocol like you would any other protocol. (For packages/libraries/... you need to create a DXE (for drivers) or application (for EFI applications) with an INF file for each DXE or app, and then include that in a .dsc for your platform. I don't know what the DEC files are for.)

Author:  mattibendewald [ Wed Sep 22, 2021 5:49 am ]
Post subject:  Re: In EDK2: How to use the real Libraries (MdePkg)

Okay, that totally makes sense. Somehow I mixed it up completely, thank you for bringing me back on track!

Author:  Ethin [ Wed Sep 22, 2021 4:17 pm ]
Post subject:  Re: In EDK2: How to use the real Libraries (MdePkg)

mattibendewald wrote:
Okay, that totally makes sense. Somehow I mixed it up completely, thank you for bringing me back on track!

Understandable; I've made that mistake with TimerLib. EDK II's build system can be confusing, and what libraries to use and avoid can also be confusing. The rule of thumb, I think, is: if a library is a template-based library (that is, if it contains a *Null implementation), use the underlying protocol only; otherwise, you can use the protocol in conjunction with the library. In the (majority) of cases involving purely non-template-based libraries, the libraries extend the functionality of EFI applications that use their associated protocol(s), or provide simpler interfaces to the (possibly more complicated) interfaces provided by the protocol.

Page 1 of 1 All times are UTC - 6 hours
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/