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