"Das U-Boot" Source Tree
1// SPDX-License-Identifier: GPL-2.0+
2/*
3 * (C) Copyright 2000-2010
4 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
5 *
6 * (C) Copyright 2001 Sysgo Real-Time Solutions, GmbH <www.elinos.com>
7 * Andreas Heppel <aheppel@sysgo.de>
8 */
9
10#include <command.h>
11#include <env.h>
12#include <env_internal.h>
13#include <asm/global_data.h>
14#include <linux/stddef.h>
15#include <search.h>
16#include <errno.h>
17#include <u-boot/crc.h>
18
19DECLARE_GLOBAL_DATA_PTR;
20
21static env_t *env_ptr = (env_t *)CONFIG_ENV_ADDR;
22
23static int env_nvram_load(void)
24{
25 char buf[CONFIG_ENV_SIZE];
26
27 memcpy(buf, (void *)CONFIG_ENV_ADDR, CONFIG_ENV_SIZE);
28
29 return env_import(buf, 1, H_EXTERNAL);
30}
31
32static int env_nvram_save(void)
33{
34 env_t env_new;
35 int rcode = 0;
36
37 rcode = env_export(&env_new);
38 if (rcode)
39 return rcode;
40
41 if (memcpy((char *)CONFIG_ENV_ADDR, &env_new, CONFIG_ENV_SIZE) == NULL)
42 rcode = 1;
43
44 return rcode;
45}
46
47/*
48 * Initialize Environment use
49 *
50 * We are still running from ROM, so data use is limited
51 */
52static int env_nvram_init(void)
53{
54 if (crc32(0, env_ptr->data, ENV_SIZE) == env_ptr->crc) {
55 gd->env_addr = (ulong)&env_ptr->data;
56 gd->env_valid = ENV_VALID;
57 } else {
58 gd->env_valid = ENV_INVALID;
59 }
60
61 return 0;
62}
63
64U_BOOT_ENV_LOCATION(nvram) = {
65 .location = ENVL_NVRAM,
66 ENV_NAME("NVRAM")
67 .load = env_nvram_load,
68 .save = env_save_ptr(env_nvram_save),
69 .init = env_nvram_init,
70};