Introduction
As embedded systems become increasingly complex, the need for large-capacity data storage becomes more and more urgent. However, the requirements of low power consumption, small size and low cost for embedded devices make it difficult for hard disks to be widely used. NAND flash memory devices have developed rapidly to meet this demand. At present, the transplantation solution for U-BOOT is mainly aimed at NOR flash memory in microprocessors. If U-BOOT can be started in NAND flash memory on microprocessors, it will bring great convenience to practical applications.
U-BOOT Introduction
U-BOOT supports processors of various architectures such as ARM and PowerPC, and also supports various operating systems such as Linux, NetBSD and VxWorks. It is mainly used to develop bootloaders, the initialization code for embedded systems. Bootloader is a piece of code that is executed after the chip is reset and before entering the operating system. It completes the transition from hardware startup to operating system startup and provides a basic operating environment for running the operating system, such as initializing the CPU, stack, and memory system. Its function is similar to the BIOS of a PC. The U-BOOT execution flow chart is shown in Figure 1.
Figure 1 U-BOOT startup flow chart
NAND flash working principle
The NAND flash of the S3C2410 development board consists of two parts: the NAND flash controller (integrated in the S3C2410 CPU) and the NAND flash chip (K9F1208U0A). When accessing data in the NAND flash chip, commands must be sent through the NAND flash controller to complete it. Therefore, the NAND flash is equivalent to a peripheral of the S3C2410, and is not located in its memory address area.
The data storage structure of the NAND flash (K9F1208U0A) is hierarchical: 1 device = 4096 blocks; 1 block = 32 pages/rows; 1 page = 528B = data block (512B) + OOB block (16B)
In each page, the last 16 bytes (also known as OOB) set the status after the NAND flash command is executed, and the remaining 512 bytes are divided into the first half and the second half. The first half, second half, and OOB can be located respectively through the NAND flash command 00h/01h/50h, and the pointer built into the NAND flash can point to their respective first addresses.
The operation characteristics of NAND flash memory are: the minimum unit of erase operation is block; each bit of NAND flash chip can only change from 1 to 0, but not from 0 to 1, so the corresponding block must be erased before writing to it; the 6th byte of OOB part is the bad block flag, that is, if it is not a bad block, the value is FF, otherwise it is a bad block; except for the 6th byte of OOB, the first 3 bytes of OOB are usually used to store the hardware ECC (check register) code of NAND flash memory;
the design idea of starting U-BOOT from NAND flash memory
If S3C2410 is configured to start from NAND flash memory, after power-on, the NAND flash controller of S3C2410 will automatically move the first 4K data in NAND flash memory to the internal RAM, and set 0x00000000 as the starting address of the internal RAM, and the CPU starts from the 0x00000000 position of the internal RAM. Therefore, the most core startup program should be placed in the first 4K of NAND flash memory.
Since the code that the NAND flash controller moves from the NAND flash to the internal RAM is limited, the core configuration of S3C2410 must be completed in the first 4K of the boot code, and the rest of the boot code must be moved to RAM for execution. In U-BOOT, the main work completed in the first 4K is the first stage (stage1) of U-BOOT startup.
According to the execution flow chart of U-BOOT, it can be seen that to realize the startup of U-BOOT from NAND flash, it is necessary to initialize NAND flash first, and move U-BOOT from NAND flash to RAM, and finally let U-BOOT support NAND flash command operations. [page]
Development environment
The hardware environment of the target board in this design is as follows: CPU is S3C2410, SDRAM is HY57V561620, and NAND flash is 64MB K9F1208U0A.
The host software environment is Redhat9.0, u-boot-1.1.3, gcc 2.95.3. Modify the Makefile of U-BOOT and add:
wch2410_config : unconfig
@./mkconfig $(@:_config=) arm arm920t wch2410 NULL s3c24x0
Name the development board wch2410. Then perform the following operations in sequence:
mkdir board/wch2410
cp board/smdk2410 board/wch2410
mv smdk2410.c wch2410.c
cp include/configs/smdk2410.h include/configs/wch2410.h
export PATH=/usr/local/arm/2.95.3/bin:$PATH
Finally, execute:
make wch2410_config
make all ARCH=arm
to generate u-boot.bin, which means that the test compilation has passed.
Specific design
Boot program design
supporting NAND flash memory
Because the entry program of U-BOOT is /cpu/arm920t/start.S, it is necessary to add the reset program of NAND flash memory to this program, as well as the function program to move U-BOOT from NAND flash memory to RAM.
First, add CONFIG_S3C2410_NAND_BOOT to /include/configs/wch2410.h, as follows:
#define CONFIG_S3C2410_NAND_BOOT 1 @Support booting from NAND flash
Then add
#ifdef CONFIG_S3C2410_NAND_BOOT
to /cpu/arm920t/start.S
copy_myself:
mov r10, lr
ldr sp, DW_STACK_START @Install the starting address of the stack
mov fp, #0 @Initialize the frame pointer register
bl nand_reset @Jump to the reset C function to execute, execute NAND flash reset
.......
/*Copy U-BOOT from NAND flash to RAM*/
ldr r0, =UBOOT_RAM_BASE @Set the first parameter: the starting address of UBOOT in RAM
mov r1, #0x0 @Set the second parameter: the starting address of NAND flash
mov r2, #0x20000 @ Set the third parameter: U-BOOT length (128KB)
bl nand_read_whole @ Call nand_read_whole() to read the data in NAND flash memory into RAM
tst r0, #0x0 @ If the return value of the function is 0, it means the execution is successful
beq ok_nand_read @ Perform memory comparison, compare the first 4K content in RAM with the first 4K content in NAND flash memory, if they are exactly the same, it means the move is successful
Among them, nand_reset () and nand_read_whole() are added to /board/wch2410/wch2410.c.
Support U-BOOT command design
The support for nand flash memory under U-BOOT is mainly to implement the operation of nand flash memory under the command line. The commands implemented for nand flash memory are: nand info (print nand Flash information), nand device (display a certain nand flash device), nand read (read nand flash), nand write (write nand flash), nand erase (erase nand flash), nand bad (display bad blocks), etc.
The main data structures used are: struct nand_flash_dev, struct nand_chip. The former includes the main chip model, storage capacity, device ID, I/O bus width and other information; the latter is the information used when operating the NAND flash memory.
a. Set configuration options
Modify /include/configs/wch2410.h, mainly to open the CFG_CMD_NAND option in CONFIG_COMMANDS. Define the starting register address and page size of the NAND flash controller in the SFR area, and define the underlying interface function of the NAND flash command layer.
b. Add the NAND flash chip model
Modify the following structure assignment in /include/linux/mtd/ nand_ids.h:
static struct nand_flash_dev nand_flash_ids[] = {
......
{"Samsung K9F1208U0A", NAND_MFR_SAMSUNG, 0x76, 26, 0, 3, 0x4000, 0},
.......
}
This way, the operation of this NAND flash chip can be performed correctly.
c. Write the NAND flash initialization function
Add the nand_init() function in /board/wch2410/wch2410.c.
void nand_init(void)
{
/* Initialize NAND flash controller, and NAND flash chip*/
nand_reset();
/* Call nand_probe() to detect chip type*/
printf ("%4lu MB\n", nand_probe(CFG_NAND_BASE) >> 20);
}
This function is called by start_armboot() at boot time.
Finally, recompile U-BOOT and burn the generated u-boot.bin into the NAND flash memory. After the target board is powered on, the following information is output from the serial port:
U-Boot 1.1.3 (Nov 14 2006 - 11:29:50)
U-Boot code: 33F80000 -> 33F9C9E4 BSS: -> 33FA0B28
RAM Configuration:
Bank #0: 30000000 64 MB
## Unknown Flash on Bank 0: ID 0xffff, Size = 0x00000000 = 0 MB
Flash: 0 kB
NAND: 64 MB
In: serial
Out: serial
Err: serial
Hit any key to stop autoboot: 0
wch2410 #
Conclusion
In the past, the solution for porting U-BOOT to the ARM9 platform was mainly aimed at the NOR flash memory in ARM9. Because the structural characteristics of NOR flash memory enable the application to run directly inside it without reading the code into RAM, the porting process is relatively simple. The difficulty in designing U-BOOT from NAND flash memory is that NAND flash memory needs to move the U-BOOT code to RAM and make U-BOOT support the command operation of NAND flash memory. This article introduces the ideas and specific procedures for implementing this design. After porting, U-BOOT runs well in the embedded system. ■
References
1 Du Chunlei. ARM Architecture and Programming [M]. Beijing: Tsinghua University Press, 2003
2 S3C2410 User's Manual [Z]. Samsung
Previous article:Rapidly implement designs based on the AMBA 3 AXI protocol
Next article:Image Acquisition and Display of Embedded Linux System
Recommended ReadingLatest update time:2024-11-16 20:29
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- Oh my god! My air conditioner has become a spirit!
- Analysis of the problem that the program cannot run after F28004x online debugging reset
- Ask for 88X3310PA1-BUS4I000 product manual
- The problem of BIN generated by STM32F051 being filled with 0
- Wireless RF communication using nRF24L01 module
- Today at 10:00 AM, live broadcast with awards: ADI's technologies and products in China's energy internet applications
- Can ultra-wideband really help all industries resume work and production?
- How to perform on-site PIM testing on RF connectors?
- IAR IDE for MSP430, 8051, ARM and other platforms
- What does damping coefficient mean? What is the damping coefficient KD value?