* [U-Boot-Users] Reading memory into environment variable
@ 2008-07-04 10:03 mcj00_rubbish at f-m.fm
2008-07-04 14:36 ` Detlev Zundel
0 siblings, 1 reply; 5+ messages in thread
From: mcj00_rubbish at f-m.fm @ 2008-07-04 10:03 UTC (permalink / raw)
To: u-boot
Hi,
I wish to read the kernel command line parameters in from a disk file
located e.g. on a FAT file system. My current idea is to implement it
like this:
1. Read disk file into RAM
2. Implement custom "mem2env" command to read memory into environment
variable, with destination variable as ${bootargs}
As far as I can see, I am not reinventing any wheels by doing this, but
does anyone know a better way?
Thanks & regards,
Martin
^ permalink raw reply [flat|nested] 5+ messages in thread
* [U-Boot-Users] Reading memory into environment variable
2008-07-04 10:03 [U-Boot-Users] Reading memory into environment variable mcj00_rubbish at f-m.fm
@ 2008-07-04 14:36 ` Detlev Zundel
2008-07-04 14:51 ` Alessandro Rubini
0 siblings, 1 reply; 5+ messages in thread
From: Detlev Zundel @ 2008-07-04 14:36 UTC (permalink / raw)
To: u-boot
Hi Martin,
> I wish to read the kernel command line parameters in from a disk file
> located e.g. on a FAT file system. My current idea is to implement it
> like this:
>
> 1. Read disk file into RAM
> 2. Implement custom "mem2env" command to read memory into environment
> variable, with destination variable as ${bootargs}
>
> As far as I can see, I am not reinventing any wheels by doing this, but
> does anyone know a better way?
I've seen the dbox guys doing something similar, although IIRC that
solution wasn't quite generic and was hacked into board specific code.
Thinking about it some more, if you can use mkimage somewhere in
userspace, you could create a script file, load that to ram and execute
it. This is very generic and not limited to setting environment
variables.
Thinking about that some more, maybe we could teach "autoscr" also to
run commands from a memory address without it being wrapped with
mkimage. This is also very generic but prone to errors...
Cheers
Detlev
--
0x2B | ~0x2B
--
DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-40 Fax: (+49)-8142-66989-80 Email: dzu at denx.de
^ permalink raw reply [flat|nested] 5+ messages in thread
* [U-Boot-Users] Reading memory into environment variable
2008-07-04 14:36 ` Detlev Zundel
@ 2008-07-04 14:51 ` Alessandro Rubini
2008-07-04 15:39 ` mcj00_rubbish at f-m.fm
0 siblings, 1 reply; 5+ messages in thread
From: Alessandro Rubini @ 2008-07-04 14:51 UTC (permalink / raw)
To: u-boot
>> 1. Read disk file into RAM
>> 2. Implement custom "mem2env" command to read memory into environment
>> variable, with destination variable as ${bootargs}
I've done the same (on u-boot-1.2.0) to read an upgrade script from a
network file or usb pen. I called the command "setenvram" (bad choice,
Wolfgang would refuse it). I'm sure later I found something similar
in mainline, but now I can't find it any more. I may have overlooked
another command.
Although it's not ready for prime time, I paste it here.
If useful I can make a proper patch against current git.
/* set environment variable from ram -- ARub */
int do_setenvram(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
{
unsigned long len, i;
char *addr;
if (argc != 4) {
printf ("Usage:\n%s\n", cmdtp->usage);
return 1;
}
addr = (char *)simple_strtol(argv[2], NULL, 16);
len = simple_strtol(argv[3], NULL, 16);
if (!addr || !len) {
printf ("Usage:\n%s\n", cmdtp->usage);
return 1;
}
addr[len] = '\0';
for (i=0; i<len; i++) {
/* turn newlines into semicolon */
if (addr[i]=='\n') addr[i] = ';';
/* ignore dos-style newlines */
if (addr[i]=='\r') addr[i] = ' ';
/* accept sh-comments and discard them */
if (addr[i]=='#') {
while (addr[i] && addr[i] != '\n')
addr[i++] = ' ';
i--;
}
}
setenv(argv[1], addr);
return 0;
}
U_BOOT_CMD(
setenvram, 4, 0, do_setenvram,
"setenvram - get environment variable from ram\n",
"name addr maxlen\n"
" - set environment variable 'name' from addr 'addr'\n"
);
^ permalink raw reply [flat|nested] 5+ messages in thread
* [U-Boot-Users] Reading memory into environment variable
2008-07-04 14:51 ` Alessandro Rubini
@ 2008-07-04 15:39 ` mcj00_rubbish at f-m.fm
2008-07-04 17:02 ` Alessandro Rubini
0 siblings, 1 reply; 5+ messages in thread
From: mcj00_rubbish at f-m.fm @ 2008-07-04 15:39 UTC (permalink / raw)
To: u-boot
Thanks for the help!
Using a proper U-Boot payload script would also be my preferred way, as
suggested by Detlev. However, this isn't my choice to make, it's an
accepted way of doing it already at my company :(
This patch looks about exactly like what I need. In fact I am using
U-Boot 1.2.0, so it's just perfect!
I am somewhat new to U-Boot development. What further work would be
required to bring this up to mainline U-Boot standard?
Thanks & regards,
Martin
On Fri, 4 Jul 2008 16:51:12 +0200, "Alessandro Rubini"
<rubini-list@gnudd.com> said:
>
> >> 1. Read disk file into RAM
> >> 2. Implement custom "mem2env" command to read memory into environment
> >> variable, with destination variable as ${bootargs}
>
> I've done the same (on u-boot-1.2.0) to read an upgrade script from a
> network file or usb pen. I called the command "setenvram" (bad choice,
> Wolfgang would refuse it). I'm sure later I found something similar
> in mainline, but now I can't find it any more. I may have overlooked
> another command.
>
> Although it's not ready for prime time, I paste it here.
> If useful I can make a proper patch against current git.
>
>
> /* set environment variable from ram -- ARub */
> int do_setenvram(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
> {
> unsigned long len, i;
> char *addr;
>
> if (argc != 4) {
> printf ("Usage:\n%s\n", cmdtp->usage);
> return 1;
> }
> addr = (char *)simple_strtol(argv[2], NULL, 16);
> len = simple_strtol(argv[3], NULL, 16);
> if (!addr || !len) {
> printf ("Usage:\n%s\n", cmdtp->usage);
> return 1;
> }
> addr[len] = '\0';
> for (i=0; i<len; i++) {
> /* turn newlines into semicolon */
> if (addr[i]=='\n') addr[i] = ';';
> /* ignore dos-style newlines */
> if (addr[i]=='\r') addr[i] = ' ';
> /* accept sh-comments and discard them */
> if (addr[i]=='#') {
> while (addr[i] && addr[i] != '\n')
> addr[i++] = ' ';
> i--;
> }
> }
> setenv(argv[1], addr);
> return 0;
> }
>
> U_BOOT_CMD(
> setenvram, 4, 0, do_setenvram,
> "setenvram - get environment variable from ram\n",
> "name addr maxlen\n"
> " - set environment variable 'name' from addr 'addr'\n"
> );
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* [U-Boot-Users] Reading memory into environment variable
2008-07-04 15:39 ` mcj00_rubbish at f-m.fm
@ 2008-07-04 17:02 ` Alessandro Rubini
0 siblings, 0 replies; 5+ messages in thread
From: Alessandro Rubini @ 2008-07-04 17:02 UTC (permalink / raw)
To: u-boot
> I am somewhat new to U-Boot development. What further work would be
> required to bring this up to mainline U-Boot standard?
Well, someone must cook it up as a patch, with proper indentation,
based on current tree, add some documentation, and hope it's
considered useful.
I might try next week, I have to study a little git first
/alessandro
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2008-07-04 17:02 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-07-04 10:03 [U-Boot-Users] Reading memory into environment variable mcj00_rubbish at f-m.fm
2008-07-04 14:36 ` Detlev Zundel
2008-07-04 14:51 ` Alessandro Rubini
2008-07-04 15:39 ` mcj00_rubbish at f-m.fm
2008-07-04 17:02 ` Alessandro Rubini
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox