利用uboot传递参数进行内核的不同配置

来源:互联网 发布:诛杀知乎 编辑:程序博客网 时间:2024/05/17 05:59

    如果一个硬件有不同的驱动支持,那么每次还得重新编译内核才能重新加载驱动吗?内核提供了一种很方便的机制,可以让我们通过uboot的命令参数来传递,调用不同的内核驱动。

   

__setup("xxx=", xxx_setup);
以内核下的文件Fbmem.c为例!

/** * fb_get_options - get kernel boot parameters * @name:   framebuffer name as it would appear in *          the boot parameter line *          (video=<name>:<options>) * @option: the option will be stored here * * NOTE: Needed to maintain backwards compatibility */int fb_get_options(char *name, char **option){char *opt, *options = NULL;int retval = 0;int name_len = strlen(name), i;if (name_len && ofonly && strncmp(name, "offb", 4))retval = 1;if (name_len && !retval) {for (i = 0; i < FB_MAX; i++) {if (video_options[i] == NULL)continue;if (!video_options[i][0])continue;opt = video_options[i];if (!strncmp(name, opt, name_len) &&    opt[name_len] == ':')options = opt + name_len + 1;}}if (options && !strncmp(options, "off", 3))retval = 1;if (option)*option = options;return retval;}#ifndef MODULE/** *video_setup - process command line options *@options: string of options * *Process command line options for frame buffer subsystem. * *NOTE: This function is a __setup and __init function. *            It only stores the options.  Drivers have to call *            fb_get_options() as necessary. * *Returns zero. * */static int __init video_setup(char *options){int i, global = 0;if (!options || !*options) global = 1; if (!global && !strncmp(options, "ofonly", 6)) { ofonly = 1; global = 1; } if (!global && !strstr(options,"fb:")) { fb_mode_option = options; global = 1; } if (!global) { for (i = 0; i < FB_MAX; i++) { if (video_options[i] == NULL) { video_options[i] = options; break; }}}return 1;}__setup("video=", video_setup);
int fb_get_options(char *name, char **option)

得到不同的内核配置参数,之后依此可选择不同的文件进行驱动加载!

原创粉丝点击