Re: [ANNOUNCE][CFT] kexec for v2.5.48 && kexec-tools-1.7 -- Success

Andy Pfiffer (andyp@osdl.org)
19 Nov 2002 11:29:50 -0800


--=-LqGcdCykaRKqWBrfgb2w
Content-Type: text/plain
Content-Transfer-Encoding: 7bit

On Tue, 2002-11-19 at 09:34, Eric W. Biederman wrote:
> Andy Pfiffer <andyp@osdl.org> writes:
>
> > On Tue, 2002-11-19 at 02:25, Eric W. Biederman wrote:
> > > > Complete kernel boot-up log attached below. I'm going to try to find my
> > > > other 576MB of RAM with the right command-line magic... ;^)
> > >
> > > Or you can write a routine to gather that information dynamically and send
> > > me a patch for /sbin/kexec. Though it may take another proc file to do
> > > that one properly.
> > >
> > > Eric

Hmmm...I seem to be having some trouble setting "mem=" (system hangs).
Maybe multiple "mem=NNNK@0xXXXXXXXX" options won't work.

While I try to figure out what's going on, here's a program ("kargs")
that composes a kernel command line from the contents of
"/proc/cmndline" and "/proc/iomem". It doesn't do as much error
checking as it should...

Usage (sh quoting): kexec --force "--command-line=`kargs`" bzImage

Andy

--=-LqGcdCykaRKqWBrfgb2w
Content-Disposition: attachment; filename=kargs.c
Content-Transfer-Encoding: quoted-printable
Content-Type: text/x-c; name=kargs.c; charset=ISO-8859-1

/*
* andyp@osdl.org
* Tue Nov 19 09:26:22 PST 2002
*
* Compose a kernel command line on stdout from the contents
* of /proc/iomem and /proc/cmndline.
*/

#include <stdio.h>
#include <stdlib.h>
#include <regex.h>

struct memregion {
unsigned long first;
unsigned long last;
struct memregion *next;
};

int memopt(char *iomem, char *out, int outlen)
{
FILE *f;
struct memregion *list, *tmp;
char *pattern;
regex_t preg;
int cc, kb;
char line[256];

if ((f =3D fopen(iomem, "r")) =3D=3D NULL)
return -1;

pattern =3D "^[0-9a-fA-F].*-[0-9a-fA-F].* : System RAM";
if (regcomp(&preg, pattern, 0)) {
(void) fclose(f);
return -1;
}

list =3D (struct memregion *) 0;
while (fgets(line, sizeof(line), f) !=3D NULL) {
if (regexec(&preg, line, 0, 0, 0) =3D=3D REG_NOMATCH)
continue;
tmp =3D (struct memregion *) malloc(sizeof(struct memregion));
if (tmp =3D=3D (struct memregion *) 0)
goto out;
cc =3D sscanf(line, "%x-%x", &tmp->first, &tmp->last);
if (cc !=3D 2) {
free(tmp);
goto out;
}
tmp->next =3D list;
list =3D tmp;
}

out[0] =3D 0;
tmp =3D list;
while (tmp) {
strcat(out, "mem=3D");
kb =3D (tmp->last - tmp->first + 1) >> 10;
sprintf(line, "%dK@0x%08x", kb, tmp->first);
strcat(out, line);
if (tmp->next)
strcat(out, " ");
tmp =3D tmp->next;
}

out:
while (list) {
tmp =3D list->next;
free(list);
list =3D tmp;
}
regfree(&preg);
(void) fclose(f);

return 0;
}

static int lastcmd(char *cmndline, char *out, int outlen)
{
FILE *f;
char line[256];

if ((f =3D fopen(cmndline, "r")) =3D=3D NULL)
return -1;
memset(out, 0, outlen);
if (fgets(line, sizeof(line), f) !=3D NULL)
strncpy(out, line, strlen(line) - 1);
fclose(f);
return 0;
}

int main(int argc, char **argv)
{
int cc;
char *name;
char memline[256];
char curline[256];

name =3D "/proc/iomem";
cc =3D memopt(name, memline, sizeof(memline));
if (cc < 0) {
perror(name);
exit(1);
}

name =3D "/proc/cmdline";
cc =3D lastcmd(name, curline, sizeof(curline));
if (cc < 0) {
perror(name);
exit(1);
}

printf("%s %s\n", curline, memline);
exit(0);
}

--=-LqGcdCykaRKqWBrfgb2w--

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/