For more information about nandflash, see.
Now I will post the code of Mr. Wei Dongshan for my learning.
@*************************************** ***************************************
@ File: head. s
@ Function: Set the SDRAM, copy the program to the SDRAM, and then jump to the SDRAM to continue execution.
@*************************************** ***************************************
. Text
. Global _ start
_ Start:
@ Function disable_watch_dog, memsetup, init_nand, nand_read_ll defined in init. c
LDR sp, = 4096 @ set Stack
BL disable_watch_dog @ close watch dog
BL memsetup @ initialize SDRAM
BL nand_init @ initialize NAND Flash
@ Copy the 4096-byte code (compiled by main. c) starting from address 1024 in NAND Flash to SDRAM
@ Nand_read_ll the function requires three parameters:
LDR r0, = 0x30000000 @ 1. Target address = 0x30000000, which is the initial address of SDRAM
MoV R1, #4096 @ 2. Source Address = 4096. During connection, all the code in Main. C exists at the beginning of NAND flash Address 4096.
MoV R2, #2048 @ 3. Copy length = 2048 (bytes). This is sufficient for Main. c In this experiment.
BL nand_read @ call the C function nand_read
LDR sp, = 0x34000000 @ set Stack
Ldr lr, = halt_loop @ sets the return address
Ldr pc, = Main @ B and Bl commands can only jump to the 32 m range before and after, so here we use the method of assigning values to PC to jump
Halt_loop:
B halt_loop
The above code has obvious functions. Now it mainly describes address-related things;
LDR sp, = 4096 @ sets the stack. After the stack is powered on, the 4 K code is automatically copied to steppingstone. functions such as disable_watch_dog and memsetup are all in this 4 K range.
The following link script is used:
Sections {
Firtst 0x00000000: {head. O init. o nand. O}
Second 0x30000000: At (4096) {main. O}
}
The above description shows that the main function is out of the 4 K range just mentioned. Therefore, in the head file, the main function of 4096 (4 K) will be compiled and copied to 3000_0000, that is, the location of the SDRAM.
In the future, when the program is relatively large, it is basically a common function, so it must take time to understand. The above is a simple description of the address ing problem.
NAND Flash Problems