[U-Boot] [PATCH] fs/fat: add a parameter: allow_whole_dev to fat_register_device()

Josh Wu josh.wu at atmel.com
Thu Jun 12 07:57:23 CEST 2014


For SPL in FAT and envrionment load/save in FAT, to support no partition
table device (whole device is FAT partition). We need specify the partition
number as 0.

But in FAT SPL and environment case, when we specify the partition number as
1, it is reasonable to support the device has no partition table and only a
FAT partition.

This patch add a parameter: allow_whole_dev for fat_register_device(). If
allow_whole_dev is true, it will enable no partition table device.

In FAT SPL and FAT file environment, we call fat_register_device() with
allow_whole_dev as true. Other cases we call it with false.

Signed-off-by: Josh Wu <josh.wu at atmel.com>
---
 board/cm5200/fwupdate.c        |    2 +-
 board/esd/common/auto_update.c |    3 +--
 board/mcc200/auto_update.c     |    4 ++--
 common/env_fat.c               |    4 ++--
 common/spl/spl_fat.c           |    2 +-
 fs/fat/fat.c                   |   15 +++++++++++----
 include/fat.h                  |    3 ++-
 7 files changed, 20 insertions(+), 13 deletions(-)

diff --git a/board/cm5200/fwupdate.c b/board/cm5200/fwupdate.c
index 06d5023..801d82a 100644
--- a/board/cm5200/fwupdate.c
+++ b/board/cm5200/fwupdate.c
@@ -120,7 +120,7 @@ static int load_rescue_image(ulong addr)
 	/* Detect partition */
 	for (partno = -1, i = 0; i < 6; i++) {
 		if (get_partition_info(stor_dev, i, &info) == 0) {
-			if (fat_register_device(stor_dev, i) == 0) {
+			if (fat_register_device(stor_dev, i, false) == 0) {
 				/* Check if rescue image is present */
 				FW_DEBUG("Looking for firmware directory '%s'"
 					" on partition %d\n", fwdir, i);
diff --git a/board/esd/common/auto_update.c b/board/esd/common/auto_update.c
index 85c3567..d2dd76a 100644
--- a/board/esd/common/auto_update.c
+++ b/board/esd/common/auto_update.c
@@ -30,7 +30,6 @@ extern int N_AU_IMAGES;
 #define MAX_LOADSZ 0x1c00000
 
 /* externals */
-extern int fat_register_device(block_dev_desc_t *, int);
 extern int file_fat_detectfs(void);
 extern long file_fat_read(const char *, void *, unsigned long);
 long do_fat_read (const char *filename, void *buffer,
@@ -390,7 +389,7 @@ int do_auto_update(void)
 		}
 	}
 
-	if (fat_register_device (stor_dev, 1) != 0) {
+	if (fat_register_device(stor_dev, 1, false) != 0) {
 		debug ("Unable to register ide disk 0:1\n");
 		return -1;
 	}
diff --git a/board/mcc200/auto_update.c b/board/mcc200/auto_update.c
index 43173ce..6cc12d5 100644
--- a/board/mcc200/auto_update.c
+++ b/board/mcc200/auto_update.c
@@ -106,7 +106,7 @@ ulong totsize;
 #define KEYPAD_MASK_HI	((1<<(KEYPAD_COL-1+(KEYPAD_ROW*3-3)))>>8)
 
 /* externals */
-extern int fat_register_device(block_dev_desc_t *, int);
+extern int fat_register_device(block_dev_desc_t *, int, bool);
 extern int file_fat_detectfs(void);
 extern long file_fat_read(const char *, void *, unsigned long);
 extern int i2c_read (unsigned char, unsigned int, int , unsigned char* , int);
@@ -373,7 +373,7 @@ int do_auto_update(void)
 		res = -1;
 		goto xit;
 	}
-	if (fat_register_device(stor_dev, 1) != 0) {
+	if (fat_register_device(stor_dev, 1, false) != 0) {
 		debug ("Unable to use USB %d:%d for fatls\n",
 			au_usb_stor_curr_dev, 1);
 		res = -1;
diff --git a/common/env_fat.c b/common/env_fat.c
index aad0487..b36e08e 100644
--- a/common/env_fat.c
+++ b/common/env_fat.c
@@ -67,7 +67,7 @@ int saveenv(void)
 		return 1;
 	}
 
-	err = fat_register_device(dev_desc, part);
+	err = fat_register_device(dev_desc, part, true);
 	if (err) {
 		printf("Failed to register %s%d:%d\n",
 			FAT_ENV_INTERFACE, dev, part);
@@ -117,7 +117,7 @@ void env_relocate_spec(void)
 		return;
 	}
 
-	err = fat_register_device(dev_desc, part);
+	err = fat_register_device(dev_desc, part, true);
 	if (err) {
 		printf("Failed to register %s%d:%d\n",
 			FAT_ENV_INTERFACE, dev, part);
diff --git a/common/spl/spl_fat.c b/common/spl/spl_fat.c
index 56be943..c7a4fd6 100644
--- a/common/spl/spl_fat.c
+++ b/common/spl/spl_fat.c
@@ -25,7 +25,7 @@ static int spl_register_fat_device(block_dev_desc_t *block_dev, int partition)
 	if (fat_registered)
 		return err;
 
-	err = fat_register_device(block_dev, partition);
+	err = fat_register_device(block_dev, partition, true);
 	if (err) {
 #ifdef CONFIG_SPL_LIBCOMMON_SUPPORT
 		printf("%s: fat register err - %d\n", __func__, err);
diff --git a/fs/fat/fat.c b/fs/fat/fat.c
index 54f42ea..ad08cde 100644
--- a/fs/fat/fat.c
+++ b/fs/fat/fat.c
@@ -81,7 +81,8 @@ int fat_set_blk_dev(block_dev_desc_t *dev_desc, disk_partition_t *info)
 	return -1;
 }
 
-int fat_register_device(block_dev_desc_t *dev_desc, int part_no)
+int fat_register_device(block_dev_desc_t *dev_desc, int part_no,
+			bool allow_whole_dev)
 {
 	disk_partition_t info;
 
@@ -91,9 +92,15 @@ int fat_register_device(block_dev_desc_t *dev_desc, int part_no)
 	/* Read the partition table, if present */
 	if (get_partition_info(dev_desc, part_no, &info)) {
 		if (part_no != 0) {
-			printf("** Partition %d not valid on device %d **\n",
-					part_no, dev_desc->dev);
-			return -1;
+			/*
+			 * If part_no = 1, we will support whole partition
+			 * device if allow_whole_dev is true
+			 */
+			if (!(allow_whole_dev && part_no == 1)) {
+				printf("** Partition %d not valid on device %d **\n",
+				       part_no, dev_desc->dev);
+				return -1;
+			}
 		}
 
 		info.start = 0;
diff --git a/include/fat.h b/include/fat.h
index 63cf787..df15945 100644
--- a/include/fat.h
+++ b/include/fat.h
@@ -203,7 +203,8 @@ long file_fat_read_at(const char *filename, unsigned long pos, void *buffer,
 long file_fat_read(const char *filename, void *buffer, unsigned long maxsize);
 const char *file_getfsname(int idx);
 int fat_set_blk_dev(block_dev_desc_t *rbdd, disk_partition_t *info);
-int fat_register_device(block_dev_desc_t *dev_desc, int part_no);
+int fat_register_device(block_dev_desc_t *dev_desc, int part_no,
+			bool allow_whole_dev);
 
 int file_fat_write(const char *filename, void *buffer, unsigned long maxsize);
 int fat_read_file(const char *filename, void *buf, int offset, int len);
-- 
1.7.9.5



More information about the U-Boot mailing list