Monday, June 3, 2013

uboot kernel parameter passing

uboot kernel at boot time, some of the parameters passed to the kernel. It is said that there are two ways bootloader pass parameters to the kernel, the other I do not know, this article describes only the tag structure of the arm architecture mass participation under way.
uboot kernel at boot time, it will pass some parameters, including: RAM location and size of the command line parameters, initrd starting position and size, framebuffer physical address and size of the development board versions.
uboot put every parameter packaged into a structure tag (tag structure see Table 1), tag list to ATAG_CORE tag starting to ATAG_NONE tag as the end of the other parameters in these two between the start tag and the end tag . tag structure placed side by side in a physical memory address (in my development board is set to PHYS_SDRAM_1 + 0x100). So long as the kernel to get this starting physical location, you can parse them one by one tag.
  1. struct  tag {  
  2.     struct  tag_header HDR;  
  3.     Union  {  
  4.         struct  tag_core Core;  
  5.         struct  tag_mem32 mem;  
  6.         struct  tag_videotext Videotext;  
  7.         struct  tag_ramdisk ramdisk;  
  8.         struct  tag_initrd initrd;  
  9.         struct  tag_serialnr serialnr;  
  10.         struct  tag_revision Revision;  
  11.         struct  tag_videolfb videolfb;  
  12.         struct  tag_cmdline cmdline;  
  13.   
  14.         / * 
  15.          * Acorn specific 
  16.          * /  
  17.         struct  tag_acorn Acorn;  
  18.   
  19.         / * 
  20.          * DC21285 specific 
  21.          * /  
  22.         struct  tag_memclk MEMCLK;  
  23.     } U;  
  24. };  
Table a tag structure tag list creation process 


  1. int  do_bootm_linux ( int  flag,  int  argc,  char  * argv [], bootm_headers_t * images)  
  2. {  
  3.     bd_t * bd = gd-> bd;  
  4.     char     * s;  
  5.     int  machid = bd-> bi_arch_number;  
  6.     void     (* theKernel) ( int  zero,  int  Arch, uint params);  
  7.   
  8. # Ifdef CONFIG_CMDLINE_TAG  
  9.     char  * CommandLine = getenv ( "bootargs" );  
  10. # Endif  
  11.   
  12.     IF  ((flag! = 0) && (flag! = BOOTM_STATE_OS_GO))  
  13.         return  1;  
  14.   
  15.     theKernel = ( void  (*) ( int ,  int , uint)) images-> EP;  
  16.   
  17.     s = getenv ( "machid" );  
  18.     IF  (s) {  
  19.         machid = simple_strtoul (s, NULL, 16);  
  20.         printf ( "Using machid 0x% x from environment \ N" , machid);  
  21.     }  
  22.   
  23.     show_boot_progress (15);  
  24.   
  25.     debug ( "# # Transferring Control to Linux (at address% 08lx) ... \ N" ,  
  26.            (Ulong) theKernel);  
  27.   
  28. # If defined (CONFIG_SETUP_MEMORY_TAGS) | | \  
  29.     defined (CONFIG_CMDLINE_TAG) | | \  
  30.     defined (CONFIG_INITRD_TAG) | | \  
  31.     defined (CONFIG_SERIAL_TAG) | | \  
  32.     defined (CONFIG_REVISION_TAG) | | \  
  33.     defined (CONFIG_LCD) | | \  
  34.     defined (CONFIG_VFD)  
  35.     setup_start_tag (bd);  
  36. # Ifdef CONFIG_SERIAL_TAG  
  37.     setup_serial_tag (¶ ms);  
  38. # Endif  
  39. # Ifdef CONFIG_REVISION_TAG  
  40.     setup_revision_tag (¶ ms);  
  41. # Endif  
  42. # Ifdef CONFIG_SETUP_MEMORY_TAGS  
  43.     setup_memory_tags (bd);  
  44. # Endif  
  45. # Ifdef CONFIG_CMDLINE_TAG  
  46.     setup_commandline_tag (bd, commandline);  
  47. # Endif  
  48. # Ifdef CONFIG_INITRD_TAG  
  49.     IF  (images-> rd_start && images-> rd_end)  
  50.         setup_initrd_tag ​​(bd, images-> rd_start, images-> rd_end);  
  51. # Endif  
  52. # If defined (CONFIG_VFD) | | defined (CONFIG_LCD)  
  53.     setup_videolfb_tag ((gd_t *) gd);  
  54. # Endif  
  55.     setup_end_tag ​​(bd);  
  56. # Endif  
  57.   
  58.     / * We assume that the kernel is in place * /  
  59.     printf ( "\ nStarting kernel ... \ N \ N" );  
  60.   
  61. # Ifdef CONFIG_USB_DEVICE  
  62.     {  
  63.         extern  void  udc_disconnect ( void );  
  64.         udc_disconnect ();  
  65.     }  
  66. # Endif  
  67.   
  68.     cleanup_before_linux ();  
  69.   
  70.     theKernel (0, machid, bd-> bi_boot_params);  
  71.     / * Does not return * /  
  72.   
  73.     return  1;  
  74. }   

The above code is the process of uboot create kernel parameters, each parameter of the specific implementation, refer lib_arm/bootm.c
Note tag list constructed by the uboot, kernel is responsible for parsing tag list, so uboot and the kernel on the tag list of the structure must have the same definition. If you need to add a new uboot tag type, kernel section also need to add the appropriate type of resolution.

No comments:

Post a Comment