The NAND Flash Driver of smdk2410 in U-boot.

Source: Internet
Author: User
Original: http://xianzilu.spaces.live.com/blog/The NAND Flash Driver of smdk2410 in U-boot. I shouldn't have written this first. Oh, but I have a poor memory. Maybe I forgot where I got the code during the porting process in a few days. First, I would like to celebrate that all my exams are over, hahaha. But do not try again ...... I heard that the course of our graduate student dean Zhao xuezeng is abnormal. The course contains 120 students and 50 students ...... God bless me. Let's get started. The standard smdk2410 board does not support NAND Flash. the startup process is as follows: U-boot 1.1.2 (May 28 2006-08:20:50) U-Boot Code: 33f80000-> 33f99a14 BSS: -> 33f9db0c
Ram Configuration:
Bank #0: 30000000 64 MB
Flash: 1 MB
* ** Warning-bad CRC, using default environmentin: Serial
Out: Serial
Err: Serial multiple rows supported by NAND (64 MB for NAND): U-boot 1.1.2 (May 28 2006-08:36:42) U-Boot Code: 33f80000-> 33f99a14 BSS:-> 33f9db0c
Ram Configuration:
Bank #0: 30000000 64 MB
Flash: 1 MB
Nand: 64 MB
* ** Warning-bad CRC, using default environmentin: Serial
Out: Serial
Err: How does serial implement this support? U-boot is a powerful bootloader, there is such a section in/received/configs/smdk2410.h /***************************** ******************************
* Command Definition
**************************************** *******************/
# Define config_commands \
(Config_cmd_dfl | \
Pai_pai_cache | \
1__0000_nand | \
/* Pai_0000_eeprom | */\
/* __Cmd_i2c | */\
/* Cfg_cmd_usb | */\
Pai_pai_reginfo | \
1__1__date | \
Cfg_cmd_elf)/* This must be encoded after the definition of config_commands (if any) */you need to describe config_cmd_dfl, which defines the default command, including bdinfo, bootd, coninfo, saveenv, flinfo, erase, protect, iminfo, imls, itest, loadb, loads, MD, mm, nm, mW, CP, CMP, CRC, base, loop, loopw, mtest, sleep, BOOTP, tftpboot, rarpboot, run, and other common commands, in the future, I will describe these commands in combination. For instructions on macro definition of commands, see the monitor functions in readme of U-boot. This is the definition of the commands supported by the compiled U-boot. In the smdk2410 default smdk2401.h, the red part is commented out. However, it is far easier to support NAND Flash without removing a comment. We can try to simply remove this comment. The old step is: Make distcleanmake smdk2410_configmake ...... A bunch of compilation information float ...... An error occurred. The location points to the file pai_nand.c. There are several errors. The reason is that the configuration of smdk2410 does not have macro definitions and functions supported by NAND Flash. What should I do? Write it by yourself? Fortunately, another configuration of vcma9 can be used for reference in U-boot. Search for vcma in source navigator and look at vcma9.h and vcma9.c. You can extract a macro definition and some function declarations from it. Some people put it in smdk2410.h and smdk2410.c, however, none of the idiot's cross-2.95.3 and cross-3.2 can recognize the macro-defined functions in cmd_nand.c that have been defined in smdk2410.h and smdk2410.c, even with extern. You may not have understood this sentence and explained it. For example, if (ale_wait) in pai_nand.c)
Nand_wait_ready (NAND);/* Do the worst case 25us wait */
Else
Udelay (10); where nand_wait_ready (NAND) is defined as # define nand_wait_ready (NAND) nf_waitrb () and nf_waitrb () in smdk2410.h () in smdk2410.c, it is defined as static inline void nf_waitrb (void)
{
S3c2410_nand * const NAND = s3c2410_getbase_nand (); While (! (NAND-> nfstat & (1 <0 )));
} The compiler says that nf_waitrb () is not defined. Even if I add such a sentence in cmd_nand.c, extern void nf_waitrb (void) may not work well for C, I cannot figure out the reference relationship of static inline when multiple files are compiled together. Regardless of it, I put the declarations of the functions defined in these macros in javas_nand.c. In order not to be shameless, I added selective compilation for smdk2410. (Please note that the following code is copied to the proper position in cmd_nand.c. cmd_nand.c has many macros for selective compilation. Pay attention to the placement and do not ignore them.)/* skip )/*-----------------------------------------------------------------------
* NAND Flash Basic functions
* Added by Lu Xianzi 2006.5.27
* Copied from Board/MPL/vcma9/vcma9.h & vcma9.c
*/# If (config_smdk2410) # include <S3C2410. h>
Typedef Enum {
Nfce_low,
Nfce_high
} Nfce_state; static inline void nf_conf (2010conf)
{
S3c2410_nand * const NAND = s3c2410_getbase_nand (); NAND-> nfconf = conf;
} Static inline void nf_cmd (u8 cmd)
{
S3c2410_nand * const NAND = s3c2410_getbase_nand (); NAND-> nfcmd = cmd;
} Static inline void nf_0000w (u8 cmd)
{
Nf_cmd (CMD );
Udelay (1 );
} Static inline void nf_addr (u8 ADDR)
{
S3c2410_nand * const NAND = s3c2410_getbase_nand (); NAND-> nfaddr = ADDR;
} Static inline void nf_setce (nfce_state S)
{
S3c2410_nand * const NAND = s3c2410_getbase_nand (); Switch (s ){
Case nfce_low:
Nand-> nfconf & = ~ (1 <11 );
Break; Case nfce_high:
Nand-> nfconf | = (1 <11 );
Break;
}
} Static inline void nf_waitrb (void)
{
S3c2410_nand * const NAND = s3c2410_getbase_nand (); While (! (NAND-> nfstat & (1 <0 )));
} Static inline void nf_write (u8 data)
{
S3c2410_nand * const NAND = s3c2410_getbase_nand (); NAND-> nfdata = data;
} Static inline u8 nf_read (void)
{
S3c2410_nand * const NAND = s3c2410_getbase_nand (); Return (NAND-> nfdata );
} Static inline void nf_init_ecc (void)
{
S3c2410_nand * const NAND = s3c2410_getbase_nand (); NAND-> nfconf |=( 1 <12 );
} Static inline u32 nf_read_ecc (void)
{
S3c2410_nand * const NAND = s3c2410_getbase_nand (); Return (NAND-> nfecc );
} Extern ulong nand_probe (ulong physadr); static inline void nf_reset (void)
{
Int I; nf_setce (nfce_low );
Nf_cmd (0xff);/* reset command */
For (I = 0; I <10; I ++);/* twb = 100ns .*/
Nf_waitrb ();/* Wait 200 ~ 500us ;*/
Nf_setce (nfce_high );
} Static inline void nf_init (void)
{
# If 0/* A little bit too optimistic */
# Define tacls 0
# Define twrph0 3
# Define twrph1 0
# Else
# Define tacls 0
# Define twrph0 4
# Define twrph1 2
# Endif nf_conf (1 <15) | (0 <14) | (0 <13) | (1 <12) | (1 <11) | (tacls <8) | (twrph0 <4) | (twrph1 <0 ));
/* NAND-> nfconf = (1 <15) | (1 <14) | (1 <13) | (1 <12) | (1 <11) | (tacls <8) | (twrph0 <4) | (twrph1 <0 );*/
/* 1 1 1, 1 XXX, r XXX, r xxx */
/* En 512b 4 step eccr nfce = H tacls twrph0 twrph1 */nf_reset ();
} Void nand_init (void)
{
S3c2410_nand * const NAND = s3c2410_getbase_nand (); nf_init ();
# Ifdef debug
Printf ("NAND Flash probing at 0x %. 8lx \ n", (ulong) nand );
# Endif
Printf ("% 4lu MB \ n", nand_probe (ulong) nand)> 20 );
} # Endif/* (config_smdk2410) */put the following macro definitions in smdk2410.h /*-----------------------------------------------------------------------
* NAND Flash settings
* Added by Lu Xianzi 2006.5.27
* Copied from include/conifgs/vcma9.h
*/
# If (config_commands & cfg_assist_nand) # define pai_max_nand_device 1/* max Number of NAND devices */
# Define sectorsize 512 # define addr_column 1
# Define addr_page 2
# Define addr_column_page 3 # define nand_chipid_unknown 0x00
# Define nand_max_floors 1
# Define nand_max_chips 1 # define nand_wait_ready (NAND) nf_waitrb () # define nand_disable_ce (NAND) nf_setce (nfce_high)
# Define nand_enable_ce (NAND) nf_setce (nfce_low) # define write_nand_command (D, ADR) nf_cmd (d)
# Define write_nand_commandw (D, ADR) nf_0000w (d)
# Define write_nand_address (D, ADR) nf_addr (d)
# Define write_nand (D, ADR) nf_write (d)
# Define read_nand (ADR) nf_read ()
/* The following functions are NOP's because s3c24x0 handles this in hardware */
# Define nand_ctl_clrale (nandptr)
# Define nand_ctl_setale (nandptr)
# Define nand_ctl_clrcle (nandptr)
# Define nand_ctl_setcle (nandptr)/* # define config_mtd_nand_verify_write 1 * // * This definition abve is commented by Lu Xianzi. 2006.05.28
Because there's no definition of a macro called _ mem_pci,
There will be a link error.
*/
# Define config_mtd_nand_ecc_jffs2 1 # endif/* config_commands & cfg_assist_nand */Note that the macro definition is different from vcma9.h in the red part. Some porting instructions on the Internet do not solve this problem, the last link fails. In fact, I canceled the write checksum and ECC verification for NAND flash in ipv_nand.c. I do not know what _ mem_pci is. I cannot find any file containing the "_ mem_pci" string in the U-boot directory, in addition to its/include/ASM/Io. h. By the way, this problem starts with the macro readb (NAND-> io_addr) in the nand_write_page function of ipv_nand.c. You can use source navigator to find the reference, finally, it points to the problem that the _ mem_pci macro does not exist. I hope some experts can see this article and point out the solution to it. After completing these changes, let's take the old step make distcleanmake smdk2410_configmake .................. A U-Boot.bin is generated. The drive of NAND Flash is now complete, OK? Try it. Last time we have burned into the board U-boot, is a support serial transmission U-boot, if you still use sjf2410 to burn U-Boot.bin is too big. You can use the serial port for transmission. The procedure is as follows: Use a Super Terminal to establish a connection: File> new connection; Name, chart, and OK; during connection, select the COM port connected to your Development Board. In port settings, select 115200 for the number of digits per second, 8 for the data bit, none for the parity check, 1 for the stop bit, and "NONE" for the data stream control ". Turn on the power of the Development Board and the following prompt is displayed: U-boot 1.1.2 (May 28 2006-08:20:50) U-Boot Code: 33f80000-> 33f99a14 BSS:-> 33f9db0c
Ram Configuration:
Bank #0: 30000000 64 MB
Flash: 1 MB
* ** Warning-bad CRC, using default environmentin: Serial
Out: Serial
Err: seriallxzrb # loadb # Ready For binary (Kermit) download to 0x33000000 at 115200 BPS... the loadb command downloads binary files from the serial port to the memory of the Development Board using the Kermit protocol. By default, the binary files are downloaded to 0x33000000. Of course, you can change it to another address. For example, loadb 30000000 is downloaded to 0x30000000. At this time select the Super Terminal menu: Transfer> send file, file name select compiled U-Boot.bin, protocol select Kermit, point to send. You can see the sending progress. Message displayed when sending ends: # total size = 0x00019a14 = 104980 bytes
# Start ADDR = 0x33000000 then you can test whether the new modification is good or not.
# Starting application at 0x33000000... U-boot 1.1.2 (May 28 2006-08:36:42) U-Boot Code: 33f80000-> 33f99a14 BSS:-> 33f9db0c
Ram Configuration:
Bank #0: 30000000 64 MB
Flash: 1 MB
Nand: 64 MB
* ** Warning-bad CRC, using default environmentin: Serial
Out: Serial
Err: Serial
Lxzrb # The go command can directly execute the program on the memory address. For example, you can see the "NAND: 64 MB" option after downloading the new nand u-boot instance to 0x33000000. Enter help. You will see that there is a set of more commands NAND than u-boot. Enter help NAND to see more detailed commands: lxzrb # Help NAND.
Nand Info-show available NAND Devices
Nand device [Dev]-show or set Current Device
Nand read [. jffs2 [s] ADDR off size
Nand write [. jffs2] ADDR off size-read/write 'SIZE' bytes starting
At offset 'off' to/from memory address 'addr'
Nand erase [clean] [off size]-erase 'SIZE' bytes from
Offset 'off' (entire device if not specified)
Nand bad-show bad Blocks
Nand read. oob addr off size-read out-of-band data
Nand write. oob addr off size-read out-of-band data input NAND info, you can see: lxzrb # NAND infodevice 0: Samsung unknown 64 MB at 0x4e000000 (64 MB, 16 KB sector) this indicates that our driver is successful. You can also try other commands. However, U-boot in nor flash still does not support nand, and you need to re-write it. U-boot supports self-writing. First let's take a look at the nor flash situation: lxzrb # flinfobank #1: AMD: 1x amd29lv800bb (8 Mbit)
Size: 1 MB in 19 sectors
Sector start addresses:
00000000 (RO) 00004000 (RO) 00006000 (RO) 00008000 (RO) 00010000 (RO)
00020000 00030000 00040000 00050000 00060000
00070000 00080000 00090000 000a0000 000b0000
000c0000 000d0000 000e0000 000f0000 (RO) a total of 19 sector, among which the first five sector totaling kb have u-boot programs, which are write-protected. To write data, Remove write protection: lxzrb # Protect off 0 1 FFFF.
Un-protected 5 sectors
Lxzrb # flinfobank #1: AMD: 1x amd29lv800bb (8 Mbit)
Size: 1 MB in 19 sectors
Sector start addresses:
00000000 00004000 00006000 00008000 00010000
00020000 00030000 00040000 00050000 00060000
00070000 00080000 00090000 000a0000 000b0000
000c0000 000d0000 000e0000 000f0000 (RO), you can see that the write protection has been removed, and the erased: lxzrb # erase 0 1 FFFF
Erasing sector 0... OK.
Erasing Sector 1... OK.
Erasing Sector 2... OK.
Erasing Sector 3... OK.
Erasing Sector 4... OK.
Erased 5 sectors and then run the following command: lxzrb # cp. B 33000000 0 19a14
Copy to flash... done CP. B is used to copy memory information. Its format is CP [. B ,. W ,. l] Source Target count, enter this command because the program was just downloaded to 0x33000000, the start address of nor flash is 0x0, and the Downloaded Program length is 0x19a14. Restart the Development Board and run the U-boot command.

 

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.