Hi,
You might want to look at 'Flash Translation Layer'.
This allows to use Flash with large sectors (called Erase Units), but rewrite on small
sectors
(typically 512 bytes). These algorithms also look after Levelling, ensuring that the
Flash is
evenly written.
For a full Translation Layer, the main trick is that a double translation is performed
:
>From a Virtual address (the address your app sees) -> Logical address (the address if
your erase
units were sorted in logical order) -> physical address (the actual address in Flash).
I recently started working on some FTL code that I might end up putting in public
domain.
If you need to know more I can refer you to some material on Net, or answer some
questions.
Best Regards,
Kris
-----Original Message-----
From: A...@yahoogroups.com [mailto:A...@yahoogroups.com] On Behalf Of ilan12800
Sent: Monday, 28 January 2008 6:58 PM
To: A...@yahoogroups.com
Subject: [AT91SAM] Programming serial NAND memory with at91 microcontroller.
Hello, my name is Ilan.
The serial memory can be written only if all the bits on page program
sectors are set to '1'. The memory can be erased (set to one`s) only
in large sectors. A 16MB memory has got 64 sectors. I am writing to
memory small blocks about 256B size. So the method is to move the
sector that must be written to other location while updating a small
data on it.
This takes a lot of time, also uses overwriting many times.
There are certain methods for optimization. If someone knows how to
optimize writing on memory please tell me.
Best regards.

(You need to be a member of AT91SAM -- send a blank email to AT91SAM-subscribe@yahoogroups.com )
Hi,
> I wanted to ask if this method is ok or it has some problems.
It depends on whether you can store your pointers (allocation map) in some EEPROM or some
such.
If you can do that, then such a scheme would be OK, providing your map is stored in a
medium with
high endurance. It also of course depends on the frequency of writes and the map/flash
endurance.
But if you are maintaining the maps on your actual flash, then you run into all sorts of
problems.
In the latter case, consider this :
The idea is that each time you have to write a block (sector), you have to move your data
to a new
location so you're not excessively wearing your flash in certain areas.
But... you have to also maintain the location of the map(s) in flash. So, how can you do
this -
the data you store must always move to a new location, but so must the map itself !
So what do you do, write in flash where the maps are ? But then you're still writing to
the same
area of flash each time you write.... and so on.
The main answer to this problem is using what's called an 'inverse map'.
Picture a map in memory where each entry (in an array) tells where the corresponding
block
(sector) is stored. What you do instead is to store the array entry in the data block
itself.
(this kind of information is called OOB, Out Of Band data, it can be in the same block
within a
sector, or somewhere else in a sector)
Say that block # 51 in flash has an entry in your array map at offset # 18.
During boot up the inverse map is built up by scanning all blocks, and reading what array
entry it
belongs to. So when you're reading Data Block # 51, it will have a tag saying that this
block
belongs to Map entry # 18. This map is typically stored in RAM (with a 2 level
translation it's
called VPM, Virtual Page Map). This is a simplified outlook, but it serves to illustrate
the
principle.
There are various other problems to address. For example, in Flash you might have lots of
blocks
of data that are quite static (meaning they're mainly read, never really written). Your
algorithm
must address that too. The idea is that when you erase and write a new sector (erase
unit), that
you _swap_ static blocks with flash blocks that are written a lot. This also helps
levelling Flash
wear. The new erase/write of blocks will take place physically on the block that was
being read
and never really written. The block that was only being read is now sitting in Flash
where you
were writing a lot. And so on...
The other main thing you must address first for a full FTL is to look at the
Cumulative
Programming Time of your flash. FTL algorithms rely on the fact that you can write
certain blocks
in a sector (erase unit) and then later come back to write more 1s into 0s. This is
especially
true for flags that are maintained to indicate the status of data blocks. You might for
example
use 0xFFFF for a block that was erased, and then start writing 0 in individual bits to
indicate
the state of that block as time goes by. (This is to guard against data loss, for example
an
interruption while you're transferring a data block to another flash block etc.)
This is a very important part of the exercise. You have to consider what will happen if
a
transaction is interrupted !
The last missing key is of course logical as well. How do you know which sectors have
been erased
more than others ? The obvious choice is to maintain an erase counter for each sector.
Simply
writing new data to sectors with the lowest erase count is not enough either. You can
still have
data sticking to certain areas while others are not used evenly. There needs to be a part
of the
algorithm that frequently 'shuffles' things around a bit.
There are new problems to address there as well. For example, when you erase a sector you
might
lose the erase counter etc.
Perhaps one last thing to mention is the process of 'Folding'.
Your idea of splitting a large sector (again, in FTL it's called an Erase Unit) into lots
of
actual 512 byte sectors (blocks) is valid, that's how it's done.
The trick here is that your map in RAM can be small since you only need to have the
address of the
erase unit. The offset into the Erase Unit (the 512 byte block used within it) is the
logical
address. Further, when you move a block of data, you can keep the logical address. When
there are
no blocks left at the same offset ie. Logical address, a 'Replacement Map' is used (the
equivalent
of your 'cache' sector). You can then scan through a whole flash erase unit and transfer
all the
current blocks, freeing up that flash erase unit to be erased and prepared to store other
data
later on. This is in principle what's referred to as 'folding'.
As a note, if you use the exact FTL algorithms as provided by Intel they are public
domain, but
you MUST use them only on PCMCIA flash !!
I've been working on my own algos, but it's not finished yet. You can buy such code, but
IMO it's
unjustifiably expensive. I'd rather roll my own :-)
There's a lot more to this, but that's the core principle that can get you started.
> As I understood any type of FTL is not seen by the high level program, is it so?
That's correct. If the FTL is set up properly, everything is transparent to the app. The
higher
level addresses are referred to as 'Virtual addresses'. Note that there are further
special
algorithms to care of situations where you want to actually execute code from that flash.
It's
called XIP (Execute In Place), in your app (and mine) you don't have to worry about that.
You need
memory managers for that anyway.
> If you can please give me a link to some material about FTL.
Perhaps you could start with a Google for 'FTL' and 'Flash wear levelling'.
I can't remember all the links where I got the PDFs that illustrate the principles, but
it's easy
to find them on the Net.
Else, I could send a couple of articles directly (white papers etc.)
Best Regards,
Kris
-----Original Message-----
From: A...@yahoogroups.com [mailto:A...@yahoogroups.com] On Behalf Of i...@gmail.com
Sent: Monday, 28 January 2008 9:14 PM
To: A...@yahoogroups.com
Subject: [AT91SAM] Re: Programming serial NAND memory with at91 microcontroller.
Hello Kris,
I have made a pretty simple algorithm to solve this problem. I freed 2 erase sectors of
memory
(each 128*512 bytes). I use only writing and reading only 512 bytes blocks, at higher
level.
I used first large sector I freed as a cache where I put newly written or rewritten
blocks of
512B. As this sector ('cache sector') fills up the program discharges it to appropriate
blocks in
memory through using second large block ( the 'help' sector ).
I wanted to ask if this method is ok or it has some problems.
As I understood any type of FTL is not seen by the high level program, is it so?
If you can please give me a link to some material about FTL.

(You need to be a member of AT91SAM -- send a blank email to AT91SAM-subscribe@yahoogroups.com )