Blame view
common/env_dataflash.c
1.73 KB
ea882baf9 New implementatio... |
1 2 |
/* * LowLevel function for DataFlash environment support |
5779d8d98 * Patch by Nicola... |
3 4 |
* Author : Gilles Gastaldi (Atmel) * |
1a4596601 Add GPL-2.0+ SPDX... |
5 |
* SPDX-License-Identifier: GPL-2.0+ |
5779d8d98 * Patch by Nicola... |
6 7 |
*/ #include <common.h> |
5779d8d98 * Patch by Nicola... |
8 9 10 |
#include <command.h> #include <environment.h> #include <linux/stddef.h> |
5779d8d98 * Patch by Nicola... |
11 |
#include <dataflash.h> |
ea882baf9 New implementatio... |
12 13 |
#include <search.h> #include <errno.h> |
5779d8d98 * Patch by Nicola... |
14 |
|
d87080b72 GCC-4.x fixes: cl... |
15 |
DECLARE_GLOBAL_DATA_PTR; |
0901d9f89 env: clean env_da... |
16 |
env_t *env_ptr; |
5779d8d98 * Patch by Nicola... |
17 |
|
0901d9f89 env: clean env_da... |
18 |
char *env_name_spec = "dataflash"; |
5779d8d98 * Patch by Nicola... |
19 |
|
ea882baf9 New implementatio... |
20 |
uchar env_get_char_spec(int index) |
5779d8d98 * Patch by Nicola... |
21 22 |
{ uchar c; |
ea882baf9 New implementatio... |
23 |
|
0901d9f89 env: clean env_da... |
24 |
read_dataflash(CONFIG_ENV_ADDR + index + offsetof(env_t, data), |
ea882baf9 New implementatio... |
25 |
1, (char *)&c); |
0901d9f89 env: clean env_da... |
26 |
return c; |
5779d8d98 * Patch by Nicola... |
27 |
} |
ea882baf9 New implementatio... |
28 |
void env_relocate_spec(void) |
5779d8d98 * Patch by Nicola... |
29 |
{ |
cca2011e6 env: dataflash: f... |
30 31 |
ulong crc, new = 0; unsigned off; |
cd0f4fa1c Revert "env: fix ... |
32 |
char buf[CONFIG_ENV_SIZE]; |
ea882baf9 New implementatio... |
33 |
|
cca2011e6 env: dataflash: f... |
34 35 36 37 38 |
/* Read old CRC */ read_dataflash(CONFIG_ENV_ADDR + offsetof(env_t, crc), sizeof(ulong), (char *)&crc); /* Read whole environment */ |
cd0f4fa1c Revert "env: fix ... |
39 |
read_dataflash(CONFIG_ENV_ADDR, CONFIG_ENV_SIZE, buf); |
cca2011e6 env: dataflash: f... |
40 41 42 43 44 45 46 47 |
/* Calculate the CRC */ off = offsetof(env_t, data); new = crc32(new, (unsigned char *)(buf + off), ENV_SIZE); if (crc == new) env_import(buf, 1); else set_default_env("!bad CRC"); |
5779d8d98 * Patch by Nicola... |
48 |
} |
ea882baf9 New implementatio... |
49 50 51 |
#ifdef CONFIG_ENV_OFFSET_REDUND #error No support for redundant environment on dataflash yet! #endif |
5779d8d98 * Patch by Nicola... |
52 53 |
int saveenv(void) { |
cd0f4fa1c Revert "env: fix ... |
54 |
env_t env_new; |
ea882baf9 New implementatio... |
55 56 |
ssize_t len; char *res; |
cd0f4fa1c Revert "env: fix ... |
57 |
res = (char *)&env_new.data; |
be11235ab env: Hide '.' var... |
58 |
len = hexport_r(&env_htab, '\0', 0, &res, ENV_SIZE, 0, NULL); |
ea882baf9 New implementatio... |
59 60 61 62 63 |
if (len < 0) { error("Cannot export environment: errno = %d ", errno); return 1; } |
cd0f4fa1c Revert "env: fix ... |
64 |
env_new.crc = crc32(0, env_new.data, ENV_SIZE); |
ea882baf9 New implementatio... |
65 66 |
return write_dataflash(CONFIG_ENV_ADDR, |
cd0f4fa1c Revert "env: fix ... |
67 |
(unsigned long)&env_new, |
ea882baf9 New implementatio... |
68 |
CONFIG_ENV_SIZE); |
5779d8d98 * Patch by Nicola... |
69 |
} |
ea882baf9 New implementatio... |
70 71 |
/* * Initialize environment use |
5779d8d98 * Patch by Nicola... |
72 |
* |
ea882baf9 New implementatio... |
73 |
* We are still running from ROM, so data use is limited. |
5779d8d98 * Patch by Nicola... |
74 75 76 77 |
* Use a (moderately small) buffer on the stack */ int env_init(void) { |
cca2011e6 env: dataflash: f... |
78 79 80 |
/* use default */ gd->env_addr = (ulong)&default_environment[0]; gd->env_valid = 1; |
5779d8d98 * Patch by Nicola... |
81 |
|
ea882baf9 New implementatio... |
82 |
return 0; |
5779d8d98 * Patch by Nicola... |
83 |
} |