blob: 379d0eb1bb333186cae1c26db32df3b30d1765f1 [file] [log] [blame]
Liu Gang0a85a9e2012-03-08 00:33:20 +00001/*
2 * (C) Copyright 2011-2012 Freescale Semiconductor, Inc.
3 *
Wolfgang Denk3765b3e2013-10-07 13:07:26 +02004 * SPDX-License-Identifier: GPL-2.0+
Liu Gang0a85a9e2012-03-08 00:33:20 +00005 */
6
7/* #define DEBUG */
8
9#include <common.h>
10#include <command.h>
11#include <environment.h>
12#include <linux/stddef.h>
13
Liu Gang0a85a9e2012-03-08 00:33:20 +000014#ifdef ENV_IS_EMBEDDED
15env_t *env_ptr = &environment;
16#else /* ! ENV_IS_EMBEDDED */
17env_t *env_ptr = (env_t *)CONFIG_ENV_ADDR;
18#endif /* ENV_IS_EMBEDDED */
19
20DECLARE_GLOBAL_DATA_PTR;
21
22#if !defined(CONFIG_ENV_OFFSET)
23#define CONFIG_ENV_OFFSET 0
24#endif
25
Simon Glasse5bce242017-08-03 12:22:01 -060026static int env_remote_init(void)
Liu Gang0a85a9e2012-03-08 00:33:20 +000027{
28 if (crc32(0, env_ptr->data, ENV_SIZE) == env_ptr->crc) {
29 gd->env_addr = (ulong)&(env_ptr->data);
Simon Glass203e94f2017-08-03 12:21:56 -060030 gd->env_valid = ENV_VALID;
Liu Gang0a85a9e2012-03-08 00:33:20 +000031 return 0;
32 }
33
Simon Glass79388222017-08-03 12:22:02 -060034 return -ENOENT;
Liu Gang0a85a9e2012-03-08 00:33:20 +000035}
36
37#ifdef CONFIG_CMD_SAVEENV
Simon Glasse5bce242017-08-03 12:22:01 -060038static int env_remote_save(void)
Liu Gang0a85a9e2012-03-08 00:33:20 +000039{
Liu Gang461632b2012-08-09 05:10:03 +000040#ifdef CONFIG_SRIO_PCIE_BOOT_SLAVE
41 printf("Can not support the 'saveenv' when boot from SRIO or PCIE!\n");
Liu Gang0a85a9e2012-03-08 00:33:20 +000042 return 1;
43#else
44 return 0;
45#endif
46}
47#endif /* CONFIG_CMD_SAVEENV */
48
Simon Glassc5951992017-08-03 12:22:17 -060049static int env_remote_load(void)
Liu Gang0a85a9e2012-03-08 00:33:20 +000050{
51#ifndef ENV_IS_EMBEDDED
Simon Goldschmidt2166ebf2018-01-31 14:47:12 +010052 return env_import((char *)env_ptr, 1);
Liu Gang0a85a9e2012-03-08 00:33:20 +000053#endif
Simon Glassc5951992017-08-03 12:22:17 -060054
55 return 0;
Liu Gang0a85a9e2012-03-08 00:33:20 +000056}
Simon Glass4415f1d2017-08-03 12:21:58 -060057
58U_BOOT_ENV_LOCATION(remote) = {
59 .location = ENVL_REMOTE,
Simon Glassac358be2017-08-03 12:22:03 -060060 ENV_NAME("Remote")
Simon Glasse5bce242017-08-03 12:22:01 -060061 .load = env_remote_load,
62 .save = env_save_ptr(env_remote_save),
63 .init = env_remote_init,
Simon Glass4415f1d2017-08-03 12:21:58 -060064};