blob: d93a137376e37efa59f0180be548c132ee8434e0 [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>
Simon Glass3db71102019-11-14 12:57:16 -070012#include <u-boot/crc.h>
Liu Gang0a85a9e2012-03-08 00:33:20 +000013
Liu Gang0a85a9e2012-03-08 00:33:20 +000014#ifdef ENV_IS_EMBEDDED
Rasmus Villemoes46d9d1c2020-02-18 08:54:09 +000015static env_t *env_ptr = &environment;
Liu Gang0a85a9e2012-03-08 00:33:20 +000016#else /* ! ENV_IS_EMBEDDED */
Rasmus Villemoes46d9d1c2020-02-18 08:54:09 +000017static env_t *env_ptr = (env_t *)CONFIG_ENV_ADDR;
Liu Gang0a85a9e2012-03-08 00:33:20 +000018#endif /* ENV_IS_EMBEDDED */
19
20DECLARE_GLOBAL_DATA_PTR;
21
Simon Glasse5bce242017-08-03 12:22:01 -060022static int env_remote_init(void)
Liu Gang0a85a9e2012-03-08 00:33:20 +000023{
24 if (crc32(0, env_ptr->data, ENV_SIZE) == env_ptr->crc) {
25 gd->env_addr = (ulong)&(env_ptr->data);
Simon Glass203e94f2017-08-03 12:21:56 -060026 gd->env_valid = ENV_VALID;
Liu Gang0a85a9e2012-03-08 00:33:20 +000027 return 0;
28 }
29
Simon Glass79388222017-08-03 12:22:02 -060030 return -ENOENT;
Liu Gang0a85a9e2012-03-08 00:33:20 +000031}
32
33#ifdef CONFIG_CMD_SAVEENV
Simon Glasse5bce242017-08-03 12:22:01 -060034static int env_remote_save(void)
Liu Gang0a85a9e2012-03-08 00:33:20 +000035{
Liu Gang461632b2012-08-09 05:10:03 +000036#ifdef CONFIG_SRIO_PCIE_BOOT_SLAVE
37 printf("Can not support the 'saveenv' when boot from SRIO or PCIE!\n");
Liu Gang0a85a9e2012-03-08 00:33:20 +000038 return 1;
39#else
40 return 0;
41#endif
42}
43#endif /* CONFIG_CMD_SAVEENV */
44
Simon Glassc5951992017-08-03 12:22:17 -060045static int env_remote_load(void)
Liu Gang0a85a9e2012-03-08 00:33:20 +000046{
47#ifndef ENV_IS_EMBEDDED
Marek Vasut890feec2020-07-07 20:51:35 +020048 return env_import((char *)env_ptr, 1, H_EXTERNAL);
Liu Gang0a85a9e2012-03-08 00:33:20 +000049#endif
Simon Glassc5951992017-08-03 12:22:17 -060050
51 return 0;
Liu Gang0a85a9e2012-03-08 00:33:20 +000052}
Simon Glass4415f1d2017-08-03 12:21:58 -060053
54U_BOOT_ENV_LOCATION(remote) = {
55 .location = ENVL_REMOTE,
Simon Glassac358be2017-08-03 12:22:03 -060056 ENV_NAME("Remote")
Simon Glasse5bce242017-08-03 12:22:01 -060057 .load = env_remote_load,
58 .save = env_save_ptr(env_remote_save),
59 .init = env_remote_init,
Simon Glass4415f1d2017-08-03 12:21:58 -060060};