]> git.ipfire.org Git - people/ms/u-boot.git/blame - common/env_eeprom.c
moving files from yaffs2/direct/ to yaffs2/ and deleting all symlinks
[people/ms/u-boot.git] / common / env_eeprom.c
CommitLineData
0bc4a1ac
WD
1/*
2 * (C) Copyright 2000-2002
3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
4 *
5 * (C) Copyright 2001 Sysgo Real-Time Solutions, GmbH <www.elinos.com>
6 * Andreas Heppel <aheppel@sysgo.de>
7
8 * See file CREDITS for list of people who contributed to this
9 * project.
10 *
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License as
13 * published by the Free Software Foundation; either version 2 of
14 * the License, or (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
24 * MA 02111-1307 USA
25 */
26
27#include <common.h>
28
29#if defined(CFG_ENV_IS_IN_EEPROM) /* Environment is in EEPROM */
30
31#include <command.h>
32#include <environment.h>
0bc4a1ac 33#include <linux/stddef.h>
0bc4a1ac 34
d87080b7
WD
35DECLARE_GLOBAL_DATA_PTR;
36
0bc4a1ac
WD
37env_t *env_ptr = NULL;
38
39char * env_name_spec = "EEPROM";
40
0bc4a1ac
WD
41uchar env_get_char_spec (int index)
42{
43 uchar c;
44
45 eeprom_read (CFG_DEF_EEPROM_ADDR,
46 CFG_ENV_OFFSET+index+offsetof(env_t,data),
47 &c, 1);
48
49 return (c);
50}
51
52void env_relocate_spec (void)
53{
54 eeprom_read (CFG_DEF_EEPROM_ADDR,
55 CFG_ENV_OFFSET,
56 (uchar*)env_ptr,
57 CFG_ENV_SIZE);
58}
59
60int saveenv(void)
61{
62 return eeprom_write (CFG_DEF_EEPROM_ADDR,
63 CFG_ENV_OFFSET,
64 (uchar *)env_ptr,
65 CFG_ENV_SIZE);
66}
67
68/************************************************************************
69 * Initialize Environment use
70 *
71 * We are still running from ROM, so data use is limited
72 * Use a (moderately small) buffer on the stack
73 */
74int env_init(void)
75{
0bc4a1ac
WD
76 ulong crc, len, new;
77 unsigned off;
78 uchar buf[64];
79
80 eeprom_init (); /* prepare for EEPROM read/write */
81
82 /* read old CRC */
83 eeprom_read (CFG_DEF_EEPROM_ADDR,
84 CFG_ENV_OFFSET+offsetof(env_t,crc),
85 (uchar *)&crc, sizeof(ulong));
86
87 new = 0;
88 len = ENV_SIZE;
89 off = offsetof(env_t,data);
90 while (len > 0) {
91 int n = (len > sizeof(buf)) ? sizeof(buf) : len;
92
93 eeprom_read (CFG_DEF_EEPROM_ADDR, CFG_ENV_OFFSET+off, buf, n);
94 new = crc32 (new, buf, n);
95 len -= n;
96 off += n;
97 }
98
99 if (crc == new) {
100 gd->env_addr = offsetof(env_t,data);
101 gd->env_valid = 1;
102 } else {
103 gd->env_addr = 0;
104 gd->env_valid = 0;
105 }
106
107 return (0);
108}
109
110#endif /* CFG_ENV_IS_IN_EEPROM */