build.ck 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. /*++
  2. Copyright (c) 2014 Minoca Corp.
  3. This file is licensed under the terms of the GNU General Public License
  4. version 3. Alternative licensing terms are available. Contact
  5. info@minocacorp.com for details. See the LICENSE file at the root of this
  6. project for complete licensing information.
  7. Module Name:
  8. Boot Manager
  9. Abstract:
  10. This module implements the boot manager, which can load an operating
  11. system loader. In a multi-boot system, there would be one boot manager
  12. that can load one of many OS loaders (including downstream loaders).
  13. Author:
  14. Evan Green 21-Feb-2014
  15. Environment:
  16. Boot
  17. --*/
  18. from menv import binplace, staticApplication, flattenedBinary, mconfig;
  19. function build() {
  20. var arch = mconfig.arch;
  21. var baseRtl = "lib/rtl/base:basertl";
  22. var bootmanPe;
  23. var commonSources;
  24. var efiApp;
  25. var efiConfig;
  26. var efiLibs;
  27. var efiSources;
  28. var elfconvConfig;
  29. var entries;
  30. var flattened;
  31. var includes;
  32. var linkerScript;
  33. var pcatApp;
  34. var pcatConfig = {};
  35. var pcatLibs;
  36. var pcatSources;
  37. var sourcesConfig;
  38. var x6432 = "";
  39. commonSources = [
  40. "bootman.c",
  41. "bootim.c"
  42. ];
  43. pcatSources = [
  44. "pcat/x86/entry.S",
  45. "bootman.c",
  46. "bootim.c",
  47. "pcat/bootxfr.c",
  48. "pcat/main.c",
  49. "pcat/paging.c"
  50. ];
  51. efiSources = [
  52. "efi/bootxfr.c",
  53. "efi/main.c"
  54. ];
  55. includes = [
  56. "$S/boot/lib/include",
  57. "$S/boot/bootman"
  58. ];
  59. sourcesConfig = {
  60. "CFLAGS": ["-fshort-wchar"],
  61. };
  62. efiConfig = {
  63. "LDFLAGS": ["-pie"]
  64. };
  65. efiLibs = [
  66. "kernel/kd:kdboot",
  67. "kernel/hl:hlboot",
  68. "lib/im:imu",
  69. "lib/bconflib:bconf",
  70. "kernel/kd/kdusb:kdnousb",
  71. "boot/lib:bootefi",
  72. "lib/basevid:basevid",
  73. "lib/fatlib:fat",
  74. "kernel/mm:mmboot"
  75. ];
  76. if ((arch == "armv7") || (arch == "armv6")) {
  77. linkerScript = "$S/uefi/include/link_arm.x";
  78. efiConfig["LDFLAGS"] += ["-Wl,--no-wchar-size-warning"];
  79. baseRtl = "lib/rtl/base:basertlb";
  80. efiLibs += ["kernel:archboot"];
  81. } else if (arch == "x86") {
  82. linkerScript = "$S/uefi/include/link_x86.x";
  83. pcatSources += [
  84. "pcat/x86/xferc.c"
  85. ];
  86. } else if (arch == "x64") {
  87. linkerScript = "$S/uefi/include/link_x64.x";
  88. pcatSources += [
  89. "pcat/x64/xfera.S",
  90. "pcat/x64/xferc.c"
  91. ];
  92. }
  93. efiLibs += [
  94. baseRtl,
  95. "lib/rtl/kmode:krtl"
  96. ];
  97. efiApp = {
  98. "label": "bootmefi.elf",
  99. "inputs": commonSources + efiSources + efiLibs,
  100. "sources_config": sourcesConfig,
  101. "includes": includes,
  102. "config": efiConfig,
  103. "entry": "BmEfiApplicationMain",
  104. "linker_script": linkerScript
  105. };
  106. entries = staticApplication(efiApp);
  107. //
  108. // Convert the ELF image into an EFI PE image.
  109. //
  110. elfconvConfig = {
  111. "ELFCONV_FLAGS": "-t efiapp"
  112. };
  113. bootmanPe = {
  114. "type": "target",
  115. "label": "bootmefi.efi",
  116. "inputs": [":bootmefi.elf"],
  117. "implicit": ["uefi/tools/elfconv:elfconv"],
  118. "tool": "elfconv",
  119. "config": elfconvConfig,
  120. "nostrip": true
  121. };
  122. entries += binplace(bootmanPe);
  123. //
  124. // On PC machines, build the BIOS version as well. The boot manager is
  125. // 32-bits even on 64-bit machines so that both 32 and 64-bit OS loaders
  126. // can be launched. This means that on x64 all the libraries need to be
  127. // recompiled as 32-bit libraries.
  128. //
  129. if ((arch == "x86") || (arch == "x64")) {
  130. if (arch == "x64") {
  131. x6432 = "32";
  132. pcatConfig["LDFLAGS"] = ["-m32"];
  133. sourcesConfig["CPPFLAGS"] = ["-m32"];
  134. }
  135. pcatLibs = [
  136. "kernel/kd:kdboot" + x6432,
  137. "kernel/hl:hlboot" + x6432,
  138. "lib/im:imu" + x6432,
  139. "lib/bconflib:bconf" + x6432,
  140. "kernel/kd/kdusb:kdnousb" + x6432,
  141. "boot/lib:bootpcat" + x6432,
  142. "lib/partlib:partlib" + x6432,
  143. "lib/basevid:basevid" + x6432,
  144. "lib/fatlib:fat" + x6432,
  145. "kernel/mm:mmboot" + x6432,
  146. "lib/rtl/base:basertl" + x6432,
  147. "lib/rtl/kmode:krtl" + x6432
  148. ];
  149. pcatApp = {
  150. "label": "bootman",
  151. "inputs": pcatSources + pcatLibs,
  152. "sources_config": sourcesConfig,
  153. "includes": includes,
  154. "config": pcatConfig,
  155. "text_address": "0x100000",
  156. "binplace": "bin",
  157. "prefix": "pcat"
  158. };
  159. entries += staticApplication(pcatApp);
  160. //
  161. // Flatten the image so the VBR can load it directly into memory.
  162. //
  163. flattened = {
  164. "label": "bootman.bin",
  165. "inputs": [":bootman"],
  166. "binplace": "bin",
  167. "nostrip": true
  168. };
  169. flattened = flattenedBinary(flattened);
  170. entries += flattened;
  171. }
  172. return entries;
  173. }