Nios® V/II Embedded Design Suite (EDS)
Support for Embedded Development Tools, Processors (SoCs and Nios® V/II processor), Embedded Development Suites (EDSs), Boot and Configuration, Operating Systems, C and C++
12590 Discussions

How can i read ans write on flash memory on uClinux

Altera_Forum
Honored Contributor II
1,745 Views

hello all 

I want to save some setting for my application need, so i want to use the flash, 

so how can i write and read from flash using driver or directly from applcation
0 Kudos
8 Replies
Altera_Forum
Honored Contributor II
472 Views

I'm going to assume CFI flash and answer from perspective of FPGA design. (If not correct, you can clarify your question.) You can instantiate a Nios II cpu core to interface to the flash and then use driver (i.e., C code) or Nios Flash Programmer to read/write the flash. Another way is to instantiate only the Flash CFI core from Altera and a couple of Avalon MM Masters to interface your application logic to the flash. This way, writing to a set of registers in your application logic will read/write flash. (See attachment for example instantiation, it may help or it may confuse you further.) Yet another way is to write your own state machine to bridge between your application logic and the flash. This is what the Altera's CFI Flash core basically is, just a simple state machine. Hope this points you in the right direction. 

 

 

 

--- Quote Start ---  

hello all 

I want to save some setting for my application need, so i want to use the flash, 

so how can i write and read from flash using driver or directly from applcation 

--- Quote End ---  

0 Kudos
Altera_Forum
Honored Contributor II
472 Views

If you don't need to additionally read or write the flash with any non-Linux system, IMHO the way to go is using a standard Linux Flash file system. I some time ago was able to read / write files in the flash of a NEEK dev board by just using what the community distribution provided out of the box. I used JFFS2, but AFAIK, nowadays UBIFS is recommended over JFFS2. 

 

see:  

http://www.alterawiki.com/wiki/mtd 

http://www.alterawiki.com/wiki/flashprogrammer 

http://www.alterawiki.com/wiki/ubifs 

http://www.alterawiki.com/wiki/initialization_script 

http://www.alterawiki.com/wiki/using_haserl_scripts_for_html_based_runtime_configuration_and_monitoring 

 

-Michael
0 Kudos
Altera_Forum
Honored Contributor II
472 Views

the question is , how i can save some data ( array of 1024 byte for exemple) in my flash memory , 

in my application start i want to read this data from flash memory to do somthing , i dont know how , if i need to write a driver or only from user space using api or somthing like that ?
0 Kudos
Altera_Forum
Honored Contributor II
472 Views

Exactly this is described in the links I posted. 

 

The "Linux way" definitely is using files in a flash file system. Why installing Linux if not making use of it's advantages ?  

-Michael
0 Kudos
Altera_Forum
Honored Contributor II
472 Views

there is no simple way to do , !!!!!!!!!!!

0 Kudos
Altera_Forum
Honored Contributor II
472 Views

?????? 

There is nothing simpler than reading and writing a file.  

 

-Michael
0 Kudos
Altera_Forum
Honored Contributor II
472 Views

oh Ok , you want to say , i just take memory as file , ok ok 

but i in my flash , i have put my zimage of µclinux , so how i can do , to dont' write on my Zimage zone,
0 Kudos
Altera_Forum
Honored Contributor II
472 Views

In the wiki you will find how to use MTD to define a Flash area as a block device a file system can be mounted on. Of course this area can be restricted to a part of the hardware-address space of the flash.  

 

But mind, that the hardware of flash chips is organized in blocks of bytes, that only can be erased (and thus modified) completely. The size and count of the blocks depends on the type of the chip used.  

 

Also mind that there is a "wear-out" effect: each block of a Flash chip can only be erased a maximum count of times.  

 

A dedicated Flash File System takes care of this by adding updated data in free places and using the blocks it manages in a cyclic way. To do this decently it needs to be allowed to use an appropriately large count of blocks.  

 

There are "Program" Flash chips with large blocks and small maximum erase count and there are "data" Flash chips with small blocks and high maximum erase count (there are multiple more types, as well). 

 

If you want to use the same flash chip(s) for your Image and for storing changeable data, beware that you use enough blocks to avoid destroying the chip by erasing a block too often.  

 

Using Flash memory is not trivial at all. So if possible you should not try to do propriety software to manage it.  

 

-Michael
0 Kudos
Reply