summaryrefslogtreecommitdiff
path: root/include/fat.h
diff options
context:
space:
mode:
authorMichael Brandt <michael.brandt@stericsson.com>2010-07-20 15:08:22 +0200
committerMichael BRANDT <michael.brandt@stericsson.com>2010-08-30 20:03:48 +0200
commit20503b61a7f73fad8ee97219f7a1e74de3a8a2ac (patch)
treeec58c1f830639a45462fe07219304a06a16b7b54 /include/fat.h
parent3a5b27b58258ff61dfae3167bc46fed0146ddffd (diff)
Read/write VFAT support from Rockbox-3.3 FAT stack
Add read/write VFAT support from Rockbox-3.3 FAT stack. It should be also applicable to the unmodified 2009.11 U-Boot release. Note that is was taken as is from Rockbox and from a older U-Boot Rockbox patch. "checkpatch" shows very many coding style errors and warnings, but it is tedious work to clean this up. To make this patch work an additional mmc_block_write() board support routine and the errno variable are needed. Furthermore following defines in the board config header file: #define CONFIG_ROCKBOX_FAT 1 #define CONFIG_U_BOOT 1 #define CONFIG_SUPPORT_VFAT 1 #define CONFIG_CMD_TREE_FAT This will be added in a follow-up patch. This patch is based on the patch from Etienne Carriere <etienne.carriere@stericsson.com> for the U671x U-Boot: This commit adds FAT write support to u-boot native read-only FAT code. Commit initially applied on u-boot-v2009.01 (SHA1: 72d15e705bc3983884105cb7755c7ba80e74a0a5) Based on FAT stack dumped from Rockbox package v3.1 (www.rockbox.org). Based on initial Rockbox FAT stack integration in u-boot by Keith Outwater (outwater@comcast.net). Current porting is aligned with Rockbox v3.3 FAT stack. Enable upon config switches: CONFIG_CMD_FAT CONFIG_ROCKBOX_FAT CONFIG_CMD_TREE_FAT (recommended) CONFIG_SUPPORT_VFAT (recommended) C code APIs (from U-boot native FAT support): int fat_register_device(block_dev_desc_t *dev_desc, int part_no); long file_fat_read(const char *path, void *buf, unsigned long maxsize); int file_fat_ls(const char *dirname); int file_fat_detectfs(void); C code APIs (added by Rockbox FAT support): long file_fat_write(const char *path, void *buf, unsigned long maxsize); int file_fat_rm(const char *path); int file_fat_rmdir(const char *path); int file_fat_mkdir(const char *path); int file_fat_cd(const char *path); int file_fat_pwd(void); int file_fat_mv(const char *oldpath, const char *newpath); unsigned int rockbox_fat_free(unsigned long size_kbyte); unsigned int rockbox_fat_size(void); Use "help fat" from u-boot console to see available commands. ST-Ericsson ID: WP264488 Change-Id: I9afc29ecb80f9152bd8534bbf11e47e54cfad796 Signed-off-by: Michael Brandt <michael.brandt@stericsson.com> Reviewed-on: http://gerrit.lud.stericsson.com/gerrit/3009
Diffstat (limited to 'include/fat.h')
-rw-r--r--include/fat.h45
1 files changed, 42 insertions, 3 deletions
diff --git a/include/fat.h b/include/fat.h
index c8b949362..26886fda0 100644
--- a/include/fat.h
+++ b/include/fat.h
@@ -3,6 +3,8 @@
*
* 2002-07-28 - rjones@nexus-tech.net - ported to ppcboot v1.1.6
* 2003-03-10 - kharris@nexus-tech.net - ported to u-boot
+ * 2006-01-18 - Keith Outwater (outwater@comcast.net) - added write support
+ * using FAT driver from rockbox project (www.rockbox.org)
*
* See file CREDITS for list of people who contributed to this
* project.
@@ -29,7 +31,9 @@
#include <asm/byteorder.h>
+#ifndef CONFIG_SUPPORT_VFAT
#define CONFIG_SUPPORT_VFAT
+#endif
#define SECTOR_SIZE FS_BLOCK_SIZE
@@ -57,12 +61,14 @@
#define SIGNLEN 8
/* File attributes */
+#ifndef CONFIG_ROCKBOX_FAT /* rockbox redefine these */
#define ATTR_RO 1
#define ATTR_HIDDEN 2
#define ATTR_SYS 4
#define ATTR_VOLUME 8
#define ATTR_DIR 16
#define ATTR_ARCH 32
+#endif
#define ATTR_VFAT (ATTR_RO | ATTR_HIDDEN | ATTR_SYS | ATTR_VOLUME)
@@ -80,7 +86,7 @@
#define LS_DIR 1
#define LS_ROOT 2
-#ifdef DEBUG
+#if (defined(DEBUG) || defined(FAT_DEBUG))
#define FAT_DPRINT(args...) printf(args)
#else
#define FAT_DPRINT(args...)
@@ -114,6 +120,14 @@
#define CHECK_CLUST(x, fatsize) ((x) <= 1 || \
(x) >= ((fatsize) != 32 ? 0xfff0 : 0xffffff0))
+#ifdef CONFIG_ROCKBOX_FAT
+/*
+ * Remember the current working directory for the four primary partitions.
+ */
+#define NUM_PARTS_WITH_CWD 4
+#define CWD_LEN 511
+#endif
+
typedef struct boot_sector {
__u8 ignored[3]; /* Bootstrap code */
char system_id[8]; /* Name of fs */
@@ -192,11 +206,20 @@ typedef struct {
int fatbufnum; /* Used by get_fatent, init to -1 */
} fsdata;
+/*
+ * This struct encapsulates partiton and device info for the currently active
+ * block device.
+ */
+typedef struct cur_block_dev {
+ block_dev_desc_t *cur_dev;
+ unsigned long part_offset;
+ int cur_part;
+} cur_block_dev_t;
+
typedef int (file_detectfs_func)(void);
typedef int (file_ls_func)(const char *dir);
typedef long (file_read_func)(const char *filename, void *buffer,
unsigned long maxsize);
-
struct filesystem {
file_detectfs_func *detect;
file_ls_func *ls;
@@ -209,12 +232,28 @@ file_detectfs_func file_fat_detectfs;
file_ls_func file_fat_ls;
file_read_func file_fat_read;
-/* Currently this doesn't check if the dir exists or is valid... */
+/*Currently this doesn't check if the dir exists or is valid */
int file_cd(const char *path);
+
int file_fat_detectfs(void);
int file_fat_ls(const char *dir);
long file_fat_read(const char *filename, void *buffer, unsigned long maxsize);
+#ifdef CONFIG_ROCKBOX_FAT
+long file_fat_write(const char *filename, void *buffer, unsigned long filesize);
+int file_fat_rm(const char *filename);
+int file_fat_mkdir(const char *dirname);
+int file_fat_rmdir(const char *dirname);
+int file_fat_pwd(void);
+int file_fat_cd(const char *dirname);
+int file_fat_mv(const char *oldname, const char *newname);
+#endif
const char *file_getfsname(int idx);
int fat_register_device(block_dev_desc_t *dev_desc, int part_no);
+#ifdef CONFIG_ROCKBOX_FAT
+#ifndef ROCKBOX_FAT_H
+#include <rockbox_fat.h>
+#endif
+#endif
+
#endif /* _FAT_H_ */