cmain.c 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. /* cmain.c - Startup code for the PowerPC. */
  2. /*
  3. * GRUB -- GRand Unified Bootloader
  4. * Copyright (C) 2003,2004,2005,2006,2007,2008 Free Software Foundation, Inc.
  5. *
  6. * GRUB is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * GRUB is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #include <grub/kernel.h>
  20. #include <grub/misc.h>
  21. #include <grub/types.h>
  22. #include <grub/ieee1275/ieee1275.h>
  23. int (*grub_ieee1275_entry_fn) (void *) GRUB_IEEE1275_ENTRY_FN_ATTRIBUTE;
  24. grub_ieee1275_phandle_t grub_ieee1275_chosen;
  25. grub_ieee1275_ihandle_t grub_ieee1275_mmu;
  26. static grub_uint32_t grub_ieee1275_flags;
  27. int
  28. grub_ieee1275_test_flag (enum grub_ieee1275_flag flag)
  29. {
  30. return (grub_ieee1275_flags & (1 << flag));
  31. }
  32. void
  33. grub_ieee1275_set_flag (enum grub_ieee1275_flag flag)
  34. {
  35. grub_ieee1275_flags |= (1 << flag);
  36. }
  37. static void
  38. grub_ieee1275_find_options (void)
  39. {
  40. grub_ieee1275_phandle_t root;
  41. grub_ieee1275_phandle_t options;
  42. grub_ieee1275_phandle_t openprom;
  43. grub_ieee1275_phandle_t bootrom;
  44. int rc;
  45. grub_uint32_t realmode = 0;
  46. char tmp[256];
  47. int is_smartfirmware = 0;
  48. int is_olpc = 0;
  49. int is_qemu = 0;
  50. grub_ssize_t actual;
  51. #ifdef __sparc__
  52. grub_ieee1275_set_flag (GRUB_IEEE1275_FLAG_NO_PARTITION_0);
  53. #endif
  54. grub_ieee1275_finddevice ("/", &root);
  55. grub_ieee1275_finddevice ("/options", &options);
  56. grub_ieee1275_finddevice ("/openprom", &openprom);
  57. rc = grub_ieee1275_get_integer_property (options, "real-mode?", &realmode,
  58. sizeof realmode, 0);
  59. if (((rc >= 0) && realmode) || (grub_ieee1275_mmu == 0))
  60. grub_ieee1275_set_flag (GRUB_IEEE1275_FLAG_REAL_MODE);
  61. rc = grub_ieee1275_get_property (openprom, "CodeGen-copyright",
  62. tmp, sizeof (tmp), 0);
  63. if (rc >= 0 && !grub_strncmp (tmp, "SmartFirmware(tm)",
  64. sizeof ("SmartFirmware(tm)") - 1))
  65. is_smartfirmware = 1;
  66. rc = grub_ieee1275_get_property (root, "architecture",
  67. tmp, sizeof (tmp), 0);
  68. if (rc >= 0 && !grub_strcmp (tmp, "OLPC"))
  69. is_olpc = 1;
  70. rc = grub_ieee1275_get_property (root, "model",
  71. tmp, sizeof (tmp), 0);
  72. if (rc >= 0 && (!grub_strcmp (tmp, "Emulated PC")
  73. || !grub_strcmp (tmp, "IBM pSeries (emulated by qemu)"))) {
  74. is_qemu = 1;
  75. }
  76. if (rc >= 0 && grub_strncmp (tmp, "IBM", 3) == 0)
  77. grub_ieee1275_set_flag (GRUB_IEEE1275_FLAG_NO_TREE_SCANNING_FOR_DISKS);
  78. /* Old Macs have no key repeat, newer ones have fully working one.
  79. The ones inbetween when repeated key generates an escaoe sequence
  80. only the escape is repeated. With this workaround however a fast
  81. e.g. down arrow-ESC is perceived as down arrow-down arrow which is
  82. also annoying but is less so than the original bug of exiting from
  83. the current window on arrow repeat. To avoid unaffected users suffering
  84. from this workaround match only exact models known to have this bug.
  85. */
  86. if (rc >= 0 && grub_strcmp (tmp, "PowerBook3,3") == 0)
  87. grub_ieee1275_set_flag (GRUB_IEEE1275_FLAG_BROKEN_REPEAT);
  88. rc = grub_ieee1275_get_property (root, "compatible",
  89. tmp, sizeof (tmp), &actual);
  90. if (rc >= 0)
  91. {
  92. char *ptr;
  93. for (ptr = tmp; ptr - tmp < actual; ptr += grub_strlen (ptr) + 1)
  94. {
  95. if (grub_memcmp (ptr, "MacRISC", sizeof ("MacRISC") - 1) == 0
  96. && (ptr[sizeof ("MacRISC") - 1] == 0
  97. || grub_isdigit (ptr[sizeof ("MacRISC") - 1])))
  98. {
  99. grub_ieee1275_set_flag (GRUB_IEEE1275_FLAG_BROKEN_ADDRESS_CELLS);
  100. grub_ieee1275_set_flag (GRUB_IEEE1275_FLAG_NO_OFNET_SUFFIX);
  101. grub_ieee1275_set_flag (GRUB_IEEE1275_FLAG_VIRT_TO_REAL_BROKEN);
  102. grub_ieee1275_set_flag (GRUB_IEEE1275_FLAG_CURSORONOFF_ANSI_BROKEN);
  103. break;
  104. }
  105. }
  106. }
  107. if (is_smartfirmware)
  108. {
  109. /* Broken in all versions */
  110. grub_ieee1275_set_flag (GRUB_IEEE1275_FLAG_BROKEN_OUTPUT);
  111. /* There are two incompatible ways of checking the version number. Try
  112. both. */
  113. rc = grub_ieee1275_get_property (openprom, "SmartFirmware-version",
  114. tmp, sizeof (tmp), 0);
  115. if (rc < 0)
  116. rc = grub_ieee1275_get_property (openprom, "firmware-version",
  117. tmp, sizeof (tmp), 0);
  118. if (rc >= 0)
  119. {
  120. /* It is tempting to implement a version parser to set the flags for
  121. e.g. 1.3 and below. However, there's a special situation here.
  122. 3rd party updates which fix the partition bugs are common, and for
  123. some reason their fixes aren't being merged into trunk. So for
  124. example we know that 1.2 and 1.3 are broken, but there's 1.2.99
  125. and 1.3.99 which are known good (and applying this workaround
  126. would cause breakage). */
  127. if (!grub_strcmp (tmp, "1.0")
  128. || !grub_strcmp (tmp, "1.1")
  129. || !grub_strcmp (tmp, "1.2")
  130. || !grub_strcmp (tmp, "1.3"))
  131. {
  132. grub_ieee1275_set_flag (GRUB_IEEE1275_FLAG_NO_PARTITION_0);
  133. grub_ieee1275_set_flag (GRUB_IEEE1275_FLAG_0_BASED_PARTITIONS);
  134. }
  135. }
  136. }
  137. if (is_olpc)
  138. {
  139. /* OLPC / XO laptops have three kinds of storage devices:
  140. - NAND flash. These are accessible via OFW callbacks, but:
  141. - Follow strange semantics, imposed by hardware constraints.
  142. - Its ABI is undocumented, and not stable.
  143. They lack "device_type" property, which conveniently makes GRUB
  144. skip them.
  145. - USB drives. Not accessible, because OFW shuts down the controller
  146. in order to prevent collisions with applications accessing it
  147. directly. Even worse, attempts to access it will NOT return
  148. control to the caller, so we have to avoid probing them.
  149. - SD cards. These work fine.
  150. To avoid breakage, we only need to skip USB probing. However,
  151. since detecting SD cards is more reliable, we do that instead.
  152. */
  153. grub_ieee1275_set_flag (GRUB_IEEE1275_FLAG_OFDISK_SDCARD_ONLY);
  154. grub_ieee1275_set_flag (GRUB_IEEE1275_FLAG_HAS_CURSORONOFF);
  155. }
  156. if (is_qemu)
  157. {
  158. /* OpenFirmware hangs on qemu if one requests any memory below 1.5 MiB. */
  159. grub_ieee1275_set_flag (GRUB_IEEE1275_FLAG_NO_PRE1_5M_CLAIM);
  160. grub_ieee1275_set_flag (GRUB_IEEE1275_FLAG_HAS_CURSORONOFF);
  161. }
  162. if (! grub_ieee1275_finddevice ("/rom/boot-rom", &bootrom)
  163. || ! grub_ieee1275_finddevice ("/boot-rom", &bootrom))
  164. {
  165. rc = grub_ieee1275_get_property (bootrom, "model", tmp, sizeof (tmp), 0);
  166. if (rc >= 0 && !grub_strncmp (tmp, "PPC Open Hack'Ware",
  167. sizeof ("PPC Open Hack'Ware") - 1))
  168. {
  169. grub_ieee1275_set_flag (GRUB_IEEE1275_FLAG_BROKEN_OUTPUT);
  170. grub_ieee1275_set_flag (GRUB_IEEE1275_FLAG_CANNOT_SET_COLORS);
  171. grub_ieee1275_set_flag (GRUB_IEEE1275_FLAG_CANNOT_INTERPRET);
  172. grub_ieee1275_set_flag (GRUB_IEEE1275_FLAG_FORCE_CLAIM);
  173. grub_ieee1275_set_flag (GRUB_IEEE1275_FLAG_NO_ANSI);
  174. }
  175. }
  176. }
  177. void
  178. grub_ieee1275_init (void)
  179. {
  180. grub_ieee1275_finddevice ("/chosen", &grub_ieee1275_chosen);
  181. if (grub_ieee1275_get_integer_property (grub_ieee1275_chosen, "mmu", &grub_ieee1275_mmu,
  182. sizeof grub_ieee1275_mmu, 0) < 0)
  183. grub_ieee1275_mmu = 0;
  184. grub_ieee1275_find_options ();
  185. }