Design of starting U-BOOT from nand flash memory

Source: Internet
Author: User

 Design of starting U-BOOT from nand flash memory

Introduction

As embedded systems become increasingly complex, the demand for large-capacity data storage becomes increasingly urgent. However, hard disks cannot be widely used due to the low power consumption, small size, and low cost requirements of embedded devices. Nand flash memory devices are rapidly evolving to meet this demand. At present, the U-BOOT porting solution is mainly for the nor flash memory in the microprocessor, if the U-BOOT can be enabled in the nand flash memory on the microprocessor, this will bring great convenience to practical applications.

About U-BOOT

U-BOOT supports arm, PowerPC and other architectures of the processor, also supports Linux, NetBSD, VxWorks and other operating systems, mainly used to develop embedded system initialization code bootloader. Bootloader is a piece of code executed before the chip is reset and enters the operating system. It completes the transition from hardware startup to operating system startup, and provides a basic operating environment for operating the operating system, such as initializing the CPU, stack, and memory system. Its function is similar to that of the BIOS of a PC. U-BOOT execution flowchart 1 is shown.

Figure 1 U-BOOT startup Flowchart

Operating principle of NAND Flash

The nand flash memory of the S3C2410 Development Board consists of the nand flash memory controller (integrated into the S3C2410 CPU) and the nand flash memory chip (k9f1208u0a. To access data in the nand flash memory chip, you must use the nand flash memory controller to send commands. Therefore, nand flash memory is equivalent to a peripheral of S3C2410, not in its memory address zone.

The data storage structure of nand flash memory (k9f1208u0a) is divided into: 1 device = 4096 blocks; 1 device = 32 pages/row (page/row ); 1 page = 528b = data block (512b) + OOB block (16b) on each page, the last 16 bytes (also known as OOB) are set after the NAND Flash command is executed, the remaining 512 bytes are divided into the first half and the second half. You can use the nand flash memory command 00 h/01 H/50 h to locate the front half, back half, and OOB respectively, and use the built-in pointer of the nand flash memory to point to the respective first address.

The Operation Features of nand flash memory are as follows: The minimum unit of the erasure operation is block. each bit of the nand flash memory chip can only change from 1 to 0, but not from 0 to 1, therefore, the corresponding block must be erased before writing data to it; the 6th bytes of OOB are the bad fast sign, that is, if it is not a bad block, the value is ff; otherwise, it is a bad block; except for OOB 6th bytes, the first three bytes of OOB are usually used to store the hardware ECC (Verification register) Code of the nand flash memory;

 Design idea of starting U-BOOT from nand flash memory

If S3C2410 is configured to start from the nand flash memory, after power-on, the S3C2410 nand flash memory controller will automatically move the first 4 k Data in the nand flash memory to the internal RAM, set 0x00000000 as the starting address of the internal RAM, And the CPU starts from the 0x00000000 position of the internal RAM. Therefore, the core startup program should be placed in the first 4 K of nand flash memory.

Since the code for the NAND Flash Controller to move from the nand flash memory to the internal RAM is limited, the core configuration of the S3C2410 must be completed in the first 4 K of the startup code, and move the remaining part of the startup code to ram for running. In the U-BOOT, the main work completed in the first 4 k is the first phase of the U-BOOT startup (stage1 ).

According to the U-BOOT execution flow chart, it is known that to start the U-BOOT from the nand flash memory, first need to initialize the nand flash memory, and the U-BOOT from the nand flash memory to the ram, finally, the U-BOOT needs to support command operations for NAND Flash.

 

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 64 MB k9f1208u0a.

The host software environment is redhat9.0, U-BOOT-1.1.3, GCC 2.95.3. Modify makefile for the U-BOOT, add:

Wch2410_config: unconfig
@./Mkconfig $ (@: _ Config =) arm ARM920T wch2410 null s3c24x0

Name the Development Board wch2410, and 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

Last run:
Make wch2410_config
Make all arch = "arm"
Generate the u-boot.bin, which passes the test compilation.

Specific design
Enable Program Design for nand flash memory

Because the U-BOOT Entry Program is/CPU/ARM920T/start. s, so you need to add the nand flash memory reset program in the program, and realize the function of moving the U-BOOT from the nand flash memory to the RAM program.

Add config_s3c2410_nand_boot to/include/configs/wch2410.h, as shown below:

# Define config_s3c2410_nand_boot 1 @ support starting from nand flash memory
Then, add/CPU/ARM920T/start. s
# Ifdef config_s3c2410_nand_boot
Copy_myself:
MoV R10, LR
LDR sp, dw_stack_start @ start address of the installation Stack
MoV FP, #0 @ initialize frame pointer register
BL nand_reset @ jump to reset C function to execute, execute nand flash memory reset
.......
/* Copy the U-BOOT from NAND Flash to Ram */
LDR r0, = uboot_ram_base @ set 1st parameters: Starting address of uboot in Ram
MoV R1, #0x0 @ set 2nd parameters: the starting address of the nand flash memory
MoV R2, #0x20000 @ set 3rd parameters: length of the U-BOOT (KB)
BL nand_read_whole @ call nand_read_whole () to read data from nand flash memory to ram
Tst r0, #0x0 @ if the return value of the function is 0, the execution is successful.
Beq OK _nand_read @ executes memory comparison and compares the first 4 K content in RAM with the first 4 K content in NAND Flash. If they are identical, the migration is successful.

Here, nand_reset () and nand_read_whole () are added to/board/wch2410/wch2410.c.

Support U-BOOT command Design

The support for nand flash memory in U-BOOT is mainly to realize the operation of nand flash memory in command line. Commands for implementing nand flash memory are: NAND Info (printing NAND Flash information), Nand device (displaying a NAND flash device), and NAND read (Reading nand flash memory), Nand write (write nand flash memory), Nand erease (erase nand flash memory), and NAND bad (display Bad blocks.

The main data structures used are: struct nand_flash_dev and struct nand_chip. The former includes information such as the main chip model, storage capacity, device ID, and I/O bus width. The latter is the information used for operating the NAND FLASH memory.

A. Set Configuration Options

Modify/include/configs/wch2410.h to enable the cmd_cmd_nand option in config_commands. Define the starting Register address and page size of the nand flash memory controller in the SFR area, and define the underlying interface functions of the NAND Flash command layer.

B. Add the NAND FLASH memory chip Model

Modify the following struct value 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 },
.......
}
In this way, operations on the nand flash memory chip can be correctly performed.
C. Compile the nand flash memory initialization Function
Add the nand_init () function to/board/wch2410/wch2410.c.
Void nand_init (void)
{
/* Initialize the NAND Flash Controller and the NAND flash chip */
Nand_reset ();
/* Call nand_probe () to detect the chip type */
Printf ("% 4lu MB/N", nand_probe (pai_nand_base)> 20 );
}

This function is called by start_armboot () at startup.

Finally re-compile the U-BOOT and the generated u-boot.bin into the nand flash memory, the target board after the power output from the serial port the following information:

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 0 xFFFF, 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 of porting the U-BOOT to the arm9-platform mainly aimed at the nor flash memory in arm9-because of the structural characteristics of the nor flash, the application can run directly in its internal, you do not need to read the code into RAM. The porting process is relatively simple. The design difficulty of starting U-BOOT from nand flash memory is that the U-BOOT code needs to be moved to Ram and the U-BOOT needs to support the command operation of nand flash memory. This article describes how to implement this design and the specific procedures. After transplantation, the 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 mannual [Z]. Samsung

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.