blob: 55faa1e5d0e8d2f9a0ed1563e1e826f094a5d3b8 [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>
Simon Glassf3998fd2019-08-02 09:44:25 -060010#include <env_internal.h>
Liu Gang0a85a9e2012-03-08 00:33:20 +000011#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
Simon Glasse5bce242017-08-03 12:22:01 -060021static int env_remote_init(void)
Liu Gang0a85a9e2012-03-08 00:33:20 +000022{
23 if (crc32(0, env_ptr->data, ENV_SIZE) == env_ptr->crc) {
24 gd->env_addr = (ulong)&(env_ptr->data);
Simon Glass203e94f2017-08-03 12:21:56 -060025 gd->env_valid = ENV_VALID;
Liu Gang0a85a9e2012-03-08 00:33:20 +000026 return 0;
27 }
28
Simon Glass79388222017-08-03 12:22:02 -060029 return -ENOENT;
Liu Gang0a85a9e2012-03-08 00:33:20 +000030}
31
32#ifdef CONFIG_CMD_SAVEENV
Simon Glasse5bce242017-08-03 12:22:01 -060033static int env_remote_save(void)
Liu Gang0a85a9e2012-03-08 00:33:20 +000034{
Liu Gang461632b2012-08-09 05:10:03 +000035#ifdef CONFIG_SRIO_PCIE_BOOT_SLAVE
36 printf("Can not support the 'saveenv' when boot from SRIO or PCIE!\n");
Liu Gang0a85a9e2012-03-08 00:33:20 +000037 return 1;
38#else
39 return 0;
40#endif
41}
42#endif /* CONFIG_CMD_SAVEENV */
43
Simon Glassc5951992017-08-03 12:22:17 -060044static int env_remote_load(void)
Liu Gang0a85a9e2012-03-08 00:33:20 +000045{
46#ifndef ENV_IS_EMBEDDED
Simon Goldschmidt2166ebf2018-01-31 14:47:12 +010047 return env_import((char *)env_ptr, 1);
Liu Gang0a85a9e2012-03-08 00:33:20 +000048#endif
Simon Glassc5951992017-08-03 12:22:17 -060049
50 return 0;
Liu Gang0a85a9e2012-03-08 00:33:20 +000051}
Simon Glass4415f1d2017-08-03 12:21:58 -060052
53U_BOOT_ENV_LOCATION(remote) = {
54 .location = ENVL_REMOTE,
Simon Glassac358be2017-08-03 12:22:03 -060055 ENV_NAME("Remote")
Simon Glasse5bce242017-08-03 12:22:01 -060056 .load = env_remote_load,
57 .save = env_save_ptr(env_remote_save),
58 .init = env_remote_init,
Simon Glass4415f1d2017-08-03 12:21:58 -060059};