blob: 00396919691fc9c4cba2ba8705d1b1537bd0d296 [file] [log] [blame]
darylm503eb15a112012-02-28 02:30:19 +00001 EADK
2 EDK II Standard Libraries and Applications
darylm503274402d2011-08-02 23:09:06 +00003 ReadMe
darylm503eb15a112012-02-28 02:30:19 +00004 Beta-1 Release
5 27 Jan. 2012
6 DRAFT
darylm503274402d2011-08-02 23:09:06 +00007
8
9OVERVIEW
10========
darylm503eb15a112012-02-28 02:30:19 +000011The EADK (uEfi Application Development Kit) provides a set of standards-based
12libraries, along with utility and demonstration applications, intended to
13ease development of UEFI applications based upon the EDK II Open-Source
14distribution.
darylm503274402d2011-08-02 23:09:06 +000015
darylm503eb15a112012-02-28 02:30:19 +000016At this time, applications developed with the EADK are intended to reside
17on, and be loaded from, storage separate from the core firmware. This is
18primarily due to size and environmental requirements.
19
20Some components of the EADK can be built as drivers. These will be identified
21explicitly in their documentation.
22
23This document describes the EDK II specific aspects of installing, building,
24and using the Standard C Library component of the EDK II Application
25Development Kit, EADK.
26
27The EADK is comprised of three packages:
28 AppPkg, StdLib, and StdLibPrivateInternalFiles.
darylm503274402d2011-08-02 23:09:06 +000029
30 AppPkg This package contains applications which demonstrate use of the
31 Standard C Library.
32 These applications reside in AppPkg/Applications.
33
34 Enquire This is a program that determines many properties of the
35 C compiler and the target machine that Enquire is run on. The
36 only changes required to port this 1990s era Unix program to
37 EDK II were the addition of eight pragmas to enquire.c in
38 order to disable some Microsoft VC++ specific warnings.
39
40 Hello This is a very simple EDK II native application that doesn't use
41 any features of the Standard C Library.
42
43 Main This application is functionally identical to Hello, except that
44 it uses the Standard C Library to provide a main() entry point.
45
darylm503eb15a112012-02-28 02:30:19 +000046 Python A port of the Python-2.7.2 interpreter for UEFI. This
47 application is disabled by default.
48 See the PythonReadMe.txt file, in the Python directory,
49 for information on configuring and building Python.
darylm503274402d2011-08-02 23:09:06 +000050
51 Sockets A collection of applications demonstrating use of the
52 EDK II Socket Libraries. These applications include:
53
54 * DataSink
55 * DataSource
darylm503eb15a112012-02-28 02:30:19 +000056 * GetAddrInfo
darylm503274402d2011-08-02 23:09:06 +000057 * GetHostByAddr
58 * GetHostByDns
59 * GetHostByName
60 * GetNetByAddr
61 * GetNetByName
62 * GetServByName
63 * GetServByPort
darylm503eb15a112012-02-28 02:30:19 +000064 * OobRx
65 * OobTx
66 * RawIp4Rx
67 * RawIp4Tx
darylm503274402d2011-08-02 23:09:06 +000068 * RecvDgram
69 * SetHostName
70 * SetSockOpt
71 * TftpServer
72 * WebServer
73
74 StdLib The StdLib package contains the standard header files as well as
darylm503eb15a112012-02-28 02:30:19 +000075 implementations of standards based libraries.
76
77 * BsdSocketLib
78 Support routines above the sockets layer and C interface for
79 the UEFI socket library.
80 * Efi
81 Template contents for the target system's
82 \Efi\StdLib\etc directory.
83 * EfiSocketLib
84 UEFI socket implementation, may be linked into an
85 application or run as a driver.
86 * Include
87 Standard include files.
88 * LibC
89 C Standard Library implementation as per
90 ISO/IEC 9899:199409 (C95).
91 * PosixLib
92 Selected functions from the "Single Unix v4" specification.
93 * SocketDxe
94 UEFI sockets driver, includes EfiSocketLib.
95 * UseSocketDxe
96 Alternate linkage for applications that get built into the
97 firmware. Cause application to use a common instance of the
98 sockets driver instead of including all of sockets into the
99 application.
darylm503274402d2011-08-02 23:09:06 +0000100
101 StdLibPrivateInternalFiles The contents of this package are for the
102 exclusive use of the library implementations in StdLib. Please do
103 not use anything from this package in your application or else
104 unexpected behavior may occur.
105 This package may be removed in a future release.
106
107
108RELEASE NOTES
109=============
darylm503eb15a112012-02-28 02:30:19 +0000110 Fixes and Additions
111 -------------------
112Beginning with this release, applications built with the StdLib package
113no longer have a dependency on the TimerLib.
114
115 Known Issues
116 -----------------
darylm503274402d2011-08-02 23:09:06 +0000117This release of the EADK has some restrictions, as described below.
118
darylm503eb15a112012-02-28 02:30:19 +0000119 1. Only the Microsoft VS2005 and VS2008, Intel C Compiler 10.1 (or later),
darylm503274402d2011-08-02 23:09:06 +0000120 GCC 4.3 (mingw32), GCC 4.4, and GCC 4.5 C compilers are supported for
darylm503eb15a112012-02-28 02:30:19 +0000121 Ia32 or X64 CPU architectures. Others may work but have not been tested.
122
123 2. The target machine must be running firmware which provides the
darylm503274402d2011-08-02 23:09:06 +0000124 UEFI 2.3 HII protocol.
darylm503eb15a112012-02-28 02:30:19 +0000125
126 3. The EADK has not been through Intel's Quality Assurance process. This
darylm503274402d2011-08-02 23:09:06 +0000127 means that specified standards compliance has not been validated, nor
128 has it undergone formal functionality testing.
darylm503eb15a112012-02-28 02:30:19 +0000129
130 4. Applications must be launched from within the EFI Shell.
131
132 6. Absolute file paths may optionally be prefixed by a volume specifier
darylm503274402d2011-08-02 23:09:06 +0000133 such as "FS0:". The volume specifier is separated from the remainder
134 of the path by a single colon ':'. The volume specifier must be one of
135 the Shell's mapped volume names as shown by the "map" command.
darylm503eb15a112012-02-28 02:30:19 +0000136
137 7. Absolute file paths that don't begin with a volume specifier;
darylm503274402d2011-08-02 23:09:06 +0000138 e.g. paths that begin with "/", are relative to the currently selected
darylm503eb15a112012-02-28 02:30:19 +0000139 volume. When the EFI Shell first starts, there is NO selected volume.
140
141 8. The tmpfile(), and related, functions require that the current volume
darylm503274402d2011-08-02 23:09:06 +0000142 have a temporary directory as specified in <paths.h>. This directory
darylm503eb15a112012-02-28 02:30:19 +0000143 is specified by macro _PATH_TMP as /Efi/StdLib/tmp.
144
145 9. Input line editing is not supported. Backspacing, deleting, or
146 otherwise attempting to modify interactive input will result in a
147 syntax error since the editing characters are interpreted the
148 same as any other character.
darylm503274402d2011-08-02 23:09:06 +0000149
150The Standard C Library provided by this package is a "hosted" implementation
151conforming to the ISO/IEC 9899-1990 C Language Standard with Addendum 1. This
152is commonly referred to as the "C 95" specification or ISO/IEC 9899:199409.
153The following instructions assume that you have an existing EDK II or UDK 2010
154source tree that has been configured to build with your tool chain. For
155convenience, it is assumed that your EDK II source tree is located at
156C:\Source\Edk2.
157
158
darylm503eb15a112012-02-28 02:30:19 +0000159EADK INSTALLATION
160=================
darylm503274402d2011-08-02 23:09:06 +0000161The EADK is integrated within the EDK II source tree and is included with
162current EDK II check-outs. If they are missing from your tree, they may be
163installed by extracting, downloading or copying them to the root of your EDK II
164source tree. The three package directories should be peers to the Conf,
165MdePkg, Nt32Pkg, etc. directories.
166
darylm503eb15a112012-02-28 02:30:19 +0000167The Python 2.7.2 distribution must be downloaded from python.org before the
168Python application can be built. Extracting Python-2.7.2.tgz into the
169AppPkg\Applications\Python directory will produce a Python-2.7.2 directory
darylm503274402d2011-08-02 23:09:06 +0000170containing the Python distribution. Python files that had to be modified for
darylm503eb15a112012-02-28 02:30:19 +0000171EDK II are in the AppPkg\Applications\Python\PyMod-2.7.2 directory. These
172files need to be copied into the corresponding directories within Python-2.7.2.
173
174The Python 2.7.1 port was superseded before it was completed. The PyMod-2.7.1
175directory tree will be deleted in the near future. Use the Python 2.7.2 port,
176as described above.
darylm503274402d2011-08-02 23:09:06 +0000177
178There are some boiler-plate declarations and definitions that need to be
179included in your application's INF and DSC build files. These are described
180in the CONFIGURATION section, below.
181
182
183BUILDING
184========
185It is not necessary to build the libraries separately from the target
186application(s). If the application references the libraries, as described in
187USAGE, below; the required libraries will be built as needed.
188To build the applications included in AppPkg, one would execute the following
189commands within the "Visual Studio Command Prompt" window:
190
191 > cd C:\Source\Edk2
192 > .\edksetup.bat
darylm503eb15a112012-02-28 02:30:19 +0000193 > build -a X64 -p AppPkg\AppPkg.dsc
darylm503274402d2011-08-02 23:09:06 +0000194
195This will produce the application executables: Enquire.efi, Hello.efi, and
196Main.efi in the C:\Source\Edk2\Build\AppPkg\DEBUG_VS2008\X64 directory; with
197the DEBUG_VS2008 component being replaced with the actual tool chain and build
198type you have selected in Conf\Tools_def.txt. These executables can now be
199loaded onto the target platform and executed.
200
201If you examine the AppPkg.dsc file, you will notice that the StdLib package is
202referenced in order to resolve the library classes comprising the Standard
203C Library. This, plus referencing the StdLib package in your application's
204.inf file is all that is needed to link your application to the standard
205libraries.
206
darylm503eb15a112012-02-28 02:30:19 +0000207Unless explicitly stated as allowed, EADK components should not be added as
208components of a DSC file which builds a platform's core firmware. There are
209incompatibilities in build flags and requirements that will conflict with the
210requirements of the core firmware. EADK components should be built using a
211separate DSC file then, if absolutely necessary, included as binary components
212of other DSC files.
darylm503274402d2011-08-02 23:09:06 +0000213
214USAGE
215=====
216This implementation of the Standard C Library is comprised of 16 separate
217libraries in addition to the standard header files. Nine of the libraries are
218associated with use of one of the standard headers; thus, if the header is used
219in an application, it must be linked with the associated library. Three
220libraries are used to provide the Console and File-system device abstractions.
221The libraries and associated header files are described in the following table.
222
223 Library
224 Class Header File(s) Notes
225---------- ---------------- -------------------------------------------------
226LibC -- Use Always -- This library is always required.
227LibCtype ctype.h, wctype.h Character classification and mapping
228LibLocale locale.h Localization types, macros, and functions
229LibMath math.h Mathematical functions, types, and macros
230LibStdio stdio.h Standard Input and Output functions, types, and
231 macros
232LibStdLib stdlib.h General Utilities for numeric conversion, random
233 num., etc.
234LibString string.h String copying, concatenation, comparison,
235 & search
236LibSignal signal.h Functions and types for handling run-time
237 conditions
238LibTime time.h Time and Date types, macros, and functions
239LibUefi sys/EfiSysCall.h Provides the UEFI system interface and
240 "System Calls"
241LibWchar wchar.h Extended multibyte and wide character utilities
242LibNetUtil Network address and number manipulation utilities
243DevConsole Automatically provided File I/O abstractions for
244 the UEFI Console device. No need to list this
245 library class in your INF file(s).
246DevShell Add if desired File I/O abstractions using UEFI shell
247 facilities. Add this to the application's main
248 INF file if file-system access needed.
249DevUtility -- Do Not Use -- Utility functions used by the Device abstractions
250LibGdtoa -- Do Not Use -- This library is used internally and should not
251 need to be explicitly specified by an
252 application. It must be defined as one of the
253 available library classes in the application's
254 DSC file.
255
256 Table 1: Standard Libraries
257 ============================
258
259
260These libraries must be fully described in the [LibraryClasses] section of the
261application package's DSC file. Then, each individual application needs to
262specify which libraries to link to by specifying the Library Class, from the
263above table, in the [LibraryClasses] section of the application's INF file. The
264AppPkg.dsc, StdLib.dsc, and Enquire.inf files provide good examples of this.
265More details are in the CONFIGURATION section, below.
266
267Within the source files of the application, use of the Standard headers and
268library functions follow standard C programming practices as formalized by
269ISO/IEC 9899:1990, with Addendum 1, (C 95) C language specification.
270
271
darylm503eb15a112012-02-28 02:30:19 +0000272BUILD CONFIGURATION
273===================
darylm503274402d2011-08-02 23:09:06 +0000274DSC Files
275---------
276
277All EDK II packages which build applications that use the standard libraries
278must include some "boilerplate" text in the package's .dsc file. To make it
279easier, and to reduce cut-and-paste errors, the "boilerplate" text has been
280consolidated into a single file, StdLib/StdLib.inc, which can be included in
281your .dsc file using the !include directive. The provided AppPkg.dsc and
282StdLib.dsc files do this on their last line.
283
darylm503eb15a112012-02-28 02:30:19 +0000284Each section of StdLib/StdLib.inc is described below.
darylm503274402d2011-08-02 23:09:06 +0000285
286 [LibraryClasses]
287 #
darylm503274402d2011-08-02 23:09:06 +0000288 # C Standard Libraries
289 #
290 LibC|StdLib/LibC/LibC.inf
darylm503274402d2011-08-02 23:09:06 +0000291 LibCType|StdLib/LibC/Ctype/Ctype.inf
darylm503274402d2011-08-02 23:09:06 +0000292 LibLocale|StdLib/LibC/Locale/Locale.inf
darylm503274402d2011-08-02 23:09:06 +0000293 LibMath|StdLib/LibC/Math/Math.inf
294 LibSignal|StdLib/LibC/Signal/Signal.inf
darylm503eb15a112012-02-28 02:30:19 +0000295 LibStdio|StdLib/LibC/Stdio/Stdio.inf
296 LibStdLib|StdLib/LibC/StdLib/StdLib.inf
297 LibString|StdLib/LibC/String/String.inf
298 LibTime|StdLib/LibC/Time/Time.inf
299 LibUefi|StdLib/LibC/Uefi/Uefi.inf
300 LibWchar|StdLib/LibC/Wchar/Wchar.inf
darylm503274402d2011-08-02 23:09:06 +0000301
darylm503eb15a112012-02-28 02:30:19 +0000302 # Common Utilities for Networking Libraries
303 LibNetUtil|StdLib/LibC/NetUtil/NetUtil.inf
304
305 # Additional libraries for POSIX functionality.
306 LibErr|StdLib/PosixLib/Err/LibErr.inf
307 LibGen|StdLib/PosixLib/Gen/LibGen.inf
308 LibGlob|StdLib/PosixLib/Glob/LibGlob.inf
309 LibStringlist|StdLib/PosixLib/Stringlist/LibStringlist.inf
310
311 # Libraries for device abstractions within the Standard C Library
312 # Applications should not directly access any functions defined in these libraries.
313 LibGdtoa|StdLib/LibC/gdtoa/gdtoa.inf
darylm503274402d2011-08-02 23:09:06 +0000314 DevConsole|StdLib/LibC/Uefi/Devices/daConsole.inf
315 DevShell|StdLib/LibC/Uefi/Devices/daShell.inf
darylm503eb15a112012-02-28 02:30:19 +0000316 DevUtility|StdLib/LibC/Uefi/Devices/daUtility.inf
317
318 [LibraryClasses.ARM.UEFI_APPLICATION]
319 NULL|ArmPkg/Library/CompilerIntrinsicsLib/CompilerIntrinsicsLib.inf
darylm503274402d2011-08-02 23:09:06 +0000320
321 Figure 1: Library Class Descriptions
322 ====================================
323
324
darylm503eb15a112012-02-28 02:30:19 +0000325Descriptions of the Library Classes comprising the Standard Libraries,
326as shown above in Figure 1: Library Class Descriptions, are provided.
darylm503274402d2011-08-02 23:09:06 +0000327
328The directives in Figure 2: Package Component Descriptions will create
329instances of the BaseLib and BaseMemoryLib library classes that are built
330with Link-time-Code-Generation disabled. This is necessary when using the
331Microsoft tool chains in order to allow the library's functions to be
332resolved during the second pass of the linker during Link-Time-Code-Generation
333of the application.
334
darylm503eb15a112012-02-28 02:30:19 +0000335A DXE driver version of the Socket library is also built.
336
darylm503274402d2011-08-02 23:09:06 +0000337 [Components]
338 # BaseLib and BaseMemoryLib need to be built with the /GL- switch
339 # when using the Microsoft tool chains. This is required so that
340 # the library functions can be resolved during the second pass of
341 # the linker during link-time-code-generation.
342 #
343 MdePkg/Library/BaseLib/BaseLib.inf {
344 <BuildOptions>
345 MSFT:*_*_*_CC_FLAGS = /X /Zc:wchar_t /GL-
346 }
347 MdePkg/Library/BaseMemoryLib/BaseMemoryLib.inf {
348 <BuildOptions>
349 MSFT:*_*_*_CC_FLAGS = /X /Zc:wchar_t /GL-
350 }
351
darylm503eb15a112012-02-28 02:30:19 +0000352 ##########
353 # Socket Layer
354 ##########
355 StdLib/SocketDxe/SocketDxe.inf
356
darylm503274402d2011-08-02 23:09:06 +0000357 Figure 2: Package Component Descriptions
358 ========================================
359
360
darylm503274402d2011-08-02 23:09:06 +0000361Each compiler assumes, by default, that it will be used with standard libraries
362and headers provided by the compiler vendor. Many of these assumptions are
363incorrect for the UEFI environment. By including a BuildOptions section, as
364shown in Figure 3: Package Build Options, these assumptions can be
365tailored for compatibility with UEFI and the EDK II Standard Libraries.
366
367 [BuildOptions]
368 INTEL:*_*_IA32_CC_FLAGS = /Qfreestanding
369 MSFT:*_*_IA32_CC_FLAGS = /X /Zc:wchar_t
darylm503eb15a112012-02-28 02:30:19 +0000370 GCC:*_*_IA32_CC_FLAGS = -nostdinc -nostdlib
darylm503274402d2011-08-02 23:09:06 +0000371
372 # The Build Options, below, are only used when building the C library
darylm503eb15a112012-02-28 02:30:19 +0000373 # to be run under an emulation environment. They disable optimization
374 # which facillitates debugging under the Emulation environment.
darylm503274402d2011-08-02 23:09:06 +0000375
darylm503eb15a112012-02-28 02:30:19 +0000376 # INTEL:*_*_IA32_CC_FLAGS = /Od
377 # MSFT:*_*_IA32_CC_FLAGS = /Od
378 # GCC:*_*_IA32_CC_FLAGS = -O0
darylm503274402d2011-08-02 23:09:06 +0000379
380 Figure 4: Package Build Options
381 ===============================
382
383The "boilerplate" text can be included using a !include directive in the
384package's .dsc file. The provided AppPkg.dsc and StdLib.dsc files include
385the "boilerplate" text as follows:
386
387 # Include Boilerplate text required for building with the Standard Libraries.
388 #
389 #############################################################################
390 !include StdLib/StdLib.inc
391
392 Figure 5: "Boilerplate" Inclusion
393 =================================
394
395
396INF Files
397=========
398The INF files for most modules will not require special directives in order to
399support the Standard Libraries. The two cases which could occur are described
400below.
401
402 [LibraryClasses]
403 UefiLib
404 LibC
405 LibString
406 LibStdio
407 DevShell
darylm503eb15a112012-02-28 02:30:19 +0000408
darylm503274402d2011-08-02 23:09:06 +0000409 Figure 6: Module Library Classes
410 ================================
411
412
413Modules of type UEFI_APPLICATION that perform file I/O should include library
414class DevShell. Including this library class will allow file operations to be
415handled by the UEFI Shell. Without this class, only Console I/O is permitted.
416
417 [BuildOptions]
418 INTEL:*_*_*_CC_FLAGS = /Qdiag-disable:181,186
419 MSFT:*_*_*_CC_FLAGS = /Oi- /wd4018 /wd4131
420 GCC:*_*_IPF_SYMRENAME_FLAGS = --redefine-syms=Rename.txt
darylm503eb15a112012-02-28 02:30:19 +0000421
darylm503274402d2011-08-02 23:09:06 +0000422 Figure 7: Module Build Options
423 ==============================
424
425
426An application's INF file may need to include a [BuildOptions] section
427specifying additional compiler and linker flags necessary to allow the
428application to be built. Usually, this section is not needed. When building
429code from external sources, though, it may be necessary to disable some
430warnings or enable/disable some compiler features.
431
432
darylm503eb15a112012-02-28 02:30:19 +0000433TARGET-SYSTEM INSTALLATION
434==========================
435Applications that use file system features or the Socket library depend upon
436the existence of a specific directory tree structure on the same volume that
437the application was loaded from. This tree structure is described below:
438
439 /EFI Root of the UEFI system area.
440 |- /Tools Directory containing applications.
441 |- /Boot UEFI specified Boot directory.
442 |- /StdLib Root of the Standard Libraries sub-tree.
443 |- /etc Configuration files used by libraries.
444 |- /tmp Temporary files created by tmpfile(), etc.
445
446
447The /Efi/StdLib/etc directory is populated from the StdLib/Efi/etc source
448directory.
449
darylm503274402d2011-08-02 23:09:06 +0000450IMPLEMENTATION-Specific Features
451================================
452It is very strongly recommended that applications not use the long or
453unsigned long types. The size of this type varies between compilers and is one
454of the less portable aspects of C. Instead, one should use the UEFI defined
455types whenever possible. Use of these types, listed below for reference,
456ensures that the declared objects have unambiguous, explicitly declared, sizes
457and characteristics.
458
459 UINT64 INT64 UINT32 INT32 UINT16 CHAR16
460 INT16 BOOLEAN UINT8 CHAR8 INT8
461 UINTN INTN PHYSICALADDRESS
462
463There are similar types declared in sys/types.h and related files.
464
465The types UINTN and INTN have the native width of the target processor
466architecture. Thus, INTN on IA32 has a width of 32 bits while INTN on X64 and
467IPF has a width of 64 bits.
468
469For maximum portability, data objects intended to hold addresses should be
470declared with type intptr_t or uintptr_t. These types, declared in
471sys/stdint.h, can be used to create objects capable of holding pointers. Note
472that these types will generate different sized objects on different processor
473architectures. If a constant size across all processors and compilers is
474needed, use type PHYSICAL_ADDRESS.
475
476Though not specifically required by the ISO/IEC 9899 standard, this
477implementation of the Standard C Library provides the following system calls
darylm503eb15a112012-02-28 02:30:19 +0000478which are declared in sys/EfiSysCall.h and/or unistd.h.
darylm503274402d2011-08-02 23:09:06 +0000479
darylm503eb15a112012-02-28 02:30:19 +0000480 close creat chmod dup dup2
481 fcntl fstat getcwd ioctl isatty
482 lseek lstat mkdir open poll
483 read rename rmdir stat unlink write
darylm503274402d2011-08-02 23:09:06 +0000484
485The open function will accept file names of "stdin:", "stdout:", and "stderr:"
486which cause the respective streams specified in the UEFI System Table to be
487opened. Normally, these are associated with the console device. When the
488application is first started, these streams are automatically opened on File
489Descriptors 0, 1, and 2 respectively.
490
darylm503eb15a112012-02-28 02:30:19 +0000491 # # #