blob: c013fdd4b0194181d50905a54b92e4b169fee6a7 [file] [log] [blame]
Liu Gang85bcd732012-03-08 00:33:20 +00001/*
2 * (C) Copyright 2011-2012 Freescale Semiconductor, Inc.
3 *
Wolfgang Denkbd8ec7e2013-10-07 13:07:26 +02004 * SPDX-License-Identifier: GPL-2.0+
Liu Gang85bcd732012-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 Gang85bcd732012-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 Glass082af922017-08-03 12:22:01 -060026static int env_remote_init(void)
Liu Gang85bcd732012-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 Glass4bc2ad22017-08-03 12:21:56 -060030 gd->env_valid = ENV_VALID;
Liu Gang85bcd732012-03-08 00:33:20 +000031 return 0;
32 }
33
Simon Glassd40d8042017-08-03 12:22:02 -060034 return -ENOENT;
Liu Gang85bcd732012-03-08 00:33:20 +000035}
36
37#ifdef CONFIG_CMD_SAVEENV
Simon Glass082af922017-08-03 12:22:01 -060038static int env_remote_save(void)
Liu Gang85bcd732012-03-08 00:33:20 +000039{
Liu Gangb4611ee2012-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 Gang85bcd732012-03-08 00:33:20 +000042 return 1;
43#else
44 return 0;
45#endif
46}
47#endif /* CONFIG_CMD_SAVEENV */
48
Simon Glass99778492017-08-03 12:22:17 -060049static int env_remote_load(void)
Liu Gang85bcd732012-03-08 00:33:20 +000050{
51#ifndef ENV_IS_EMBEDDED
52 env_import((char *)env_ptr, 1);
53#endif
Simon Glass99778492017-08-03 12:22:17 -060054
55 return 0;
Liu Gang85bcd732012-03-08 00:33:20 +000056}
Simon Glassc10a88e2017-08-03 12:21:58 -060057
58U_BOOT_ENV_LOCATION(remote) = {
59 .location = ENVL_REMOTE,
Simon Glassd8273ed2017-08-03 12:22:03 -060060 ENV_NAME("Remote")
Simon Glass082af922017-08-03 12:22:01 -060061 .load = env_remote_load,
62 .save = env_save_ptr(env_remote_save),
63 .init = env_remote_init,
Simon Glassc10a88e2017-08-03 12:21:58 -060064};