歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux綜合 >> Linux內核 >> U-Boot與Linux內核的交互

U-Boot與Linux內核的交互

日期:2017/3/1 10:26:58   编辑:Linux內核

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

U-Boot源代碼下載地址 http://www.linuxidc.com/Linux/2011-07/38897.htm

目錄

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