wok annotate syslinux/stuff/iso2exe/iso2exe.sh @ rev 17491

syslinux/iso2exe: speedup crc
author Pascal Bellard <pascal.bellard@slitaz.org>
date Fri Jan 02 21:46:16 2015 +0100 (2015-01-02)
parents 054f70cb9bec
children aa46cf9cc35a
rev   line source
pascal@13691 1 #!/bin/sh
pascal@13691 2
pascal@13691 3 ddq()
pascal@13691 4 {
pascal@13691 5 dd $@ 2> /dev/null
pascal@13691 6 }
pascal@13691 7
pascal@13691 8 store()
pascal@13691 9 {
pascal@13691 10 n=$2; for i in $(seq 8 8 ${4:-16}); do
pascal@13691 11 printf '\\\\x%02X' $(($n & 255))
pascal@13691 12 n=$(($n >> 8))
pascal@13691 13 done | xargs echo -en | ddq bs=1 conv=notrunc of=$3 seek=$(($1))
pascal@13691 14 }
pascal@13691 15
pascal@13972 16 get()
pascal@13972 17 {
pascal@13972 18 echo $(od -j $(($1)) -N ${3:-2} -t u${3:-2} -An $2)
pascal@13972 19 }
pascal@13972 20
pascal@17476 21 compress()
pascal@17476 22 {
pascal@17489 23 if [ "$1" ]; then
pascal@17489 24 gzip -9 > $1
pascal@17489 25 [ "$(which advdef 2> /dev/null)" ] &&
pascal@17489 26 advdef -z4 $1 > /dev/null
pascal@17489 27 elif [ "$(which xz 2> /dev/null)" ]; then
pascal@17476 28 xz -z -e --format=lzma --lzma1=mode=normal --stdout
pascal@17476 29 else
pascal@17476 30 lzma e -si -so
pascal@17476 31 fi 2> /dev/null
pascal@17476 32 }
pascal@17476 33
pascal@14150 34 add_rootfs()
pascal@13691 35 {
pascal@13691 36 TMP=/tmp/iso2exe$$
pascal@13713 37 mkdir -p $TMP/bin $TMP/dev
pascal@17477 38 cp -a /dev/?d?* /dev/tty /dev/tty0 $TMP/dev
pascal@13691 39 $0 --get init > $TMP/init.exe
pascal@17489 40 # mount -o loop,ro $1 $TMP
pascal@17489 41 # oldslitaz="$(ls $TMP/boot/isolinux/splash.lss 2> /dev/null)"
pascal@17489 42 # umount -d $TMP
pascal@17489 43 # [ "$oldslitaz" ] && # for SliTaz <= 3.0 only...
pascal@17489 44 # grep -q mount.posixovl.iso2exe $TMP/init.exe &&
pascal@17489 45 # cp /usr/sbin/mount.posixovl $TMP/bin/mount.posixovl.iso2exe \
pascal@17489 46 # 2> /dev/null && echo "Store mount.posixovl ($(wc -c \
pascal@17489 47 # < /usr/sbin/mount.posixovl) bytes) ..."
pascal@17252 48 find $TMP -type f -print0 | xargs -0 chmod +x
pascal@17489 49 ( cd $TMP ; find * | cpio -o -H newc ) | compress $TMP/rootfs.gz
pascal@13691 50 SIZE=$(wc -c < $TMP/rootfs.gz)
pascal@13972 51 store 24 $SIZE $1
pascal@14261 52 OFS=$(( $OFS - $SIZE ))
pascal@17454 53 printf "Adding rootfs.gz file at %04X (%d bytes) ...\n" $OFS $SIZE
pascal@13691 54 cat $TMP/rootfs.gz | ddq of=$1 bs=1 seek=$OFS conv=notrunc
pascal@13691 55 rm -rf $TMP
pascal@14150 56 }
pascal@14150 57
pascal@14261 58 add_dosexe()
pascal@14261 59 {
pascal@14261 60 OFS=$((0x7EE0))
pascal@17454 61 printf "Adding DOS/EXE at %04X (%d bytes) ...\n" $OFS $((0x8000 - $OFS))
pascal@14261 62 $0 --get bootiso.bin 2> /dev/null | \
pascal@14261 63 ddq bs=1 skip=$OFS of=$1 seek=$OFS conv=notrunc
pascal@14261 64 }
pascal@14261 65
pascal@14150 66 add_doscom()
pascal@14150 67 {
pascal@13972 68 SIZE=$($0 --get boot.com | wc -c)
pascal@13691 69 OFS=$(( $OFS - $SIZE ))
pascal@17454 70 printf "Adding DOS boot file at %04X (%d bytes) ...\n" $OFS $SIZE
pascal@13972 71 $0 --get boot.com | ddq of=$1 bs=1 seek=$OFS conv=notrunc
pascal@13972 72 store 66 $(($OFS+0xC0)) $1
pascal@14150 73 }
pascal@14150 74
pascal@14150 75 add_win32exe()
pascal@14150 76 {
pascal@13974 77 SIZE=$($0 --get win32.exe 2> /dev/null | tee /tmp/exe$$ | wc -c)
pascal@17454 78 printf "Adding WIN32 file at %04X (%d bytes) ...\n" 0 $SIZE
pascal@14261 79 ddq if=/tmp/exe$$ of=$1 conv=notrunc
pascal@14261 80 printf "Adding bootiso head at %04X...\n" 0
pascal@14261 81 $0 --get bootiso.bin 2> /dev/null > /tmp/exe$$
pascal@14261 82 ddq if=/tmp/exe$$ of=$1 bs=128 count=1 conv=notrunc
pascal@14266 83 store $((0x94)) $((0xE0 - 12*8)) $1
pascal@14266 84 store $((0xF4)) $((16 - 12)) $1
pascal@14267 85 ddq if=$1 of=/tmp/coff$$ bs=1 skip=$((0x178)) count=$((0x88))
pascal@14267 86 ddq if=/tmp/coff$$ of=$1 conv=notrunc bs=1 seek=$((0x178 - 12*8))
pascal@14267 87 ddq if=/tmp/exe$$ of=$1 bs=1 count=30 seek=$((0x1A0)) skip=$((0x1A0)) conv=notrunc
pascal@14267 88 ddq if=$2 bs=1 skip=$((0x1BE)) seek=$((0x1BE)) count=66 of=$1 conv=notrunc
pascal@14261 89 store 69 $(($SIZE/512)) $1 8
pascal@14261 90 store 510 $((0xAA55)) $1
pascal@14267 91 rm -f /tmp/exe$$ /tmp/coff$$
pascal@17454 92 printf "Moving syslinux hybrid boot record at %04X (512 bytes) ...\n" $SIZE
pascal@14261 93 ddq if=$2 bs=1 count=512 of=$1 seek=$SIZE conv=notrunc
pascal@14261 94 OFS=$(($SIZE+512))
pascal@14257 95 }
pascal@14257 96
pascal@14257 97 add_fdbootstrap()
pascal@14257 98 {
pascal@14268 99 SIZE=$($0 --get bootfd.bin 2> /dev/null | wc -c)
pascal@14257 100 if [ $SIZE -ne 0 ]; then
pascal@17454 101 SIZE=$(( $SIZE - 512 )) # sector 2 is data
pascal@17454 102 OFS=$(( $OFS - $SIZE ))
pascal@17454 103 printf "Adding floppy bootstrap file at %04X (%d bytes) ...\n" $OFS $SIZE
pascal@14268 104 $0 --get bootfd.bin | \
pascal@14268 105 ddq of=$1 bs=1 count=512 seek=$OFS conv=notrunc
pascal@14268 106 $0 --get bootfd.bin | \