Detailed explanation of U-boot transplantation on S3C2440 (1)

Publisher:初入茅庐Latest update time:2023-01-03 Source: elecfansKeywords:U-boot  S3C2440 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

1. Transplantation environment

  • Host: VMWare--Fedora 9

  • Development board: Mini2440--64MB Nand, Kernel:2.6.30.4

  • Compiler: arm-linux-gcc-4.3.2.tgz

  • u-boot:u-boot-2009.08.tar.bz2

2. Transplantation steps

Features of this transplant include:

  • Support Nand Flash reading and writing

  • Support booting from Nor/Nand Flash

  • Support CS8900 or DM9000 network card 

  • Support Yaffs file system 

  • Support USB download (not yet implemented)

1. Understand the main directory structure and startup process of u-boot, as shown below.

 

    The stage1 code of u-boot is usually placed in the cpu/xxxx/start.S file, which is written in assembly language;

    The stage2 code of u-boot is usually placed in the lib_xxxx/board.c file, which is written in C language.

    The flow chart of each part is as follows:

 

 

 

2. Create your own development board project and test the compilation.

   At present, u-boot directly supports many CPUs. You can check some subdirectories of the board directory. For example, the board/samsung/ directory supports some Samsung ARM processors, including smdk2400, smdk2410 and smdk6400, but not 2440, so we Build your own development board project right here.

 

1) Since the resources of 2440 and 2410 are similar, the main frequency and peripherals are slightly different, so we established our own development board project under board/samsung/ and named it my2440

#tar -jxvf u-boot-2009.08.tar.bz2 //Unzip the source code
#cd u-boot-2009.08/board/samsung/ //Enter the directory
#mkdir my2440 //Create the my2440 folder

 

2) Since the resources of 2440 and 2410 are similar, we use the code of the 2410 project as a template and modify it later.

#cp -rf smdk2410/* my2440/ //Copy all codes under 2410 to 2440

#cd my2440 //Enter the my2440 directory

#mv smdk2410.c my2440.c //Rename smdk2410.c under my2440 to my2440.c

#cd ../../../ //Return to the u-boot root directory
#cp include/configs/smdk2410.h include/configs/my2440.h //Create the 2440 header file
#gedit board/samsung/my2440/ Makefile //Modify the compilation items of Makefile under my2440, as follows:

COBJS := my2440.o flash.o //Because we renamed smdk2410.c to my2440.c under my2440

3) Modify the Makefile file in the u-boot and directory. Find the place where smdk2410_config is found, and create the compilation options of my2440_config according to the format of smdk2410_config, and also specify the cross compiler.

#gedit Makefile

CROSS_COMPILE ?= arm-linux- //Specify the cross compiler as arm-linux-gcc

 

smdk2410_config: unconfig //2410 compilation option format
    @$(MKCONFIG) $(@:_config=) arm arm920t smdk2410 samsung s3c24x0

 

my2440_config: unconfig //2440 compilation option format
    @$(MKCONFIG) $(@:_config=) arm arm920t my2440 samsung s3c24x0

 

*Description: arm: CPU architecture (ARCH)

       arm920t: CPU type

       my2440: The directory corresponding to the creation of a new development board project in the board directory

       samsung: The superior directory of the new development board project directory. If you create a new development board project directory directly under the board, this will be NULL.

       s3c24x0: CPU model

*Note: The second line of the compilation option format must be started with the Tab key, otherwise compilation errors will occur.

 

4) Test and compile the newly created my2440 development board project

#make my2440_config //If Configuring for my2440 board... appears, it means the setting is correct

#make //After compilation, the u-boot.bin file will appear in the root directory, then the first step of u-boot transplantation is completed.

 

So far, u-boot has no use for its own my2440 development board. The above transplantation only builds a framework for my2440 development board u-boot. To realize its functions, it must be based on the specific resources of the my2440 development board. to modify the u-boot source code.

3. Analyze or modify and add the u-boot source code according to the steps of the u-boot startup flow chart to make it suitable for the my2440 development board (Note: Modified or added places are indicated in red).

1) Analysis of the stage1 entry point of my2440 development board u-boot.
Generally in embedded system software development, after all source code files are compiled, the linker reads a link allocation file, which defines the entry point of the program, allocation of code segments, data segments, etc. Then the link file of our my2440 development board u-boot is cpu/arm920t/u-boot.lds. Part of the code to open this file is as follows:

Knowing that the entry point of the program is _start, then we open the first program cpu/arm920t/start.S to be run by my2440 development board u-boot (that is, the stage1 part of u-boot), and find the location of _start as follows:

From this assembly code, you can see that the program jumps to start_code and starts execution. Then the code found at start_code is as follows:

/*
 * the actual start code
 */

start_code:
    /*
     * set the cpu to SVC32 mode
     */
    mrs r0,cpsr
    bic r0,r0,#0x1f
    orr r0,r0,#0xd3
    msr cpsr,r0

    bl colored_LED_init //here The two lines are to initialize the LED on the AT91RM9200DK development board
    bl red_LED_on

 

It can be seen from this that start_code is the real beginning of u-boot startup code. The above is the process of stage1 entry of u-boot.

2) Hardware device initialization in stage 1 of my2440 development board u-boot.
Because there are two lines in the u-boot startup code that are the LED initial codes of AT91RM9200DK, but the LED resources on our my2440 are inconsistent with those of the development board, so we need to delete or block the code there, plus the LED driver code of my2440 (Note: Adding the my2440 LED function is only used to indicate the running status of u-boot, which brings convenience to debugging. You can put this code anywhere you want to debug). The code is as follows:

    /*bl colored_LED_init //These two lines are the LED initialization of the AT91RM9200DK development board, comment out
    bl red_LED_on*/

 

#if defined(CONFIG_S3C2440) //Difference from other development boards

//According to the mini2440 schematic, it can be seen that the LEDs are controlled by PB5, 6, 7, and 8 ports of S3C2440. The following is the PB port register base address (check the DataSheet of 2440)
#define GPBCON 0x56000010
#define GPBDAT 0x56000014
#define GPBUP 0x56000018    

    //The following operations on the register refer to the DataSheet of S3C2440
    ldr r0, =GPBUP
    ldr r1, =0x7FF //That is: binary 11111111111, turn off the PB port pull-up
    str r1, [r0]

    ldr r0, =GPBCON //Configure PB5, 6, 7, and 8 are output ports, corresponding to bits 10-17 of the PBCON register
    ldr r1, =0x154FD //That is: binary 010101010011111101
    str r1, [r0]

    ldr r0, =GPBDAT
    ldr r1, =0x1C0 //That is: binary 111000000, PB5 is set to low level, 6, 7, and 8 are set to high level
    str r1, [r0]

#endif

//This code causes LED1 on the development board to light up after u-boot is started, but LED2, LED3, and LED4 do not light up.

 

 

Add the CONFIG_S3C2440 macro in the include/configs/my2440.h header file

 

 

#gedit cpu/arm920t/s3c24x0/speed.c //Modify the function to obtain the clock frequency according to the set frequency division coefficient FCLK:HCLK:PCLK = 1:4:8

staTIc ulong get_PLLCLK(int pllreg)
{
    S3C24X0_CLOCK_POWER * const clk_power = S3C24X0_GetBase_CLOCK_POWER();
    ulong r, m, p, s;

    if (pllreg == MPLL)
    r = clk_power->MPLLCON;
    else if (pllreg == UPLL)
    r = clk_power->UPLLCON;
    else
    hang();

    m = ((r & 0xFF000) >> 12) + 8;
    p = ((r & 0x003F0) >> 4) + 2;
    s = r & 0x3;

#if defined(CONFIG_S3C2440)
    if(pllreg == MPLL)
    {   //参考S3C2440芯片手册上的公式:PLL=(2 * m * Fin)/(p * 2s)
        return((CONFIG_SYS_CLK_FREQ * m * 2) / (p << s));
    }
#endif

    return((CONFIG_SYS_CLK_FREQ * m) / (p << s));
}

/* return HCLK frequency */
ulong get_HCLK(void)
{
    S3C24X0_CLOCK_POWER * const clk_power = S3C24X0_GetBase_CLOCK_POWER();

#if defined(CONFIG_S3C2440)
    return(get_FCLK()/4);
#endif

    return((clk_power->CLKDIVN & 0x2) ? get_FCLK()/2 : get_FCLK());
}

 

alright! After the modification is completed, we recompile u-boot, and then download it to RAM to run the test. As a result, the terminal outputs information and a shell-like command line appears, which indicates that the transplantation of this part is completed. The schematic diagram is as follows:


 

#gedit include/configs/my2440.h

#define CONFIG_ARM920T        1    /* This is an ARM920T Core     */
#define CONFIG_S3C2410        1    /* in a SAMSUNG S3C2410 SoC    */
#define CONFIG_SMDK2410       1    /* on a SAMSUNG SMDK2410 Board */
#define CONFIG_S3C2440        1    /* in a SAMSUNG S3C2440 SoC    */

 

Now compile u-boot and a u-boot.bin file will be generated in the root directory. Then we use the original supervivi of mini2440 to download u-boot.bin to RAM and run the test (note: when we use supervivi to download, we have already initialized the CPU and RAM, so we need to block the CPU in u-boot , RAM initialization), as follows:

/*#ifndef CONFIG_SKIP_LOWLEVEL_INIT //Shield u-boot's initialization of CPU and RAM in the start.S file
   bl cpu_init_crit
#endif*/

#make my2440_config

#make

 

After downloading and running, you can see that the first LED light on the development board is on, and the other three are off. The test results meet the above requirements. The terminal running results are as follows:

 

#gedit cpu/arm920t/start.S

.globl _start
_start: b start_code //Jump the execution of the program to start_code

 

#gedit cpu/arm920t/u-boot.lds

OUTPUT_FORMAT("elf32-littlearm", "elf32-littlearm", "elf32-littlearm")
OUTPUT_ARCH(arm) //Define the target platform of the generated file to be arm
ENTRY(_start) //Define the entry point of the program to be _start

SEC TI ONS
{
    //Some other code segments, data segments, etc. are allocated
    . = 0x00000000;

    . = ALIGN(4);
    .text :
    {
        cpu/arm920t/start.o (.text)
        *(.text)
    }
    ..... ............................................. }
    ​

[1] [2]
Keywords:U-boot  S3C2440 Reference address:Detailed explanation of U-boot transplantation on S3C2440 (1)

Previous article:Taking s3c2440 as an example to explain the startup process of the arm chip
Next article:A brief discussion on how to learn and get started with ARM embedded systems

Recommended ReadingLatest update time:2024-11-23 02:41

S3C2440 USB device controller
The s3c2440 soc integrates a usb1.1 device controller, which can perform full-speed/low-speed control, interrupt and batch transmission. In addition to endpoint 0, it has four endpoints. Each endpoint can be used as an interrupt and batch endpoint. Each endpoint has a 128-byte FIFO, so the maximum packet of the endpoi
[Microcontroller]
S3C2440 - Send and receive strings using URAT0 query method
UART initialization function void Uart_Init(int pclk,int baud) {     int i;     rGPHCON|=0xa0; //GPH2,GPH3 as TXD0,RXD0     rGPHUP = 0x0; //GPH2, GPH3 internal pull-up     if(pclk == 0)     pclk = PCLK;     rUFCON0 = 0x0; //Disable the FIFO control register of 3 channels     rUFCON1 = 0x0;     rUFCON2 = 0x0;     rUM
[Microcontroller]
S3C2440 UART2 is configured as CTS problem solved
By default, the Linux kernel sets the function of uart2 to nRTS1 and nTCTS1, and it is not used as a normal serial port. If we want to use uart2 as a serial port, we need to make the following modifications: The Linux 2.6 kernel sets the value of the GPHCON register to 0x16faaa, which means that GPH6 is set to nRTS1
[Microcontroller]
S3C2440 serial communication basic function code
Function: Send out the content received through the serial port. What you see on the PC is that what you input in the serial communication software will be displayed in real time. Main file: serial.c 1 //The most commonly used registers are ULCON, UCON, UBRDIV, UTRSTAT, UTXH,
[Microcontroller]
S3C2440 GPIO example simulation analysis in ISRAM
Run the LED program on the mini2440 (S3C2440) board to make GPB5 output low level and light up the LED. Simulate code in ISRAM   1. The complete program of Led_on.s is as follows code:   --------------------------------led_on.S------------------ ----------------------------------   PRESERVE8 ; Keep the stack 8
[Microcontroller]
Detailed explanation of Uboot transplantation on S3C2440 (Part 4)
1. Transplantation Environment Host: VMWare--Fedora 9 Development board: Mini2440--64MB Nand, Kernel: 2.6.30.4 Compiler: arm-linux-gcc-4.3.2.tgz u-boot:u-boot-2009.08.tar.bz2 2. Transplantation Steps In this article, we first let the development board support CS8900 or DM9000X network car
[Microcontroller]
Detailed explanation of Uboot transplantation on S3C2440 (Part 4)
Chapter 4: TIny4412 U-BOOT transplantation four-configuration clock frequency source code analysis
The previous article talked about the principle of configuring the clock. Today, let's analyze it in detail with the source code. In the U-Boot source code, the system clock is initialized in the system_clock_init function in the clock_init_zthtiny4412.S file in the board folder (board/Samsung/mytiny4412). Our Tiny441
[Microcontroller]
Chapter 4: TIny4412 U-BOOT transplantation four-configuration clock frequency source code analysis
Install u-boot on mini2440
There are many articles on the Internet about how to port u-boot to 2440. I am just a novice and have never been involved in porting, so here I will just talk about my experience in installing u-boot on mini2440. I hope everyone can give me more advice. 1. Supervivi is already installed by default in the NOR flash o
[Microcontroller]
Latest Microcontroller Articles
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号