wok-current annotate linux/stuff/bootloader.sh @ rev 8355
Fix: xorg-xf86-video-intel needs xcb-util to have 3d support.
author | Christopher Rogers <slaxemulator@gmail.com> |
---|---|
date | Thu Feb 03 11:34:07 2011 +0000 (2011-02-03) |
parents | 3bff7f88b1c8 |
children | 7d497422d803 |
rev | line source |
---|---|
pascal@4504 | 1 #!/bin/sh |
pascal@4504 | 2 # |
pascal@4504 | 3 # This script creates a floppy image set from a linux bzImage and can merge |
pascal@4504 | 4 # a cmdline and/or one or more initramfs. |
pascal@4504 | 5 # The total size can not exceed 15M because INT 15H function 87H limitations. |
pascal@4504 | 6 # |
pascal@4504 | 7 # (C) 2009 Pascal Bellard - GNU General Public License v3. |
pascal@4504 | 8 |
pascal@4504 | 9 usage() |
pascal@4504 | 10 { |
pascal@4504 | 11 cat <<EOT |
pascal@4504 | 12 Usage: $0 bzImage [--prefix image_prefix] [--cmdline 'args'] |
pascal@6715 | 13 [--rdev device] [--video mode] [--flags rootflags] [--tracks cnt] |
pascal@6715 | 14 [--format 1440|1680|1920|2880 ] [--initrd initrdfile]... |
pascal@6715 | 15 |
pascal@6715 | 16 Default values: --format 1440 --tracks 80 --prefix floppy. |
pascal@4504 | 17 |
pascal@4504 | 18 Example: |
pascal@6713 | 19 $0 /boot/vmlinuz-2.6.30.6 --rdev /dev/ram0 --video -3 --cmdline 'rw lang=fr_FR kmap=fr-latin1 laptop autologin' --initrd /boot/rootfs.gz --initrd ./myconfig.gz |
pascal@4504 | 20 EOT |
pascal@4504 | 21 exit 1 |
pascal@4504 | 22 } |
pascal@4504 | 23 |
pascal@4504 | 24 KERNEL="" |
pascal@4504 | 25 INITRD="" |
pascal@4504 | 26 CMDLINE="" |
pascal@6713 | 27 PREFIX="floppy." |
pascal@4504 | 28 FORMAT="1440" |
pascal@6713 | 29 RDEV="" |
pascal@6713 | 30 VIDEO="" |
pascal@6713 | 31 FLAGS="" |
pascal@6715 | 32 TRACKS="" |
pascal@6713 | 33 DEBUG="" |
pascal@4504 | 34 while [ -n "$1" ]; do |
pascal@4504 | 35 case "$1" in |
pascal@6713 | 36 --c*|-c*) CMDLINE="$2"; shift;; |
pascal@6713 | 37 --i*|-i*) INITRD="$INITRD $2"; shift;; |
pascal@6713 | 38 --p*|-p*) PREFIX="$2"; shift;; |
pascal@6713 | 39 --fo*|-f*) FORMAT="$2"; shift;; |
pascal@6713 | 40 --fl*) FLAGS="$2"; shift;; # 1 read-only, 0 read-write |
pascal@6713 | 41 --r*|-r*) RDEV="$2"; shift;; # /dev/??? |
pascal@6713 | 42 --v*|-v*) VIDEO="$2"; shift;; # -3 .. n |
pascal@6715 | 43 --t*|-t*) TRACKS="$2"; shift;; # likely 81 .. 84 |
pascal@6713 | 44 --debug) DEBUG="1";; |
pascal@4504 | 45 *) KERNEL="$1";; |
pascal@4504 | 46 esac |
pascal@4504 | 47 shift |
pascal@4504 | 48 done |
pascal@4504 | 49 [ -n "$KERNEL" -a -f "$KERNEL" ] || usage |
pascal@6715 | 50 if [ -n "$TRACKS" ]; then |
pascal@6715 | 51 if [ $(( $FORMAT % $TRACKS )) -ne 0 ]; then |
pascal@6715 | 52 echo "Invalid track count for format $FORMAT." |
pascal@6715 | 53 usage |
pascal@6715 | 54 fi |
pascal@6715 | 55 fi |
pascal@4504 | 56 |
pascal@6713 | 57 # write a 16 bits data |
pascal@6713 | 58 # usage: store16 offset data16 file |
pascal@6713 | 59 store16() |
pascal@6713 | 60 { |
pascal@6715 | 61 echo $(( $2 + 0x10000 )) | \ |
pascal@6715 | 62 awk '{ printf "\\\\x%02X\\\\x%02X",$1%256,($1/256)%256 }' | \ |
pascal@6713 | 63 xargs echo -en | \ |
pascal@6713 | 64 dd bs=2 conv=notrunc of=$3 seek=$(( $1 / 2 )) 2> /dev/null |
pascal@6713 | 65 [ -n "$DEBUG" ] && printf "store16(%04X) = %04X\n" $1 $2 1>&2 |
pascal@6713 | 66 } |
pascal@6713 | 67 |
pascal@4504 | 68 # write a 32 bits data |
pascal@4504 | 69 # usage: storelong offset data32 file |
pascal@4504 | 70 storelong() |
pascal@4504 | 71 { |
pascal@6713 | 72 echo $2 | awk '{ printf "\\\\x%02X\\\\x%02X\\\\x%02X\\\\x%02X", |
pascal@6713 | 73 $1%256,($1/256)%256,($1/256/256)%256,($1/256/256/256)%256 }' | \ |
pascal@6713 | 74 xargs echo -en | \ |
pascal@6713 | 75 dd bs=4 conv=notrunc of=$3 seek=$(( $1 / 4 )) 2> /dev/null |
pascal@6713 | 76 [ -n "$DEBUG" ] && printf "storelong(%04X) = %08X\n" $1 $2 1>&2 |
pascal@4504 | 77 } |
pascal@4504 | 78 |
pascal@4504 | 79 # read a 32 bits data |
pascal@4504 | 80 # usage: getlong offset file |
pascal@4504 | 81 getlong() |
pascal@4504 | 82 { |
pascal@4504 | 83 dd if=$2 bs=1 skip=$(( $1 )) count=4 2> /dev/null | \ |
pascal@4504 | 84 hexdump -e '"" 1/4 "%d" "\n"' |
pascal@4504 | 85 } |
pascal@4504 | 86 |
pascal@4504 | 87 floppyset() |
pascal@4504 | 88 { |
pascal@4504 | 89 # bzImage offsets |
pascal@6715 | 90 CylinderCount=496 |
pascal@4504 | 91 SetupSzOfs=497 |
pascal@6713 | 92 FlagsOfs=498 |
pascal@4504 | 93 SyssizeOfs=500 |
pascal@6713 | 94 VideoModeOfs=506 |
pascal@6713 | 95 RootDevOfs=508 |
pascal@4504 | 96 CodeAdrOfs=0x214 |
pascal@4504 | 97 RamfsAdrOfs=0x218 |
pascal@4504 | 98 RamfsLenOfs=0x21C |
pascal@4504 | 99 ArgPtrOfs=0x228 |
pascal@4504 | 100 |
pascal@4504 | 101 # boot+setup address |
pascal@4504 | 102 SetupBase=0x90000 |
pascal@4504 | 103 |
pascal@4504 | 104 stacktop=0x9E00 |
pascal@4504 | 105 |
pascal@4504 | 106 bs=/tmp/bs$$ |
pascal@4504 | 107 |
pascal@4504 | 108 # Get and patch boot sector |
pascal@5939 | 109 # See http://hg.slitaz.org/wok/raw-file/711d076b277c/linux/stuff/linux-header-2.6.34.u |
pascal@4504 | 110 dd if=$KERNEL bs=512 count=1 of=$bs 2> /dev/null |
pascal@4504 | 111 uudecode <<EOT | dd of=$bs conv=notrunc 2> /dev/null |
pascal@4504 | 112 begin-base64 644 - |
pascal@5424 | 113 /L+6nWgAkAcGF4n8McC5HQDzq1sfD6mg8X1ABlfFd3ixBvOlZWaPR3gGH8ZF |
pascal@5424 | 114 +D/6l1hB6DQBvgACA3QO6HYBWwseKAJ0LFNH6AoBXuhmAbAgzRCwCM0QTuhl |
pascal@5424 | 115 ATwIdAOIBK05NigCdPDoPgE8CnXgiHz+ieb/TBD/TBi/9AGBTRz/gMdFMACc |
pascal@5424 | 116 sBCxBUi0k4lEHLABiUQUmGaY0+BIZgMFZtPoaAAQB7+AACn4nHMCAccx21BW |
pascal@5424 | 117 6J4AXrkAgLSH/kQczRVYnXfcoRoCvxwCsQk4RBxyuJPNE+oAACCQsEYoyL7b |
pascal@5424 | 118 AejSAF3rI4D5E3IEOMF3a4D+AnIEOOZ3bGCB/QAGdCoGUlFTlrQCULEGtQTB |
pascal@5424 | 119 xQSwDyHoBJAnFEAn6IwA/s117LAgzRDitOiWAJjNE2FSUCjIdwKwAZg5+HIC |
pascal@5424 | 120 ifhQtALNE5VeWFpyoJVBjuGAxwJPdFFOdfSM4ZU4wXVFiMj+xrEBOOZ1O4j0 |
pascal@5424 | 121 /sW2AID9UHIwOi7wAXIqtQBgvt4B/kQMU+gxAFvoOAB1FlKYzRO4AQLNE1rQ |
pascal@5424 | 122 1Dpk/nXqRgjkdeVh64sWB7AxLAO0DrsHAM0QPA1088OwDejv/6wIwHX4w79s |
pascal@5424 | 123 BLFbZQINuA0BZToNdArNFnT0mM0Wju9Hw1g6AEluc2VydCBkaXNrIDEuBw0A |
pascal@4511 | 124 AA== |
pascal@4504 | 125 ==== |
pascal@4504 | 126 EOT |
pascal@4504 | 127 |
pascal@4504 | 128 # Get setup |
pascal@4504 | 129 setupsz=$(getlong $SetupSzOfs $bs) |
pascal@4504 | 130 setupszb=$(( $setupsz & 255 )) |
pascal@4504 | 131 dd if=$KERNEL bs=512 skip=1 count=$setupszb 2> /dev/null >> $bs |
pascal@4504 | 132 |
pascal@6715 | 133 if [ -n "$TRACKS" ]; then |
pascal@6715 | 134 [ -n "$DEBUG" ] && echo -n "--tracks " 1>&2 |
pascal@6715 | 135 n=$(getlong $CylinderCount $bs) |
pascal@6715 | 136 store16 $CylinderCount $(( ($n & -256) + $TRACKS )) $bs |
pascal@6715 | 137 fi |
pascal@6713 | 138 if [ -n "$FLAGS" ]; then |
pascal@6713 | 139 [ -n "$DEBUG" ] && echo -n "--flags " 1>&2 |
pascal@6715 | 140 store16 $FlagsOfs $FLAGS $bs |
pascal@6713 | 141 fi |
pascal@6713 | 142 if [ -n "$VIDEO" ]; then |
pascal@6713 | 143 [ -n "$DEBUG" ] && echo -n "--video " 1>&2 |
pascal@6715 | 144 store16 $VideoModeOfs $VIDEO $bs |
pascal@6713 | 145 fi |
pascal@6713 | 146 if [ -n "$RDEV" ]; then |
pascal@6713 | 147 [ -n "$DEBUG" ] && echo -n "--rdev " 1>&2 |
pascal@6713 | 148 n=$(stat -c '0x%02t%02T' $RDEV 2> /dev/null) |
pascal@6713 | 149 [ -n "$n" ] || n=$RDEV |
pascal@6715 | 150 store16 $RootDevOfs $n $bs |
pascal@6713 | 151 fi |
pascal@6713 | 152 |
pascal@4504 | 153 # Store cmdline after setup |
pascal@4504 | 154 if [ -n "$CMDLINE" ]; then |
pascal@6713 | 155 [ -n "$DEBUG" ] && echo -n "--cmdline '$CMDLINE' " 1>&2 |
pascal@4504 | 156 echo -n "$CMDLINE" | dd bs=512 count=1 conv=sync 2> /dev/null >> $bs |
pascal@6713 | 157 storelong $ArgPtrOfs $(( $SetupBase + $stacktop )) $bs |
pascal@4504 | 158 fi |
pascal@4504 | 159 |
pascal@4504 | 160 # Compute initramfs size |
pascal@4504 | 161 initrdlen=0 |
pascal@4504 | 162 padding=0 |
pascal@4504 | 163 for i in $( echo $INITRD | sed 's/,/ /' ); do |
pascal@4504 | 164 [ -s "$i" ] || continue |
pascal@6713 | 165 [ -n "$DEBUG" ] && echo "--initrd $i " 1>&2 |
pascal@4504 | 166 initrdlen=$(( $initrdlen + $padding )) |
pascal@4504 | 167 padding=$(stat -c %s $i) |
pascal@4504 | 168 initrdlen=$(( $initrdlen + $padding )) |
pascal@4504 | 169 padding=$(( 4096 - ($padding & 4095) )) |
pascal@4504 | 170 [ $padding -eq 4096 ] && padding=0 |
pascal@4504 | 171 done |
pascal@4504 | 172 Ksize=$(( $(getlong $SyssizeOfs $bs)*16 )) |
pascal@4504 | 173 Kpad=$(( (($Ksize+4095)/4096)*4096 - Ksize )) |
pascal@4504 | 174 if [ $initrdlen -ne 0 ]; then |
pascal@6713 | 175 [ -n "$DEBUG" ] && echo "initrdlen = $initrdlen " 1>&2 |
pascal@4504 | 176 Kbase=$(getlong $CodeAdrOfs $bs) |
pascal@4504 | 177 storelong $RamfsAdrOfs \ |
pascal@4504 | 178 $(( (0x1000000 - $initrdlen) & 0xFFFF0000 )) $bs |
pascal@6714 | 179 storelong $RamfsLenOfs $(( ($initrdlen + 3) & -4 )) $bs |
pascal@4504 | 180 fi |
pascal@4504 | 181 |
pascal@4504 | 182 # Output boot sector + setup + cmdline |
pascal@4504 | 183 dd if=$bs 2> /dev/null |
pascal@4504 | 184 |
pascal@4504 | 185 # Output kernel code |
pascal@4504 | 186 dd if=$KERNEL bs=512 skip=$(( $setupszb + 1 )) 2> /dev/null |
pascal@4504 | 187 |
pascal@4504 | 188 # Pad to next sector |
pascal@4504 | 189 Kpad=$(( 512 - ($(stat -c %s $KERNEL) & 511) )) |
pascal@4504 | 190 [ $Kpad -eq 512 ] || dd if=/dev/zero bs=1 count=$Kpad 2> /dev/null |
pascal@4504 | 191 |
pascal@4504 | 192 # Output initramfs |
pascal@4504 | 193 padding=0 |
pascal@4504 | 194 for i in $( echo $INITRD | sed 's/,/ /' ); do |
pascal@4504 | 195 [ -s "$i" ] || continue |
pascal@6713 | 196 [ $padding -ne 0 ] && dd if=/dev/zero bs=1 count=$padding 2> /dev/null |
pascal@4504 | 197 dd if=$i 2> /dev/null |
pascal@6713 | 198 padding=$(( 4 - ($(stat -c %s $i) & 3) )) |
pascal@6713 | 199 [ $padding -eq 4 ] && padding=0 |
pascal@4504 | 200 done |
pascal@4504 | 201 |
pascal@4504 | 202 # Cleanup |
pascal@4504 | 203 rm -f $bs |
pascal@4504 | 204 } |
pascal@4504 | 205 |
pascal@6715 | 206 if [ "$FORMAT" == "0" ]; then # unsplitted |
pascal@6715 | 207 floppyset > $PREFIX |
pascal@6715 | 208 exit |
pascal@6715 | 209 fi |
pascal@4504 | 210 floppyset | split -b ${FORMAT}k /dev/stdin floppy$$ |
pascal@4504 | 211 i=1 |
pascal@4504 | 212 ls floppy$$* | while read file ; do |
pascal@6713 | 213 output=$PREFIX$(printf "%03d" $i) |
pascal@4504 | 214 cat $file /dev/zero | dd bs=1k count=$FORMAT conv=sync of=$output 2> /dev/null |
pascal@4504 | 215 echo $output |
pascal@4504 | 216 rm -f $file |
pascal@4504 | 217 i=$(( $i + 1 )) |
pascal@4504 | 218 done |