1 /* cmain.c - Startup code for the PowerPC. */
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/>.
22 #include <grub/kernel.h>
23 #include <grub/misc.h>
24 #include <grub/types.h>
25 #include <grub/machine/kernel.h>
26 #include <grub/ieee1275/ieee1275.h>
28 int (*grub_ieee1275_entry_fn
) (void *);
30 grub_ieee1275_phandle_t grub_ieee1275_chosen
;
31 grub_ieee1275_ihandle_t grub_ieee1275_mmu
;
33 static grub_uint32_t grub_ieee1275_flags
;
38 grub_ieee1275_test_flag (enum grub_ieee1275_flag flag
)
40 return (grub_ieee1275_flags
& (1 << flag
));
44 grub_ieee1275_set_flag (enum grub_ieee1275_flag flag
)
46 grub_ieee1275_flags
|= (1 << flag
);
49 #define SF "SmartFirmware(tm)"
50 #define OHW "PPC Open Hack'Ware"
53 grub_ieee1275_find_options (void)
55 grub_ieee1275_phandle_t root
;
56 grub_ieee1275_phandle_t options
;
57 grub_ieee1275_phandle_t openprom
;
58 grub_ieee1275_phandle_t bootrom
;
60 grub_uint32_t realmode
= 0;
62 int is_smartfirmware
= 0;
65 grub_ieee1275_finddevice ("/", &root
);
66 grub_ieee1275_finddevice ("/options", &options
);
67 grub_ieee1275_finddevice ("/openprom", &openprom
);
69 rc
= grub_ieee1275_get_integer_property (options
, "real-mode?", &realmode
,
71 if (((rc
>= 0) && realmode
) || (grub_ieee1275_mmu
== 0))
72 grub_ieee1275_set_flag (GRUB_IEEE1275_FLAG_REAL_MODE
);
74 rc
= grub_ieee1275_get_property (openprom
, "CodeGen-copyright",
75 tmp
, sizeof (tmp
), 0);
76 if (rc
>= 0 && !grub_strncmp (tmp
, SF
, sizeof (SF
) - 1))
79 rc
= grub_ieee1275_get_property (root
, "architecture",
80 tmp
, sizeof (tmp
), 0);
81 if (rc
>= 0 && !grub_strcmp (tmp
, "OLPC"))
86 /* Broken in all versions */
87 grub_ieee1275_set_flag (GRUB_IEEE1275_FLAG_BROKEN_OUTPUT
);
89 /* There are two incompatible ways of checking the version number. Try
91 rc
= grub_ieee1275_get_property (openprom
, "SmartFirmware-version",
92 tmp
, sizeof (tmp
), 0);
94 rc
= grub_ieee1275_get_property (openprom
, "firmware-version",
95 tmp
, sizeof (tmp
), 0);
98 /* It is tempting to implement a version parser to set the flags for
99 e.g. 1.3 and below. However, there's a special situation here.
100 3rd party updates which fix the partition bugs are common, and for
101 some reason their fixes aren't being merged into trunk. So for
102 example we know that 1.2 and 1.3 are broken, but there's 1.2.99
103 and 1.3.99 which are known good (and applying this workaround
104 would cause breakage). */
105 if (!grub_strcmp (tmp
, "1.0")
106 || !grub_strcmp (tmp
, "1.1")
107 || !grub_strcmp (tmp
, "1.2")
108 || !grub_strcmp (tmp
, "1.3"))
110 grub_ieee1275_set_flag (GRUB_IEEE1275_FLAG_NO_PARTITION_0
);
111 grub_ieee1275_set_flag (GRUB_IEEE1275_FLAG_0_BASED_PARTITIONS
);
118 /* OLPC / XO laptops have three kinds of storage devices:
120 - NAND flash. These are accessible via OFW callbacks, but:
121 - Follow strange semantics, imposed by hardware constraints.
122 - Its ABI is undocumented, and not stable.
123 They lack "device_type" property, which conveniently makes GRUB
126 - USB drives. Not accessible, because OFW shuts down the controller
127 in order to prevent collisions with applications accessing it
128 directly. Even worse, attempts to access it will NOT return
129 control to the caller, so we have to avoid probing them.
131 - SD cards. These work fine.
133 To avoid brekage, we only need to skip USB probing. However,
134 since detecting SD cards is more reliable, we do that instead.
137 grub_ieee1275_set_flag (GRUB_IEEE1275_FLAG_OFDISK_SDCARD_ONLY
);
140 if (! grub_ieee1275_finddevice ("/rom/boot-rom", &bootrom
))
142 rc
= grub_ieee1275_get_property (bootrom
, "model", tmp
, sizeof (tmp
), 0);
143 if (rc
>= 0 && !grub_strncmp (tmp
, OHW
, sizeof (OHW
) - 1))
145 grub_ieee1275_set_flag (GRUB_IEEE1275_FLAG_BROKEN_OUTPUT
);
146 grub_ieee1275_set_flag (GRUB_IEEE1275_FLAG_CANNOT_SET_COLORS
);
147 grub_ieee1275_set_flag (GRUB_IEEE1275_FLAG_CANNOT_INTERPRET
);
148 grub_ieee1275_set_flag (GRUB_IEEE1275_FLAG_FORCE_CLAIM
);
149 grub_ieee1275_set_flag (GRUB_IEEE1275_FLAG_NO_ANSI
);
158 grub_ieee1275_init (void)
160 grub_ieee1275_finddevice ("/chosen", &grub_ieee1275_chosen
);
162 if (grub_ieee1275_get_integer_property (grub_ieee1275_chosen
, "mmu", &grub_ieee1275_mmu
,
163 sizeof grub_ieee1275_mmu
, 0) < 0)
164 grub_ieee1275_mmu
= 0;
166 grub_ieee1275_find_options ();