Re: [U-Boot-Users] Reading memory into environment variable

2008-07-04 Thread Detlev Zundel
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: [EMAIL PROTECTED]

-
Sponsored by: SourceForge.net Community Choice Awards: VOTE NOW!
Studies have shown that voting for your favorite open source project,
along with a healthy diet, reduces your potential for chronic lameness
and boredom. Vote Now at http://www.sourceforge.net/community/cca08
___
U-Boot-Users mailing list
U-Boot-Users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/u-boot-users


Re: [U-Boot-Users] Reading memory into environment variable

2008-07-04 Thread Alessandro Rubini

 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; ilen; 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
);  


-
Sponsored by: SourceForge.net Community Choice Awards: VOTE NOW!
Studies have shown that voting for your favorite open source project,
along with a healthy diet, reduces your potential for chronic lameness
and boredom. Vote Now at http://www.sourceforge.net/community/cca08
___
U-Boot-Users mailing list
U-Boot-Users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/u-boot-users


Re: [U-Boot-Users] Reading memory into environment variable

2008-07-04 Thread mcj00_rubbish
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
[EMAIL PROTECTED] 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; ilen; 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
 );  
 

-
Sponsored by: SourceForge.net Community Choice Awards: VOTE NOW!
Studies have shown that voting for your favorite open source project,
along with a healthy diet, reduces your potential for chronic lameness
and boredom. Vote Now at http://www.sourceforge.net/community/cca08
___
U-Boot-Users mailing list
U-Boot-Users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/u-boot-users