blob: b1a7d1a4c12e3d38e870b2f34a4ab36586355525 [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>
10#include <environment.h>
11#include <linux/stddef.h>
12
Liu Gang85bcd732012-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 Glass082af922017-08-03 12:22:01 -060025static int env_remote_init(void)
Liu Gang85bcd732012-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 Glass4bc2ad22017-08-03 12:21:56 -060029 gd->env_valid = ENV_VALID;
Liu Gang85bcd732012-03-08 00:33:20 +000030 return 0;
31 }
32
Simon Glassd40d8042017-08-03 12:22:02 -060033 return -ENOENT;
Liu Gang85bcd732012-03-08 00:33:20 +000034}
35
36#ifdef CONFIG_CMD_SAVEENV
Simon Glass082af922017-08-03 12:22:01 -060037static int env_remote_save(void)
Liu Gang85bcd732012-03-08 00:33:20 +000038{
Liu Gangb4611ee2012-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 Gang85bcd732012-03-08 00:33:20 +000041 return 1;
42#else
43 return 0;
44#endif
45}
46#endif /* CONFIG_CMD_SAVEENV */
47
Simon Glass99778492017-08-03 12:22:17 -060048static int env_remote_load(void)
Liu Gang85bcd732012-03-08 00:33:20 +000049{
50#ifndef ENV_IS_EMBEDDED
Simon Goldschmidt35b4c322018-01-31 14:47:12 +010051 return env_import((char *)env_ptr, 1);
Liu Gang85bcd732012-03-08 00:33:20 +000052#endif
Simon Glass99778492017-08-03 12:22:17 -060053
54 return 0;
Liu Gang85bcd732012-03-08 00:33:20 +000055}
Simon Glassc10a88e2017-08-03 12:21:58 -060056
57U_BOOT_ENV_LOCATION(remote) = {
58 .location = ENVL_REMOTE,
Simon Glassd8273ed2017-08-03 12:22:03 -060059 ENV_NAME("Remote")
Simon Glass082af922017-08-03 12:22:01 -060060 .load = env_remote_load,
61 .save = env_save_ptr(env_remote_save),
62 .init = env_remote_init,
Simon Glassc10a88e2017-08-03 12:21:58 -060063};