[PATCH v2 0/5] fs: fat: calculate FAT type based on cluster count
christian.taedcke-oss at weidmueller.com
christian.taedcke-oss at weidmueller.com
Fri Nov 10 10:42:10 CET 2023
From: Christian Taedcke <christian.taedcke at weidmueller.com>
This series fixes an issue where the FAT type (FAT12, FAT16) is not
correctly detected, e.g. when the BPB field BS_FilSysType contains the
valid value "FAT ".
This issue occures, for example, if a partition is formatted by
swupdate using its diskformat handler. swupdate uses the FAT library
from http://elm-chan.org/fsw/ff/ internally.
See https://groups.google.com/g/swupdate/c/7Yc3NupjXx8 for a
discussion in the swupdate mailing list.
Please refer to the commit messages for more details.
1. Added bootsector checks
Most tests from https://www.win.tue.nl/~aeb/linux/fs/fat/fat-2.html
are added in the latest commit. Only the tests VIII, IX and X are
not implemented.
I also checked the Linux kernel code (v6.6) and did not find any
checks on 'vistart->fs_type'. This is the reason why is skipped them
here.
See section '3. Size comparisons' for the impact on the binary size.
2. Tests
I will try to implement some tests for the next version of this series.
3. Size comparisons
I executed bloat-o-meter from the Linux kernel for an arm64
target (config xilinx_zynqmp_mini_emmc0_defconfig):
Comparison of the binary spl/u-boot-spl between master (rev
e17d174773e9ba9447596708e702b7382e47a6cf) and this patch
series (including the added validity checks of the boot sector):
add/remove: 0/0 grow/shrink: 1/1 up/down: 100/-12 (88)
Function old new delta
read_bootsectandvi 308 408 +100
fat_itr_root 444 432 -12
Total: Before=67977, After=68065, chg +0.13%
When compare the size of the binary spl/u-boot-spl between master this
series without the the validity checks of the boot sector (so i removed the
last commit in this series):
add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-24 (-24)
Function old new delta
read_bootsectandvi 308 296 -12
fat_itr_root 444 432 -12
Total: Before=67977, After=67953, chg -0.04%
So the size of the spl on this arm64 target increases by 88 bytes for
this series. When i remove the validity check the size decreases by 24 bytes.
Changes in v2:
- Use get_unaligned_le16 instead of custom macro
- Move code change in test/image/spl_load_fs.c into separate commit
- Use get_unaligned_le16 instead of custom macro
- Extract FAT32 logic from determine_fat_bits() into
read_bootsectandvi()
- Rename determine_fat_bits() to determine_legacy_fat_bits()
- Keep one goto label instead of removing both
- Move changing gotos from read_bootsectandvi() into separate commit
- Add validity checks for boot sector
Christian Taedcke (5):
fs: fat: use get_unaligned_le16 to convert u8[2] to u16
test: spl: Remove usage of FAT32_SIGN
fs: fat: calculate FAT type based on cluster count
fs: fat: simplify gotos from read_bootsectandvi
fs: fat: add bootsector validity check
fs/fat/fat.c | 114 +++++++++++++++++++++++++++++----------
include/fat.h | 6 ---
test/image/spl_load_fs.c | 2 +-
3 files changed, 88 insertions(+), 34 deletions(-)
--
2.34.1
More information about the U-Boot
mailing list