2 * (C) Copyright 2005-2007 Samsung Electronics
3 * Kyungmin Park <kyungmin.park@samsung.com>
5 * See file CREDITS for list of people who contributed to this
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
26 #if defined(CFG_ENV_IS_IN_ONENAND) /* Environment is in OneNAND */
29 #include <environment.h>
30 #include <linux/stddef.h>
33 #include <linux/mtd/compat.h>
34 #include <linux/mtd/mtd.h>
35 #include <linux/mtd/onenand.h>
37 extern struct mtd_info onenand_mtd;
38 extern struct onenand_chip onenand_chip;
40 /* References to names in env_common.c */
41 extern uchar default_environment[];
43 #define ONENAND_ENV_SIZE(mtd) (mtd.oobblock - ENV_HEADER_SIZE)
45 char *env_name_spec = "OneNAND";
47 #ifdef ENV_IS_EMBEDDED
48 extern uchar environment[];
49 env_t *env_ptr = (env_t *) (&environment[0]);
50 #else /* ! ENV_IS_EMBEDDED */
51 static unsigned char onenand_env[MAX_ONENAND_PAGESIZE];
52 env_t *env_ptr = (env_t *) onenand_env;
53 #endif /* ENV_IS_EMBEDDED */
55 uchar env_get_char_spec(int index)
57 DECLARE_GLOBAL_DATA_PTR;
59 return (*((uchar *) (gd->env_addr + index)));
62 void env_relocate_spec(void)
64 DECLARE_GLOBAL_DATA_PTR;
65 unsigned long env_addr;
69 env_addr = CFG_ENV_ADDR;
70 env_addr -= (unsigned long)onenand_chip.base;
72 /* Check OneNAND exist */
73 if (onenand_mtd.oobblock)
74 /* Ignore read fail */
75 onenand_read(&onenand_mtd, env_addr, onenand_mtd.oobblock,
76 &retlen, (u_char *) env_ptr);
78 onenand_mtd.oobblock = MAX_ONENAND_PAGESIZE;
80 if (crc32(0, env_ptr->data, ONENAND_ENV_SIZE(onenand_mtd)) !=
85 memcpy(env_ptr->data, default_environment,
86 ONENAND_ENV_SIZE(onenand_mtd));
88 crc32(0, env_ptr->data, ONENAND_ENV_SIZE(onenand_mtd));
91 gd->env_addr = (ulong) & env_ptr->data;
97 unsigned long env_addr = CFG_ENV_ADDR;
98 struct erase_info instr;
101 instr.len = CFG_ENV_SIZE;
102 instr.addr = env_addr;
103 instr.addr -= (unsigned long)onenand_chip.base;
104 if (onenand_erase(&onenand_mtd, &instr)) {
105 printf("OneNAND: erase failed at 0x%08x\n", env_addr);
111 crc32(0, env_ptr->data, onenand_mtd.oobblock - ENV_HEADER_SIZE);
113 env_addr -= (unsigned long)onenand_chip.base;
114 if (onenand_write(&onenand_mtd, env_addr, onenand_mtd.oobblock, &retlen,
115 (u_char *) env_ptr)) {
116 printf("OneNAND: write failed at 0x%08x\n", instr.addr);
125 DECLARE_GLOBAL_DATA_PTR;
128 gd->env_addr = (ulong) & default_environment[0];
134 #endif /* CFG_ENV_IS_IN_ONENAND */