NSLU2-Linux
view · edit · print · history

How to change the kernel command line used by Debian / NSLU2

The kernel command line used by a Debian/NSLU2 system is passed to the kernel by the second-stage boot loader, APEX. Two utilities for changing the kernel command line stored in the APEX configuration environment are described on this page. Apart from these two utilities, the command line can also be changed by rebuilding APEX. This option is not described here. Please see CompileApex for information on compiling APEX.


Using apex-env on Debian/NSLU2 (etch)

The Debian apex-nslu2 package includes a utility apex-env which can be used to change the APEX configuration environment in which the kernel command line is stored. However, the Debian etch installer ships with a zero padded copy of the MTD block that contains APEX, but apex-env will not work unless the MTD block is padded with 0xffs. [Update: 9th November 2008, with daily image of Debian apex-env works fine without changing anything in the mtdblock2 partition ]

You can try to regenerate a copy of a 0xff padded /dev/mtdblock2 yourself, and then edit the APEX configuration environment using apex-env, but to make life easier for you, I have created a copy of a 0xff padded APEX MTD block. Replacing the Debian etch APEX with the 0xff padded copy will allow you to use apex-env. Martin Michlmayr is kindly hosting the copy of the MTD block (etch-modified-mtdblock2.bin) on his web site. It contains the following configuration in the APEX environment:

 $ sudo apex-env printenv
 bootaddr *= 0x00008000
 cmdline = console=ttyS0,115200 rtc-x1205.probe=0,0x6f noirqdebug rootdelay=10
 cmdline-alt *= console=ttyS0,115200 rtc-x1205.probe=0,0x6f noirqdebug
 fis-drv *= nor:0x7e0000+4k
 kernelsrc *= fis://kernel
 kernelsrc-alt *= fis://kernel
 ramdiskaddr *= 0x01000000
 ramdisksrc *= fis://ramdisk
 ramdisksrc-alt *= fis://ramdisk
 startup *= copy -s $kernelsrc $bootaddr; copy -s $ramdisksrc
 $ramdiskaddr; wait 10 Type ^C key to cancel autoboot.; boot

Note The APEX configuration in this file has the rootdelay parameter set to 10 seconds which is required if your root partition is an LVM logical volume or is contained on a RAID system (add reference to appropriate Wiki page). you use this file, you'll be able to use apex-env to set the rootdelay parameter to anything you want (see below).

To replace the Debian etch APEX copy, download etch-modified-mtdblock2.bin, and copy it to your NSLU2. You may want to make a backup of you current flash at this stage (see the NSLU2/Debian FAQ). Then do

 $ su -c 'cat etch-modified-mtdblock2.bin > /dev/mtdblock2'

to overwrite the existing copy of APEX in the NSLU2 flash.

Check that your APEX configuration matches the one listed above by doing

 $ sudo apex-env printenv

If it does, you should be able to change the kernel command line stored in the APEX configuration environment by by doing

 $ sudo apex-env setenv cmdline 'console=ttyS0,115200 rtc-x1205.probe=0,0x6f noirqdebug'

You can add any additional kernel options you want to set, e.g. 'rootdelay=10' to the end of the kernel command line.

See 'apex-env --help' or 'man apex-env' for more information.


Using apexctl (written by Phil Endecott)

Phil Endecott wrote a utility (apexctl) which allows one to edit the APEX configuration environment. His program does not require that the APEX MTD block be padded with 0xffs. This program reads and writes the APEX environment variables from Linux via the /dev/mtd interface to the flash. It should be possible to make safe one-off changes to the kernel command line etc. Below are examples of how to use the program.

 # apexctl
 Usage:
 apexctl [options] printenv
 apexctl [options] getenv variable
 (exit status 2 if not found)
 apexctl [options] setenv variable value
 apexctl [options] init
 Options:
 -d device specify /dev/mtd* device containing environment
 -o offset specify offset into device of start of environment
 (in decimal; prefix with 0x for hex)
 # apexctl -d /dev/mtdblock2 -o 0x1c000 printenv cmdline = console=ttyS0,115200 rtc-x1205.probe=0,0x6f \ 
noirqdebug root=/dev/nfs ip=any nfsroot=/nfsroot/%s \
startup = copy -s nor:0x1a0000+0x150000 0x00008000; wait 20 Type ^C key to cancel autoboot.; boot
 # /tmp/apexctl -d /dev/mtdblock2 -o 0x1c000 getenv cmdline console=ttyS0,115200 rtc-x1205.probe=0,0x6f \ 
noirqdebug root=/dev/nfs ip=any nfsroot=/nfsroot/%s
 # /tmp/apexctl -d /dev/mtdblock2 -o 0x1c000 setenv foo blah
 # /tmp/apexctl -d /dev/mtdblock2 -o 0x1c000 printenv cmdline = console=ttyS0,115200 rtc-x1205.probe=0,0x6f \ 
noirqdebug root=/dev/nfs ip=any nfsroot=/nfsroot/%s \
startup = copy -s nor:0x1a0000+0x150000 0x00008000; wait 20 Type ^C key to cancel autoboot.; boot foo = blah

The source code is here http://svn.chezphil.org/utils/trunk/apexctl.cc. It relies on some library utility stuff from http://svn.chezphil.org/libpbe/trunk/.

If you would like to try this but don't have the necessary tools to compile it, let me know and I can send a binary; it's about 33k.

You may have noticed from the example output above that I have been experimenting with an NFS root filesystem. This is a bit tricky if you don't have an initramfs. I got this working eventually; let me know if you're interested.

view · edit · print · history · Last edited by john.
Based on work by Cedric Boutillier, dumfrac, and Phil Endecott.
Originally by Phil Endecott.
Page last modified on November 09, 2008, at 07:55 PM