U_boot_cmd command implementation

Source: Internet
Author: User

In uboot, commands are defined by the u_boot_cmd macro. In essence, they are easy to understand, but today I have learned something

Let's take a look at the definition of the u_boot_cmd macro in uboot:

/* This is the attribute that defines a structure. Put it in the. u_boot_cmd section, which is equivalent to. Data/. BSS */

# Define struct_section _ attribute _ (unused, section (". u_boot_cmd ")))

/* Macro definition, used to define a command */
# Define u_boot_cmd (name, maxargs, rep, CMD, usage )/
Pai_tbl_t _ u_boot_cmd _ # name struct_section = {# name, maxargs, rep, CMD, usage}

In this way, all the variables named cmd_tbl_t defined by u_boot_cmd will be placed in the. u_boot_cmd section (you can see the link script XXX. lDs of uboot). How to put the variables is the work of the linker.

Here we need to look at the two operations # name and # name. # name directly follows the character, # name will put the name in the form.

For example, define a command boot

U_boot_cmd (BOOT, 0, 0, fun, "Boot XXX ");

After expansion, it will become:

Pai_tbl_t _ u_boot_cmd_boot _ attribute ___ (unused, section (". u_boot_cmd") = {"Boot", 0, 0, fun, "Boot XXX "}

Most of them remain unchanged. I expanded struct_section, changed # name to boot, and changed # name to "Boot ". It is not difficult to see the role.

From the above, can we define a variable while the program is running ?? We can define a variable through # XXX, and then use it in this form.

In general, variables are defined by macro definitions, which should be struct variables accurately. In addition, the variables of the same struct are put in a segment, which makes full use of the function of the connector and is rarely seen, but it is indeed very practical. The advantage of this is that developers of all development modules do not have to maintain a global struct array, and you do not know which table in the array is used by others, this method solves such troubles and is worth promoting.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.