blob: 166bebf52b5b577c7b8f2310b610e886199b4557 [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>
Simon Glass401d1c42020-10-30 21:38:53 -060011#include <asm/global_data.h>
Liu Gang0a85a9e2012-03-08 00:33:20 +000012#include <linux/stddef.h>
Simon Glass3db71102019-11-14 12:57:16 -070013#include <u-boot/crc.h>
Liu Gang0a85a9e2012-03-08 00:33:20 +000014
Liu Gang0a85a9e2012-03-08 00:33:20 +000015#ifdef ENV_IS_EMBEDDED
Rasmus Villemoes46d9d1c2020-02-18 08:54:09 +000016static env_t *env_ptr = &environment;
Liu Gang0a85a9e2012-03-08 00:33:20 +000017#else /* ! ENV_IS_EMBEDDED */
Rasmus Villemoes46d9d1c2020-02-18 08:54:09 +000018static env_t *env_ptr = (env_t *)CONFIG_ENV_ADDR;
Liu Gang0a85a9e2012-03-08 00:33:20 +000019#endif /* ENV_IS_EMBEDDED */
20
21DECLARE_GLOBAL_DATA_PTR;
22
Simon Glasse5bce242017-08-03 12:22:01 -060023static int env_remote_init(void)
Liu Gang0a85a9e2012-03-08 00:33:20 +000024{
25 if (crc32(0, env_ptr->data, ENV_SIZE) == env_ptr->crc) {
26 gd->env_addr = (ulong)&(env_ptr->data);
Simon Glass203e94f2017-08-03 12:21:56 -060027 gd->env_valid = ENV_VALID;
Liu Gang0a85a9e2012-03-08 00:33:20 +000028 return 0;
29 }
30
Simon Glass79388222017-08-03 12:22:02 -060031 return -ENOENT;
Liu Gang0a85a9e2012-03-08 00:33:20 +000032}
33
34#ifdef CONFIG_CMD_SAVEENV
Simon Glasse5bce242017-08-03 12:22:01 -060035static int env_remote_save(void)
Liu Gang0a85a9e2012-03-08 00:33:20 +000036{
Liu Gang461632b2012-08-09 05:10:03 +000037#ifdef CONFIG_SRIO_PCIE_BOOT_SLAVE
38 printf("Can not support the 'saveenv' when boot from SRIO or PCIE!\n");
Liu Gang0a85a9e2012-03-08 00:33:20 +000039 return 1;
40#else
41 return 0;
42#endif
43}
44#endif /* CONFIG_CMD_SAVEENV */
45
Simon Glassc5951992017-08-03 12:22:17 -060046static int env_remote_load(void)
Liu Gang0a85a9e2012-03-08 00:33:20 +000047{
48#ifndef ENV_IS_EMBEDDED
Marek Vasut890feec2020-07-07 20:51:35 +020049 return env_import((char *)env_ptr, 1, H_EXTERNAL);
Liu Gang0a85a9e2012-03-08 00:33:20 +000050#endif
Simon Glassc5951992017-08-03 12:22:17 -060051
52 return 0;
Liu Gang0a85a9e2012-03-08 00:33:20 +000053}
Simon Glass4415f1d2017-08-03 12:21:58 -060054
55U_BOOT_ENV_LOCATION(remote) = {
56 .location = ENVL_REMOTE,
Simon Glassac358be2017-08-03 12:22:03 -060057 ENV_NAME("Remote")
Simon Glasse5bce242017-08-03 12:22:01 -060058 .load = env_remote_load,
59 .save = env_save_ptr(env_remote_save),
60 .init = env_remote_init,
Simon Glass4415f1d2017-08-03 12:21:58 -060061};