blob: b1a7d1a4c12e3d38e870b2f34a4ab36586355525 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Liu Gang0a85a9e2012-03-08 00:33:20 +00002/*
3 * (C) Copyright 2011-2012 Freescale Semiconductor, Inc.
Liu Gang0a85a9e2012-03-08 00:33:20 +00004 */
5
6/* #define DEBUG */
7
8#include <common.h>
9#include <command.h>
10#include <environment.h>
11#include <linux/stddef.h>
12
Liu Gang0a85a9e2012-03-08 00:33:20 +000013#ifdef ENV_IS_EMBEDDED
14env_t *env_ptr = &environment;
15#else /* ! ENV_IS_EMBEDDED */
16env_t *env_ptr = (env_t *)CONFIG_ENV_ADDR;
17#endif /* ENV_IS_EMBEDDED */
18
19DECLARE_GLOBAL_DATA_PTR;
20
21#if !defined(CONFIG_ENV_OFFSET)
22#define CONFIG_ENV_OFFSET 0
23#endif
24
Simon Glasse5bce242017-08-03 12:22:01 -060025static int env_remote_init(void)
Liu Gang0a85a9e2012-03-08 00:33:20 +000026{
27 if (crc32(0, env_ptr->data, ENV_SIZE) == env_ptr->crc) {
28 gd->env_addr = (ulong)&(env_ptr->data);
Simon Glass203e94f2017-08-03 12:21:56 -060029 gd->env_valid = ENV_VALID;
Liu Gang0a85a9e2012-03-08 00:33:20 +000030 return 0;
31 }
32
Simon Glass79388222017-08-03 12:22:02 -060033 return -ENOENT;
Liu Gang0a85a9e2012-03-08 00:33:20 +000034}
35
36#ifdef CONFIG_CMD_SAVEENV
Simon Glasse5bce242017-08-03 12:22:01 -060037static int env_remote_save(void)
Liu Gang0a85a9e2012-03-08 00:33:20 +000038{
Liu Gang461632b2012-08-09 05:10:03 +000039#ifdef CONFIG_SRIO_PCIE_BOOT_SLAVE
40 printf("Can not support the 'saveenv' when boot from SRIO or PCIE!\n");
Liu Gang0a85a9e2012-03-08 00:33:20 +000041 return 1;
42#else
43 return 0;
44#endif
45}
46#endif /* CONFIG_CMD_SAVEENV */
47
Simon Glassc5951992017-08-03 12:22:17 -060048static int env_remote_load(void)
Liu Gang0a85a9e2012-03-08 00:33:20 +000049{
50#ifndef ENV_IS_EMBEDDED
Simon Goldschmidt2166ebf2018-01-31 14:47:12 +010051 return env_import((char *)env_ptr, 1);
Liu Gang0a85a9e2012-03-08 00:33:20 +000052#endif
Simon Glassc5951992017-08-03 12:22:17 -060053
54 return 0;
Liu Gang0a85a9e2012-03-08 00:33:20 +000055}
Simon Glass4415f1d2017-08-03 12:21:58 -060056
57U_BOOT_ENV_LOCATION(remote) = {
58 .location = ENVL_REMOTE,
Simon Glassac358be2017-08-03 12:22:03 -060059 ENV_NAME("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};