Detailed explanation of Uboot transplantation on S3C2440 (Part 1)

Publisher:cheng1984Latest update time:2016-06-14 Source: eefocusKeywords:Uboot 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

The features of this transplant include:

  • Support Nand Flash read and write

  • 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.




    		    Detailed explanation of Uboot transplantation on S3C2440 (Part 1)
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 flowchart of each part is as follows:

 




    		    Detailed explanation of Uboot transplantation on S3C2440 (Part 1)
2. Create your own development board project and test compilation.
Currently, u-boot directly supports many CPUs. You can check some subdirectories of the board directory, such as the board/samsung/ directory, which supports some Samsung ARM processors, including smdk2400, smdk2410 and smdk6400, but not 2440, so we will build our own development board project here.
1) Since the resources of 2440 and 2410 are similar, but the main frequency and peripherals are slightly different, we created 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, the code of the 2410 project is used as a template and modified later.

#cp -rf smdk2410/* my2440/ //Copy all the 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 ../../../ //Back to u-boot root directory
#cp include/configs/smdk2410.h include/configs/my2440.h //Create 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 directory. Find the smdk2410_config, and create the compilation options of my2440_config according to the format of smdk2410_config. In addition, 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: corresponds to the directory where a new development board project is created under the board directory

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

s3c24x0: CPU model

*Note: The second line of the compilation option format must start with the Tab key, otherwise the compilation will fail.

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

#make my2440_config //If Configuring for my2440 board... appears, the settings are correct

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

So far, u-boot is of no use to my my2440 development board. The above transplantation only builds a u-boot framework for the my2440 development board. To realize its functions, the u-boot source code must be modified according to the specific resource conditions of the my2440 development board.

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

1) Analysis of the stage1 entry point of the u-boot of the my2440 development board.
Generally, in embedded system software development, after all source code files are compiled, the linker needs to read a link allocation file, which defines the program entry point, code segment, data segment, etc. The link file of our my2440 development board u-boot is cpu/arm920t/u-boot.lds. Open the file and some of the code is as follows:

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

From this assembly code, we can see that the program jumps to start_code and starts execution. Then the code 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 coloured_LED_init //The two lines here are to initialize the LED on the AT91RM9200DK development board
bl red_LED_on

From this we can see that start_code is the real starting point of the u-boot startup code. The above is the process of the u-boot stage1 entry.

2) Initialization of hardware devices in stage 1 of u-boot of my2440 development board.
Since there are two lines of AT91RM9200DK LED initialization code in the u-boot startup code, but the LED resources on my2440 are inconsistent with those of the development board, we need to delete or shield the code there, and add the LED driver code of my2440 (Note: adding the my2440 LED function is only used to indicate the running status of u-boot, which is convenient for debugging. You can put this code anywhere you want to debug). The code is as follows:

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

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

//According to the mini2440 schematic diagram, the LEDs are controlled by ports PB5, 6, 7, and 8 of the S3C2440. The following are the base addresses of the PB port registers (check the DataSheet of 2440)
#define GPBCON 0x56000010
#define GPBDAT 0x56000014
#define GPBUP 0x56000018

//The following register operations refer to the S3C2440 DataSheet
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, 8 as 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, 8 are high level
str r1,[r0]

#endif

//This code turns on LED1 on the development board after u-boot is started, while LED2, LED3, and LED4 are off

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

#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 S3 C2440 SoC */

 

3) Add support for some registers of S3C2440, interrupt disable part and clock setting part in u-boot.
Since the registers and addresses of 2410 and 2440 are mostly the same, we can just add support for 2440 based on 2410. The code is as follows:

In addition to adding the clock part of S3C2440 in start.S, you also need to modify or add some codes in board/samsung/my2440/my2440.c and cpu/arm920t/s3c24x0/speed.c, as follows:

#gedit board/samsung/my2440/my2440.c //Set the main frequency and USB clock frequency parameters to be consistent with those in start.S

#define FCLK_SPEED 2 //The default setting is 2, which means the red code below is valid

#if FCLK_SPEED==0 /* Fout = 203MHz, Fin = 12MHz for Audio */
#define M_MDIV 0xC3
#define M_PDIV 0x4
#define M_SDIV 0x1
#elif FCLK_SPEED==1 /* Fout = 202.8MHz */
#define M_MDIV 0xA1
#define M_PDIV 0x3
#define M_SDIV 0x1
#elifFCLK_SPEED==2/* Fout = 405MHz */
#defineM_MDIV 0x7F //These three values ​​are set according to the "PLL VALUE SELECTION TABLE" section of the S3C2440 chip manual
#define M_PDIV 0x2
#define M_SDIV 0x1
#endif

#define USB_CLOCK 2 //The default setting is 2, which means the red code below is valid

#if USB_CLOCK==0
#define U_M_MDIV 0xA1
#define U_M_PDIV 0x3
#define U_M_SDIV 0x1
#elifUSB_CLOCK==1
#define U_M_MDIV 0x48
#define U_M_PDIV 0x3
#define U_M_SDIV 0x2
#elifUSB_CLOCK==2/* Fout = 48MHz */
#defineU_M_MDIV 0x38 //These three values ​​are set according to the "PLL VALUE SELECTION TABLE" section of the S3C2440 chip manual
#define U_M_PDIV 0x2
#define U_M_SDIV 0x2
#endif

#gedit cpu/arm920t/start.S

#if defined(CONFIG_S3C2400)|| defined(CONFIG_S3C2410) || defined(CONFIG_S3C2440)
/* turn off the watchdog */

# if defined(CONFIG_S3C2400)
# define pWTCON 0x15300000
# define INTMSK 0x14400008 /* Interupt-Controller base addresses */
# define CLKDIVN 0x14800014 /* clock divisor register */
#else //The register addresses of 2410 and 2440 below are consistent
# define pWTCON 0x53000000
# define INTMSK 0x4A000008 /* Interupt-Controller base addresses */
# define INTSUBMSK 0x4A00001C
# define CLKDIVN 0x4C000014 /* clock divisor register */
# endif

ldr r0,=pWTCON
mov r1, #0x0
str r1,[r0]

/*
*mask all IRQs by setting all bits in the INTMR - default
*/
mov r1, #0xffffffff
ldr r0,=INTMSK
str r1,[r0]
# if defined(CONFIG_S3C2410)
ldr r1,=0x3ff
ldr r0,=INTSUBMSK
str r1,[r0]
# endif
# if defined(CONFIG_S3C2440)//Add interrupt disable part of s3c2440
ldr r1,=0x7fff //According to the 2440 chip manual, the INTSUBMSK register has 15 bits available

ldr r0,=INTSUBMSK
str r1,[r0]
# endif

# if defined(CONFIG_S3C2440) //Add the clock part of s3c2440# endif
#endif /* CONFIG_S3C2400 || CONFIG_S3C2410 || CONFIG_S3C2440 */

#define MPLLCON 0x4C000004 //System main frequency configuration register base address

#define UPLLCON 0x4C000008 //USB clock frequency configuration register base address
ldr r0,=CLKDIVN //Set the frequency division coefficient FCLK:HCLK:PCLK = 1:4:8
mov r1,#5
str r1,[r0]

ldr r0, =MPLLCON //Set the system main frequency to 405MHz

ldr r1, =0x7F021 //This value refers to the "PLL VALUE SELECTION TABLE" section of the chip manual

str r1, [r0]

ldr r0, =UPLLCON //Set USB clock frequency to 48MHz

ldr r1, =0x38022 //This value refers to the "PLL VALUE SELECTION TABLE" section of the chip manual

str r1, [r0]

#else //The clock part of other development boards, don't worry about it here, we are now working on 2440

/* FCLK:HCLK:PCLK = 1:2:4 */
/* default FCLK is 120 MHz !*/

ldr r0,=CLKDIVN
mov r1, #3
str r1,[r0]

#gedit cpu/arm920t/s3c24x0/speed.c //Modify the function of obtaining 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;
elseif(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)
{ //Refer to the formula in the S3C2440 chip manual: 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());
}

OK! After the modification is completed, we recompile u-boot and then download it to RAM to run the test. The terminal will output information and a command line similar to Shell will appear, which means that this part of the transplantation is complete. The schematic diagram is as follows:



    		    Detailed explanation of Uboot transplantation on S3C2440 (Part 1)

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 to run the test (Note: when we use supervivi to download, the CPU and RAM have been initialized, so we need to block the initialization of CPU and RAM in u-boot), as follows:

/*#ifndef CONFIG_SKIP_LOWLEVEL_INIT //Shield u-boot from initializing 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 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:



    		    Detailed explanation of Uboot transplantation on S3C2440 (Part 1)

#gedit cpu/arm920t/start.S

.globl _start
_start: b start_code // Jump the program execution 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 is arm
ENTRY(_start)//Define the entry point of the program is _start

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

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


Keywords:Uboot Reference address:Detailed explanation of Uboot transplantation on S3C2440 (Part 1)

Previous article:Detailed explanation of Uboot transplantation on S3C2440 (Part 2)
Next article:Detailed explanation of Uboot transplantation on S3C2440 (Part 3)

Recommended ReadingLatest update time:2024-11-16 15:37

Embedded ARM learning summary (VI) --S3C2440 system architecture learning summary
Platform introduction: mini2440 development board, S3c2440 main chip hardware information 1.130 IO ports, 289 pins 17*17, BGA package 2. Power supply Core: 1.25v Memory power supply: 1.8V GPIO: 3.3v 3. There is 4K bytes of SRAM space 0x40000000-0x40001000 inside the chip; 4.s3c2440 external Main frequency: 12M cryst
[Microcontroller]
Detailed explanation of S3C2440 clock system
Before talking about the system clock, because these devices are all dependent on the system clock, we must first talk about the system clock. The clock system of S3C2440 is as follows There are two types of external clock sources, crystal oscillator or external frequency, which are selected by om3-2. The clock circ
[Microcontroller]
Detailed explanation of S3C2440 clock system
Porting u-boot-2010.09 to S3C2440 (IV) - Determining the size of uboot through BSS segment and _start
BSS (Baidu Encyclopedia) It is the abbreviation of "Block Started by Symbol", which means "block starting with a symbol". BSS is the uninitialized data segment generated by the Unix linker. The other segments are the "text" segment containing program code and the "data" segment containing initialized data. Variables
[Microcontroller]
Detailed explanation of 2440init.s of s3c2440_Supplement
1.S3C2440 supports two boot modes: NAND FLASH and NOR FLASH. There are many articles on the Internet that analyze the startup file 2440init.s of TQ2440. The introduction is very detailed. Here I just describe the program flow after S3C2440 is powered on. Regardless of the startup mode, ARM starts running from 0X00
[Microcontroller]
Exynos4412 Uboot compilation tool - installation of cross tool chain arm-linux-gcc
1. What is cross-compilation? Run the compiler on the development host to compile the kernel and application. The kernel and program run on the target machine. This compilation process is called cross-compilation. The compiler runs on the development host (usually an X86-based PC), and the compiled code is for the tar
[Microcontroller]
Exynos4412 Uboot compilation tool - installation of cross tool chain arm-linux-gcc
s3c2440 IRQ processing process
Note that the ucos code (that is, the code in the main function) and the startup code both work in Supervisor mode, while IRQ works in External Interrupt mode. The register sets used in these two modes are different, so be sure to keep the corresponding registers when switching modes. If I set timer 2 to generate an
[Microcontroller]
S3C2440 touch screen driver code analysis
lab environment: Host: Fedora14 Development board: Tq2440 Ported Linux kernel version: linux-2.6.30.4   I recently studied the touch screen driver code of S3C2440, which can be regarded as a review of the previous period of time, so that I can recall some knowledge about the driver. The touch screen driver cod
[Microcontroller]
S3C2440 touch screen driver code analysis
Learn ARM development(11)
Because the compiled UBOOT written to FLASH always failed to run several times before. So what should I do? After thinking for a long time and checking the source code, I still didn't find the problem. Maybe the source code of the UBOOT is too large, there are many compilation switches, and many driver options, so I
[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号