![]() |
Passing a custom parameter to the kernel
Hi,
I'm hacking some code in the kernel, and want to pass in a custom parameter to the kernel (either at boot time, or after startup), which my new code will use. This parameter is a number, ranging from 40 to 800, for example. The existing boot command line parameters do not allow the use of a user defined custom parameter to be passed in to the kernel. Is there a way to do this, either during or after boot? Thanks, John |
Have you tried using module_param()?
|
As far I know, any string you pass to kernel at boot time is available in /proc/cmdline pseudo file.
Check your current /proc/cmdline and you will find all strings you kernel received at boot time, even those are user space specific or are not used by anyone. |
Quote:
either one. I will post what I find after looking into it some more. John |
Quote:
I was looking into module_param, but it appears that it is used mainly for modules. There seems to be no documentation on what needs to be done if I wanted to add a parameter to the "kernel" boot command line in grub.conf, that would be visible as a global after init is done. John |
Quote:
For example, consider the loopback block device module (loop.ko). This module takes a single optional parameter (max_loop) telling it the maximum number of loopback devices. So if I want to alter this parameter at the time of module loading, I would do something like this: Code:
# modprobe loop max_loop=32Code:
kernel /vmlinuz root=/dev/sda3 loop.max_loop=32If you want to be slightly more arcane about kernel parameters for built-in code, you can always use the __setup() macro. If you want to be slightly more sophisticated, you could create a sysctl interface. |
Quote:
Code:
kernel /vmlinuz ro root=LABEL=/ rhgb quiet loop.max_loop=32 myparam=45Code:
[root@agente86 ~]# cat /proc/cmdline Code:
[root@agente86 ~]# for arg in $(cat /proc/cmdline); do |
Quote:
Since this is a hack for a temporary test system, I decided to use the __setup macro and get_option() in init/main.c, as follows: Code:
unsigned int my_param;and in the kernel code areas where I need to use this parameter, I extern my_param and use it; I'm still not clear how I would use module_param() in the case where it is not a parameter for a single module, but rather a value that I need to see and use in several kernel code areas, ie: mm and fs, for example. |
Quote:
I wanted to add that in the current kernel, the command line is also available as a global: Code:
char *saved_command_lineeasily parsed in C code in the kernel, to get any user parameter that is added to the "kernel" line of the grub configuration file. Please see my earlier post for what I eventually used. |
Sorry !
I didn't realize you are talking about coding in kernel space. I had to read your post a second time to figure out that, and it is very clear at beginning of your original post - my bad .... have a happy hacking, |
Quote:
and is a specific point i put this function in main.c or not? |
Quote:
Declare the function in main.c like the other __init functions like nosmp, maxcpus, etc, and then the related __setup() function below that, for clarity. In the code area where you want to use this parameter, declare "extern my_param" up top, so you can use it. Hope this helps. John |
| All times are GMT -5. The time now is 08:39 AM. |