2009-01-28 07:57:22     Read - Write Bytes in Parallel NOR Flash @ BF-537 STAMP Board

Document created by Aaronwu Employee on Aug 9, 2013
Version 1Show Document
  • View in full screen mode

2009-01-28 07:57:22     Read - Write Bytes in Parallel NOR Flash @ BF-537 STAMP Board

Samuel Ayet (SPAIN)

Message: 68474   

 

Hi all,

 

I'm using the BF-537 STAMP board with the 2008R1.5 and what I want is read and write to the flash about 64bytes (just some data options of my program) because I need store this data in a non volatile memory and I don't need any file system support because only are 64bytes, I only need to see 64 bytes of flash as a little chunck of continous memory. I have seen that MTD makes things easy in memoryes because is a layer of abstraction for memory devices, but I'm not sure if this will help me and how will do it. I have read this document: http://docs.blackfin.uclinux.org/doku.php?id=linux-kernel:mtd&s[]=nor&s[]=flash and I have activated the options for the paralell NOR flash and when I boot I get this information:

 

Creating 4 MTD partitions on "physmap-flash.0":

0x00000000-0x00040000 : "Bootloader"

0x00040000-0x00120000 : "Kernel"

0x00120000-0x003f0000 : "RootFS"

0x003f0000-0x00400000 : "MAC Address"

 

 

Then I try to mount the RootFS and I can't mount the mtd2 / mtdblock2 (RootFS). Just I type:

 

 

 

root>> mount -t jff2s /dev/mtdblock2 /mnt

 

And I get:

 

Cowardly refusing to erase blocks on filesystem with no valid JFFS2 nodes

empty_blocks 3, bad_blocks 0, c->nr_blocks 45

 

 

What's wrong?

 

Exactly what I need is two functions for read write to the flash of my board (Parallel NOR Flash - M29W32) and the prototypes of this functions may be something like this:

 

/* Function Read */

 

data = read_from_flash (int address);

 

/* Function Write */

 

status = write_to_flash(int address, char data);

 

 

 

If someone could help me  and tell how to solve this problem (with any other file system or with a flash Driver of uClinux) it will be helpfull for me.

 

 

 

Thank You for your patience!

 

Samuel

QuoteReplyEditDelete

 

 

2009-01-28 13:39:13     Re: Read - Write Bytes in Parallel NOR Flash @ BF-537 STAMP Board

Robin Getz (UNITED STATES)

Message: 68485   

 

Samuel:

 

Just like your desktop -- you need to format a parition before you can mount it. (if you don't need file systems support - why mount as jffs2?)

 

-Robin

 

 

QuoteReplyEditDelete

 

 

2009-01-28 14:11:59     Re: Read - Write Bytes in Parallel NOR Flash @ BF-537 STAMP Board

Mike Frysinger (UNITED STATES)

Message: 68487   

 

like Robin said, you need to prepare things first:

http://docs.blackfin.uclinux.org/doku.php?id=linux-kernel:jffs

 

and like he said, why not just use the last partition to store your data ?  that last flash block is 65k and we only use it to store the MAC address in the first few bytes.  so you could use it via /dev/mtdchar3 to store your data.

QuoteReplyEditDelete

 

 

2009-01-29 05:03:38     Re: Read - Write Bytes in Parallel NOR Flash @ BF-537 STAMP Board

Samuel Ayet (SPAIN)

Message: 68506   

 

In the http://docs.blackfin.uclinux.org/doku.php?id=linux-kernel:jffs says that I need to flash my  flash memory with a jffs2 image and I don't really need have all my image root file system in flash. I use the file system jffs2 because i think will be easyer to write in the flash...but i don't know if i'm wrong... How can I use the '/devmtdchar3' to store my data? I mean, I have to format (loosing the MAC) and then mount? How can i directly write in it? I don't know exactly how to write in this partition as you can see.. Running uClinux 'root>>ls-l /dev' there is no device called mtdchar3, do you mean mtdblock3?

 

root>> ls -l /dev

 

crw-rw----    1 root     root       1,   1 Jan  1 08:33 mem

crw-rw----    1 root     root      90,   0 Jan  1 08:33 mtd0

crw-rw----    1 root     root      90,   1 Jan  1 08:33 mtd0ro

crw-rw----    1 root     root      90,   2 Jan  1 08:33 mtd1

crw-rw----    1 root     root      90,   3 Jan  1 08:33 mtd1ro

crw-rw----    1 root     root      90,   4 Jan  1 08:33 mtd2

crw-rw----    1 root     root      90,   5 Jan  1 08:33 mtd2ro

crw-rw----    1 root     root      90,   6 Jan  1 08:33 mtd3

crw-rw----    1 root     root      90,   7 Jan  1 08:33 mtd3ro

brw-rw----    1 root     root      31,   0 Jan  1 08:33 mtdblock0

brw-rw----    1 root     root      31,   1 Jan  1 08:33 mtdblock1

brw-rw----    1 root     root      31,   2 Jan  1 08:33 mtdblock2

brw-rw----    1 root     root      31,   3 Jan  1 08:33 mtdblock3

 

QuoteReplyEditDelete

 

 

2009-01-29 11:18:42     Re: Read - Write Bytes in Parallel NOR Flash @ BF-537 STAMP Board

Mike Frysinger (UNITED STATES)

Message: 68519   

 

enable the MTD char layer in the kernel then

 

there is no formatting or filesystems or anything.  you simply read/write it like a file.

QuoteReplyEditDelete

 

 

2009-01-30 06:23:58     Re: Read - Write Bytes in Parallel NOR Flash @ BF-537 STAMP Board

Samuel Ayet (SPAIN)

Message: 68575   

 

First, thank you for this information! Ok, I have enabled the MTD direct char access. I have read here: "http://docs.blackfin.uclinux.org/doku.php?id=device_files" that /dev/mtdchar# is not the devide wich I have to use to read/write a raw chars in the flash. The correct device is /dev/mtd# (where # means to the number of the MTD partition).  I have a problem reading the MTD partition of the "MAC Address" (Permision denided) but only with this partition (readin mtd2 for example I have permision). The program I have used just open the mtd3 device and try to read 1024 bytes of the flash. This is the program used:

 

int main(int argc, char* argv[], char** envp){

 

    int fd,read,i;

    unsigned char buff[1024];

 

    printf("Opening File Descriptor of MTD raw char...");

    fd = open("/dev/mtd3", O_RDWR);

    if (fd == -1){

        printf("Error: %s \n",strerror(errno));

    }

    else{

        printf("O.K.\n");

    }

  

    read = read(fd,&buff,1024);

 

    if(read < 0){

        printf("Error reading at MTD: %s\n",strerror(errno));

    }

 

    else{

        for(i=0;i<leidos;i++){

            printf("Character number %d read is: %0x\n",i,buff[i]);

        }

    }

}

 

Here are the MTD partitions shown at the start up of uClinux:

 

Creating 4 MTD partitions on "physmap-flash.0":

0x00000000-0x00040000 : "Bootloader"

0x00040000-0x00120000 : "Kernel"

0x00120000-0x003f0000 : "RootFS"

0x003f0000-0x00400000 : "MAC Address"

 

 

And I have the Error of 'Permision Denided'. Trying to solve this, I have changed the permisions of this device: 'chmod 777 /dev/mtd3' and I don't have solved nothing because I get the same error, 'Permision Denided', and I don't have any other ideas why I have this problem.

 

Note that if I use '/dev/mtd2' (the Root File System partiton) I don't have this problem. And the final question is: How can I get the Permision to read/write to the '/dev/mtd3'?

 

Thank you verty much!

QuoteReplyEditDelete

 

 

2009-01-30 06:42:59     Re: Read - Write Bytes in Parallel NOR Flash @ BF-537 STAMP Board

Samuel Ayet (SPAIN)

Message: 68576   

 

Note: If I open the /dev/mtd3 as O_RDONLY it let me read the flash. I don't have permision to write only. Thank you!

QuoteReplyEditDelete

 

 

2009-01-30 07:20:02     Re: Read - Write Bytes in Parallel NOR Flash @ BF-537 STAMP Board

Samuel Ayet (SPAIN)

Message: 68577   

 

Note 2: In the MTD partitions where I have permission to write (for example "/dev/mtd2") I can't write due to a error.

 

MTD do_write_oneword(): software timeout

MTD do_write_oneword(): software timeout

MTD do_write_oneword(): software timeout

Input/output error

 

 

 

So I only can read flash (any mtd partition), but I can't write nothing in it (any mtd partition )... Any ideas?

 

QuoteReplyEditDelete

 

 

2009-01-30 08:12:15     Re: Read - Write Bytes in Parallel NOR Flash @ BF-537 STAMP Board

Samuel Ayet (SPAIN)

Message: 68579   

 

Note3: New Idea. I have thought: Maybe is a protected sector of the u-boot?...and yes...is a protected sector of the u-boot. If in the u-boot we see the file info ('flinfo') we can se that the mtd3 (0x203F0000 to 0x20400000) is protected to READ ONLY. This may afect in my error? I try to unprotect it 'protect off 0x203F0000 0x20400000' but everytime I reboot, the block return to be protected... Now I don't have any more Ideas...sorry...can anyone help me please?

 

bf537> flinfo

Bank # 1: ST Microelectronics

20000000 (RO) 20002000 (RO) 20004000 (RO) 20006000 (RO) 20008000 (RO)

2000A000 (RO) 2000C000 (RO) 2000E000 (RO) 20010000 (RO) 20020000

20030000 20040000 20050000 20060000 20070000

20080000 20090000 200A0000 200B0000 200C0000

200D0000 200E0000 200F0000 20100000 20110000

20120000 20130000 20140000 20150000 20160000

20170000 20180000 20190000 201A0000 201B0000

201C0000 201D0000 201E0000 201F0000 20200000

20210000 20220000 20230000 20240000 20250000

20260000 20270000 20280000 20290000 202A0000

202B0000 202C0000 202D0000 202E0000 202F0000

20300000 20310000 20320000 20330000 20340000

20350000 20360000 20370000 20380000 20390000

203A0000 203B0000 203C0000 203D0000 203E0000

203F0000 (RO)

QuoteReplyEditDelete

 

 

2009-01-30 09:33:53     Re: Read - Write Bytes in Parallel NOR Flash @ BF-537 STAMP Board

Mike Frysinger (UNITED STATES)

Message: 68583   

 

the last partition is marked as read only in the partition map in the boards file.  you will need to change that if you want to write to it.

Attachments

    Outcomes