All of lore.kernel.org
 help / color / mirror / Atom feed
* [U-Boot] u-boot: How to read file from FAT filesystem on NorFlash MTD partition
@ 2009-11-15 14:56 Xianwei Zeng
  2009-11-15 18:48 ` Wolfgang Denk
  0 siblings, 1 reply; 8+ messages in thread
From: Xianwei Zeng @ 2009-11-15 14:56 UTC (permalink / raw)
  To: u-boot

Hello,

I hope I am not sending mail to the wrong mail list.

I am porting u-boot to our Xscale based board, with 32MB Nor Flash on
board. And in this board, it is required that, the u-boot should be able to
read some files from a FAT file system on one of the Nor Flash partitions.
The Nor Flash is managed as MTD device under Linux OS.

In current  u-boot implementation, I can use fatload to read files from
mmc or USB storage device, which is also FAT filesystem. And I can
also use fsload command to read files from JFFS2 filesytem on NorFlash
or NandFlash.

But I found I cann't uses these command to read files from a FAT filesystem
on NorFlash. I cann't format this partition to JFFS2 filesystem because it
is exported to Windows/Linux host via USB gadget after system boots up.

Can someone tell me the best way to solve this problem, or give me some
hints of which part of code I need to change?

I am creating a new command following fsload, using MTD devices in U-Boot,
and try to mount the FAT filesystem, but failed at reading the real file
data out,
although I can read the file name, the file size and the file start sector
number out.

-- 
Best Regards
Xianwei ZENG
----Linux Fans

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [U-Boot] u-boot: How to read file from FAT filesystem on NorFlash MTD partition
  2009-11-15 14:56 [U-Boot] u-boot: How to read file from FAT filesystem on NorFlash MTD partition Xianwei Zeng
@ 2009-11-15 18:48 ` Wolfgang Denk
  2009-11-16  1:29   ` Xianwei Zeng
  0 siblings, 1 reply; 8+ messages in thread
From: Wolfgang Denk @ 2009-11-15 18:48 UTC (permalink / raw)
  To: u-boot

Dear Xianwei Zeng,

In message <52c6d4120911150656w2edcf528oad05796e52b134f6@mail.gmail.com> you wrote:
>
> In current  u-boot implementation, I can use fatload to read files from
> mmc or USB storage device, which is also FAT filesystem. And I can
> also use fsload command to read files from JFFS2 filesytem on NorFlash
> or NandFlash.
> 
> But I found I cann't uses these command to read files from a FAT filesystem
> on NorFlash. I cann't format this partition to JFFS2 filesystem because it
> is exported to Windows/Linux host via USB gadget after system boots up.
> 
> Can someone tell me the best way to solve this problem, or give me some
> hints of which part of code I need to change?

It seems you did not enable mtdparts support in your configuration?


Best regards,

Wolfgang Denk

-- 
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
Systems programmers are the high priests of a low cult.
                                                       -- R.S. Barton

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [U-Boot] u-boot: How to read file from FAT filesystem on NorFlash MTD partition
  2009-11-15 18:48 ` Wolfgang Denk
@ 2009-11-16  1:29   ` Xianwei Zeng
  2009-11-16  6:40     ` Wolfgang Denk
  0 siblings, 1 reply; 8+ messages in thread
From: Xianwei Zeng @ 2009-11-16  1:29 UTC (permalink / raw)
  To: u-boot

Dear Wolfgang Denk,

Thank you for your reply.

On Mon, Nov 16, 2009 at 3:48 AM, Wolfgang Denk <wd@denx.de> wrote:

> Dear Xianwei Zeng,
>
> In message <52c6d4120911150656w2edcf528oad05796e52b134f6@mail.gmail.com>
> you wrote:
> >
> > But I found I cann't uses these command to read files from a FAT
> filesystem
> > on NorFlash. I cann't format this partition to JFFS2 filesystem because
> it
> > is exported to Windows/Linux host via USB gadget after system boots up.
> >
> > Can someone tell me the best way to solve this problem, or give me some
> > hints of which part of code I need to change?
>
> It seems you did not enable mtdparts support in your configuration?
>
>
Yes. I didn?t enable the mtdparts support. I will try it.

Do I need to write extra driver, for example something I was doing,
writing FAT + MTD support?

I am reading the u-boot source code, but didn't get any hint about
the FAT + MTD usage.

-- 
Best Regards
Xianwei ZENG
----Linux Fans

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [U-Boot] u-boot: How to read file from FAT filesystem on NorFlash MTD partition
  2009-11-16  1:29   ` Xianwei Zeng
@ 2009-11-16  6:40     ` Wolfgang Denk
  2009-11-16 12:46       ` Xianwei Zeng
  0 siblings, 1 reply; 8+ messages in thread
From: Wolfgang Denk @ 2009-11-16  6:40 UTC (permalink / raw)
  To: u-boot

Dear Xianwei Zeng,

In message <52c6d4120911151729s61a250e0j1b0ec02b43191036@mail.gmail.com> you wrote:
>
> Yes. I didn't enable the mtdparts support. I will try it.
>
> Do I need to write extra driver, for example something I was doing,
> writing FAT + MTD support?

No, you don't need any special drivers.

Best regards,

Wolfgang Denk

-- 
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
Overdrawn?  But I still have checks left!

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [U-Boot] u-boot: How to read file from FAT filesystem on NorFlash MTD partition
  2009-11-16  6:40     ` Wolfgang Denk
@ 2009-11-16 12:46       ` Xianwei Zeng
  2009-11-24  3:09         ` Xianwei Zeng
  0 siblings, 1 reply; 8+ messages in thread
From: Xianwei Zeng @ 2009-11-16 12:46 UTC (permalink / raw)
  To: u-boot

Dear Wolfgang Denk,

Sorry for the simple question, but I can't find the document to guide me
to read file from FAT file system in NOR FLASH.

On Mon, Nov 16, 2009 at 3:40 PM, Wolfgang Denk <wd@denx.de> wrote:

> Dear Xianwei Zeng,
>
> In message <52c6d4120911151729s61a250e0j1b0ec02b43191036@mail.gmail.com>
> you wrote:
> >
> > Yes. I didn't enable the mtdparts support. I will try it.
> >
> > Do I need to write extra driver, for example something I was doing,
> > writing FAT + MTD support?
>
> No, you don't need any special drivers.
>
>
After I enbale CONFIG_CMD_MTDPARTS, I can get MTD partition information.
For example, I set env to:

  mtdids=nor0=smt300-nor
  mtdparts=mtdparts=smt300-nor:4608k at 0x00080000(sys)ro

And then I can use mtdparts command to list the partition info:

device nor0 <smt300-nor>, # parts = 1
 #: name                size            offset          mask_flags
 0: sys                 0x00480000      0x00080000      1

But I still don't know the way how to read file inside this FAT filesystem.

  * Which command can do this? (fatload seems can not because the interface
is not known)
  * From which verion u-boot supports this feature? Our u-boot is based
v2009.08. Do we
    need to update to latest one? (v2009.11-rc1)

Any document you suggest me to read? u-boot/README is not enough.

Thank you very much.

-- 
Best Regards
Xianwei ZENG
----Linux Fans

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [U-Boot] u-boot: How to read file from FAT filesystem on NorFlash MTD partition
  2009-11-16 12:46       ` Xianwei Zeng
@ 2009-11-24  3:09         ` Xianwei Zeng
  0 siblings, 0 replies; 8+ messages in thread
From: Xianwei Zeng @ 2009-11-24  3:09 UTC (permalink / raw)
  To: u-boot

Hi,


> But I still don't know the way how to read file inside this FAT filesystem.
>
>   * Which command can do this? (fatload seems can not because the interface
> is not known)
>   * From which verion u-boot supports this feature? Our u-boot is based
> v2009.08. Do we
>     need to update to latest one? (v2009.11-rc1)
>
> I check the document and didn't found the answer. So I have to write it by
myself.

I created a patch which provide two functions:
  fat_norflash_init()
  fat_norflash_load()

The user call these function in sequence to read file from FAT file system
on Nor Flash.

Here is my code, it has not been cleaned for common use, so a little bit
ugly:

Index: b/common/fat_norflash.c
===================================================================
--- /dev/null
+++ b/common/fat_norflash.c
@@ -0,0 +1,148 @@
+/*
+ * (C) Copyright 2009
+ * Zeng Xianwei <xianweizeng@gmail.com>
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ */
+#include <config.h>
+#include <common.h>
+#include <asm/errno.h>
+#include <asm/arch/hardware.h>
+#include <part.h>
+#include <flash.h>
+
+#ifdef CONFIG_FAT_NORFLASH
+
+/* #define DEBUG */
+
+#ifdef DEBUG
+#define DPRINTF(args...)      printf(args)
+#else
+#define DPRINTF(args...)
+#endif
+
+extern flash_info_t flash_info[];
+extern int fat_register_device(block_dev_desc_t * dev_desc, int part_no);
+
+static block_dev_desc_t norflash_dev;
+
+struct fat_norflash_info_t {
+    unsigned long start;
+    int size;
+} fat_norflash_info;
+
+/* block read function, called by disk_read() in fat.c */
+static unsigned long
+norflash_bread(int dev, ulong blknr, lbaint_t blkcnt, void *dst)
+{
+    ulong src = fat_norflash_info.start + blknr * 512;
+
+    DPRINTF("== read: nr %ld cnt %ld src %lx dst %p ==\n",
+        blknr, blkcnt, src, dst);
+    memcpy((unsigned char *)dst, (unsigned char *)(src), blkcnt * 512);
+
+    return blkcnt;
+}
+
+int fat_norflash_init(uint32_t address, int size)
+{
+    int bank, cnt;
+    flash_info_t *info;
+
+    for (bank = 0; bank < CONFIG_SYS_MAX_FLASH_BANKS; ++bank) {
+        cnt = 0;
+        info = &flash_info[bank];
+
+        /* Nothing to do if the bank doesn't exist */
+        if (info->sector_count == 0)
+            continue;
+        /* Found */
+        if (address >= info->start[0] &&
+            address < (info->start[0] + info->size)) {
+            break;
+        }
+    }
+
+    if (bank == CONFIG_SYS_MAX_FLASH_BANKS)
+        return -ENODEV;
+
+    if (size > info->size) {
+        printf("Fat filesystem size exceeds entile flash size.\n");
+        return -EINVAL;
+    }
+
+    /* Valid flash infomation */
+    fat_norflash_info.start = address;
+    fat_norflash_info.size = size;
+    sprintf((char *)norflash_dev.vendor, "Flash ID: %ld", info->flash_id);
+
+    /* Initialize block layer */
+    norflash_dev.blksz = 512;
+    norflash_dev.lba = size / 512;
+    norflash_dev.part_type = PART_TYPE_DOS;
+    norflash_dev.dev = 0;
+    norflash_dev.lun = 0;
+    norflash_dev.type = DEV_TYPE_HARDDISK;
+    norflash_dev.removable = 0;
+    norflash_dev.block_read = norflash_bread;
+    norflash_dev.if_type = IF_TYPE_UNKNOWN;
+    norflash_dev.priv = &fat_norflash_info;
+
+    DPRINTF("Fat FileSystem on NorFlash at %lx size %lu bytes (%luMB) ",
+           address, size, size / (1024 * 1024));
+    return 0;
+}
+
+int
+fat_norflash_load(const char *filename, unsigned long load_addr,
+          unsigned long maxsize)
+{
+    struct fat_norflash_info_t *info =
+        (struct fat_norflash_info_t *)(norflash_dev.priv);
+    long size;
+    int ret;
+
+    if (!norflash_dev.blksz) {
+        printf("Fat on NorFlash has not been initialized.\n");
+        return -ENODEV;
+    }
+
+    ret = fat_register_device(&norflash_dev, 1);
+    if (ret) {
+        printf ("Unable to use fat on nor flash at %lx err %d\n",
+            info->start, ret);
+        return 1;
+    }
+
+    if (maxsize > info->size)
+        maxsize = info->size;
+
+    DPRINTF("Load file \"%s\" to memory %lx\n",  filename, load_addr);
+    size = file_fat_read (filename, (unsigned char *) load_addr, maxsize);
+    if (size == -1) {
+        printf("Unable to read \"%s\" from FAT in NorFlash at %lx\n",
+               filename, info->start);
+        return 1;
+    }
+
+    printf ("\n%ld bytes read\n", size);
+    return 0;
+}
+

-- 
Best Regards
Xianwei ZENG
----Linux Fans

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [U-Boot] u-boot: How to read file from FAT filesystem on NorFlash MTD partition
  2009-12-01 14:25 Stefan Roese
@ 2009-12-02  2:55 ` Xianwei Zeng
  0 siblings, 0 replies; 8+ messages in thread
From: Xianwei Zeng @ 2009-12-02  2:55 UTC (permalink / raw)
  To: u-boot

Hi Stefan,

On Tue, Dec 1, 2009 at 11:25 PM, Stefan Roese <sr@denx.de> wrote:

>
> This approach has multiple advantages:
>
> - Multiple file systems will be usable (FAT, EXT2 etc.)
> - Multiple MTD devices will be supported (NOR, NAND etc.)
>
>
I agree with you.

I though this is supported(and Wolfgang also told me that) in u-boot but
can't
find the documents, so I did it it a ugly but directly access way.


> It would be great if you could rework your patch according to my
> suggestions.
>

I will try it next week. Thank you for your suggestions.

-- 
Best Regards
Xianwei ZENG
----Linux Fans

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [U-Boot] u-boot: How to read file from FAT filesystem on NorFlash MTD partition
@ 2009-12-01 14:25 Stefan Roese
  2009-12-02  2:55 ` Xianwei Zeng
  0 siblings, 1 reply; 8+ messages in thread
From: Stefan Roese @ 2009-12-01 14:25 UTC (permalink / raw)
  To: u-boot

Hi,

sorry for jumping in so late, but Wolfgang just broughtthis thread to my 
attention. So here are my ideas and comments to your approach/patch:

> >   * Which command can do this? (fatload seems can not because the
> > interface is not known)
> >   * From which verion u-boot supports this feature? Our u-boot is based
> > v2009.08. Do we
> >     need to update to latest one? (v2009.11-rc1)
> >
> > I check the document and didn't found the answer. So I have to write it
> > by myself.
>
> I created a patch which provide two functions:
>   fat_norflash_init()
>   fat_norflash_load()
>
> The user call these function in sequence to read file from FAT file system
> on Nor Flash.

It's possible to do it this way of course, but we really shouldn't go this 
way. The "right way" to implement FAT support on NOR FLASH would be to add a 
small block layer to the MTD devices. And MTD block device could then be used 
by the existing file system drivers (e.g. fatls etc).

We already can export the NOR FLASH as an MTD device, using the 
CONFIG_FLASH_CFI_MTD config option. It shouldn't be too hard to add a block 
layer over this MTD device, like done in the Linux kernel 
(drivers/mtd/mtdblock_ro.c).

This approach has multiple advantages:

- Multiple file systems will be usable (FAT, EXT2 etc.)
- Multiple MTD devices will be supported (NOR, NAND etc.)

It would be great if you could rework your patch according to my suggestions.

Thanks.

Cheers,
Stefan

--
DENX Software Engineering GmbH,      MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich,  Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-0 Fax: (+49)-8142-66989-80 Email: office at denx.de

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2009-12-02  2:55 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-11-15 14:56 [U-Boot] u-boot: How to read file from FAT filesystem on NorFlash MTD partition Xianwei Zeng
2009-11-15 18:48 ` Wolfgang Denk
2009-11-16  1:29   ` Xianwei Zeng
2009-11-16  6:40     ` Wolfgang Denk
2009-11-16 12:46       ` Xianwei Zeng
2009-11-24  3:09         ` Xianwei Zeng
2009-12-01 14:25 Stefan Roese
2009-12-02  2:55 ` Xianwei Zeng

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.