Skip to content

Commit e896b5b

Browse files
pseregiettimg236
authored andcommitted
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 efc5da6 commit e896b5b

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
@@ -207,16 +207,22 @@ createstaging() {
207207

208208
IMAGE_SIZE="$((clusters * cluster_size))"
209209

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

0 commit comments

Comments
 (0)