Commit Graph

59 Commits

Author SHA1 Message Date
Benoît Thébaudeau
1170e634dd FAT: Make it possible to read from any file position
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 <benoit.thebaudeau@advansee.com>
Cc: Wolfgang Denk <wd@denx.de>
Signed-off-by: Tom Rini <trini@ti.com>
2012-09-26 11:11:32 -07:00
Benoît Thébaudeau
7ee46cebcb FAT: Fix file contents listed as directory
With:
fatls mmc 0 /dir/file
dir: regular directory
file: regular file

The previous code read the contents of file as if it were directory entries to
list. This patch refuses to list file contents as if it were a folder.

Signed-off-by: Benoît Thébaudeau <benoit.thebaudeau@advansee.com>
Cc: Wolfgang Denk <wd@denx.de>
2012-09-18 12:01:53 -07:00
Benoît Thébaudeau
0880e5bb0c FAT: Simplify get_contents
One call to get_cluster can be factorized with another, so avoid
duplicating code.

Signed-off-by: Benoît Thébaudeau <benoit.thebaudeau@advansee.com>
Cc: Wolfgang Denk <wd@denx.de>
2012-09-02 17:22:43 +02:00
Benoît Thébaudeau
cc63b25efb FAT: get_cluster: Add buffer bouncing
Add a buffer bouncing mechanism to get_cluster.  This can be useful
for misaligned applicative buffers passed through get_contents.
This is required for the following patches in the case of data
aligned differently relatively to buffers and clusters.

Signed-off-by: Benoît Thébaudeau <benoit.thebaudeau@advansee.com>
Cc: Wolfgang Denk <wd@denx.de>
2012-09-02 17:22:10 +02:00
Benoît Thébaudeau
cd1b042c5c FAT: Fix redundant sector read
With the previous code, the remaining prefetched sectors were read
again after each sector.  With this patch, each sector is read only
once, thus making the prefetch useful.

Signed-off-by: Benoît Thébaudeau <benoit.thebaudeau@advansee.com>
Cc: Wolfgang Denk <wd@denx.de>
2012-09-02 17:16:08 +02:00
Benoît Thébaudeau
88503ad3bb FAT: cosmetic: Remove useless assignment
fatlength is not used after this assignment, so it is useless and can
be removed.

Signed-off-by: Benoît Thébaudeau <benoit.thebaudeau@advansee.com>
Cc: Wolfgang Denk <wd@denx.de>
2012-09-02 17:15:16 +02:00
Benoît Thébaudeau
8006dd2e57 FAT: get_fatent: Fix FAT boundary check
startblock must be taken into account in order not to read past the
end of the FAT.

Signed-off-by: Benoît Thébaudeau <benoit.thebaudeau@advansee.com>
Cc: Wolfgang Denk <wd@denx.de>
2012-09-02 17:14:30 +02:00
Benoît Thébaudeau
9795e07b04 FAT: cosmetic: Remove extra spaces
Remove spaces before opening parentheses in function calls.

Signed-off-by: Benoît Thébaudeau <benoit.thebaudeau@advansee.com>
Cc: Wolfgang Denk <wd@denx.de>
2012-09-02 17:13:18 +02:00
Marek Vasut
b37d41aa24 Block: Remove MG DISK support
This driver is unused and obsolete.

Signed-off-by: Marek Vasut <marex@denx.de>
Cc: Wolfgang Denk <wd@denx.de>
Cc: unsik Kim <donari75@gmail.com>
2012-06-21 20:53:09 +02:00
Eric Nelson
9a800ac718 fs/fat: align disk buffers on cache line to enable DMA and cache
Signed-off-by: Eric Nelson <eric.nelson@boundarydevices.com>
Acked-by: Mike Frysinger <vapier@gentoo.org>
2012-04-30 16:54:50 +02:00
Kyle Moffett
46236b1407 fs/fat: Improve error handling
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.D.Moffett@boeing.com>
2012-01-05 20:10:37 +01:00
Kyle Moffett
9813b750f3 fs/fat: Fix FAT detection to support non-DOS partition tables
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 <Kyle.D.Moffett@boeing.com>

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 <wd@denx.de>
2012-01-05 20:10:06 +01:00
Sergei Shtylyov
bf34e7d952 fat: reset VFAT short alias checksum on first match
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 <sshtylyov@ru.mvista.com>
Signed-off-by: Martin Mueller <martin.mueller5@de.bosch.com>
2012-01-05 16:03:24 +01:00
Andreas Bießmann
2d1b83b346 fat.c: fix printf() length modifier
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:

---8<---
fat.c: In function 'do_fat_read':
fat.c:879: warning: format '%d' expects type 'int', but argument 4 has type 'long unsigned int'
--->8---

Signed-off-by: Andreas Bießmann <biessmann@corscience.de>
cc: Mike Frysinger <vapier@gentoo.org>
cc: Thomas Chou <thomas@wytron.com.tw>
cc: rjones@nexus-tech.net
cc: kharris@nexus-tech.net
Acked-by: Mike Frysinger <vapier@gentoo.org>
2011-12-17 23:56:40 +01:00
Wolfgang Denk
6471ada534 fs/fat/fat.c: Fix GCC 4.6 build warning
Fix:
fat.c: In function 'fat_register_device':
fat.c:74:19: warning: variable 'info' set but not used
[-Wunused-but-set-variable]

Signed-off-by: Wolfgang Denk <wd@denx.de>
2011-11-07 22:11:20 +01:00
J. Vijayanand
206d68fdd4 fat: correct ATTR_VFAT check
ATTR_VFAT condition requires multiple bits to be set but the present
condition checking in do_fat_read() & get_dentfromdir() ends up
passing on even a single bit being set.

Signed-off-by: J. Vijayanand <vijayanand.jayaraman@in.bosch.com>
Signed-off-by: Sergei Shtylyov <sshtylyov@ru.mvista.com>
2011-10-27 23:53:57 +02:00
Wolfgang Denk
e116cc069f fs/fat/fat.c: fix warning: 'part_size' defined but not used
Commit c30a15e "FAT: Add FAT write feature" introduced a compiler
warning.  Fix this.

Signed-off-by: Wolfgang Denk <wd@denx.de>
Cc: Donggeun Kim <dg77.kim@samsung.com>
Cc: Kyungmin Park <kyungmin.park@samsung.com>
2011-10-27 23:53:57 +02:00
Donggeun Kim
c30a15e590 FAT: Add FAT write feature
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 <dg77.kim@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
2011-10-26 21:40:44 +02:00
Sergei Shtylyov
025421eab4 fat: replace LINEAR_PREFETCH_SIZE with PREFETCH_BLOCKS
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 <sshtylyov@mvista.com>
2011-10-01 21:52:19 +02:00
Sergei Shtylyov
40e219165b fat: root directory cluster only makes sense for FAT32
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 <sshtylyov@mvista.com>
2011-10-01 21:52:06 +02:00
Sergei Shtylyov
60b36f0fc7 fat: cannot compare bytes and sectors
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 <sshtylyov@mvista.com>
2011-10-01 21:51:23 +02:00
Sergei Shtylyov
ac4977719e fat: fix crash with big sector size
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 <sshtylyov@mvista.com>
2011-10-01 21:50:39 +02:00
Erik Hansen
3f270f42d7 fat32 root directory handling
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@makarta.com>
2011-04-02 09:38:24 +02:00
Stefano Babic
11c8dd36ed FAT: buffer overflow with FAT12/16
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 <sbabic@denx.de>
CC: Mikhail Zolotaryov <lebon@lebon.org.ua>
2010-10-20 09:14:38 +02:00
Mikhail Zolotaryov
3831530dcb VFAT: fix processing of scattered long file name entries
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 <lebon@lebon.org.ua>
2010-10-12 22:39:14 +02:00
Wolfgang Denk
7385c28e9b fs/fat: Big code cleanup.
- reformat
- throw out macros like FAT_DPRINT and FAT_DPRINT
- remove dead code

Signed-off-by: Wolfgang Denk <wd@denx.de>
2010-07-24 20:54:46 +02:00
Wolfgang Denk
2aa98c6612 FAT32: fix broken root directory handling.
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 <wd@denx.de>
2010-07-24 20:53:50 +02:00
Wolfgang Denk
66c2d73cfc FAT32: fix support for superfloppy-format (PBR)
"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 <wd@denx.de>
2010-07-24 20:53:43 +02:00
Thomas Chou
1117cbf2ad nios: remove nios-32 arch
The nios-32 arch is obsolete and broken. So it is removed.

Signed-off-by: Thomas Chou <thomas@wytron.com.tw>
2010-05-28 10:56:04 -04:00
Tom Rix
651351fe98 FAT replace compare_sign with strncmp.
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@windriver.com>
2009-06-12 20:45:48 +02:00
unsik Kim
75eb82ec7c mflash: Initial mflash support
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 <donari75@gmail.com>
2009-04-03 23:47:06 +02:00
Wolfgang Denk
65f7d41031 fat.c: fix warning: array subscript is above array bounds
Fix based on suggestion by David Hawkins <dwh@ovro.caltech.edu>.

Signed-off-by: Wolfgang Denk <wd@denx.de>
2009-01-27 21:36:28 +01:00
Bryan Wu
7e4b9b4f6f fat: fix unaligned errors
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 <bryan.wu@analog.com>
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
2009-01-24 02:03:39 +01:00
Sonic Zhang
8c5170a7d0 fs/fat: handle FAT on SATA
The FAT file system driver should also handle FAT on SATA devices.

Signed-off-by: Sonic Zhang <Sonic.Zhang@analog.com>
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
2008-12-10 09:21:48 +01:00
Remy Bohmer
3c2c2f4279 Remove non-ascii characters from fat code
This code contains some non-ascii characters in comment lines and code.
Most editors do not display those characters properly and editing those
files results always in diffs at these places which are usually not required
to be changed at all. This is error prone.

So, remove those weird characters and replace them by normal C-style
equivalents for which the proper defines were already in the header.

Signed-off-by: Remy Bohmer <linux@bohmer.net>
2008-12-04 20:51:44 +01:00
Jean-Christophe PLAGNIOL-VILLARD
08ab4e1780 fs: Move conditional compilation to Makefile
Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
2008-08-31 04:24:56 +02:00
michael
8ce4e5c2c0 Fix checking fat32 cluster size.
This fixes the cluster size tests in the FAT32 file system.
The current implementation of VFAT support doesn't work if the
referred cluster has an offset > 16bit representation, causing
"fatload" and "fatls" commands etc. to fail.

Signed-off-by: michael trimarchi <trimarchi@gandalf.sssup.it>
2008-03-03 00:40:42 +01:00
Andy Fleming
21f6f9636f Fix CONFIG_MMC usage in fat code
A #if statement in fat.c depended on CONFIG_MMC, instead of
defined(CONFIG_MMC).  This meant CONFIG_MMC needed to be defined
as "1" rather than just defined.  Now it's better.

Signed-off-by: Andy Fleming <afleming@freescale.com>
2008-02-14 22:03:17 +01:00
Andy Fleming
02df4a270f Fix my own merge stupidity
Way back in August I merged Heiko's patch:
566a494f592: [PCS440EP] upgrade the PCS440EP board

with Jon's CONFIG_COMMANDS patches.

This was done in commit: 6bf6f114dc

However, in the process, I left out some of Heiko's good changes.

Now Heiko's and Jon's patches are properly merged in fat_register_device()

Signed-off-by: Andy Fleming <afleming@freescale.com>
2008-01-09 23:13:00 +01:00
Wolfgang Denk
bf1060ea4f Fix missing brace error in fs/fat/fat.c
[pointed out by Roderik Wildenburg]

Signed-off-by: Wolfgang Denk <wd@denx.de>
2007-08-07 16:02:13 +02:00
Andy Fleming
6bf6f114dc Merge branch 'testing' into working
Conflicts:

	CHANGELOG
	fs/fat/fat.c
	include/configs/MPC8560ADS.h
	include/configs/pcs440ep.h
	net/eth.c
2007-08-03 02:23:23 -05:00
Jon Loeliger
dd60d1223b fs/: Remove obsolete references to CONFIG_COMMANDS
Signed-off-by: Jon Loeliger <jdl@freescale.com>
2007-07-09 17:56:50 -05:00
Jon Loeliger
4e109ae982 fs/: Augment CONFIG_COMMANDS tests with defined(CONFIG_CMD_*).
This is a compatibility step that allows both the older form
and the new form to co-exist for a while until the older can
be removed entirely.

All transformations are of the form:
Before:
    #if (CONFIG_COMMANDS & CFG_CMD_AUTOSCRIPT)
After:
    #if (CONFIG_COMMANDS & CFG_CMD_AUTOSCRIPT) || defined(CONFIG_CMD_AUTOSCRIPT)

Signed-off-by: Jon Loeliger <jdl@freescale.com>
2007-07-04 00:23:12 +02:00
Heiko Schocher
566a494f59 [PCS440EP] upgrade the PCS440EP board:
- Show on the Status LEDs, some States of the board.
                - Get the MAC addresses from the EEProm
                - use PREBOOT
                - use the CF on the board.
                - check the U-Boot image in the Flash with a SHA1
                  checksum.
                - use dynamic TLB entries generation for the SDRAM

Signed-off-by: Heiko Schocher <hs@denx.de>
2007-06-22 19:11:54 +02:00
Peter Pearse
3e3b956906 Reduce line lengths to 80 characters max. 2007-05-18 16:47:03 +01:00
Peter Pearse
b0d8f5bf0d New board SMN42 branch 2007-05-09 11:37:56 +01:00
Wolfgang Denk
77ddac9480 Cleanup for GCC-4.x 2005-10-13 16:45:02 +02:00
Wolfgang Denk
d06a5f7ebf Add support for Altera NIOS DK1C20 board
Patch by Shlomo Kut, 13 Dec 2004
2005-08-06 01:56:59 +02:00
stroese
20cc00ddac "static" from "do_fat_read" removed 2004-12-16 17:57:26 +00:00
wdenk
a5bbcc3c53 * Patches by Sean Chang, 09 Aug 2004:
- Added support for both 8 and 16 bit mode access to System ACE CF
    through MPU.
  - Fixed missing System ACE CF device during get FAT partition info
    in fat_register_device function.
  - Enabled System ACE CF support on ML300.

* Patch by Sean Chang, 09 Aug 2004:
  Synch defines for saveenv and do_saveenv functions so they get
  compiled under the same statement.
2004-09-29 22:55:14 +00:00