]>
git.ipfire.org Git - people/ms/u-boot.git/blob - common/env_dataflash.c
2 * LowLevel function for DataFlash environment support
3 * Author : Gilles Gastaldi (Atmel)
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,
22 #include <environment.h>
23 #include <linux/stddef.h>
24 #include <dataflash.h>
28 DECLARE_GLOBAL_DATA_PTR
;
32 char *env_name_spec
= "dataflash";
34 uchar
env_get_char_spec(int index
)
38 read_dataflash(CONFIG_ENV_ADDR
+ index
+ offsetof(env_t
, data
),
43 void env_relocate_spec(void)
45 char buf
[CONFIG_ENV_SIZE
];
47 read_dataflash(CONFIG_ENV_ADDR
, CONFIG_ENV_SIZE
, buf
);
52 #ifdef CONFIG_ENV_OFFSET_REDUND
53 #error No support for redundant environment on dataflash yet!
62 res
= (char *)&env_new
.data
;
63 len
= hexport_r(&env_htab
, '\0', 0, &res
, ENV_SIZE
, 0, NULL
);
65 error("Cannot export environment: errno = %d\n", errno
);
68 env_new
.crc
= crc32(0, env_new
.data
, ENV_SIZE
);
70 return write_dataflash(CONFIG_ENV_ADDR
,
71 (unsigned long)&env_new
,
76 * Initialize environment use
78 * We are still running from ROM, so data use is limited.
79 * Use a (moderately small) buffer on the stack
83 ulong crc
, len
= ENV_SIZE
, new = 0;
90 AT91F_DataflashInit(); /* prepare for DATAFLASH read/write */
93 read_dataflash(CONFIG_ENV_ADDR
+ offsetof(env_t
, crc
),
94 sizeof(ulong
), (char *)&crc
);
96 off
= offsetof(env_t
, data
);
98 int n
= (len
> sizeof(buf
)) ? sizeof(buf
) : len
;
100 read_dataflash(CONFIG_ENV_ADDR
+ off
, n
, (char *)buf
);
102 new = crc32(new, buf
, n
);
108 gd
->env_addr
= offsetof(env_t
, data
);
111 gd
->env_addr
= (ulong
)&default_environment
[0];