Fix ppc64 iso creation. Add console machine_type for ppc yaboot separation.
[catalyst.git] / targets / support / bootloader-setup.sh
1 #!/bin/bash
2 # Copyright 1999-2005 Gentoo Foundation
3 # Distributed under the terms of the GNU General Public License v2
4 # $Header: /var/cvsroot/gentoo/src/catalyst/targets/support/bootloader-setup.sh,v 1.27 2006/01/27 22:49:10 rocket Exp $
5 . ${clst_sharedir}/targets/support/functions.sh
6 . ${clst_sharedir}/targets/support/filesystem-functions.sh
7
8 # $1 is the destination root
9
10 extract_cdtar $1
11 extract_kernels $1/boot
12 check_dev_manager
13 check_bootargs
14 check_filesystem_type
15
16 default_append_line="root=/dev/ram0 init=/linuxrc ${cmdline_opts} ${custom_kopts} cdroot"
17
18 case ${clst_mainarch} in
19         alpha)
20                 # NO SOFTLEVEL SUPPORT YET
21                 acfg=$1/etc/aboot.conf
22                 bctr=0
23                 for x in ${clst_boot_kernel}
24                 do
25                         echo -n "${bctr}:/boot/${x} " >> ${acfg}
26                         echo -n "initrd=/boot/${x}.igz root=/dev/ram0 " >> ${acfg}
27                         echo "init=/linuxrc ${cmdline_opts} cdroot" >> ${acfg}
28                         ((bctr=${bctr}+1))
29                 done
30                 ;;
31         arm)
32                 # NO SOFTLEVEL SUPPORT YET
33                 ;;
34         hppa)
35                 # NO SOFTLEVEL SUPPORT YET
36                 icfg=$1/boot/palo.conf
37                 kmsg=$1/boot/kernels.msg
38                 hmsg=$1/boot/help.msg
39                 echo "--commandline=0/${first} initrd=${first}.igz root=/dev/ram0 init=/linuxrc ${cmdline_opts}" >> ${icfg}
40                 echo "--bootloader=boot/iplboot" >> ${icfg}
41                 echo "--ramdisk=boot/${first}.igz" >> ${icfg}
42                 ;;
43         ppc|ppc64)
44                 # NO SOFTLEVEL SUPPORT YET
45                 
46                 # PPC requirements: 
47                 # -----------------
48                 # The specs indicate the kernels to be build. We need to put
49                 # those kernels and the corresponding initrd.img.gz(s) in the
50                 # /boot directory. This directory contains a message boot.msg 
51                 # containing some info to be displayed on boot, a configuration
52                 # (yaboot.conf) specifying the boot options (kernel/initrd 
53                 # combinations). The boot directory also contains a file called
54                 # yaboot, which normally gets copied from the live environment.
55                 # For now we supply a prebuilt file, prebuilt configuration 
56                 # and prebuilt boot message. This can be enhanced later on
57                 # but the following suffices for now:
58
59                 # this sets up the config file for yaboot
60
61
62                 # ADD RUNLEVEL SUPPORT ???
63
64                 icfg=$1/boot/yaboot.conf
65                 kmsg=$1/boot/boot.msg
66
67                 echo "default ${first}" > ${icfg}
68                 echo "timeout 300" >> ${icfg}
69                 echo "device=cd:" >> ${icfg}
70                 echo "root=/dev/ram" >> ${icfg}
71                 echo "fgcolor=white" >> ${icfg}
72                 echo "bgcolor=black" >> ${icfg}
73                 echo "message=/boot" >> ${icfg}
74                 
75                 # Setup the IBM yaboot.conf     
76                 etc_icfg=$1/etc/yaboot.conf
77                 mkdir -p $1/etc 
78                 IBM_YABOOT="FALSE"
79                 echo "default ${first}" > ${etc_icfg}
80                 echo "timeout 300" >> ${etc_icfg}
81                 echo "device=cd:" >> ${etc_icfg}
82                 echo "root=/dev/ram" >> ${etc_icfg}
83                 echo "fgcolor=white" >> ${etc_icfg}
84                 echo "bgcolor=black" >> ${etc_icfg}
85                 echo "message=/boot/boot.msg" >> ${etc_icfg}
86                 
87                 for x in ${clst_boot_kernel}
88                 do      
89                         eval "clst_kernel_console=\$clst_boot_kernel_${x}_console"
90                         eval "clst_kernel_machine_type=\$clst_boot_kernel_${x}_machine_type"
91                         eval custom_kopts=\$${x}_kernelopts
92                                 
93                         echo "APPENDING CUSTOM KERNEL ARGS: ${custom_kopts}"
94                         if [ "${clst_kernel_machine_type}" == "ibm" ]
95                         then
96                                 IBM_YABOOT="true"
97                                 if [ -n "${clst_kernel_console}" ]
98                                 then
99                                         for y in ${clst_kernel_console}
100                                         do
101                                                 echo ${y}
102                                                 echo >> ${etc_icfg}
103                                                 echo "image=/boot/${x}" >> ${etc_icfg}
104
105                                                 if [ -e "$1/boot/${x}.igz" ]
106                                                 then
107                                                         echo "initrd=/boot/${x}.igz" >> ${etc_icfg}
108                                                 fi
109
110                                                 echo "label=${x} [${y}] " >> ${etc_icfg}
111                                                 echo "read-write" >> ${icfg}
112                                                 if [ "${clst_livecd_splash_type}" == "gensplash" -a -n "${clst_livecd_splash_theme}" ]
113                                                 then
114                                                         echo "append=\"${default_append_line} console=${y} splash=silent,theme:${clst_livecd_splash_theme}\"" >> ${etc_icfg}
115                                                 else
116                                                         echo "append=\"${default_append_line} console=${y} splash=silent\"" >> ${etc_icfg}
117                                                 fi
118                                         done
119                                 else
120                                         echo >> ${etc_icfg}
121                                         echo "image=/boot/${x}" >> ${etc_icfg}
122
123                                         if [ -e "$1/boot/${x}.igz" ]
124                                         then
125                                                 echo "initrd=/boot/${x}.igz" >> ${etc_icfg}
126                                         fi
127
128                                         echo "label=${x}" >> ${etc_icfg}
129                                         echo "read-write" >> ${etc_icfg}
130                                         if [ "${clst_livecd_splash_type}" == "gensplash" -a -n "${clst_livecd_splash_theme}" ]
131                                         then
132                                                 echo "append=\"${default_append_line} splash=silent,theme:${clst_livecd_splash_theme}\"" >> ${etc_icfg}
133                                         else
134                                                 echo "append=\"${default_append_line} splash=silent\"" >> ${etc_icfg}
135                                         fi
136                                 fi
137                         else
138                                 if [ -n "${clst_kernel_console}" ]
139                                 then
140                                         for y in ${clst_kernel_console}
141                                         do
142                                                 echo >> ${icfg}
143                                                 echo "image=/boot/${x}" >> ${icfg}
144
145                                                 if [ -e "$1/boot/${x}.igz" ]
146                                                 then
147                                                         echo "initrd=/boot/${x}.igz" >> ${icfg}
148                                                 fi
149
150                                                 echo "label=${x} [${y}] " >> ${icfg}
151                                                 echo "read-write" >> ${icfg}
152                                                 if [ "${clst_livecd_splash_type}" == "gensplash" -a -n "${clst_livecd_splash_theme}" ]
153                                                 then
154                                                         echo "append=\"${default_append_line} console=${y} splash=silent,theme:${clst_livecd_splash_theme}\"" >> ${icfg}
155                                                 else
156                                                         echo "append=\"${default_append_line} console=${y} splash=silent\"" >> ${icfg}
157                                                 fi
158                                         done
159                                 else
160                                         echo >> ${icfg}
161                                         echo "image=/boot/${x}" >> ${icfg}
162
163                                         if [ -e "$1/boot/${x}.igz" ]
164                                         then
165                                                 echo "initrd=/boot/${x}.igz" >> ${icfg}
166                                         fi
167
168                                         echo "label=${x}" >> ${icfg}
169                                         echo "read-write" >> ${icfg}
170                                         if [ "${clst_livecd_splash_type}" == "gensplash" -a -n "${clst_livecd_splash_theme}" ]
171                                         then
172                                                 echo "append=\"${default_append_line} splash=silent,theme:${clst_livecd_splash_theme}\"" >> ${icfg}
173                                         else
174                                                 echo "append=\"${default_append_line} splash=silent\"" >> ${icfg}
175                                         fi
176                                 fi
177                         fi
178                 done
179
180                 if [ "${IBM_YABOOT}" == "FALSE" ]
181                 then 
182                         rm ${etc_kmsg}
183                         rmdir $1/etc
184                         if [ -d $1/ppc ]
185                         then
186                                 rm -r $1/ppc
187                         fi
188                 fi
189
190                 ;;
191         sparc*)
192                 # NO SOFTLEVEL SUPPORT YET
193                 
194                 scfg=$1/boot/silo.conf
195                 echo "default=\"help\"" > ${scfg}
196                 echo "message=\"/boot/boot.msg\"" >> ${scfg}
197
198                 for x in ${clst_boot_kernel}
199                 do
200                         echo >> ${icfg}
201                         echo "image=\"/boot/${x}\"" >> ${scfg}
202                         echo -e "\tlabel=\"${x}\"" >> ${scfg}
203                         echo -e "\tappend=\"initrd=/boot/${x}.igz root=/dev/ram0 init=/linuxrc ${cmdline_opts} cdroot\"" >> ${scfg}
204
205                 done
206
207                 echo "image=\"cat /boot/silo.conf\"" >> ${scfg}
208                 echo -e "label=\"config\"" >> ${scfg}
209                 echo "image=\"cat /boot/video.msg\"" >> ${scfg}
210                 echo -e "label=\"video\"" >> ${scfg}
211                 echo "image=\"cat /boot/help.msg\"" >> ${scfg}
212                 echo -e "label=\"help\"" >> ${scfg}
213                 ;;
214         ia64)
215                 # NO SOFTLEVEL SUPPORT YET
216                 
217                 iacfg=$1/boot/elilo.conf
218                 echo 'prompt' > ${iacfg}
219                 echo 'message=/efi/boot/elilo.msg' >> ${iacfg}
220                 echo 'chooser=simple' >> ${iacfg}
221                 echo 'timeout=50' >> ${iacfg}
222                 echo >> ${iacfg}
223                 for x in ${clst_boot_kernel}
224                 do
225                         echo "image=/efi/boot/${x}" >> ${iacfg}
226                         echo "  label=${x}" >> ${iacfg}
227                         echo '  append="'initrd=${x}.igz ${default_append_line}'"' >> ${iacfg}
228                         echo "  initrd=/efi/boot/${x}.igz" >> ${iacfg}
229                         echo >> ${iacfg}
230                         echo "image=/efi/boot/${x}" >> ${iacfg}
231                         echo "  label=${x}-serial">> ${iacfg}
232                         echo '  append="'initrd=${x}.igz ${default_append_line}' console=tty0 console=ttyS0,9600"' >> ${iacfg}
233                         echo "  initrd=/efi/boot/${x}.igz" >> ${iacfg}
234                         echo >> ${iacfg}
235                         mv $1/boot/${x}{,.igz} $1/boot/efi/boot
236                 done
237                 cp ${iacfg} $1/boot/efi/boot
238                 ;;
239         x86|amd64)
240                 if [ -e $1/isolinux/isolinux.bin ]
241                 then
242                         mv $1/boot/* $1/isolinux
243                         rmdir $1/boot
244                         # the rest of this function sets up the config file for isolinux
245                         icfg=$1/isolinux/isolinux.cfg
246                         kmsg=$1/isolinux/kernels.msg
247                         echo "default ${first}" > ${icfg}
248                         echo "timeout 150" >> ${icfg}
249                         echo "prompt 1" >> ${icfg}
250                         echo "display boot.msg" >> ${icfg}
251                         echo "F1 kernels.msg" >> ${icfg}
252                         echo "F2 F2.msg" >> ${icfg}
253                         echo "F3 F3.msg" >> ${icfg}
254                         echo "F4 F4.msg" >> ${icfg}
255                         echo "F5 F5.msg" >> ${icfg}
256                         echo "F6 F6.msg" >> ${icfg}
257                         echo "F7 F7.msg" >> ${icfg}
258
259                         echo "Available kernels:" > ${kmsg}
260                         for i in 2 3 4 5 6 7
261                         do
262                                 cp ${clst_sharedir}/livecd/files/x86-F$i.msg \
263                                         $1/isolinux/F$i.msg
264                         done
265
266                         for x in ${clst_boot_kernel}
267                         do
268                                 eval custom_kopts=\$${x}_kernelopts
269                                 echo "APPENDING CUSTOM KERNEL ARGS: ${custom_kopts}"
270                                 echo >> ${icfg}
271                                 
272                                 eval "clst_kernel_softlevel=\$clst_boot_kernel_${x}_softlevel"
273
274                                 if [ -n "${clst_kernel_softlevel}" ]
275                                 then
276                                         for y in ${clst_kernel_softlevel}
277                                         do
278                                                 echo "label ${x}-${y}" >> ${icfg}
279                                                 echo "  kernel ${x}" >> ${icfg}
280                                                 if [ "${clst_livecd_splash_type}" == "gensplash" -a -n "${clst_livecd_splash_theme}" ]
281                                                 then
282                                                         echo "  append ${default_append_line} softlevel=${y} initrd=${x}.igz vga=791 splash=silent,theme:${clst_livecd_splash_theme} CONSOLE=/dev/tty1 quiet" >> ${icfg}
283                                                 else
284                                                         echo "  append ${default_append_line} softlevel=${y} initrd=${x}.igz vga=791 splash=silent" >> ${icfg}
285                                                 fi
286
287                                                 echo >> ${icfg}
288                                                 echo "   ${x}" >> ${kmsg}
289                                                 echo "label ${x}-${y}-nofb" >> ${icfg}
290                                                 echo "  kernel ${x}" >> ${icfg}
291                                                 echo "  append ${default_append_line} softlevel=${y} initrd=${x}.igz" >> ${icfg}
292                                                 echo >> ${icfg}
293                                                 echo "   ${x}-nofb" >> ${kmsg}
294                                         done
295                                 else
296                                         echo "label ${x}" >> ${icfg}
297                                         echo "  kernel ${x}" >> ${icfg}
298                                         if [ "${clst_livecd_splash_type}" == "gensplash" -a -n "${clst_livecd_splash_theme}" ]
299                                         then
300                                                 echo "  append ${default_append_line} initrd=${x}.igz vga=791 splash=silent,theme:${clst_livecd_splash_theme} CONSOLE=/dev/tty1 quiet" >> ${icfg}
301                                         else
302                                                 echo "  append ${default_append_line} initrd=${x}.igz vga=791 splash=silent" >> ${icfg}
303                                         fi
304
305                                         echo >> ${icfg}
306                                         echo "   ${x}" >> ${kmsg}
307                                         echo "label ${x}-nofb" >> ${icfg}
308                                         echo "  kernel ${x}" >> ${icfg}
309                                         echo "  append ${default_append_line} initrd=${x}.igz" >> ${icfg}
310                                         echo >> ${icfg}
311                                         echo "   ${x}-nofb" >> ${kmsg}
312                                 fi
313                         done
314
315                         if [ -f $1/isolinux/memtest86 ]
316                         then
317                                 echo >> $icfg
318                                 echo "   memtest86" >> $kmsg
319                                 echo "label memtest86" >> $icfg
320                                 echo "  kernel memtest86" >> $icfg
321                         fi
322                 fi
323
324                 if [ -e $1/boot/efi/elilo.efi ]
325                 then
326                         iacfg=$1/boot/elilo.conf
327                         echo 'prompt' > ${iacfg}
328                         echo 'message=/efi/boot/elilo.msg' >> ${iacfg}
329                         echo 'chooser=simple' >> ${iacfg}
330                         echo 'timeout=50' >> ${iacfg}
331                         echo >> ${iacfg}
332                         for x in ${clst_boot_kernel}
333                         do
334                                 echo "image=/efi/boot/${x}" >> ${iacfg}
335                                 echo "  label=${x}" >> ${iacfg}
336                                 echo '  append="'initrd=${x}.igz ${default_append_line}'"' >> ${iacfg}
337                                 echo "  initrd=/efi/boot/${x}.igz" >> ${iacfg}
338                                 echo >> ${iacfg}
339                                 echo "image=/efi/boot/${x}" >> ${iacfg}
340                                 echo >> ${iacfg}
341                                 cp -f $1/boot/${x}{,.igz} $1/boot/efi/boot > /dev/null
342                                 cp -f $1/isolinux/${x}{,.igz} $1/boot/efi/boot > /dev/null
343                         done
344                         cp ${iacfg} $1/boot/efi/boot
345                 fi
346
347                 if [ -e $1/boot/grub/stage2_eltorito ]
348                 then
349                         icfg=$1/boot/grub/grub.conf
350                         echo "default 1" > ${icfg}
351                         echo "timeout 150" >> ${icfg}
352
353                         # Setup help message
354                         echo >> ${icfg}
355                         echo "title help" >> ${icfg}
356                         cp ${clst_sharedir}/livecd/files/README.txt \
357                                 $1/boot/help.msg
358                         echo "cat /boot/help.msg" >> ${icfg}
359
360                         for x in ${clst_boot_kernel}
361                         do
362                                 eval custom_kopts=\$${x}_kernelopts
363                                 echo "APPENDING CUSTOM KERNEL ARGS: ${custom_kopts}"
364                                 echo >> ${icfg}
365                                 
366                                 eval "clst_kernel_softlevel=\$clst_boot_kernel_${x}_softlevel"
367                                 
368                                 if [ -n "${clst_kernel_softlevel}" ]
369                                 then
370                                         for y in ${clst_kernel_softlevel}
371                                         do
372                                                 echo "title ${x}-${y}" >> ${icfg}
373                                                 if [ "${clst_livecd_splash_type}" == "gensplash" -a -n "${clst_livecd_splash_theme}" ]
374                                                 then
375                                                         echo "kernel /boot/${x} softlevel=${y} ${default_append_line} vga=791 splash=silent,theme:${clst_livecd_splash_theme} CONSOLE=/dev/tty1 quiet" >> ${icfg}
376                                                 else
377                                                         echo "kernel /boot/${x} softlevel=${y} ${default_append_line} vga=791 splash=silent" >> ${icfg}
378                                                 fi
379                                                 if [ -e $1/boot/${x}.igz ]
380                                                 then
381                                                         echo "initrd /boot/${x}.igz" >> ${icfg}
382                                                 fi
383                                                 echo >> ${icfg}
384                                                 echo "title ${x}-${y} [ No FrameBuffer ]" >> ${icfg}
385                                                 echo "kernel ${x} /boot/${x} softlevel=${y} ${default_append_line}" >> ${icfg}
386                                                 if [ -e $1/boot/${x}.igz ]
387                                                 then
388                                                         echo "initrd /boot/${x}.igz" >> ${icfg}
389                                                 fi
390                                                 echo >> ${icfg}
391                                         done
392                                 else
393                                         echo "title ${x}" >> ${icfg}
394                                         if [ "${clst_livecd_splash_type}" == "gensplash" -a -n "${clst_livecd_splash_theme}" ]
395                                         then
396                                                 echo "kernel /boot/${x} ${default_append_line} vga=791 splash=silent,theme:${clst_livecd_splash_theme} CONSOLE=/dev/tty1 quiet" >> ${icfg}
397                                         else
398                                                 echo "kernel /boot/${x} ${default_append_line} vga=791 splash=silent" >> ${icfg}
399                                         fi
400                                         if [ -e $1/boot/${x}.igz ]
401                                         then
402                                                 echo "initrd /boot/${x}.igz" >> ${icfg}
403                                         fi
404                                         echo >> ${icfg}
405                                         echo "title ${x} [ No FrameBuffer ]" >> ${icfg}
406                                         echo "kernel ${x} /boot/${x} ${default_append_line}" >> ${icfg}
407                                         if [ -e $1/boot/${x}.igz ]
408                                         then
409                                                 echo "initrd /boot/${x}.igz" >> ${icfg}
410                                         fi
411                                 fi
412
413                         done
414
415                         if [ -f $1/boot/memtest86 ]
416                         then
417                                 echo >> ${icfg}
418                                 echo "title memtest86" >> ${icfg}
419                                 echo "kernel /boot/memtest86" >> ${icfg}
420                         fi
421                 fi
422                 ;;
423         mips)
424
425                 # NO SOFTLEVEL SUPPORT YET
426
427
428                 # Mips is an interesting arch -- where most archs will
429                 # use ${1} as the root of the LiveCD, an SGI LiveCD lacks
430                 # such a root.  Instead, we will use ${1} as a scratch
431                 # directory to build the components we need for the
432                 # CD image, and then pass these components to the
433                 # `sgibootcd` tool which outputs a final CD image
434                 scratch="${1}"
435                 mkdir ${scratch}/kernels
436                 mkdir ${scratch}/kernels/misc
437                 mkdir ${scratch}/arcload
438                 echo "" > ${scratch}/arc.cf
439
440                 # Move kernel binaries to ${scratch}/kernels, and
441                 # move everything else to ${scratch}/kernels/misc
442                 for x in ${clst_boot_kernel}; do
443                         mv ${1}/boot/${x} ${scratch}/kernels
444                         mv ${1}/boot/${x}.igz ${scratch}/kernels/misc
445                 done
446                 rmdir ${1}/boot
447
448                 # Source the bashified arcload config
449                 source ${clst_sharedir}/targets/support/mips-arcload_conf.sh
450
451                 # Generate top portions of the config
452                 echo -e "${topofconfig}${serial}${dbg}${cmt1}" >> ${scratch}/arc.cf
453
454                 # Next, figure out what kernels were specified in the
455                 # spec file, and generate the appropriate arcload conf
456                 # blocks specific to each system
457                 ip22="$(echo ${clst_boot_kernel} | tr " " "\n" | grep "ip22" | tr "\n" " ")"
458                 ip27="$(echo ${clst_boot_kernel} | tr " " "\n" | grep "ip27" | tr "\n" " ")"
459                 ip28="$(echo ${clst_boot_kernel} | tr " " "\n" | grep "ip28" | tr "\n" " ")"
460                 ip30="$(echo ${clst_boot_kernel} | tr " " "\n" | grep "ip30" | tr "\n" " ")"
461                 ip32="$(echo ${clst_boot_kernel} | tr " " "\n" | grep "ip32" | tr "\n" " ")"
462
463                 if [ -n "${ip22}" ]; then
464                         echo -e "${ip22base}" >> ${scratch}/arc.cf
465                         for x in ${ip22}; do echo -e "${!x}" >> ${scratch}/arc.cf; done
466                         echo -e "${ip22vid}${ip22x}" >> ${scratch}/arc.cf
467                 fi
468
469                 [ -n "${ip27}" ] && echo -e "${ip27base}" >> ${scratch}/arc.cf
470                 [ -n "${ip28}" ] && echo -e "${ip28base}" >> ${scratch}/arc.cf
471                 [ -n "${ip30}" ] && echo -e "${ip30base}" >> ${scratch}/arc.cf
472
473                 if [ -n "${ip32}" ]; then
474                         echo -e "${ip32base}" >> ${scratch}/arc.cf
475                         for x in ${ip32}; do echo -e "${!x}" >> ${scratch}/arc.cf; done
476                         echo -e "${ip32vid}${ip32x}" >> ${scratch}/arc.cf
477                 fi
478
479                 # Finish off the config
480                 echo -e "${cmt2}" >> ${scratch}/arc.cf
481
482                 # Move the bootloader binaries & config to their destination
483                 mv ${1}/sashARCS ${1}/sash64 ${1}/arc.cf ${scratch}/arcload
484                 ;;
485 esac
486 exit $?