U-Boot与Linux内核的交互


说明:本文所使用的U-Boot的版本是1.1.6,平台是S3C2440。

U-Boot源代码下载地址

目录

一、简介
1.1标记列表
二、设置标记存放的地址
2.1相关的结构体定义
2.2标记存放地址的设定
三、标记的设置
3.1设置标记ATAG_CORE
3.2设置内存标记ATAG_MEM
3.3设置命令行标记ATAG_CMDLINE
3.4设置ATAG_NONE

一、简介

U-Boot与Linux内核的交互是单向的,U-Boot将各类参数传递给讷河。由于他们不能同时运行,传递办法只能有一个个:U-Boot将参数放在某个约定的地方之后,在启动内核,内核启动后从这个地方获得参数。

1.1标记列表

除了约定好参数存放的地方外,还要规定参数的结构。Linux2.4.x以后的内核都以标记列表(tagged list)的形式来传递参数。标记就是一种数据结构;标记列表就是挨着存放的多个标记。标记列表以标记ATAG_CORE开始,以ATAGE_NONE结束。

标记的数据结构为tag,它是偶一个tag_header结构和一个联合体(union)组成。tag_header结构体表示标记的类型及长度,比如是表示内存还是表示命令行参数等。对于不同类型的标记使用不同的联合体,比如表示内存=时使用tag_men32,表示命令行时使用tag_cmdline。其定定义在include/asm-arm/setup.c文件中。

  1. /*  
  2.  * The new way of passing information: a list of tagged entries  
  3.  */  
  4.   
  5. /* The list ends with an ATAG_NONE node. */  
  6. #define ATAG_NONE   0x00000000  
  7.   
  8. struct tag_header {  
  9.     u32 size;  
  10.     u32 tag;  
  11. };  
  12.   
  13. /* The list must start with an ATAG_CORE node */  
  14. #define ATAG_CORE   0x54410001  
  15.   
  16. struct tag_core {  
  17.     u32 flags;      /* bit 0 = read-only */  
  18.     u32 pagesize;  
  19.     u32 rootdev;  
  20. };  
  21.   
  22. /* it is allowed to have multiple ATAG_MEM nodes */  
  23. #define ATAG_MEM    0x54410002  
  24.   
  25. struct tag_mem32 {  
  26.     u32 size;  
  27.     u32 start;  /* physical start address */  
  28. };  
  29.   
  30. /* VGA text type displays */  
  31. #define ATAG_VIDEOTEXT  0x54410003  
  32.   
  33. struct tag_videotext {  
  34.     u8      x;  
  35.     u8      y;  
  36.     u16     video_page;  
  37.     u8      video_mode;  
  38.     u8      video_cols;  
  39.     u16     video_ega_bx;  
  40.     u8      video_lines;  
  41.     u8      video_isvga;  
  42.     u16     video_points;  
  43. };  
  44.   
  45. /* describes how the ramdisk will be used in kernel */  
  46. #define ATAG_RAMDISK    0x54410004  
  47.   
  48. struct tag_ramdisk {  
  49.     u32 flags;  /* bit 0 = load, bit 1 = prompt */  
  50.     u32 size;   /* decompressed ramdisk size in _kilo_ bytes */  
  51.     u32 start;  /* starting block of floppy-based RAM disk image */  
  52. };  
  53.   
  54. /* describes where the compressed ramdisk image lives (virtual address) */  
  55. /*  
  56.  * this one accidentally used virtual addresses - as such,  
  57.  * its depreciated.  
  58.  */  
  59. #define ATAG_INITRD 0x54410005  
  60.   
  61. /* describes where the compressed ramdisk image lives (physical address) */  
  62. #define ATAG_INITRD2    0x54420005  
  63.   
  64. struct tag_initrd {  
  65.     u32 start;  /* physical start address */  
  66.     u32 size;   /* size of compressed ramdisk image in bytes */  
  67. };  
  68.   
  69. /* board serial number. "64 bits should be enough for everybody" */  
  70. #define ATAG_SERIAL 0x54410006  
  71.   
  72. struct tag_serialnr {  
  73.     u32 low;  
  74.     u32 high;  
  75. };  
  76.   
  77. /* board revision */  
  78. #define ATAG_REVISION   0x54410007  
  79.   
  80. struct tag_revision {  
  81.     u32 rev;  
  82. };  
  83.   
  84. /* initial values for vesafb-type framebuffers. see struct screen_info  
  85.  * in include/linux/tty.h  
  86.  */  
  87. #define ATAG_VIDEOLFB   0x54410008  
  88.   
  89. struct tag_videolfb {  
  90.     u16     lfb_width;  
  91.     u16     lfb_height;  
  92.     u16     lfb_depth;  
  93.     u16     lfb_linelength;  
  94.     u32     lfb_base;  
  95.     u32     lfb_size;  
  96.     u8      red_size;  
  97.     u8      red_pos;  
  98.     u8      green_size;  
  99.     u8      green_pos;  
  100.     u8      blue_size;  
  101.     u8      blue_pos;  
  102.     u8      rsvd_size;  
  103.     u8      rsvd_pos;  
  104. };  
  105.   
  106. /* command line: \0 terminated string */  
  107. #define ATAG_CMDLINE    0x54410009  
  108.   
  109. struct tag_cmdline {  
  110.     char    cmdline[1]; /* this is the minimum size */  
  111. };  
  112.   
  113. /* acorn RiscPC specific information */  
  114. #define ATAG_ACORN  0x41000101  
  115.   
  116. struct tag_acorn {  
  117.     u32 memc_control_reg;  
  118.     u32 vram_pages;  
  119.     u8 sounddefault;  
  120.     u8 adfsdrives;  
  121. };  
  122.   
  123. /* footbridge memory clock, see arch/arm/mach-footbridge/arch.c */  
  124. #define ATAG_MEMCLK 0x41000402  
  125.   
  126. struct tag_memclk {  
  127.     u32 fmemclk;  
  128. };  
  129.   
  130. struct tag {  
  131.     struct tag_header hdr;  
  132.     union {  
  133.         struct tag_core     core;  
  134.         struct tag_mem32    mem;  
  135.         struct tag_videotext    videotext;  
  136.         struct tag_ramdisk  ramdisk;  
  137.         struct tag_initrd   initrd;  
  138.         struct tag_serialnr serialnr;  
  139.         struct tag_revision revision;  
  140.         struct tag_videolfb videolfb;  
  141.         struct tag_cmdline  cmdline;  
  142.   
  143.         /*  
  144.          * Acorn specific  
  145.          */  
  146.         struct tag_acorn    acorn;  
  147.   
  148.         /*  
  149.          * DC21285 specific  
  150.          */  
  151.         struct tag_memclk   memclk;  
  152.     } u;  
  153. };  
  154.   
  155. #define tag_next(t)<span style="white-space:pre"> </span>((struct tag *)((u32 *)(t) + (t)->hdr.size))  
  156. #define tag_size(type)<span style="white-space:pre">  </span>((sizeof(struct tag_header) + sizeof(struct type)) >> 2) //???  
  • 1
  • 2
  • 3
  • 下一页

相关内容