Skip to content

Commit 9130759

Browse files
committed
rpi-make-boot-image: Fix FAT12 image generation
mkfs.vfat -F option was not specified which caused mkfs to deduce the FAT type on it's own. For a small enough image FAT12 would be selected. 805a4fd introduced cluster calculation function that ends up only using FAT32 or FAT16. Creating a small image would fail with message : mkfs.fat: Not enough or too many clusters for filesystem - try less or more sectors per cluster
1 parent 805a4fd commit 9130759

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

tools/rpi-make-boot-image

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -205,16 +205,22 @@ createstaging() {
205205

206206
IMAGE_SIZE="$((clusters * cluster_size))"
207207

208+
root_dir_sectors="$((((ROOT_DIR_ENTRIES * 32) + cluster_size - 1)/cluster_size))"
208209
# FAT32/FAT16 determined by number of clusters
209210
if [ "$clusters" -gt "65526" ]; then
210211
FAT_SIZE="32"
211-
fat_table_sectors="$(((((clusters + 2)*4) + SECTOR_SIZE - 1)/SECTOR_SIZE))"
212-
else
212+
fat_table_sectors="$(((((clusters + 2)*4) + SECTOR_SIZE - 1)/SECTOR_SIZE))"
213+
elif [ "$clusters" -gt "4085" ]; then
213214
FAT_SIZE="16"
214-
fat_table_sectors="$(((((clusters + 2)*2) + SECTOR_SIZE - 1)/SECTOR_SIZE))"
215-
# Add some sectors based on ROOT_DIR_ENTRIES
216-
root_dir_sectors="$((((ROOT_DIR_ENTRIES * 32) + cluster_size - 1)/cluster_size))"
217-
fat_table_sectors="$((fat_table_sectors + root_dir_sectors))"
215+
fat_table_sectors="$(((((clusters + 2)*2) + SECTOR_SIZE - 1)/SECTOR_SIZE))"
216+
# Add some sectors based on ROOT_DIR_ENTRIES
217+
fat_table_sectors="$((fat_table_sectors + root_dir_sectors))"
218+
else
219+
FAT_SIZE="12"
220+
#12 bits per cluster = 3 bytes for 2 clusters
221+
fat_table_sectors=$(((((clusters + 2)*3+1) / 2 + SECTOR_SIZE - 1)/SECTOR_SIZE))
222+
# Add some sectors based on ROOT_DIR_ENTRIES
223+
fat_table_sectors="$((fat_table_sectors + root_dir_sectors))"
218224
fi
219225
IMAGE_SIZE="$((IMAGE_SIZE + fat_table_sectors * SECTOR_SIZE))"
220226
IMAGE_SIZE="$(((IMAGE_SIZE + 1023)/1024))"

0 commit comments

Comments
 (0)