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 #if defined(CFG_ENV_IS_IN_DATAFLASH) /* Environment is in DataFlash */
25 #include <environment.h>
26 #include <linux/stddef.h>
28 #include <dataflash.h>
30 env_t *env_ptr = NULL;
32 char * env_name_spec = "dataflash";
34 extern int read_dataflash (unsigned long addr, unsigned long size, char
36 extern int write_dataflash (unsigned long addr_dest, unsigned long addr_src,
38 extern int AT91F_DataflashInit (void);
39 extern uchar default_environment[];
40 /* extern int default_environment_size; */
43 uchar env_get_char_spec (int index)
46 read_dataflash (CFG_ENV_ADDR+index+offsetof(env_t,data),1,&c);
50 void env_relocate_spec (void)
52 read_dataflash (CFG_ENV_ADDR,CFG_ENV_SIZE,(uchar *)env_ptr);
57 /* env must be copied to do not alter env structure in memory*/
58 unsigned char temp[CFG_ENV_SIZE];
60 memcpy(temp, env_ptr, CFG_ENV_SIZE);
61 return write_dataflash (CFG_ENV_ADDR, (unsigned long)temp, CFG_ENV_SIZE);
64 /************************************************************************
65 * Initialize Environment use
67 * We are still running from ROM, so data use is limited
68 * Use a (moderately small) buffer on the stack
72 DECLARE_GLOBAL_DATA_PTR;
77 if (gd->env_valid == 0){
78 AT91F_DataflashInit(); /* prepare for DATAFLASH read/write */
81 read_dataflash (CFG_ENV_ADDR+offsetof(env_t,crc),sizeof(ulong),&crc);
84 off = offsetof(env_t,data);
86 int n = (len > sizeof(buf)) ? sizeof(buf) : len;
87 read_dataflash (CFG_ENV_ADDR+off,n , buf);
88 new = crc32 (new, buf, n);
93 gd->env_addr = offsetof(env_t,data);
96 gd->env_addr = (ulong)&default_environment[0];
104 #endif /* CFG_ENV_IS_IN_DATAFLASH */