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

10

我想在U-Boot和Linux内核中添加自定义的atag变量。
我该如何实现?
有没有添加ATAG变量到U-BootLinux的步骤?


2
你可能应该考虑使用设备树。ATAGs已经被弃用了。 - tangrs
3个回答

5
  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.
    
    1. 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.


5

最新的Linux内核试图用设备树来淘汰ATAGS。然而,在setup.h文件中,定义了不同的ATAG值和结构体。要解析这些内容,您需要像以下代码一样添加它们。

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);

这些内容可以在 atags_parse.c 中找到。当然,在 setup.h 中也需要添加它们的值。

u-boot 可能没有那么明确定义,因为它大多数情况下通过内核命令行传递参数,这不是 ARM 特有的。使用 命令参数设备树 可能是首选方法。如果你提供了需要的配置类型示例,其他人可能会给予更好的指导。


1
参考文献:Linux ARM启动文档,解释ATAGS等。 - artless noise

4

按照以下步骤进行操作:

要实现这个目标,需要修改两个部分。一个是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.

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接