# HG changeset patch # User Pascal Bellard # Date 1475263798 -7200 # Node ID 31e215a4b9bb1c48d153abccdde79aa90bd45545 # Parent ca1cc546e49ca7b05e536dd23fe1b9cc8474bc2a syslinux/isohybrid: boot efi support diff -r ca1cc546e49c -r 31e215a4b9bb syslinux/stuff/iso2exe/iso2exe.sh --- a/syslinux/stuff/iso2exe/iso2exe.sh Fri Sep 30 21:17:41 2016 +0200 +++ b/syslinux/stuff/iso2exe/iso2exe.sh Fri Sep 30 21:29:58 2016 +0200 @@ -21,11 +21,9 @@ compress() { if [ "$1" ]; then - [ "$(which zopfli 2> /dev/null)" ] && - zopfli --i100 -c /dev/stdin > $1 || gzip -9 > $1 [ "$(which advdef 2> /dev/null)" ] && - advdef -z4 $1 > /dev/null + advdef -z4 -i100 $1 > /dev/null elif [ "$(which xz 2> /dev/null)" ]; then xz -z -e --format=lzma --lzma1=mode=normal --stdout else @@ -88,13 +86,28 @@ ddq if=/tmp/rezipped$$.gz bs=1 of=$1 seek=$OFS conv=notrunc HOLE=$(($HOLE+$n)) rm -f /tmp/rezipped$$.gz + if [ -n "$gpt" ]; then + store $((0x25E)) $n $1 + store $((0x25C)) $OFS $1 + fi } add_win32exe() { SIZE=$($0 --get win32.exe 2> /dev/null | tee /tmp/exe$$ | wc -c) + [ -n "$gpt" ] && SIZE=$(($SIZE+1024)) + [ -n "$mac" ] && SIZE=$(($SIZE+3072)) printf "Adding WIN32 file at %04X (%d bytes) ...\n" 0 $SIZE ddq if=/tmp/exe$$ of=$1 conv=notrunc + if [ -n "$gpt" ]; then + printf "Adding GPT at %04X (1024 bytes) ...\n" 512 + ddq if=$2 bs=512 skip=1 of=$1 seek=1 conv=notrunc + i=3; [ -n "$mac" ] && i=9 + ddq if=/tmp/exe$$ bs=512 skip=1 of=$1 seek=$i conv=notrunc + for i in 12C 154 17C ; do # always 3 UPX sections + store $((0x$i)) $((1024 + $(get 0x$i $1))) $1 2 + done + fi printf "Adding bootiso head at %04X...\n" 0 $0 --get bootiso.bin 2> /dev/null > /tmp/exe$$ ddq if=/tmp/exe$$ of=$1 bs=128 count=1 conv=notrunc @@ -104,12 +117,13 @@ ddq if=/tmp/coff$$ of=$1 conv=notrunc bs=1 seek=$((0x178 - 12*8)) ddq if=/tmp/exe$$ of=$1 bs=1 count=24 seek=$((0x1A0)) skip=$((0x1A0)) conv=notrunc ddq if=$2 bs=1 skip=$((0x1B8)) seek=$((0x1B8)) count=72 of=$1 conv=notrunc - store 417 $(($SIZE/512)) $1 8 store 510 $((0xAA55)) $1 rm -f /tmp/exe$$ /tmp/coff$$ - printf "Moving syslinux hybrid boot record at %04X (512 bytes) ...\n" $SIZE - ddq if=$2 bs=1 count=512 of=$1 seek=$SIZE conv=notrunc - OFS=$(($SIZE+512)) + i=$SIZE; OFS=$(($SIZE+512)) + [ -n "$mac" ] && OFS=$SIZE && i=1536 + store 417 $(($i/512)) $1 8 + printf "Moving syslinux hybrid boot record at %04X (512 bytes) ...\n" $i + ddq if=$2 bs=1 count=512 of=$1 seek=$i conv=notrunc } add_fdbootstrap() @@ -141,16 +155,21 @@ fileofs() { - [ $(get 1024 "$ISO") -eq 35615 ] && i=1024 || - i=$((512*(1+$(get 417 "$ISO" 1)))) + [ $(get 1024 "$ISO") -eq 35615 ] && x=1024 || + x=$((512*(1+$(get 417 "$ISO" 1)))) stub=$(($(get 20 "$ISO") - 0xC0)) c=$(custom_config_sector "$ISO") SIZE=0; OFFSET=0 case "$1" in - win32.exe) [ $i -eq 1024 ] || SIZE=$(($i - 512));; - syslinux.mbr) [ $i -eq 1024 ] || OFFSET=$(($i - 512)); SIZE=512;; - flavor.info) OFFSET=$i - SIZE=$(ddq bs=512 skip=$(($i/512)) if="$ISO" | gzsize);; + win32.exe) [ $x -eq 2048 ] && x=10752 + [ $x -eq 1024 ] || SIZE=$(($x - 512));; + syslinux.mbr) [ $x -eq 1024 ] || OFFSET=$(($x - 512)); SIZE=512;; + flavor.info) [ $(get 22528 "$ISO") -eq 35615 ] && OFFSET=22528 + [ $x -eq 2048 ] && x=$(get 0x25C "$ISO") && + SIZE=$(get 0x25E "$ISO") + [ $(get $x "$ISO") -eq 35615 ] && OFFSET=$x + [ $OFFSET -ne 0 ] && [ $SIZE -eq 0 ] && + SIZE=$(ddq bs=512 skip=$(($OFFSET/512)) if="$ISO" | gzsize);; floppy.boot) SIZE=$(($(get 26 "$ISO" 1)*512)) OFFSET=$(($(get 64 "$ISO") - 0xC0 - $SIZE));; rootfs.gz) SIZE=$(get 24 "$ISO"); OFFSET=$(($stub - $SIZE));; @@ -168,7 +187,7 @@ sed '/^append=/!d;s/^[^=]*=.//' | wc -c);; custom.initrd) i=$(ddq bs=2k skip=$c if="$ISO" count=1 | \ sed '/^append=\|^initrd:/!d' | wc -c) - OFFSET=$((2048*$c+$i+40)) + OFFSET=$((2048*$c+$x+40)) SIZE=$(($(ddq bs=2k skip=$c if="$ISO" count=1 | \ sed '/^initrd:/!d;s/.*://') + 0));; esac @@ -193,6 +212,46 @@ OFFSET=$(stat -c %s "$ISO") [ $OFFSET -gt $HEAP ] && printf "%d free bytes in %04X..%04X\n" $(($OFFSET - $HEAP)) $HEAP $OFFSET + if [ $(get 510 "$ISO") -eq 43605 ]; then + echo "MBR partitions :" + for i in 0 1 2 3; do + SIZE=$(get $((446+12+16*i)) "$ISO" 4) + [ $SIZE -eq 0 ] && continue + OFFSET=$(get $((446+8+16*i)) "$ISO" 4) + printf " $i:%08X %08X %02X\n" $OFFSET $SIZE \ + $(get $((446+4+16*i)) "$ISO" 1) + done + if [ $(get 466 "$ISO") -eq 65263 ]; then + echo "EFI partitions :" + n=$(get 584 "$ISO" 1) + s=$(get 596 "$ISO") + o=$((($(get 552 "$ISO" 1)*512)-($(get 592 "$ISO")*$s))) + i=0 + while [ $n -gt $i ]; do + f=$(get $(($o+0x20)) "$ISO" 4) + l=$(($(get $(($o+0x28)) "$ISO" 4)-$f)) + [ $l -eq 0 ] && break + printf " $i:%08X %08X %s\n" $f $(($l+1)) \ + "$(od -An -N 36 -w -j $(($o+0x38)) -t a "$ISO" \ + | sed 's/\( nul\)*//g;s/ //g;s/ sp//')" + o=$(($o+$s)) + i=$(($i+1)) + done + fi + fi + o=2048 + if [ $(get $o "$ISO") -eq 19792 ]; then + echo "Apple partitions :" + i=0 + while [ $(get $o "$ISO") -eq 19792 ]; do + f=$((0x$(od -An -N 4 -j $(($o+8)) -t x1 "$ISO" | sed 's/ //g'))) + l=$((0x$(od -An -N 4 -j $(($o+0x54)) -t x1 "$ISO" | sed 's/ //g'))) + printf " $i:%08X %08X %s\n" $f $l \ + "$(ddq bs=1 skip=$(($o+16)) count=32 if="$ISO")" + o=$(($o+2048)) + i=$(($i+1)) + done + fi } extract() @@ -211,10 +270,10 @@ clear_custom_config() { - start=$(custom_config_sector $1) - cnt=$((512 - ($start % 512))) - [ $cnt -ne 512 ] && - ddq if=/dev/zero of=$1 bs=2k seek=$start count=$cnt + start=$(custom_config_sector $1) + cnt=$((512 - ($start % 512))) + [ $cnt -ne 512 ] && + ddq if=/dev/zero of=$1 bs=2k seek=$start count=$cnt } case "$1" in --build) @@ -408,6 +467,7 @@ [ $(id -u) -ne 0 ] && cmd="$0 $@" && exec su -c "$cmd" < /dev/tty append= initrd= + while [ "$1" ]; do case "${1/--/-}" in -get) shift @@ -434,9 +494,16 @@ b=$(get 417 $1 1) n=$(($(get 64 $1) + 0xC0 - ($(get 26 $1 1)*512) - ($b+1)*512)) ddq if=$1 bs=512 count=1 skip=$b of=$1 conv=notrunc - ddq if=/dev/zero bs=512 seek=1 count=1 of=$1 conv=notrunc - ddq if=$1 bs=512 seek=2 count=30 skip=$(($b+1)) of=$1 conv=notrunc - ddq if=/dev/zero bs=1 seek=$n count=$((0x8000 - $n)) of=$1 conv=notrunc ;; + if [ $(get 512 $1) -eq 17989 ]; then + n=$(($(get 0x25C $1)/512)) + ddq if=$1 bs=512 seek=44 count=20 skip=$n of=$1 conv=notrunc + ddq if=/dev/zero bs=512 seek=9 count=35 of=$1 conv=notrunc + ddq if=/dev/zero bs=512 seek=3 count=1 of=$1 conv=notrunc + else + ddq if=/dev/zero bs=512 seek=1 count=1 of=$1 conv=notrunc + ddq if=$1 bs=512 seek=2 count=30 skip=$(($b+1)) of=$1 conv=notrunc + ddq if=/dev/zero bs=1 seek=$n count=$((0x8000 - $n)) of=$1 conv=notrunc + fi ;; *) ddq if=/dev/zero bs=1k count=32 of=$1 conv=notrunc ;; esac case "${2/--/-}" in @@ -452,10 +519,19 @@ 23117) echo "The file $1 is already an EXE file." 1>&2 && exit 1;; 0) [ -x /usr/bin/isohybrid ] && isohybrid $1;; esac - + + gpt= ; [ $(get 466 $1) -eq 65263 ] && gpt=1 + mac= ; [ $(get 2048 $1) -eq 19792 ] && mac=1 echo "Read hybrid & tazlito data..." - ddq if=$1 bs=512 count=1 of=/tmp/hybrid$$ - ddq if=$1 bs=512 skip=2 count=20 of=/tmp/tazlito$$ + if [ -n "gpt" ]; then + echo "GUID Partition Table..." + n=3; [ -n "mac" ] && n=9 && echo "Apple Partition Table..." + ddq if=$1 bs=512 count=$n of=/tmp/hybrid$$ + ddq if=$1 bs=512 skip=44 count=20 of=/tmp/tazlito$$ + else + ddq if=$1 bs=512 count=1 of=/tmp/hybrid$$ + ddq if=$1 bs=512 skip=2 count=20 of=/tmp/tazlito$$ + fi add_win32exe $1 /tmp/hybrid$$ add_tazlito_info $1 /tmp/tazlito$$ rm -f /tmp/tazlito$$ /tmp/hybrid$$ diff -r ca1cc546e49c -r 31e215a4b9bb syslinux/stuff/iso2exe/taziso --- a/syslinux/stuff/iso2exe/taziso Fri Sep 30 21:17:41 2016 +0200 +++ b/syslinux/stuff/iso2exe/taziso Fri Sep 30 21:29:58 2016 +0200 @@ -756,7 +756,8 @@ gotposixovl() { - mount.posixovl 2>&1 | grep -qi usage && menuitem "$@" + mount.posixovl 2>&1 | grep -qi usage && gotcdfile 'rootfs*.gz' && + menuitem "$@" } gotposixovlzip() @@ -774,6 +775,11 @@ gotcdfile "$1" && menuitem "$@" } +gottazusb() +{ + gotcdfile 'rootfs*.gz' && xfile tazusb "$@" +} + isbzImage() { [ $(get 514 $file 4) -eq 1400005704 ] && @@ -869,6 +875,11 @@ hascustomconf && menuitem "$@" } +hasflavor() +{ + [ -x /usr/bin/tazlito ] && [ -s $media/boot/bzImage ] && menuitem "$@" +} + gotisomd5() { [ "$(which md5sum 2> /dev/null)" ] && @@ -1081,6 +1092,7 @@ flavdata() { [ $(get 1024 "$ISO") -eq 35615 ] && n=2 || n=$((1+$(get 417 "$ISO" 1))) + [ $n -eq 4 ] && n=20 dd if="$ISO" bs=512 skip=$n count=20 2>/dev/null | zcat 2>/dev/null } @@ -1191,9 +1203,10 @@ floppyset() { - gotcdfile isolinux.cfg + gotcdfile 'isolinux.cfg' parse_isolinux < $file > /tmp/var$$ . /tmp/var$$ + [ -z "$KERNEL" ] && echo "Can't parse isolinux.cfg" && return for i in $media/$KERNEL $(dirname $file)/$KERNEL $media/$(locase $KERNEL) \ $(dirname $file)/$(locase $KERNEL); do [ -s $i ] && KERNEL=$i && break @@ -1356,10 +1369,10 @@ $(gotposixovl "installtaz" "Hard disk installation (TAZUSB way)") \ $(gotposixovlzip "inst2zip" "ZIP installation archive (UMSDOS way)") \ $(gotposixovlzip "insttaz2zip" "ZIP installation archive (TAZUSB way)") \ -$(xfile tazusb "usbkey" "USB key read/write installation") \ +$(gottazusb "usbkey" "USB key read/write installation") \ $(ishybrid "usbbootkey" "USB boot key (read only)") \ $(hasflavinfo "showfavinfo" "Show flavor extra info") \ -$(xfile tazlito "flavor" "Get flavor file") \ +$(hasflavor "flavor" "Get flavor file") \ $(cdfile isolinux.cfg "floppyset" "Boot floppy set") \ $(hastazboot "tazboot" "Get tazboot.exe Linux loader") \ $(cdexe boot/bzImage "bzimage" "Get linux DOS/EXE file") \ diff -r ca1cc546e49c -r 31e215a4b9bb syslinux/stuff/tools/isohybrid.sh --- a/syslinux/stuff/tools/isohybrid.sh Fri Sep 30 21:17:41 2016 +0200 +++ b/syslinux/stuff/tools/isohybrid.sh Fri Sep 30 21:29:58 2016 +0200 @@ -14,7 +14,7 @@ heads=64 # zipdrive-style geometry sectors=32 partype=23 # "Windows hidden IFS" -entry=1 +entry= id=$(( ($RANDOM <<16) + $RANDOM)) offset=0 partok=0 @@ -74,15 +74,111 @@ readiso $1 $2 4 | od -N 4 -t u4 -An } +# read a 16 bits data +read16() +{ + readiso $1 $2 2 | od -N 2 -t u2 -An +} + +# read a 8 bits data +read8() +{ + readiso $1 $2 1 | od -N 1 -t u1 -An +} + # write a 32 bits data store32() { - n=$2; for i in 1 2 3 4; do - printf '\\\\x%02X' $(($n & 255)) - n=$(($n >> 8)) + n=$2; for i in 0 8 16 24; do + printf '\\\\x%02X' $((($n >> $i) & 255)) done | xargs echo -en | ddq bs=1 conv=notrunc of=$iso seek=$(($1)) } +store32sw() +{ + n=$2; for i in 24 16 8 0; do + printf '\\\\x%02X' $((($n >> $i) & 255)) + done | xargs echo -en | ddq bs=1 conv=notrunc of=$iso seek=$(($1)) +} + +crc32() +{ + t0=00000000; t1=77073096; t2=EE0E612C; t3=990951BA; + t4=076DC419; t5=706AF48F; t6=E963A535; t7=9E6495A3; + t8=0EDB8832; t9=79DCB8A4; t10=E0D5E91E; t11=97D2D988; + t12=09B64C2B; t13=7EB17CBD; t14=E7B82D07; t15=90BF1D91; + t16=1DB71064; t17=6AB020F2; t18=F3B97148; t19=84BE41DE; + t20=1ADAD47D; t21=6DDDE4EB; t22=F4D4B551; t23=83D385C7; + t24=136C9856; t25=646BA8C0; t26=FD62F97A; t27=8A65C9EC; + t28=14015C4F; t29=63066CD9; t30=FA0F3D63; t31=8D080DF5; + t32=3B6E20C8; t33=4C69105E; t34=D56041E4; t35=A2677172; + t36=3C03E4D1; t37=4B04D447; t38=D20D85FD; t39=A50AB56B; + t40=35B5A8FA; t41=42B2986C; t42=DBBBC9D6; t43=ACBCF940; + t44=32D86CE3; t45=45DF5C75; t46=DCD60DCF; t47=ABD13D59; + t48=26D930AC; t49=51DE003A; t50=C8D75180; t51=BFD06116; + t52=21B4F4B5; t53=56B3C423; t54=CFBA9599; t55=B8BDA50F; + t56=2802B89E; t57=5F058808; t58=C60CD9B2; t59=B10BE924; + t60=2F6F7C87; t61=58684C11; t62=C1611DAB; t63=B6662D3D; + t64=76DC4190; t65=01DB7106; t66=98D220BC; t67=EFD5102A; + t68=71B18589; t69=06B6B51F; t70=9FBFE4A5; t71=E8B8D433; + t72=7807C9A2; t73=0F00F934; t74=9609A88E; t75=E10E9818; + t76=7F6A0DBB; t77=086D3D2D; t78=91646C97; t79=E6635C01; + t80=6B6B51F4; t81=1C6C6162; t82=856530D8; t83=F262004E; + t84=6C0695ED; t85=1B01A57B; t86=8208F4C1; t87=F50FC457; + t88=65B0D9C6; t89=12B7E950; t90=8BBEB8EA; t91=FCB9887C; + t92=62DD1DDF; t93=15DA2D49; t94=8CD37CF3; t95=FBD44C65; + t96=4DB26158; t97=3AB551CE; t98=A3BC0074; t99=D4BB30E2; + t100=4ADFA541; t101=3DD895D7; t102=A4D1C46D; t103=D3D6F4FB; + t104=4369E96A; t105=346ED9FC; t106=AD678846; t107=DA60B8D0; + t108=44042D73; t109=33031DE5; t110=AA0A4C5F; t111=DD0D7CC9; + t112=5005713C; t113=270241AA; t114=BE0B1010; t115=C90C2086; + t116=5768B525; t117=206F85B3; t118=B966D409; t119=CE61E49F; + t120=5EDEF90E; t121=29D9C998; t122=B0D09822; t123=C7D7A8B4; + t124=59B33D17; t125=2EB40D81; t126=B7BD5C3B; t127=C0BA6CAD; + t128=EDB88320; t129=9ABFB3B6; t130=03B6E20C; t131=74B1D29A; + t132=EAD54739; t133=9DD277AF; t134=04DB2615; t135=73DC1683; + t136=E3630B12; t137=94643B84; t138=0D6D6A3E; t139=7A6A5AA8; + t140=E40ECF0B; t141=9309FF9D; t142=0A00AE27; t143=7D079EB1; + t144=F00F9344; t145=8708A3D2; t146=1E01F268; t147=6906C2FE; + t148=F762575D; t149=806567CB; t150=196C3671; t151=6E6B06E7; + t152=FED41B76; t153=89D32BE0; t154=10DA7A5A; t155=67DD4ACC; + t156=F9B9DF6F; t157=8EBEEFF9; t158=17B7BE43; t159=60B08ED5; + t160=D6D6A3E8; t161=A1D1937E; t162=38D8C2C4; t163=4FDFF252; + t164=D1BB67F1; t165=A6BC5767; t166=3FB506DD; t167=48B2364B; + t168=D80D2BDA; t169=AF0A1B4C; t170=36034AF6; t171=41047A60; + t172=DF60EFC3; t173=A867DF55; t174=316E8EEF; t175=4669BE79; + t176=CB61B38C; t177=BC66831A; t178=256FD2A0; t179=5268E236; + t180=CC0C7795; t181=BB0B4703; t182=220216B9; t183=5505262F; + t184=C5BA3BBE; t185=B2BD0B28; t186=2BB45A92; t187=5CB36A04; + t188=C2D7FFA7; t189=B5D0CF31; t190=2CD99E8B; t191=5BDEAE1D; + t192=9B64C2B0; t193=EC63F226; t194=756AA39C; t195=026D930A; + t196=9C0906A9; t197=EB0E363F; t198=72076785; t199=05005713; + t200=95BF4A82; t201=E2B87A14; t202=7BB12BAE; t203=0CB61B38; + t204=92D28E9B; t205=E5D5BE0D; t206=7CDCEFB7; t207=0BDBDF21; + t208=86D3D2D4; t209=F1D4E242; t210=68DDB3F8; t211=1FDA836E; + t212=81BE16CD; t213=F6B9265B; t214=6FB077E1; t215=18B74777; + t216=88085AE6; t217=FF0F6A70; t218=66063BCA; t219=11010B5C; + t220=8F659EFF; t221=F862AE69; t222=616BFFD3; t223=166CCF45; + t224=A00AE278; t225=D70DD2EE; t226=4E048354; t227=3903B3C2; + t228=A7672661; t229=D06016F7; t230=4969474D; t231=3E6E77DB; + t232=AED16A4A; t233=D9D65ADC; t234=40DF0B66; t235=37D83BF0; + t236=A9BCAE53; t237=DEBB9EC5; t238=47B2CF7F; t239=30B5FFE9; + t240=BDBDF21C; t241=CABAC28A; t242=53B39330; t243=24B4A3A6; + t244=BAD03605; t245=CDD70693; t246=54DE5729; t247=23D967BF; + t248=B3667A2E; t249=C4614AB8; t250=5D681B02; t251=2A6F2B94; + t252=B40BBE37; t253=C30C8EA1; t254=5A05DF1B; t255=2D02EF8D; + crc=$((0xFFFFFFFF)) + dd if=$iso bs=1 skip=$(($1)) count=$(($2)) 2> /dev/null | \ + od -v -w1 -t u1 -An | { + while read n; do + local x=$((($crc ^ $n) & 255)) + eval x=0x\$t$x + crc=$(((($crc >> 8) & 0x00FFFFFF) ^ $x)) + done + echo $(($crc ^ 0xFFFFFFFF)) + } +} + main() { uudecode | gunzip | ddq bs=512 count=1 of=$iso conv=notrunc \ @@ -90,13 +186,44 @@ store32 432 $(($lba * 4)) store32 440 $id store32 508 0xAA550000 - e=$(( (($entry -1) % 4) *16 +446)) + e=$(( ((${entry:-1} -1) % 4) *16 +446)) store32 $e 0x10080 esect=$(( ($sectors + ((($cylinders -1) & 0x300) >>2)) <<16)) ecyl=$(( (($cylinders -1) & 0xff) <<24)) store32 $(($e + 4)) $(($partype + (($heads - 1) <<8) +$esect +$ecyl)) store32 $(($e + 8)) $offset store32 $(($e + 12)) $(($cylinders * $heads * $sectors)) + if [ -n "$efi_ofs" ]; then + [ $(read16 0 1024) -eq 35615 -a $(read16 11 0) -ne 35615 ] && + ddq bs=512 conv=notrunc skip=2 seek=44 count=20 if=$iso of=$iso + store32 $((446+16)) $((0xFFFFFE00)) + store32 $((446+16+4)) $((0xFFFFFEEF)) + store32 $((446+16+8)) $efi_ofs + store32 $((446+16+12)) $efi_len + uudecode <