wok-next rev 17454

syslinux/iso2exe: create a vfat partition in usb bootkey (DOS case only)
author Pascal Bellard <pascal.bellard@slitaz.org>
date Thu Dec 18 11:42:27 2014 +0100 (2014-12-18)
parents c2b42fe954b3
children 18dc23394a2c
files syslinux/receipt syslinux/stuff/iso2exe/bootiso.S syslinux/stuff/iso2exe/init syslinux/stuff/iso2exe/iso2exe.sh
line diff
     1.1 --- a/syslinux/receipt	Wed Dec 17 19:51:54 2014 +0100
     1.2 +++ b/syslinux/receipt	Thu Dec 18 11:42:27 2014 +0100
     1.3 @@ -29,6 +29,7 @@
     1.4  	sed -i 's/ifcpu64.c32/ifcpu64.c32 md5sum.c32/' com32/modules/Makefile
     1.5      make clean
     1.6      make all 2>&1 | sed 's/NO_WERROR=1/NO_Werror=1/;/syslinux64.exe/d'
     1.7 +    echo "make core: LDFLAGS=$LDFLAGS"
     1.8      make -C core
     1.9      make -C com32
    1.10      ./isohybrid.sh --build
     2.1 --- a/syslinux/stuff/iso2exe/bootiso.S	Wed Dec 17 19:51:54 2014 +0100
     2.2 +++ b/syslinux/stuff/iso2exe/bootiso.S	Thu Dec 18 11:42:27 2014 +0100
     2.3 @@ -129,11 +129,11 @@
     2.4  	movw	$0x100, %si
     2.5  	movw	-126(%si), %ax
     2.6  	cwd				// clear dx
     2.7 -	pushw	%dx			// dos exit
     2.8 +	pushw	%dx			// dos exit()
     2.9  	cmpb	$0x2F, %al
    2.10  	movw	$0x3000+EXESTR(help), %ax
    2.11 -	jbe	abort
    2.12 -	int	$0x21
    2.13 +	je	abort
    2.14 +	int	$0x21			// get DOS version
    2.15  	cmpb	$3, %al
    2.16  	movb	$EXESTR(noDOS3), %al
    2.17  	jb	abort
    2.18 @@ -172,7 +172,7 @@
    2.19  	popfw			// < 286 : flags[12..15] are forced 1
    2.20  	pushfw			// = 286 : flags[12..15] are forced 0
    2.21  	popw	%bx		// > 286 : only flags[15] is forced 0
    2.22 -	popfw			// restore flags
    2.23 +	popfw			// restore flags (IOPL)
    2.24  	addb	%ah, %bh	// test F0 and 00 cases
    2.25  	cmpb	%ah, %bh
    2.26  	movb	$EXESTR(no386), %al
     3.1 --- a/syslinux/stuff/iso2exe/init	Wed Dec 17 19:51:54 2014 +0100
     3.2 +++ b/syslinux/stuff/iso2exe/init	Thu Dec 18 11:42:27 2014 +0100
     3.3 @@ -2,6 +2,11 @@
     3.4  
     3.5  DIALOG=dialog
     3.6  
     3.7 +ddq()
     3.8 +{
     3.9 +	dd $@ 2> /dev/null
    3.10 +}
    3.11 +
    3.12  get()
    3.13  {
    3.14  	od -j $1 -N ${3:-2} -t u${3:-2} -An $2 2> /dev/null ||
    3.15 @@ -28,6 +33,14 @@
    3.16  	umount /proc
    3.17  }
    3.18  
    3.19 +words2bin()
    3.20 +{
    3.21 +	for i in $@ ; do
    3.22 +		printf '\\\\x%02X\\\\x%02X' $(($i&255)) $((($i>>8)&255)) | \
    3.23 +			xargs echo -en
    3.24 +	done
    3.25 +}
    3.26 +
    3.27  gettazboot()
    3.28  {
    3.29  	echo "Creating $(basename $1) ..."
    3.30 @@ -36,12 +49,9 @@
    3.31  	S=$((32+$L))
    3.32  	P=$((($S+511)/512))
    3.33  	E=$((4096-(32*$P)))
    3.34 -	for i in 0x5A4D $(($S%512)) $P 0 2 $E -1 $((${2:-0}-16)) \
    3.35 -			-2 0 256 -16 28 0x6C53 0x5469 0x7A61; do 
    3.36 -		printf '\\\\x%02X\\\\x%02X' $(($i&255)) $((($i>>8)&255)) | \
    3.37 -			xargs echo -en
    3.38 -	done > $1
    3.39 -	dd bs=1 count=$L skip=$(echo $O) if=/mnt/$ISO >> $1 2> /dev/null
    3.40 +	words2bin 0x5A4D $(($S%512)) $P 0 2 $E -1 $((${2:-0}-16)) \
    3.41 +			-2 0 256 -16 28 0x6C53 0x5469 0x7A61 > $1
    3.42 +	ddq bs=1 count=$L skip=$(echo $O) if=/mnt/$ISO >> $1
    3.43  }
    3.44  
    3.45  checkmagic()
    3.46 @@ -82,7 +92,7 @@
    3.47  tazusbinitfs()
    3.48  {
    3.49  	PAD=$(($(stat -c %s $1) % 4))
    3.50 -	[ $PAD -ne 0 ] && dd if=/dev/zero bs=1 count=$((4 - $PAD)) >> $1
    3.51 +	[ $PAD -ne 0 ] && ddq if=/dev/zero bs=1 count=$((4 - $PAD)) >> $1
    3.52  	mkdir -p /tmp/fs/etc /tmp/fs/lib /tmp/fs/home
    3.53  	cp -a /etc/locale.conf /tmp/fs/etc 2> /dev/null
    3.54  	cp -a /etc/keymap.conf /tmp/fs/etc 2> /dev/null
    3.55 @@ -163,7 +173,7 @@
    3.56  arg subroot "Change root to directory"
    3.57  mount.posixovl -F /mnt/\$val -- -oallow_other -odefault_permissions -osuid
    3.58  mount --bind /mnt /mnt/\$val/mnt/dos
    3.59 -#mount -o size=0 -t tmpfs tmpfs /mnt/\$val/mnt/dos/\$val
    3.60 +mount -o size=0 -t tmpfs tmpfs /mnt/\$val/mnt/dos/\$val
    3.61  LDSO=\$(ls /mnt/\$val/lib/ld-* | sed q)
    3.62  export LD_LIBRARY_PATH=\$val/lib:\$val/usr/lib:/lib
    3.63    [ "$debug" = "true" ] && sh
    3.64 @@ -195,7 +205,7 @@
    3.65  		return 1
    3.66  	fi
    3.67  	echo "Install root filesystem in /slitaz..."
    3.68 -	if [ -n "$1" ]; then
    3.69 +	if [ "$1" ]; then
    3.70  		if [ -d /media/cdrom/fs ]; then
    3.71  			( cd /mnt/slitaz/fs; find | cpio -o -H newc ) | gzip -9
    3.72  		else
    3.73 @@ -308,7 +318,7 @@
    3.74  		cp -a /media/cdrom/fs/. /
    3.75  	else
    3.76  		for i in $(ls_r /media/cdrom/boot/rootfs*); do
    3.77 -			unlzma < $i | (cd / ; cpio -idmu )
    3.78 +			uncpio $i
    3.79  		done
    3.80  	fi
    3.81  	cp /tmp/fs/etc/* /etc
    3.82 @@ -394,7 +404,7 @@
    3.83  Please insert a blank disk in floppy drive.\n
    3.84  " 12 70
    3.85  	[ $? -eq 0 ] || return
    3.86 -	dd if=/media/cdrom/boot/memtest of=/dev/fd0
    3.87 +	ddq if=/media/cdrom/boot/memtest of=/dev/fd0
    3.88  }
    3.89  
    3.90  pxe()
    3.91 @@ -424,7 +434,7 @@
    3.92  Please insert a blank disk in floppy drive.\n
    3.93  " 12 70
    3.94  	[ $? -eq 0 ] || return
    3.95 -	dd if=/media/cdrom/boot/?pxe of=/dev/fd0
    3.96 +	ddq if=/media/cdrom/boot/?pxe of=/dev/fd0
    3.97  }
    3.98  
    3.99  gotposixovl()
   3.100 @@ -435,7 +445,7 @@
   3.101  
   3.102  xfile()
   3.103  {
   3.104 -	[ -n "$(which $1)" ] && echo -en "\"$2\"	\"$3\""
   3.105 +	[ "$(which $1)" ] && echo -en "\"$2\"	\"$3\""
   3.106  }
   3.107  
   3.108  cdfile()
   3.109 @@ -466,19 +476,20 @@
   3.110  Please insert a floppy in drive now.\n 
   3.111  " 10 70
   3.112  	[ $? -eq 0 ] || return
   3.113 -	dd if=/mnt/$ISO of=/dev/fd0 bs=1 count=512 \
   3.114 +	ddq if=/mnt/$ISO of=/dev/fd0 bs=1 count=512 \
   3.115  		skip=$(( $(get 66 /mnt/$ISO) - $sz ))
   3.116 -	echo "$ISO" | dd of=/dev/fd0 bs=512 seek=1 count=1
   3.117 -	dd if=/mnt/$ISO of=/dev/fd0 bs=1 count=$sz seek=2 \
   3.118 +	echo "$ISO" | ddq of=/dev/fd0 bs=512 seek=1 count=1
   3.119 +	ddq if=/mnt/$ISO of=/dev/fd0 bs=1 count=$sz seek=2 \
   3.120  		skip=$(( $(get 66 /mnt/$ISO) - $sz + 512 ))
   3.121  }
   3.122  
   3.123  usbdev()
   3.124  {
   3.125 +	echo "Wait 5 seconds for USB devices..."
   3.126  	sleep 5
   3.127  	DEV="$(grep -l 1 /sys/block/*/removable | \
   3.128  		sed 's|/sys/block/\(.*\)/removable|\1|')"
   3.129 -	[ -n "$DEV" ] || return
   3.130 +	[ "$DEV" ] || return
   3.131  	exec 3>&1
   3.132  	device=`$DIALOG  --clear \
   3.133  	--title " Select your USB key " \
   3.134 @@ -499,14 +510,51 @@
   3.135  		--title " Create a USB boot key " \
   3.136  		--yes-label "Continue" --yesno \
   3.137  "\nThe USB key will be used like a CD-ROM. You will not be able to write
   3.138 -any data on it.\n\n
   3.139 +any data on the boot partition.\n\n
   3.140 +An extra FAT32 partition will be created with the remaining free space.\n\n
   3.141  You should choose 'USB key read/write installation' to be
   3.142  able to save the package updates or your own configuration and data files.\n\n
   3.143  Please plug your USB stick in now.\n 
   3.144 -" 13 70
   3.145 +" 16 70
   3.146  	[ $? -eq 0 ] || return
   3.147  	usbdev || return
   3.148 -	dd if=/mnt/$ISO of=$device
   3.149 +	
   3.150 +	# perform dd in progess bar
   3.151 +	max=$(($(stat -c %s /mnt/$ISO)/1024/1024))
   3.152 +	mkfifo /tmp/fifodd
   3.153 +	dialog --gauge " The ISO image transfer can be long. Please wait..." \
   3.154 +			6 70 0 < /tmp/fifodd &
   3.155 +	i=0; ddq if=/mnt/$ISO bs=1024k | ( 
   3.156 +		while ddq bs=1024k count=1 ; do 
   3.157 +		i=$(($i + 1))
   3.158 +		[ $i -gt $max ] && break
   3.159 +		echo $((($i*100)/$max)) > /tmp/fifodd
   3.160 +	done ) > $device
   3.161 +
   3.162 +	# partition + fat32 format for the remining space
   3.163 +	od -j 466 -N 12 -t u2 -An $device | { read dx cx ol oh ll lh 
   3.164 +	if [ $dx -eq $((0x3F17)) ]; then
   3.165 +		cx=$(($cx & 0xFF00))
   3.166 +		ofs=$(($ll+($lh<<16)))
   3.167 +		n=$(($(cat /sys/block/${device#/dev/}/size)-$ofs))
   3.168 +		m=$(($cx+($n/8)))
   3.169 +		[ $m -gt $((0x3FF00)) ] && m=$((0x3FF00))
   3.170 +		m=$((($m & 0xFF00)+(($m>>16)<<6)))
   3.171 +		words2bin 0 $((0x101+$cx)) 0x3F0B $((32+$m)) \
   3.172 +			$ll $lh $(($n & 0xFFFF)) $(($n >> 16)) | \
   3.173 +			ddq bs=1 seek=446 of=$device
   3.174 +		if [ "$(which mkdosfs 2> /dev/null)" ]; then
   3.175 +			losetup -o $((512*$ofs)) /dev/loop0 $device
   3.176 +			mkdosfs -n "SLITAZ BOOT" /dev/loop0
   3.177 +			words2bin $(($ofs & 0xFFFF)) $(($ofs >> 16)) | \
   3.178 +				ddq bs=1 seek=28 of=/dev/loop0
   3.179 +			losetup -d /dev/loop0
   3.180 +		fi
   3.181 + 	fi ; }
   3.182 + 	
   3.183 + 	# kill dialog --gauge
   3.184 +	sleep 1
   3.185 +	rm /tmp/fifodd
   3.186  }
   3.187  
   3.188  usbkey()
   3.189 @@ -630,7 +678,7 @@
   3.190  	cat > /tmp/dialog <<EOT
   3.191  $DIALOG  --clear \
   3.192  	--title " Welcome to SliTaz " \
   3.193 -	--menu "" 21 70 15 \
   3.194 +	--menu "" 23 70 17 \
   3.195  $(xfile tazkeymap	"tazkeymap"	"Select keyboard ($keymap)") \
   3.196  $(xfile tazlocale	"tazlocale"	"Select locale ($locale)") \
   3.197  $(cdfile boot/bzImage	"live"		"SliTaz RAM boot") \
     4.1 --- a/syslinux/stuff/iso2exe/iso2exe.sh	Wed Dec 17 19:51:54 2014 +0100
     4.2 +++ b/syslinux/stuff/iso2exe/iso2exe.sh	Thu Dec 18 11:42:27 2014 +0100
     4.3 @@ -26,14 +26,15 @@
     4.4  	$0 --get init > $TMP/init.exe
     4.5  	grep -q mount.posixovl.iso2exe $TMP/init.exe &&
     4.6  	cp /usr/sbin/mount.posixovl $TMP/bin/mount.posixovl.iso2exe \
     4.7 -		2> /dev/null && echo "Store mount.posixovl..."
     4.8 +		2> /dev/null && echo "Store mount.posixovl ($(wc -c \
     4.9 +			< /usr/sbin/mount.posixovl) bytes) ..."
    4.10  	find $TMP -type f -print0 | xargs -0 chmod +x
    4.11  	( cd $TMP ; find * | cpio -o -H newc ) | \
    4.12  		lzma e $TMP/rootfs.gz -si 2> /dev/null
    4.13  	SIZE=$(wc -c < $TMP/rootfs.gz)
    4.14  	store 24 $SIZE $1
    4.15  	OFS=$(( $OFS - $SIZE ))
    4.16 -	printf "Adding rootfs.gz file at %04X...\n" $OFS
    4.17 +	printf "Adding rootfs.gz file at %04X (%d bytes) ...\n" $OFS $SIZE
    4.18  	cat $TMP/rootfs.gz | ddq of=$1 bs=1 seek=$OFS conv=notrunc
    4.19  	rm -rf $TMP
    4.20  }
    4.21 @@ -41,7 +42,7 @@
    4.22  add_dosexe()
    4.23  {
    4.24  	OFS=$((0x7EE0))
    4.25 -	printf "Adding DOS/EXE at %04X...\n" $OFS
    4.26 +	printf "Adding DOS/EXE at %04X (%d bytes) ...\n" $OFS $((0x8000 - $OFS))
    4.27  	$0 --get bootiso.bin 2> /dev/null | \
    4.28  	ddq bs=1 skip=$OFS of=$1 seek=$OFS conv=notrunc
    4.29  }
    4.30 @@ -50,16 +51,16 @@
    4.31  {
    4.32  	SIZE=$($0 --get boot.com | wc -c)
    4.33  	OFS=$(( $OFS - $SIZE ))
    4.34 -	printf "Adding DOS boot file at %04X...\n" $OFS
    4.35 +	printf "Adding DOS boot file at %04X (%d bytes) ...\n" $OFS $SIZE
    4.36  	$0 --get boot.com | ddq of=$1 bs=1 seek=$OFS conv=notrunc
    4.37  	store 66 $(($OFS+0xC0)) $1
    4.38  }
    4.39  
    4.40  add_win32exe()
    4.41  {
    4.42 -	printf "Adding WIN32 file at %04X...\n" 0
    4.43  	ddq if=/tmp/exe$$ of=$1 conv=notrunc
    4.44  	SIZE=$($0 --get win32.exe 2> /dev/null | tee /tmp/exe$$ | wc -c)
    4.45 +	printf "Adding WIN32 file at %04X (%d bytes) ...\n" 0 $SIZE
    4.46  	ddq if=/tmp/exe$$ of=$1 conv=notrunc
    4.47  	printf "Adding bootiso head at %04X...\n" 0
    4.48  	$0 --get bootiso.bin 2> /dev/null > /tmp/exe$$
    4.49 @@ -73,7 +74,7 @@
    4.50  	store 69 $(($SIZE/512)) $1 8
    4.51  	store 510 $((0xAA55)) $1
    4.52  	rm -f /tmp/exe$$ /tmp/coff$$
    4.53 -	printf "Moving syslinux hybrid boot record at %04X ...\n" $SIZE
    4.54 +	printf "Moving syslinux hybrid boot record at %04X (512 bytes) ...\n" $SIZE
    4.55  	ddq if=$2 bs=1 count=512 of=$1 seek=$SIZE conv=notrunc
    4.56  	OFS=$(($SIZE+512))
    4.57  }
    4.58 @@ -82,13 +83,14 @@
    4.59  {
    4.60  	SIZE=$($0 --get bootfd.bin 2> /dev/null | wc -c)
    4.61  	if [ $SIZE -ne 0 ]; then
    4.62 -		OFS=$(( $OFS - $SIZE + 512 ))
    4.63 -		printf "Adding floppy bootstrap file at %04X...\n" $OFS
    4.64 +		SIZE=$(( $SIZE -  512 )) # sector 2 is data
    4.65 +		OFS=$(( $OFS - $SIZE ))
    4.66 +		printf "Adding floppy bootstrap file at %04X (%d bytes) ...\n" $OFS $SIZE
    4.67  		$0 --get bootfd.bin | \
    4.68  		ddq of=$1 bs=1 count=512 seek=$OFS conv=notrunc
    4.69  		$0 --get bootfd.bin | \
    4.70  		ddq of=$1 bs=1 skip=1024 seek=$((512 + $OFS)) conv=notrunc
    4.71 -		store 28 $(($SIZE/512 - 1)) $1 8
    4.72 +		store 28 $(($SIZE/512)) $1 8
    4.73  	fi
    4.74  }
    4.75  case "$1" in
    4.76 @@ -206,15 +208,17 @@
    4.77  	ddq if=$1 bs=512 count=1 of=/tmp/hybrid$$
    4.78  	ddq if=$1 bs=512 skip=2 count=20 of=/tmp/tazlito$$
    4.79  	add_win32exe $1 /tmp/hybrid$$
    4.80 -	printf "Moving tazlito data record at %04X ...\n" $OFS
    4.81 +	printf "Moving tazlito data record at %04X (512 bytes) ...\n" $OFS
    4.82  	ddq if=/tmp/tazlito$$ bs=1 count=512 of=$1 seek=$OFS conv=notrunc
    4.83  	rm -f /tmp/tazlito$$ /tmp/hybrid$$
    4.84 +	HOLE=$(($OFS+512))
    4.85  	
    4.86  	# keep the largest room for the tazlito info file
    4.87  	add_dosexe $1
    4.88  	add_rootfs $1
    4.89  	add_doscom $1
    4.90  	add_fdbootstrap $1
    4.91 +	printf "%d free bytes in %04X..%04X\n" $(($OFS-$HOLE)) $HOLE $OFS
    4.92  	store 26 ${RANDOM:-0} $1
    4.93  	i=66
    4.94  	n=0