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