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 #include <environment.h>
27 #include <linux/stddef.h>
30 #include <linux/mtd/compat.h>
31 #include <linux/mtd/mtd.h>
32 #include <linux/mtd/onenand.h>
34 extern struct mtd_info onenand_mtd;
35 extern struct onenand_chip onenand_chip;
37 /* References to names in env_common.c */
38 extern uchar default_environment[];
40 #define ONENAND_ENV_SIZE(mtd) (mtd.writesize - ENV_HEADER_SIZE)
42 char *env_name_spec = "OneNAND";
44 #ifdef ENV_IS_EMBEDDED
45 extern uchar environment[];
46 env_t *env_ptr = (env_t *) (&environment[0]);
47 #else /* ! ENV_IS_EMBEDDED */
48 static unsigned char onenand_env[MAX_ONENAND_PAGESIZE];
49 env_t *env_ptr = (env_t *) onenand_env;
50 #endif /* ENV_IS_EMBEDDED */
52 DECLARE_GLOBAL_DATA_PTR;
54 uchar env_get_char_spec(int index)
56 return (*((uchar *) (gd->env_addr + index)));
59 void env_relocate_spec(void)
61 unsigned long env_addr;
65 env_addr = CONFIG_ENV_ADDR;
67 /* Check OneNAND exist */
68 if (onenand_mtd.writesize)
69 /* Ignore read fail */
70 onenand_read(&onenand_mtd, env_addr, onenand_mtd.writesize,
71 &retlen, (u_char *) env_ptr);
73 onenand_mtd.writesize = MAX_ONENAND_PAGESIZE;
75 if (crc32(0, env_ptr->data, ONENAND_ENV_SIZE(onenand_mtd)) !=
80 memcpy(env_ptr->data, default_environment,
81 ONENAND_ENV_SIZE(onenand_mtd));
83 crc32(0, env_ptr->data, ONENAND_ENV_SIZE(onenand_mtd));
86 gd->env_addr = (ulong) & env_ptr->data;
92 unsigned long env_addr = CONFIG_ENV_ADDR;
93 struct erase_info instr = {
98 instr.len = CONFIG_ENV_SIZE;
99 instr.addr = env_addr;
100 instr.mtd = &onenand_mtd;
101 if (onenand_erase(&onenand_mtd, &instr)) {
102 printf("OneNAND: erase failed at 0x%08lx\n", env_addr);
108 crc32(0, env_ptr->data, ONENAND_ENV_SIZE(onenand_mtd));
110 if (onenand_write(&onenand_mtd, env_addr, onenand_mtd.writesize, &retlen,
111 (u_char *) env_ptr)) {
112 printf("OneNAND: write failed at 0x%08x\n", instr.addr);
122 gd->env_addr = (ulong) & default_environment[0];