Added fix from bug #119123. This is catalyst 2.0_rc16.
[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.23 2006/01/16 15:45:03 wolf31o2 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 eval "clst_kernel_softlevel=\$clst_boot_kernel_${clst_kname}_softlevel"
17
18 default_append_line="root=/dev/ram0 init=/linuxrc ${cmdline_opts} ${custom_kopts} cdroot"
19
20 if ${clst_kernel_softlevel}
21 then
22         default_append_line="${default_append_line} softlevel=${clst_kernel_softlevel}"
23 fi
24
25 case ${clst_mainarch} in
26         alpha)
27                 acfg=$1/etc/aboot.conf
28                 bctr=0
29                 for x in ${clst_boot_kernel}
30                 do
31                         echo -n "${bctr}:/boot/${x} " >> ${acfg}
32                         echo -n "initrd=/boot/${x}.igz root=/dev/ram0 " >> ${acfg}
33                         echo "init=/linuxrc ${cmdline_opts} cdroot" >> ${acfg}
34                         ((bctr=${bctr}+1))
35                 done
36                 ;;
37         arm)
38                 ;;
39         hppa)
40                 icfg=$1/boot/palo.conf
41                 kmsg=$1/boot/kernels.msg
42                 hmsg=$1/boot/help.msg
43                 echo "--commandline=0/${first} initrd=${first}.igz root=/dev/ram0 init=/linuxrc ${cmdline_opts}" >> ${icfg}
44                 echo "--bootloader=boot/iplboot" >> ${icfg}
45                 echo "--ramdisk=boot/${first}.igz" >> ${icfg}
46                 ;;
47         ppc)
48                 # PPC requirements: 
49                 # -----------------
50                 # The specs indicate the kernels to be build. We need to put
51                 # those kernels and the corresponding initrd.img.gz(s) in the
52                 # /boot directory. This directory contains a message boot.msg 
53                 # containing some info to be displayed on boot, a configuration
54                 # (yaboot.conf) specifying the boot options (kernel/initrd 
55                 # combinations). The boot directory also contains a file called
56                 # yaboot, which normally gets copied from the live environment.
57                 # For now we supply a prebuilt file, prebuilt configuration 
58                 # and prebuilt boot message. This can be enhanced later on
59                 # but the following suffices for now:
60
61                 # this sets up the config file for yaboot
62                 icfg=$1/boot/yaboot.conf
63                 kmsg=$1/boot/boot.msg
64                 echo "default ${first}" > ${icfg}
65                 echo "timeout 300" >> ${icfg}
66                 echo "device=cd:" >> ${icfg}
67                 echo "root=/dev/ram" >> ${icfg}
68                 echo "fgcolor=white" >> ${icfg}
69                 echo "bgcolor=black" >> ${icfg}
70                 echo "message=/boot/boot.msg" >> ${icfg}
71                 for x in ${clst_boot_kernel}
72                 do
73                         eval custom_kopts=\$${x}_kernelopts
74                         echo "APPENDING CUSTOM KERNEL ARGS: ${custom_kopts}"
75                         echo >> ${icfg}
76                         echo "image=/boot/${x}" >> ${icfg}
77
78                         if [ -e "$1/boot/${x}.igz" ]
79                         then
80                                 echo "initrd=/boot/${x}.igz" >> ${icfg}
81                         fi
82
83                         echo "label=${x}" >> ${icfg}
84                         echo "read-write" >> ${icfg}
85                         if [ "${clst_livecd_splash_type}" == "gensplash" -a -n "${clst_livecd_splash_theme}" ]
86                         then
87                                 echo "append=\"${default_append_line} splash=silent,theme:${clst_livecd_splash_theme}\"" >> ${icfg}
88                         else
89                                 echo "append=\"${default_append_line} splash=silent\"" >> ${icfg}
90                         fi
91                 done
92                 ;;
93         sparc*)
94                 scfg=$1/boot/silo.conf
95                 echo "default=\"help\"" > ${scfg}
96                 echo "message=\"/boot/boot.msg\"" >> ${scfg}
97
98                 for x in ${clst_boot_kernel}
99                 do
100                         echo >> ${icfg}
101                         echo "image=\"/boot/${x}\"" >> ${scfg}
102                         echo -e "\tlabel=\"${x}\"" >> ${scfg}
103                         echo -e "\tappend=\"initrd=/boot/${x}.igz root=/dev/ram0 init=/linuxrc ${cmdline_opts} cdroot\"" >> ${scfg}
104
105                 done
106
107                 echo "image=\"cat /boot/silo.conf\"" >> ${scfg}
108                 echo -e "label=\"config\"" >> ${scfg}
109                 echo "image=\"cat /boot/video.msg\"" >> ${scfg}
110                 echo -e "label=\"video\"" >> ${scfg}
111                 echo "image=\"cat /boot/help.msg\"" >> ${scfg}
112                 echo -e "label=\"help\"" >> ${scfg}
113                 ;;
114         ia64)
115                 iacfg=$1/boot/elilo.conf
116                 echo 'prompt' > ${iacfg}
117                 echo 'message=/efi/boot/elilo.msg' >> ${iacfg}
118                 echo 'chooser=simple' >> ${iacfg}
119                 echo 'timeout=50' >> ${iacfg}
120                 echo >> ${iacfg}
121                 for x in ${clst_boot_kernel}
122                 do
123                         echo "image=/efi/boot/${x}" >> ${iacfg}
124                         echo "  label=${x}" >> ${iacfg}
125                         echo '  append="'initrd=${x}.igz ${default_append_line}'"' >> ${iacfg}
126                         echo "  initrd=/efi/boot/${x}.igz" >> ${iacfg}
127                         echo >> ${iacfg}
128                         echo "image=/efi/boot/${x}" >> ${iacfg}
129                         echo "  label=${x}-serial">> ${iacfg}
130                         echo '  append="'initrd=${x}.igz ${default_append_line}' console=tty0 console=ttyS0,9600"' >> ${iacfg}
131                         echo "  initrd=/efi/boot/${x}.igz" >> ${iacfg}
132                         echo >> ${iacfg}
133                 done
134                 cp ${iacfg} $1/boot/efi/boot
135                 mv $1/boot/${x}{,.igz} $1/boot/efi/boot
136                 ;;
137         x86|amd64)
138                 if [ -e $1/isolinux/isolinux.bin ]
139                 then
140                         mv $1/boot/* $1/isolinux
141                         rmdir $1/boot
142                         # the rest of this function sets up the config file for isolinux
143                         icfg=$1/isolinux/isolinux.cfg
144                         kmsg=$1/isolinux/kernels.msg
145                         echo "default ${first}" > ${icfg}
146                         echo "timeout 150" >> ${icfg}
147                         echo "prompt 1" >> ${icfg}
148                         echo "display boot.msg" >> ${icfg}
149                         echo "F1 kernels.msg" >> ${icfg}
150                         echo "F2 F2.msg" >> ${icfg}
151                         echo "F3 F3.msg" >> ${icfg}
152                         echo "F4 F4.msg" >> ${icfg}
153                         echo "F5 F5.msg" >> ${icfg}
154                         echo "F6 F6.msg" >> ${icfg}
155                         echo "F7 F7.msg" >> ${icfg}
156
157                         echo "Available kernels:" > ${kmsg}
158                         for i in 2 3 4 5 6 7
159                         do
160                                 cp ${clst_sharedir}/livecd/files/x86-F$i.msg \
161                                         $1/isolinux/F$i.msg
162                         done
163
164                         for x in ${clst_boot_kernel}
165                         do
166                                 eval custom_kopts=\$${x}_kernelopts
167                                 echo "APPENDING CUSTOM KERNEL ARGS: ${custom_kopts}"
168                                 echo >> ${icfg}
169                                 echo "label ${x}" >> ${icfg}
170                                 echo "  kernel ${x}" >> ${icfg}
171                                 if [ "${clst_livecd_splash_type}" == "gensplash" -a -n "${clst_livecd_splash_theme}" ]
172                                 then
173                                         echo "  append ${default_append_line} initrd=${x}.igz vga=791 splash=silent,theme:${clst_livecd_splash_theme} CONSOLE=/dev/tty1 quiet" >> ${icfg}
174                                 else
175                                         echo "  append ${default_append_line} initrd=${x}.igz vga=791 splash=silent" >> ${icfg}
176                                 fi
177
178                                 echo >> ${icfg}
179                                 echo "   ${x}" >> ${kmsg}
180                                 echo "label ${x}-nofb" >> ${icfg}
181                                 echo "  kernel ${x}" >> ${icfg}
182                                 echo "  append ${default_append_line} initrd=${x}.igz" >> ${icfg}
183                                 echo >> ${icfg}
184                                 echo "   ${x}-nofb" >> ${kmsg}
185                         done
186
187                         if [ -f $1/isolinux/memtest86 ]
188                         then
189                                 echo >> $icfg
190                                 echo "   memtest86" >> $kmsg
191                                 echo "label memtest86" >> $icfg
192                                 echo "  kernel memtest86" >> $icfg
193                         fi
194                 fi
195
196                 if [ -e $1/boot/grub/stage2_eltorito ]
197                 then
198                         icfg=$1/boot/grub/grub.conf
199                         echo "default 1" > ${icfg}
200                         echo "timeout 150" >> ${icfg}
201
202                         # Setup help message
203                         echo >> ${icfg}
204                         echo "title help" >> ${icfg}
205                         cp ${clst_sharedir}/livecd/files/README.txt \
206                                 $1/boot/help.msg
207                         echo "cat /boot/help.msg" >> ${icfg}
208
209                         for x in ${clst_boot_kernel}
210                         do
211                                 eval custom_kopts=\$${x}_kernelopts
212                                 echo "APPENDING CUSTOM KERNEL ARGS: ${custom_kopts}"
213                                 echo >> ${icfg}
214                                 echo "title ${x}" >> ${icfg}
215
216                                 if [ "${clst_livecd_splash_type}" == "gensplash" -a -n "${clst_livecd_splash_theme}" ]
217                                 then
218                                         echo "kernel /boot/${x} ${default_append_line} vga=791 splash=silent,theme:${clst_livecd_splash_theme} CONSOLE=/dev/tty1 quiet" >> ${icfg}
219                                 else
220                                         echo "kernel /boot/${x} ${default_append_line} vga=791 splash=silent" >> ${icfg}
221                                 fi
222
223                                 if [ -e $1/boot/${x}.igz ]
224                                 then
225                                         echo "initrd /boot/${x}.igz" >> ${icfg}
226                                 fi
227
228                                 echo >> ${icfg}
229                                 echo "title ${x} [ No FrameBuffer ]" >> ${icfg}
230                                 echo "kernel ${x} /boot/${x} ${default_append_line}" >> ${icfg}
231                                 if [ -e $1/boot/${x}.igz ]
232                                 then
233                                         echo "initrd /boot/${x}.igz" >> ${icfg}
234                                 fi
235                         done
236
237                         if [ -f $1/boot/memtest86 ]
238                         then
239                                 echo >> ${icfg}
240                                 echo "title memtest86" >> ${icfg}
241                                 echo "kernel /boot/memtest86" >> ${icfg}
242                         fi
243                 fi
244                 ;;
245         mips)
246                 # Mips is an interesting arch -- where most archs will
247                 # use ${1} as the root of the LiveCD, an SGI LiveCD lacks
248                 # such a root.  Instead, we will use ${1} as a scratch
249                 # directory to build the components we need for the
250                 # CD image, and then pass these components to the
251                 # `sgibootcd` tool which outputs a final CD image
252                 scratch="${1}"
253                 mkdir ${scratch}/kernels
254                 mkdir ${scratch}/kernels/misc
255                 mkdir ${scratch}/arcload
256                 echo "" > ${scratch}/arc.cf
257
258                 # Move kernel binaries to ${scratch}/kernels, and
259                 # move everything else to ${scratch}/kernels/misc
260                 for x in ${clst_boot_kernel}; do
261                         mv ${1}/boot/${x} ${scratch}/kernels
262                         mv ${1}/boot/${x}.igz ${scratch}/kernels/misc
263                 done
264                 rmdir ${1}/boot
265
266                 # Source the bashified arcload config
267                 source ${clst_sharedir}/targets/support/mips-arcload_conf.sh
268
269                 # Generate top portions of the config
270                 echo -e "${topofconfig}${serial}${dbg}${cmt1}" >> ${scratch}/arc.cf
271
272                 # Next, figure out what kernels were specified in the
273                 # spec file, and generate the appropriate arcload conf
274                 # blocks specific to each system
275                 ip22="$(echo ${clst_boot_kernel} | tr " " "\n" | grep "ip22" | tr "\n" " ")"
276                 ip27="$(echo ${clst_boot_kernel} | tr " " "\n" | grep "ip27" | tr "\n" " ")"
277                 ip28="$(echo ${clst_boot_kernel} | tr " " "\n" | grep "ip28" | tr "\n" " ")"
278                 ip30="$(echo ${clst_boot_kernel} | tr " " "\n" | grep "ip30" | tr "\n" " ")"
279                 ip32="$(echo ${clst_boot_kernel} | tr " " "\n" | grep "ip32" | tr "\n" " ")"
280
281                 if [ -n "${ip22}" ]; then
282                         echo -e "${ip22base}" >> ${scratch}/arc.cf
283                         for x in ${ip22}; do echo -e "${!x}" >> ${scratch}/arc.cf; done
284                         echo -e "${ip22vid}${ip22x}" >> ${scratch}/arc.cf
285                 fi
286
287                 [ -n "${ip27}" ] && echo -e "${ip27base}" >> ${scratch}/arc.cf
288                 [ -n "${ip28}" ] && echo -e "${ip28base}" >> ${scratch}/arc.cf
289                 [ -n "${ip30}" ] && echo -e "${ip30base}" >> ${scratch}/arc.cf
290
291                 if [ -n "${ip32}" ]; then
292                         echo -e "${ip32base}" >> ${scratch}/arc.cf
293                         for x in ${ip32}; do echo -e "${!x}" >> ${scratch}/arc.cf; done
294                         echo -e "${ip32vid}${ip32x}" >> ${scratch}/arc.cf
295                 fi
296
297                 # Finish off the config
298                 echo -e "${cmt2}" >> ${scratch}/arc.cf
299
300                 # Move the bootloader binaries & config to their destination
301                 mv ${1}/sashARCS ${1}/sash64 ${1}/arc.cf ${scratch}/arcload
302                 ;;
303 esac
304 exit $?