blob: 0cc383c23602e3fdf353a47c77bf1ee752988da6 [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
Liu Gang85bcd732012-03-08 00:33:20 +00008#include <command.h>
Simon Glass9d1f6192019-08-02 09:44:25 -06009#include <env_internal.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060010#include <asm/global_data.h>
Tom Rinidec7ea02024-05-20 13:35:03 -060011#include <linux/errno.h>
Liu Gang85bcd732012-03-08 00:33:20 +000012#include <linux/stddef.h>
Simon Glass48b6c6b2019-11-14 12:57:16 -070013#include <u-boot/crc.h>
Liu Gang85bcd732012-03-08 00:33:20 +000014
Liu Gang85bcd732012-03-08 00:33:20 +000015#ifdef ENV_IS_EMBEDDED
Rasmus Villemoes5d18fc12020-02-18 08:54:09 +000016static env_t *env_ptr = &environment;
Liu Gang85bcd732012-03-08 00:33:20 +000017#else /* ! ENV_IS_EMBEDDED */
Rasmus Villemoes5d18fc12020-02-18 08:54:09 +000018static env_t *env_ptr = (env_t *)CONFIG_ENV_ADDR;
Liu Gang85bcd732012-03-08 00:33:20 +000019#endif /* ENV_IS_EMBEDDED */
20
21DECLARE_GLOBAL_DATA_PTR;
22
Simon Glass082af922017-08-03 12:22:01 -060023static int env_remote_init(void)
Liu Gang85bcd732012-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 Glass4bc2ad22017-08-03 12:21:56 -060027 gd->env_valid = ENV_VALID;
Liu Gang85bcd732012-03-08 00:33:20 +000028 return 0;
29 }
30
Simon Glassd40d8042017-08-03 12:22:02 -060031 return -ENOENT;
Liu Gang85bcd732012-03-08 00:33:20 +000032}
33
34#ifdef CONFIG_CMD_SAVEENV
Simon Glass082af922017-08-03 12:22:01 -060035static int env_remote_save(void)
Liu Gang85bcd732012-03-08 00:33:20 +000036{
Liu Gangb4611ee2012-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 Gang85bcd732012-03-08 00:33:20 +000039 return 1;
40#else
41 return 0;
42#endif
43}
44#endif /* CONFIG_CMD_SAVEENV */
45
Simon Glass99778492017-08-03 12:22:17 -060046static int env_remote_load(void)
Liu Gang85bcd732012-03-08 00:33:20 +000047{
48#ifndef ENV_IS_EMBEDDED
Marek Vasutdfe4b7e2020-07-07 20:51:35 +020049 return env_import((char *)env_ptr, 1, H_EXTERNAL);
Liu Gang85bcd732012-03-08 00:33:20 +000050#endif
Simon Glass99778492017-08-03 12:22:17 -060051
52 return 0;
Liu Gang85bcd732012-03-08 00:33:20 +000053}
Simon Glassc10a88e2017-08-03 12:21:58 -060054
55U_BOOT_ENV_LOCATION(remote) = {
56 .location = ENVL_REMOTE,
Simon Glassd8273ed2017-08-03 12:22:03 -060057 ENV_NAME("Remote")
Simon Glass082af922017-08-03 12:22:01 -060058 .load = env_remote_load,
59 .save = env_save_ptr(env_remote_save),
60 .init = env_remote_init,
Simon Glassc10a88e2017-08-03 12:21:58 -060061};