Analysis of nandflash initialization process in u-boot

Publisher:Xingfu8888Latest update time:2024-07-25 Source: cnblogsKeywords:u-boot  nandflash Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

The following is an analysis of the nand flash initialization code nand_init():
1. If (CONFIG_COMMANDS & CFG_CMD_NAND) is defined and (CFG_NAND_LEGACY) is not defined, then start_armboot() calls nand_init() in driver/nand/nand.c, otherwise if (CONFIG_COMMANDS & CFG_CMD_NAND) is defined and CFG_NAND_LEGACY is defined, then call the self-defined nand_init(). In my current scenario, nand_init() in driver/nand/nand.c is used.

2.nand_init() calls nand_init_chip() in this file to initialize nand.

3.nand_init_chip() first calls board_nand_init().

4.board_nand_init() is a function that needs to be added by yourself. The main function of this function is to assign values ​​to the function pointers of the struct nand_chip structure, so that they point to some functions written by yourself for the nand driver. For unassigned pointers, uboot will assign general nand driver function pointers to them later.

5.nand_init_chip() then calls nand_scan().

6.nand_scan() is defined in drivers/nand/nand_base.c file. It first assigns the pointer in struct nand_chip structure that is not assigned in board_nand_init() function to the general nand driver function pointer.

7. The function pointer assigned to the struct nand_chip structure by the general nand driver function nand_select_chip() is used to turn on or off the nand chip, 0 for on, 1 for off. In this function, the hwcontrol function pointer in the nand_chip structure is called, and the function pointed to by this pointer needs to be written by yourself. This function pointer is assigned in the board_nand_init() function. The main function is to send some nand flash on and off commands to the nand flash.

8. The rest of nand_scan() initializes the nand_chip and mtd_info structures.

9.nand_scan() finally calls nand_default_bbt() in drivers/nand/nand_bbt.c file when returning.

10.nand_default_bby() selects a bad block description table and calls nand_scan_bbt() in this file when returning.

11.nand_scan_bbt() searches for and creates a bad block description table.

12. Finally, return to nand_init(), and the initialization of the nand driver is completed.

The following is an analysis of the execution process of the command nand read addr ofs size:
1. The function of the nand read addr ofs size command is to read data of length size bytes from the offset ofs of the nand flash address and store it at the memory address addr.

2. main_loop() in the common/main.c file mainly executes read_line() to read the command line.

3. After read_line() reads the command line, it calls run_command() in the common/main.c file.

4.run_command() calls find_cmd() in the common/command.c file to find the cmd_tbl_t structure of the command in the .u_boot_cmd segment and returns the structure after finding it. The structure of the command is registered in the .u_boot_cmd segment through the macro definition U_BOOT_CMD defined in include/command.h.

5. After run_command() finds the cmd_tbl_t structure of the command, it executes the function corresponding to the command. In this scenario, it is the function do_nand() corresponding to the nand command.

6. There are two versions of do_nand(), one with CFG_NAND_LEGACY defined. The other without CFG_NAND_LEGACY defined. Both versions are defined in the common/cmd_nand.c file. For this scenario, use the do_nand() function without CFG_NAND_LEGACY defined. To use do_nand(), you must also define the macros CONFIG_COMMANDS&CFG_CMD_NAND. (If CFG_NAND_LEGACY is not defined, the functions called by the do_nand() function in this scenario are all defined in the drivers/nand_legacy/nand_legacy.c file).

7. For our scenario do_nand() will call nand_read() which is defined in include/nand.h file.

8.nand_read() calls the read pointer of the nand_info_t structure corresponding to this nand chip. The read pointer in nand_scan() points to the nand_read() function in the same file (drivers/nand/nand_base.c).

9. The nand_read() function will eventually call the cmdfunc pointer in the nand_chip structure and send a command to the nand flash chip through the function pointed to by this pointer, thus completing the execution of the entire command.


Keywords:u-boot  nandflash Reference address:Analysis of nandflash initialization process in u-boot

Previous article:Platform bus globalfifo driver
Next article:u-boot transplant summary (I) start.S analysis

Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号