blob: d93a137376e37efa59f0180be548c132ee8434e0 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Liu Gang85bcd732012-03-08 00:33:20 +00002/*
3 * (C) Copyright 2011-2012 Freescale Semiconductor, Inc.
Liu Gang85bcd732012-03-08 00:33:20 +00004 */
5
6/* #define DEBUG */
7
8#include <common.h>
9#include <command.h>
Simon Glass9d1f6192019-08-02 09:44:25 -060010#include <env_internal.h>
Liu Gang85bcd732012-03-08 00:33:20 +000011#include <linux/stddef.h>
Simon Glass48b6c6b2019-11-14 12:57:16 -070012#include <u-boot/crc.h>
Liu Gang85bcd732012-03-08 00:33:20 +000013
Liu Gang85bcd732012-03-08 00:33:20 +000014#ifdef ENV_IS_EMBEDDED
Rasmus Villemoes5d18fc12020-02-18 08:54:09 +000015static env_t *env_ptr = &environment;
Liu Gang85bcd732012-03-08 00:33:20 +000016#else /* ! ENV_IS_EMBEDDED */
Rasmus Villemoes5d18fc12020-02-18 08:54:09 +000017static env_t *env_ptr = (env_t *)CONFIG_ENV_ADDR;
Liu Gang85bcd732012-03-08 00:33:20 +000018#endif /* ENV_IS_EMBEDDED */
19
20DECLARE_GLOBAL_DATA_PTR;
21
Simon Glass082af922017-08-03 12:22:01 -060022static int env_remote_init(void)
Liu Gang85bcd732012-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 Glass4bc2ad22017-08-03 12:21:56 -060026 gd->env_valid = ENV_VALID;
Liu Gang85bcd732012-03-08 00:33:20 +000027 return 0;
28 }
29
Simon Glassd40d8042017-08-03 12:22:02 -060030 return -ENOENT;
Liu Gang85bcd732012-03-08 00:33:20 +000031}
32
33#ifdef CONFIG_CMD_SAVEENV
Simon Glass082af922017-08-03 12:22:01 -060034static int env_remote_save(void)
Liu Gang85bcd732012-03-08 00:33:20 +000035{
Liu Gangb4611ee2012-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 Gang85bcd732012-03-08 00:33:20 +000038 return 1;
39#else
40 return 0;
41#endif
42}
43#endif /* CONFIG_CMD_SAVEENV */
44
Simon Glass99778492017-08-03 12:22:17 -060045static int env_remote_load(void)
Liu Gang85bcd732012-03-08 00:33:20 +000046{
47#ifndef ENV_IS_EMBEDDED
Marek Vasutdfe4b7e2020-07-07 20:51:35 +020048 return env_import((char *)env_ptr, 1, H_EXTERNAL);
Liu Gang85bcd732012-03-08 00:33:20 +000049#endif
Simon Glass99778492017-08-03 12:22:17 -060050
51 return 0;
Liu Gang85bcd732012-03-08 00:33:20 +000052}
Simon Glassc10a88e2017-08-03 12:21:58 -060053
54U_BOOT_ENV_LOCATION(remote) = {
55 .location = ENVL_REMOTE,
Simon Glassd8273ed2017-08-03 12:22:03 -060056 ENV_NAME("Remote")
Simon Glass082af922017-08-03 12:22:01 -060057 .load = env_remote_load,
58 .save = env_save_ptr(env_remote_save),
59 .init = env_remote_init,
Simon Glassc10a88e2017-08-03 12:21:58 -060060};