wok-6.x diff linux/stuff/bootloader.sh @ rev 4504
linux: add floppy boot support
author | Pascal Bellard <pascal.bellard@slitaz.org> |
---|---|
date | Sun Nov 22 12:46:40 2009 +0100 (2009-11-22) |
parents | |
children | b5013b460117 |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/linux/stuff/bootloader.sh Sun Nov 22 12:46:40 2009 +0100 1.3 @@ -0,0 +1,155 @@ 1.4 +#!/bin/sh 1.5 +# 1.6 +# This script creates a floppy image set from a linux bzImage and can merge 1.7 +# a cmdline and/or one or more initramfs. 1.8 +# The total size can not exceed 15M because INT 15H function 87H limitations. 1.9 +# 1.10 +# (C) 2009 Pascal Bellard - GNU General Public License v3. 1.11 + 1.12 +usage() 1.13 +{ 1.14 +cat <<EOT 1.15 +Usage: $0 bzImage [--prefix image_prefix] [--cmdline 'args'] 1.16 + [--format 1440|1680|1720|2880 ] [--initrd initrdfile]... 1.17 + 1.18 +Example: 1.19 +$0 /boot/vmlinuz-2.6.30.6 --cmdline 'rw lang=fr_FR kmap=fr-latin1 laptop autologin' --initrd /boot/rootfs.gz --initrd ./myconfig.gz 1.20 +EOT 1.21 +exit 1 1.22 +} 1.23 + 1.24 +KERNEL="" 1.25 +INITRD="" 1.26 +CMDLINE="" 1.27 +PREFIX="floppy" 1.28 +FORMAT="1440" 1.29 +while [ -n "$1" ]; do 1.30 + case "$1" in 1.31 + --cmdline) CMDLINE="$2"; shift;; 1.32 + --initrd) INITRD="$INITRD $2"; shift;; 1.33 + --prefix) PREFIX="$2"; shift;; 1.34 + --format) FORMAT="$2"; shift;; 1.35 + *) KERNEL="$1";; 1.36 + esac 1.37 + shift 1.38 +done 1.39 +[ -n "$KERNEL" -a -f "$KERNEL" ] || usage 1.40 + 1.41 +# write a 32 bits data 1.42 +# usage: storelong offset data32 file 1.43 +storelong() 1.44 +{ 1.45 + printf "00000 %02X %02X %02X %02X \n" \ 1.46 + $(( $2 & 255 )) $(( ($2>>8) & 255 )) \ 1.47 + $(( ($2>>16) & 255 )) $(( ($2>>24) & 255 )) | \ 1.48 + hexdump -R | dd bs=1 conv=notrunc of=$3 seek=$(( $1 )) 2> /dev/null 1.49 +} 1.50 + 1.51 +# read a 32 bits data 1.52 +# usage: getlong offset file 1.53 +getlong() 1.54 +{ 1.55 + dd if=$2 bs=1 skip=$(( $1 )) count=4 2> /dev/null | \ 1.56 + hexdump -e '"" 1/4 "%d" "\n"' 1.57 +} 1.58 + 1.59 +floppyset() 1.60 +{ 1.61 + # bzImage offsets 1.62 + SetupSzOfs=497 1.63 + SyssizeOfs=500 1.64 + CodeAdrOfs=0x214 1.65 + RamfsAdrOfs=0x218 1.66 + RamfsLenOfs=0x21C 1.67 + ArgPtrOfs=0x228 1.68 + 1.69 + # boot+setup address 1.70 + SetupBase=0x90000 1.71 + 1.72 + stacktop=0x9E00 1.73 + 1.74 + bs=/tmp/bs$$ 1.75 + 1.76 + # Get and patch boot sector 1.77 + dd if=$KERNEL bs=512 count=1 of=$bs 2> /dev/null 1.78 + uudecode <<EOT | dd of=$bs conv=notrunc 2> /dev/null 1.79 +begin-base64 644 - 1.80 +v/Sd/GgAkAcxyQYXify7eACO2cU3sQbzpY7ZiSeMRwKg8X2YQAYfxkX4P/qX 1.81 +mEEw9jHb6FcBvgACgEwRgMdEJACcA3QO6GYBvigCORxyLkeLHFboQQFfizXo 1.82 +UgGwIOg+AbAIzRBOmM0WPAh0BZiJBEZGOzV08OgmATwKdd+5GABqAOL8ieaw 1.83 +D7/0Af5NHLEFtJOJRBywAYlEFJmJVBCJVBhmMdtD0+NLZgMdZtPraAAQB7+A 1.84 +ACn7nHMCAd9TVjHb6NQAXrkAgLSH/kQczRVbnXfcoRoCSL8cArEJOEQccrAx 1.85 +wM0T6gAAIJCwRijIvrkB6L0AXesjgPkTcgQ4wXdogP4CcgQ45ndpgP1Qc3Ng 1.86 +BlJRU5a0AlC5BgBRsQTBxQSwDyHoBJAnFEAn6HMA4u6wIM0QWeK0mM0TYTH2 1.87 +rZGtkq1QKMh3ArABmDn4cgKJ+FBStALNE1qVXlhynCn3AfHB5gkB8zjBdSaI 1.88 +yP7GsQE45nUciPS2AP7FPBN1EoD9UHINtQBgvrwB6CUAmM0WYaMEAFJRZo8G 1.89 +AAAJ/3WeFgewLrQOuwcAzRA8DXUOsArr8bAN6Oz/rAjAdfjDWDoASW5zZXJ0 1.90 +IG5leHQgZmxvcHB5IGFuZCBwcmVzcyBhbnkga2V5IHRvIGNvbnRpbnVlLgcN 1.91 +AA== 1.92 +==== 1.93 +EOT 1.94 + 1.95 + # Get setup 1.96 + setupsz=$(getlong $SetupSzOfs $bs) 1.97 + setupszb=$(( $setupsz & 255 )) 1.98 + dd if=$KERNEL bs=512 skip=1 count=$setupszb 2> /dev/null >> $bs 1.99 + 1.100 + # Store cmdline after setup 1.101 + if [ -n "$CMDLINE" ]; then 1.102 + echo -n "$CMDLINE" | dd bs=512 count=1 conv=sync 2> /dev/null >> $bs 1.103 + storelong ArgPtrOfs $(( $SetupBase + $stacktop )) $bs 1.104 + fi 1.105 + 1.106 + # Compute initramfs size 1.107 + initrdlen=0 1.108 + padding=0 1.109 + for i in $( echo $INITRD | sed 's/,/ /' ); do 1.110 + [ -s "$i" ] || continue 1.111 + initrdlen=$(( $initrdlen + $padding )) 1.112 + padding=$(stat -c %s $i) 1.113 + initrdlen=$(( $initrdlen + $padding )) 1.114 + padding=$(( 4096 - ($padding & 4095) )) 1.115 + [ $padding -eq 4096 ] && padding=0 1.116 + done 1.117 + Ksize=$(( $(getlong $SyssizeOfs $bs)*16 )) 1.118 + Kpad=$(( (($Ksize+4095)/4096)*4096 - Ksize )) 1.119 + if [ $initrdlen -ne 0 ]; then 1.120 + Kbase=$(getlong $CodeAdrOfs $bs) 1.121 + storelong $RamfsAdrOfs \ 1.122 + $(( (0x1000000 - $initrdlen) & 0xFFFF0000 )) $bs 1.123 + storelong $RamfsLenOfs $initrdlen $bs 1.124 + fi 1.125 + 1.126 + # Output boot sector + setup + cmdline 1.127 + dd if=$bs 2> /dev/null 1.128 + 1.129 + # Output kernel code 1.130 + dd if=$KERNEL bs=512 skip=$(( $setupszb + 1 )) 2> /dev/null 1.131 + 1.132 + # Pad to next sector 1.133 + Kpad=$(( 512 - ($(stat -c %s $KERNEL) & 511) )) 1.134 + [ $Kpad -eq 512 ] || dd if=/dev/zero bs=1 count=$Kpad 2> /dev/null 1.135 + 1.136 + # Output initramfs 1.137 + padding=0 1.138 + for i in $( echo $INITRD | sed 's/,/ /' ); do 1.139 + [ -s "$i" ] || continue 1.140 + [ $padding -ne 0 ] && dd if=/dev/zero bs=1 count=$padding 1.141 + dd if=$i 2> /dev/null 1.142 + padding=$(( 4096 - ($(stat -c %s $i) & 4095) )) 1.143 + [ $padding -eq 4096 ] && padding=0 1.144 + done 1.145 + 1.146 + # Cleanup 1.147 + rm -f $bs 1.148 +} 1.149 + 1.150 +floppyset | split -b ${FORMAT}k /dev/stdin floppy$$ 1.151 +i=1 1.152 +ls floppy$$* | while read file ; do 1.153 + output=$PREFIX.$(printf "%03d" $i) 1.154 + cat $file /dev/zero | dd bs=1k count=$FORMAT conv=sync of=$output 2> /dev/null 1.155 + echo $output 1.156 + rm -f $file 1.157 + i=$(( $i + 1 )) 1.158 +done