[PATCH] fs: fat: Handle 'FAT sector size mismatch'

Tom Rini trini at konsulko.com
Tue Feb 17 16:03:36 CET 2026


On Tue, Feb 17, 2026 at 09:26:43AM +0530, Varadarajan Narayanan wrote:

> Do FAT read and write based on the device sector size
> instead of the size recorded in the FAT meta data.
> 
> FAT code issues i/o in terms of the sector size. Convert that to
> device sector size before doing the actual i/o. Additionally,
> handle leading/trailing blocks when the meta data based block
> no and i/o size is not an exact multiple of the device sector
> size or vice versa.
> 
> Tested on UFS device with sector size 4096 and meta data recorded
> sector size 512.
> 
> Signed-off-by: Varadarajan Narayanan <varadarajan.narayanan at oss.qualcomm.com>

We have two sets of problems here now.

[snip]
> diff --git a/fs/fat/fat.c b/fs/fat/fat.c
> index 9ce5df59f9b..a725d924fd9 100644
> --- a/fs/fat/fat.c
> +++ b/fs/fat/fat.c
> @@ -45,11 +45,13 @@ static void downcase(char *str, size_t len)
>  
>  static struct blk_desc *cur_dev;
>  static struct disk_partition cur_part_info;
> +static int fat_sect_size;
>  
>  #define DOS_BOOT_MAGIC_OFFSET	0x1fe
>  #define DOS_FS_TYPE_OFFSET	0x36
>  #define DOS_FS32_TYPE_OFFSET	0x52
>  
> +#if IS_ENABLED(CONFIG_SPL_FS_FAT)

This isn't the right way to test. You want IS_ENABLED(CONFIG_XPL_BUILD)
to limit this to when we're in an xPL phase. The test for
CONFIG_SPL_FS_FAT is always true on platforms with SPL and FAT support,
even when building full U-Boot.

The second problem is size growth in general:
   aarch64: (for 1/1 boards) all +950.0 rodata +14.0 text +936.0
            qemu_arm64     : all +950 rodata +14 text +936
               u-boot: add: 0/0, grow: 4/0 bytes: 936/0 (936)
                 function                                   old     new   delta
                 disk_write                                 132     596    +464
                 disk_read                                  100     544    +444
                 fat_itr_root                               428     448     +20
                 read_bootsectandvi                         408     416      +8
       arm: (for 1/1 boards) all +686.0 rodata +6.0 text +680.0
            tqma6dl_mba6_mmc: all +686 rodata +6 text +680
               u-boot: add: 0/0, grow: 4/0 bytes: 648/0 (648)
                 function                                   old     new   delta
                 disk_read                                   48     368    +320
                 disk_write                                  76     384    +308
                 fat_itr_root                               300     312     +12
                 read_bootsectandvi                         272     280      +8

So nearly a kilobyte on ARM64 and a bit more than half a kilobyte
otherwise on around 1100 platforms. Is there some re-factoring / code
sharing that can be done here?

-- 
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 228 bytes
Desc: not available
URL: <https://lists.denx.de/pipermail/u-boot/attachments/20260217/85f63c7e/attachment.sig>


More information about the U-Boot mailing list