U-Boot-1.1.6 is transplanted to the MINI2440 development board (1) - analysis before transplantation

Publisher:chaohuangmeitaoLatest update time:2022-11-18 Source: zhihuKeywords:U-Boot Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

Port U-Boot-1.1.6 to the MINI2440 development board and boot from NAND Flash (NOR Flash is not used).


What you need to prepare:


Linux environment: Ubuntu 16.04

Cross-compilation tool chain: arm-linux-gcc-3.4.5

U-Boot-1.1.6 Source: u-boot-1.1.6.tar.bz2

S3C2440手册:S3C2440A 32-BIT CMOS MICROCONTROLLER USERS MANUAL

ARM920T Technical Reference Manual: ARM920T Technical Reference Manual

Other related datasheets

Reference materials: "Complete Manual of Embedded Linux Application Development" and online blog (#^.^#).

Note: The following involves basic Linux operating commands and will not be described in detail.


Set up the cross-compilation environment:


It is recommended to use the compiled cross-compilation tool chain directly. The arm-linux-gcc-3.4.5 used here is to create a new folder in the directory:


soz@tzw-pc:~$ mkdir arm

soc@tzw-pc:~$ cd arm/

so-called@tzw-pc:~arm$ mkdir -p toolchains/arm-linux-gcc/3.4.5

Save the cross-compilation toolchain in a folder:


tzw@tzw-pc:~/arm$ ls toolchains/arm-linux-gcc/3.4.5/

arm-linux  bin  distributed  include  info  lib  libexec  man  tmp

The executable files in the /bin directory are the files used during compilation.


Then add the path of the cross-compilation tool chain to the environment variable. There are many ways to add it. Here, save it in the bash.bashrc file, open and edit bash.bashrc:


so-called@tzw-pc:~$ sudo gedit /etc/bash.bashrc

Start a new line at the end of the file and add the following statement. Be careful not to change other content in the file:


------- bash.bashrc -------

export PATH=$PATH:/home/tzw/arm/toolchains/arm-linux-gcc/3.4.5/bin

Save and close the file.


In Ubuntu, opening a new terminal or typing bash on the terminal to open a new shell will read /etc/bash.bashrc and ~/.bashrc. Therefore, using this method, you only need to reopen a terminal to make the environment variables take effect. . You can also enter the following command in the old terminal to make the environment variables take effect:


so-called@tzw-pc:~$ source /etc/bash.bashrc

Reopen a terminal (shortcut key: Ctrl+Alt+t) and enter the command:


so-called@tzw-pc:~$ arm-linux-gcc -v

Press Enter to see the output information:


Reading specs from /home/tzw/arm/toolchains/arm-linux-gcc/3.4.5/bin/../lib/gcc/arm-linux/3.4.5/specs

...

gcc version 3.4.5

Then the cross-compilation tool chain has been set up, and the last line is the version of GCC used. If the following message appears:


arm-linux-gcc: command not found

The instructions are not set correctly and you need to check whether the above steps are completed.




Get U-Boot source code:


Download the u-boot-1.1.6 source code compression package from the official website, create a new u-boot folder in the arm directory and extract the source code to the u-boot folder:


soc@tzw-pc:~/arm$ mkdir u-boot

soc@tzw-pc:~/arm$ cd u-boot

soz@tzw-pc:~/arm/u-boot$ tar -jxvf u-boot-1.1.6.tar.bz2

View the decompression results:


so-called@tzw-pc:~/arm/u-boot$ ls u-boot-1.1.6

arm_config.mk                  fs              MAKEALL

avr32_config.mk                i386_config.mk  Makefile

blackfin_config.mk             include         microblaze_config.mk

board                          lib_arm         mips_config.mk

CHANGELOG                      lib_avr32       mkconfig

CHANGELOG-before-U-Boot-1.1.5  lib_blackfin    nand_spl

common                         lib_generic     net

config.mk lib_i386 nios2_config.mk

COPYING                        lib_m68k        nios_config.mk

cpu                            lib_microblaze  post

CREDITS                        lib_mips        ppc_config.mk

disk                           lib_nios        README

doc                            lib_nios2       rtc

drivers                        lib_ppc         rules.mk

dtt                            m68k_config.mk  tools

examples                       MAINTAINERS

You can see the U-Boot source code in the /arm/u-boot/u-boot-1.1.6 directory.




Compile U-Boot-1.1.6 for the first time:


Instead of modifying the source code directly, copy the source code and modify it:


so-called@tzw-pc:~/arm/u-boot$ mkdir u-boot-mini2440-1.1.6

so-called@tzw-pc:~/arm/u-boot$ cp -r u-boot-1.1.6/* u-boot-mini2440-1.1.6/

View the copied results:


so-called@tzw-pc:~/arm/u-boot$ cd u-boot-mini2440-1.1.6/

soz@tzw-pc:~/arm/u-boot/u-boot-mini2440-1.1.6$ ls

arm_config.mk                  fs              MAKEALL

avr32_config.mk                i386_config.mk  Makefile

blackfin_config.mk             include         microblaze_config.mk

board                          lib_arm         mips_config.mk

CHANGELOG                      lib_avr32       mkconfig

CHANGELOG-before-U-Boot-1.1.5  lib_blackfin    nand_spl

common                         lib_generic     net

config.mk lib_i386 nios2_config.mk

COPYING                        lib_m68k        nios_config.mk

cpu                            lib_microblaze  post

CREDITS                        lib_mips        ppc_config.mk

disk                           lib_nios        README

doc                            lib_nios2       rtc

drivers                        lib_ppc         rules.mk

dtt                            m68k_config.mk  tools

examples                       MAINTAINERS

mini2440开发板使用Samsung的S3C2440芯片,与U-Boot-1.1.6中已有的smdk2410开发板(采用Samsung S3C2410芯片)相似,因此在smdk2410的基础上进行移植。


首先测试一下源码是否能正常编译:


tzw@tzw-pc:~/arm/u-boot/u-boot-mini2440-1.1.6$ make distclean

tzw@tzw-pc:~/arm/u-boot/u-boot-mini2440-1.1.6$ make smdk2410_config

tzw@tzw-pc:~/arm/u-boot/u-boot-mini2440-1.1.6$ make

make distclean:完全清除所有配置以及生成的文件。

make clean:清除所有生成的文件,会保留配置。

make smdk2410_config:进行smdk2410开发板的配置。

make:根据Makefile生成二进制文件u-boot.bin。

等待一段时间,可以在/u-boot-mini2440-1.1.6目录下看到生成的二进制文件:


tzw@tzw-pc:~/arm/u-boot/u-boot-mini2440-1.1.6$ ls u-boot.bin

u-boot.bin

如果开发板是smdk2410的话,那么将这个二进制文件烧写进开发板,就可以在串口上看到U-Boot的运行输出信息了。


如果make执行过程中出现错误的话,一般是一些依赖的库没有安装,根据报错信息依次安装所需要的库进行了,直到最后生成u-boot.bin这个二进制文件。




移植前的分析:


由上述可知,U-Boot的编译首先需要配置,然后才进行编译:


tzw@tzw-pc:~/arm/u-boot/u-boot-mini2440-1.1.6$ make smdk2410_config --just-print

make smdk2410_config --just-print:仅输出将要执行的语句,但并不执行。

输出信息:


tzw@tzw-pc:~/arm/u-boot/u-boot-mini2440-1.1.6$ make smdk2410_config --just-print

rm -f include/config.h include/config.mk

    board/*/config.tmp board/*/*/config.tmp

/home/tzw/arm/u-boot/u-boot-mini2440-1.1.6/mkconfig smdk2410 arm arm920t smdk2410 NULL s3c24x0

可知首先删除了原先的一些配置相关的文件:


include/config.h

include/config.mk

board/*/config.tmp

board/*/*/config.tmp

即/include目录下的config.h、config.mk,/board目录下所有与配置相关的config.tmp文件。


然后执行:


mkconfig smdk2410 arm arm920t smdk2410 NULL s3c24x0

mkconfig是/u-boot-mini2440-1.1.6目录下的一个文件,后面是输入的6个参数:


mkconfig smdk2410 arm arm920t smdk2410 NULL s3c24x0

$0       $1       $2  $3      $4       $5   $6

$0表示所执行的程序的名称;

$1~$6为所执行的程序的输入参数。

从Makefile中可知:


------- Makefile -------

92 MKCONFIG    := $(SRCTREE)/mkconfig

93 export MKCONFIG

...

1879 smdk2410_config    :    unconfig

1880     @$(MKCONFIG) $(@:_config=) arm arm920t smdk2410 NULL s3c24x0

打开顶层mkconfig文件,进行分析:


默认创建新的配置文件,并将板子的名称置为"":


------- mkconfig -------

11 APPEND=no    # Default: Create new config file

12 BOARD_NAME=""    # Name to print in make output

判断传入的参数是否含有特殊项,并进行处理,这里并无特殊项:


------- mkconfig -------

14 while [ $# -gt 0 ] ; do

15     case "$1" in

16     --) shift ; break ;;

17     -a) shift ; APPEND=yes ;;

18     -n) shift ; BOARD_NAME="${1%%_config}" ; shift ;;

19     *)  break ;;

20     esac

21 done

$# 所执行的程序的参数的个数;

-gt 大于(greater than);

-eq 等于(equal);

-ne 不等于(not equal);

-ge 大于等于(greater and equal);

-lt 小于(less than);

-le小于等于(less and equal)。

第23行判断开发板名称是否存在,并将其赋值为第一个参数,即BOARD_NAME=smdk2410:


------- mkconfig -------

23 [ "${BOARD_NAME}" ] || BOARD_NAME="$1"

第25、26行对参数个数进行判断,不满足要求则退出:


------- mkconfig -------

25 [ $# -lt 4 ] && exit 1

26 [ $# -gt 6 ] && exit 1

输出配置信息:Configuring for smdk2410 board...


------- mkconfig -------

28 echo "Configuring for ${BOARD_NAME} board..."

第33行到62行新建链接文件:


------- mkconfig -------

33 if [ "$SRCTREE" != "$OBJTREE" ] ; then

34     mkdir -p ${OBJTREE}/include

35     mkdir -p ${OBJTREE}/include2

36     cd ${OBJTREE}/include2

37     rm -f asm

38     ln -s ${SRCTREE}/include/asm-$2 asm

39     LNPREFIX="../../include2/asm/"

40     cd ../include

41     rm -rf asm-$2

42     rm -f asm

43     mkdir asm-$2

44     ln -s asm-$2 asm

45 else

46     cd ./include

47     rm -f asm

48     ln -s asm-$2 asm

49 fi

50 

51 rm -f asm-$2/arch

52 

53 if [ -z "$6" -o "$6" = "NULL" ] ; then

54     ln -s ${LNPREFIX}arch-$3 asm-$2/arch

55 else

56     ln -s ${LNPREFIX}arch-$6 asm-$2/arch

57 be

58 

59 if [ "$2" = "arm" ] ; then

60     rm -f asm-$2/proc

61     ln -s ${LNPREFIX}proc-armv asm-$2/proc

62 fi

The first if judgment executes the else branch on line 45, enters the /include directory, and creates a link file /asm pointing to /asm-arm.

Then delete the original /asm-arm/arch directory.

The second if judgment executes the else branch on line 55 and creates a link file /asm-arm/arch pointing to /arch-s3c24x0.

Finally, execute the judgment on line 60, delete the original /asm-arm/proc directory, and create a link file /asm-arm/proc pointing to /asm-arm/proc-armv.

Lines 67 to 73 create the config.mk file:


------- mkconfig -------

67 echo "ARCH   = $2" >  config.mk

68 echo "CPU    = $3" >> config.mk

69 echo "BOARD  = $4" >> config.mk

70 

71 [ "$5" ] && [ "$5" != "NULL" ] && echo "VENDOR = $5" >> config.mk

72 

73 [ "$6" ] && [ "$6" != "NULL" ] && echo "SOC    = $6" >> config.mk

Contents of the /include/config.mk file:


------- /include/config.mk -------

1 ARCH   = arm

2 CPU    = arm920t

3 BOARD = smdk2410

4 SOC    = s3c24x0

Finally create the config.h file:


------- mkconfig -------

78 if [ "$APPEND" = "yes" ]    # Append to existing config file

79 then

80     echo >> config.h

81 else

82     > config.h        # Create new config file

83 be

84 echo "/* Automatically generated - do not edit */" >>config.h

85 echo "#include " >>config.h

Contents of the /include/config.h file:


------- /include/config.h -------

1 /* Automatically generated - do not edit */

2 #include

Therefore, the result of the make smdk2410_config command is to call the mkconfig command for configuration, delete the original link file, create a new link file, and generate two files, config.mk and config.h.

[1] [2]
Keywords:U-Boot Reference address:U-Boot-1.1.6 is transplanted to the MINI2440 development board (1) - analysis before transplantation

Previous article:U-Boot-1.1.6 is transplanted to the MINI2440 development board (3) - the first stage of source code analysis
Next article:Detailed explanation of ARM processing registers and user mode

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号