LinuxQuestions.org
Visit the LQ Articles and Editorials section
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 12-25-2008, 02:18 AM   #1
mintzyuval
LQ Newbie
 
Registered: Dec 2008
Location: Tel-Aviv, Israel
Posts: 14

Rep: Reputation: 0
How can I access bootargs from inside the kernel?


Hey guys,

Sorry if I post this question in the wrong place / it was already asked before in a different thread (likely) - I tried to find this topic and failed... That's what happens when you're new to all of this...

Anyhow, I'm trying to work on my linux (2.6.23.1) and I wanted to ask about bootargs - how exactly and when are they used? how can I access them from inside the kernel drivers? (and from when?)

I'm using U-boot as a boot-loader (For a mips processor), and I'd like to attempt to write drivers which could use paramaters passed from the U-boot via the bootargs.

Anyway, if anyone could answer / refer me to a document about this topic, I'd be grateful.

Thanks,
Mintz Yuval
 
Old 12-25-2008, 07:29 PM   #2
stress_junkie
Senior Member
 
Registered: Dec 2005
Location: Massachusetts, USA
Distribution: Ubuntu 10.04 and CentOS 5.5
Posts: 3,873

Rep: Reputation: 331Reputation: 331Reputation: 331Reputation: 331
The files under /proc are your window into the running kernel. It looks to me like the /proc/cmdline file has the boot parameters.
Code:
cat /proc/cmdline
root=UUID=<long-value> ro quiet splash
 
Old 12-28-2008, 08:39 AM   #3
mintzyuval
LQ Newbie
 
Registered: Dec 2008
Location: Tel-Aviv, Israel
Posts: 14

Original Poster
Rep: Reputation: 0
First - thanks.

I didn't know how to access it from user-space.

But what I'm really interested is in accessing it via kernel-space (e.g. what's the function interface inside the kernel for getting bootarg values)

Thanks,
Mintz Yuval
 
Old 12-28-2008, 01:18 PM   #4
i92guboj
Gentoo support team
 
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 4,036

Rep: Reputation: 372Reputation: 372Reputation: 372Reputation: 372
http://cateee.net/lkddb/web-lkddb/CMDLINE.html
 
Old 12-29-2008, 01:31 AM   #5
mintzyuval
LQ Newbie
 
Registered: Dec 2008
Location: Tel-Aviv, Israel
Posts: 14

Original Poster
Rep: Reputation: 0
Well - I'm not certain what to do with the information you've given me in the last link; My problem is not in setting the CMDLINE (so I could use the /proc/cmdline pseudo-file) but in using bootargs passed from boot-loader while inside kernel initialization.

(unless, of course, I can use the /proc pseudo-file before my filesystem are initialized; but it seems unlikely to me)

Thanks,
Mintz Yuval
 
Old 12-29-2008, 02:19 AM   #6
i92guboj
Gentoo support team
 
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 4,036

Rep: Reputation: 372Reputation: 372Reputation: 372Reputation: 372
Then I think I completely misunderstood your question. I'll try once more hehe

Is this what you mean?


http://www.tldp.org/LDP/lkmpg/2.6/html/x323.html

Last edited by i92guboj; 12-29-2008 at 03:17 AM.
 
Old 12-29-2008, 03:11 AM   #7
mintzyuval
LQ Newbie
 
Registered: Dec 2008
Location: Tel-Aviv, Israel
Posts: 14

Original Poster
Rep: Reputation: 0
I think we fail to understand each other...
Either the last link has nothing to do with what I've asked, or I simply fail to understand what it means entirely.

Let's re-state my question:

I'm using U-boot as a boot loader. Let's assume I wish to set bootargs to be: "root=08:01 rw silent MyDriver=3500"

Now, I expect the linux to recieve this as bootargs, and indeed, if I'll use "cat /proc/cmdline" from the user shell, I'll see those values.

But now let's assume that I wish to change (or write a new) one of my linux driver, and I want it to use one of the values passed via the bootargs.
For example, let's assume I wish to change my serial driver to use the value in MyDriver (if such a value was set) to configure the serial port.

My question is - which functions can I use inside the kernel's code to get that value; there should be a "foo()" function that returns values from the bootargs for kernel usage, right?

What I'm really interested is in that "foo()" function, so I could extract those values inside kernel-space (before pseduo-filesystem initialization).

I hope that clarifies my need.

Thanks again,
Mintz Yuval
 
Old 12-29-2008, 03:17 AM   #8
i92guboj
Gentoo support team
 
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 4,036

Rep: Reputation: 372Reputation: 372Reputation: 372Reputation: 372
Sorry, I have no absolutely no idea how that link was messed that way. I probably clicked the wrong boormark when pasting it or something like that. It obviously had nothing to do with the question (it was about Gentoo ebuilds development, and not kernel related at all). I have fixed it. Look at it now. Sorry for all the inconvenience. I guess I missed a couple of coffee cups today.

Last edited by i92guboj; 12-29-2008 at 03:19 AM.
 
Old 12-29-2008, 05:26 AM   #9
mintzyuval
LQ Newbie
 
Registered: Dec 2008
Location: Tel-Aviv, Israel
Posts: 14

Original Poster
Rep: Reputation: 0
Thanks.

However, the new link describes the passing of arguments to module insterted from user-space via 'insmod'.
My need is for a way (functions) to get variables out of the bootargs for drivers which aren't modules but instead integral part of the kernel.

Mintz Yuval
 
Old 12-29-2008, 05:56 AM   #10
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 12,138

Rep: Reputation: 987Reputation: 987Reputation: 987Reputation: 987Reputation: 987Reputation: 987Reputation: 987Reputation: 987
Quote:
Originally Posted by mintzyuval View Post
My need is for a way (functions) to get variables out of the bootargs for drivers which aren't modules but instead integral part of the kernel.
Really ???.
And how do you propose to do that ?. Are you intending to continually patch the mainline ?. Modules sound like a potentially better solution.
Then you could use modprobe.conf (or its facimile depending on init) to pass your parms.

As for your initial question - "good question". Several layers seem to be involved (from the boot-loader onwards), and I'm not confident there is a "one-true" answer (from kernel space).
 
Old 01-01-2009, 05:46 AM   #11
mintzyuval
LQ Newbie
 
Registered: Dec 2008
Location: Tel-Aviv, Israel
Posts: 14

Original Poster
Rep: Reputation: 0
Thanks. I agree that modules in general will be more useful for this purpose, but let's assume I want to add this kind of support to a driver which is essential for reaching userspace.
For example, let's assume I'd like my IDE driver to suppot this kind of configuration. If it'll be configured as a module I won't have a filesystem from which to load the modules (Since my root is on an ATA disk).
I would still like to be able to re-configure those values via the U-boot (even if rarely).

Of course, it might be that my assumption is wrong, and I can use the IDE as module?

Thanks,
Mintz Yuval
 
Old 03-31-2009, 08:59 AM   #12
Pete in Indy
LQ Newbie
 
Registered: Mar 2009
Location: Indiana, USA
Distribution: Linux 2.6.28
Posts: 2

Rep: Reputation: 0
An answer to your question

Mintzyuval,

It has been three months, but I thought it a nice coincidence that this past week I needed to do exactly what you were trying to do and I wanted to post an answer in case it could benefit you or anyone else that hits this thread.

details:
kernel: 2.6.28-rc8, target to OMAP35xx
boot: xloader and u-boot from NAND FLASH
scenario:
1. need to access hardware registers for the MMC interface to the SD card (my equivalent of your IDE interface in how your using it in your system)
2. cannot insmod the SD card on the MMC because I'm booting from NAND that finds the rootFS on the SD card via MMC core - I need the module_param values set to non-default values BEFORE the rootFS brings up the Linux prompt.

solution:
1. cancel autoboot
2. modify bootargs similar to the last var that is set in this example:
setenv bootargs display=\${display} console=\${consoledev},\${baudrate} root=/dev/mmcblk0p1 rw rootdelay=1 omap_hsmmc.mmc_debug_freq=48000000

in my case, I set a few more var for my system and then do a "saveenv" as always required, then "reset".

"omap_hsmmc" is the name of the built-in driver module that I cannot insmod because I need it for booting fully to the linux prompt.
"mmc_debug_freq" is the global var I've defined in the module in which I've used:
module_param(mmc_debug_freq, int, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP);

so, your bootargs var simply needs to be appended with something like:
<your_mod_name>.<your_mod_parameter_var_name>=<an_appropriate_value>

CAUTION: use printenv to verify that your bootargs isn't truncated after you append it due to a limitation in the var length supported by U-boot.

Good luck,
Peter
 
Old 04-02-2009, 10:36 AM   #13
mintzyuval
LQ Newbie
 
Registered: Dec 2008
Location: Tel-Aviv, Israel
Posts: 14

Original Poster
Rep: Reputation: 0
Nice

Hey,

first - thanks. It's uncommon to recieve an answer after such a long period of time.

I've got several questions though -

1. Do every module_param I declare accessed via bootargs? in other words, can the bootargs can values to all the 'module_params', or some parameters are required in the decleration of the 'module_params'?
2. On which phase during the kernel's arise are the bootargs parsed and set?

Thanks,
Mintz Yuval
 
Old 04-03-2009, 06:59 AM   #14
Pete in Indy
LQ Newbie
 
Registered: Mar 2009
Location: Indiana, USA
Distribution: Linux 2.6.28
Posts: 2

Rep: Reputation: 0
Quote:
Originally Posted by mintzyuval View Post
Hey,

first - thanks. It's uncommon to recieve an answer after such a long period of time.

I've got several questions though -

1. Do every module_param I declare accessed via bootargs? in other words, can the bootargs can values to all the 'module_params', or some parameters are required in the decleration of the 'module_params'?
2. On which phase during the kernel's arise are the bootargs parsed and set?

Thanks,
Mintz Yuval
1. The grammar of your question is throwing me off a bit.
I believe you are asking me if bootargs can be defined to contain a pre-assignment for any variable declared in your Kernel modules by means of the module_params command.
I believe the answer is yes, any variable defined in a kernel module using the module_params function should be configurable using this method.

The following exceptions apply:
1.1. the variable you wish to set is in a kernel module that you have not configured as a built-in module (i.e. you will later load that kernel module at the kernel prompt using insmod *.ko and assign the variables with the proper insmod switches)
1.2. the <module_name>.<param_name> defined along with bootargs must not exceed the line-length supported by U-boot

2. If you are using U-boot to boot the Kernel with root file system, then set bootargs in your non-volatile storage using U-boot.
For example, I'm booting from a pre-flashed NAND flash so my code actually looks like this:

setenv bootargs display=\${display} console=\${consoledev},\${baudrate} root=/dev/mmcblk0p1 rw rootdelay=1 omap_hsmmc.mmc_debug_freq=48000000

setenv nandbootargs setenv bootargs display=\${display} console=\${consoledev},\${baudrate} root=/dev/mmcblk0p1 rw rootdelay=1 omap_hsmmc.mmc_debug_freq=48000000


setenv nandboot run nandbootargs\;nand read \${loadaddr} \${uimage_addr} \${uimage_size}\;bootm \${loadaddr}

setenv bootcmd run nandboot

saveenv


You might have something similar, but instead of NAND flash, you would have some other non-volatile memory, i.e. a hard drive you are accessing via IDE memory controller device.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Iptables To Access LAN devices inside&Outside ActionTech DSL schenke Linux - Networking 5 01-02-2008 12:57 PM
¿IPC inside Kernel? (help) Ojp Programming 4 03-21-2006 02:35 PM
IPTABLES NAT Gateway, No Access from the inside? nweaver916 Linux - Networking 2 08-27-2004 03:46 PM
Apache 2 Server - Can't access it via ip address from inside LAN Robstro Linux - Networking 1 06-30-2004 01:50 PM
Kernel Inside Out unixbrain Linux - Newbie 6 09-23-2003 06:18 AM


All times are GMT -5. The time now is 06:58 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration