SimpleOS

LXR

Navigation



Site hébergé par : enix

The LXR Cross Referencer for SOS

source navigation ]
diff markup ]
identifier search ]
general search ]
 
 
Article:1 ] [ 2 ] [ 3 ] [ 4 ] [ 5 ] [ 6 ] [ 6.5 ] [ 7 ] [ 7.5 ] [ 8 ] [ 9 ] [ 9.5 ]

Diff markup

Differences between /support/build_image.sh (Article 9) and /support/build_image.sh (Article 8)


001 #!/bin/sh                                         001 #!/bin/sh
002 # Copyright (C) 2003, David Decotigny             002 # Copyright (C) 2003, David Decotigny
003                                                   003 
004 # This program is free software; you can redis    004 # This program is free software; you can redistribute it and/or
005 # modify it under the terms of the GNU General    005 # modify it under the terms of the GNU General Public License
006 # as published by the Free Software Foundation    006 # as published by the Free Software Foundation; either version 2
007 # of the License, or (at your option) any late    007 # of the License, or (at your option) any later version.
008                                                   008   
009 # This program is distributed in the hope that    009 # This program is distributed in the hope that it will be useful,
010 # but WITHOUT ANY WARRANTY; without even the i    010 # but WITHOUT ANY WARRANTY; without even the implied warranty of
011 # MERCHANTABILITY or FITNESS FOR A PARTICULAR     011 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
012 # GNU General Public License for more details.    012 # GNU General Public License for more details.
013                                                   013    
014 # You should have received a copy of the GNU G    014 # You should have received a copy of the GNU General Public License
015 # along with this program; if not, write to th    015 # along with this program; if not, write to the Free Software
016 # Foundation, Inc., 59 Temple Place - Suite 33    016 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
017 # USA.                                            017 # USA. 
018                                                   018 
019 # 1) What does it do ?                            019 # 1) What does it do ?
020 #                                                 020 #
021 #  1) Check where Grub is installed (lookup_gr    021 #  1) Check where Grub is installed (lookup_grub)
022 #  2) Assign some local variables using the sh    022 #  2) Assign some local variables using the shell script arguments.
023 #      a) Argument 1 : the destination  (eithe    023 #      a) Argument 1 : the destination  (either a file or a drive, like a:)
024 #      b) Argument 2 : the loader (i.e kernel)    024 #      b) Argument 2 : the loader (i.e kernel)
025 #      c) Argument 3 : options passed to the l    025 #      c) Argument 3 : options passed to the loader
026 #      d) Argument 4 : the modules (that can b    026 #      d) Argument 4 : the modules (that can be loaded optionally by Grub)
027 #  3) Test whether destination is a drive or a    027 #  3) Test whether destination is a drive or a file
028 #  4) Create the directory structure inside th    028 #  4) Create the directory structure inside the drive
029 #  5) Copy the loader in the drive                029 #  5) Copy the loader in the drive
030 #  6) Generate the 'menu.txt' file used by Gru    030 #  6) Generate the 'menu.txt' file used by Grub to generate the boot menu
031 #  7) Copy all modules                            031 #  7) Copy all modules
032 #  8) Copy the menu.txt file                      032 #  8) Copy the menu.txt file
033 #                                                 033 #
034 # 2) Why is it so complex ?                       034 # 2) Why is it so complex ?
035 #    Because it must support various Grub/mtoo    035 #    Because it must support various Grub/mtools installations and versions
036 #                                                 036 #
037 # In fact, this shell script is used in the KO    037 # In fact, this shell script is used in the KOS (kos.enix.org)
038 # project. This operating system consists in a    038 # project. This operating system consists in a loader and many many
039 # modules that are linked together at boot tim    039 # modules that are linked together at boot time. It is much more
040 # complex that a simple monolithic kernel.        040 # complex that a simple monolithic kernel.
041 #                                                 041 #
042 # For your simple monolithic kernel, you only     042 # For your simple monolithic kernel, you only need to give argument 1
043 # and 2.                                          043 # and 2.
044                                                   044 
045 print_usage () {                                  045 print_usage () {
046   echo "Usage: $0 [X:|image] path/to/loader op    046   echo "Usage: $0 [X:|image] path/to/loader option path/to/modules..."
047   echo "       where X: is a valid floppy driv    047   echo "       where X: is a valid floppy drive on your computer"
048   echo "       where image is any file name"      048   echo "       where image is any file name"
049   exit 1                                          049   exit 1
050 }                                                 050 }
051                                                   051 
052 grub_dirs_common="/usr/local/share/grub/i386-f    052 grub_dirs_common="/usr/local/share/grub/i386-freebsd /usr/local/share/grub/i386-pc /usr/share/grub/i386-pc /usr/lib/grub/i386-pc /usr/local/grub /usr/share/grub/i386-redhat /usr/local/src/grub-0.5.94 $HOME/share/grub/i386-pc/"
053 sbin_grub_path="/usr/local/sbin /usr/sbin /sbi    053 sbin_grub_path="/usr/local/sbin /usr/sbin /sbin $HOME/sbin"
054                                                   054 
055 PATH=$PATH:/sbin:/usr/sbin:/usr/local/sbin        055 PATH=$PATH:/sbin:/usr/sbin:/usr/local/sbin
056 export PATH                                       056 export PATH
057                                                   057 
058 MTOOLSRC=mtoolsrc                                 058 MTOOLSRC=mtoolsrc
059 export MTOOLSRC                                   059 export MTOOLSRC
060                                                   060 
061 # Redefined variables                             061 # Redefined variables
062 FLOPPY_DRIVE=A:                                   062 FLOPPY_DRIVE=A:
063 IMG_FNAME=fd.img                                  063 IMG_FNAME=fd.img
064                                                   064 
065 ##                                                065 ##
066 ## Format disk image                              066 ## Format disk image
067 ##                                                067 ##
068 init_image () {                                   068 init_image () {
069   echo "Initialize disk image $IMG_FILE..."       069   echo "Initialize disk image $IMG_FILE..."
070   if [ ! -f $IMG_FNAME ] ; then                   070   if [ ! -f $IMG_FNAME ] ; then
071     dd if=/dev/zero of=$IMG_FNAME bs=18k count    071     dd if=/dev/zero of=$IMG_FNAME bs=18k count=80 1>/dev/null 2>&1
072   fi                                              072   fi
073                                                   073 
074   rm -f $MTOOLSRC                                 074   rm -f $MTOOLSRC
075   echo "drive u: file=\"$IMG_FNAME\" 1.44M fil    075   echo "drive u: file=\"$IMG_FNAME\" 1.44M filter" > $MTOOLSRC
076                                                   076 
077   if mformat U: ; then : ; else                   077   if mformat U: ; then : ; else
078     rm -f $MTOOLSRC                               078     rm -f $MTOOLSRC
079     echo "drive u: file=\"$IMG_FNAME\" 1.44M"     079     echo "drive u: file=\"$IMG_FNAME\" 1.44M" > $MTOOLSRC
080     if mformat U: ; then : ; else                 080     if mformat U: ; then : ; else
081       rm -f $MTOOLSRC                             081       rm -f $MTOOLSRC
082       echo "drive u: file=\"$IMG_FNAME\"" > $M    082       echo "drive u: file=\"$IMG_FNAME\"" > $MTOOLSRC
083       mformat U:                                  083       mformat U:
084     fi                                            084     fi
085   fi                                              085   fi
086 }                                                 086 }
087                                                   087 
088                                                   088 
089 ##                                                089 ##
090 ## Format (real) floppy disk                      090 ## Format (real) floppy disk
091 ##                                                091 ##
092 init_floppy () {                                  092 init_floppy () {
093   echo "Formatting floppy..."                     093   echo "Formatting floppy..."
094   mformat $FLOPPY_DRIVE || exit 1                 094   mformat $FLOPPY_DRIVE || exit 1
095 }                                                 095 }
096                                                   096 
097                                                   097 
098 lookup_grub () {                                  098 lookup_grub () {
099   # Look for a correct GRUBDIR                    099   # Look for a correct GRUBDIR
100   for d in $grub_dirs_common ; do                 100   for d in $grub_dirs_common ; do
101     if [ -d $d ] ; then                           101     if [ -d $d ] ; then
102       GRUBDIR=$d                                  102       GRUBDIR=$d
103       break                                       103       break
104     fi                                            104     fi
105   done                                            105   done
106                                                   106 
107   # Try to guess with whereis (Credits to Kari    107   # Try to guess with whereis (Credits to Karim Dridi)
108   if [ ! -d "$GRUBDIR" ] ; then                   108   if [ ! -d "$GRUBDIR" ] ; then
109     GRUBDIR=`whereis grub | awk '{ print "find    109     GRUBDIR=`whereis grub | awk '{ print "find "$3" -name stage2" }' | sh | xargs dirname 2>/dev/null`
110   fi                                              110   fi
111                                                   111 
112   # Try to guess with locate                      112   # Try to guess with locate
113   if [ ! -d "$GRUBDIR" ] ; then                   113   if [ ! -d "$GRUBDIR" ] ; then
114      GRUBDIR=`locate stage2 | head -1 | xargs     114      GRUBDIR=`locate stage2 | head -1 | xargs dirname 2>/dev/null`
115   fi                                              115   fi
116                                                   116 
117   # Look for a correct sbin/grub                  117   # Look for a correct sbin/grub
118   for d in $sbin_grub_path ; do                   118   for d in $sbin_grub_path ; do
119     if [ -x $d/grub ] ; then                      119     if [ -x $d/grub ] ; then
120       SBIN_GRUB=$d/grub                           120       SBIN_GRUB=$d/grub
121       break                                       121       break
122     fi                                            122     fi
123   done                                            123   done
124                                                   124 
125   if [ -d "$GRUBDIR" -a -x "$SBIN_GRUB" ] ; th    125   if [ -d "$GRUBDIR" -a -x "$SBIN_GRUB" ] ; then 
126     echo "Found correct grub installation in $    126     echo "Found correct grub installation in $GRUBDIR"
127     echo "Found correct /sbin/grub at $SBIN_GR    127     echo "Found correct /sbin/grub at $SBIN_GRUB"
128   else                                            128   else
129     echo "Couldn't find a correct grub install    129     echo "Couldn't find a correct grub installation."
130     exit 1                                        130     exit 1
131   fi                                              131   fi
132 }                                                 132 }
133                                                   133 
134 ##                                                134 ##
135 ## setup_disk [drive]                             135 ## setup_disk [drive]
136 ## => setup disk directory structure / copy fi    136 ## => setup disk directory structure / copy files
137 ##                                                137 ##
138 setup_disk () {                                   138 setup_disk () {
139   echo "Setup destination disk..."                139   echo "Setup destination disk..."
140                                                   140 
141   mmd $1/boot                                     141   mmd $1/boot
142   mmd $1/boot/grub                                142   mmd $1/boot/grub
143                                                   143 
144   if [ -d $GRUBDIR/stage1 ] ; then                144   if [ -d $GRUBDIR/stage1 ] ; then
145     mcopy $GRUBDIR/stage1/stage1 $1/boot/grub/    145     mcopy $GRUBDIR/stage1/stage1 $1/boot/grub/
146     mcopy $GRUBDIR/stage2/stage2 $1/boot/grub/    146     mcopy $GRUBDIR/stage2/stage2 $1/boot/grub/
147   else                                            147   else
148     mcopy $GRUBDIR/stage1 $1/boot/grub/           148     mcopy $GRUBDIR/stage1 $1/boot/grub/
149     mcopy $GRUBDIR/stage2 $1/boot/grub/           149     mcopy $GRUBDIR/stage2 $1/boot/grub/
150   fi                                              150   fi
151   mmd $1/system                                   151   mmd $1/system
152   mmd $1/modules                                  152   mmd $1/modules
153                                                   153 
154   $SBIN_GRUB --batch --no-floppy <<EOT 1>/dev/    154   $SBIN_GRUB --batch --no-floppy <<EOT 1>/dev/null 2>/dev/null || exit 1
155 device (fd0) $IMG_FNAME                           155 device (fd0) $IMG_FNAME
156 install (fd0)/boot/grub/stage1 (fd0) (fd0)/boo    156 install (fd0)/boot/grub/stage1 (fd0) (fd0)/boot/grub/stage2 p (fd0)/boot/grub/menu.txt
157 quit                                              157 quit
158 EOT                                               158 EOT
159 }                                                 159 }
160                                                   160 
161                                                   161 
162                                                   162 
163 ##############################################    163 #################################################
164 ## Real start                                     164 ## Real start
165 ##                                                165 ##
166 #[ "$#" -lt 3 ] && print_usage                    166 #[ "$#" -lt 3 ] && print_usage
167                                                   167 
168 lookup_grub                                       168 lookup_grub
169                                                   169 
170 dest="$1" ; shift                                 170 dest="$1" ; shift
171 loader_fname="$1" ; shift                         171 loader_fname="$1" ; shift
172 options="$1" ; shift                              172 options="$1" ; shift
173 modules="$*"                                      173 modules="$*"
174                                                   174 
175 # Init destination disk                           175 # Init destination disk
176 case x$dest in                                    176 case x$dest in
177   x*:)                                            177   x*:)
178     drive=$dest                                   178     drive=$dest
179     IMG_FNAME=$dest                               179     IMG_FNAME=$dest
180     FLOPPY_DRIVE=$dest                            180     FLOPPY_DRIVE=$dest
181     init_floppy                                   181     init_floppy
182     ;;                                            182     ;;
183   x*)                                             183   x*) 
184     drive=U:                                      184     drive=U:
185     IMG_FNAME=$dest                               185     IMG_FNAME=$dest
186     init_image                                    186     init_image
187     ;;                                            187     ;;
188 esac                                              188 esac
189                                                   189 
190 # Create directory structure                      190 # Create directory structure
191 setup_disk $drive                                 191 setup_disk $drive
192                                                   192 
193 # Copy the loader                                 193 # Copy the loader
194 mcopy -bo $loader_fname $drive/system/`basenam    194 mcopy -bo $loader_fname $drive/system/`basename $loader_fname`
195                                                   195 
196 # Generate the menu.txt file                      196 # Generate the menu.txt file
197 rm -f menu.txt                                    197 rm -f menu.txt
198 cat <<EOF > menu.txt                              198 cat <<EOF > menu.txt
199 timeout 0                                         199 timeout 0 
200 default 0                                         200 default 0
201 title  Simple OS                                  201 title  Simple OS
202 root   (fd0)                                      202 root   (fd0)
203 kernel /system/`basename $loader_fname` $optio    203 kernel /system/`basename $loader_fname` $options
204 EOF                                               204 EOF
205                                                   205 
206 # Copy the modules                                206 # Copy the modules
207 for f in $modules ; do                            207 for f in $modules ; do
208     if [ ! -f $f ] ; then                         208     if [ ! -f $f ] ; then
209         echo "ERROR: module $f not correctly c    209         echo "ERROR: module $f not correctly compiled in."
210         exit 1                                    210         exit 1
211     fi                                            211     fi
212     if ! mcopy -bo $f $drive/modules/`basename    212     if ! mcopy -bo $f $drive/modules/`basename $f` ; then
213         echo "ERROR: module $f could not be tr    213         echo "ERROR: module $f could not be transferred to floppy."
214         exit 1                                    214         exit 1
215     fi                                            215     fi
216     echo module /modules/`basename $f` >> menu    216     echo module /modules/`basename $f` >> menu.txt
217 done                                              217 done
218                                                   218 
219 # Transfers the menu.txt file to floppy           219 # Transfers the menu.txt file to floppy
220 mcopy -bo menu.txt $drive/boot/grub/              220 mcopy -bo menu.txt $drive/boot/grub/
                                                      

source navigation ] diff markup ] identifier search ] general search ]