Blame view
env/nvram.c
3.04 KB
c609719b8 Initial revision |
1 |
/* |
ea882baf9 New implementatio... |
2 |
* (C) Copyright 2000-2010 |
c609719b8 Initial revision |
3 4 5 6 |
* Wolfgang Denk, DENX Software Engineering, wd@denx.de. * * (C) Copyright 2001 Sysgo Real-Time Solutions, GmbH <www.elinos.com> * Andreas Heppel <aheppel@sysgo.de> |
3765b3e7b Coding Style clea... |
7 |
* SPDX-License-Identifier: GPL-2.0+ |
c609719b8 Initial revision |
8 9 10 11 12 13 14 15 16 17 18 19 20 |
*/ /* * 09-18-2001 Andreas Heppel, Sysgo RTS GmbH <aheppel@sysgo.de> * * It might not be possible in all cases to use 'memcpy()' to copy * the environment to NVRAM, as the NVRAM might not be mapped into * the memory space. (I.e. this is the case for the BAB750). In those * cases it might be possible to access the NVRAM using a different * method. For example, the RTC on the BAB750 is accessible in IO * space using its address and data registers. To enable usage of * NVRAM in those cases I invented the functions 'nvram_read()' and * 'nvram_write()', which will be activated upon the configuration |
6d0f6bcf3 rename CFG_ macro... |
21 |
* #define CONFIG_SYS_NVRAM_ACCESS_ROUTINE. Note, that those functions are |
c609719b8 Initial revision |
22 23 24 25 26 |
* strongly dependent on the used HW, and must be redefined for each * board that wants to use them. */ #include <common.h> |
c609719b8 Initial revision |
27 28 |
#include <command.h> #include <environment.h> |
c609719b8 Initial revision |
29 |
#include <linux/stddef.h> |
ea882baf9 New implementatio... |
30 31 |
#include <search.h> #include <errno.h> |
c609719b8 Initial revision |
32 |
|
957a0e695 env_nvram: Move c... |
33 |
DECLARE_GLOBAL_DATA_PTR; |
6d0f6bcf3 rename CFG_ macro... |
34 |
#ifdef CONFIG_SYS_NVRAM_ACCESS_ROUTINE |
c609719b8 Initial revision |
35 36 |
extern void *nvram_read(void *dest, const long src, size_t count); extern void nvram_write(long dest, const void *src, size_t count); |
c609719b8 Initial revision |
37 |
#else |
0e8d15866 rename CFG_ENV ma... |
38 |
env_t *env_ptr = (env_t *)CONFIG_ENV_ADDR; |
c609719b8 Initial revision |
39 |
#endif |
bf95df44f env: factor out t... |
40 |
#ifdef CONFIG_SYS_NVRAM_ACCESS_ROUTINE |
b2cdef486 env: restore old ... |
41 42 43 44 |
/** Call this function from overridden env_get_char_spec() if you need * this functionality. */ int env_nvram_get_char(int index) |
c609719b8 Initial revision |
45 |
{ |
c609719b8 Initial revision |
46 |
uchar c; |
91494ca6a env: clean env_nv... |
47 |
nvram_read(&c, CONFIG_ENV_ADDR + index, 1); |
c609719b8 Initial revision |
48 49 |
return c; |
c609719b8 Initial revision |
50 |
} |
bf95df44f env: factor out t... |
51 |
#endif |
c609719b8 Initial revision |
52 |
|
c59519919 env: Adjust the l... |
53 |
static int env_nvram_load(void) |
c609719b8 Initial revision |
54 |
{ |
cd0f4fa1c Revert "env: fix ... |
55 |
char buf[CONFIG_ENV_SIZE]; |
ea882baf9 New implementatio... |
56 |
|
6d0f6bcf3 rename CFG_ macro... |
57 |
#if defined(CONFIG_SYS_NVRAM_ACCESS_ROUTINE) |
ea882baf9 New implementatio... |
58 |
nvram_read(buf, CONFIG_ENV_ADDR, CONFIG_ENV_SIZE); |
c609719b8 Initial revision |
59 |
#else |
cd0f4fa1c Revert "env: fix ... |
60 |
memcpy(buf, (void *)CONFIG_ENV_ADDR, CONFIG_ENV_SIZE); |
c609719b8 Initial revision |
61 |
#endif |
2166ebf78 env: make env dri... |
62 |
return env_import(buf, 1); |
c609719b8 Initial revision |
63 |
} |
e5bce247b env: Switch over ... |
64 |
static int env_nvram_save(void) |
c609719b8 Initial revision |
65 |
{ |
cd0f4fa1c Revert "env: fix ... |
66 |
env_t env_new; |
ea882baf9 New implementatio... |
67 |
int rcode = 0; |
7ce1526ed env: Add env_expo... |
68 69 70 |
rcode = env_export(&env_new); if (rcode) return rcode; |
ea882baf9 New implementatio... |
71 |
|
6d0f6bcf3 rename CFG_ macro... |
72 |
#ifdef CONFIG_SYS_NVRAM_ACCESS_ROUTINE |
cd0f4fa1c Revert "env: fix ... |
73 74 75 76 |
nvram_write(CONFIG_ENV_ADDR, &env_new, CONFIG_ENV_SIZE); #else if (memcpy((char *)CONFIG_ENV_ADDR, &env_new, CONFIG_ENV_SIZE) == NULL) rcode = 1; |
c609719b8 Initial revision |
77 78 79 |
#endif return rcode; } |
ea882baf9 New implementatio... |
80 |
/* |
c609719b8 Initial revision |
81 82 83 84 |
* Initialize Environment use * * We are still running from ROM, so data use is limited */ |
e5bce247b env: Switch over ... |
85 |
static int env_nvram_init(void) |
c609719b8 Initial revision |
86 |
{ |
6d0f6bcf3 rename CFG_ macro... |
87 |
#if defined(CONFIG_SYS_NVRAM_ACCESS_ROUTINE) |
c609719b8 Initial revision |
88 |
ulong crc; |
cd0f4fa1c Revert "env: fix ... |
89 |
uchar data[ENV_SIZE]; |
ea882baf9 New implementatio... |
90 91 |
nvram_read(&crc, CONFIG_ENV_ADDR, sizeof(ulong)); |
91494ca6a env: clean env_nv... |
92 |
nvram_read(data, CONFIG_ENV_ADDR + sizeof(ulong), ENV_SIZE); |
c609719b8 Initial revision |
93 94 |
if (crc32(0, data, ENV_SIZE) == crc) { |
91494ca6a env: clean env_nv... |
95 |
gd->env_addr = (ulong)CONFIG_ENV_ADDR + sizeof(long); |
c609719b8 Initial revision |
96 97 |
#else if (crc32(0, env_ptr->data, ENV_SIZE) == env_ptr->crc) { |
91494ca6a env: clean env_nv... |
98 |
gd->env_addr = (ulong)&env_ptr->data; |
c609719b8 Initial revision |
99 |
#endif |
203e94f6c env: Add an enum ... |
100 |
gd->env_valid = ENV_VALID; |
c609719b8 Initial revision |
101 |
} else { |
91494ca6a env: clean env_nv... |
102 |
gd->env_addr = (ulong)&default_environment[0]; |
2d7cb5b42 env: Replace all ... |
103 |
gd->env_valid = ENV_INVALID; |
c609719b8 Initial revision |
104 |
} |
91494ca6a env: clean env_nv... |
105 106 |
return 0; |
c609719b8 Initial revision |
107 |
} |
4415f1d1f env: Create a loc... |
108 109 110 |
U_BOOT_ENV_LOCATION(nvram) = { .location = ENVL_NVRAM, |
ac358beb8 env: Drop the env... |
111 |
ENV_NAME("NVRAM") |
e5bce247b env: Switch over ... |
112 113 114 |
.load = env_nvram_load, .save = env_save_ptr(env_nvram_save), .init = env_nvram_init, |
4415f1d1f env: Create a loc... |
115 |
}; |