slitaz-dev-tools diff mirror-tools/var/www/slitaz/mirror/floppies/builder/bootloader @ rev 5
Add /var/www/mirror-info/mirror from mirror-tools stuff.
author | Christopher Rogers <slaxemulator@gmail.com> |
---|---|
date | Thu Feb 24 01:29:50 2011 +0000 (2011-02-24) |
parents | |
children |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/mirror-tools/var/www/slitaz/mirror/floppies/builder/bootloader Thu Feb 24 01:29:50 2011 +0000 1.3 @@ -0,0 +1,211 @@ 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 + [--rdev device] [--video mode] [--flags rootflags] [--tracks cnt] 1.17 + [--format 1440|1680|1920|2880 ] [--initrd initrdfile]... 1.18 + 1.19 +Default values: --format 1440 --tracks 80 --prefix floppy. 1.20 + 1.21 +Example: 1.22 +$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 1.23 +EOT 1.24 +exit 1 1.25 +} 1.26 + 1.27 +KERNEL="" 1.28 +INITRD="" 1.29 +CMDLINE="" 1.30 +PREFIX="floppy." 1.31 +FORMAT="1440" 1.32 +RDEV="" 1.33 +VIDEO="" 1.34 +FLAGS="" 1.35 +TRACKS="" 1.36 +DEBUG="" 1.37 +while [ -n "$1" ]; do 1.38 + case "$1" in 1.39 + --c*|-c*) CMDLINE="$2"; shift;; 1.40 + --i*|-i*) INITRD="$INITRD $2"; shift;; 1.41 + --p*|-p*) PREFIX="$2"; shift;; 1.42 + --fo*|-f*) FORMAT="$2"; shift;; 1.43 + --fl*) FLAGS="$2"; shift;; # 1 read-only, 0 read-write 1.44 + --r*|-r*) RDEV="$2"; shift;; # /dev/??? 1.45 + --v*|-v*) VIDEO="$2"; shift;; # -3 .. n 1.46 + --t*|-t*) TRACKS="$2"; shift;; # likely 81 .. 84 1.47 + --debug) DEBUG="1";; 1.48 + *) KERNEL="$1";; 1.49 + esac 1.50 + shift 1.51 +done 1.52 +[ -n "$KERNEL" -a -f "$KERNEL" ] || usage 1.53 +if [ -n "$TRACKS" ]; then 1.54 + if [ $(( $FORMAT % $TRACKS )) -ne 0 ]; then 1.55 + echo "Invalid track count for format $FORMAT." 1.56 + usage 1.57 + fi 1.58 +fi 1.59 + 1.60 +# write a 16 bits data 1.61 +# usage: store16 offset data16 file 1.62 +store16() 1.63 +{ 1.64 + echo $(( $2 + 0x10000 )) | \ 1.65 + awk '{ printf "\\\\x%02X\\\\x%02X",$1%256,($1/256)%256 }' | \ 1.66 + xargs echo -en | \ 1.67 + dd bs=2 conv=notrunc of=$3 seek=$(( $1 / 2 )) 2> /dev/null 1.68 + [ -n "$DEBUG" ] && printf "store16(%04X) = %04X\n" $1 $2 1>&2 1.69 +} 1.70 + 1.71 +# write a 32 bits data 1.72 +# usage: storelong offset data32 file 1.73 +storelong() 1.74 +{ 1.75 + echo $2 | awk '{ printf "\\\\x%02X\\\\x%02X\\\\x%02X\\\\x%02X", 1.76 + $1%256,($1/256)%256,($1/256/256)%256,($1/256/256/256)%256 }' | \ 1.77 + xargs echo -en | \ 1.78 + dd bs=4 conv=notrunc of=$3 seek=$(( $1 / 4 )) 2> /dev/null 1.79 + [ -n "$DEBUG" ] && printf "storelong(%04X) = %08X\n" $1 $2 1>&2 1.80 +} 1.81 + 1.82 +# read a 32 bits data 1.83 +# usage: getlong offset file 1.84 +getlong() 1.85 +{ 1.86 + dd if=$2 bs=1 skip=$(( $1 )) count=4 2> /dev/null | \ 1.87 + hexdump -e '"" 1/4 "%d" "\n"' 1.88 +} 1.89 + 1.90 +floppyset() 1.91 +{ 1.92 + # bzImage offsets 1.93 + CylinderCount=496 1.94 + SetupSzOfs=497 1.95 + FlagsOfs=498 1.96 + SyssizeOfs=500 1.97 + VideoModeOfs=506 1.98 + RootDevOfs=508 1.99 + CodeAdrOfs=0x214 1.100 + RamfsAdrOfs=0x218 1.101 + RamfsLenOfs=0x21C 1.102 + ArgPtrOfs=0x228 1.103 + 1.104 + # boot+setup address 1.105 + SetupBase=0x90000 1.106 + 1.107 + stacktop=0x9E00 1.108 + 1.109 + bs=/tmp/bs$$ 1.110 + 1.111 + # Get and patch boot sector 1.112 + # See http://hg.slitaz.org/wok/raw-file/711d076b277c/linux/stuff/linux-header-2.6.34.u 1.113 + dd if=$KERNEL bs=512 count=1 of=$bs 2> /dev/null 1.114 + uudecode <<EOT | dd of=$bs conv=notrunc 2> /dev/null 1.115 +begin-base64 644 - 1.116 +/L+6nWgAkAcGF4n8McC5HQDzq1sfD6mg8X1ABlfFd3ixBvOlZWaPR3gGH8ZF 1.117 ++D/6l1hB6DQBvgACA3QO6HYBWwseKAJ0LFNH6AoBXuhmAbAgzRCwCM0QTuhl 1.118 +ATwIdAOIBK05NigCdPDoPgE8CnXgiHz+ieb/TBD/TBi/9AGBTRz/gMdFMACc 1.119 +sBCxBUi0k4lEHLABiUQUmGaY0+BIZgMFZtPoaAAQB7+AACn4nHMCAccx21BW 1.120 +6J4AXrkAgLSH/kQczRVYnXfcoRoCvxwCsQk4RBxyuJPNE+oAACCQsEYoyL7b 1.121 +AejSAF3rI4D5E3IEOMF3a4D+AnIEOOZ3bGCB/QAGdCoGUlFTlrQCULEGtQTB 1.122 +xQSwDyHoBJAnFEAn6IwA/s117LAgzRDitOiWAJjNE2FSUCjIdwKwAZg5+HIC 1.123 +ifhQtALNE5VeWFpyoJVBjuGAxwJPdFFOdfSM4ZU4wXVFiMj+xrEBOOZ1O4j0 1.124 +/sW2AID9UHIwOi7wAXIqtQBgvt4B/kQMU+gxAFvoOAB1FlKYzRO4AQLNE1rQ 1.125 +1Dpk/nXqRgjkdeVh64sWB7AxLAO0DrsHAM0QPA1088OwDejv/6wIwHX4w79s 1.126 +BLFbZQINuA0BZToNdArNFnT0mM0Wju9Hw1g6AEluc2VydCBkaXNrIDEuBw0A 1.127 +AA== 1.128 +==== 1.129 +EOT 1.130 + 1.131 + # Get setup 1.132 + setupsz=$(getlong $SetupSzOfs $bs) 1.133 + setupszb=$(( $setupsz & 255 )) 1.134 + dd if=$KERNEL bs=512 skip=1 count=$setupszb 2> /dev/null >> $bs 1.135 + 1.136 + if [ -n "$TRACKS" ]; then 1.137 + [ -n "$DEBUG" ] && echo -n "--tracks " 1>&2 1.138 + n=$(getlong $CylinderCount $bs) 1.139 + store16 $CylinderCount $(( ($n & -256) + $TRACKS )) $bs 1.140 + fi 1.141 + if [ -n "$FLAGS" ]; then 1.142 + [ -n "$DEBUG" ] && echo -n "--flags " 1>&2 1.143 + store16 $FlagsOfs $FLAGS $bs 1.144 + fi 1.145 + if [ -n "$VIDEO" ]; then 1.146 + [ -n "$DEBUG" ] && echo -n "--video " 1>&2 1.147 + store16 $VideoModeOfs $VIDEO $bs 1.148 + fi 1.149 + if [ -n "$RDEV" ]; then 1.150 + if [ "$(dirname $RDEV)" == "/dev" -a -b $RDEV ]; then 1.151 + [ -n "$DEBUG" ] && echo -n "--rdev " 1>&2 1.152 + RDEV=$(stat -c '0x%02t%02T' $RDEV 2> /dev/null) 1.153 + store16 $RootDevOfs $RDEV $bs 1.154 + fi 1.155 + fi 1.156 + 1.157 + # Store cmdline after setup 1.158 + if [ -n "$CMDLINE" ]; then 1.159 + [ -n "$DEBUG" ] && echo -n "--cmdline '$CMDLINE' " 1>&2 1.160 + echo -n "$CMDLINE" | dd bs=512 count=1 conv=sync 2> /dev/null >> $bs 1.161 + storelong $ArgPtrOfs $(( $SetupBase + $stacktop )) $bs 1.162 + fi 1.163 + 1.164 + # Compute initramfs size 1.165 + initrdlen=0 1.166 + for i in $( echo $INITRD | sed 's/,/ /' ); do 1.167 + [ -s "$i" ] || continue 1.168 + [ -n "$DEBUG" ] && echo "--initrd $i " 1>&2 1.169 + initrdlen=$(( ($initrdlen + $(stat -c %s $i) + 3) & -4 )) 1.170 + done 1.171 + if [ $initrdlen -ne 0 ]; then 1.172 + [ -n "$DEBUG" ] && echo "initrdlen = $initrdlen " 1>&2 1.173 + storelong $RamfsAdrOfs \ 1.174 + $(( (0x1000000 - $initrdlen) & 0xFFFF0000 )) $bs 1.175 + storelong $RamfsLenOfs $initrdlen $bs 1.176 + fi 1.177 + 1.178 + # Output boot sector + setup + cmdline 1.179 + dd if=$bs 2> /dev/null 1.180 + 1.181 + # Output kernel code 1.182 + dd if=$KERNEL bs=512 skip=$(( $setupszb + 1 )) 2> /dev/null 1.183 + 1.184 + # Pad to next sector 1.185 + Kpad=$(( 512 - ($(stat -c %s $KERNEL) & 511) )) 1.186 + [ $Kpad -eq 512 ] || dd if=/dev/zero bs=1 count=$Kpad 2> /dev/null 1.187 + 1.188 + # Output initramfs 1.189 + padding=0 1.190 + for i in $( echo $INITRD | sed 's/,/ /' ); do 1.191 + [ -s "$i" ] || continue 1.192 + [ $padding -ne 0 ] && dd if=/dev/zero bs=1 count=$padding 2> /dev/null 1.193 + dd if=$i 2> /dev/null 1.194 + padding=$(( 4 - ($(stat -c %s $i) & 3) )) 1.195 + [ $padding -eq 4 ] && padding=0 1.196 + done 1.197 + 1.198 + # Cleanup 1.199 + rm -f $bs 1.200 +} 1.201 + 1.202 +if [ "$FORMAT" == "0" ]; then # unsplitted 1.203 + floppyset > $PREFIX 1.204 + exit 1.205 +fi 1.206 +floppyset | split -b ${FORMAT}k /dev/stdin floppy$$ 1.207 +i=1 1.208 +ls floppy$$* | while read file ; do 1.209 + output=$PREFIX$(printf "%03d" $i) 1.210 + cat $file /dev/zero | dd bs=1k count=$FORMAT conv=sync of=$output 2> /dev/null 1.211 + echo $output 1.212 + rm -f $file 1.213 + i=$(( $i + 1 )) 1.214 +done