FlashROM is a bug den

03/02/2020Bug's nest

Flashrom is a bug den

Embedded software often requires some form of access to flash ROM . If you are developing application layer software, you may be accessing it without being aware of the fact that it is a flash ROM. However, if you are using an area that stores values ​​even after the power is turned off (sometimes called secondary storage) and it is not a hard disk (HDD), most access to flash rom. There is no problem even if you think about it.

And this flash ROM actually has various pitfalls or precautions when using it, and bugs come to such places. As a result, the number of bugs related to flash ROMs increases, and flash ROMs become a bug den . Here are some things to keep in mind when dealing with flash roms.

What is Flash ROM?

By the way, what is Flash ROM ? It is sometimes called flash memory, but when written in English, it becomes Flush ROM. Since it is named ROM, it is Read Only memory, that is, read-only memory , and one of the rewritable ROMs is Flush ROM. Rewritable and read-only memory … You can’t write that it’s read-only, but you can write it because it’s rewritable … Yes, I don’t understand the meaning of Japanese.

In fact, as the name implies , flash ROM is an element that does not seem to make sense as an entity, so there is a reason for bugs to come here as well. The ROM remembers the information even when the power is turned off, but the information disappears in the flash rom after a few days. So, if various bad conditions overlap, the information may disappear in a few days. Can I call it ROM? There can be situations where you want to dig in unintentionally.

By the way, what is ROM ? ROM is actually a word that represents the type of memory element that is paired with the word RAM . ROM is Read Only Memory, which is read-only memory, and RAM is Random Access Memory, which is readable and writable memory .

There are various types of memory in this big group of ROM and RAM, and I will organize the situation around here in another article. Just keep in mind that the flash ROM is a strange memory element that is read-only but also writable .

By the way, flash ROM is a name that represents the type of memory element. And, as a part using this memory element called flash ROM, there are SD card and SSD (Solid State Drive) which is often used in recent PCs . In other words, there is a flash ROM in the SD card or SSD. Therefore, SD cards and SSDs are also flash ROMs in a broad sense, but since SD cards and SSDs access flash ROMs through the built-in controller IC , they are excluded this time, and flash ROM elements are excluded in this article. Here are some things to keep in mind when accessing directly .

Why are bugs coming?

By the way, why are there bugs in flash ROMs ? In fact, Flash ROM has the following three features that you don’t really care about when designing and implementing software .

  • Write speed changes : Writing may be awaited due to wear leveling, etc.
  • There is an upper limit on the number of writes : There is a limit of thousands to hundreds of thousands (worst case)
  • Data evaporates : In the worst case, data disappears in a few days

Let’s take a closer look at each feature.

Writing speed changes

Flash ROM takes 1 to 3 digits to read and write compared to DRAM (Dynamic Random Access Memory) used for main memory of PCs . Then, the speed of writing is variation in large, occasionally is Do very slow write me, in some cases , in seconds, you sometimes things happen that are writing to wait. This variation in writing speed varies depending on the type and usage of the flash ROM, so it cannot be said unconditionally, but there is a problem if it is not designed, implemented, or tested on the assumption that such a thing may occur. Will come out.

To the variation of the write speed to occur Furashuromu specific features in the software of the various levels in order to respond to that measures are carried out and due to the fact. And begin to detail introduce the technical description would but a little rough summarized easy because becomes long, ① block writing Read Veriy Wirte processing to take a long time ② window for air leveling is time to data copy for the It takes ③ It takes time for the garbage collection . Of these, ① is a process that is required each time a flash ROM is written, and it takes relatively the same amount of time, but ② and ③ are sometimes necessary and sometimes not necessary, and are executed only when necessary, so at that time. It only takes extra time . From the application software’s point of view, it seems to be a symptom that writing suddenly slows down at one point.

If it takes a little extra time, I don’t care so much, but if it takes a lot of time , for example, from a few hundred meters to a few seconds, the flash rom will be written for that much time. If you wait, various timeouts may occur and the process may end with an error. Care must be taken in design and implementation to prevent this from happening.

There is a limit on the number of writes

Due to its structure, flash ROM has an upper limit on the number of times it can be written or rewritten . This is a feature only of flash ROM because there is no upper limit to the number of rewrites in DRAM used for main memory of PCs. This is the upper limit of the number of rewrites, but it also varies greatly from hundreds of thousands to thousands depending on the type of flash ROM and usage conditions .

Until a long time ago, there were not so many types of flash ROMs, and most flash ROMs had an upper limit of hundreds of thousands of rewrites. Therefore, even with a device using flash memory, it was okay if the upper limit of the number of rewrites was set to hundreds of thousands.

However, various technologies have been created to increase the capacity, and the types of flash ROMs have increased depending on which technology was incorporated to create them. Nowadays, there are some that have various values ​​for the maximum number of rewrites. I have come. Of the flash ROMs published at the time of this writing, the one with the smallest rewrite limit is TLC’s Nnad type flash ROM, which is thousands of times . As the latest technology, QLC Nand type has also appeared, but there is not much information about the maximum number of rewrites yet. However, due to its structure, the upper limit of rewriting is expected to be smaller than that of the Nand type of TLC.

When the maximum number of rewrites reaches several thousand, the life of the flash ROM due to the maximum number of rewrites will be shorter than the life of the device itself unless it is used with caution . It is possible that the device itself can be used for about 10 years, but the flash ROM cannot be rewritten in about 3 years.

To prevent this, it is necessary to check the maximum number of rewrites from the type of flash ROM used in the device, and design and implement the necessary processing in the software accordingly. If you forget this, it will be a product with a short life, so it’s a bit bad.

Data evaporates

I mentioned that TLC Nand type flash roms have a rewrite limit of several thousand times, so you need to be careful, but in fact, Nand type flash roms have another very troublesome feature . That is, the data disappears over time . Of course, the data of any flashrom will disappear after a long period of decades or hundreds of years, but usually the device itself will be broken and lost by then, so it does not matter that the flashrom data disappears. Hmm.

For example, in MLC Nand type flash ROM , the stored data will be lost in 10 days under bad conditions . The condition is that the ambient temperature is about 60 degrees after rewriting about 3,000 times, which is close to the upper limit of rewriting . By the way, if the ambient temperature is 70 degrees, the data will disappear in about 3 days. The ambient temperature of 60 degrees or 70 degrees seems to be a very harsh condition, but it is about this temperature in the interior of a car parked in direct sunlight in summer.

If the lost data is a program, the device will not work even when the power is turned on, which is quite annoying. To prevent this from happening , you need to be careful when using Nand-type flash roms . By the way, TLC Nand type flash rom structurally loses data in a shorter period of time than MLC Nand type flash rom. However, at Gutara’s father’s company, TLC’s Nand type flash rom was not used in the product, so I do not know well because there was no information on how long the data would disappear.

SSD, SD card and MMC are ok

The features of the flash ROM introduced so far are the same for the flash ROM used for SSDs, SD cards and MMCs . However, with SSDs, SD cards, and MMCs, the built-in controller program incorporates processing to deal with these features or problems, so there are not many problems during actual use. Each instruction manual also contains precautions for use, so it is okay if you follow those precautions.

However, when the flash rom is incorporated into the company’s circuit as a raw element and the flash rom is used directly in the software, it is necessary to carefully design and implement it so that the features introduced here do not adversely affect it. I have. All of them have no problem in the early stage of development, and if you use them for a while, problems will be discovered, so like the time bomb bug of software, the range of influence when a problem occurs will be wide, so please be careful. Please handle it.

Return to the bug nest