Skip to contentSkip to conversation

cmd_fat: add FAT write command

PATCH New Maximilian Schwerin 5 participants 14 messages Mar 13, 2012 – Mar 30, 2012 VFAT/FAT/msdos filesystem

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 cmd_fat: add FAT write command

From: Donggeun Kim <dg77.kim at>

Once CONFIG_FAT_WRITE is defined,
users can invoke 'fatwrite' command that saves data in RAM as a FAT file.

This patch also removes compile error after patch of 'fs/fat: Fix FAT detection to support non-DOS partition tables'.

Signed-off-by Donggeun Kim <dg77.kim <at> samsung.com>
Signed-off-by Kyungmin Park <kyungmin.park <at> samsung.com>
---
 common/cmd_fat.c   |   57 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 fs/fat/fat_write.c |   20 +++++++-----------
 2 files changed, 65 insertions(+), 12 deletions(-)
common/cmd_fat.c +57 -0
index 0220494..fef1c82 100644
@@ -184,3 +184,60 @@ U_BOOT_CMD(
 	"<interface> <dev[:part]>\n"
 	"    - print information about filesystem from 'dev' on 'interface'"
 );
+
+#ifdef CONFIG_FAT_WRITE
+static int do_fat_fswrite(cmd_tbl_t *cmdtp, int flag,
+		int argc, char * const argv[])
+{
+	long size;
+	unsigned long addr;
+	unsigned long count;
+	block_dev_desc_t *dev_desc = NULL;
+	int dev = 0;
+	int part = 1;
+	char *ep;
+
+	if (argc < 5)
+		return cmd_usage(cmdtp);
+
+	dev = (int)simple_strtoul(argv[2], &ep, 16);
+	dev_desc = get_dev(argv[1], dev);
+	if (dev_desc == NULL) {
+		puts("\n** Invalid boot device **\n");
+		return 1;
+	}
+	if (*ep) {
+		if (*ep != ':') {
+			puts("\n** Invalid boot device, use `dev[:part]' **\n");
+			return 1;
+		}
+		part = (int)simple_strtoul(++ep, NULL, 16);
+	}
+	if (fat_register_device(dev_desc, part) != 0) {
+		printf("\n** Unable to use %s %d:%d for fatwrite **\n",
+			argv[1], dev, part);
+		return 1;
+	}
+	addr = simple_strtoul(argv[3], NULL, 16);
+	count = simple_strtoul(argv[5], NULL, 16);
+
+	size = file_fat_write(argv[4], (void *)addr, count);
+	if (size == -1) {
+		printf("\n** Unable to write \"%s\" from %s %d:%d **\n",
+			argv[4], argv[1], dev, part);
+		return 1;
+	}
+
+	printf("%ld bytes write\n", size);
+
+	return 0;
+}
+
+U_BOOT_CMD(
+	fatwrite,	6,	0,	do_fat_fswrite,
+	"write file into a dos filesystem",
+	"<interface> <dev[:part]> <addr> <filename> <bytes>\n"
+	"    - write file 'filename' from the address 'addr' in RAM\n"
+	"      to 'dev' on 'interface'"
+);
+#endif
fs/fat/fat_write.c +8 -12
index 3bfc1c4..16f8400 100644
@@ -41,23 +41,19 @@ static void uppercase(char *str, int len)
 }
 
 static int total_sector;
-static int disk_write(__u32 startblock, __u32 getsize, __u8 *bufptr)
+static int disk_write(__u32 block, __u32 nr_blocks, void *buf)
 {
-	if (cur_dev == NULL)
+	if (!cur_dev || !cur_dev->block_write)
 		return -1;
 
-	if (startblock + getsize > total_sector) {
+	if (cur_part_info.start + block + nr_blocks >
+		cur_part_info.start + total_sector) {
 		printf("error: overflow occurs\n");
 		return -1;
 	}
 
-	startblock += part_offset;
-
-	if (cur_dev->block_read) {
-		return cur_dev->block_write(cur_dev->dev, startblock, getsize,
-					   (unsigned long *) bufptr);
-	}
-	return -1;
+	return cur_dev->block_write(cur_dev->dev,
+			cur_part_info.start + block, nr_blocks,	buf);
 }
 
 /*
@@ -797,7 +793,7 @@ static int check_overflow(fsdata *mydata, __u32 clustnum, unsigned long size)
 	if (size % mydata->sect_size)
 		sect_num++;
 
-	if (startsect + sect_num > total_sector)
+	if (startsect + sect_num > cur_part_info.start + total_sector)
 		return -1;
 
 	return 0;
@@ -947,7 +943,7 @@ static int do_fat_write(const char *filename, void *buffer,
 
 	total_sector = bs.total_sect;
 	if (total_sector == 0)
-		total_sector = part_size;
+		total_sector = cur_part_info.size;
 
 	root_cluster = bs.root_cluster;
 
Signature · 1 line
1.7.0.4
#1 lore raw

PATCH 1/2 FAT write: Fix compile errors

This patch removes compile errors introduced by 'fs/fat: Fix FAT detection to support non-DOS partition tables'.

This patch was originally part of

http://article.gmane.org/gmane.comp.boot-loaders.u-boot/121847

---
 fs/fat/fat_write.c |   20 ++++++++------------
 1 files changed, 8 insertions(+), 12 deletions(-)
fs/fat/fat_write.c +8 -12
index 3bfc1c4..16f8400 100644
@@ -41,23 +41,19 @@ static void uppercase(char *str, int len)
 }
 
 static int total_sector;
-static int disk_write(__u32 startblock, __u32 getsize, __u8 *bufptr)
+static int disk_write(__u32 block, __u32 nr_blocks, void *buf)
 {
-	if (cur_dev == NULL)
+	if (!cur_dev || !cur_dev->block_write)
 		return -1;
 
-	if (startblock + getsize > total_sector) {
+	if (cur_part_info.start + block + nr_blocks >
+		cur_part_info.start + total_sector) {
 		printf("error: overflow occurs\n");
 		return -1;
 	}
 
-	startblock += part_offset;
-
-	if (cur_dev->block_read) {
-		return cur_dev->block_write(cur_dev->dev, startblock, getsize,
-					   (unsigned long *) bufptr);
-	}
-	return -1;
+	return cur_dev->block_write(cur_dev->dev,
+			cur_part_info.start + block, nr_blocks,	buf);
 }
 
 /*
@@ -797,7 +793,7 @@ static int check_overflow(fsdata *mydata, __u32 clustnum, unsigned long size)
 	if (size % mydata->sect_size)
 		sect_num++;
 
-	if (startsect + sect_num > total_sector)
+	if (startsect + sect_num > cur_part_info.start + total_sector)
 		return -1;
 
 	return 0;
@@ -947,7 +943,7 @@ static int do_fat_write(const char *filename, void *buffer,
 
 	total_sector = bs.total_sect;
 	if (total_sector == 0)
-		total_sector = part_size;
+		total_sector = cur_part_info.size;
 
 	root_cluster = bs.root_cluster;
 
Signature · 1 line
1.7.0.4
#2 lore raw

PATCH 1/1 fs/fat/fat_write.c: Fix GCC 4.6 warnings

Fix:
fat_write.c: In function 'find_directory_entry':
fat_write.c:826:8: warning: variable 'prevcksum' set but not used [-Wunused-but-set-variable]
fat_write.c: In function 'do_fat_write':
fat_write.c:933:6: warning: variable 'root_cluster' set but not used [-Wunused-but-set-variable]
fat_write.c:925:12: warning: variable 'slotptr' set but not used [-Wunused-but-set-variable]

---
 fs/fat/fat_write.c |   10 +---------
 1 files changed, 1 insertions(+), 9 deletions(-)
fs/fat/fat_write.c +1 -9
index 16f8400..a6181e7 100644
@@ -823,7 +823,6 @@ static dir_entry *empty_dentptr;
 static dir_entry *find_directory_entry(fsdata *mydata, int startsect,
 	char *filename, dir_entry *retdent, __u32 start)
 {
-	__u16 prevcksum = 0xffff;
 	__u32 curclust = (startsect - mydata->data_begin) / mydata->clust_size;
 
 	debug("get_dentfromdir: %s\n", filename);
@@ -857,8 +856,6 @@ static dir_entry *find_directory_entry(fsdata *mydata, int startsect,
 #ifdef CONFIG_SUPPORT_VFAT
 				if ((dentptr->attr & ATTR_VFAT) &&
 				    (dentptr->name[0] & LAST_LONG_ENTRY_MASK)) {
-					prevcksum =
-					((dir_slot *)dentptr)->alias_checksum;
 					get_long_file_name(mydata, curclust,
 						     get_dentfromdir_block,
 						     &dentptr, l_name);
@@ -922,7 +919,6 @@ static int do_fat_write(const char *filename, void *buffer,
 	unsigned long size)
 {
 	dir_entry *dentptr, *retdent;
-	dir_slot *slotptr;
 	__u32 startsect;
 	__u32 start_cluster;
 	boot_sector bs;
@@ -930,7 +926,7 @@ static int do_fat_write(const char *filename, void *buffer,
 	fsdata datablock;
 	fsdata *mydata = &datablock;
 	int cursect;
-	int root_cluster, ret = -1, name_len;
+	int ret = -1, name_len;
 	char l_filename[VFAT_MAXLEN_BYTES];
 	int write_size = size;
 
@@ -945,8 +941,6 @@ static int do_fat_write(const char *filename, void *buffer,
 	if (total_sector == 0)
 		total_sector = cur_part_info.size;
 
-	root_cluster = bs.root_cluster;
-
 	if (mydata->fatsize == 32)
 		mydata->fatlength = bs.fat32_length;
 	else
@@ -1047,8 +1041,6 @@ static int do_fat_write(const char *filename, void *buffer,
 			goto exit;
 		}
 	} else {
-		slotptr = (dir_slot *)empty_dentptr;
-
 		/* Set short name to set alias checksum field in dir_slot */
 		set_name(empty_dentptr, filename);
 		fill_dir_slot(mydata, &empty_dentptr, filename);
Signature · 1 line
1.7.1
#3 lore raw

PATCH 1/1 fs/fat/fat_write.c: Fix GCC 4.6 warnings

Quoted 10 lines · On Sun, 25 Mar 2012 00:57:06 +0100 Anatolij Gustschin <[email protected]> wrote:

Fix:
fat_write.c: In function 'find_directory_entry':
fat_write.c:826:8: warning: variable 'prevcksum' set but not used [-Wunused-but-set-variable]
fat_write.c: In function 'do_fat_write':
fat_write.c:933:6: warning: variable 'root_cluster' set but not used [-Wunused-but-set-variable]
fat_write.c:925:12: warning: variable 'slotptr' set but not used [-Wunused-but-set-variable]

Quoted 5 lines
---
 fs/fat/fat_write.c |   10 +---------
 1 files changed, 1 insertions(+), 9 deletions(-)

I'll push this patch through my staging branch if nobody objects.

Thanks,
Anatolij

#4 lore raw

PATCH 1/2 FAT write: Fix compile errors

In reply to Maximilian Schwerin

Hello Maximilian,

Quoted 5 lines · On Thu, 22 Mar 2012 15:38:55 +0100 Maximilian Schwerin <[email protected]> wrote:

This patch removes compile errors introduced by 'fs/fat: Fix FAT detection to support non-DOS partition tables'.

This patch was originally part of

Quoted 7 lines

http://article.gmane.org/gmane.comp.boot-loaders.u-boot/121847

---
 fs/fat/fat_write.c |   20 ++++++++------------
 1 files changed, 8 insertions(+), 12 deletions(-)

Applied to u-boot-staging/agust at denx.de after fixing commit log and all attribution tags.

NOTE: When submitting patches from other people you should preserve their authorship and SoB and add your SoB.

Thanks,
Anatolij

#5 lore raw

PATCH 1/2 cmd_fat: add FAT write command

In reply to Maximilian Schwerin

Dear Maximilian,

Quoted 4 lines · In message <[email protected]> you wrote:

From: Donggeun Kim <dg77.kim at>

Once CONFIG_FAT_WRITE is defined,
users can invoke 'fatwrite' command that saves data in RAM as a FAT file.

Thanks for picking up this patch. A few minor comments:

Please add documentation for the new CONFIG_FAT_WRITE config option to the top level README.

Quoted 2 lines

This patch also removes compile error after patch of 'fs/fat: Fix FAT detection to support non-DOS partition tables'.

Which compile error would that be? I am not aware of any such error.

If ther eis one, the fix should be in a separate patch; otherwise this comment should be removed.

Thanks!

#6 lore raw

PATCH 2/2 Add support for loading and saving the environment to a FAT partition

In reply to Maximilian Schwerin

The following must be defined:

CONFIG_ENV_IS_IN_FAT
Enable this saving environment to FAT.

FAT_ENV_INTERFACE
Interface the FAT resides on (e.g. mmc).

FAT_ENV_DEVICE
The interface device number (e.g. 0 for mmc0)

FAT_ENV_PART
The device part (e.g. 1 for mmc0:1)

FAT_ENV_FILE
The filename of the environment file.

---
 common/Makefile     |    1 +
 common/cmd_nvedit.c |    3 +-
 common/env_fat.c    |  158 +++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 161 insertions(+), 1 deletions(-)
 create mode 100644 common/env_fat.c
common/Makefile +1 -0
index 2a31c62..7fcb108 100644
@@ -54,6 +54,7 @@ COBJS-$(CONFIG_ENV_IS_IN_NVRAM) += env_embedded.o
 COBJS-$(CONFIG_ENV_IS_IN_FLASH) += env_flash.o
 COBJS-$(CONFIG_ENV_IS_IN_MG_DISK) += env_mgdisk.o
 COBJS-$(CONFIG_ENV_IS_IN_MMC) += env_mmc.o
+COBJS-$(CONFIG_ENV_IS_IN_FAT) += env_fat.o
 COBJS-$(CONFIG_ENV_IS_IN_NAND) += env_nand.o
 COBJS-$(CONFIG_ENV_IS_IN_NVRAM) += env_nvram.o
 COBJS-$(CONFIG_ENV_IS_IN_ONENAND) += env_onenand.o
common/cmd_nvedit.c +2 -1
index 22f9821..b1494dc 100644
@@ -61,13 +61,14 @@ DECLARE_GLOBAL_DATA_PTR;
 	!defined(CONFIG_ENV_IS_IN_DATAFLASH)	&& \
 	!defined(CONFIG_ENV_IS_IN_MG_DISK)	&& \
 	!defined(CONFIG_ENV_IS_IN_MMC)		&& \
+	!defined(CONFIG_ENV_IS_IN_FAT)		&& \
 	!defined(CONFIG_ENV_IS_IN_NAND)		&& \
 	!defined(CONFIG_ENV_IS_IN_NVRAM)	&& \
 	!defined(CONFIG_ENV_IS_IN_ONENAND)	&& \
 	!defined(CONFIG_ENV_IS_IN_SPI_FLASH)	&& \
 	!defined(CONFIG_ENV_IS_NOWHERE)
 # error Define one of CONFIG_ENV_IS_IN_{EEPROM|FLASH|DATAFLASH|ONENAND|\
-SPI_FLASH|MG_DISK|NVRAM|MMC} or CONFIG_ENV_IS_NOWHERE
+SPI_FLASH|MG_DISK|NVRAM|MMC|FAT} or CONFIG_ENV_IS_NOWHERE
 #endif
 
 #define XMK_STR(x)	#x
common/env_fat.c new file +158 -0

158 lines not on this page · raw message

Signature · 1 line
1.7.0.4
#7 lore raw

PATCH 2/2 Add support for loading and saving the environment to a FAT partition

Dear Maximilian Schwerin,

Quoted 14 lines · In message <[email protected]> you wrote:

The following must be defined:

CONFIG_ENV_IS_IN_FAT
Enable this saving environment to FAT.

FAT_ENV_INTERFACE
Interface the FAT resides on (e.g. mmc).

FAT_ENV_DEVICE
The interface device number (e.g. 0 for mmc0)

FAT_ENV_PART
The device part (e.g. 1 for mmc0:1)

Quoted 8 lines

FAT_ENV_FILE
The filename of the environment file.

---
 common/Makefile     |    1 +
 common/cmd_nvedit.c |    3 +-
 common/env_fat.c    |  158 +++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 161 insertions(+), 1 deletions(-)
 create mode 100644 common/env_fat.c

Applied, thanks.

As your SoB was missing, I signed it. I also removed the dead "/* #define DEBUG */" line.

Best regards,

Wolfgang Denk

Signature · 8 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
PUBLIC NOTICE AS REQUIRED BY LAW:  Any Use of This  Product,  in  Any
Manner  Whatsoever,  Will  Increase  the  Amount  of  Disorder in the
Universe. Although No Liability Is Implied Herein,  the  Consumer  Is
Warned  That  This  Process Will Ultimately Lead to the Heat Death of
the Universe.
#8 lore raw

PATCH 2/2 cmd_fat: add FAT write command

In reply to Maximilian Schwerin

Once CONFIG_FAT_WRITE is defined, users can invoke 'fatwrite' command that saves data in RAM as a FAT file.

This patch was originally part of

http://article.gmane.org/gmane.comp.boot-loaders.u-boot/121847

---
 README           |    8 +++++-
 common/cmd_fat.c |   57 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 63 insertions(+), 2 deletions(-)
README +6 -2
index 1f8bd20..fe077b9 100644
@@ -1250,8 +1250,12 @@ The following options need to be configured:
 
 - FAT(File Allocation Table) filesystem write function support:
 		CONFIG_FAT_WRITE
-		Support for saving memory data as a file
-		in FAT formatted partition
+
+		Define this to enable support for saving memory data as a
+		file in FAT formatted partition.
+
+		This will also enable the command "fatwrite" enabling the
+		user to write files to FAT.
 
 - Keyboard Support:
 		CONFIG_ISA_KEYBOARD
common/cmd_fat.c +57 -0

60 lines not on this page · raw message

Signature · 1 line
1.7.0.4
#9 lore raw

PATCH 2/2 cmd_fat: add FAT write command

Quoted 5 lines · On Thu, 22 Mar 2012 15:38:56 +0100 Maximilian Schwerin <[email protected]> wrote:

Once CONFIG_FAT_WRITE is defined, users can invoke 'fatwrite' command that saves data in RAM as a FAT file.

This patch was originally part of

Quoted 8 lines

http://article.gmane.org/gmane.comp.boot-loaders.u-boot/121847

---
 README           |    8 +++++-
 common/cmd_fat.c |   57 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 63 insertions(+), 2 deletions(-)

Applied to u-boot-staging/agust at denx.de after fixing attribution tags and a typo. Thanks.

Hmm, emails to dg77.kim at samsung.com address are now rejected:
Recipient address rejected: User unknown (in reply to RCPT TO command)

common/cmd_fat.c U_BOOT_CMD( · line 231

Quoted 1 line
common/cmd_fat.c +1 -0
+	printf("%ld bytes write\n", size);

typo fixed, s/write/written/

Thanks,
Anatolij

#10 lore raw

PATCH 2/2 cmd_fat: add FAT write command

Quoted 18 lines · Anatolij Gustschin
Quoted 7 lines · On Thu, 22 Mar 2012 15:38:56 +0100 Maximilian Schwerin <[email protected]> wrote:

Once CONFIG_FAT_WRITE is defined, users can invoke 'fatwrite' command that saves data in RAM as a FAT file.

This patch was originally part of

http://article.gmane.org/gmane.comp.boot-loaders.u-boot/121847

Quoted 7 lines
---
 README           |    8 +++++-
 common/cmd_fat.c |   57
++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 63 insertions(+), 2 deletions(-)
Quoted 5 lines

Applied to u-boot-staging/agust at denx.de after fixing attribution tags and a typo. Thanks.

Hmm, emails to dg77.kim at samsung.com address are now rejected:
Recipient address rejected: User unknown (in reply to RCPT TO command)

Hi,

FYI: Now Mr. Kim is left the company. So if any issue and codes from Mr. Kim, then let me follow up.

Thank you,
Kyungmin Park

Quoted 13 lines

common/cmd_fat.c U_BOOT_CMD( · line 231

Quoted 3 lines
common/cmd_fat.c +1 -0
+	printf("%ld bytes write\n", size);

typo fixed, s/write/written/

Thanks,
Anatolij
_______________________________________________
U-Boot mailing list
U-Boot at lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot

#11 lore raw

PATCH 2/2 cmd_fat: add FAT write command

On Mon, 26 Mar 2012 09:34:07 +0900
Kyungmin Park <[email protected]> wrote:
...

Quoted 3 lines
Quoted 2 lines

Hmm, emails to dg77.kim at samsung.com address are now rejected:
Recipient address rejected: User unknown (in reply to RCPT TO command)

Hi,

Hi,

Quoted 2 lines

FYI: Now Mr. Kim is left the company. So if any issue and codes from Mr. Kim, then let me follow up.

Thanks for the info. When compiling the FAT write code with newer GCC 4.6.1 I've seen some warnings and fixed them by this patch [1]. Could you please look at this patch and if it is okay, then send your Acked-by?

Quoted 2 lines

Thank you,
Kyungmin Park

Thanks,
Anatolij

[1] http://patchwork.ozlabs.org/patch/148551/

#12 lore raw

PATCH 2/2 cmd_fat: add FAT write command

Quoted 25 lines

-----Urspr?ngliche Nachricht-----
Von: Anatolij Gustschin [mailto:agust at denx.de]
Gesendet: Montag, 26. M?rz 2012 09:13
An: Kyungmin Park
Cc: Maximilian Schwerin; u-boot at lists.denx.de
Betreff: Re: [U-Boot] [PATCH 2/2] cmd_fat: add FAT write command

On Mon, 26 Mar 2012 09:34:07 +0900
Kyungmin Park <[email protected]> wrote:
...

Quoted 2 lines
Quoted 2 lines

Hmm, emails to dg77.kim at samsung.com address are now rejected:
Recipient address rejected: User unknown (in reply to

RCPT TO command)

Quoted 1 line

Hi,

Hi,

Quoted 2 lines

FYI: Now Mr. Kim is left the company. So if any issue and codes from Mr. Kim, then let me follow up.

Thanks for the info. When compiling the FAT write code with newer GCC 4.6.1 I've seen some warnings and fixed them by this patch [1]. Could you please look at this patch and if it is okay, then send your Acked-by?

Quoted 8 lines
Quoted 2 lines

Thank you,
Kyungmin Park

Thanks,
Anatolij

[1] http://patchwork.ozlabs.org/patch/148551/

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20120326/b4fc4d0d/attachment.pgp>

#13 lore raw

PATCH 2/2 cmd_fat: add FAT write command

In reply to Anatolij Gustschin

Maybe some debug codes are included.

Quoted 29 lines · Anatolij Gustschin

On Mon, 26 Mar 2012 09:34:07 +0900
Kyungmin Park <[email protected]> wrote:
...

Quoted 3 lines
Quoted 2 lines

Hmm, emails to dg77.kim at samsung.com address are now rejected:
Recipient address rejected: User unknown (in reply to RCPT TO command)

Hi,

Hi,

Quoted 2 lines

FYI: Now Mr. Kim is left the company. So if any issue and codes from Mr. Kim, then let me follow up.

Thanks for the info. When compiling the FAT write code with newer GCC 4.6.1 I've seen some warnings and fixed them by this patch [1]. Could you please look at this patch and if it is okay, then send your Acked-by?

Quoted 2 lines

Thank you,
Kyungmin Park

Thanks,
Anatolij

[1] http://patchwork.ozlabs.org/patch/148551/
_______________________________________________
U-Boot mailing list
U-Boot at lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot