wok-current annotate linux/stuff/bootloader.sh @ rev 4506
linux/boot: fix cmdline tail
author | Pascal Bellard <pascal.bellard@slitaz.org> |
---|---|
date | Mon Nov 23 11:01:54 2009 +0100 (2009-11-23) |
parents | aa65a927a2f3 |
children | b1b311195e79 |
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@4504 | 42 printf "00000 %02X %02X %02X %02X \n" \ |
pascal@4504 | 43 $(( $2 & 255 )) $(( ($2>>8) & 255 )) \ |
pascal@4504 | 44 $(( ($2>>16) & 255 )) $(( ($2>>24) & 255 )) | \ |
pascal@4504 | 45 hexdump -R | dd bs=1 conv=notrunc of=$3 seek=$(( $1 )) 2> /dev/null |
pascal@4504 | 46 } |
pascal@4504 | 47 |
pascal@4504 | 48 # read a 32 bits data |
pascal@4504 | 49 # usage: getlong offset file |
pascal@4504 | 50 getlong() |
pascal@4504 | 51 { |
pascal@4504 | 52 dd if=$2 bs=1 skip=$(( $1 )) count=4 2> /dev/null | \ |
pascal@4504 | 53 hexdump -e '"" 1/4 "%d" "\n"' |
pascal@4504 | 54 } |
pascal@4504 | 55 |
pascal@4504 | 56 floppyset() |
pascal@4504 | 57 { |
pascal@4504 | 58 # bzImage offsets |
pascal@4504 | 59 SetupSzOfs=497 |
pascal@4504 | 60 SyssizeOfs=500 |
pascal@4504 | 61 CodeAdrOfs=0x214 |
pascal@4504 | 62 RamfsAdrOfs=0x218 |
pascal@4504 | 63 RamfsLenOfs=0x21C |
pascal@4504 | 64 ArgPtrOfs=0x228 |
pascal@4504 | 65 |
pascal@4504 | 66 # boot+setup address |
pascal@4504 | 67 SetupBase=0x90000 |
pascal@4504 | 68 |
pascal@4504 | 69 stacktop=0x9E00 |
pascal@4504 | 70 |
pascal@4504 | 71 bs=/tmp/bs$$ |
pascal@4504 | 72 |
pascal@4504 | 73 # Get and patch boot sector |
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@4504 | 77 v/Sd/GgAkAcxyQYXify7eACO2cU3sQbzpY7ZiSeMRwKg8X2YQAYfxkX4P/qX |
pascal@4506 | 78 mEEx2+hAAb4AAoBMEYDHRCQAnAN0DuhmAb4oAjkcci9HixxW6EIBX4s16FIB |
pascal@4506 | 79 sCDNELAIzRBOmM0WPAh0BJiJBK07NXTx6CsBPAp14Yh8/rkYAGoA4vyJ5rAP |
pascal@4506 | 80 v/QB/k0csQW0k4lEHLABiUQUmYlUEIlUGGYx20PT40tmAx1m0+toABAHv4AA |
pascal@4506 | 81 KfuccwIB31NWMdvo1ABeuQCAtIf+RBzNFVudd9yhGgJIvxwCsQk4RBxysDHA |
pascal@4506 | 82 zRPqAAAgkLBGKMi+twHovABd6yOA+RNyBDjBd2iA/gJyBDjmd2mA/VBzc2AG |
pascal@4506 | 83 UlFTlrQCULkGAFGxBMHFBLAPIegEkCcUQCfodQDi7rAgzRBZ4rSYzRNhMfat |
pascal@4506 | 84 ka2SrVAoyHcCsAGYOfhyAon4UFK0As0TWpVeWHKcKfcB8cHmCQHzOMF1JojI |
pascal@4506 | 85 /saxATjmdRyI9P7FtgA8E3USgP1Qcg21AGC+ugHoJACYzRZhowQAUlFmjwYA |
pascal@4506 | 86 AAn/dZ4WB7AxLAO0DrsHAM0QPA1088OwDejv/6wIwHX4w1g6AEluc2VydCBu |
pascal@4506 | 87 ZXh0IGZsb3BweSBhbmQgcHJlc3MgYW55IGtleSB0byBjb250aW51ZS4HDQA= |
pascal@4504 | 88 ==== |
pascal@4504 | 89 EOT |
pascal@4504 | 90 |
pascal@4504 | 91 # Get setup |
pascal@4504 | 92 setupsz=$(getlong $SetupSzOfs $bs) |
pascal@4504 | 93 setupszb=$(( $setupsz & 255 )) |
pascal@4504 | 94 dd if=$KERNEL bs=512 skip=1 count=$setupszb 2> /dev/null >> $bs |
pascal@4504 | 95 |
pascal@4504 | 96 # Store cmdline after setup |
pascal@4504 | 97 if [ -n "$CMDLINE" ]; then |
pascal@4504 | 98 echo -n "$CMDLINE" | dd bs=512 count=1 conv=sync 2> /dev/null >> $bs |
pascal@4504 | 99 storelong ArgPtrOfs $(( $SetupBase + $stacktop )) $bs |
pascal@4504 | 100 fi |
pascal@4504 | 101 |
pascal@4504 | 102 # Compute initramfs size |
pascal@4504 | 103 initrdlen=0 |
pascal@4504 | 104 padding=0 |
pascal@4504 | 105 for i in $( echo $INITRD | sed 's/,/ /' ); do |
pascal@4504 | 106 [ -s "$i" ] || continue |
pascal@4504 | 107 initrdlen=$(( $initrdlen + $padding )) |
pascal@4504 | 108 padding=$(stat -c %s $i) |
pascal@4504 | 109 initrdlen=$(( $initrdlen + $padding )) |
pascal@4504 | 110 padding=$(( 4096 - ($padding & 4095) )) |
pascal@4504 | 111 [ $padding -eq 4096 ] && padding=0 |
pascal@4504 | 112 done |
pascal@4504 | 113 Ksize=$(( $(getlong $SyssizeOfs $bs)*16 )) |
pascal@4504 | 114 Kpad=$(( (($Ksize+4095)/4096)*4096 - Ksize )) |
pascal@4504 | 115 if [ $initrdlen -ne 0 ]; then |
pascal@4504 | 116 Kbase=$(getlong $CodeAdrOfs $bs) |
pascal@4504 | 117 storelong $RamfsAdrOfs \ |
pascal@4504 | 118 $(( (0x1000000 - $initrdlen) & 0xFFFF0000 )) $bs |
pascal@4504 | 119 storelong $RamfsLenOfs $initrdlen $bs |
pascal@4504 | 120 fi |
pascal@4504 | 121 |
pascal@4504 | 122 # Output boot sector + setup + cmdline |
pascal@4504 | 123 dd if=$bs 2> /dev/null |
pascal@4504 | 124 |
pascal@4504 | 125 # Output kernel code |
pascal@4504 | 126 dd if=$KERNEL bs=512 skip=$(( $setupszb + 1 )) 2> /dev/null |
pascal@4504 | 127 |
pascal@4504 | 128 # Pad to next sector |
pascal@4504 | 129 Kpad=$(( 512 - ($(stat -c %s $KERNEL) & 511) )) |
pascal@4504 | 130 [ $Kpad -eq 512 ] || dd if=/dev/zero bs=1 count=$Kpad 2> /dev/null |
pascal@4504 | 131 |
pascal@4504 | 132 # Output initramfs |
pascal@4504 | 133 padding=0 |
pascal@4504 | 134 for i in $( echo $INITRD | sed 's/,/ /' ); do |
pascal@4504 | 135 [ -s "$i" ] || continue |
pascal@4504 | 136 [ $padding -ne 0 ] && dd if=/dev/zero bs=1 count=$padding |
pascal@4504 | 137 dd if=$i 2> /dev/null |
pascal@4504 | 138 padding=$(( 4096 - ($(stat -c %s $i) & 4095) )) |
pascal@4504 | 139 [ $padding -eq 4096 ] && padding=0 |
pascal@4504 | 140 done |
pascal@4504 | 141 |
pascal@4504 | 142 # Cleanup |
pascal@4504 | 143 rm -f $bs |
pascal@4504 | 144 } |
pascal@4504 | 145 |
pascal@4504 | 146 floppyset | split -b ${FORMAT}k /dev/stdin floppy$$ |
pascal@4504 | 147 i=1 |
pascal@4504 | 148 ls floppy$$* | while read file ; do |
pascal@4504 | 149 output=$PREFIX.$(printf "%03d" $i) |
pascal@4504 | 150 cat $file /dev/zero | dd bs=1k count=$FORMAT conv=sync of=$output 2> /dev/null |
pascal@4504 | 151 echo $output |
pascal@4504 | 152 rm -f $file |
pascal@4504 | 153 i=$(( $i + 1 )) |
pascal@4504 | 154 done |