Design of U-BOOT booting from NAND flash memory

Publisher:JoyousJourneyLatest update time:2012-05-22 Source: 21ic Keywords:U-BOOT  S3C2410 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

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

Keywords:U-BOOT  S3C2410 Reference address:Design of U-BOOT booting from NAND flash memory

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

WinCE-IIC Debugging Assistant (S3C2410)
I have been debugging a new hardware platform these two days, and the MCU it uses is still S3C2410. A new RTC module has been added to the platform, and the chip used is DS1337. This is an IIC interface clock chip. I encountered some problems when I started debugging. The MCU was still unable to communicate with the D
[Microcontroller]
WinCE-IIC Debugging Assistant (S3C2410)
OK6410A development board (three) 13 u-boot-2021.01 boot analysis SPL image running part boot detailed analysis
url : git@github.com:lisider/u-boot.git branch : ok6410a commit id : e63a4077ad3aea53107495b0b68b95e720fe6033 config :ok6410a_mini_defconfig // There are 67 .S .s .c files involved From the entrance to the exit // Run at 0x0c00 0000 // The entry is the b reset at the _start label in arch/arm/lib/vectors.S rese
[Microcontroller]
s3c2410 transplants MPlayer to linux2.6
The Linux kernel I use is 2.6.14.1. The MPlayer version is MPlayer-1.0pre7try2.bz2. Although mad’s mp3 library has been added, playing sound files will cause mplayer errors. I have to disable the sound when playing videos. It’s strange. Madplay plays MP3 is very good. The following is an introduction to the entire tra
[Microcontroller]
u-boot-2009.08 transplantation on mini2440 (VI) --- add boot kernel function
Migration environment 1. Host environment: CentOS 5.5 under VMare, 1G memory. 2. Integrated development environment: Eclipse IDE 3. Compilation environment: arm-linux-gcc v4.4.3, arm-none-eabi-gcc v4.5.1. 4. Development board: mini2440, 2M nor flash, 128M nand flash. 5.u-boot version: u-boot-2009.08 6. References: ht
[Microcontroller]
S3C2410 LCD transplantation on SkyEye
Today I finally got the s3c2410 lcd on skyeye. I saw some friends posting questions online, so I want to share with you.     First of all, my skyeye is version 1.2.3, and the linux kernel version is 2.6.16.21-0.8, which comes with suse 10.0. u-boot-1.1.6 is the boot program. u-boot porting for skyeye is available onl
[Microcontroller]
S3C2410 LCD transplantation on SkyEye
OK6410A development board (three) 20 u-boot-2021.01 boot analysis U-boot image running part system clock
The registers mainly involved in setting the system clock Belongs to 3 SYSTEM CONTROLLER Range 0x7E00_F000 0x7E00_FFFF S3C6410 clock |---APLL---------ARMCLK --- for CPU | External crystal (XTIPLL) + internal OSC (oscillator) | 0     | |----HCLK   --- for AXI/AHB bus peripherals   |---OM --- Master Cloc
[Microcontroller]
OK6410A development board (three) 20 u-boot-2021.01 boot analysis U-boot image running part system clock
Transplantation on Embedded Linux System Based on ADSP BF533
1 Introduction Boot Loader is a boot program that runs before the operating system kernel runs. It is used to initialize hardware devices, change the processor operation mode, reorganize interrupt vectors and establish memory space mapping, thereby bringing the system's hardware and software to an appropr
[Microcontroller]
Transplantation on Embedded Linux System Based on ADSP BF533
uboot-2011.12 ported to S3C2440 (Sequence 2) - binutils binary tool set and u-boot
Overview binutils is a set of binary tools, including addr2line, ar, gprof, nm, objcopy, objdumpr, ranlib, size, strings, strip, etc. ar software ar is used to create, modify, and extract library files. ar requires at least two parameters to run, for example: $ ar rv libtest.a add.o minus.o It means to make add.o an
[Microcontroller]
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
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号