ReadMe.txt 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502
  1. EADK
  2. EDK II Standard Libraries and Applications
  3. ReadMe
  4. Version 1.02
  5. 21 Dec. 2012
  6. OVERVIEW
  7. ========
  8. The EADK (uEfi Application Development Kit) provides a set of standards-based
  9. libraries, along with utility and demonstration applications, intended to
  10. ease development of UEFI applications based upon the EDK II Open-Source
  11. distribution.
  12. At this time, applications developed with the EADK are intended to reside
  13. on, and be loaded from, storage separate from the core firmware. This is
  14. primarily due to size and environmental requirements.
  15. This release of the EADK should only be used to produce UEFI Applications. Due to the execution
  16. environment built by the StdLib component, execution as a UEFI driver can cause system stability
  17. issues.
  18. This document describes the EDK II specific aspects of installing, building,
  19. and using the Standard C Library component of the EDK II Application
  20. Development Kit, EADK.
  21. The EADK is comprised of three packages:
  22. AppPkg, StdLib, and StdLibPrivateInternalFiles.
  23. AppPkg This package contains applications which demonstrate use of the
  24. Standard C and Sockets Libraries.
  25. These applications reside in AppPkg/Applications.
  26. Enquire This is a program that determines many properties of the
  27. C compiler and the target machine that Enquire is run on. The
  28. only changes required to port this 1990s era Unix program to
  29. EDK II were the addition of eight pragmas to enquire.c in
  30. order to disable some Microsoft VC++ specific warnings.
  31. Hello This is a very simple EDK II native application that doesn't use
  32. any features of the Standard C Library.
  33. Main This application is functionally identical to Hello, except that
  34. it uses the Standard C Library to provide a main() entry point.
  35. Python A port of the Python-2.7.2 interpreter for UEFI. Building this
  36. application is disabled by default.
  37. See the PythonReadMe.txt file, in the Python directory,
  38. for information on configuring and building Python.
  39. Sockets A collection of applications demonstrating use of the
  40. EDK II Socket Libraries. These applications include:
  41. * DataSink * DataSource
  42. * GetAddrInfo * GetHostByAddr
  43. * GetHostByDns * GetHostByName
  44. * GetNetByAddr * GetNetByName
  45. * GetServByName * GetServByPort
  46. * OobRx * OobTx
  47. * RawIp4Rx * RawIp4Tx
  48. * RecvDgram * SetHostName
  49. * SetSockOpt * TftpServer
  50. * WebServer
  51. StdLib The StdLib package contains the standard header files as well as
  52. implementations of other standards-based libraries.
  53. * BsdSocketLib
  54. Support routines above the sockets layer and C interface for
  55. the UEFI socket library.
  56. * Efi
  57. Template contents for the target system's
  58. \Efi\StdLib\etc directory.
  59. * EfiSocketLib
  60. UEFI socket implementation, may be linked into an
  61. application or run as a driver.
  62. * Include
  63. Standard include files.
  64. * LibC
  65. C Standard Library implementation as per
  66. ISO/IEC 9899:199409 (C95).
  67. * PosixLib
  68. Selected functions from the "Single Unix v4" specification.
  69. * SocketDxe
  70. UEFI sockets driver, includes EfiSocketLib.
  71. * UseSocketDxe
  72. Alternate linkage for applications that get built into the
  73. firmware. Cause application to use a common instance of the
  74. sockets driver instead of including all of sockets into the
  75. application.
  76. StdLibPrivateInternalFiles The contents of this package are for the
  77. exclusive use of the library implementations in StdLib. Please do
  78. not use anything from this package in your application or else
  79. unexpected behavior may occur.
  80. This package may be removed in a future release.
  81. RELEASE NOTES
  82. =============
  83. Fixes and Additions
  84. -------------------
  85. Beginning with release 1.01, applications built with the StdLib package
  86. no longer have a dependency on the TimerLib.
  87. Known Issues
  88. -----------------
  89. This release of the EADK has some restrictions, as described below.
  90. 1. The target machine must be running firmware which provides the
  91. UEFI 2.3 HII protocol.
  92. 2. Applications must be launched from within the EFI Shell.
  93. 3. Absolute file paths may optionally be prefixed by a volume specifier
  94. such as "FS0:". The volume specifier is separated from the remainder
  95. of the path by a single colon ':'. The volume specifier must be one of
  96. the Shell's mapped volume names as shown by the "map" command.
  97. 4. Absolute file paths that don't begin with a volume specifier;
  98. e.g. paths that begin with "/", are relative to the currently selected
  99. volume. When the EFI Shell first starts, there is NO selected volume.
  100. 5. The tmpfile(), and related, functions require that the current volume
  101. have a temporary directory as specified in <paths.h>. This directory
  102. is specified by macro _PATH_TMP as /Efi/StdLib/tmp.
  103. The Standard C Library provided by this package is a "hosted" implementation
  104. conforming to the ISO/IEC 9899-1990 C Language Standard with Addendum 1. This
  105. is commonly referred to as the "C 95" specification or ISO/IEC 9899:199409.
  106. The following instructions assume that you have an existing EDK II or UDK 2010
  107. source tree that has been configured to build with your tool chain. For
  108. convenience, it is assumed that your EDK II source tree is located at
  109. C:\Source\Edk2.
  110. EADK INSTALLATION
  111. =================
  112. The EADK is integrated within the EDK II source tree and is included with
  113. current EDK II check-outs. If they are missing from your tree, they may be
  114. installed by extracting, downloading or copying them to the root of your EDK II
  115. source tree. The three package directories should be peers to the Conf,
  116. MdePkg, Nt32Pkg, etc. directories.
  117. There are some boiler-plate declarations and definitions that need to be
  118. included in your application's INF and DSC build files. These are described
  119. in the CONFIGURATION section, below.
  120. A subset of the Python 2.7.2 distribution is included as part of AppPkg. If desired,
  121. the full Python 2.7.2 distribution may be downloaded from python.org and used instead.
  122. Delete or rename the existing Python-2.7.2 directory then extract the downloaded
  123. Python-2.7.2.tgz file into the AppPkg\Applications\Python directory. This will produce a
  124. Python-2.7.2 directory containing the full Python distribution. Python files that had to be
  125. modified for EDK II are in the AppPkg\Applications\Python\PyMod-2.7.2 directory. These
  126. files need to be copied into the corresponding directories within the extracted Python-2.7.2
  127. directory before Python can be built.
  128. BUILDING
  129. ========
  130. It is not necessary to build the libraries separately from the target
  131. application(s). If the application references the libraries, as described in
  132. USAGE, below; the required libraries will be built as needed.
  133. To build the applications included in AppPkg, one would execute the following
  134. commands within the "Visual Studio Command Prompt" window:
  135. > cd C:\Source\Edk2
  136. > .\edksetup.bat
  137. > build -a X64 -p AppPkg\AppPkg.dsc
  138. This will produce the application executables: Enquire.efi, Hello.efi, and
  139. Main.efi in the C:\Source\Edk2\Build\AppPkg\DEBUG_VS2008\X64 directory; with
  140. the DEBUG_VS2008 component being replaced with the actual tool chain and build
  141. type you have selected in Conf\Tools_def.txt. These executables can now be
  142. loaded onto the target platform and executed.
  143. If you examine the AppPkg.dsc file, you will notice that the StdLib package is
  144. referenced in order to resolve the library classes comprising the Standard
  145. C Library. This, plus referencing the StdLib package in your application's
  146. .inf file is all that is needed to link your application to the standard
  147. libraries.
  148. Unless explicitly stated as allowed, EADK components should not be added as
  149. components of a DSC file which builds a platform's core firmware. There are
  150. incompatibilities in build flags and requirements that will conflict with the
  151. requirements of the core firmware. EADK components should be built using a
  152. separate DSC file then, if absolutely necessary, included as binary components
  153. of other DSC files.
  154. USAGE
  155. =====
  156. This implementation of the Standard C Library is comprised of 16 separate
  157. libraries in addition to the standard header files. Nine of the libraries are
  158. associated with use of one of the standard headers; thus, if the header is used
  159. in an application, it must be linked with the associated library. Three
  160. libraries are used to provide the Console and File-system device abstractions.
  161. The libraries and associated header files are described in the following table.
  162. Library
  163. Class Header File(s) Notes
  164. ---------- ---------------- -------------------------------------------------
  165. LibC -- Use Always -- This library is always required.
  166. LibCtype ctype.h, wctype.h Character classification and mapping
  167. LibLocale locale.h Localization types, macros, and functions
  168. LibMath math.h Mathematical functions, types, and macros
  169. LibStdio stdio.h Standard Input and Output functions, types, and
  170. macros
  171. LibStdLib stdlib.h General Utilities for numeric conversion, random
  172. num., etc.
  173. LibString string.h String copying, concatenation, comparison,
  174. & search
  175. LibSignal signal.h Functions and types for handling run-time
  176. conditions
  177. LibTime time.h Time and Date types, macros, and functions
  178. LibUefi sys/EfiSysCall.h Provides the UEFI system interface and
  179. "System Calls"
  180. LibWchar wchar.h Extended multibyte and wide character utilities
  181. LibNetUtil Network address and number manipulation utilities
  182. DevConsole Automatically provided File I/O abstractions for
  183. the UEFI Console device. No need to list this
  184. library class in your INF file(s).
  185. DevShell Add if desired File I/O abstractions using UEFI shell
  186. facilities. Add this to the application's main
  187. INF file if file-system access needed.
  188. DevUtility -- Do Not Use -- Utility functions used internally by the Device abstractions
  189. LibGdtoa -- Do Not Use -- This library is used internally and should not
  190. need to be explicitly specified by an
  191. application. It must be defined as one of the
  192. available library classes in the application's
  193. DSC file.
  194. Table 1: Standard Libraries
  195. ============================
  196. The DevConsole and DevShell libraries provide device I/O functionality and are treated
  197. specially. DevConsole is automatically included so there is no need to reference it in your
  198. application's DSC or INF files. DevShell must be listed, in your application's INF file in the
  199. [LibraryClasses] section, if your application does file I/O.
  200. These libraries must be fully described in the [LibraryClasses] section of the
  201. application package's DSC file. Then, each individual application needs to
  202. specify which libraries to link to by specifying the Library Class, from the
  203. above table, in the [LibraryClasses] section of the application's INF file. The
  204. AppPkg.dsc, StdLib.dsc, and Enquire.inf files provide good examples of this.
  205. More details are in the CONFIGURATION section, below.
  206. In order to simplify this process, the [LibraryClasses] definitions, and others, are
  207. specified in the StdLib.inc file. If this file is included in the DSC file, usually at the
  208. end, then other DSC file changes or additions are unnecessary. This is further described in
  209. the CONFIGURATION section, below.
  210. Within the source files of the application, use of the Standard headers and
  211. library functions follow standard C programming practices as formalized by
  212. ISO/IEC 9899:1990, with Addendum 1, (C 95) C language specification.
  213. BUILD CONFIGURATION
  214. ===================
  215. DSC Files
  216. ---------
  217. All EDK II packages which build applications that use the standard libraries
  218. must include some "boilerplate" text in the package's .dsc file. To make it
  219. easier, and to reduce cut-and-paste errors, the "boilerplate" text has been
  220. consolidated into a single file, StdLib/StdLib.inc, which can be included in
  221. your .dsc file using the !include directive. The provided AppPkg.dsc and
  222. StdLib.dsc files do this on their last line.
  223. The "boilerplate" text can be included using a !include directive in the
  224. package's .dsc file. The provided AppPkg.dsc and StdLib.dsc files include
  225. the following "boilerplate" text:
  226. ##############################################################################
  227. #
  228. # Specify whether we are running in an emulation environment, or not.
  229. # Define EMULATE if we are, else keep the DEFINE commented out.
  230. #
  231. # DEFINE EMULATE = 1
  232. ##############################################################################
  233. #
  234. # Include Boilerplate text required for building with the Standard Libraries.
  235. #
  236. ##############################################################################
  237. !include StdLib/StdLib.inc
  238. Figure 1: "Boilerplate" Inclusion
  239. =================================
  240. The EMULATE macro must be defined if one desires to do source-level debugging within one of
  241. the emulated environments such as NT32Pkg or UnixPkg.
  242. The final boilerplate line, in Figure 1, includes the StdLib.inc file.
  243. Each section of StdLib/StdLib.inc is described below.
  244. If desired, all of the Socket applications, in AppPkg, can be built by including Sockets.inc:
  245. !include AppPkg/Applications/Sockets/Sockets.inc
  246. Figure 2: Socket Applications "Boilerplate" Inclusion
  247. =====================================================
  248. Descriptions of the Library Classes comprising the Standard Libraries,
  249. as shown in Figure 3: Library Class Descriptions, are provided.
  250. [LibraryClasses]
  251. #
  252. # C Standard Libraries
  253. #
  254. LibC|StdLib/LibC/LibC.inf
  255. LibCType|StdLib/LibC/Ctype/Ctype.inf
  256. LibLocale|StdLib/LibC/Locale/Locale.inf
  257. LibMath|StdLib/LibC/Math/Math.inf
  258. LibSignal|StdLib/LibC/Signal/Signal.inf
  259. LibStdio|StdLib/LibC/Stdio/Stdio.inf
  260. LibStdLib|StdLib/LibC/StdLib/StdLib.inf
  261. LibString|StdLib/LibC/String/String.inf
  262. LibTime|StdLib/LibC/Time/Time.inf
  263. LibUefi|StdLib/LibC/Uefi/Uefi.inf
  264. LibWchar|StdLib/LibC/Wchar/Wchar.inf
  265. # Common Utilities for Networking Libraries
  266. LibNetUtil|StdLib/LibC/NetUtil/NetUtil.inf
  267. # Additional libraries for POSIX functionality.
  268. LibErr|StdLib/PosixLib/Err/LibErr.inf
  269. LibGen|StdLib/PosixLib/Gen/LibGen.inf
  270. LibGlob|StdLib/PosixLib/Glob/LibGlob.inf
  271. LibStringlist|StdLib/PosixLib/Stringlist/LibStringlist.inf
  272. # Libraries for device abstractions within the Standard C Library
  273. # Applications should not directly access any functions defined in these libraries.
  274. LibGdtoa|StdLib/LibC/gdtoa/gdtoa.inf
  275. DevConsole|StdLib/LibC/Uefi/Devices/daConsole.inf
  276. DevShell|StdLib/LibC/Uefi/Devices/daShell.inf
  277. DevUtility|StdLib/LibC/Uefi/Devices/daUtility.inf
  278. [LibraryClasses.ARM.UEFI_APPLICATION]
  279. NULL|ArmPkg/Library/CompilerIntrinsicsLib/CompilerIntrinsicsLib.inf
  280. Figure 3: Library Class Descriptions
  281. ====================================
  282. The directives in Figure 4: Package Component Descriptions will create
  283. instances of the BaseLib and BaseMemoryLib library classes that are built
  284. with Link-time-Code-Generation disabled. This is necessary when using the
  285. Microsoft tool chains in order to allow the library's functions to be
  286. resolved during the second pass of the linker during Link-Time-Code-Generation
  287. of the application.
  288. A DXE driver version of the Socket library is also built.
  289. [Components]
  290. # BaseLib and BaseMemoryLib need to be built with the /GL- switch
  291. # when using the Microsoft tool chains. This is required so that
  292. # the library functions can be resolved during the second pass of
  293. # the linker during link-time-code-generation.
  294. #
  295. MdePkg/Library/BaseLib/BaseLib.inf {
  296. <BuildOptions>
  297. MSFT:*_*_*_CC_FLAGS = /X /Zc:wchar_t /GL-
  298. }
  299. MdePkg/Library/BaseMemoryLib/BaseMemoryLib.inf {
  300. <BuildOptions>
  301. MSFT:*_*_*_CC_FLAGS = /X /Zc:wchar_t /GL-
  302. }
  303. ##########
  304. # Socket Layer
  305. ##########
  306. StdLib/SocketDxe/SocketDxe.inf
  307. Figure 4: Package Component Descriptions
  308. ========================================
  309. Each compiler assumes, by default, that it will be used with standard libraries
  310. and headers provided by the compiler vendor. Many of these assumptions are
  311. incorrect for the UEFI environment. By including a BuildOptions section, as
  312. shown in Figure 5: Package Build Options, these assumptions can be
  313. tailored for compatibility with UEFI and the EDK II Standard Libraries.
  314. Note that the set of BuildOptions used is determined by the state of the EMULATE macro.
  315. [BuildOptions]
  316. !ifndef $(EMULATE)
  317. # These Build Options are used when building the Standard Libraries to be run
  318. # on real hardware.
  319. INTEL:*_*_IA32_CC_FLAGS = /Qfreestanding
  320. MSFT:*_*_IA32_CC_FLAGS = /X /Zc:wchar_t
  321. GCC:*_*_IA32_CC_FLAGS = -nostdinc -nostdlib
  322. !else
  323. # The Build Options, below, are only used when building the Standard Libraries
  324. # to be run under an emulation environment.
  325. # They disable optimization which facillitates debugging under the Emulation environment.
  326. INTEL:*_*_IA32_CC_FLAGS = /Od
  327. MSFT:*_*_IA32_CC_FLAGS = /Od
  328. GCC:*_*_IA32_CC_FLAGS = -O0
  329. Figure 5: Package Build Options
  330. ===============================
  331. INF Files
  332. =========
  333. The INF files for most modules will not require special directives in order to
  334. support the Standard Libraries. The two sections which require attention: LibraryClasses
  335. and BuildOptions, are described below.
  336. [LibraryClasses]
  337. UefiLib
  338. LibC
  339. LibString
  340. LibStdio
  341. DevShell
  342. Figure 6: Module Library Classes
  343. ================================
  344. Modules of type UEFI_APPLICATION that perform file I/O must include library
  345. class DevShell. Including this library class will allow file operations to be
  346. handled by the UEFI Shell. Without this class, only Console I/O is supported.
  347. An application's INF file might need to include a [BuildOptions] section
  348. specifying additional compiler and linker flags necessary to allow the
  349. application to be built. Usually, this section is not needed. When building
  350. code from external sources, though, it may be necessary to disable some
  351. warnings or enable/disable some compiler features.
  352. [BuildOptions]
  353. INTEL:*_*_*_CC_FLAGS = /Qdiag-disable:181,186
  354. MSFT:*_*_*_CC_FLAGS = /Oi- /wd4018 /wd4131
  355. GCC:*_*_IPF_SYMRENAME_FLAGS = --redefine-syms=Rename.txt
  356. Figure 7: Module Build Options
  357. ==============================
  358. TARGET-SYSTEM INSTALLATION
  359. ==========================
  360. Applications that use file system features or the Socket library depend upon
  361. the existence of a specific directory tree structure on the same volume that
  362. the application was loaded from. This tree structure is described below:
  363. /EFI Root of the UEFI system area.
  364. |- /Tools Directory containing applications.
  365. |- /Boot UEFI specified Boot directory.
  366. |- /StdLib Root of the Standard Libraries sub-tree.
  367. |- /etc Configuration files used by libraries.
  368. |- /tmp Temporary files created by tmpfile(), etc.
  369. The /Efi/StdLib/etc directory must be manually populated from the StdLib/Efi/etc source
  370. directory.
  371. IMPLEMENTATION-Specific Features
  372. ================================
  373. It is very strongly recommended that applications not use the long or
  374. unsigned long types. The size of these types varies between compilers and is one
  375. of the less portable aspects of C. Instead, one should use the UEFI defined
  376. types whenever possible. Use of these types, listed below for reference,
  377. ensures that the declared objects have unambiguous, explicitly declared, sizes
  378. and characteristics.
  379. UINT64 INT64 UINT32 INT32 UINT16 CHAR16
  380. INT16 BOOLEAN UINT8 CHAR8 INT8
  381. UINTN INTN PHYSICALADDRESS
  382. There are similar types declared in sys/types.h and related files.
  383. The types UINTN and INTN have the native width of the target processor
  384. architecture. Thus, INTN on IA32 has a width of 32 bits while INTN on X64 and
  385. IPF has a width of 64 bits.
  386. For maximum portability, data objects intended to hold addresses should be
  387. declared with type intptr_t or uintptr_t. These types, declared in
  388. sys/stdint.h, can be used to create objects capable of holding pointers. Note
  389. that these types will generate different sized objects on different processor
  390. architectures. If a constant size across all processors and compilers is
  391. needed, use type PHYSICAL_ADDRESS.
  392. Though not specifically required by the ISO/IEC 9899 standard, this
  393. implementation of the Standard C Library provides the following system calls
  394. which are declared in sys/EfiSysCall.h and/or unistd.h.
  395. close creat chmod dup dup2
  396. fcntl fstat getcwd ioctl isatty
  397. lseek lstat mkdir open poll
  398. read rename rmdir stat unlink write
  399. The open function will accept file names of "stdin:", "stdout:", and "stderr:"
  400. which cause the respective streams specified in the UEFI System Table to be
  401. opened. Normally, these are associated with the console device. When the
  402. application is first started, these streams are automatically opened on File
  403. Descriptors 0, 1, and 2 respectively.
  404. # # #