uboot傳遞參數'console=ttyXXX'的作用


轉載於:http://blog.csdn.net/jgdu1981/article/details/8643057

linux啟動時uboot傳遞進console=ttyS0,115200n8的參數

內核中用__setup()宏聲明參數處理的方法

關於__setup宏參考 early_param和__setup宏

  1. __setup("console=", console_setup);  

console_setup函數處理

1.console_cmdline結構體

  1. struct console_cmdline  
  2. {  
  3.     char    name[8];        //驅動名  
  4.     int index;      //次設備號  
  5.     char    *options;       //選項  
  6. #ifdef CONFIG_A11Y_BRAILLE_CONSOLE  
  7.     char    *brl_options;     
  8. #endif  
  9. };  

2.console_setup

  1. static int __init console_setup(char *str)  
  2. {  
  3.     char buf[sizeof(console_cmdline[0].name) + 4]; //分配驅動名+index的緩沖區  
  4.     char *s, *options, *brl_options = NULL;  
  5.     int idx;  
  6.   
  7. #ifdef CONFIG_A11Y_BRAILLE_CONSOLE  
  8.     if (!memcmp(str, "brl,", 4)) {  
  9.         brl_options = "";  
  10.         str += 4;  
  11.     } else if (!memcmp(str, "brl=", 4)) {  
  12.         brl_options = str + 4;  
  13.         str = strchr(brl_options, ',');  
  14.         if (!str) {  
  15.             printk(KERN_ERR "need port name after brl=\n");  
  16.             return 1;  
  17.         }  
  18.         *(str++) = 0;  
  19.     }  
  20. #endif  
  21.     if (str[0] >= '0' && str[0] <= '9') { //第一個參數屬於[0,9]  
  22.         strcpy(buf, "ttyS");    //則將其驅動名設為ttyS  
  23.         strncpy(buf + 4, str, sizeof(buf) - 5);//將次設備號放其后面  
  24.     } else {  
  25.         strncpy(buf, str, sizeof(buf) - 1); //放設備號到其后面  
  26.     }  
  27.     buf[sizeof(buf) - 1] = 0;  
  28.     if ((options = strchr(str, ',')) != NULL)   //獲取options  
  29.         *(options++) = 0;  
  30. #ifdef __sparc__  
  31.     if (!strcmp(str, "ttya"))  
  32.         strcpy(buf, "ttyS0");  
  33.     if (!strcmp(str, "ttyb"))  
  34.         strcpy(buf, "ttyS1");  
  35. #endif  
  36.     for (s = buf; *s; s++)  
  37.         if ((*s >= '0' && *s <= '9') || *s == ',')  
  38.             break;  
  39.     idx = simple_strtoul(s, NULL, 10);  //獲取次設備號  
  40.     *s = 0;  
  41.   
  42.     __add_preferred_console(buf, idx, options, brl_options);  
  43.     console_set_on_cmdline = 1;  
  44.     return 1;  
  45. }  

__add_preferred_console函數

  1. static int __add_preferred_console(char *name, int idx, char *options,char *brl_options)  
  2. {  
  3.     struct console_cmdline *c;  
  4.     int i;  
  5.     for (i = 0; i < MAX_CMDLINECONSOLES && console_cmdline[i].name[0]; i++)  //可以最多8個console  
  6.         if (strcmp(console_cmdline[i].name, name) == 0 && console_cmdline[i].index == idx) {  
  7.             //比較已注冊的console_cmdline數組中的項的名字及次設備號,若console_cmdline已經存在  
  8.                 if (!brl_options)  
  9.                     selected_console = i;   //設置全局selected_console索引號  
  10.                 return 0;       //則返回  
  11.         }  
  12.     if (i == MAX_CMDLINECONSOLES)   //判斷console_cmdline數組是否滿了  
  13.         return -E2BIG;  
  14.     if (!brl_options)  
  15.         selected_console = i;   //設置全局selected_console索引號  
  16.     c = &console_cmdline[i];    //獲取全局console_cmdline數組的第i項地址  
  17.     strlcpy(c->name, name, sizeof(c->name));  //填充全局console_cmdline的驅動名  
  18.     c->options = options;    //填充配置選項115200n8  
  19. #ifdef CONFIG_A11Y_BRAILLE_CONSOLE  
  20.     c->brl_options = brl_options;  
  21. #endif  
  22.     c->index = idx;  //填充索引號0  
  23.     return 0;  
  24. }  

整體的作用是根據uboot傳遞的參數設置全局console_cmdline數組 該數組及全局selected_console,在register_console中會使用到 二 console 設備驅動


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM