Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Liu Gang | 0a85a9e | 2012-03-08 00:33:20 +0000 | [diff] [blame] | 2 | /* |
3 | * (C) Copyright 2011-2012 Freescale Semiconductor, Inc. | ||||
Liu Gang | 0a85a9e | 2012-03-08 00:33:20 +0000 | [diff] [blame] | 4 | */ |
5 | |||||
6 | /* #define DEBUG */ | ||||
7 | |||||
Liu Gang | 0a85a9e | 2012-03-08 00:33:20 +0000 | [diff] [blame] | 8 | #include <command.h> |
Simon Glass | f3998fd | 2019-08-02 09:44:25 -0600 | [diff] [blame] | 9 | #include <env_internal.h> |
Simon Glass | 401d1c4 | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 10 | #include <asm/global_data.h> |
Tom Rini | 0f92fa4 | 2024-04-27 08:11:03 -0600 | [diff] [blame] | 11 | #include <linux/errno.h> |
Liu Gang | 0a85a9e | 2012-03-08 00:33:20 +0000 | [diff] [blame] | 12 | #include <linux/stddef.h> |
Simon Glass | 3db7110 | 2019-11-14 12:57:16 -0700 | [diff] [blame] | 13 | #include <u-boot/crc.h> |
Liu Gang | 0a85a9e | 2012-03-08 00:33:20 +0000 | [diff] [blame] | 14 | |
Liu Gang | 0a85a9e | 2012-03-08 00:33:20 +0000 | [diff] [blame] | 15 | #ifdef ENV_IS_EMBEDDED |
Rasmus Villemoes | 46d9d1c | 2020-02-18 08:54:09 +0000 | [diff] [blame] | 16 | static env_t *env_ptr = &environment; |
Liu Gang | 0a85a9e | 2012-03-08 00:33:20 +0000 | [diff] [blame] | 17 | #else /* ! ENV_IS_EMBEDDED */ |
Rasmus Villemoes | 46d9d1c | 2020-02-18 08:54:09 +0000 | [diff] [blame] | 18 | static env_t *env_ptr = (env_t *)CONFIG_ENV_ADDR; |
Liu Gang | 0a85a9e | 2012-03-08 00:33:20 +0000 | [diff] [blame] | 19 | #endif /* ENV_IS_EMBEDDED */ |
20 | |||||
21 | DECLARE_GLOBAL_DATA_PTR; | ||||
22 | |||||
Simon Glass | e5bce24 | 2017-08-03 12:22:01 -0600 | [diff] [blame] | 23 | static int env_remote_init(void) |
Liu Gang | 0a85a9e | 2012-03-08 00:33:20 +0000 | [diff] [blame] | 24 | { |
25 | if (crc32(0, env_ptr->data, ENV_SIZE) == env_ptr->crc) { | ||||
26 | gd->env_addr = (ulong)&(env_ptr->data); | ||||
Simon Glass | 203e94f | 2017-08-03 12:21:56 -0600 | [diff] [blame] | 27 | gd->env_valid = ENV_VALID; |
Liu Gang | 0a85a9e | 2012-03-08 00:33:20 +0000 | [diff] [blame] | 28 | return 0; |
29 | } | ||||
30 | |||||
Simon Glass | 7938822 | 2017-08-03 12:22:02 -0600 | [diff] [blame] | 31 | return -ENOENT; |
Liu Gang | 0a85a9e | 2012-03-08 00:33:20 +0000 | [diff] [blame] | 32 | } |
33 | |||||
34 | #ifdef CONFIG_CMD_SAVEENV | ||||
Simon Glass | e5bce24 | 2017-08-03 12:22:01 -0600 | [diff] [blame] | 35 | static int env_remote_save(void) |
Liu Gang | 0a85a9e | 2012-03-08 00:33:20 +0000 | [diff] [blame] | 36 | { |
Liu Gang | 461632b | 2012-08-09 05:10:03 +0000 | [diff] [blame] | 37 | #ifdef CONFIG_SRIO_PCIE_BOOT_SLAVE |
38 | printf("Can not support the 'saveenv' when boot from SRIO or PCIE!\n"); | ||||
Liu Gang | 0a85a9e | 2012-03-08 00:33:20 +0000 | [diff] [blame] | 39 | return 1; |
40 | #else | ||||
41 | return 0; | ||||
42 | #endif | ||||
43 | } | ||||
44 | #endif /* CONFIG_CMD_SAVEENV */ | ||||
45 | |||||
Simon Glass | c595199 | 2017-08-03 12:22:17 -0600 | [diff] [blame] | 46 | static int env_remote_load(void) |
Liu Gang | 0a85a9e | 2012-03-08 00:33:20 +0000 | [diff] [blame] | 47 | { |
48 | #ifndef ENV_IS_EMBEDDED | ||||
Marek Vasut | 890feec | 2020-07-07 20:51:35 +0200 | [diff] [blame] | 49 | return env_import((char *)env_ptr, 1, H_EXTERNAL); |
Liu Gang | 0a85a9e | 2012-03-08 00:33:20 +0000 | [diff] [blame] | 50 | #endif |
Simon Glass | c595199 | 2017-08-03 12:22:17 -0600 | [diff] [blame] | 51 | |
52 | return 0; | ||||
Liu Gang | 0a85a9e | 2012-03-08 00:33:20 +0000 | [diff] [blame] | 53 | } |
Simon Glass | 4415f1d | 2017-08-03 12:21:58 -0600 | [diff] [blame] | 54 | |
55 | U_BOOT_ENV_LOCATION(remote) = { | ||||
56 | .location = ENVL_REMOTE, | ||||
Simon Glass | ac358be | 2017-08-03 12:22:03 -0600 | [diff] [blame] | 57 | ENV_NAME("Remote") |
Simon Glass | e5bce24 | 2017-08-03 12:22:01 -0600 | [diff] [blame] | 58 | .load = env_remote_load, |
59 | .save = env_save_ptr(env_remote_save), | ||||
60 | .init = env_remote_init, | ||||
Simon Glass | 4415f1d | 2017-08-03 12:21:58 -0600 | [diff] [blame] | 61 | }; |