This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

How can I access bootargs from inside the kernel?

Hi All,

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.32-52) 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  when?)

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

with regards
-Kaushal

  • Hello Kaushal,

    Could you please share on what board are you working? and with what OS (Android/Ubuntu based, or some else)?

    Anyway, bootargs are passed to the kernel by the linux bootloader (u-boot), you can see/access them by stopping the boot process at u-boot & then use the commands printenv, setenv, savenv.

    Useful articles on the topic can be found on omappedia (for omap devices bootloaders) & denx website:

    http://omappedia.org/wiki/Bootloader_Project

    http://www.denx.de/wiki/view/DULG/LinuxKernelArgs  and http://www.denx.de/wiki/view/DULG/LinuxBootArgs

    Best Regards,

    Yordan

  • Hi Yordan,

    I'm working on omap4430 based custom board with 4.2.5 JB OS.

    I want to know how can we read the bootargs from inside kernel?
    is there any kernel driver who is reading these value?

    with reagrds
    -Kaushal

  • Hello,

    In android 4AJ2.5 the bootargs are actually set within the kernel. See blaze_defconfig, for example. You have the following two lines: 

    CONFIG_CMDLINE="console=ttyO2,115200n8 mem=1G vmalloc=768M androidboot.console=ttyO2 omap_wdt.timer_margin=30"
    CONFIG_CMDLINE_EXTEND=y

    the CONFIG_CMDLINE sets the bootargs, which the kernel uses (you can verify that with cat /proc/cmdline), and CONFIG_CMDLINE_EXTENG=y allows the addition of other arguments, when insmoding a .ko file, for example.

    Best Regards,

    Yordan

  • Not sure if understand the question. My 2 cents. This is more of a linux question than a OMAP 4 question.

    The kernel bootargs string is not usually accessed as a whole from within the kernel. The bootargs string is accessed by individual option.

    For global variables, a bootarg option of "your_arg=a_value" is handled with this sort of code:

    static int __init your_handler(char *str)
    {
      ...handle str="a_value"
    }

    your_board_init()
    {
      ...
      __setup("your_arg=", your_handler);
      ...
    }

    For driver modules, a bootarg option of "your_driver.your_arg=1" is handled with this sort of code:

    static int your_arg = 0;
    module_param(your_arg, int, 0);
    MODULE_PARM_DESC(your_arg, "Your Arg, default=0");

    Both global and module options are used throughout the kernel.

    In userspace, I think "/proc/cmdline" contains the bootargs.

  • Hi Kaushal,

    Bootargs are used at starting of kernel boots.U can see how they are used in init/main.c .

    To access bootargs we used genrally two macros 

    1) early_param(ur_bootargs, function_handler)

    2) __setup(ur,bootargs,function_handler)

    early_param() executed before __setup() macro.

    If u want to use bootargs in ur own driver then it's better u can use __setup as describe by NORMAN WONG in this post.

    For further investigation u can go throgh this page..http://www.e-reading.bz/chapter.php/101551/103/Hallinan_-_Embedded_Linux_Primer__A_Practical,_Real-World_Approach.html.

    Regards

    Vikram

  • Hello Yordan,

    Thanks for that explanation.

    Is it possible to add additional arguments to bootargs during boot time via bootloader or other mechanisms ? 
    (Like if we are using GRUB as the bootloader on a PC then we can go and edit the bootargs. If we are using uboot we can change boot.scr to update the bootargs.)

    Or do I have to compile a new kernel ?

    I am using Android Jelly Bean 4.2.2 on an OMAP5 board.

    --Kiran 

  • Hi Kiran, 

    What do you mean by adding bootargs during boot time? I am not aware of a method to change the boot args on the fly, when bootloader or kernel are loading on the device.

    What I can propose is:

    1. Stop the boot process at u-boot.

    2. Use the command setenv to modify/add environment variable, then use saveenv to save the changes you've made.

    3. Continue with booting the kernel (issue the boot command in u-boot prompt).

    Best Regards,

    Yordan

  • Hi Yordan,

    Thanks for your quick reply. I like the method you proposed.

    I was thinking that TI is using some proprietary boot loader.  Are you saying that TI is using uboot itself ?
    How can I interrupt the bootloader ?
    I tried pressing some keys like Ctrl-C, Esc but it did not help.

    I am giving the logs that come during boot below.


    Thanks,
    Kiran

    Texas Instruments Inc Bootloader 1.1.0-ge3a6f493

    Build Info: Sep 11 2013 - 19:31:49
    OMAP reset reason PRM_RSTST = 0x0001
    PMIC reset reason SWOFF_STATUS = 0x00
    sram: boot device: EMMC
    kernel @ 80008000 (4898560)
    ramdisk @ 81000000 (184196)
    Device Serial Number: 2E6604F02AC20021
    booting kernel...
    Uncompressing Linux... done, booting the kernel.
    [ 0.000000] Booting Linux on physical CPU 0

    [ 0.000000] Initializing cgroup subsys cpu
    [ 0.000000] Linux version 3.4.48 (a0271468@dta0212502ub) (gcc version 4.6.x-google 20120106 (prerelease) (GCC) ) #1 SMP PREEMPT Wed Sep 11 19:37:01 CDT 2013
    [ 0.000000] CPU: ARMv7 Processor [412fc0f2] revision 2 (ARMv7), cr=10c5387d
    [ 0.000000] CPU: PIPT / VIPT nonaliasing data cache, PIPT instruction cache
    [ 0.000000] Machine: OMAP5 panda board

  • Hi Kiran,

    You should see a countdown from 3 down to 0 between u-boot & kernel.

    If not, then most likely bootdelay is set to 0 in your u-boot sources. You need to increase that time.

    I see you are working on OMAP5 uEVM: "Machine: OMAP5 panda board"


    Are you using Android or GLSDK on your board? Which release?

    Best Regards,

    Yordan

  • Hi,

    I am using Android, downloaded from the page given below.

    http://software-dl.ti.com/omap/omap5/omap5_public_sw/OMAP5432-EVM/5AJ_1_5_1_Release/index_FDS.html

    I am using the prebuilt images provided in the link given above.

    So do I have to recompile u-boot after changing the bootdelay ?

    --Kiran

  • Hi,

    Things are a bit different in omap5 Android releases (they use usbboot).

    You need to modify the sources in order to add bootdelay, and then recompile the bootloader.

    Sources can be downloaded following the release notes in: http://omapedia.org/wiki/Panda5AJ.1.5.1_Release_Notes

    Best Regards,

    Yordan

  • Thanks Yordan.

    Is usbboot derived from uboot ? Will setenv and savenv work in usbboot as well ?

    --Kiran

  • No, this is a different bootloader, see: http://omappedia.org/wiki/Omapboot#USBBOOT

    I'll have to additionally dig in the sources.

    Best Regards,
    Yordan

  • I was able to pass additional boot args to the kernel. In OMAP5 EVM, pressing a button while booting takes the system to fastboot mode. And then using the fastboot binary on the host machine we can pass additional bootargs to the kernel.

    --Kiran