tool for editing builtin command line
Amos Waterland
apw at us.ibm.com
Fri Aug 4 08:22:25 EST 2006
The following is a tool for reading and editing the builtin command line
arguments in Linux zImage files and other bootable files that follow the
same format. It is useful in a cluster context in which one is booting
the same kernel on many machines with the only difference being their
network autoconfiguration values. Inspired by a script that Michal
Ostrowski posted earlier.
To see the existing arguments in a bootable image:
$ ./builtin-cmdline zImage
console=ttyS0,19200
To put new arguments in the image:
$ ./builtin-cmdline zImage "ro root=/dev/nfs nfsroot=192.168.0.3:/nfsroot \
ip=192.168.0.4::192.168.0.2:255.255.255.0:cluster001:eth0:off"
Signed-off-by: Amos Waterland <apw at us.ibm.com>
---
#!/bin/bash
#
# Copyright (C) 2006 Amos Waterland <apw at us.ibm.com>, IBM Corp.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
function help()
{
local name=$1;
local version=$2;
echo -e "\`$name' manipulates builtin command line arguments\n" \
"\n" \
"Usage: $name FILE [ARGS]\n" \
" -?, --help Show this help statement.\n" \
" --version Show version statement.\n" \
"\n" \
"Examples: $name zImage\n" \
" $name zImage 'console=ttyS0'";
}
function work()
{
local file=$1;
local args=$2;
local off; local siz; local out;
off=$(objdump -h $file |
gawk -- '{if($2=="__builtin_cmdline") {print strtonum("0x"$6);}}';)
if [ -z $off ]; then
echo "error: cannot find command line section in: $file"; return 1;
fi
siz=$(objdump -h $file |
gawk -- '{if($2=="__builtin_cmdline") {print strtonum("0x"$3);}}';)
if [ -z $siz ]; then return 1; fi
if [ -z "$args" ]; then
out=$(dd bs=1 if=$file skip=$off count=$siz 2>/dev/null);
if [ $? -ne 0 ]; then return 1; fi
echo $out;
else
dd if=/dev/zero of=$file bs=1 \
seek=$off conv=notrunc count=$siz 2>/dev/null
if [ $? -ne 0 ]; then return 1; fi
echo -n "$args" | dd \
of=$file bs=1 seek=$off conv=notrunc count=$siz 2>/dev/null
if [ $? -ne 0 ]; then return 1; fi
fi
return 0;
}
function main()
{
local args;
local file;
local name=builtin-cmdline;
local version=0.1.0;
while [ $# -gt 0 ]; do
case $1 in
-\? | --help)
help $name $version; return 1;
;;
--version)
echo "$name $version"; return 1;
;;
*)
if [ -z "$file" ]; then
file="$1"; shift;
elif [ -z "$args" ]; then
args="$1"; shift;
else
help $name $version; return 1;
fi
;;
esac
done
[ -z "$file" ] && {
help $name $version; return 1;
}
work "$file" "$args" || {
echo "bailing out because of errors"; return 1;
}
return 0;
}
main "$@";
exit $?;
More information about the Linuxppc-dev
mailing list