blob: c5dce5b9662cb5af1647836745020b0560568561 [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
14char *env_name_spec = "Remote";
15
16#ifdef ENV_IS_EMBEDDED
17env_t *env_ptr = &environment;
18#else /* ! ENV_IS_EMBEDDED */
19env_t *env_ptr = (env_t *)CONFIG_ENV_ADDR;
20#endif /* ENV_IS_EMBEDDED */
21
22DECLARE_GLOBAL_DATA_PTR;
23
24#if !defined(CONFIG_ENV_OFFSET)
25#define CONFIG_ENV_OFFSET 0
26#endif
27
Simon Glasse5bce242017-08-03 12:22:01 -060028static int env_remote_init(void)
Liu Gang0a85a9e2012-03-08 00:33:20 +000029{
30 if (crc32(0, env_ptr->data, ENV_SIZE) == env_ptr->crc) {
31 gd->env_addr = (ulong)&(env_ptr->data);
Simon Glass203e94f2017-08-03 12:21:56 -060032 gd->env_valid = ENV_VALID;
Liu Gang0a85a9e2012-03-08 00:33:20 +000033 return 0;
34 }
35
Simon Glass79388222017-08-03 12:22:02 -060036 return -ENOENT;
Liu Gang0a85a9e2012-03-08 00:33:20 +000037}
38
39#ifdef CONFIG_CMD_SAVEENV
Simon Glasse5bce242017-08-03 12:22:01 -060040static int env_remote_save(void)
Liu Gang0a85a9e2012-03-08 00:33:20 +000041{
Liu Gang461632b2012-08-09 05:10:03 +000042#ifdef CONFIG_SRIO_PCIE_BOOT_SLAVE
43 printf("Can not support the 'saveenv' when boot from SRIO or PCIE!\n");
Liu Gang0a85a9e2012-03-08 00:33:20 +000044 return 1;
45#else
46 return 0;
47#endif
48}
49#endif /* CONFIG_CMD_SAVEENV */
50
Simon Glasse5bce242017-08-03 12:22:01 -060051static void env_remote_load(void)
Liu Gang0a85a9e2012-03-08 00:33:20 +000052{
53#ifndef ENV_IS_EMBEDDED
54 env_import((char *)env_ptr, 1);
55#endif
56}
Simon Glass4415f1d2017-08-03 12:21:58 -060057
58U_BOOT_ENV_LOCATION(remote) = {
59 .location = ENVL_REMOTE,
Simon Glasse5bce242017-08-03 12:22:01 -060060 .load = env_remote_load,
61 .save = env_save_ptr(env_remote_save),
62 .init = env_remote_init,
Simon Glass4415f1d2017-08-03 12:21:58 -060063};