1 // SPDX-License-Identifier: GPL-2.0+
3 * (C) Copyright 2000-2010
4 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
6 * (C) Copyright 2001 Sysgo Real-Time Solutions, GmbH <www.elinos.com>
7 * Andreas Heppel <aheppel@sysgo.de>
12 #include <env_internal.h>
13 #include <asm/global_data.h>
14 #include <linux/stddef.h>
17 #include <u-boot/crc.h>
19 DECLARE_GLOBAL_DATA_PTR;
21 static env_t *env_ptr = (env_t *)CONFIG_ENV_ADDR;
23 static int env_nvram_load(void)
25 char buf[CONFIG_ENV_SIZE];
27 memcpy(buf, (void *)CONFIG_ENV_ADDR, CONFIG_ENV_SIZE);
29 return env_import(buf, 1, H_EXTERNAL);
32 static int env_nvram_save(void)
37 rcode = env_export(&env_new);
41 if (memcpy((char *)CONFIG_ENV_ADDR, &env_new, CONFIG_ENV_SIZE) == NULL)
48 * Initialize Environment use
50 * We are still running from ROM, so data use is limited
52 static int env_nvram_init(void)
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;
58 gd->env_valid = ENV_INVALID;
64 U_BOOT_ENV_LOCATION(nvram) = {
65 .location = ENVL_NVRAM,
67 .load = env_nvram_load,
68 .save = env_save_ptr(env_nvram_save),
69 .init = env_nvram_init,