wok rev 7859

syslinux/isohybrid: add options
author Pascal Bellard <pascal.bellard@slitaz.org>
date Sat Jan 01 17:45:34 2011 +0100 (2011-01-01)
parents e4ac1a10c7be
children a80a9972e567
files syslinux/stuff/tools/isohybrid.sh
line diff
     1.1 --- a/syslinux/stuff/tools/isohybrid.sh	Fri Dec 31 15:36:06 2010 +0100
     1.2 +++ b/syslinux/stuff/tools/isohybrid.sh	Sat Jan 01 17:45:34 2011 +0100
     1.3 @@ -1,80 +1,108 @@
     1.4  #!/bin/sh
     1.5  
     1.6 -build="--build"
     1.7 -if [ "$1" == "$build" ]; then
     1.8 -	cat  >> $0 <<EOM
     1.9 -$(uuencode -m mbr/isohdpfx.bin -)
    1.10 +if [ "$1" == "--build" ]; then
    1.11 +	cat >> $0 <<EOM
    1.12 +$(for i in fx fx_f fx_c px px_f px_c ; do
    1.13 +     cat mbr/isohdp$i.bin /dev/zero | dd bs=512 count=1 2> /dev/null
    1.14 +  done | gzip -9 | uuencode -m -)
    1.15  EOT
    1.16  EOM
    1.17 -	busybox sed -i "/$build/{NNNNNNNNNd}" $0
    1.18 +	sed -i '/--build/,/^fi/d' $0
    1.19  	exit
    1.20  fi
    1.21 +iso=
    1.22 +heads=64	# zipdrive-style geometry
    1.23 +sectors=32
    1.24 +partype=23	# "Windows hidden IFS"
    1.25 +entry=1
    1.26 +id=$(( ($RANDOM <<16) + $RANDOM))
    1.27 +offset=0
    1.28 +partok=0
    1.29 +hd0=0
    1.30  
    1.31 -if [ -z "$1" ]; then
    1.32 +while [ -n "$1" ]; do
    1.33 +	case "$1" in
    1.34 +	-ct*)	hd0=2;;
    1.35 +	-e*)	entry=$2; shift;;
    1.36 +	-f*)	hd0=1;;
    1.37 +	-h)	heads=$2; shift;;
    1.38 +	-i*)	id=$(($2)); shift;;
    1.39 +	-noh*)	hd0=0;;
    1.40 +	-nop*)	partok=0;;
    1.41 +	-o*)	offset=$(($2)); shift;;
    1.42 +	-p*)	partok=1;;
    1.43 +	-s)	sectors=$2; shift;;
    1.44 +	-t*)	partype=$(($2 & 255)); shift;;
    1.45 +	*)	iso=$1;;
    1.46 +	esac
    1.47 +	shift
    1.48 +done
    1.49 +
    1.50 +if [ ! -f "$iso" ]; then
    1.51  	cat << EOT
    1.52  usage: $0 isoimage
    1.53  EOT
    1.54  	exit 1
    1.55  fi
    1.56 -iso=$1
    1.57 -heads=64	# zipdrive-style geometry
    1.58 -sectors=32
    1.59 -partype=23	# "Windows hidden IFS"
    1.60 +
    1.61 +ddq()
    1.62 +{
    1.63 +	dd "$@" 2> /dev/null
    1.64 +}
    1.65  
    1.66  readiso()
    1.67  {
    1.68 -	dd if=$iso bs=2k skip=$1 count=1 2> /dev/null | \
    1.69 -	dd bs=1 skip=$2 count=$3 2> /dev/null
    1.70 +	ddq bs=2k skip=$1 count=1 if=$iso | ddq bs=1 skip=$2 count=$3
    1.71  }
    1.72  
    1.73  # read a 32 bits data
    1.74 -readlong()
    1.75 +read32()
    1.76  {
    1.77 -	readiso $1 $2 4  | hexdump -e '"" 1/4 "%d" "\n"'
    1.78 +	readiso $1 $2 4 | hexdump -e '"" 1/4 "%d" "\n"'
    1.79  }
    1.80  
    1.81  # write a 32 bits data
    1.82 -storelong()
    1.83 +store32()
    1.84  {
    1.85 -	printf "00000  %02X %02X %02X %02X \n" \
    1.86 -		$(( $2 & 255 )) $(( ($2>>8) & 255 )) \
    1.87 -		$(( ($2>>16) & 255 )) $(( ($2>>24) & 255 )) | \
    1.88 -	hexdump -R | dd bs=1 conv=notrunc of=$iso seek=$(( $1 )) 2> /dev/null
    1.89 +	echo $2 | awk '{ for(n=$1,i=4;i--;n/=256) printf "\\\\x%02X",n%256 }' |\
    1.90 +	xargs echo -en | ddq bs=1 conv=notrunc of=$iso seek=$(($1))
    1.91  }
    1.92  
    1.93 -setmbr()
    1.94 +main()
    1.95  {
    1.96 -	uudecode | dd of=$iso conv=notrunc 2> /dev/null
    1.97 -	storelong 432 $(( $lba * 4 ))
    1.98 -	storelong 440 $(( ($RANDOM << 16) + $RANDOM ))
    1.99 -	storelong 446 $(( 0x80 + ( 1 << 16) ))
   1.100 -	esect=$(( $sectors + ((($cylinders -1) & 0x300) >> 2) ))
   1.101 -	ecyl=$(( ($cylinders - 1) & 0xff ))
   1.102 -	storelong 450 $(( $partype + (($heads - 1) << 8) + ($esect << 16) + ($ecyl <<24) ))
   1.103 -	storelong 458 $(( $cylinders * $heads * $sectors ))
   1.104 -	storelong 510 $(( 0xAA55 ))
   1.105 +	uudecode | gunzip | ddq bs=512 count=1 of=$iso conv=notrunc \
   1.106 +	  skip=$(( (3*$partok) + $hd0))
   1.107 +	store32 432 $(($lba * 4))
   1.108 +	store32 440 $id
   1.109 +	store32 508 $((0xAA550000))
   1.110 +	e=$(( (($entry -1) % 4) *16 +446))
   1.111 +	store32 $e $((0x10080))
   1.112 +	esect=$(( ($sectors + ((($cylinders -1) & 0x300) >>2)) <<16))
   1.113 +	ecyl=$(( (($cylinders -1) & 0xff) <<24))
   1.114 +	store32 $(($e + 4)) $(($partype + (($heads - 1) <<8) +$esect +$ecyl))
   1.115 +	store32 $(($e + 8)) $offset
   1.116 +	store32 $(($e + 12)) $(($cylinders * $heads * $sectors))
   1.117  }
   1.118  
   1.119 -if [ "$(readiso 17 7 23)" != "EL TORITO SPECIFICATION" ]; then
   1.120 -	echo "$iso: no boot record found.";
   1.121 +abort()
   1.122 +{
   1.123 +	echo "$iso: $1"
   1.124  	exit 1
   1.125 -fi
   1.126 -catalog=$(readlong 17 71)
   1.127 -if [ "$(readiso $catalog 0 32 | md5sum | awk '{ print $1 }')" != \
   1.128 -     "788e7bfdad52cc6aae525725f24a7f89" ]; then
   1.129 -	echo "$iso: invalid boot catalog.";
   1.130 -	exit 1
   1.131 -fi
   1.132 -lba=$(readlong $catalog 40)
   1.133 -if [ $(readlong $lba 64) -ne 1886961915 ]; then
   1.134 -	echo "$iso: bootloader does not have a isolinux.bin hybrid signature.";
   1.135 -	exit 1
   1.136 -fi
   1.137 +}
   1.138 +
   1.139 +[ "$(readiso 17 7 23)" == "EL TORITO SPECIFICATION" ] ||
   1.140 +	abort "no boot record found."
   1.141 +cat=$(read32 17 71)
   1.142 +[ $(read32 $cat 0) -eq 1 -a $(read32 $cat 30) -eq $(( 0x88AA55 )) ] ||
   1.143 +	abort "invalid boot catalog."
   1.144 +lba=$(read32 $cat 40)
   1.145 +[ $(read32 $lba 64) -eq 1886961915 ] ||
   1.146 +	abort "no isolinux.bin hybrid signature in bootloader."
   1.147  size=$(stat -c "%s" $iso)
   1.148 -pad=$(( $size % (512 * $heads * $sectors) ))
   1.149 -[ $pad -eq 0 ] || pad=$((  (512 * $heads * $sectors) - $pad ))
   1.150 -[ $pad -eq 0 ] || dd if=/dev/zero bs=512 count=$(( $pad / 512 )) >> $iso 2> /dev/null
   1.151 -cylinders=$(( ($size + $pad) / (512 * $heads * $sectors) ))
   1.152 +trksz=$(( 512 * $heads * $sectors ))
   1.153 +cylinders=$(( ($size + $trksz - 1) / $trksz ))
   1.154 +pad=$(( (($cylinders * $trksz) - $size) / 512 ))
   1.155 +[ $pad -eq 0 ] || ddq bs=512 count=$pad if=/dev/zero >> $iso
   1.156  if [ $cylinders -gt 1024 ]; then
   1.157  	cat 1>&2 <<EOT
   1.158  Warning: more than 1024 cylinders ($cylinders).
   1.159 @@ -83,4 +111,4 @@
   1.160  	cylinders=1024
   1.161  fi
   1.162  
   1.163 -setmbr <<EOT
   1.164 +main <<EOT