[Arm-wince] Introduction to nandflash driver development in WinCE

Source: Internet
Author: User

First, let's talk about flash. Flash is a kind of non-Easy Loss memory. Generally, flash storage devices are divided into nandflash and norflash. These two types of Flash have their own advantages and disadvantages. In terms of reading and writing speed, norflash reads faster and nandflash writes faster. The capacity of nandflash is generally much larger than that of norflash, And it is cheaper than the price. However, norflash supports xip, but nandflash does not, and nandflash may have bad blocks. Related comparisons are introduced in many articles on the Internet.

Here we will introduce the nandflash driver. In wince, we have special support for flash storage device drivers. Generally, FAL + FMD architecture is used in the traditional architecture. In Windows ce6.0 R2, the latest version of Wince also supports the MDD + PDD architecture. In the FAL + FMD architecture, the FAL layer is composedMicrosoftTo achieve this, we need to implement the relevant interface functions at the FMD layer. In the MDD + PDD architecture, MDD replaces the fal in the original architecture, while PDD is equivalent to the original FMD, as long as the PDD layer is implemented. If your system has been upgraded to wince6.0 R2, you can find the source code of these two architecture drivers under the \ wince600 \ public \ common \ oak \ DRIVERS directory. Since the MDD + PDD architecture is only supported in wince6.0 R2, I have not implemented it. Therefore, we will only introduce the nandflash driver development based on the FAL + FMD architecture. This is also the Flash Driver development architecture that everyone currently uses.

As mentioned above, we need to implement the relevant interfaces of the FMD layer. The following describes various interface functions:

1. pvoid fmd_init (lpctstr lpactivereg, ppci_reg_info pregin, ppci_reg_info pregout): This is the initialization function of the flash device. When the Flash Driver is to be loaded when the wince is started, the function is called to initialize the flash device. If your system has nandflash controller, You need to initialize your nandflash controller here. If not, you need to configure the chip selection and timing for your hardware design. Return a handle to indicate success. This handle will be used by the fmd_deinit (...) function. If it returns NULL, it indicates failure.

2. bool fmd_deinit (pvoid HFMD): This function is called when the nandflash driver is detached. The parameter is the handle returned by the fmd_init function. in this function, you can release resources and disable nandflash controller.

3. bool fmd_readsector (sector_addr startsectoraddr, lpbyte precise ctorbuff, precise ctorinfo precise ctorinfobuff, DWORD dwnumsectors): This function is used to read a sector of nandflash. For nandflash, a large page is divided into large pages and small pages. A large page contains 2048 bytes and a small page contains 512 bytes. Therefore, each slice of a large page has 2048 bytes, and each slice of a small page has 512 bytes.

Startsectoraddr: the starting address of the nandflash physical sector. For nandflash, It is the page from which nandflash starts.

Psectorbuff: sector data buffer. Data of each sector read from nandflash is stored in this buffer.

Psectorinfobuff: Sector Information buffer. Generally, the information of each sector is stored in the out-of-band data of nandflash. For small pages, out-of-band data is 16 bytes, and large pages are 64 bytes. Read the information about this sector from the out-of-band data of nandflash and store it in this buffer.

Dwnumsectors: number of sectors to read, which is equivalent to the number of pages to read in nandflash.

4. bool fmd_writesector (sector_addr startsectoraddr, lpbyte effecctorbuff, effecctorinfo extends ctorinfobuff, DWORD dwnumsectors): This function is used to write a sector of nandflash. The parameter has the same meaning as the above fmd_readsector parameter.

5. bool fmd_eraseblock (block_id blockid): This function is used to erase a block of nandflash. The parameter is the block address of the nandflash to be erased, that is, the first block.

6. DWORD fmd_getblockstatus (block_id blockid): This function obtains the status of a block in nandflash. The parameter is the block address of nandflash. Because nandflash may have bad blocks, this function first checks whether the current block is a bad block for nandflash, this generally reads out-of-band data of the current block's 0th pages and 1st pages. For small pages, nandflash generally reads 5th bytes. For large pages, nandflash generally reads 0th bytes. If it is not 0xff, this block is a bad block. Of course, we recommend that you check the datasheet of nandflash to determine which byte to read. If this block is found to be a bad block, block_status_bad should be returned. If it is not a bad block, you need to read the slice information of the starting slice of the block. If an error occurs while reading the information of this sector, block_status_unknown should be returned. Otherwise, unique information will be judged and corresponding results will be returned.

7. bool fmd_setblockstatus (block_id blockid, DWORD dwstatus): This function sets the status of a block in nandflash. The first parameter is the block address of nandflash, and the second parameter is the status to be set. In this function, first check whether dwstatus is block_status_bad. If yes, make the block mark for nandflash and return false. If not, write dwstatus to the sector info of The 0th pages of the block. This function is the opposite of the above function.

8. bool fmd_getinfo (pflashinfo): This function is used to return flash information. Pflashinfo is a structure containing flash information.

Pflashinfo-> flashtype: the type of flash. For nandflash, it should be NAND.

Pflashinfo-> wdatabytespersector: the number of bytes in a single slice. The value is 2048 for a large page and 512 for a small page.

Pflashinfo-> dwnumblocks: Total number of blocks in flash. Check the nandflash datasheet.

Pflashinfo-> wsectorsperblock: the number of sectors contained in each block.

Pflashinfo-> dwbytesperblock: the number of bytes contained in each block.

9. Void fmd_powerdown () and void fmd_powerup (): these two functions are used for power supply.Management. Fmd_powerdown () is used to power off the flash device, and fmd_powerup () is used to power back the flash device. Implement these two functions based on your processor and related hardware environment. If this parameter is not implemented, nandflash will not be affected.

10. bool fmd_oemiocontrol (...): Like many iocontrol functions, different cases are used to implement corresponding functions. For nandflash, the above cases do not always need to be implemented. In fact, if nothing is implemented, it does not affect the use of nandflash. The wince document defines some cases to be implemented. You can implement them or not.

For nandflash, You can implement the above functions. When nandflash was released, the manufacturer had marked the Bad blocks in nandflash. Therefore, during the first nandflash operation, do not erase nandflash, because it may erase the bad block mark, so that you cannot determine which block is a bad block.

For ECC verification, many processes currently include nandflash controller, and nandflash Controller provides hardware ECC functions. If you do not have the hardware ECC, you can also use the software ECC. The soft ECC code can be found under \ wince600 \ public \ common \ oak \ drivers \ block \ msflashfmd \ ECC. In general, ECC verification generates three-byte verification codes for 512 bytes. That is to say, for small pages, each page has three-byte ECC verification codes. For large pages, it contains 12 bytes. These verification codes should be written in the out-of-band data of the slice when writing the slice data. When reading sector data, the data is read first, and then calculated based on the data ECC, and then compared with the read ECC. If the data is consistent, it indicates that the data is correct.

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.