wok annotate syslinux/stuff/tools/isohybrid.sh @ rev 5953
Up: exiftool 8.27
author | Antoine Bodin <gokhlayeh@mailoo.org> |
---|---|
date | Tue Aug 03 22:23:30 2010 +0200 (2010-08-03) |
parents | 81f59d88ba12 |
children | b25fc6e108b2 |
rev | line source |
---|---|
pascal@4513 | 1 #!/bin/sh |
pascal@4513 | 2 |
pascal@4513 | 3 build="--build" |
pascal@4513 | 4 if [ "$1" == "$build" ]; then |
pascal@4513 | 5 cat >> $0 <<EOM |
pascal@4513 | 6 $(uuencode -m mbr/isohdpfx.bin -) |
pascal@4513 | 7 EOT |
pascal@4513 | 8 EOM |
pascal@5078 | 9 busybox sed -i "/$build/{NNNNNNNNNd}" $0 |
pascal@4513 | 10 exit |
pascal@4513 | 11 fi |
pascal@4513 | 12 |
pascal@4513 | 13 if [ -z "$1" ]; then |
pascal@4513 | 14 cat << EOT |
pascal@4513 | 15 usage: $0 isoimage |
pascal@4513 | 16 EOT |
pascal@4513 | 17 exit 1 |
pascal@4513 | 18 fi |
pascal@4513 | 19 iso=$1 |
pascal@4513 | 20 heads=64 # zipdrive-style geometry |
pascal@4513 | 21 sectors=32 |
pascal@4513 | 22 partype=23 # "Windows hidden IFS" |
pascal@4513 | 23 |
pascal@4513 | 24 readiso() |
pascal@4513 | 25 { |
pascal@4513 | 26 dd if=$iso bs=2k skip=$1 count=1 2> /dev/null | \ |
pascal@4513 | 27 dd bs=1 skip=$2 count=$3 2> /dev/null |
pascal@4513 | 28 } |
pascal@4513 | 29 |
pascal@4513 | 30 # read a 32 bits data |
pascal@4513 | 31 readlong() |
pascal@4513 | 32 { |
pascal@4513 | 33 readiso $1 $2 4 | hexdump -e '"" 1/4 "%d" "\n"' |
pascal@4513 | 34 } |
pascal@4513 | 35 |
pascal@4513 | 36 # write a 32 bits data |
pascal@4513 | 37 storelong() |
pascal@4513 | 38 { |
pascal@4513 | 39 printf "00000 %02X %02X %02X %02X \n" \ |
pascal@4513 | 40 $(( $2 & 255 )) $(( ($2>>8) & 255 )) \ |
pascal@4513 | 41 $(( ($2>>16) & 255 )) $(( ($2>>24) & 255 )) | \ |
pascal@4513 | 42 hexdump -R | dd bs=1 conv=notrunc of=$iso seek=$(( $1 )) 2> /dev/null |
pascal@4513 | 43 } |
pascal@4513 | 44 |
pascal@4513 | 45 setmbr() |
pascal@4513 | 46 { |
pascal@4513 | 47 uudecode | dd of=$iso conv=notrunc 2> /dev/null |
pascal@4513 | 48 storelong 432 $(( $lba * 4 )) |
pascal@4513 | 49 storelong 440 $(( ($RANDOM << 16) + $RANDOM )) |
pascal@4513 | 50 storelong 446 $(( 0x80 + ( 1 << 16) )) |
pascal@4513 | 51 esect=$(( $sectors + ((($cylinders -1) & 0x300) >> 2) )) |
pascal@4513 | 52 ecyl=$(( ($cylinders - 1) & 0xff )) |
pascal@4513 | 53 storelong 450 $(( $partype + (($heads - 1) << 8) + ($esect << 16) + ($ecyl <<24) )) |
pascal@4513 | 54 storelong 458 $(( $cylinders * $heads * $sectors )) |
pascal@4513 | 55 storelong 510 $(( 0xAA55 )) |
pascal@4513 | 56 } |
pascal@4513 | 57 |
pascal@4513 | 58 if [ "$(readiso 17 7 23)" != "EL TORITO SPECIFICATION" ]; then |
pascal@4513 | 59 echo "$iso: no boot record found."; |
pascal@4513 | 60 exit 1 |
pascal@4513 | 61 fi |
pascal@4513 | 62 catalog=$(readlong 17 71) |
pascal@4513 | 63 if [ "$(readiso $catalog 0 32 | md5sum | awk '{ print $1 }')" != \ |
pascal@4513 | 64 "788e7bfdad52cc6aae525725f24a7f89" ]; then |
pascal@4513 | 65 echo "$iso: invalid boot catalog."; |
pascal@4513 | 66 exit 1 |
pascal@4513 | 67 fi |
pascal@4513 | 68 lba=$(readlong $catalog 40) |
pascal@4513 | 69 if [ $(readlong $lba 64) -ne 1886961915 ]; then |
pascal@4513 | 70 echo "$iso: bootloader does not have a isolinux.bin hybrid signature."; |
pascal@4513 | 71 exit 1 |
pascal@4513 | 72 fi |
pascal@4513 | 73 size=$(stat -c "%s" $iso) |
pascal@4513 | 74 pad=$(( $size % (512 * $heads * $sectors) )) |
pascal@4513 | 75 [ $pad -eq 0 ] || pad=$(( (512 * $heads * $sectors) - $pad )) |
pascal@4513 | 76 [ $pad -eq 0 ] || dd if=/dev/zero bs=512 count=$(( $pad / 512 )) >> $iso 2> /dev/null |
pascal@4513 | 77 cylinders=$(( ($size + $pad) / (512 * $heads * $sectors) )) |
pascal@4513 | 78 if [ $cylinders -gt 1024 ]; then |
pascal@4513 | 79 cat 1>&2 <<EOT |
pascal@4513 | 80 Warning: more than 1024 cylinders ($cylinders). |
pascal@4513 | 81 Not all BIOSes will be able to boot this device. |
pascal@4513 | 82 EOT |
pascal@4513 | 83 cylinders=1024 |
pascal@4513 | 84 fi |
pascal@4513 | 85 |
pascal@4513 | 86 setmbr <<EOT |