简体   繁体   English

如何在U-Boot和Linux内核中添加自定义ATAG变量?

[英]How to add customised ATAG variable in U-Boot and Linux kernel?

I want to add customized atag variable in U-Boot and Linux kernel. 我想在U-Boot和Linux内核中添加自定义的atag变量。
How can i achieve this? 我怎样才能实现这一目标?
Is there any procedure to add an ATAG variable in U-Boot and Linux ? 是否有任何程序在U-BootLinux添加ATAG变量?

  1. U-Boot changes required : 需要U-Boot更改:

     A. Make sure the CONFIG_CMDLINE_TAG/CONFIG_SETUP_MEMORY_TAGS/CONFIG_INITRD_TAG are defined in you project definition header file ( u-boot/include/configs/am335x_evm.h ), and we can add our own tag here, eg. CONFIG_CUSTOM_TAG. B. Add the structure definition you wanna append w/ ATAG in u-boot/include/asm-arm/setup.h, eg. #define ATAG_CUSTOM 0x5441000a struct tag_custom{ unsigned char mac_addr[6]; }; C. Add the struct at the tail of "u"... struct tag { struct tag_header hdr; union { struct tag_core core; struct tag_mem32 mem; struct tag_videotext videotext; struct tag_ramdisk ramdisk; struct tag_initrd initrd; struct tag_serialnr serialnr; struct tag_revision revision; struct tag_videolfb videolfb; struct tag_cmdline cmdline; /* * Acorn specific */ struct tag_acorn acorn; /* * DC21285 specific */ struct tag_memclk memclk; /****** INFOTECH Custom TAG ********/ struct tag_custom custom; } u; }; D. Add implementation code in lib_arm/bootm.c: static void setup_custom_tag(bd_t *bd); static void setup_custom_tag(bd_t *bd) { params->hdr.tag = ATAG_CUSTOM; params->hdr.size = tag_size (tag_macaddr); params->u.custom.cmd =0; params = tag_next (params); } E. Add "#ifdef CONFIG_CUSTOM_TAG / #endif" at every place you change the code. F. Done of U-Boot modification. 
    1. Linux Changes required: 需要Linux更改:

      A. Add parse tag code in linux/arch/arm/kernel/setup.c: A.在linux / arch / arm / kernel / setup.c中添加解析标记代码:

       int cmd; static int __init parse_tag_custom(const struct tag *tag){ printk("u.custom.cmd=%d\\n",tag->u.custom.cmd); return 0; } __tagtable(ATAG_MACADDR, parse_tag_custom); 

      B. Add the structure declaration as U-Boot did in linux/include/asm-arm/setup.h: B.在linux / include / asm-arm / setup.h中将结构声明添加为U-Boot:

       #define ATAG_MACADDR 0x5441000a struct tag_custom { int cmd; }; 

      C. Add the struct at the tail of "u"... C.在“你”的尾部添加结构...

       struct tag { struct tag_header hdr; union { struct tag_core core; struct tag_mem32 mem; struct tag_videotext videotext; struct tag_ramdisk ramdisk; struct tag_initrd initrd; struct tag_serialnr serialnr; struct tag_revision revision; struct tag_videolfb videolfb; struct tag_cmdline cmdline; /* * Acorn specific */ struct tag_acorn acorn; /* * DC21285 specific */ struct tag_memclk memclk; /* Add Infotech custom tag */ struct tag_custom custom; } u; }; 

      D. Done w/ Kernel parts. D.完成内核部分。

The latest Linux kernel is attempting to obsolete ATAGS with device trees . 最新的Linux内核试图用设备树淘汰ATAGS However, the setup.h file defines the different ATAG values and structures. 但是, setup.h文件定义了不同的ATAG值和结构。 To parse these, you need to add them with something like, 要解析这些,你需要添加类似的东西,

static int __init parse_tag_custom(const struct tag *tag)
{
    if (tag->hdr.size > CUSTOM_SIZE) {
         /* Use, storing or acting on passed values */ 
         tag->u.custom;
    }
    return 0;
}

__tagtable(ATAG_CUSTOM, parse_tag_custom);

as found in atags_parse.c . atags_parse.c中找到。 Of course, you need to add these to the values in setup.h . 当然,您需要将这些添加到setup.h中的值。

u-boot is probably less defined as for the most part, it passes arguments via the kernel command line as this is not ARM specific. u-boot可能在很大程度上被定义为较少,它通过内核命令行传递参数,因为这不是ARM特定的。 A command argument or device trees is probably the preferred method. 命令参数设备树可能是首选方法。 If you gave an example of what type of configuration you need, someone could probably give better guidance. 如果您举例说明了您需要什么类型的配置,那么有人可能会提供更好的指导。

Follow this procedure , 按照这个程序,

To achieve this goal, there're 2 parts need to be modified. 为实现这一目标,需要修改两个部分。 One is the U-Boot, and the other one is the Linux kernel. 一个是U-Boot,另一个是Linux内核。

    1.    U-Boot changes required :

        A.     Make sure the  CONFIG_CMDLINE_TAG/CONFIG_SETUP_MEMORY_TAGS/CONFIG_INITRD_TAG are defined in you project definition header file ( u-boot/include/configs/am335x_evm.h ), and we  can add our own tag here, eg. CONFIG_CUSTOM_TAG.

        B.     Add the structure definition you wanna append w/ ATAG in u-boot/include/asm-arm/setup.h, eg.

            #define ATAG_CUSTOM 0x5441000a
            struct tag_custom{
            unsigned char mac_addr[6];
            };

        C.    Add the struct at the tail of "u"...

            struct tag {
                    struct tag_header hdr;
                    union {
                    struct tag_core         core;
                    struct tag_mem32        mem;
                    struct tag_videotext    videotext;
                    struct tag_ramdisk      ramdisk;
                    struct tag_initrd       initrd;
                    struct tag_serialnr     serialnr;
                    struct tag_revision     revision;
                    struct tag_videolfb     videolfb;
                    struct tag_cmdline      cmdline;

                    /*
                     * Acorn specific
                     */
                    struct tag_acorn        acorn;

                    /*
                     * DC21285 specific
                     */
                    struct tag_memclk       memclk;

                    /****** INFOTECH Custom TAG ********/

                   struct tag_custom custom;
                    } u;
                };

        D.    Add implementation code in lib_arm/bootm.c:

            static void setup_custom_tag(bd_t *bd);

            static void setup_custom_tag(bd_t *bd) {
                params->hdr.tag = ATAG_CUSTOM;
                   params->hdr.size = tag_size (tag_macaddr);
                params->u.custom.cmd =0;
                params = tag_next (params);
            }

        E.    Add "#ifdef CONFIG_CUSTOM_TAG / #endif" at every place you change the code.

        F.    Done of U-Boot modification.

2. Linux Changes required:

        A.    Add parse tag code in linux/arch/arm/kernel/setup.c:

            int cmd;
            static int __init parse_tag_custom(const struct tag *tag){
                    printk("u.custom.cmd=%d\n",tag->u.custom.cmd);
                return 0;
            }

            __tagtable(ATAG_MACADDR, parse_tag_custom);

        B. Add the structure declaration as U-Boot did in linux/include/asm-arm/setup.h:

            #define ATAG_MACADDR 0x5441000a
            struct tag_custom {
                int cmd;
            };

        C. Add the struct at the tail of "u"...

            struct tag {
                struct tag_header hdr;
               union {
                    struct tag_core         core;
                 struct tag_mem32        mem;
                struct tag_videotext    videotext;
                struct tag_ramdisk      ramdisk;
                struct tag_initrd       initrd;
                struct tag_serialnr     serialnr;
                struct tag_revision     revision;
                struct tag_videolfb     videolfb;
                struct tag_cmdline      cmdline;

                /*
                 * Acorn specific
                 */
                struct tag_acorn        acorn;

                /*
                 * DC21285 specific
                 */
                struct tag_memclk       memclk;

                /* Add Infotech custom tag */

                struct tag_custom      custom;
                } u;
            };

        D. Done w/ Kernel parts.

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM