From: Andy Fleming Date: Thu, 30 Oct 2008 17:35:39 -0500 Subject: [U-Boot] [PATCH 10/10] fs: make the static array to dynamic allocation In-Reply-To: <1225406139-21485-10-git-send-email-afleming@freescale.com> References: <1225406139-21485-1-git-send-email-afleming@freescale.com> <1225406139-21485-2-git-send-email-afleming@freescale.com> <1225406139-21485-3-git-send-email-afleming@freescale.com> <1225406139-21485-4-git-send-email-afleming@freescale.com> <1225406139-21485-5-git-send-email-afleming@freescale.com> <1225406139-21485-6-git-send-email-afleming@freescale.com> <1225406139-21485-7-git-send-email-afleming@freescale.com> <1225406139-21485-8-git-send-email-afleming@freescale.com> <1225406139-21485-9-git-send-email-afleming@freescale.com> <1225406139-21485-10-git-send-email-afleming@freescale.com> Message-ID: <1225406139-21485-11-git-send-email-afleming@freescale.com> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de From: Dave Liu Current fat.c have three 64KB static array, it makes the BSS section larger. Change the static to dynamic allocation. Signed-off-by: Dave Liu --- fs/fat/fat.c | 38 +++++++++++++++++++++++++++++++++++--- 1 files changed, 35 insertions(+), 3 deletions(-) diff --git a/fs/fat/fat.c b/fs/fat/fat.c index 2f0bd8c..e3563aa 100644 --- a/fs/fat/fat.c +++ b/fs/fat/fat.c @@ -28,6 +28,7 @@ #include #include #include +#include #include #include @@ -63,6 +64,37 @@ int disk_read (__u32 startblock, __u32 getsize, __u8 * bufptr) return -1; } +__u8 *get_vfatname_block; +__u8 *get_dentfromdir_block; +__u8 *do_fat_read_block; +static int fat_mem_done = 0; +static int fat_memory_alloc(void) +{ + if (fat_mem_done) + return 0; + + get_vfatname_block = (__u8 *)malloc(MAX_CLUSTSIZE); + if (!get_vfatname_block) { + printf("alloc get_vfatname_block failed\n\r"); + return -1; + } + + get_dentfromdir_block = (__u8 *)malloc(MAX_CLUSTSIZE); + if (!get_dentfromdir_block) { + printf("alloc get_dentfromdir_block failed\n\r"); + return -1; + } + + do_fat_read_block = (__u8 *)malloc(MAX_CLUSTSIZE); + if (!do_fat_read_block) { + printf("alloc do_fat_read_block failed\n\r"); + return -1; + } + + fat_mem_done = 1; + + return 0; +} int fat_register_device(block_dev_desc_t *dev_desc, int part_no) @@ -70,6 +102,9 @@ fat_register_device(block_dev_desc_t *dev_desc, int part_no) unsigned char buffer[SECTOR_SIZE]; disk_partition_t info; + if (fat_memory_alloc()) + printf("fat memory alloc failed\n\r"); + if (!dev_desc->block_read) return -1; cur_dev = dev_desc; @@ -433,7 +468,6 @@ slot2str(dir_slot *slotptr, char *l_name, int *idx) * into 'retdent' * Return 0 on success, -1 otherwise. */ -__u8 get_vfatname_block[MAX_CLUSTSIZE]; static int get_vfatname(fsdata *mydata, int curclust, __u8 *cluster, dir_entry *retdent, char *l_name) @@ -519,7 +553,6 @@ mkcksum(const char *str) * Get the directory entry associated with 'filename' from the directory * starting at 'startsect' */ -__u8 get_dentfromdir_block[MAX_CLUSTSIZE]; static dir_entry *get_dentfromdir (fsdata * mydata, int startsect, char *filename, dir_entry * retdent, int dols) @@ -725,7 +758,6 @@ read_bootsectandvi(boot_sector *bs, volume_info *volinfo, int *fatsize) } -__u8 do_fat_read_block[MAX_CLUSTSIZE]; /* Block buffer */ long do_fat_read (const char *filename, void *buffer, unsigned long maxsize, int dols) -- 1.5.4.GIT