wok-4.x rev 6715

linux/bootloader.sh: fix signed 16bits
author Pascal Bellard <pascal.bellard@slitaz.org>
date Thu Oct 14 17:08:12 2010 +0200 (2010-10-14)
parents 3bff7f88b1c8
children 5abda65ec235
files linux/stuff/bootloader.sh
line diff
     1.1 --- a/linux/stuff/bootloader.sh	Thu Oct 14 13:41:19 2010 +0200
     1.2 +++ b/linux/stuff/bootloader.sh	Thu Oct 14 17:08:12 2010 +0200
     1.3 @@ -10,8 +10,10 @@
     1.4  {
     1.5  cat <<EOT
     1.6  Usage: $0 bzImage [--prefix image_prefix] [--cmdline 'args']
     1.7 -       [--rdev device] [--video mode] [--flags rootflags] 
     1.8 -       [--format 1440|1680|1720|2880 ] [--initrd initrdfile]...
     1.9 +       [--rdev device] [--video mode] [--flags rootflags] [--tracks cnt]
    1.10 +       [--format 1440|1680|1920|2880 ] [--initrd initrdfile]...
    1.11 +
    1.12 +Default values: --format 1440 --tracks 80 --prefix floppy.
    1.13  
    1.14  Example:
    1.15  $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.16 @@ -27,6 +29,7 @@
    1.17  RDEV=""
    1.18  VIDEO=""
    1.19  FLAGS=""
    1.20 +TRACKS=""
    1.21  DEBUG=""
    1.22  while [ -n "$1" ]; do
    1.23  	case "$1" in
    1.24 @@ -37,18 +40,26 @@
    1.25  	--fl*)     FLAGS="$2"; shift;;	# 1 read-only, 0 read-write
    1.26  	--r*|-r*)  RDEV="$2"; shift;;	# /dev/???
    1.27  	--v*|-v*)  VIDEO="$2"; shift;;	# -3 .. n
    1.28 +	--t*|-t*)  TRACKS="$2"; shift;; # likely 81 .. 84
    1.29  	--debug)   DEBUG="1";;
    1.30  	*) KERNEL="$1";;
    1.31  	esac
    1.32  	shift
    1.33  done
    1.34  [ -n "$KERNEL" -a -f "$KERNEL" ] || usage
    1.35 +if [ -n "$TRACKS" ]; then
    1.36 +	if [ $(( $FORMAT % $TRACKS )) -ne 0 ]; then
    1.37 +		echo "Invalid track count for format $FORMAT."
    1.38 +		usage
    1.39 +	fi
    1.40 +fi
    1.41  
    1.42  # write a 16 bits data
    1.43  # usage: store16 offset data16 file
    1.44  store16()
    1.45  {
    1.46 -	echo $2 | awk '{ printf "\\\\x%02X\\\\x%02X",$1%256,($1/256)%256 }' | \
    1.47 +	echo $(( $2 + 0x10000 )) | \
    1.48 +		awk '{ printf "\\\\x%02X\\\\x%02X",$1%256,($1/256)%256 }' | \
    1.49  		xargs echo -en | \
    1.50  	dd bs=2 conv=notrunc of=$3 seek=$(( $1 / 2 )) 2> /dev/null
    1.51  	[ -n "$DEBUG" ] && printf "store16(%04X) = %04X\n" $1 $2 1>&2
    1.52 @@ -76,6 +87,7 @@
    1.53  floppyset()
    1.54  {
    1.55  	# bzImage offsets
    1.56 +	CylinderCount=496
    1.57  	SetupSzOfs=497
    1.58  	FlagsOfs=498
    1.59  	SyssizeOfs=500
    1.60 @@ -118,19 +130,24 @@
    1.61  	setupszb=$(( $setupsz & 255 ))
    1.62  	dd if=$KERNEL bs=512 skip=1 count=$setupszb 2> /dev/null >> $bs
    1.63  
    1.64 +	if [ -n "$TRACKS" ]; then
    1.65 +		[ -n "$DEBUG" ] && echo -n "--tracks " 1>&2
    1.66 +		n=$(getlong $CylinderCount $bs)
    1.67 +		store16 $CylinderCount $(( ($n & -256) + $TRACKS )) $bs
    1.68 +	fi
    1.69  	if [ -n "$FLAGS" ]; then
    1.70  		[ -n "$DEBUG" ] && echo -n "--flags " 1>&2
    1.71 -		store16 $FlagsOfs $(( $FLAGS )) $bs
    1.72 +		store16 $FlagsOfs $FLAGS $bs
    1.73  	fi
    1.74  	if [ -n "$VIDEO" ]; then
    1.75  		[ -n "$DEBUG" ] && echo -n "--video " 1>&2
    1.76 -		store16 $VideoModeOfs $(( $VIDEO )) $bs
    1.77 +		store16 $VideoModeOfs $VIDEO $bs
    1.78  	fi
    1.79  	if [ -n "$RDEV" ]; then
    1.80  		[ -n "$DEBUG" ] && echo -n "--rdev " 1>&2
    1.81  		n=$(stat -c '0x%02t%02T' $RDEV 2> /dev/null)
    1.82  		[ -n "$n" ] || n=$RDEV
    1.83 -		store16 $RootDevOfs $(( $n )) $bs
    1.84 +		store16 $RootDevOfs $n $bs
    1.85  	fi
    1.86  
    1.87  	# Store cmdline after setup
    1.88 @@ -186,6 +203,10 @@
    1.89  	rm -f $bs
    1.90  }
    1.91  
    1.92 +if [ "$FORMAT" == "0" ]; then # unsplitted
    1.93 +	floppyset > $PREFIX
    1.94 +	exit
    1.95 +fi
    1.96  floppyset | split -b ${FORMAT}k /dev/stdin floppy$$
    1.97  i=1
    1.98  ls floppy$$* | while read file ; do