2 * (C) Copyright 2006-2007 OpenMoko, Inc.
3 * Author: Harald Welte <laforge@openmoko.org>
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation; either version 2 of
8 * the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
24 #include <environment.h>
27 #include <asm/errno.h>
29 #if defined(CFG_ENV_OFFSET_OOB)
31 int do_dynenv(cmd_tbl_t
*cmdtp
, int flag
, int argc
, char *argv
[])
33 struct mtd_info
*mtd
= &nand_info
[0];
39 buf
= malloc(mtd
->oobsize
);
43 ret
= mtd
->read_oob(mtd
, 8, size
, (size_t *) &size
, (u_char
*) buf
);
44 if (!strcmp(cmd
, "get")) {
46 if (buf
[0] == 'E' && buf
[1] == 'N' &&
47 buf
[2] == 'V' && buf
[3] == '0')
48 printf("0x%08x\n", *((u_int32_t
*) &buf
[4]));
50 printf("No dynamic environment marker in OOB block 0\n");
52 } else if (!strcmp(cmd
, "set")) {
53 unsigned long addr
, dummy
;
63 if (arg_off_size(argc
-2, argv
+2, mtd
, &addr
, &dummy
, 1) < 0) {
64 printf("Offset or partition name expected\n");
71 memcpy(&tmp
, &addr
, 4);
72 for (i
= 0; i
!= 4; i
++)
73 if (tmp
[i
] & ~buf
[i
+4]) {
74 printf("ERROR: erase OOB block to "
75 "write this value\n");
79 memcpy(buf
+4, &addr
, 4);
81 printf("%02x %02x %02x %02x - %02x %02x %02x %02x\n",
82 buf
[0], buf
[1], buf
[2], buf
[3],
83 buf
[4], buf
[5], buf
[6], buf
[7]);
85 ret
= mtd
->write_oob(mtd
, 8, size
, (size_t *) &size
, (u_char
*) buf
);
87 CFG_ENV_OFFSET
= addr
;
95 printf("Usage:\n%s\n", cmdtp
->usage
);
101 U_BOOT_CMD(dynenv
, 3, 1, do_dynenv
,
102 "dynenv - dynamically placed (NAND) environment\n",
103 "dynenv set off - set enviromnent offset\n"
104 "dynenv get - get environment offset\n");
106 #endif /* CFG_ENV_OFFSET_OOB */