1 /* LowLevel function for DataFlash environment support
2 * Author : Gilles Gastaldi (Atmel)
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation; either version 2 of
7 * the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
22 #include <environment.h>
23 #include <linux/stddef.h>
24 #include <dataflash.h>
26 DECLARE_GLOBAL_DATA_PTR;
28 env_t *env_ptr = NULL;
30 char * env_name_spec = "dataflash";
32 extern int read_dataflash (unsigned long addr, unsigned long size, char
34 extern int write_dataflash (unsigned long addr_dest, unsigned long addr_src,
36 extern int AT91F_DataflashInit (void);
37 extern uchar default_environment[];
40 uchar env_get_char_spec (int index)
43 read_dataflash(CONFIG_ENV_ADDR + index + offsetof(env_t,data),
48 void env_relocate_spec (void)
50 read_dataflash(CONFIG_ENV_ADDR, CONFIG_ENV_SIZE, (char *)env_ptr);
55 /* env must be copied to do not alter env structure in memory*/
56 unsigned char temp[CONFIG_ENV_SIZE];
57 memcpy(temp, env_ptr, CONFIG_ENV_SIZE);
58 return write_dataflash(CONFIG_ENV_ADDR, (unsigned long)temp, CONFIG_ENV_SIZE);
61 /************************************************************************
62 * Initialize Environment use
64 * We are still running from ROM, so data use is limited
65 * Use a (moderately small) buffer on the stack
72 if (gd->env_valid == 0){
73 AT91F_DataflashInit(); /* prepare for DATAFLASH read/write */
76 read_dataflash(CONFIG_ENV_ADDR + offsetof(env_t, crc),
77 sizeof(ulong), (char *)&crc);
80 off = offsetof(env_t,data);
82 int n = (len > sizeof(buf)) ? sizeof(buf) : len;
83 read_dataflash(CONFIG_ENV_ADDR + off, n, (char *)buf);
84 new = crc32 (new, buf, n);
89 gd->env_addr = offsetof(env_t,data);
92 gd->env_addr = (ulong)&default_environment[0];