Http://www.ej38.com/showinfo/flash-147650.html-
Notes for writing the nor Flash Driver Under uboot
Version: 0.8
Data: 20090823
Author: crifan
Mail: Green-waste (AT) 163.com
Recently, I encountered some detours and recorded them. I may be able to help others. It can also be recorded by yourself. If necessary, it should be checked later.
【Terms in nor flash]
1.
Bottom/top boot sect (bottom/top boot block)
The so-called boot sect means that nor flash is not the same as NAND Flash. From the beginning to the end, NAND Flash is composed of pages of the same size.
Nor flash generally has a boot sect. It seems that due to historical reasons, nor flash is often used as a device for storing startup code, that is, starting from nor flash, this boot sect block is specially designed to store startup code. According to the description in Datasheet, the first or last one is bottom sect. Therefore, it is the last 64 kB block and is divided into four independent blocks. The first 16kb is used for a small amount of system initialization code. Two 8 KB blocks are used to store parameters. The remaining 32 KB block is called the main block, which is used to store application code.
2.
Sector (sector)
The sector (sector) Here is the smallest erased unit in Flash: block ).
So sector count is the number of blocks.
3.
Sector count (number of sectors) and sector list
Here, the nor flash, m29w320db, has a total of 63 normal 64 kB blocks, plus the four blocks previously mentioned as a normal 64 kB block, so 63 + 4 = 67.
The so-called "sector list" in the driver, that is, the block list, and the code comments are clearly written:
Ulong
Start [pai_max_flash_sect];
/* Physical sector Start Addresses */
Used to store the starting address of each block. You also need to initialize the driver. For m29w320db here, it is also very simple. Add the block size 64 K from the start order until the last three, calculate the corresponding address, and enter it.
4.
Protect (write protection)
Nor flash provides corresponding protection mechanisms from the register configuration and hardware of the software to prevent data that does not need to be modified or deleted intentionally or unintentionally. For example, some mechanisms store some system startup parameters of flash in nor flash, or for some other reason, only allow you to use part of nor flash space, in the flash_info_t struct of uboot, set the corresponding bit to 1:
Uchar
Protect [pai_max_flash_sect];/* sector protection status
*/
In this way, the program can avoid intentionally or unintentionally erasing useful data.
[WritePrecautions for nor Flash Driver]
1.
Bit Width (bitwidth, X8/x16/x32)
In nor flash controller, here I use the promecell pl172 and mpmc (multiport memory controller) of arm, which can be connected to a variety of different storage devices, such as static memory ), nor flash, and you can set whether to support page mode, extended wait, and write protection (Enable write protection, you can see that it is ROM.
After the mpmc and nor flash on the hardware are connected. Before using nor flash, initialize mpmc.
Note that the bit width is not noticed at the beginning. Therefore, when initializing mpmc, The mpmcstaticconfig register is set to x16 (16 bits). However, later, I went to uboot to find another person's nor Flash Driver (refer to \ board \ OXC \ flash. c), the issued command reads the ID, which is also X8 (8 bits:
ADDR [0x0aaa] = 0xaa;
ADDR [0x0555] = 0x55;
ADDR [0x0aaa] = 0x90;
Therefore, neither manufacture ID nor device ID can be read correctly. The read operations are 0xff. Then confirm again. When mpmcstaticconfig is configured, The x16 mode is configured, and then the command is sent again. The command is also sent in x16 mode. For details, refer: \ board \ mvs1 \ flash. the code in C. when reading the ID:
ADDR [0x0555] = 0x00aa;
ADDR [0x02aa] = 0x0055;
ADDR [0x0555] = 0x0090;
To read the expected ID correctly:
Value = ADDR [0];
/* Manufacturer ID
*/
The read result is 0x20 h.
Value = ADDR [1];
/* Device ID
*/
The read result is 0x22cb.
Match with datasheet:
-Manufacturer code: 0020 H
-Bottom device code m29w320db: 22cbh
2.
Different bits correspond to different time series
The time sequence mentioned here, that is, the address of X8 and x16, is different and the order is also different.
Note that you must convert the address to the corresponding type:
X8 is vu_char *
X16 is vu_short *
Then write the corresponding address and value.
3.
Reset command
After reading the code in uboot, it seems that most of the reset commands on other devices are 0xff.
What we use here is STM (STMicroelectronics, which later seems to have changed to numonyx, a joint venture between Intel and St ...) Nor flash,M29w320db(32 m, Bottom Boot sect)
, Which is 0xf0.
4.
Position of the Boot Sector
After reading datasheet, I thought that bottom sect is the bottom Sect and the largest address. The result in Datasheet is at the beginning of the flashback computation, that is, the block with the largest address is the first block. Therefore, the boot sector here is the block 0-3:
# Size (Kbyte/kword) address range (X8)/address range (x16)
66 64/32 3fda-h-3fffffh
1f8000h-1fffffh
.....
.....
3 32/16 008000h-00ffffh
004000h-007fffh
2 8/4
006000h-007fffh
003000h-003fffh
1 8/4
004000h-005fffh
002000h-002fffh
0 16/8 running 00h-003fffh
000000h-001fffh