2 * LowLevel function for DataFlash environment support
3 * Author : Gilles Gastaldi (Atmel)
5 * SPDX-License-Identifier: GPL-2.0+
9 #include <environment.h>
10 #include <linux/stddef.h>
11 #include <dataflash.h>
15 DECLARE_GLOBAL_DATA_PTR;
19 char *env_name_spec = "dataflash";
21 uchar env_get_char_spec(int index)
25 read_dataflash(CONFIG_ENV_ADDR + index + offsetof(env_t, data),
30 void env_relocate_spec(void)
32 char buf[CONFIG_ENV_SIZE];
34 read_dataflash(CONFIG_ENV_ADDR, CONFIG_ENV_SIZE, buf);
39 #ifdef CONFIG_ENV_OFFSET_REDUND
40 #error No support for redundant environment on dataflash yet!
49 res = (char *)&env_new.data;
50 len = hexport_r(&env_htab, '\0', 0, &res, ENV_SIZE, 0, NULL);
52 error("Cannot export environment: errno = %d\n", errno);
55 env_new.crc = crc32(0, env_new.data, ENV_SIZE);
57 return write_dataflash(CONFIG_ENV_ADDR,
58 (unsigned long)&env_new,
63 * Initialize environment use
65 * We are still running from ROM, so data use is limited.
66 * Use a (moderately small) buffer on the stack
70 ulong crc, len = ENV_SIZE, new = 0;
77 AT91F_DataflashInit(); /* prepare for DATAFLASH read/write */
80 read_dataflash(CONFIG_ENV_ADDR + offsetof(env_t, crc),
81 sizeof(ulong), (char *)&crc);
83 off = offsetof(env_t, data);
85 int n = (len > sizeof(buf)) ? sizeof(buf) : len;
87 read_dataflash(CONFIG_ENV_ADDR + off, n, (char *)buf);
89 new = crc32(new, buf, n);
95 gd->env_addr = offsetof(env_t, data);
98 gd->env_addr = (ulong)&default_environment[0];