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.
Previous article:Platform bus globalfifo driver
Next article:u-boot transplant summary (I) start.S analysis
- Popular Resources
- Popular amplifiers
- Learn ARM development(16)
- Learn ARM development(17)
- Learn ARM development(18)
- Embedded system debugging simulation tool
- A small question that has been bothering me recently has finally been solved~~
- Learn ARM development (1)
- Learn ARM development (2)
- Learn ARM development (4)
- Learn ARM development (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- CGD and Qorvo to jointly revolutionize motor control solutions
- CGD and Qorvo to jointly revolutionize motor control solutions
- Keysight Technologies FieldFox handheld analyzer with VDI spread spectrum module to achieve millimeter wave analysis function
- Infineon's PASCO2V15 XENSIV PAS CO2 5V Sensor Now Available at Mouser for Accurate CO2 Level Measurement
- Advanced gameplay, Harting takes your PCB board connection to a new level!
- Advanced gameplay, Harting takes your PCB board connection to a new level!
- A new chapter in Great Wall Motors R&D: solid-state battery technology leads the future
- Naxin Micro provides full-scenario GaN driver IC solutions
- Interpreting Huawei’s new solid-state battery patent, will it challenge CATL in 2030?
- Are pure electric/plug-in hybrid vehicles going crazy? A Chinese company has launched the world's first -40℃ dischargeable hybrid battery that is not afraid of cold
- Type-C interface display solution
- Is there any module similar to Yiweilian?
- How to choose the right operational amplifier
- How to use a switching boost chip to solder a circuit to achieve 5-24V output
- Here is a basic CAD shortcut key
- [GD32L233C-START Review] 1. Unboxing + Environment Setup
- Maxim Basic Analog IC APP download helps you innovate analog design!
- How is the internal low-pass filter of Bh1415 designed? How is the 150pf connected to pin 3 determined?
- Its automobile inner wheel difference safety warning system
- Motor drive