01 Feb, 2013

1 commit

  • In case a function argument is known/fixed size array in C, the argument is
    still decoyed as pointer instead ( T f(U n[k]) ~= T fn(U *n) ) and therefore
    calling sizeof on the function argument will result in the size of the pointer,
    not the size of the array.

    The VFAT code contains such a bug, this patch fixes it.

    Reported-by: Aaron Williams
    Signed-off-by: Marek Vasut
    Cc: Tom Rini
    Cc: Aaron Williams
    Tested-by: Michal Simek
    Reviewed-by: Joe Hershberger

    Marek Vasut
     

26 Oct, 2012

3 commits

  • This makes the FAT filesystem API more consistent with other block-based
    filesystems. If in the future standard multi-filesystem commands such as
    "ls" or "load" are implemented, having FAT work the same way as other
    filesystems will be necessary.

    Convert cmd_fat.c to the new API, so the code looks more like other files
    implementing the same commands for other filesystems.

    Signed-off-by: Stephen Warren
    Reviewed-by: Benoît Thébaudeau

    Stephen Warren
     
  • cur_part_info.{name,type} are strings. So, we don't need to memset()
    the entire thing, just put the NULL-termination in the first byte.

    Add missing initialization of the bootable and uuid fields.

    None of these fields are actually used by fat.c. However, since it
    stores the entire disk_partition_t, we should make sure that all fields
    are valid.

    Signed-off-by: Stephen Warren
    Reviewed-by: Benoît Thébaudeau

    Stephen Warren
     
  • A future patch will implement the more standard filesystem API
    fat_set_blk_dev(). This API has no way to know which partition number
    the partition represents. Equally, future DM rework will make the
    concept of partition number harder to pass around.

    So, simply remove cur_part_nr from fat.c; its only use is in a
    diagnostic printf, and the context where it's printed should make it
    obvious which partition is referred to anyway (since the partition ID
    would come from the user command-line that caused it).

    Signed-off-by: Stephen Warren
    Reviewed-by: Benoît Thébaudeau

    Stephen Warren
     

17 Oct, 2012

1 commit

  • The mkcksum() function now takes one parameter, the pointer to
    11-byte wide character array, which it then operates on.

    Currently, the function is wrongly passed (dir_entry)->name, which
    is only 8-byte wide character array. Though by further inspecting
    the dir_entry structure, it can be noticed that the name[8] entry
    is immediatelly followed by ext[3] entry. Thus, name[8] and ext[3]
    in the dir_entry structure actually work as this 11-byte wide array
    since they're placed right next to each other by current compiler
    behavior.

    Depending on this is obviously wrong, thus fix this by correctly
    passing both (dir_entry)->name and (dir_entry)->ext to the mkcksum()
    function and adjust the function appropriately.

    Signed-off-by: Marek Vasut
    Cc: Tom Rini

    Marek Vasut
     

09 Oct, 2012

1 commit

  • The recent switch to use get_device_and_partition() from do_fat_ls()
    broke the ability to access a FAT filesystem directly on a whole device;
    FAT only works within a partition on a device.

    This change makes e.g. "fatls mmc 0:0" work; explicitly requesting
    partition ID 0 is something that get_device_and_partition() fully
    supports. However, fat_register_device() expects partition ID 1 to be
    used in the full-disk case; partition ID 1 was previously implicitly
    specified when the user didn't actually specify a partition ID. Update
    fat_register_device() to expect the correct ID.

    This change does imply that if a user explicitly executes "fatls mmc 0:1"
    then this will fail, and may be a change in behaviour.

    Note that this still prevents "fatls mmc 0:auto" from working. The next
    patch will fix that.

    Signed-off-by: Stephen Warren

    Stephen Warren
     

27 Sep, 2012

1 commit

  • When storage devices contain files larger than the embedded RAM, it is
    useful to be able to read these files by chunks, e.g. for a software
    update to the embedded NAND Flash from an external storage device (USB
    stick, SD card, etc.).

    Hence, this patch makes it possible by adding a new FAT API to read
    files from a given position. This patch also adds this feature to the
    fatload command.

    Signed-off-by: Benoît Thébaudeau
    Cc: Wolfgang Denk
    Signed-off-by: Tom Rini

    Benoît Thébaudeau
     

19 Sep, 2012

1 commit


02 Sep, 2012

6 commits


22 Jun, 2012

1 commit


30 Apr, 2012

1 commit


06 Jan, 2012

2 commits

  • The FAT filesystem fails silently in inexplicable ways when given a
    filesystem with a block-size that does not match the device sector size.
    In theory this is not an unsupportable combination but requires a major
    rewrite of a lot of the filesystem. Until that occurs, the filesystem
    should detect that scenario and display a helpful error message.

    This scenario in particular occurred on a 512-byte blocksize FAT fs
    stored in an El-Torito boot volume on a CD-ROM (2048-byte sector size).

    Additionally, in many circumstances the ->block_read method will not
    return a negative number to indicate an error but instead return 0 to
    indicate the number of blocks successfully read (IE: None).

    The FAT filesystem should defensively check to ensure that it got all of
    the sectors that it asked for when reading.

    Signed-off-by: Kyle Moffett

    Kyle Moffett
     
  • The FAT filesystem code currently ends up requiring that the partition
    table be a DOS MBR, as it checks for the DOS 0x55 0xAA signature on the
    partition table (which may be Mac, EFI, ISO9660, etc) before actually
    computing the partition offset.

    This fixes support for accessing a FAT filesystem in an ISO9660 boot
    volume (El-Torito format) by reordering the filesystem checks and
    reading the 0x55 0xAA "DOS boot signature" and FAT/FAT32 magic number
    from the first sector of the partition instead of from sector 0.

    Signed-off-by: Kyle Moffett

    Fix build warning: fat.c: In function 'fat_register_device':
    fat.c:66:15: warning: variable 'found_partition' set but not used
    [-Wunused-but-set-variable]
    Signed-off-by: Wolfgang Denk

    Kyle Moffett
     

05 Jan, 2012

1 commit

  • The VFAT short alias checksum read from a long file name is only overwritten
    when another long file name appears in a directory list. Until then it renders
    short file names invisible that have the same checksum. Reset the checksum on
    first match.

    Signed-off-by: Sergei Shtylyov
    Signed-off-by: Martin Mueller

    Sergei Shtylyov
     

18 Dec, 2011

1 commit

  • The DIRENTSPERBLOCK utilizes sizeof() which will return a size_t which has no
    fixed size. Therefor use correct length modifer for printf() statement to
    prevent compiler warnings.

    This patch fixes following warning:

    ---88---

    Signed-off-by: Andreas Bießmann
    cc: Mike Frysinger
    cc: Thomas Chou
    cc: rjones@nexus-tech.net
    cc: kharris@nexus-tech.net
    Acked-by: Mike Frysinger

    Andreas Bießmann
     

08 Nov, 2011

1 commit


28 Oct, 2011

2 commits


27 Oct, 2011

1 commit

  • In some cases, saving data in RAM as a file with FAT format is required.
    This patch allows the file to be written in FAT formatted partition.

    The usage is similar with reading a file.
    First, fat_register_device function is called before file_fat_write function
    in order to set target partition.
    Then, file_fat_write function is invoked with desired file name,
    start ram address for writing data, and file size.

    Signed-off-by: Donggeun Kim
    Signed-off-by: Kyungmin Park

    Donggeun Kim
     

02 Oct, 2011

4 commits

  • Currently in do_fat_read() when reading FAT sectors, we have to divide down
    LINEAR_PREFETCH_SIZE by the sector size, whereas it's defined as 2 sectors
    worth of bytes. In order to avoid redundant multiplication/division, introduce
    #define PREFETCH_BLOCKS instead of #define LINEAR_PREFETCH_SIZE.

    Signed-off-by: Sergei Shtylyov

    Sergei Shtylyov
     
  • The root directory cluster field only exists in a FAT32 boot sector, so the
    'root_cluster' variable in do_fat_read() contains garbage in case of FAT12/16.
    Make it contain 0 instead as this is what is passed to get_vfatname() in that
    case anyway.

    Signed-off-by: Sergei Shtylyov

    Sergei Shtylyov
     
  • The code multiples the FAT size in sectors by the sector size and then tries to
    compare that to the number of sectors in the 'getsize' variable. While fixing
    this, also change the initial value of 'getsize' as the division of FATBUFSIZE
    by the sector size gets us FATBUFBLOCKS.

    Signed-off-by: Sergei Shtylyov

    Sergei Shtylyov
     
  • Apple iPod nanos have sector sizes of 2 or 4 KiB, which crashes U-Boot when it
    tries to read the boot sector into 512-byte buffer situated on stack. Make the
    FAT code indifferent to the sector size.

    Signed-off-by: Sergei Shtylyov

    Sergei Shtylyov
     

02 Apr, 2011

1 commit

  • Fat directory handling didn't check reaching the end of the root directory. It
    relied on a stop condition based on a directory entry with a name starting with
    a '\0' character. This check in itself is wrong ('\0' indicates free entry, not
    end_of_directory) but outside the scope of this fix. For FAT32, the end of the
    rootdir is reached when the end of the cluster chain is reached. The code didn't
    check this condition and started to read an incorrect cluster. This caused a
    subsequent read request of a sector outside the range of the usb stick in
    use. On its turn, the usb stick protested with a stall handshake.

    Both FAT32 and non-FAT32 (FAT16/FAT12) end or rootdir checks have been put in.

    Signed-off-by: Erik Hansen

    Erik Hansen
     

20 Oct, 2010

1 commit

  • Last commit 3831530dcb7b71329c272ccd6181f8038b6a6dd0a was intended
    "explicitly specify FAT12/16 root directory parsing buffer size, instead
    of relying on cluster size". Howver, the underlying function requires
    the size of the buffer in blocks, not in bytes, and instead of passing
    a double sector size a request for 1024 blocks is sent. This generates
    a buffer overflow with overwriting of other structure (in the case seen,
    USB structures were overwritten).

    Signed-off-by: Stefano Babic
    CC: Mikhail Zolotaryov

    Stefano Babic
     

13 Oct, 2010

1 commit

  • The U-Boot code has the following bugs related to the processing of Long File
    Name (LFN) entries scattered across several clusters/sectors :

    1) get_vfatname() function is designed to gather scattered LFN entries by
    cluster chain processing - that doesn't work for FAT12/16 root directory.
    In other words, the function expects the following input data:
    1.1) FAT32 directory (which is cluster chain based);
    OR
    1.2) FAT12/16 non-root directory (which is also cluster chain based);
    OR
    1.3) FAT12/16 root directory (allocated as contiguous sectors area), but
    all necessary information MUST be within the input buffer of filesystem cluster
    size (thus cluster-chain jump is never initiated).

    In order to accomplish the last condition, root directory parsing code in
    do_fat_read() uses the following trick: read-out cluster-size block, process
    only first sector (512 bytes), then shift 512 forward, read-out cluster-size
    block and so on. This works great unless cluster size is equal to 512 bytes
    (in a case you have a small partition), or long file name entries are scattered
    across three sectors, see 4) for details.

    2) Despite of the fact that get_vfatname() supports FAT32 root directory
    browsing, do_fat_read() function doesn't send current cluster number correctly,
    so root directory look-up doesn't work correctly.

    3) get_vfatname() doesn't gather scattered entries correctly also is the case
    when all LFN entries are located at the end of the source cluster, but real
    directory entry (which must be returned) is at the only beginning of the
    next one. No error detected, the resulting directory entry returned contains
    a semi-random information (wrong size, wrong start cluster number and so on)
    i.e. the entry is not accessible.

    4) LFN (VFAT) allows up to 20 entries (slots) each containing 26 bytes (13
    UTF-16 code units) to represent a single long file name i.e. up to 520 bytes.
    U-Boot allocates 256 bytes buffer instead, i.e. 10 or more LFN slots record
    may cause buffer overflow / memory corruption.
    Also, it's worth to mention that 20+1 slots occupy 672 bytes space which may
    take more than one cluster of 512 bytes (medium-size FAT32 or small FAT16
    partition) - get_vfatname() function doesn't support such case as well.

    The patch attached fixes these problems in the following way:
    - keep using 256 bytes buffer for a long file name, but safely prevent a
    possible buffer overflow (skip LFN processing, if it contains 10 or more
    slots).

    - explicitly specify FAT12/16 root directory parsing buffer size, instead
    of relying on cluster size. The value used is a double sector size (to store
    current sector and the next one). This fixes the first problem and increases
    performance on big FAT12/16 partitions;

    - send current cluster number (FAT32) to get_vfatname() during root
    directory processing;

    - use LFN counter to seek the real directory entry in get_vfatname() - fixes the
    third problem;

    - skip deleted entries in the root directory (to prevent bogus buffer
    overflow detection and LFN counter steps).

    Note: it's not advised to split up the patch, because a separate part may
    operate incorrectly.

    Signed-off-by: Mikhail Zolotaryov

    Mikhail Zolotaryov
     

25 Jul, 2010

3 commits

  • - reformat
    - throw out macros like FAT_DPRINT and FAT_DPRINT
    - remove dead code

    Signed-off-by: Wolfgang Denk

    Wolfgang Denk
     
  • On FAT32, instead of fetching the cluster numbers from the FAT, the
    code assumed (incorrectly) that the clusters for the root directory
    were allocated contiguously. In the result, only the first cluster
    could be accessed. At the typical cluster size of 8 sectors this
    caused all accesses to files after the first 128 entries to fail -
    "fatls" would terminate after 128 files (usually displaying a bogus
    file name, occasionally even crashing the system), and "fatload"
    would fail to find any files that were not in the first directory
    cluster.

    Signed-off-by: Wolfgang Denk

    Wolfgang Denk
     
  • "Superfloppy" format (in U-Boot called PBR) did not work for FAT32 as
    the file system type string is at a different location. Add support
    for FAT32.

    Signed-off-by: Wolfgang Denk

    Wolfgang Denk
     

28 May, 2010

1 commit


13 Jun, 2009

1 commit

  • The static function compare_sign is only used to compare the fs_type string
    and does not do anything more than what strncmp does.

    The addition of the trailing '\0' to fs_type, while legal, is not needed
    because the it is never printed out and strncmp does not depend on NULL
    terminated strings.

    Signed-off-by: Tom Rix

    Tom Rix
     

04 Apr, 2009

1 commit

  • Mflash is fusion memory device mainly targeted consumer eletronic and
    mobile phone.
    Internally, it have nand flash and other hardware logics and supports
    some different operation (ATA, IO, XIP) modes.

    IO mode is custom mode for the host that doesn't have IDE interface.
    (Many mobile targeted SoC doesn't have IDE bus)

    This driver support mflash IO mode.

    Followings are brief descriptions about IO mode.

    1. IO mode based on ATA protocol and uses some custom command. (read
    confirm, write confirm)
    2. IO mode uses SRAM bus interface.

    Signed-off-by: unsik Kim

    unsik Kim
     

28 Jan, 2009

1 commit


24 Jan, 2009

1 commit

  • A couple of buffers in the fat code are declared as an array of bytes.
    But it is then cast up to a structure with 16bit and 32bit members.
    Since GCC assumes structure alignment here, we have to force the
    buffers to be aligned according to the structure usage.

    Signed-off-by: Bryan Wu
    Signed-off-by: Mike Frysinger

    Bryan Wu
     

10 Dec, 2008

1 commit