wok diff syslinux/stuff/iso2exe/iso2exe.sh @ rev 24227

syslinux: add apple partitions (again)
author Pascal Bellard <pascal.bellard@slitaz.org>
date Sat Jan 01 10:31:50 2022 +0000 (2022-01-01)
parents f95bb62ba57c
children 4e9f81882cd3
line diff
     1.1 --- a/syslinux/stuff/iso2exe/iso2exe.sh	Fri Dec 31 10:26:14 2021 +0000
     1.2 +++ b/syslinux/stuff/iso2exe/iso2exe.sh	Sat Jan 01 10:31:50 2022 +0000
     1.3 @@ -46,10 +46,17 @@
     1.4  	if [ "$2" = "--array" ] || grep -qs rootfs $TMP/mnt/boot/isolinux/isolinux.cfg ; then
     1.5  		$0 --get rootfs.gz > $TMP/rootfs.gz
     1.6  		SIZE=$(wc -c < $TMP/rootfs.gz)
     1.7 -		store 24 $SIZE $1
     1.8 -		OFS=$(( 0x7FF0 - SIZE ))
     1.9 -		printf "Adding rootfs.gz file at %04X (%d bytes) ...\n" $OFS $SIZE
    1.10 -		ddn if=$TMP/rootfs.gz of=$1 bs=1 seek=$OFS
    1.11 +		if [ $(get 2048 $1) -eq 19792 -a $SIZE -lt 1912 ]; then	### Apple partitions
    1.12 +			store 24 $((0 - SIZE)) $1
    1.13 +			OFS2=$(( 0x1000 - SIZE ))
    1.14 +			OFS=$(( 0x7FF0 ))
    1.15 +		else
    1.16 +			store 24 $SIZE $1
    1.17 +			unset OFS2
    1.18 +			OFS=$(( 0x7FF0 - SIZE ))
    1.19 +		fi
    1.20 +		printf "Adding rootfs.gz file at %04X (%d bytes) ...\n" ${OFS2:-$OFS} $SIZE
    1.21 +		ddn if=$TMP/rootfs.gz of=$1 bs=1 seek=${OFS2:-$OFS}
    1.22  	fi
    1.23  	umount $TMP/mnt
    1.24  	rm -rf $TMP
    1.25 @@ -75,26 +82,32 @@
    1.26  {
    1.27  	$0 --get bootiso.bin 2> /dev/null > /tmp/bin$$
    1.28  	SIZE=$($0 --get win32.exe 2> /dev/null | tee /tmp/exe$$ | wc -c)
    1.29 -	n=1536
    1.30 -	cut=$((0x98+$(get 0x94 /tmp/exe$$)))	### end of header
    1.31 +	n=1536; n0=0; n2=0
    1.32 +	cut=$((0x98+$(get 0x94 /tmp/exe$$)))			### end of header
    1.33  	if [ $(get 2048 /tmp/bin$$) -eq 19792 ]; then		### Fix EFI Apple partition
    1.34  		o=$(($(get 584 "$1")*512))
    1.35  		f=$(($(get $((o+0x20)) "$1" 4)/4))
    1.36  		l=$((($(get $((o+0x28)) "$1" 4)+1)/4-f))
    1.37  		store $((0x1008)) $(printf "%08x" $f | sed 's|\(..\)\(..\)\(..\)\(..\)|0x\4\3\2\1|') /tmp/bin$$ 32
    1.38  		store $((0x1054)) $(printf "%08x" $l | sed 's|\(..\)\(..\)\(..\)\(..\)|0x\4\3\2\1|') /tmp/bin$$ 32
    1.39 -		n=4608
    1.40 +		printf "Adding Apple partition at %04X (2560 bytes) ...\n" 2048
    1.41 +		if [ $(get 0x86 /tmp/exe$$) -eq 3 ]; then	### UPX files have 3 sections
    1.42 +			n0=136; n2=2696				### cut header / sections decripttion
    1.43 +		else
    1.44 +			n=4608
    1.45 +		fi
    1.46  	fi
    1.47 -	SIZE=$((SIZE+n))
    1.48 +	SIZE=$((SIZE+n+n2-n0))
    1.49  	printf "Adding WIN32 file at %04X (%d bytes) ...\n" 0 $SIZE
    1.50  	[ -n "$gpt" ] && printf "Adding GPT at %04X (1024 bytes) ...\n" 512
    1.51  	for i in $(seq 396 40 $((356+$(get 0x86 /tmp/exe$$)*40))); do	### 18C 1B4 1DC
    1.52 -		x=$((n + $(get $i /tmp/exe$$)))
    1.53 +		x=$((n + n2 - n0 + $(get $i /tmp/exe$$)))
    1.54  		store $i $x /tmp/exe$$		### section offset
    1.55  	done
    1.56  	store $((0x94)) $((n + cut - 0x98)) /tmp/exe$$
    1.57  	ddn if=/tmp/exe$$ of=$1 bs=1 count=$cut
    1.58 -	ddn if=/tmp/exe$$ of=$1 bs=1 skip=$cut seek=$((n+cut))
    1.59 +	[ $n2 -ne 0 ] && ddn if=/tmp/exe$$ of=$1 bs=1 skip=$cut seek=$((n+cut)) count=$n0
    1.60 +	ddn if=/tmp/exe$$ of=$1 bs=1 skip=$((n0+cut)) seek=$((n+n2+cut))
    1.61  	printf "Adding bootiso head at %04X...\n" 0
    1.62  	store 510 $((0xAA55)) $1
    1.63  	while read adrs sz rem; do
    1.64 @@ -171,7 +184,10 @@
    1.65  	c=$(custom_config_sector "$ISO")
    1.66  	SIZE=0; OFFSET=0
    1.67  	case "$1" in
    1.68 -	win32.exe)	[ $x -eq 2048 ] && x=10752
    1.69 +	win32.exe)	[ $x -eq 2048 ] &&
    1.70 +			x=$((40*$(get 0x86 "$ISO")+\
    1.71 +			     0x98-24+$(get 0x94 "$ISO"))) &&
    1.72 +			x=$(($(get $x "$ISO")+$(get $((x+4)) "$ISO")))
    1.73  			[ $x -eq 1024 ] || SIZE=$x;;
    1.74  	syslinux.mbr)	[ $x -eq 1024 ] || OFFSET=$((x - 512)); SIZE=336;;
    1.75  	flavor.info)	[ $(get 22528 "$ISO") -eq 35615 ] && OFFSET=22528
    1.76 @@ -182,7 +198,8 @@
    1.77  			SIZE=$(ddq bs=512 skip=$((OFFSET/512)) if="$ISO" | gzsize);;
    1.78  	floppy.boot)	SIZE=$(($(get 26 "$ISO" 1)*512))
    1.79  			OFFSET=$(($(get 64 "$ISO") - 0xC0 - SIZE));;
    1.80 -	rootfs.gz)	SIZE=$(get 24 "$ISO"); OFFSET=$((stub - SIZE));;
    1.81 +	rootfs.gz)	SIZE=$(get 24 "$ISO"); OFFSET=$((stub - SIZE))
    1.82 +			[ $SIZE -gt 60000 ] && SIZE=$((0x10000 - SIZE)) && OFFSET=$((0x1000 - SIZE));;
    1.83  	isoboot.com)	OFFSET=$(($(get 64 "$ISO") - 0xC0))
    1.84  			SIZE=$((stub - $(get 24 "$ISO") - OFFSET));;
    1.85  	dosstub)	[ "$dosstub" ] && OFFSET=$stub && SIZE=$((0x7FF0 - OFFSET));;
    1.86 @@ -307,6 +324,7 @@
    1.87  {
    1.88  	start=$(custom_config_sector $1)
    1.89  	cnt=$((512 - (start % 512)))
    1.90 +	[ $(($(stat -c %s $1)/2048 - $start)) -ge $cnt ] &&	### Do not enlarge iso !
    1.91  	[ $cnt -ne 512 ] &&
    1.92  	ddq if=/dev/zero of=$1 bs=2k seek=$start count=$cnt
    1.93  }