ECE497 Modifying Kernel Command Line Parameters

From eLinux.org
Revision as of 13:05, 28 April 2011 by Lesterwm (talk | contribs)
Jump to: navigation, search

The Linux kernel is booted with a series of parameters known as the kernel command line. On the BeagleBoard, the uBoot bootloader handles both the booting and the passing of parameters. A typical command line on the BeagleBoard might look something like this:

#console=ttyS2,115200n8 console=tty0 root=/dev/mmcblk0p2 rw rootwait

Modification of the kernel command line is necessary for things like:

Static MAC Addresses or

Using the TI Pico Projector

In order to edit the command line, we need to edit a few uBoot files.

Modifying Boot.scr

When uBoot finishes its initilization phase, it looks for a file called boot.scr This is a binary file which is read by uBoot before it loads uImage which allows us to modify environment variables such as 'bootargs' (the kernel command-line) before we boot.

Boot.cmd

Boot.cmd is the plain text, uncompiled version of boot.scr. A standard BeagleBoard boot.cmd might look like:

if fatload mmc 0 80200000 uImage
then
\techo ***** Kernel: /dev/mmcblk0p1/uImage *****
else
echo ***** Kernel: /dev/mtd3 *****
nand read 80200000 280000 400000
fi

echo ***** RootFS: /dev/mmcblk0p2 *****
setenv bootargs 'console=ttyS2,115200n8 console=tty0 ethaddr=01:2b:03:01:23:45 g_ether.host_addr=00:dc:c8:f7:75:05  g_ether.dev_addr=00:dd:dc:eb:6d:f1 root=/dev/mmcblk0p2 rw rootwait'

bootm 80200000 

The key part of this file is the line

setenv bootargs 'console=ttyS2,115200n8 console=tty0 ...'

This is the kernel command line, any additional parameters added on this line will be passed to the kernel when it is booted.

Compiling with mkimage

Once the boot.cmd file has been authored, we need to compile it to produce a boot.scr file. This is done with the mkimage program. On Ubuntu, this program is available through the package 'uboot-mkimage'. It should be similarly available for most distributions.

Once mkimage is installed, you'll want to run it on boot.cmd to create boot.scr:

mkimage -A arm -O linux -T script -C none -a 0 -e 0 -n 'Execute uImage' -d boot.cmd boot.scr

Replacing the old boot.scr

Once the new boot.scr file has been created, place it in the root directory of the BeagleBoard's SD card (the same directory as uImage).

Next time you boot, the kernel will be passed your newly added parameters!

If you have ssh access to your BeagleBoard, you can install your newly created boot.scr with the following command:

scp boot.scr root@beagleboard:/media/mmcblk0p1/

just be sure to replace 'beagleboard' with your BeagleBoard's hostname or IP address

User.scr

If the USER button is held while the BeagleBoard boots, uBoot will look for the file user.scr instead of boot.scr. This gives us the chance to boot the kernel with two different command lines (or even boot another kernel all together).

The process for modifying or creating a user.scr file is the same as boot.scr, just change the filename.

Makefile version

In order to simplify this overly complex process, we can use a Makefile like the one below:

# Makefile to create boot.scr and user.scr for uBoot 
#
# Author: Michael Lester

all: boot.scr user.scr

boot.scr: boot.cmd
	mkimage -A arm -O linux -T script -C none -a 0 -e 0 -n 'Execute uImage' -d boot.cmd boot.scr

user.scr: user.cmd
	mkimage -A arm -O linux -T script -C none -a 0 -e 0 -n 'Boot Ramdisk' -d user.cmd user.scr

install: boot.scr user.scr
	scp *.scr root@beagleboard:/media/mmcblk0p1/

So, in order to compile both boot.cmd and user.cmd into .scr files and install them on the BeagleBoard, just run:

make && make install