Upgraded GRUB2 to 2.00 release.
[AROS.git] / arch / all-pc / boot / grub2-aros / grub-core / kern / ieee1275 / cmain.c
blobdd04d3976d3f5b96e667d3ed1194694e3b34182e
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.
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.
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.
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/>.
20 #include <grub/kernel.h>
21 #include <grub/misc.h>
22 #include <grub/types.h>
23 #include <grub/ieee1275/ieee1275.h>
25 int (*grub_ieee1275_entry_fn) (void *);
27 grub_ieee1275_phandle_t grub_ieee1275_chosen;
28 grub_ieee1275_ihandle_t grub_ieee1275_mmu;
30 static grub_uint32_t grub_ieee1275_flags;
34 int
35 grub_ieee1275_test_flag (enum grub_ieee1275_flag flag)
37 return (grub_ieee1275_flags & (1 << flag));
40 void
41 grub_ieee1275_set_flag (enum grub_ieee1275_flag flag)
43 grub_ieee1275_flags |= (1 << flag);
46 #define SF "SmartFirmware(tm)"
47 #define OHW "PPC Open Hack'Ware"
49 static void
50 grub_ieee1275_find_options (void)
52 grub_ieee1275_phandle_t root;
53 grub_ieee1275_phandle_t options;
54 grub_ieee1275_phandle_t openprom;
55 grub_ieee1275_phandle_t bootrom;
56 int rc;
57 grub_uint32_t realmode = 0;
58 char tmp[256];
59 int is_smartfirmware = 0;
60 int is_olpc = 0;
61 int is_qemu = 0;
62 grub_ssize_t actual;
64 #ifdef __sparc__
65 grub_ieee1275_set_flag (GRUB_IEEE1275_FLAG_NO_PARTITION_0);
66 #endif
68 grub_ieee1275_finddevice ("/", &root);
69 grub_ieee1275_finddevice ("/options", &options);
70 grub_ieee1275_finddevice ("/openprom", &openprom);
72 rc = grub_ieee1275_get_integer_property (options, "real-mode?", &realmode,
73 sizeof realmode, 0);
74 if (((rc >= 0) && realmode) || (grub_ieee1275_mmu == 0))
75 grub_ieee1275_set_flag (GRUB_IEEE1275_FLAG_REAL_MODE);
77 rc = grub_ieee1275_get_property (openprom, "CodeGen-copyright",
78 tmp, sizeof (tmp), 0);
79 if (rc >= 0 && !grub_strncmp (tmp, SF, sizeof (SF) - 1))
80 is_smartfirmware = 1;
82 rc = grub_ieee1275_get_property (root, "architecture",
83 tmp, sizeof (tmp), 0);
84 if (rc >= 0 && !grub_strcmp (tmp, "OLPC"))
85 is_olpc = 1;
87 rc = grub_ieee1275_get_property (root, "model",
88 tmp, sizeof (tmp), 0);
89 if (rc >= 0 && !grub_strcmp (tmp, "Emulated PC"))
90 is_qemu = 1;
92 if (rc >= 0 && grub_strncmp (tmp, "IBM", 3) == 0)
93 grub_ieee1275_set_flag (GRUB_IEEE1275_FLAG_NO_TREE_SCANNING_FOR_DISKS);
95 /* Old Macs have no key repeat, newer ones have fully working one.
96 The ones inbetween when repeated key generates an escaoe sequence
97 only the escape is repeated. With this workaround however a fast
98 e.g. down arrow-ESC is perceived as down arrow-down arrow which is
99 also annoying but is less so than the original bug of exiting from
100 the current window on arrow repeat. To avoid unaffected users suffering
101 from this workaround match only exact models known to have this bug.
103 if (rc >= 0 && grub_strcmp (tmp, "PowerBook3,3") == 0)
104 grub_ieee1275_set_flag (GRUB_IEEE1275_FLAG_BROKEN_REPEAT);
106 rc = grub_ieee1275_get_property (root, "compatible",
107 tmp, sizeof (tmp), &actual);
108 if (rc >= 0)
110 char *ptr;
111 for (ptr = tmp; ptr - tmp < actual; ptr += grub_strlen (ptr) + 1)
113 if (grub_memcmp (ptr, "MacRISC", sizeof ("MacRISC") - 1) == 0
114 && (ptr[sizeof ("MacRISC") - 1] == 0
115 || grub_isdigit (ptr[sizeof ("MacRISC") - 1])))
117 grub_ieee1275_set_flag (GRUB_IEEE1275_FLAG_BROKEN_ADDRESS_CELLS);
118 grub_ieee1275_set_flag (GRUB_IEEE1275_FLAG_NO_OFNET_SUFFIX);
119 grub_ieee1275_set_flag (GRUB_IEEE1275_FLAG_VIRT_TO_REAL_BROKEN);
120 break;
125 if (is_smartfirmware)
127 /* Broken in all versions */
128 grub_ieee1275_set_flag (GRUB_IEEE1275_FLAG_BROKEN_OUTPUT);
130 /* There are two incompatible ways of checking the version number. Try
131 both. */
132 rc = grub_ieee1275_get_property (openprom, "SmartFirmware-version",
133 tmp, sizeof (tmp), 0);
134 if (rc < 0)
135 rc = grub_ieee1275_get_property (openprom, "firmware-version",
136 tmp, sizeof (tmp), 0);
137 if (rc >= 0)
139 /* It is tempting to implement a version parser to set the flags for
140 e.g. 1.3 and below. However, there's a special situation here.
141 3rd party updates which fix the partition bugs are common, and for
142 some reason their fixes aren't being merged into trunk. So for
143 example we know that 1.2 and 1.3 are broken, but there's 1.2.99
144 and 1.3.99 which are known good (and applying this workaround
145 would cause breakage). */
146 if (!grub_strcmp (tmp, "1.0")
147 || !grub_strcmp (tmp, "1.1")
148 || !grub_strcmp (tmp, "1.2")
149 || !grub_strcmp (tmp, "1.3"))
151 grub_ieee1275_set_flag (GRUB_IEEE1275_FLAG_NO_PARTITION_0);
152 grub_ieee1275_set_flag (GRUB_IEEE1275_FLAG_0_BASED_PARTITIONS);
157 if (is_olpc)
159 /* OLPC / XO laptops have three kinds of storage devices:
161 - NAND flash. These are accessible via OFW callbacks, but:
162 - Follow strange semantics, imposed by hardware constraints.
163 - Its ABI is undocumented, and not stable.
164 They lack "device_type" property, which conveniently makes GRUB
165 skip them.
167 - USB drives. Not accessible, because OFW shuts down the controller
168 in order to prevent collisions with applications accessing it
169 directly. Even worse, attempts to access it will NOT return
170 control to the caller, so we have to avoid probing them.
172 - SD cards. These work fine.
174 To avoid breakage, we only need to skip USB probing. However,
175 since detecting SD cards is more reliable, we do that instead.
178 grub_ieee1275_set_flag (GRUB_IEEE1275_FLAG_OFDISK_SDCARD_ONLY);
179 grub_ieee1275_set_flag (GRUB_IEEE1275_FLAG_HAS_CURSORONOFF);
182 if (is_qemu)
184 /* OpenFirmware hangs on qemu if one requests any memory below 1.5 MiB. */
185 grub_ieee1275_set_flag (GRUB_IEEE1275_FLAG_NO_PRE1_5M_CLAIM);
187 grub_ieee1275_set_flag (GRUB_IEEE1275_FLAG_HAS_CURSORONOFF);
190 if (! grub_ieee1275_finddevice ("/rom/boot-rom", &bootrom))
192 rc = grub_ieee1275_get_property (bootrom, "model", tmp, sizeof (tmp), 0);
193 if (rc >= 0 && !grub_strncmp (tmp, OHW, sizeof (OHW) - 1))
195 grub_ieee1275_set_flag (GRUB_IEEE1275_FLAG_BROKEN_OUTPUT);
196 grub_ieee1275_set_flag (GRUB_IEEE1275_FLAG_CANNOT_SET_COLORS);
197 grub_ieee1275_set_flag (GRUB_IEEE1275_FLAG_CANNOT_INTERPRET);
198 grub_ieee1275_set_flag (GRUB_IEEE1275_FLAG_FORCE_CLAIM);
199 grub_ieee1275_set_flag (GRUB_IEEE1275_FLAG_NO_ANSI);
204 #undef SF
205 #undef OHW
207 void
208 grub_ieee1275_init (void)
210 grub_ieee1275_finddevice ("/chosen", &grub_ieee1275_chosen);
212 if (grub_ieee1275_get_integer_property (grub_ieee1275_chosen, "mmu", &grub_ieee1275_mmu,
213 sizeof grub_ieee1275_mmu, 0) < 0)
214 grub_ieee1275_mmu = 0;
216 grub_ieee1275_find_options ();