# HG changeset patch # User Pascal Bellard # Date 1526550811 -7200 # Node ID 6b369e63e8f648ca4983811e7c2cd98a06d77bce # Parent 5d84fadfd92852384b7bd44a607fd653d92cde2c uefi: add fat32 support diff -r 5d84fadfd928 -r 6b369e63e8f6 tazlito --- a/tazlito Wed May 16 10:03:24 2018 +0200 +++ b/tazlito Thu May 17 11:53:31 2018 +0200 @@ -311,10 +311,19 @@ fix_efi_boot_img_size $1 $2 $n $efiblock # Build file list tree - fatsz=$(get 22 "$2/boot/isolinux/efi.img") resv=$(get 14 "$2/boot/isolinux/efi.img") - basecluster=$((($resv+2*$fatsz)/4+$efiblock-1)) - hd "$2/boot/isolinux/efi.img" | awk 'BEGIN { skiphead=4 } + if [ $(get 57 "$2/boot/isolinux/efi.img" 1) -ne 49 ]; then + skiphead=5 + fatsz=$(get 36 "$2/boot/isolinux/efi.img" 4) + basecluster=$((($resv+2*$fatsz)/4+$efiblock-2)) + dd if=$1 bs=512 skip=$(($efiblock*4)) count=3 \ + of=$1 seek=$(($efiblock*4+3)) conv=notrunc + else + skiphead=4 + fatsz=$(get 22 "$2/boot/isolinux/efi.img") + basecluster=$((($resv+2*$fatsz)/4+$efiblock-1)) + fi 2> /dev/null + hd "$2/boot/isolinux/efi.img" | awk 'BEGIN { skiphead='$skiphead' } { if (skiphead!=0) { if ($1=="*") skiphead-- @@ -374,6 +383,7 @@ ' | ( while read offset cluster file; do cluster=$(($(first_block "$2/$file")-$basecluster)) set32 $(($efiblock*2048+0x$offset+10)) $cluster "$1" 16 + set32 $(($efiblock*2048+0x$offset+4)) $(($cluster>>16)) "$1" 16 echo "$cluster $((($(stat -c %s "$2/$file")+2047)/2048)) $file" done @@ -386,12 +396,13 @@ if (state==0) { if ($2=="") { if ($1==12849) fat=12 - else fat=16 + else if ($1==13873) fat=16 + else fat=32 state++ } else { for (i=1;i<$2;i++) c[$1+i]=$1+i - c[$1+$2]=65535 + c[$1+$2]=268435455 } next } @@ -410,10 +421,21 @@ next } n=$1*256+prev + if (fat==32) { + prev=n + state=13 + next + } } else if (state==3) { n=$1*16+prev } + else if (state==13) { + prev=$1*65536+prev + state++ + next + } + else n=$1*16777216+prev if (n!=0) c[pos+1]=n pos++ state=1 @@ -423,7 +445,11 @@ if (c[i]=="") c[i]=0 if (c[i+1]=="") c[i+1]=0 if (fat==12) printf "0 %02X %1X%1X %02X |\n",c[i]%256,c[i+1]%16,(c[i]/256)%16,(c[i+1]/16)%256 - else printf "0 %02X %02X %02X %02X |\n",c[i]%256,(c[i]/256)%256,c[i+1]%256,(c[i+1]/256)%256 + else if (fat==16) printf "0 %02X %02X %02X %02X |\n",c[i]%256,(c[i]/256)%256,c[i+1]%256,(c[i+1]/256)%256 + else { + printf "0 %02X %02X %02X %02X |\n",c[i]%256,(c[i]/256)%256,(c[i]/65536)%256,(c[i]/16777216)%256 + printf "0 %02X %02X %02X %02X |\n",c[i+1]%256,(c[i+1]/256)%256,(c[i+1]/65536)%256,(c[i+1]/16777216)%256 + } } }' | hexdump -R | dd of="$1" seek=$((4*$efiblock+$fatsz+$resv)) \ conv=notrunc bs=512 > /dev/null 2>&1 @@ -480,19 +506,30 @@ print n }') local clusters=$(($fclust+$dclust)) - if [ $clusters -lt 4085 ]; then + if [ $clusters -lt 4068 ]; then fsect=$(((($clusters+2)*3+1023)/1024)) ftype="31 32" fhead="F8 FF FF" - else + rsect=$(( 1+ ((2*$fsect)-1)%4 )) + fsz="$(printf "%04X" $fsect | sed 's/\(..\)\(..\)/\2 \1/')" + rootsz=2 + elif [ $clusters -lt 65525 ]; then fsect=$((($clusters+2+255)/256)) ftype="31 36" fhead="F8 FF FF FF" + rsect=$(( 1+ ((2*$fsect)-1)%4 )) + fsz="$(printf "%04X" $fsect | sed 's/\(..\)\(..\)/\2 \1/')" + rootsz=2 + else + fsect=$((($clusters+2+127)/128)) + ftype="33 32" + fhead="F8 FF FF 0F FF FF FF FF F8 FF FF 0F" + rsect=$(( 6+ ((2*$fsect)-6)%4 )) + fsz="$(printf "%08X" $fsect | sed 's/\(..\)\(..\)\(..\)\(..\)/\4 \3 \2 \1/')" + rootsz=1 fi - rsect=$(( 1+ ((2*$fsect)-1)%4 )) - fsz="$(printf "%02X %02X" $(($fsect%256)) $((($fsect>>8)%256)))" # reserved + fat*2 + root dir + dirs - count=$((($rsect + $fsect*2)/4 + 2 + $dclust )) + count=$((($rsect + $fsect*2)/4 + $rootsz + $dclust )) s=$((($count+$fclust)*4)) if [ $s -gt 65535 ]; then size="00 00" @@ -506,16 +543,36 @@ count=$s 2> /dev/null # Create boot sector - echo -en '\x55\xAA' | dd of=$basedir/boot/isolinux/efi.img \ - seek=510 bs=1 conv=notrunc 2> /dev/null - hexdump -R < /dev/null + if [ "$ftype" == "33 32" ]; then + hexdump -R < /dev/null # Create fats echo "0 $fhead |" | hexdump -R | dd of=$basedir/boot/isolinux/efi.img \ @@ -523,6 +580,11 @@ echo "0 $fhead |" | hexdump -R | dd of=$basedir/boot/isolinux/efi.img \ seek=$(($rsect+$fsect)) bs=512 conv=notrunc 2> /dev/null + # Add label + echo "0 53 59 53 54 45 4d 00 00 00 00 00 08 |" | hexdump -R | \ + dd of=$basedir/boot/isolinux/efi.img bs=512 conv=notrunc \ + seek=$(($rsect+$fsect+$fsect)) 2> /dev/null + mkdir -p /tmp/mnt$$ mount -o loop $basedir/boot/isolinux/efi.img /tmp/mnt$$ ( cd $basedir; find efi -type d | cpio -o -H newc ) | \