wok-6.x rev 12557

linux: update bootloader.sh
author Pascal Bellard <pascal.bellard@slitaz.org>
date Sat Apr 28 13:25:47 2012 +0200 (2012-04-28)
parents 66e38bd6a132
children 873a0ed5aab7
files linux/stuff/bootloader.sh
line diff
     1.1 --- a/linux/stuff/bootloader.sh	Sat Apr 28 13:23:21 2012 +0200
     1.2 +++ b/linux/stuff/bootloader.sh	Sat Apr 28 13:25:47 2012 +0200
     1.3 @@ -9,218 +9,260 @@
     1.4  usage()
     1.5  {
     1.6  cat <<EOT
     1.7 -Usage: $0 bzImage [--prefix image_prefix] [--cmdline 'args']
     1.8 +Usage: $0 bzImage [--prefix image_prefix]
     1.9 +       [--format 1200|1440|1680|1920|2880|... ] [--mem mb]
    1.10         [--rdev device] [--video mode] [--flags rootflags] [--tracks cnt]
    1.11 -       [--format 1440|1680|1920|2880 ] [--initrd initrdfile]...
    1.12 +       [--cmdline 'args'] [--dont-edit-cmdline] [--no-syssize-fix]
    1.13 +       [--address-initrd address] [--initrd initrdfile]...
    1.14  
    1.15 -Default values: --format 1440 --tracks 80 --prefix floppy.
    1.16 -
    1.17 -Or:	cat fd0*.img | $0 --extract
    1.18 -
    1.19 -Create the kernel, cmdline and rootfs files from a floppy set
    1.20 +Default values: --format 1440 --tracks 80 --rdev /dev/fd0 --prefix floppy. --mem 16
    1.21  
    1.22  Example:
    1.23 -$0 /boot/vmlinuz-2.6.30.6 --rdev /dev/ram0 --video -3 \
    1.24 ---cmdline 'rw lang=fr_FR kmap=fr-latin1 laptop autologin' \
    1.25 ---initrd /boot/rootfs.gz --initrd ./myconfig.gz
    1.26 +$0 /boot/bzImage --rdev /dev/ram0 --video -3 --cmdline 'rw lang=fr_FR kmap=fr-latin1 laptop autologin' --initrd /boot/rootfs.gz --initrd ./myconfig.gz
    1.27  EOT
    1.28  exit 1
    1.29  }
    1.30  
    1.31 -ddq()
    1.32 +KERNEL=""
    1.33 +INITRD=""
    1.34 +ADRSRD=""
    1.35 +CMDLINE=""
    1.36 +PREFIX="floppy."
    1.37 +FORMAT="1440"
    1.38 +RDEV=""
    1.39 +VIDEO=""
    1.40 +FLAGS=""
    1.41 +TRACKS="80"
    1.42 +MEM="16"
    1.43 +NOEDIT=""
    1.44 +NOSYSSIZEFIX=""
    1.45 +DEBUG=""
    1.46 +while [ -n "$1" ]; do
    1.47 +	case "${1/--/-}" in
    1.48 +	-c*) CMDLINE="$2"; shift;;
    1.49 +	-i*) INITRD="$INITRD $2"; shift;;
    1.50 +	-a*) ADRSRD="$2"; shift;;
    1.51 +	-h*) HEAP="$2"; shift;;
    1.52 +	-l*) LOADERTYPE="$2"; shift;;
    1.53 +	-p*) PREFIX="$2"; shift;;
    1.54 +	-fl*)FLAGS="$2"; shift;;	# 1 read-only, 0 read-write
    1.55 +	-f*) FORMAT="$2"; shift;;
    1.56 +	-m*) MEM="$(echo $2 | sed 's/[^0-9]//g')"; shift;;
    1.57 +	-r*) RDEV="$2"; shift;;
    1.58 +	-v*) VIDEO="$2"; shift;;	# -3 .. n
    1.59 +	-t*) TRACKS="$2"; shift;; # likely 81 .. 84
    1.60 +	-n*) NOSYSSIZEFIX="1";;
    1.61 +	-debug) DEBUG="1";;
    1.62 +	-d*) NOEDIT="1";;
    1.63 +	*) KERNEL="$1";;
    1.64 +	esac
    1.65 +	shift
    1.66 +done
    1.67 +[ -n "$KERNEL" -a -f "$KERNEL" ] || usage
    1.68 +while [ -L "$KERNEL" ]; do KERNEL="$(readlink "$KERNEL")"; done
    1.69 +if [ $(( $FORMAT % $TRACKS )) -ne 0 ]; then
    1.70 +	echo "Invalid track count for format $FORMAT."
    1.71 +	usage
    1.72 +fi
    1.73 +[ 0$MEM -lt 4  ] && MEM=4
    1.74 +[ $MEM -gt 16 ] && MEM=16
    1.75 +
    1.76 +ddq() { dd $@ 2> /dev/null; }
    1.77 +
    1.78 +patch()
    1.79  {
    1.80 -	dd $@ 2> /dev/null
    1.81 +	echo -en $(echo ":$2" | sed 's/:/\\x/g') | \
    1.82 +		ddq bs=1 conv=notrunc of=$3 seek=$((0x$1))
    1.83 +	[ -n "$DEBUG" ] && echo "patch $1 $2		$4" 1>&2
    1.84  }
    1.85  
    1.86 -dbg()
    1.87 +# usage: store bits offset data file
    1.88 +store()
    1.89  {
    1.90 -	[ -n "$DEBUG" ] && echo "$@" 1>&2
    1.91 +	n=$3; for i in $(seq 8 8 $1); do
    1.92 +		printf '\\\\x%02X' $(($n & 255))
    1.93 +		n=$(($n >> 8))
    1.94 +	done | xargs echo -en | ddq bs=1 conv=notrunc of=$4 seek=$(($2))
    1.95 +	[ -n "$DEBUG" ] && printf "store%d(%03X) = %0$(($1/4))X	%s\n" $1 $2 $3 "$5" 1>&2
    1.96  }
    1.97  
    1.98 -# write a 32 bits data
    1.99 -# usage: put offset data32 file [bytes]
   1.100 -put()
   1.101 +# usage: getlong offset file
   1.102 +getlong()
   1.103  {
   1.104 -	n=$2; for i in $(seq 1 ${4:-4}); do
   1.105 -		printf '\\\\x%02X' $(($n & 255))
   1.106 -		n=$(($n >> 8))
   1.107 -	done | xargs echo -en | ddq bs=1 conv=notrunc of=$3 seek=$1
   1.108 -	[ -n "$DEBUG" ] && printf "put$4(%04X) = %X\n" $1 $2 1>&2
   1.109 +	ddq if=$2 bs=1 skip=$(($1)) count=4 | hexdump -e '"" 1/4 "%d" "\n"'
   1.110  }
   1.111  
   1.112 -# read a 32 bits data
   1.113 -# usage: get offset file [bytes]
   1.114 -get()
   1.115 +error()
   1.116  {
   1.117 -	ddq if=$2 bs=1 skip=$(($1)) count=${3:-4} | hexdump -e '"" 1/4 "%d"'
   1.118 +	echo $@ 1>&2
   1.119 +	rm -f $bs
   1.120 +	exit 1
   1.121  }
   1.122  
   1.123 -SetupSzOfs=0x1F1
   1.124 -SyssizeOfs=0x1F4
   1.125 -RamfsLenOfs=0x21C
   1.126 -ArgPtrOfs=0x228
   1.127 -
   1.128  floppyset()
   1.129  {
   1.130  	# bzImage offsets
   1.131 -	CylinderCount=0x1F0
   1.132 -	FlagsOfs=0x1F2
   1.133 -	VideoModeOfs=0x1FA
   1.134 -	RootDevOfs=0x1FC
   1.135 -	CodeAdrOfs=0x214
   1.136 +	SetupSzOfs=497
   1.137 +	FlagsOfs=498
   1.138 +	VideoModeOfs=506
   1.139 +	RootDevOfs=508
   1.140 +	Magic=0x202
   1.141  	RamfsAdrOfs=0x218
   1.142 +	RamfsLenOfs=0x21C
   1.143  
   1.144  	# boot+setup address
   1.145  	SetupBase=0x90000
   1.146  
   1.147 -	stacktop=0x9E00
   1.148 -
   1.149  	bs=/tmp/bs$$
   1.150  
   1.151  	# Get and patch boot sector
   1.152 -	# See  http://hg.slitaz.org/wok/raw-file/711d076b277c/linux/stuff/linux-header-2.6.34.u
   1.153 +	# See http://hg.slitaz.org/wok/file/66e38bd6a132/linux/stuff/linux-header.u
   1.154 +	[ -n "$DEBUG" ] && echo "Read bootsector..." 1>&2
   1.155  	ddq if=$KERNEL bs=512 count=1 of=$bs
   1.156 +
   1.157 +	[ $(( $(getlong 0x1FE $bs) & 0xFFFF )) -eq 43605 ] ||
   1.158 +		error "Not bootable"
   1.159 +	
   1.160  	uudecode <<EOT | ddq of=$bs conv=notrunc
   1.161  begin-base64 644 -
   1.162 -/L+6nWgAkAcGF4n8McC5HQDzq1sfD6mg8X1ABlfFd3ixBvOlZWaPR3gGH8ZF
   1.163 -+D/6l1hB6DQBvgACA3QO6HYBWwseKAJ0LFNH6AoBXuhmAbAgzRCwCM0QTuhl
   1.164 -ATwIdAOIBK05NigCdPDoPgE8CnXgiHz+ieb/TBD/TBi/9AGBTRz/gMdFMACc
   1.165 -sBCxBUi0k4lEHLABiUQUmGaY0+BIZgMFZtPoaAAQB7+AACn4nHMCAccx21BW
   1.166 -6J4AXrkAgLSH/kQczRVYnXfcoRoCvxwCsQk4RBxyuJPNE+oAACCQsEYoyL7b
   1.167 -AejSAF3rI4D5E3IEOMF3a4D+AnIEOOZ3bGCB/QAGdCoGUlFTlrQCULEGtQTB
   1.168 -xQSwDyHoBJAnFEAn6IwA/s117LAgzRDitOiWAJjNE2FSUCjIdwKwAZg5+HIC
   1.169 -ifhQtALNE5VeWFpyoJVBjuGAxwJPdFFOdfSM4ZU4wXVFiMj+xrEBOOZ1O4j0
   1.170 -/sW2AID9UHIwOi7wAXIqtQBgvt4B/kQMU+gxAFvoOAB1FlKYzRO4AQLNE1rQ
   1.171 -1Dpk/nXqRgjkdeVh64sWB7AxLAO0DrsHAM0QPA1088OwDejv/6wIwHX4w79s
   1.172 -BLFbZQINuA0BZToNdArNFnT0mM0Wju9Hw1g6AEluc2VydCBkaXNrIDEuBw0A
   1.173 -AA==
   1.174 +/L+4nWgAkBeJ/BYHMcC5HgDzq1sfD6Gg8X1AxXd4BlexBvOlFh9kZo9HeMZF
   1.175 ++D/6l1hB6DwBvgACgUwQIIDGRCWbA3QO6GoBWwseKAJ0LFNH6AYBXuhaAbAg
   1.176 +zRCwCM0QTuhZATwIdAOIBK05NigCdPDoMgE8CnXgiHz+W4nm/0gQxkAVk4Dz
   1.177 +CHX0u/QBoRUCsQVmix9mS2bT60NoAAgHv4AAiXwTiUQbAfjR7yn7nHMCAd9Q
   1.178 +V1ZTMdvongBbXlmGzbSHFgfNFVidd9ChGQK7HAKxCTlEG3K6l80T6gAAIJCw
   1.179 +RijIvtgB6MoAXesjgPkTcgQ4wXdrgP4CcgQ45ndsYIH9AAZ0KgZSUVOWtAJQ
   1.180 +sQa1BMHFBLAPIegEkCcUQCfohAD+zXXssCDNEOK06I4AmM0TYVJQKMh3ArAB
   1.181 +mDn4cgKJ+FC0As0TlV5YWnKglUGO6YDHAk90S0519IzplTjBdT+IyP7GsQE4
   1.182 +5nU1iPT+xYD9ULYAdSq1AGC+2wH+RAxT6C8AW+g2AHUWUpjNE7gBAs0TWtDU
   1.183 +OmT+depGCOR15WHrkbAxLAO0DrsHAM0QPA1088OwDejv/6wIwHX4w79sBLFb
   1.184 +ZAINuA0BZDoNdArNFnT0mM0WjudHw1g6AEluc2VydCBkaXNrIDEHDQA=
   1.185  ====
   1.186  EOT
   1.187 -
   1.188  	# Get setup
   1.189 -	setupsz=$(get $SetupSzOfs $bs 1)
   1.190 +	setupsz=$(( $(getlong $SetupSzOfs $bs) & 0xFF ))
   1.191 +	if [ $setupsz -eq 0 ]; then
   1.192 +		setupsz=4
   1.193 +		store 8 $SetupSzOfs $setupsz $bs "setup size $setupsz"
   1.194 +	fi
   1.195 +	[ -n "$DEBUG" ] && echo "Read setup ($setupsz sectors) ..." 1>&2
   1.196  	ddq if=$KERNEL bs=512 skip=1 count=$setupsz >> $bs
   1.197  
   1.198 -	if [ -n "$TRACKS" ]; then
   1.199 -		dbg -n "--tracks "
   1.200 -		put $CylinderCount $TRACKS $bs 1
   1.201 +	Version=$(( $(getlong 0x206 $bs) & 0xFFFF ))
   1.202 +	[ $(getlong $Magic $bs) -ne 1400005704 ] && Version=0
   1.203 +	feature=""
   1.204 +	while read prot kern info ; do
   1.205 +		[ $Version -lt $((0x$prot)) ] && continue
   1.206 +		feature="features $prot starting from kernel $kern "
   1.207 +	done <<EOT
   1.208 +200	1.3.73	kernel_version, bzImage, initrd, loadflags/type_of_loader
   1.209 +201	1.3.76	heap_end_ptr
   1.210 +202	2.4.0	new cmdline
   1.211 +204	2.6.14	long syssize
   1.212 +EOT
   1.213 +	[ -n "$DEBUG" ] && printf "Protocol %X $feature\n" $Version 1>&2
   1.214 +	
   1.215 +	# Old kernels need bootsector patches to disable rescent features
   1.216 +	while read minversion maxversion offset bytes rem; do
   1.217 +		[ $Version -gt $(( 0x$maxversion )) ] && continue
   1.218 +		[ $Version -lt $(( 0x$minversion )) ] && continue
   1.219 +		patch $offset $bytes $bs "$rem"
   1.220 +	done <<EOT
   1.221 +000 1FF 08D	B8:00:01			force zImage (movw \$0x100, %ax)
   1.222 +000 1FF 0CB	EB:0B				skip initrd code 
   1.223 +000 201	01E	EB:1E:00:00:00:00		room for the cmdline magic
   1.224 +000 201	036	BE:00:00:E8:76:01:EB:0A:06:57:B1:06:F3:A5:EB:DE	code in cmdline magic moved
   1.225 +000 1FF 039	90:90:90			no kernel version
   1.226 +000 201 04B	22:00				old cmdline ptr 1
   1.227 +000 201 06D	22:00				old cmdline ptr 2
   1.228 +000 203 1F6	00:00 				syssize32
   1.229 +200 FFF	210	FF				type_of_loader=FF
   1.230 +201 FFF 224	00:9B				heap_end_ptr
   1.231 +EOT
   1.232 +	if [ $Version -lt 514 ]; then
   1.233 +		version_string=$((0x200 + ($(getlong 0x20E $bs) & 65535) ))
   1.234 +		store	16	0x0037	$version_string	$bs version_string
   1.235  	fi
   1.236 -	if [ -n "$FLAGS" ]; then
   1.237 -		dbg -n "--flags "
   1.238 -		put $FlagsOfs $FLAGS $bs 2
   1.239 +	if [ $Version -ge 512 -a $(getlong 0x214 $bs) -ge $((0x100000)) ]; then 
   1.240 +		patch	211	81	$bs	loadflags=can_use_heap+loadhigh
   1.241 +		patch	09D	10	$bs	LOADSEG=0x1000
   1.242 +		patch	0A0	00:01	$bs	LOADSZ=0x10000
   1.243  	fi
   1.244 -	if [ -n "$VIDEO" ]; then
   1.245 -		dbg -n "--video "
   1.246 -		put $VideoModeOfs $VIDEO $bs 2
   1.247 -	fi
   1.248 -	if [ -n "$RDEV" ]; then
   1.249 -		dbg -n "--rdev "
   1.250 -		n=$(stat -c '0x%02t%02T' $RDEV 2> /dev/null)
   1.251 -		[ -n "$n" ] || n=$RDEV
   1.252 -		put $RootDevOfs $n $bs 2
   1.253 +	[ -n "$CMDLINE" ] || patch 04D EB $bs "No cmdline"
   1.254 +	[ -n "$NOEDIT" ] && patch 059 0D:46:EB:14 $bs 'mov CR,%al ; inc %si; jmp putal'
   1.255 +	[ 1$TRACKS -ne 180 ] &&	store	8	0x171		$TRACKS $bs TRACKS
   1.256 +	
   1.257 +	[ -n "$FLAGS" ] &&	store	16	$FlagsOfs	$FLAGS $bs FLAGS
   1.258 +	[ -n "$VIDEO" ] &&	store	16	$VideoModeOfs	$VIDEO $bs VIDEO
   1.259 +	[ -n "$RDEV" ] || case "$FORMAT" in
   1.260 +		1200)	RDEV=0x0208 ;;
   1.261 +		1440)	RDEV=0x021C ;;
   1.262 +		2880)	RDEV=0x0220 ;;
   1.263 +		*)	RDEV=0x0200 ;;
   1.264 +	esac
   1.265 +	while [ -L "$RDEV" ]; do RDEV="$(readlink "$RDEV")"; done
   1.266 +	[ -b "$RDEV" ] && RDEV=$(stat -c '0x%02t%02T' $RDEV 2> /dev/null)
   1.267 +	store 16 $RootDevOfs $RDEV $bs RDEV
   1.268 +	
   1.269 +	# Store cmdline after setup
   1.270 +	if [ -n "$CMDLINE" ]; then
   1.271 +		echo -n "$CMDLINE" | ddq bs=512 count=1 conv=sync >> $bs
   1.272 +		CmdlineOfs=0x9E00	# Should be in 0x8000 .. 0xA000
   1.273 +		ArgPtrOfs=0x228
   1.274 +		ArgPtrVal=$(( $SetupBase + $CmdlineOfs ))
   1.275 +		if [ $Version -lt 514 ]; then
   1.276 +			ArgPtrOfs=0x0020
   1.277 +			ArgPtrVal=$(( 0xA33F + ($CmdlineOfs << 16) ))
   1.278 +		fi
   1.279 +		store 32 $ArgPtrOfs $ArgPtrVal $bs "Cmdline '$CMDLINE'"
   1.280  	fi
   1.281  
   1.282 -	# Store cmdline after setup
   1.283 -	if [ -n "$CMDLINE" ]; then
   1.284 -		dbg -n "--cmdline '$CMDLINE' "
   1.285 -		echo -n "$CMDLINE" | ddq bs=512 count=1 conv=sync >> $bs
   1.286 -		put $ArgPtrOfs $(( $SetupBase + $stacktop )) $bs
   1.287 -	fi
   1.288 -
   1.289 -	# Compute initramfs size
   1.290 +	# Compute initramfs size (protocol >= 2.00)
   1.291 +	[ $Version -lt 512 ] && INITRD=""
   1.292  	initrdlen=0
   1.293 -	padding=0
   1.294 +INITRDPAD=4
   1.295 +INITRDALIGN=0x1000
   1.296  	for i in $( echo $INITRD | sed 's/,/ /' ); do
   1.297  		[ -s "$i" ] || continue
   1.298 -		dbg "--initrd $i "
   1.299 -		initrdlen=$(( $initrdlen + $padding ))
   1.300 -		padding=$(stat -c %s $i)
   1.301 -		initrdlen=$(( $initrdlen + $padding ))
   1.302 -		padding=$(( 4096 - ($padding & 4095) ))
   1.303 -		[ $padding -eq 4096 ] && padding=0
   1.304 +		while [ -L "$i" ]; do i="$(readlink $i)"; done
   1.305 +		size=$(( ($(stat -c %s "$i") + $INITRDPAD - 1) & -$INITRDPAD ))
   1.306 +		[ -n "$DEBUG" ] && echo "initrd $i $size " 1>&2
   1.307 +		initrdlen=$(( $initrdlen + $size ))
   1.308 +		[ -n "$ADRSRD" ] || ADRSRD=$(( (($MEM * 0x100000) - $initrdlen) & -$INITRDALIGN ))
   1.309 +		store 32 $RamfsAdrOfs $(( $ADRSRD )) $bs initrd adrs
   1.310 +		store 32 $RamfsLenOfs $initrdlen $bs initrdlen
   1.311  	done
   1.312 -	Ksize=$(( $(get $SyssizeOfs $bs)*16 ))
   1.313 -	Kpad=$(( (($Ksize+4095)/4096)*4096 - Ksize ))
   1.314 -	if [ $initrdlen -ne 0 ]; then
   1.315 -		dbg "initrdlen = $initrdlen "
   1.316 -		Kbase=$(get $CodeAdrOfs $bs)
   1.317 -		put $RamfsAdrOfs \
   1.318 -			$(( (0x1000000 - $initrdlen) & 0xFFFF0000 )) $bs
   1.319 -		put $RamfsLenOfs $(( ($initrdlen + 3) & -4 )) $bs
   1.320 -	fi
   1.321 +
   1.322 +	[ -n "$NOSYSSIZEFIX" ] || store 32 0x1F4 \
   1.323 +		$(( ($(stat -c %s $KERNEL)+15)/16 - ($setupsz+1)*32)) $bs fix system size
   1.324  
   1.325  	# Output boot sector + setup + cmdline
   1.326  	ddq if=$bs
   1.327  
   1.328  	# Output kernel code
   1.329 -	ddq if=$KERNEL bs=512 skip=$(( $setupsz + 1 ))
   1.330 -
   1.331 -	# Pad to next sector
   1.332 -	Kpad=$(( 512 - ($(stat -c %s $KERNEL) & 511) ))
   1.333 -	[ $Kpad -eq 512 ] || ddq if=/dev/zero bs=1 count=$Kpad
   1.334 +	syssz=$(( ($(getlong 0x1F4 $bs)+31)/32 ))
   1.335 +	cat $KERNEL /dev/zero | ddq bs=512 skip=$(( $setupsz+1 )) count=$syssz
   1.336  
   1.337  	# Output initramfs
   1.338 -	padding=0
   1.339  	for i in $( echo $INITRD | sed 's/,/ /' ); do
   1.340  		[ -s "$i" ] || continue
   1.341 -		[ $padding -ne 0 ] && ddq if=/dev/zero bs=1 count=$padding
   1.342  		ddq if=$i
   1.343 -		padding=$(( 4 - ($(stat -c %s $i) & 3) ))
   1.344 -		[ $padding -eq 4 ] && padding=0
   1.345 +		padding=$(( $INITRDPAD - ($(stat -c %s $i) % $INITRDPAD) ))
   1.346 +		[ $padding -eq $INITRDPAD ] || ddq if=/dev/zero bs=1 count=$padding
   1.347  	done
   1.348  
   1.349  	# Cleanup
   1.350  	rm -f $bs
   1.351  }
   1.352  
   1.353 -KERNEL=""
   1.354 -INITRD=""
   1.355 -CMDLINE=""
   1.356 -PREFIX="floppy."
   1.357 -FORMAT="1440"
   1.358 -RDEV=""
   1.359 -VIDEO=""
   1.360 -FLAGS=""
   1.361 -TRACKS=""
   1.362 -DEBUG=""
   1.363 -while [ -n "$1" ]; do
   1.364 -	case "${1/--/-}" in
   1.365 -	-c*)	CMDLINE="$2"; shift;;
   1.366 -	-i*)	INITRD="$INITRD $2"; shift;;
   1.367 -	-p*)	PREFIX="$2"; shift;;
   1.368 -	-fl*)	FLAGS="$2"; shift;;	# 1 read-only, 0 read-write
   1.369 -	-f*)	FORMAT="$2"; shift;;
   1.370 -	-r*)	RDEV="$2"; shift;;	# /dev/???
   1.371 -	-v*)	VIDEO="$2"; shift;;	# -3 .. n
   1.372 -	-t*)	TRACKS="$2"; shift;; 	# likely 81 .. 84
   1.373 -	-d*)	DEBUG="1";;
   1.374 -	-e*)	ddq bs=512 count=2 > kernel
   1.375 -		setupsz=$(get $SetupSzOfs kernel 1)
   1.376 -		ddq bs=512 count=$(($setupsz - 1)) >> kernel
   1.377 -		[ $(get $ArgPtrOfs kernel) -ne 0 ] && 
   1.378 -			ddq bs=512 count=1 | strings > cmdline
   1.379 -		syssz=$(get $SyssizeOfs kernel)
   1.380 -		ddq bs=512 count=$(( ($syssz + 31) / 32 )) >> kernel
   1.381 -		ddq bs=16 seek=$(($syssz + 32 + $setupsz*32)) count=0 of=kernel
   1.382 -		ramsz=$(get $RamfsLenOfs kernel)
   1.383 -		ddq bs=512 count=$((($ramsz + 511) / 512)) of=rootfs
   1.384 -		ddq bs=1 seek=$ramsz count=0 of=rootfs
   1.385 -		exit ;;
   1.386 -	*) KERNEL="$1";;
   1.387 -	esac
   1.388 -	shift
   1.389 -done
   1.390 -[ -n "$KERNEL" -a -f "$KERNEL" ] || usage
   1.391 -[ -n "$TRACKS" ] && [ $(( $FORMAT % $TRACKS )) -ne 0 ] &&
   1.392 -	echo "Invalid track count for format $FORMAT." && usage
   1.393 -
   1.394  if [ "$FORMAT" == "0" ]; then # unsplitted
   1.395  	floppyset > $PREFIX
   1.396 +	PAD=$(( 512 - ($(stat -c %s $PREFIX) % 512) ))
   1.397 +	[ $PAD -ne 512 ] && ddq if=/dev/zero bs=1 count=$PAD >> $PREFIX
   1.398  	exit
   1.399  fi
   1.400  floppyset | split -b ${FORMAT}k /dev/stdin floppy$$
   1.401  i=1
   1.402 -ls floppy$$* | while read file ; do
   1.403 +ls floppy$$* 2> /dev/null | while read file ; do
   1.404  	output=$PREFIX$(printf "%03d" $i)
   1.405  	cat $file /dev/zero | ddq bs=1k count=$FORMAT conv=sync of=$output
   1.406  	echo $output