public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: Laszlo Ersek <lersek@redhat.com>
To: GN Keshava <keshava.gn@gmail.com>
Cc: "edk2-devel@lists.01.org" <edk2-devel@ml01.01.org>,
	"Carsey, Jaben" <jaben.carsey@intel.com>
Subject: Re: Use fprintf in UEFI
Date: Thu, 29 Sep 2016 09:31:42 +0200	[thread overview]
Message-ID: <49e7533e-4c7c-3585-2b57-6f851860da46@redhat.com> (raw)
In-Reply-To: <CABKwMdtNJrV4u+G_Px0pu9=q8vXpC1FC_sMXcHtwZfU_xa9UeA@mail.gmail.com>

CC Jaben

On 09/29/16 08:01, GN Keshava wrote:
> Hi,
> 
> There is fprintf function in Stdio library. But how to use it? The first
> argument is "FILE" type. But I have "EFI_FILE_PROTOCOL* File" which I got
> from "EFIOpenFile" function. How to map to "FILE" type?
> 
> Sorry if this is silly. A newbie here. Didn't get much idea in internet
> search. :)

(1) You're trying to mix edk2 APIs with standard C library APIs. Don't
do that.

I think what you are missing is the fact that using edk2, you can write
a UEFI application *either* against edk2 APIs (protocols and libraries),
*or* against standard C APIs (using the stdlib implementation of edk2).
In some cases it is okay to call edk2 APIs directly, from stdlib
applications, but in general I'd advise against that.

I told you to read "AppPkg/ReadMe.txt"; that file explains what is
necessary for what "flavor" of UEFI application. It even mentions two
example programs, "Main" and "Hello", which don't do anything but
highlight the differences.

For another (quite self-contained) example,
"AppPkg/Applications/OrderedCollectionTest" is an application that I
wrote myself; it uses fopen() and fprintf(). This is a unit tester for
an MdePkg library that I also wrote, so it actually exemplifies how you
can use both stdlib and an edk2 library, as long as they don't step on
each other's toes.

(2) You can write formatted output to files using only edk2 APIs as
well, but for that, you first have to format the text into memory
buffers with PrintLib functions, then write the buffers to files with
the ShellLib APIs or with direct protocol calls.

(3) The standard C lib implementation in edk2 is only available for use
by UEFI applications (no other module types; that is, no drivers).
What's more, those applications have to be started from the shell (you
can't boot them directly from the boot manager, for example). This is
also documented in AppPkg/ReadMe.txt.

Thanks
Laszlo


  reply	other threads:[~2016-09-29  7:31 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-09-29  6:01 Use fprintf in UEFI GN Keshava
2016-09-29  7:31 ` Laszlo Ersek [this message]
2016-09-29  7:52   ` GN Keshava

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=49e7533e-4c7c-3585-2b57-6f851860da46@redhat.com \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox