From: Amos Waterland <apw@us.ibm.com>
To: linuxppc-dev@ozlabs.org
Subject: tool for editing builtin command line
Date: Thu, 3 Aug 2006 18:22:25 -0400 [thread overview]
Message-ID: <20060803222225.GA23341@kvasir.watson.ibm.com> (raw)
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@us.ibm.com>
---
#!/bin/bash
#
# Copyright (C) 2006 Amos Waterland <apw@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 $?;
reply other threads:[~2006-08-03 22:22 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20060803222225.GA23341@kvasir.watson.ibm.com \
--to=apw@us.ibm.com \
--cc=linuxppc-dev@ozlabs.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).