source: SVN/rincon/u-boot/common/env_onenand.c @ 55

Last change on this file since 55 was 55, checked in by Tim Harvey, 2 years ago

rincon: added latest u-boot source

restored form server backup

Signed-off-by: Tim Harvey <tharvey@…>

File size: 3.1 KB
Line 
1/*
2 * (C) Copyright 2005-2007 Samsung Electronics
3 * Kyungmin Park <kyungmin.park@samsung.com>
4 *
5 * See file CREDITS for list of people who contributed to this
6 * project.
7 *
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.
12 *
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.
17 *
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,
21 * MA 02111-1307 USA
22 */
23
24#include <common.h>
25#include <command.h>
26#include <environment.h>
27#include <linux/stddef.h>
28#include <malloc.h>
29
30#include <linux/mtd/compat.h>
31#include <linux/mtd/mtd.h>
32#include <linux/mtd/onenand.h>
33
34extern struct mtd_info onenand_mtd;
35extern struct onenand_chip onenand_chip;
36
37/* References to names in env_common.c */
38extern uchar default_environment[];
39
40#define ONENAND_ENV_SIZE(mtd)   (mtd.writesize - ENV_HEADER_SIZE)
41
42char *env_name_spec = "OneNAND";
43
44#ifdef ENV_IS_EMBEDDED
45extern uchar environment[];
46env_t *env_ptr = (env_t *) (&environment[0]);
47#else /* ! ENV_IS_EMBEDDED */
48static unsigned char onenand_env[MAX_ONENAND_PAGESIZE];
49env_t *env_ptr = (env_t *) onenand_env;
50#endif /* ENV_IS_EMBEDDED */
51
52DECLARE_GLOBAL_DATA_PTR;
53
54uchar env_get_char_spec(int index)
55{
56        return (*((uchar *) (gd->env_addr + index)));
57}
58
59void env_relocate_spec(void)
60{
61        unsigned long env_addr;
62        int use_default = 0;
63        size_t retlen;
64
65        env_addr = CONFIG_ENV_ADDR;
66
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);
72        else
73                onenand_mtd.writesize = MAX_ONENAND_PAGESIZE;
74
75        if (crc32(0, env_ptr->data, ONENAND_ENV_SIZE(onenand_mtd)) !=
76            env_ptr->crc)
77                use_default = 1;
78
79        if (use_default) {
80                memcpy(env_ptr->data, default_environment,
81                       ONENAND_ENV_SIZE(onenand_mtd));
82                env_ptr->crc =
83                    crc32(0, env_ptr->data, ONENAND_ENV_SIZE(onenand_mtd));
84        }
85
86        gd->env_addr = (ulong) & env_ptr->data;
87        gd->env_valid = 1;
88}
89
90int saveenv(void)
91{
92        unsigned long env_addr = CONFIG_ENV_ADDR;
93        struct erase_info instr = {
94                .callback       = NULL,
95        };
96        size_t retlen;
97
98        instr.len = CONFIG_ENV_SIZE;
99        instr.addr = env_addr;
100        if (onenand_erase(&onenand_mtd, &instr)) {
101                printf("OneNAND: erase failed at 0x%08lx\n", env_addr);
102                return 1;
103        }
104
105        /* update crc */
106        env_ptr->crc =
107            crc32(0, env_ptr->data, ONENAND_ENV_SIZE(onenand_mtd));
108
109        if (onenand_write(&onenand_mtd, env_addr, onenand_mtd.writesize, &retlen,
110             (u_char *) env_ptr)) {
111                printf("OneNAND: write failed at 0x%08x\n", instr.addr);
112                return 2;
113        }
114
115        return 0;
116}
117
118int env_init(void)
119{
120        /* use default */
121        gd->env_addr = (ulong) & default_environment[0];
122        gd->env_valid = 1;
123
124        return 0;
125}
Note: See TracBrowser for help on using the repository browser.