[U-Boot] How make xxx_config works?

Today, I'm going to talk about the question how make xxx_config in U-Boot works?

I'm very curious about this quesiton.

Let's take the virtual board "Helloween" with MIPS cpu on-board as the example.

U-Boot version is u-boot-2012.04.


According to the README in root path of U-Boot, one will know how to add a new board into U-Boot.

 

First step for that, you should add your board "Helloween" into boards.cfg, which locates in root path of U-Boot too.

For that, you just need to reference the board that uses the same CPU as yours.

After that, you should add a board header file in include/configs/, according to the named rule, you should name it "helloween.h"

The third step, you should make a directory in board/,  after it's done, there will exist a directory  "board/helloween/"

    Let's hold a moment for this, in this step, there are some files that need to be added, at least four files, which are helloween.c, Makefile, lowlevel_init.S, u-boot.lds respectively.

Ok, in the fourth step, you should make a directory in arch/mips/cpu/mips32/, after finishing making that directory, it will look like this  "arch/mips/cpu/mips32/helloween". It is assumed this MIPS CPU is mips32r2 release version.

    In this directory, there may also be some files you will need to add which related to the CPU, or may not.

 

After the necessary steps above, now we have a new board wait to be build.  As you know, there steps are not that easy, so please be patient.

At least for me, this is what I love, what I would like to dedicate myself to, so, I will never fell tedious.

Well, let's go ahead.

 

The first step in building, it should be "make distclean".

By the way, in this talk,  I do not wanna talk about make option "O=xxx", which is used to direct where to store the object files produced during the building process.

After running that command, we type "make helloween_config" to configure for the board "helloween".  

This is what I want to focus on in this talk.

 

What on earth runs behind when we slightly type into "make helloween_config" on the console?

There will be more details as we go further, let's move towards it step by step.

As you might know, if there is not any arguments in command line while make is called, make will look for the first target in that Makefile, and built it.

When you type "make helloween_config" in command line, Linux command make will be called with the argument "helloween_config", or the target "helloween_config".  Right? It is quite basic.

 

Here is a snippet in Makefile locating in the root path of U-Boot related with that target:

unconfig:
    @rm -f $(obj)include/config.h $(obj)include/config.mk \
        $(obj)board/*/config.tmp $(obj)board/*/*/config.tmp \
        $(obj)include/autoconf.mk $(obj)include/autoconf.mk.dep

%_config::    unconfig
    @$(MKCONFIG) -A $(@:_config=)

 

NOTE:

In Makefile rules, % is present in the target, its usage is the same with *, which could be used to represent any number of characters.

For the same symbol, it will have different meaning or use deponding on where it is used.

 

So, for the virtual board helloween after we run "make helloween", %_config = helloween_config. This equation is just for your understanding, it is very semantic, nor syntactic.

"::" is calld double-colon rules, but it is almost obscure. 

For more details about it, pleace have a look at the end of chapter 2 in the book "Managing projects with GNU Make" third version.

"unconfig" is the prerequisite to the target "%_config" here, and it will be built before commands in the rule run.

What unconfig does is to delete some files to clean by calling Linux command "rm".

 

The main part of the rule is the command script:

    @$(MKCONFIG) -A $(@:_config=)

 

MKCONFIG    := $(SRCTREE)/mkconfig, which also resides in the root path of U-Boot.

 

The cofusing part in that command is $(@:_config=), right?

Before going into that detail, we must know there is one kind of referencing methods, which is called substitution reference.

Its syntax goes like this:   a = $(b:c=d)

What it does is to search c in b, and if found, substitute d for c, the result will be placed in a.

Ok, with the substitution reference, let's go back to $(@:_config=).

In it,  the second @ is used to indicate the target in the rule:

%_config::    unconfig
    @$(MKCONFIG) -A $(@:_config=)

 

Put it in a simple way, the second @ is equal to %_config, the target in that rule.

Do you remember that, in a rule, $@ is used to get the value of the target ? Yes, in my opinion, this is why the second represents the target.

Substitution reference is applied to the second @, and the result is used as the second argument to mkconfig.

@:_config=, search "_config" in @(that is %_config, also helloween_config, the commnd line argument of make),

If found, replace "config" with nothing. Why nothing ? Because you see, there is nothing in the right of the sign of equality.

So, according to what mentioned above, $(@:_config=) will repace "_config" in @(helloween_config) with nothing,

just simply delete _config in @

that is

$(@:_config=) = helloween

 Ok, this is the first part.

And now, we know @$(MKCONFIG) -A $(@:_config=) is actually mkconfig -A helloween.

 

Let's move on to mkconfig now.

'Cause there is a tight relationship between mkconfig and boards.cfg, which is mentioned before.  Please recall it.

So, just for reference, let's add a line to boards.cfg for the board helloween, it lookes like this:

# Target                     ARCH        CPU         Board name          Vendor            SoC          Options
################################################################################

helloween                       mips       mips32      helloween              shawn       helloween     helloween:CPU_CLOCK_RATE=81000000

from: http://www.cnblogs.com/lake-of-embedded-system/archive/2012/08/11/2633773.html

发布了35 篇原创文章 · 获赞 3 · 访问量 7万+

猜你喜欢

转载自blog.csdn.net/dabbler_zhu/article/details/9906635