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

Alessandro Rubini rubini-list at gnudd.com
Fri Jul 4 16:51:12 CEST 2008


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





More information about the U-Boot mailing list