Introduction to MTD/CFI driver in Linux

Source: Internet
Author: User
Some Intel FLASH chips (such as the StrataFlash series) support multiple partitions, that is, each partition can be operated at the same time. it should be said that this is a good feature, but it will also bring some problems, remember the original

Some Intel FLASH chips (such as the StrataFlash series) support multiple partitions, that is, each partition can be operated at the same time. it should be said that this is a good feature, but it will also bring some problems, remember the original transplant Linux-2.4.21, hanging JFFS2 file system, often will report some "Magic bitmask not found" errors, followed in and found that FLASH read out are some 0x80 and other data, check the data and find that the FLASH has the partitioning feature. The FLASH Driver of Linux only uses one status variable to indicate the status of the entire FLASH, this will cause the actual status of a partition to be inconsistent with that recorded by the system. as a result, this point is not actually in the read status during FLASH reading. At that time, the solution was: no matter what the record status was during each read, the first entry into the status should be said. of course, this will bring about performance degradation, and the specific loss of the clock cycle will not be counted.

In the era of Linux-2.6.x (2.6.13), except Lock/Unlock) in addition to this old problem, the multi-partition error did not appear. surprised, I decided to study the MTD/FLASH Driver of Linux.

Before talking about the driver, let's clarify several programming points:

1: read/write, read/write according to the bus bit width, note that it is not the FLASH chip bit width (such as back-to-back ).

2: Addressing. the address to be accessed by the program is different from the address pin of the FLASH chip, for example, a 16-bit FLASH chip, for CPU, 0x00 and 0x01 indicate two different bytes, but the FLASH pins get 0, that is, they all point to the first WORD of FLASH. Bit0 of the address bus can be considered to be suspended or converted to the bus. bit0 actually outputs bit1. This explains key point 1.

3: The chip manual mentions that the offset is based on WORD, and the bit width of WORD depends on the bit width of the chip. Therefore, the actual offset = manual offset * buswidth/8 during the command.

4: The variable length (for example, CFI information) mentioned in the chip Manual. for example, 2 indicates that a variable is a 16-bit number, but two words must be read during reading, then, combine the low 8 bits of each WORD into a 16-bit number. It is really troublesome to read the WORD and then piece it together. especially when reading the large structure, it is easy to refer to the cfi_read_pri function of cfi_util.c.

5: back-to-back, that is, two 16-bit chips are connected to a 32-bit bus. The problem is addressing. Obviously, the first step is to read and write data in 32 bits. The second is the address of the command. the actual offset = manual offset * interleave * device_type/8, device_type = buswidth/interleave, while buswidth is 32 (bus bit width ). In addition, in back-to-back mode, the command and the returned status code are "dual copies", for example, two 16-bit back-to-back segments, and the read command is 0x00ff00ff.

If you don't want to write code as flexible as Linux (consider various methods, bit widths, CFI, and so on), it's much simpler, you only need to consider the key point 1 and the size of the erased block. of course, if it is a back-to-back method, the actual size of the erased block must be multiplied by an interleave.

Enter the Linux code

The relationship between CHIP, MAP, and MTD is still confused, so the following is just a simple explanation of the context and various programming points.

1: construct the map_info structure, specify the base address, bit width, size, and other information as well as the "cfi_probe" limitation, and then call do_map_probe ().

2: do_map_probe () find the chip driver "cfi_probe.c" based on the name "cfi_probe" and call cfi_probe () directly ().

3: cfi_probe () directly calls mtd_do_chip_probe () and passes in the cfi_probe_chip () function pointer.

4: mtd_do_chip_probe () is divided into two steps. First, call genprobe_ident_chips () to detect the chip information, and then call check_cmd_set () to obtain and initialize the chip command set (multi-partition initialization is in it ).

5: If the genprobe_ident_chips () function does not consider multi-chip connection, you only need to check the previous genprobe_new_chip () call. after the call, cfi. chipshift = cfi. cfiq-> DevSize, 2 ^ chipshift = FLASH size.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.