Blame view
env/nvram.c
3.04 KB
c609719b8
|
1 |
/* |
ea882baf9
|
2 |
* (C) Copyright 2000-2010 |
c609719b8
|
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
|
7 |
* SPDX-License-Identifier: GPL-2.0+ |
c609719b8
|
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
|
21 |
* #define CONFIG_SYS_NVRAM_ACCESS_ROUTINE. Note, that those functions are |
c609719b8
|
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
|
27 28 |
#include <command.h> #include <environment.h> |
c609719b8
|
29 |
#include <linux/stddef.h> |
ea882baf9
|
30 31 |
#include <search.h> #include <errno.h> |
c609719b8
|
32 |
|
957a0e695
|
33 |
DECLARE_GLOBAL_DATA_PTR; |
6d0f6bcf3
|
34 |
#ifdef CONFIG_SYS_NVRAM_ACCESS_ROUTINE |
c609719b8
|
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
|
37 |
#else |
0e8d15866
|
38 |
env_t *env_ptr = (env_t *)CONFIG_ENV_ADDR; |
c609719b8
|
39 |
#endif |
bf95df44f
|
40 |
#ifdef CONFIG_SYS_NVRAM_ACCESS_ROUTINE |
b2cdef486
|
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
|
45 |
{ |
c609719b8
|
46 |
uchar c; |
91494ca6a
|
47 |
nvram_read(&c, CONFIG_ENV_ADDR + index, 1); |
c609719b8
|
48 49 |
return c; |
c609719b8
|
50 |
} |
bf95df44f
|
51 |
#endif |
c609719b8
|
52 |
|
c59519919
|
53 |
static int env_nvram_load(void) |
c609719b8
|
54 |
{ |
cd0f4fa1c
|
55 |
char buf[CONFIG_ENV_SIZE]; |
ea882baf9
|
56 |
|
6d0f6bcf3
|
57 |
#if defined(CONFIG_SYS_NVRAM_ACCESS_ROUTINE) |
ea882baf9
|
58 |
nvram_read(buf, CONFIG_ENV_ADDR, CONFIG_ENV_SIZE); |
c609719b8
|
59 |
#else |
cd0f4fa1c
|
60 |
memcpy(buf, (void *)CONFIG_ENV_ADDR, CONFIG_ENV_SIZE); |
c609719b8
|
61 |
#endif |
2166ebf78
|
62 |
return env_import(buf, 1); |
c609719b8
|
63 |
} |
e5bce247b
|
64 |
static int env_nvram_save(void) |
c609719b8
|
65 |
{ |
cd0f4fa1c
|
66 |
env_t env_new; |
ea882baf9
|
67 |
int rcode = 0; |
7ce1526ed
|
68 69 70 |
rcode = env_export(&env_new); if (rcode) return rcode; |
ea882baf9
|
71 |
|
6d0f6bcf3
|
72 |
#ifdef CONFIG_SYS_NVRAM_ACCESS_ROUTINE |
cd0f4fa1c
|
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
|
77 78 79 |
#endif return rcode; } |
ea882baf9
|
80 |
/* |
c609719b8
|
81 82 83 84 |
* Initialize Environment use * * We are still running from ROM, so data use is limited */ |
e5bce247b
|
85 |
static int env_nvram_init(void) |
c609719b8
|
86 |
{ |
6d0f6bcf3
|
87 |
#if defined(CONFIG_SYS_NVRAM_ACCESS_ROUTINE) |
c609719b8
|
88 |
ulong crc; |
cd0f4fa1c
|
89 |
uchar data[ENV_SIZE]; |
ea882baf9
|
90 91 |
nvram_read(&crc, CONFIG_ENV_ADDR, sizeof(ulong)); |
91494ca6a
|
92 |
nvram_read(data, CONFIG_ENV_ADDR + sizeof(ulong), ENV_SIZE); |
c609719b8
|
93 94 |
if (crc32(0, data, ENV_SIZE) == crc) { |
91494ca6a
|
95 |
gd->env_addr = (ulong)CONFIG_ENV_ADDR + sizeof(long); |
c609719b8
|
96 97 |
#else if (crc32(0, env_ptr->data, ENV_SIZE) == env_ptr->crc) { |
91494ca6a
|
98 |
gd->env_addr = (ulong)&env_ptr->data; |
c609719b8
|
99 |
#endif |
203e94f6c
|
100 |
gd->env_valid = ENV_VALID; |
c609719b8
|
101 |
} else { |
91494ca6a
|
102 |
gd->env_addr = (ulong)&default_environment[0]; |
2d7cb5b42
|
103 |
gd->env_valid = ENV_INVALID; |
c609719b8
|
104 |
} |
91494ca6a
|
105 106 |
return 0; |
c609719b8
|
107 |
} |
4415f1d1f
|
108 109 110 |
U_BOOT_ENV_LOCATION(nvram) = { .location = ENVL_NVRAM, |
ac358beb8
|
111 |
ENV_NAME("NVRAM") |
e5bce247b
|
112 113 114 |
.load = env_nvram_load, .save = env_save_ptr(env_nvram_save), .init = env_nvram_init, |
4415f1d1f
|
115 |
}; |