]> git.ozlabs.org Git - yaboot.git/blob - first/ofboot
Commit yaboot 1.3.4-pre2
[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
114         [ "$1" = "ybsd" ] && BOOT="load-base release-load-area \" ${4}${5%/*} ${5##*/},/bsd\" \$boot"
115         [ "$1" != ybsd -a "$4" != quit  ] && BOOT="load-base release-load-area \" ${4}${5}\" \$boot"
116         BT2=": boot$1 \" Booting $2...\" .printf 100 ms $BOOT ;"
117         MENU2="\"       $3 for $2${c-,}\"(0d 0a)\" .printf"
118         GET2="      ascii $3 of \" $3 \"(0d 0a)\" .printf boot$1 endof"
119         shift 5
120         COUNT="$(($COUNT + 1))"
121         ;;
122         3)
123         [ "$DEBUG" = 1 ] && $PRINTF 1>&2 "$PRG: DEBUG: file3: $5\n"
124         [ "$COUNT" = "$OSNUM" ] && c="."
125         [ "$4" = "quit" ] && BOOT=quit
126         [ "$1" = "ybsd" ] && BOOT="load-base release-load-area \" ${4}${5%/*} ${5##*/},/bsd\" \$boot"
127         [ "$1" != ybsd -a "$4" != quit  ] && BOOT="load-base release-load-area \" ${4}${5}\" \$boot"
128         BT3=": boot$1 \" Booting $2...\" .printf 100 ms $BOOT ;"
129         MENU3="\"       $3 for $2${c-,}\"(0d 0a)\" .printf"
130         GET3="      ascii $3 of \" $3 \"(0d 0a)\" .printf boot$1 endof"
131         shift 5
132         COUNT="$(($COUNT + 1))"
133         ;;
134         4)
135         [ "$DEBUG" = 1 ] && $PRINTF 1>&2 "$PRG: DEBUG: file4: $5\n"
136         [ "$COUNT" = "$OSNUM" ] && c="."
137         [ "$4" = "quit" ] && BOOT=quit
138         [ "$1" = "ybsd" ] && BOOT="load-base release-load-area \" ${4}${5%/*} ${5##*/},/bsd\" \$boot"
139         [ "$1" != ybsd -a "$4" != quit  ] && BOOT="load-base release-load-area \" ${4}${5}\" \$boot"
140         BT4=": boot$1 \" Booting $2...\" .printf 100 ms $BOOT ;"
141         MENU4="\"       $3 for $2${c-,}\"(0d 0a)\" .printf"
142         GET4="      ascii $3 of \" $3 \"(0d 0a)\" .printf boot$1 endof"
143         shift 5
144         COUNT="$(($COUNT + 1))"
145         ;;
146         5)
147         [ "$DEBUG" = 1 ] && $PRINTF 1>&2 "$PRG: DEBUG: file5: $5\n"
148         [ "$COUNT" = "$OSNUM" ] && c="."
149         [ "$4" = "quit" ] && BOOT=quit
150         [ "$1" = "ybsd" ] && BOOT="load-base release-load-area \" ${4}${5%/*} ${5##*/},/bsd\" \$boot"
151         [ "$1" != ybsd -a "$4" != quit  ] && BOOT="load-base release-load-area \" ${4}${5}\" \$boot"
152         BT5=": boot$1 \" Booting $2...\" .printf 100 ms $BOOT ;"
153         MENU5="\"       $3 for $2${c-,}\"(0d 0a)\" .printf"
154         GET5="      ascii $3 of \" $3 \"(0d 0a)\" .printf boot$1 endof"
155         shift 5
156         COUNT="$(($COUNT + 1))"
157         ;;
158         6)
159         [ "$DEBUG" = 1 ] && $PRINTF 1>&2 "$PRG: DEBUG: file6: $5\n"
160         [ "$COUNT" = "$OSNUM" ] && c="."
161         [ "$4" = "quit" ] && BOOT=quit
162         [ "$1" = "ybsd" ] && BOOT="load-base release-load-area \" ${4}${5%/*} ${5##*/},/bsd\" \$boot"
163         [ "$1" != ybsd -a "$4" != quit  ] && BOOT="load-base release-load-area \" ${4}${5}\" \$boot"
164         BT6=": boot$1 \" Booting $2...\" .printf 100 ms $BOOT ;"
165         MENU6="\"       $3 for $2${c-,}\"(0d 0a)\" .printf"
166         GET6="      ascii $3 of \" $3 \"(0d 0a)\" .printf boot$1 endof"
167         shift 5
168         COUNT="$(($COUNT + 1))"
169         ;;
170         7)
171         [ "$DEBUG" = 1 ] && $PRINTF 1>&2 "$PRG: DEBUG: file7: $5\n"
172         [ "$COUNT" = "$OSNUM" ] && c="."
173         [ "$4" = "quit" ] && BOOT=quit
174         [ "$1" = "ybsd" ] && BOOT="load-base release-load-area \" ${4}${5%/*} ${5##*/},/bsd\" \$boot"
175         [ "$1" != ybsd -a "$4" != quit  ] && BOOT="load-base release-load-area \" ${4}${5}\" \$boot"
176         BT7=": boot$1 \" Booting $2...\" .printf 100 ms $BOOT ;"
177         MENU7="\"       $3 for $2${c-,}\"(0d 0a)\" .printf"
178         GET7="      ascii $3 of \" $3 \"(0d 0a)\" .printf boot$1 endof"
179         shift 5
180         COUNT="$(($COUNT + 1))"
181         ;;
182         8)
183         [ "$DEBUG" = 1 ] && $PRINTF 1>&2 "$PRG: DEBUG: file8: $5\n"
184         [ "$COUNT" = "$OSNUM" ] && c="."
185         [ "$4" = "quit" ] && BOOT=quit
186         [ "$1" = "ybsd" ] && BOOT="load-base release-load-area \" ${4}${5%/*} ${5##*/},/bsd\" \$boot"
187         [ "$1" != ybsd -a "$4" != quit  ] && BOOT="load-base release-load-area \" ${4}${5}\" \$boot"
188         BT8=": boot$1 \" Booting $2...\" .printf 100 ms $BOOT ;"
189         MENU8="\"       $3 for $2${c-,}\"(0d 0a)\" .printf"
190         GET8="      ascii $3 of \" $3 \"(0d 0a)\" .printf boot$1 endof"
191         shift 5
192         COUNT="$(($COUNT + 1))"
193         ;;
194     esac
195 done
196
197 ## first OS is reserved.
198 if [ "$OSNAME1" != yaboot ] ; then
199     echo 1>&2 "ofboot: first OS must be yaboot"
200     exit 1
201 fi
202
203 ## concatenate the variables together.
204 case "$OSNUM" in
205     1)
206     BOOTVARS="${BTYA}"
207     MENUOPTS="${MENUYA}"
208     GETOS="${GETYA}"
209     ;;
210     2)
211     BOOTVARS="${BTYA}\n${BT2}"
212     MENUOPTS="${MENUYA}\n${MENU2}"
213     GETOS="${GETYA}\n${GET2}"
214     ;;
215     3)
216     BOOTVARS="${BTYA}\n${BT2}\n${BT3}"
217     MENUOPTS="${MENUYA}\n${MENU2}\n${MENU3}"
218     GETOS="${GETYA}\n${GET2}\n${GET3}"
219     ;;
220     4)
221     BOOTVARS="${BTYA}\n${BT2}\n${BT3}\n${BT4}"
222     MENUOPTS="${MENUYA}\n${MENU2}\n${MENU3}\n${MENU4}"
223     GETOS="${GETYA}\n${GET2}\n${GET3}\n${GET4}"
224     ;;
225     5)
226     BOOTVARS="${BTYA}\n${BT2}\n${BT3}\n${BT4}\n${BT5}"
227     MENUOPTS="${MENUYA}\n${MENU2}\n${MENU3}\n${MENU4}\n${MENU5}"
228     GETOS="${GETYA}\n${GET2}\n${GET3}\n${GET4}\n${GET5}"
229     ;;
230     6)
231     BOOTVARS="${BTYA}\n${BT2}\n${BT3}\n${BT4}\n${BT5}\n${BT6}"
232     MENUOPTS="${MENUYA}\n${MENU2}\n${MENU3}\n${MENU4}\n${MENU5}\n${MENU6}"
233     GETOS="${GETYA}\n${GET2}\n${GET3}\n${GET4}\n${GET5}\n${GET6}"
234     ;;
235     7)
236     BOOTVARS="${BTYA}\n${BT2}\n${BT3}\n${BT4}\n${BT5}\n${BT6}\n${BT7}"
237     MENUOPTS="${MENUYA}\n${MENU2}\n${MENU3}\n${MENU4}\n${MENU5}\n${MENU6}\n${MENU7}"
238     GETOS="${GETYA}\n${GET2}\n${GET3}\n${GET4}\n${GET5}\n${GET6}\n${GET7}"
239     ;;
240     8)
241     BOOTVARS="${BTYA}\n${BT2}\n${BT3}\n${BT4}\n${BT5}\n${BT6}\n${BT7}\n${BT8}"
242     MENUOPTS="${MENUYA}\n${MENU2}\n${MENU3}\n${MENU4}\n${MENU5}\n${MENU6}\n${MENU7}\n${MENU8}"
243     GETOS="${GETYA}\n${GET2}\n${GET3}\n${GET4}\n${GET5}\n${GET6}\n${GET7}\n${GET8}"
244     ;;
245 esac
246
247 if [ -n "$YBINOFICON" -a -f "$YBINOFICON" -a -r "$YBINOFICON" ] ; then
248     OFBOOTICON="$(cat "$YBINOFICON")"
249 else
250     OFBOOTICON="<OS-BADGE-ICONS>
251 1010
252 000000000000F8FEACF6000000000000
253 0000000000F5FFFFFEFEF50000000000
254 00000000002BFAFEFAFCF70000000000
255 0000000000F65D5857812B0000000000
256 0000000000F5350B2F88560000000000
257 0000000000F6335708F8FE0000000000
258 00000000005600F600F5FD8100000000
259 00000000F9F8000000F5FAFFF8000000
260 000000008100F5F50000F6FEFE000000
261 000000F8F700F500F50000FCFFF70000
262 00000088F70000F50000F5FCFF2B0000
263 0000002F582A00F5000008ADE02C0000
264 00090B0A35A62B0000002D3B350A0000
265 000A0A0B0B3BF60000505E0B0A0B0A00
266 002E350B0B2F87FAFCF45F0B2E090000
267 00000007335FF82BF72B575907000000
268 000000000000ACFFFF81000000000000
269 000000000081FFFFFFFF810000000000
270 0000000000FBFFFFFFFFAC0000000000
271 000000000081DFDFDFFFFB0000000000
272 000000000081DD5F83FFFD0000000000
273 000000000081DDDF5EACFF0000000000
274 0000000000FDF981F981FFFF00000000
275 00000000FFACF9F9F981FFFFAC000000
276 00000000FFF98181F9F981FFFF000000
277 000000ACACF981F981F9F9FFFFAC0000
278 000000FFACF9F981F9F981FFFFFB0000
279 00000083DFFBF981F9F95EFFFFFC0000
280 005F5F5FDDFFFBF9F9F983DDDD5F0000
281 005F5F5F5FDD81F9F9E7DF5F5F5F5F00
282 0083DD5F5F83FFFFFFFFDF5F835F0000
283 000000FBDDDFACFBACFBDFDFFB000000
284 000000000000FFFFFFFF000000000000
285 0000000000FFFFFFFFFFFF0000000000
286 0000000000FFFFFFFFFFFF0000000000
287 0000000000FFFFFFFFFFFF0000000000
288 0000000000FFFFFFFFFFFF0000000000
289 0000000000FFFFFFFFFFFF0000000000
290 0000000000FFFFFFFFFFFFFF00000000
291 00000000FFFFFFFFFFFFFFFFFF000000
292 00000000FFFFFFFFFFFFFFFFFF000000
293 000000FFFFFFFFFFFFFFFFFFFFFF0000
294 000000FFFFFFFFFFFFFFFFFFFFFF0000
295 000000FFFFFFFFFFFFFFFFFFFFFF0000
296 00FFFFFFFFFFFFFFFFFFFFFFFFFF0000
297 00FFFFFFFFFFFFFFFFFFFFFFFFFFFF00
298 00FFFFFFFFFFFFFFFFFFFFFFFFFF0000
299 000000FFFFFFFFFFFFFFFFFFFF000000
300 </OS-BADGE-ICONS>"
301 fi
302
303 ## create tmp files safely.
304 TMP="${TMPDIR:-/tmp}"
305 TMPBOOT=`mktemp -q "$TMP/ofboot.XXXXXX"`
306     if [ $? != 0 ] ; then
307         echo 1>&2 "Cannot create temp file, aborting."
308         exit 1
309     fi
310
311 ## create the real script
312 $PRINTF \
313 "<CHRP-BOOT>
314 <COMPATIBLE>
315 MacRISC
316 </COMPATIBLE>
317 <DESCRIPTION>
318 PowerPC GNU/Linux First Stage Bootstrap
319 </DESCRIPTION>
320 <BOOT-SCRIPT>
321 : .printf fb8-write drop ;
322 $BOOTVARS
323 \" screen\" output
324 variable interactive
325 $MENU interactive !
326
327 0 interactive @ = if
328   bootyaboot
329 then
330
331 dev screen
332 \" \"(0000000000aa00aa0000aaaaaa0000aa00aaaa5500aaaaaa)\" drop 0 7 set-colors
333 \" \"(5555555555ff55ff5555ffffff5555ff55ffffff55ffffff)\" drop 8 15 set-colors
334 device-end
335 $FGCOLOR to foreground-color
336 $BGCOLOR to background-color
337 \" \"(0C)\" .printf
338
339 \" First Stage GNU/Linux Bootstrap\"(0d 0a)\" .printf
340 \"  \"(0d 0a)\" .printf
341 $MENUOPTS
342 \"  \"(0d 0a)\" .printf
343 \" Boot: \" .printf
344 get-msecs d# $TIMEOUT 3E8 * +
345 begin
346   key? if
347     key case
348 $GETOS
349     endcase
350   then
351   dup get-msecs &lt;
352 until
353 drop
354 \"  \"(0d 0a)\" .printf $DEFAULTOS
355 </BOOT-SCRIPT>
356 $OFBOOTICON
357 </CHRP-BOOT>\n" > "$TMPBOOT"
358
359 echo "$TMPBOOT"