]>
Commit | Line | Data |
---|---|---|
83d290c5 | 1 | // SPDX-License-Identifier: GPL-2.0+ |
c609719b | 2 | /* |
ea882baf | 3 | * (C) Copyright 2000-2010 |
c609719b WD |
4 | * Wolfgang Denk, DENX Software Engineering, [email protected]. |
5 | * | |
6 | * (C) Copyright 2001 Sysgo Real-Time Solutions, GmbH <www.elinos.com> | |
7 | * Andreas Heppel <[email protected]> | |
c609719b WD |
8 | */ |
9 | ||
d678a59d | 10 | #include <common.h> |
c609719b | 11 | #include <command.h> |
7b51b576 | 12 | #include <env.h> |
f3998fdc | 13 | #include <env_internal.h> |
401d1c4f | 14 | #include <asm/global_data.h> |
c609719b | 15 | #include <linux/stddef.h> |
ea882baf WD |
16 | #include <search.h> |
17 | #include <errno.h> | |
3db71108 | 18 | #include <u-boot/crc.h> |
c609719b | 19 | |
957a0e69 JCPV |
20 | DECLARE_GLOBAL_DATA_PTR; |
21 | ||
46d9d1c3 | 22 | static env_t *env_ptr = (env_t *)CONFIG_ENV_ADDR; |
c609719b | 23 | |
c5951991 | 24 | static int env_nvram_load(void) |
c609719b | 25 | { |
cd0f4fa1 | 26 | char buf[CONFIG_ENV_SIZE]; |
ea882baf | 27 | |
cd0f4fa1 | 28 | memcpy(buf, (void *)CONFIG_ENV_ADDR, CONFIG_ENV_SIZE); |
ade03b55 | 29 | |
890feeca | 30 | return env_import(buf, 1, H_EXTERNAL); |
c609719b WD |
31 | } |
32 | ||
e5bce247 | 33 | static int env_nvram_save(void) |
c609719b | 34 | { |
cd0f4fa1 | 35 | env_t env_new; |
ea882baf WD |
36 | int rcode = 0; |
37 | ||
7ce1526e MV |
38 | rcode = env_export(&env_new); |
39 | if (rcode) | |
40 | return rcode; | |
ea882baf | 41 | |
cd0f4fa1 TR |
42 | if (memcpy((char *)CONFIG_ENV_ADDR, &env_new, CONFIG_ENV_SIZE) == NULL) |
43 | rcode = 1; | |
ade03b55 | 44 | |
c609719b WD |
45 | return rcode; |
46 | } | |
47 | ||
ea882baf | 48 | /* |
c609719b WD |
49 | * Initialize Environment use |
50 | * | |
51 | * We are still running from ROM, so data use is limited | |
52 | */ | |
e5bce247 | 53 | static int env_nvram_init(void) |
c609719b | 54 | { |
c609719b | 55 | if (crc32(0, env_ptr->data, ENV_SIZE) == env_ptr->crc) { |
a73c1f00 | 56 | gd->env_addr = (ulong)&env_ptr->data; |
203e94f6 | 57 | gd->env_valid = ENV_VALID; |
c609719b | 58 | } else { |
4735de4f | 59 | gd->env_valid = ENV_INVALID; |
c609719b | 60 | } |
91494ca6 IG |
61 | |
62 | return 0; | |
c609719b | 63 | } |
4415f1d1 SG |
64 | |
65 | U_BOOT_ENV_LOCATION(nvram) = { | |
66 | .location = ENVL_NVRAM, | |
ac358beb | 67 | ENV_NAME("NVRAM") |
e5bce247 SG |
68 | .load = env_nvram_load, |
69 | .save = env_save_ptr(env_nvram_save), | |
70 | .init = env_nvram_init, | |
4415f1d1 | 71 | }; |