]> git.ozlabs.org Git - yaboot.git/blob - first/ofboot
fc6b08aac08b16fc43e7aa4083e19265936408a9
[yaboot.git] / first / ofboot
1 #%ybinscript-1.1
2
3 ## THIS IS NOT A CONFFILE DO NOT EDIT !!!
4
5 ###############################################################################
6 ##
7 ## ofboot first stage autoconfiguring bootloader for yaboot and ybin
8 ## Copyright (C) 2000, 2001 Ethan Benson
9 ##
10 ## Forth code written by Chris Emerson
11 ##
12 ## Copyright (C) 2000, 2001 Chris Emerson
13 ##
14 ## Portions of Forth code also written by iNOUE Koich!
15 ##
16 ## Copyright (C) 2000, 2001 iNOUE Koich!
17 ##
18 ## This program is free software; you can redistribute it and/or
19 ## modify it under the terms of the GNU General Public License
20 ## as published by the Free Software Foundation; either version 2
21 ## of the License, or (at your option) any later version.
22 ##
23 ## This program is distributed in the hope that it will be useful,
24 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
25 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
26 ## GNU General Public License for more details.
27 ##
28 ## You should have received a copy of the GNU General Public License
29 ## along with this program; if not, write to the Free Software
30 ## Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
31 ##
32 ###############################################################################
33
34 ## THIS IS NOT A CONFFILE DO NOT EDIT !!!
35 ##
36 ## This script is not meant to be called directly, only by ybin.
37 ##
38 ## Usage: OS-count defaultos timeout fgc bgc osname oslabel oskey osdev osfile ...
39
40 DEBUG=0
41 PRG=ofboot
42
43 ## make sure we are called at least somewhat sanely.
44 if [ $# = 0 ] ; then
45     echo 1>&2 "$PRG: Need arguments"
46     exit 1
47 fi
48
49 if [ $# != "$(($1 * 5 + 5))" ] ; then
50     echo 1>&2 "$PRG: Invalid argument count: $# should be $(($1 * 5 + 5))"
51     exit 1
52 fi
53
54 if [ "$1" -gt 8 ] ; then
55     echo 1>&2 "$PRG: Maximum number of OSes is currently 8"
56     exit 1
57 fi
58
59 ## we need printf so \n works, but echo -e -n will sometimes do.
60 if [ "$(printf printf_test 2>/dev/null)" = printf_test ] ; then
61     PRINTF=printf
62 else
63     PRINTF="echo -e -n"
64 fi
65
66 ## make sure echo is not lame if we must use it.
67 if [ "$PRINTF" != printf ] ; then
68     if [ "$(echo -e -n echo_test)" != echo_test ] ; then
69         echo 1>&2 "$PRG: printf unavailable and echo is broken, sorry."
70         exit 1
71     fi
72 fi
73
74 ## get first 5 args which are global and dispose of them.
75 OSNUM="$1"
76 DEFAULTOS="$2"
77 TIMEOUT="$3"
78 FGCOLOR="$4"
79 BGCOLOR="$5"
80 shift 5
81
82 ## is a boot menu actually needed?
83 if [ "$OSNUM" = 1 ] ; then
84     MENU=0
85 else
86     MENU=1
87 fi
88
89 ## create the variables.
90 ##
91 ## OSNAME="$1"
92 ## OSLABEL="$2"
93 ## OSKEY="$3"
94 ## OSDEV="$4"
95 ## OSFILE="$5"
96
97 COUNT=1
98 while [ "$COUNT" -le "$OSNUM" ] ; do
99     case "$COUNT" in
100         1)
101         OSNAME1="$1"
102         [ "$DEBUG" = 1 ] && $PRINTF 1>&2 "$PRG: DEBUG: file1: $5\n"
103         [ "$COUNT" = "$OSNUM" ] && c="."
104         BTYA=": boot$1 \" Loading second stage bootstrap...\" .printf 100 ms load-base release-load-area \" ${4}${5}\" \$boot ;"
105         MENUYA="\" Press $3 for GNU/Linux${c-,}\"(0d 0a)\" .printf"
106         GETYA="      ascii $3 of \" $3 \"(0d 0a)\" .printf boot$1 endof"
107         shift 5
108         COUNT="$(($COUNT + 1))"
109         ;;
110         2)
111         [ "$DEBUG" = 1 ] && $PRINTF 1>&2 "$PRG: DEBUG: file2: $5\n"
112         [ "$COUNT" = "$OSNUM" ] && c="."
113         [ "$4" = "quit" ] && BOOT=quit || BOOT="load-base release-load-area \" ${4}${5}\" \$boot"
114         BT2=": boot$1 \" Booting $2...\" .printf 100 ms $BOOT ;"
115         MENU2="\"       $3 for $2${c-,}\"(0d 0a)\" .printf"
116         GET2="      ascii $3 of \" $3 \"(0d 0a)\" .printf boot$1 endof"
117         shift 5
118         COUNT="$(($COUNT + 1))"
119         ;;
120         3)
121         [ "$DEBUG" = 1 ] && $PRINTF 1>&2 "$PRG: DEBUG: file3: $5\n"
122         [ "$COUNT" = "$OSNUM" ] && c="."
123         [ "$4" = "quit" ] && BOOT=quit || BOOT="load-base release-load-area \" ${4}${5}\" \$boot"
124         BT3=": boot$1 \" Booting $2...\" .printf 100 ms $BOOT ;"
125         MENU3="\"       $3 for $2${c-,}\"(0d 0a)\" .printf"
126         GET3="      ascii $3 of \" $3 \"(0d 0a)\" .printf boot$1 endof"
127         shift 5
128         COUNT="$(($COUNT + 1))"
129         ;;
130         4)
131         [ "$DEBUG" = 1 ] && $PRINTF 1>&2 "$PRG: DEBUG: file4: $5\n"
132         [ "$COUNT" = "$OSNUM" ] && c="."
133         [ "$4" = "quit" ] && BOOT=quit || BOOT="load-base release-load-area \" ${4}${5}\" \$boot"
134         BT4=": boot$1 \" Booting $2...\" .printf 100 ms $BOOT ;"
135         MENU4="\"       $3 for $2${c-,}\"(0d 0a)\" .printf"
136         GET4="      ascii $3 of \" $3 \"(0d 0a)\" .printf boot$1 endof"
137         shift 5
138         COUNT="$(($COUNT + 1))"
139         ;;
140         5)
141         [ "$DEBUG" = 1 ] && $PRINTF 1>&2 "$PRG: DEBUG: file5: $5\n"
142         [ "$COUNT" = "$OSNUM" ] && c="."
143         [ "$4" = "quit" ] && BOOT=quit || BOOT="load-base release-load-area \" ${4}${5}\" \$boot"
144         BT5=": boot$1 \" Booting $2...\" .printf 100 ms $BOOT ;"
145         MENU5="\"       $3 for $2${c-,}\"(0d 0a)\" .printf"
146         GET5="      ascii $3 of \" $3 \"(0d 0a)\" .printf boot$1 endof"
147         shift 5
148         COUNT="$(($COUNT + 1))"
149         ;;
150         6)
151         [ "$DEBUG" = 1 ] && $PRINTF 1>&2 "$PRG: DEBUG: file6: $5\n"
152         [ "$COUNT" = "$OSNUM" ] && c="."
153         [ "$4" = "quit" ] && BOOT=quit || BOOT="load-base release-load-area \" ${4}${5}\" \$boot"
154         BT6=": boot$1 \" Booting $2...\" .printf 100 ms $BOOT ;"
155         MENU6="\"       $3 for $2${c-,}\"(0d 0a)\" .printf"
156         GET6="      ascii $3 of \" $3 \"(0d 0a)\" .printf boot$1 endof"
157         shift 5
158         COUNT="$(($COUNT + 1))"
159         ;;
160         7)
161         [ "$DEBUG" = 1 ] && $PRINTF 1>&2 "$PRG: DEBUG: file7: $5\n"
162         [ "$COUNT" = "$OSNUM" ] && c="."
163         [ "$4" = "quit" ] && BOOT=quit || BOOT="load-base release-load-area \" ${4}${5}\" \$boot"
164         BT7=": boot$1 \" Booting $2...\" .printf 100 ms $BOOT ;"
165         MENU7="\"       $3 for $2${c-,}\"(0d 0a)\" .printf"
166         GET7="      ascii $3 of \" $3 \"(0d 0a)\" .printf boot$1 endof"
167         shift 5
168         COUNT="$(($COUNT + 1))"
169         ;;
170         8)
171         [ "$DEBUG" = 1 ] && $PRINTF 1>&2 "$PRG: DEBUG: file8: $5\n"
172         [ "$COUNT" = "$OSNUM" ] && c="."
173         [ "$4" = "quit" ] && BOOT=quit || BOOT="load-base release-load-area \" ${4}${5}\" \$boot"
174         BT8=": boot$1 \" Booting $2...\" .printf 100 ms $BOOT ;"
175         MENU8="\"       $3 for $2${c-,}\"(0d 0a)\" .printf"
176         GET8="      ascii $3 of \" $3 \"(0d 0a)\" .printf boot$1 endof"
177         shift 5
178         COUNT="$(($COUNT + 1))"
179         ;;
180     esac
181 done
182
183 ## first OS is reserved.
184 if [ "$OSNAME1" != yaboot ] ; then
185     echo 1>&2 "ofboot: first OS must be yaboot"
186     exit 1
187 fi
188
189 ## concatenate the variables together.
190 case "$OSNUM" in
191     1)
192     BOOTVARS="${BTYA}"
193     MENUOPTS="${MENUYA}"
194     GETOS="${GETYA}"
195     ;;
196     2)
197     BOOTVARS="${BTYA}\n${BT2}"
198     MENUOPTS="${MENUYA}\n${MENU2}"
199     GETOS="${GETYA}\n${GET2}"
200     ;;
201     3)
202     BOOTVARS="${BTYA}\n${BT2}\n${BT3}"
203     MENUOPTS="${MENUYA}\n${MENU2}\n${MENU3}"
204     GETOS="${GETYA}\n${GET2}\n${GET3}"
205     ;;
206     4)
207     BOOTVARS="${BTYA}\n${BT2}\n${BT3}\n${BT4}"
208     MENUOPTS="${MENUYA}\n${MENU2}\n${MENU3}\n${MENU4}"
209     GETOS="${GETYA}\n${GET2}\n${GET3}\n${GET4}"
210     ;;
211     5)
212     BOOTVARS="${BTYA}\n${BT2}\n${BT3}\n${BT4}\n${BT5}"
213     MENUOPTS="${MENUYA}\n${MENU2}\n${MENU3}\n${MENU4}\n${MENU5}"
214     GETOS="${GETYA}\n${GET2}\n${GET3}\n${GET4}\n${GET5}"
215     ;;
216     6)
217     BOOTVARS="${BTYA}\n${BT2}\n${BT3}\n${BT4}\n${BT5}\n${BT6}"
218     MENUOPTS="${MENUYA}\n${MENU2}\n${MENU3}\n${MENU4}\n${MENU5}\n${MENU6}"
219     GETOS="${GETYA}\n${GET2}\n${GET3}\n${GET4}\n${GET5}\n${GET6}"
220     ;;
221     7)
222     BOOTVARS="${BTYA}\n${BT2}\n${BT3}\n${BT4}\n${BT5}\n${BT6}\n${BT7}"
223     MENUOPTS="${MENUYA}\n${MENU2}\n${MENU3}\n${MENU4}\n${MENU5}\n${MENU6}\n${MENU7}"
224     GETOS="${GETYA}\n${GET2}\n${GET3}\n${GET4}\n${GET5}\n${GET6}\n${GET7}"
225     ;;
226     8)
227     BOOTVARS="${BTYA}\n${BT2}\n${BT3}\n${BT4}\n${BT5}\n${BT6}\n${BT7}\n${BT8}"
228     MENUOPTS="${MENUYA}\n${MENU2}\n${MENU3}\n${MENU4}\n${MENU5}\n${MENU6}\n${MENU7}\n${MENU8}"
229     GETOS="${GETYA}\n${GET2}\n${GET3}\n${GET4}\n${GET5}\n${GET6}\n${GET7}\n${GET8}"
230     ;;
231 esac
232
233 if [ -n "$YBINOFICON" -a -f "$YBINOFICON" -a -r "$YBINOFICON" ] ; then
234     OFBOOTICON="$(cat "$YBINOFICON")"
235 else
236     OFBOOTICON="<OS-BADGE-ICONS>
237 1010
238 000000000000F8FEACF6000000000000
239 0000000000F5FFFFFEFEF50000000000
240 00000000002BFAFEFAFCF70000000000
241 0000000000F65D5857812B0000000000
242 0000000000F5350B2F88560000000000
243 0000000000F6335708F8FE0000000000
244 00000000005600F600F5FD8100000000
245 00000000F9F8000000F5FAFFF8000000
246 000000008100F5F50000F6FEFE000000
247 000000F8F700F500F50000FCFFF70000
248 00000088F70000F50000F5FCFF2B0000
249 0000002F582A00F5000008ADE02C0000
250 00090B0A35A62B0000002D3B350A0000
251 000A0A0B0B3BF60000505E0B0A0B0A00
252 002E350B0B2F87FAFCF45F0B2E090000
253 00000007335FF82BF72B575907000000
254 000000000000ACFFFF81000000000000
255 000000000081FFFFFFFF810000000000
256 0000000000FBFFFFFFFFAC0000000000
257 000000000081DFDFDFFFFB0000000000
258 000000000081DD5F83FFFD0000000000
259 000000000081DDDF5EACFF0000000000
260 0000000000FDF981F981FFFF00000000
261 00000000FFACF9F9F981FFFFAC000000
262 00000000FFF98181F9F981FFFF000000
263 000000ACACF981F981F9F9FFFFAC0000
264 000000FFACF9F981F9F981FFFFFB0000
265 00000083DFFBF981F9F95EFFFFFC0000
266 005F5F5FDDFFFBF9F9F983DDDD5F0000
267 005F5F5F5FDD81F9F9E7DF5F5F5F5F00
268 0083DD5F5F83FFFFFFFFDF5F835F0000
269 000000FBDDDFACFBACFBDFDFFB000000
270 000000000000FFFFFFFF000000000000
271 0000000000FFFFFFFFFFFF0000000000
272 0000000000FFFFFFFFFFFF0000000000
273 0000000000FFFFFFFFFFFF0000000000
274 0000000000FFFFFFFFFFFF0000000000
275 0000000000FFFFFFFFFFFF0000000000
276 0000000000FFFFFFFFFFFFFF00000000
277 00000000FFFFFFFFFFFFFFFFFF000000
278 00000000FFFFFFFFFFFFFFFFFF000000
279 000000FFFFFFFFFFFFFFFFFFFFFF0000
280 000000FFFFFFFFFFFFFFFFFFFFFF0000
281 000000FFFFFFFFFFFFFFFFFFFFFF0000
282 00FFFFFFFFFFFFFFFFFFFFFFFFFF0000
283 00FFFFFFFFFFFFFFFFFFFFFFFFFFFF00
284 00FFFFFFFFFFFFFFFFFFFFFFFFFF0000
285 000000FFFFFFFFFFFFFFFFFFFF000000
286 </OS-BADGE-ICONS>"
287 fi
288
289 ## create tmp files safely.
290 TMP="${TMPDIR:-/tmp}"
291 TMPBOOT=`mktemp -q "$TMP/ofboot.XXXXXX"`
292     if [ $? != 0 ] ; then
293         echo 1>&2 "Cannot create temp file, aborting."
294         exit 1
295     fi
296
297 ## create the real script
298 $PRINTF \
299 "<CHRP-BOOT>
300 <COMPATIBLE>
301 MacRISC
302 </COMPATIBLE>
303 <DESCRIPTION>
304 PowerPC GNU/Linux First Stage Bootstrap
305 </DESCRIPTION>
306 <BOOT-SCRIPT>
307 : .printf fb8-write drop ;
308 $BOOTVARS
309 \" screen\" output
310 variable interactive
311 $MENU interactive !
312
313 0 interactive @ = if
314   bootyaboot
315 then
316
317 dev screen
318 \" \"(0000000000aa00aa0000aaaaaa0000aa00aaaa5500aaaaaa)\" drop 0 7 set-colors
319 \" \"(5555555555ff55ff5555ffffff5555ff55ffffff55ffffff)\" drop 8 15 set-colors
320 device-end
321 $FGCOLOR to foreground-color
322 $BGCOLOR to background-color
323 \" \"(0C)\" .printf
324
325 \" First Stage GNU/Linux Bootstrap\"(0d 0a)\" .printf
326 \"  \"(0d 0a)\" .printf
327 $MENUOPTS
328 \"  \"(0d 0a)\" .printf
329 \" Boot: \" .printf
330 get-msecs d# $TIMEOUT 3E8 * +
331 begin
332   key? if
333     key case
334 $GETOS
335     endcase
336   then
337   dup get-msecs &lt;
338 until
339 drop
340 \"  \"(0d 0a)\" .printf $DEFAULTOS
341 </BOOT-SCRIPT>
342 $OFBOOTICON
343 </CHRP-BOOT>\n" > "$TMPBOOT"
344
345 echo "$TMPBOOT"