本文共 2070 字,大约阅读时间需要 6 分钟。
/arch/arm/include/uapi/asm/setup.h
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; } u;};
内核参数通过一个静态的tag链表在启动的时候传递到内核。每个tag的结构为
+-----------+
tag_header
+-----------+
tag_xxx
+-----------+
其中tag_header为tag头,表明tag_xxx的类型和大小,之所以要标识tag_xxx的类型是因为不同的tag需要不同的处理函数。tag_header的结构为
struct tag_header
{
int size;
int tag;
}
size表示tag的结构大小,tag为表示tag类型的常量。这个静态的链表必须以tag_header.tag = ATAG_CORE开始,并以tag_header.tag = ATAG_NONE结束。
这里的
__HEAD/* Determine validity of the r2 atags pointer. The heuristic requires * that the pointer be aligned, in the first 16k of physical RAM and * that the ATAG_CORE marker is first and present. If CONFIG_OF_FLATTREE * is selected, then it will also accept a dtb pointer. Future revisions * of this function may be more lenient with the physical address and * may also be able to move the ATAGS block if necessary. * * Returns: * r2 either valid atags pointer, valid dtb pointer, or zero * r5, r6 corrupted */__vet_atags: tst r2, #0x3 @ aligned?是否4bytes对齐? bne 1f @ 不是就不合法 ldr r5, [r2, #0] @ 取得第一个atags结构的size#ifdef CONFIG_OF_FLATTREE ldr r6, =OF_DT_MAGIC @ is it a DTB? cmp r5, r6 beq 2f#endif cmp r5, #ATAG_CORE_SIZE @ is first tag ATAG_CORE?,#define ATAG_CORE_SIZE ((2*4 + 3*4) >> 2) cmpne r5, #ATAG_CORE_SIZE_EMPTY @ #define ATAG_CORE_SIZE_EMPTY ((2*4) >> 2) bne 1f @ size不是5(*4bytes),也不是2(*4bytes),不合法 ldr r5, [r2, #4] @ 取得tag ldr r6, =ATAG_CORE cmp r5, r6 @ 比较tag bne 1f @ 不是ATAG_CORE就不合法 2: mov pc, lr @ atag/dtb pointer is ok1: mov r2, #0 mov pc, lrENDPROC(__vet_atags)
转载地址:http://rdsqb.baihongyu.com/