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;
17 static int env_dataflash_get_char(int index)
21 read_dataflash(CONFIG_ENV_ADDR + index + offsetof(env_t, data),
26 static int env_dataflash_load(void)
30 char buf[CONFIG_ENV_SIZE];
33 read_dataflash(CONFIG_ENV_ADDR + offsetof(env_t, crc),
34 sizeof(ulong), (char *)&crc);
36 /* Read whole environment */
37 read_dataflash(CONFIG_ENV_ADDR, CONFIG_ENV_SIZE, buf);
39 /* Calculate the CRC */
40 off = offsetof(env_t, data);
41 new = crc32(new, (unsigned char *)(buf + off), ENV_SIZE);
46 set_default_env("!bad CRC");
51 #ifdef CONFIG_ENV_OFFSET_REDUND
52 #error No support for redundant environment on dataflash yet!
55 static int env_dataflash_save(void)
60 ret = env_export(&env_new);
64 return write_dataflash(CONFIG_ENV_ADDR,
65 (unsigned long)&env_new,
69 U_BOOT_ENV_LOCATION(dataflash) = {
70 .location = ENVL_DATAFLASH,
72 .get_char = env_dataflash_get_char,
73 .load = env_dataflash_load,
74 .save = env_save_ptr(env_dataflash_save),