wok-current annotate linux/stuff/bootloader.sh @ rev 5666
linux: include xhci-hcd,smsc*,ipheth,int51x1,vmxnet3 modules
author | Christophe Lincoln <pankso@slitaz.org> |
---|---|
date | Sun May 30 12:03:29 2010 +0200 (2010-05-30) |
parents | 7798d8b688a9 |
children | 85241294b8f8 |
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@4504 | 13 [--format 1440|1680|1720|2880 ] [--initrd initrdfile]... |
pascal@4504 | 14 |
pascal@4504 | 15 Example: |
pascal@4504 | 16 $0 /boot/vmlinuz-2.6.30.6 --cmdline 'rw lang=fr_FR kmap=fr-latin1 laptop autologin' --initrd /boot/rootfs.gz --initrd ./myconfig.gz |
pascal@4504 | 17 EOT |
pascal@4504 | 18 exit 1 |
pascal@4504 | 19 } |
pascal@4504 | 20 |
pascal@4504 | 21 KERNEL="" |
pascal@4504 | 22 INITRD="" |
pascal@4504 | 23 CMDLINE="" |
pascal@4504 | 24 PREFIX="floppy" |
pascal@4504 | 25 FORMAT="1440" |
pascal@4504 | 26 while [ -n "$1" ]; do |
pascal@4504 | 27 case "$1" in |
pascal@4504 | 28 --cmdline) CMDLINE="$2"; shift;; |
pascal@4504 | 29 --initrd) INITRD="$INITRD $2"; shift;; |
pascal@4504 | 30 --prefix) PREFIX="$2"; shift;; |
pascal@4504 | 31 --format) FORMAT="$2"; shift;; |
pascal@4504 | 32 *) KERNEL="$1";; |
pascal@4504 | 33 esac |
pascal@4504 | 34 shift |
pascal@4504 | 35 done |
pascal@4504 | 36 [ -n "$KERNEL" -a -f "$KERNEL" ] || usage |
pascal@4504 | 37 |
pascal@4504 | 38 # write a 32 bits data |
pascal@4504 | 39 # usage: storelong offset data32 file |
pascal@4504 | 40 storelong() |
pascal@4504 | 41 { |
pascal@5564 | 42 echo $2 | awk '{ printf "%c%c%c%c",$1%256,($1/256)%256,($1/256/256)%256, |
pascal@5564 | 43 ($1/256/256/256)%256 }' | \ |
pascal@5564 | 44 dd bs=1 conv=notrunc of=$3 seek=$(( $1 )) 2> /dev/null |
pascal@4504 | 45 } |
pascal@4504 | 46 |
pascal@4504 | 47 # read a 32 bits data |
pascal@4504 | 48 # usage: getlong offset file |
pascal@4504 | 49 getlong() |
pascal@4504 | 50 { |
pascal@4504 | 51 dd if=$2 bs=1 skip=$(( $1 )) count=4 2> /dev/null | \ |
pascal@4504 | 52 hexdump -e '"" 1/4 "%d" "\n"' |
pascal@4504 | 53 } |
pascal@4504 | 54 |
pascal@4504 | 55 floppyset() |
pascal@4504 | 56 { |
pascal@4504 | 57 # bzImage offsets |
pascal@4504 | 58 SetupSzOfs=497 |
pascal@4504 | 59 SyssizeOfs=500 |
pascal@4504 | 60 CodeAdrOfs=0x214 |
pascal@4504 | 61 RamfsAdrOfs=0x218 |
pascal@4504 | 62 RamfsLenOfs=0x21C |
pascal@4504 | 63 ArgPtrOfs=0x228 |
pascal@4504 | 64 |
pascal@4504 | 65 # boot+setup address |
pascal@4504 | 66 SetupBase=0x90000 |
pascal@4504 | 67 |
pascal@4504 | 68 stacktop=0x9E00 |
pascal@4504 | 69 |
pascal@4504 | 70 bs=/tmp/bs$$ |
pascal@4504 | 71 |
pascal@4504 | 72 # Get and patch boot sector |
pascal@5564 | 73 # See http://hg.slitaz.org/wok/raw-file/tip/linux/stuff/linux-header-2.6.30.6.u |
pascal@4504 | 74 dd if=$KERNEL bs=512 count=1 of=$bs 2> /dev/null |
pascal@4504 | 75 uudecode <<EOT | dd of=$bs conv=notrunc 2> /dev/null |
pascal@4504 | 76 begin-base64 644 - |
pascal@5424 | 77 /L+6nWgAkAcGF4n8McC5HQDzq1sfD6mg8X1ABlfFd3ixBvOlZWaPR3gGH8ZF |
pascal@5424 | 78 +D/6l1hB6DQBvgACA3QO6HYBWwseKAJ0LFNH6AoBXuhmAbAgzRCwCM0QTuhl |
pascal@5424 | 79 ATwIdAOIBK05NigCdPDoPgE8CnXgiHz+ieb/TBD/TBi/9AGBTRz/gMdFMACc |
pascal@5424 | 80 sBCxBUi0k4lEHLABiUQUmGaY0+BIZgMFZtPoaAAQB7+AACn4nHMCAccx21BW |
pascal@5424 | 81 6J4AXrkAgLSH/kQczRVYnXfcoRoCvxwCsQk4RBxyuJPNE+oAACCQsEYoyL7b |
pascal@5424 | 82 AejSAF3rI4D5E3IEOMF3a4D+AnIEOOZ3bGCB/QAGdCoGUlFTlrQCULEGtQTB |
pascal@5424 | 83 xQSwDyHoBJAnFEAn6IwA/s117LAgzRDitOiWAJjNE2FSUCjIdwKwAZg5+HIC |
pascal@5424 | 84 ifhQtALNE5VeWFpyoJVBjuGAxwJPdFFOdfSM4ZU4wXVFiMj+xrEBOOZ1O4j0 |
pascal@5424 | 85 /sW2AID9UHIwOi7wAXIqtQBgvt4B/kQMU+gxAFvoOAB1FlKYzRO4AQLNE1rQ |
pascal@5424 | 86 1Dpk/nXqRgjkdeVh64sWB7AxLAO0DrsHAM0QPA1088OwDejv/6wIwHX4w79s |
pascal@5424 | 87 BLFbZQINuA0BZToNdArNFnT0mM0Wju9Hw1g6AEluc2VydCBkaXNrIDEuBw0A |
pascal@4511 | 88 AA== |
pascal@4504 | 89 ==== |
pascal@4504 | 90 EOT |
pascal@4504 | 91 |
pascal@4504 | 92 # Get setup |
pascal@4504 | 93 setupsz=$(getlong $SetupSzOfs $bs) |
pascal@4504 | 94 setupszb=$(( $setupsz & 255 )) |
pascal@4504 | 95 dd if=$KERNEL bs=512 skip=1 count=$setupszb 2> /dev/null >> $bs |
pascal@4504 | 96 |
pascal@4504 | 97 # Store cmdline after setup |
pascal@4504 | 98 if [ -n "$CMDLINE" ]; then |
pascal@4504 | 99 echo -n "$CMDLINE" | dd bs=512 count=1 conv=sync 2> /dev/null >> $bs |
pascal@4504 | 100 storelong ArgPtrOfs $(( $SetupBase + $stacktop )) $bs |
pascal@4504 | 101 fi |
pascal@4504 | 102 |
pascal@4504 | 103 # Compute initramfs size |
pascal@4504 | 104 initrdlen=0 |
pascal@4504 | 105 padding=0 |
pascal@4504 | 106 for i in $( echo $INITRD | sed 's/,/ /' ); do |
pascal@4504 | 107 [ -s "$i" ] || continue |
pascal@4504 | 108 initrdlen=$(( $initrdlen + $padding )) |
pascal@4504 | 109 padding=$(stat -c %s $i) |
pascal@4504 | 110 initrdlen=$(( $initrdlen + $padding )) |
pascal@4504 | 111 padding=$(( 4096 - ($padding & 4095) )) |
pascal@4504 | 112 [ $padding -eq 4096 ] && padding=0 |
pascal@4504 | 113 done |
pascal@4504 | 114 Ksize=$(( $(getlong $SyssizeOfs $bs)*16 )) |
pascal@4504 | 115 Kpad=$(( (($Ksize+4095)/4096)*4096 - Ksize )) |
pascal@4504 | 116 if [ $initrdlen -ne 0 ]; then |
pascal@4504 | 117 Kbase=$(getlong $CodeAdrOfs $bs) |
pascal@4504 | 118 storelong $RamfsAdrOfs \ |
pascal@4504 | 119 $(( (0x1000000 - $initrdlen) & 0xFFFF0000 )) $bs |
pascal@4504 | 120 storelong $RamfsLenOfs $initrdlen $bs |
pascal@4504 | 121 fi |
pascal@4504 | 122 |
pascal@4504 | 123 # Output boot sector + setup + cmdline |
pascal@4504 | 124 dd if=$bs 2> /dev/null |
pascal@4504 | 125 |
pascal@4504 | 126 # Output kernel code |
pascal@4504 | 127 dd if=$KERNEL bs=512 skip=$(( $setupszb + 1 )) 2> /dev/null |
pascal@4504 | 128 |
pascal@4504 | 129 # Pad to next sector |
pascal@4504 | 130 Kpad=$(( 512 - ($(stat -c %s $KERNEL) & 511) )) |
pascal@4504 | 131 [ $Kpad -eq 512 ] || dd if=/dev/zero bs=1 count=$Kpad 2> /dev/null |
pascal@4504 | 132 |
pascal@4504 | 133 # Output initramfs |
pascal@4504 | 134 padding=0 |
pascal@4504 | 135 for i in $( echo $INITRD | sed 's/,/ /' ); do |
pascal@4504 | 136 [ -s "$i" ] || continue |
pascal@4504 | 137 [ $padding -ne 0 ] && dd if=/dev/zero bs=1 count=$padding |
pascal@4504 | 138 dd if=$i 2> /dev/null |
pascal@4504 | 139 padding=$(( 4096 - ($(stat -c %s $i) & 4095) )) |
pascal@4504 | 140 [ $padding -eq 4096 ] && padding=0 |
pascal@4504 | 141 done |
pascal@4504 | 142 |
pascal@4504 | 143 # Cleanup |
pascal@4504 | 144 rm -f $bs |
pascal@4504 | 145 } |
pascal@4504 | 146 |
pascal@4504 | 147 floppyset | split -b ${FORMAT}k /dev/stdin floppy$$ |
pascal@4504 | 148 i=1 |
pascal@4504 | 149 ls floppy$$* | while read file ; do |
pascal@4504 | 150 output=$PREFIX.$(printf "%03d" $i) |
pascal@4504 | 151 cat $file /dev/zero | dd bs=1k count=$FORMAT conv=sync of=$output 2> /dev/null |
pascal@4504 | 152 echo $output |
pascal@4504 | 153 rm -f $file |
pascal@4504 | 154 i=$(( $i + 1 )) |
pascal@4504 | 155 done |