tazlito rev 499

uefi: add fat32 support
author Pascal Bellard <pascal.bellard@slitaz.org>
date Thu May 17 11:53:31 2018 +0200 (16 months ago)
parents 5d84fadfd928
children 35f0bc818f6a
files tazlito
line diff
     1.1 --- a/tazlito	Wed May 16 10:03:24 2018 +0200
     1.2 +++ b/tazlito	Thu May 17 11:53:31 2018 +0200
     1.3 @@ -311,10 +311,19 @@
     1.4  	fix_efi_boot_img_size $1 $2 $n $efiblock
     1.5  	
     1.6  	# Build file list tree
     1.7 -	fatsz=$(get 22 "$2/boot/isolinux/efi.img")
     1.8  	resv=$(get 14 "$2/boot/isolinux/efi.img")
     1.9 -	basecluster=$((($resv+2*$fatsz)/4+$efiblock-1))
    1.10 -	hd "$2/boot/isolinux/efi.img" | awk 'BEGIN { skiphead=4 }
    1.11 +	if [ $(get 57 "$2/boot/isolinux/efi.img" 1) -ne 49 ]; then
    1.12 +		skiphead=5
    1.13 +		fatsz=$(get 36 "$2/boot/isolinux/efi.img" 4)
    1.14 +		basecluster=$((($resv+2*$fatsz)/4+$efiblock-2))
    1.15 +		dd if=$1 bs=512 skip=$(($efiblock*4)) count=3 \
    1.16 +			of=$1 seek=$(($efiblock*4+3)) conv=notrunc
    1.17 +	else
    1.18 +		skiphead=4
    1.19 +		fatsz=$(get 22 "$2/boot/isolinux/efi.img")
    1.20 +		basecluster=$((($resv+2*$fatsz)/4+$efiblock-1))
    1.21 +	fi 2> /dev/null
    1.22 +	hd "$2/boot/isolinux/efi.img" | awk 'BEGIN { skiphead='$skiphead' }
    1.23  {
    1.24    if (skiphead!=0) {
    1.25      if ($1=="*") skiphead--
    1.26 @@ -374,6 +383,7 @@
    1.27  ' | (	while read offset cluster file; do
    1.28  		cluster=$(($(first_block "$2/$file")-$basecluster))
    1.29  		set32 $(($efiblock*2048+0x$offset+10)) $cluster "$1" 16
    1.30 +		set32 $(($efiblock*2048+0x$offset+4)) $(($cluster>>16)) "$1" 16
    1.31  		echo "$cluster $((($(stat -c %s "$2/$file")+2047)/2048)) $file"
    1.32  	done
    1.33  
    1.34 @@ -386,12 +396,13 @@
    1.35    if (state==0) {
    1.36      if ($2=="") {
    1.37        if ($1==12849) fat=12
    1.38 -      else fat=16
    1.39 +      else if ($1==13873) fat=16
    1.40 +      else fat=32
    1.41        state++
    1.42      }
    1.43      else {
    1.44        for (i=1;i<$2;i++) c[$1+i]=$1+i
    1.45 -      c[$1+$2]=65535
    1.46 +      c[$1+$2]=268435455
    1.47      }
    1.48      next
    1.49    }
    1.50 @@ -410,10 +421,21 @@
    1.51        next
    1.52      }
    1.53      n=$1*256+prev
    1.54 +    if (fat==32) {
    1.55 +      prev=n
    1.56 +      state=13
    1.57 +      next
    1.58 +    }
    1.59    }
    1.60    else if (state==3) {
    1.61      n=$1*16+prev
    1.62    }
    1.63 +  else if (state==13) {
    1.64 +    prev=$1*65536+prev
    1.65 +    state++
    1.66 +    next
    1.67 +  }
    1.68 +  else n=$1*16777216+prev
    1.69    if (n!=0) c[pos+1]=n
    1.70    pos++
    1.71    state=1
    1.72 @@ -423,7 +445,11 @@
    1.73      if (c[i]=="") c[i]=0
    1.74      if (c[i+1]=="") c[i+1]=0
    1.75      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
    1.76 -    else printf "0  %02X %02X %02X %02X |\n",c[i]%256,(c[i]/256)%256,c[i+1]%256,(c[i+1]/256)%256
    1.77 +    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
    1.78 +    else {
    1.79 +      printf "0  %02X %02X %02X %02X |\n",c[i]%256,(c[i]/256)%256,(c[i]/65536)%256,(c[i]/16777216)%256
    1.80 +      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
    1.81 +    }
    1.82    }
    1.83  }' | hexdump -R | dd of="$1" seek=$((4*$efiblock+$fatsz+$resv)) \
    1.84  		conv=notrunc bs=512 > /dev/null 2>&1
    1.85 @@ -480,19 +506,30 @@
    1.86  			print n
    1.87  		}')
    1.88  	local clusters=$(($fclust+$dclust))
    1.89 -	if [ $clusters -lt 4085 ]; then
    1.90 +	if [ $clusters -lt 4068 ]; then
    1.91  		fsect=$(((($clusters+2)*3+1023)/1024))
    1.92  		ftype="31 32"
    1.93  		fhead="F8 FF FF"
    1.94 -	else
    1.95 +		rsect=$(( 1+ ((2*$fsect)-1)%4 ))
    1.96 +		fsz="$(printf "%04X" $fsect | sed 's/\(..\)\(..\)/\2 \1/')"
    1.97 +		rootsz=2
    1.98 +	elif [ $clusters -lt 65525 ]; then
    1.99  		fsect=$((($clusters+2+255)/256))
   1.100  		ftype="31 36"
   1.101  		fhead="F8 FF FF FF"
   1.102 +		rsect=$(( 1+ ((2*$fsect)-1)%4 ))
   1.103 +		fsz="$(printf "%04X" $fsect | sed 's/\(..\)\(..\)/\2 \1/')"
   1.104 +		rootsz=2
   1.105 +	else
   1.106 +		fsect=$((($clusters+2+127)/128))
   1.107 +		ftype="33 32"
   1.108 +		fhead="F8 FF FF 0F FF FF FF FF F8 FF FF 0F"
   1.109 +		rsect=$(( 6+ ((2*$fsect)-6)%4 ))
   1.110 +		fsz="$(printf "%08X" $fsect | sed 's/\(..\)\(..\)\(..\)\(..\)/\4 \3 \2 \1/')"
   1.111 +		rootsz=1
   1.112  	fi
   1.113 -	rsect=$(( 1+ ((2*$fsect)-1)%4 ))
   1.114 -	fsz="$(printf "%02X %02X" $(($fsect%256)) $((($fsect>>8)%256)))"
   1.115  	#       reserved +   fat*2   + root dir  +   dirs
   1.116 -	count=$((($rsect + $fsect*2)/4 +  2  + $dclust ))
   1.117 +	count=$((($rsect + $fsect*2)/4 +  $rootsz  + $dclust ))
   1.118  	s=$((($count+$fclust)*4))
   1.119  	if [ $s -gt 65535 ]; then
   1.120  		size="00 00"
   1.121 @@ -506,16 +543,36 @@
   1.122  		count=$s 2> /dev/null
   1.123  
   1.124  	# Create boot sector
   1.125 -	echo -en '\x55\xAA' | dd of=$basedir/boot/isolinux/efi.img \
   1.126 -		seek=510 bs=1 conv=notrunc 2> /dev/null
   1.127 -	hexdump -R <<EOT | dd of=$basedir/boot/isolinux/efi.img \
   1.128 -		conv=notrunc 2> /dev/null
   1.129 +	if [ "$ftype" == "33 32" ]; then
   1.130 +		hexdump -R <<EOT | dd of=$basedir/boot/isolinux/efi.img \
   1.131 +			conv=notrunc
   1.132 +0  eb 58 90 53 6c 69 54 61  7a 00 00 00 02 04 $rsect 00  |
   1.133 +0  02 00 00 $size f8 00 00  20 00 40 00 00 00 00 00  |
   1.134 +0  $size32     $fsz         00 00 00 00 02 00 00 00  |
   1.135 +0  01 00 03 00 00 00 00 00  00 00 00 00 00 00 00 00  |  
   1.136 +0  80 00 29 00 00 00 00 53  59 53 54 45 4d 00 00 00  |
   1.137 +0  00 00 46 41 54 $ftype 20 20 20 cd 18 cd 19 eb fa  |
   1.138 +EOT
   1.139 +		while read ofs data; do
   1.140 +			echo "0 ${data//:/ } |" | hexdump -R | dd conv=notrunc \
   1.141 +			bs=1 seek=$ofs of=$basedir/boot/isolinux/efi.img
   1.142 +		done <<EOT
   1.143 +510	55:aa:52:52:61:41
   1.144 +996	72:72:41:61:ff:ff:ff:ff:02
   1.145 +1022	55:aa
   1.146 +EOT
   1.147 +	else
   1.148 +		echo -en '\x55\xAA' | dd of=$basedir/boot/isolinux/efi.img \
   1.149 +			seek=510 bs=1 conv=notrunc
   1.150 +		hexdump -R <<EOT | dd of=$basedir/boot/isolinux/efi.img \
   1.151 +			conv=notrunc
   1.152  0  eb 3c 90 53 6c 69 54 61  7a 00 00 00 02 04 $rsect 00  |
   1.153  0  02 40 00 $size f8 $fsz   20 00 40 00 00 00 00 00  |
   1.154 -0  $size32     80 00 29 00  00 00 00 4e 4f 20 4e 41  |
   1.155 -0  4d 45 20 20 20 20 46 41  54 $ftype 20 20 20 cd 18  |
   1.156 +0  $size32     80 00 29 00  00 00 00 53 59 53 54 45  |
   1.157 +0  4d 20 20 20 20 20 46 41  54 $ftype 20 20 20 cd 18  |
   1.158  0  cd 19 eb fa  |
   1.159  EOT
   1.160 +	fi 2> /dev/null
   1.161  
   1.162  	# Create fats
   1.163  	echo "0  $fhead |" | hexdump -R | dd of=$basedir/boot/isolinux/efi.img \
   1.164 @@ -523,6 +580,11 @@
   1.165  	echo "0  $fhead |" | hexdump -R | dd of=$basedir/boot/isolinux/efi.img \
   1.166  		seek=$(($rsect+$fsect)) bs=512 conv=notrunc 2> /dev/null
   1.167  
   1.168 +	# Add label
   1.169 +	echo "0  53 59 53 54 45 4d 00 00  00 00 00 08 |" | hexdump -R | \
   1.170 +		dd of=$basedir/boot/isolinux/efi.img bs=512 conv=notrunc \
   1.171 +		seek=$(($rsect+$fsect+$fsect)) 2> /dev/null
   1.172 +
   1.173  	mkdir -p /tmp/mnt$$
   1.174  	mount -o loop $basedir/boot/isolinux/efi.img /tmp/mnt$$
   1.175  	( cd $basedir; find efi -type d | cpio -o -H newc ) | \