[PATCH v3 0/9] fs: fat: calculate FAT type based on cluster count

christian.taedcke-oss at weidmueller.com christian.taedcke-oss at weidmueller.com
Wed Nov 15 13:44:15 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 commit 'fs: fat: add bootsector validity check'.
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 '2. Size comparisons' for the impact on the binary size.

2. 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:

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 v3:
- Enable some fs tests for FAT12
- Add test to detect fat fs type

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 (9):
  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
  test: Add support to create a fat12 fs
  test: fs: Add fat12 to supported fs of some tests
  test: Add size granularity parameter to mk_fs
  test: fs: Add test to detect fat type

 fs/fat/fat.c                         | 114 ++++++++++++++++++++-------
 include/fat.h                        |   6 --
 test/image/spl_load_fs.c             |   2 +-
 test/py/tests/fs_helper.py           |  11 ++-
 test/py/tests/test_fs/conftest.py    |  53 ++++++++++++-
 test/py/tests/test_fs/test_fs_fat.py |  25 ++++++
 6 files changed, 170 insertions(+), 41 deletions(-)
 create mode 100644 test/py/tests/test_fs/test_fs_fat.py

-- 
2.34.1



More information about the U-Boot mailing list