Liu Gang | 85bcd73 | 2012-03-08 00:33:20 +0000 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2011-2012 Freescale Semiconductor, Inc. |
| 3 | * |
Wolfgang Denk | bd8ec7e | 2013-10-07 13:07:26 +0200 | [diff] [blame] | 4 | * SPDX-License-Identifier: GPL-2.0+ |
Liu Gang | 85bcd73 | 2012-03-08 00:33:20 +0000 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | /* #define DEBUG */ |
| 8 | |
| 9 | #include <common.h> |
| 10 | #include <command.h> |
| 11 | #include <environment.h> |
| 12 | #include <linux/stddef.h> |
| 13 | |
Liu Gang | 85bcd73 | 2012-03-08 00:33:20 +0000 | [diff] [blame] | 14 | #ifdef ENV_IS_EMBEDDED |
| 15 | env_t *env_ptr = &environment; |
| 16 | #else /* ! ENV_IS_EMBEDDED */ |
| 17 | env_t *env_ptr = (env_t *)CONFIG_ENV_ADDR; |
| 18 | #endif /* ENV_IS_EMBEDDED */ |
| 19 | |
| 20 | DECLARE_GLOBAL_DATA_PTR; |
| 21 | |
| 22 | #if !defined(CONFIG_ENV_OFFSET) |
| 23 | #define CONFIG_ENV_OFFSET 0 |
| 24 | #endif |
| 25 | |
Simon Glass | 082af92 | 2017-08-03 12:22:01 -0600 | [diff] [blame] | 26 | static int env_remote_init(void) |
Liu Gang | 85bcd73 | 2012-03-08 00:33:20 +0000 | [diff] [blame] | 27 | { |
| 28 | if (crc32(0, env_ptr->data, ENV_SIZE) == env_ptr->crc) { |
| 29 | gd->env_addr = (ulong)&(env_ptr->data); |
Simon Glass | 4bc2ad2 | 2017-08-03 12:21:56 -0600 | [diff] [blame] | 30 | gd->env_valid = ENV_VALID; |
Liu Gang | 85bcd73 | 2012-03-08 00:33:20 +0000 | [diff] [blame] | 31 | return 0; |
| 32 | } |
| 33 | |
Simon Glass | d40d804 | 2017-08-03 12:22:02 -0600 | [diff] [blame] | 34 | return -ENOENT; |
Liu Gang | 85bcd73 | 2012-03-08 00:33:20 +0000 | [diff] [blame] | 35 | } |
| 36 | |
| 37 | #ifdef CONFIG_CMD_SAVEENV |
Simon Glass | 082af92 | 2017-08-03 12:22:01 -0600 | [diff] [blame] | 38 | static int env_remote_save(void) |
Liu Gang | 85bcd73 | 2012-03-08 00:33:20 +0000 | [diff] [blame] | 39 | { |
Liu Gang | b4611ee | 2012-08-09 05:10:03 +0000 | [diff] [blame] | 40 | #ifdef CONFIG_SRIO_PCIE_BOOT_SLAVE |
| 41 | printf("Can not support the 'saveenv' when boot from SRIO or PCIE!\n"); |
Liu Gang | 85bcd73 | 2012-03-08 00:33:20 +0000 | [diff] [blame] | 42 | return 1; |
| 43 | #else |
| 44 | return 0; |
| 45 | #endif |
| 46 | } |
| 47 | #endif /* CONFIG_CMD_SAVEENV */ |
| 48 | |
Simon Glass | 9977849 | 2017-08-03 12:22:17 -0600 | [diff] [blame] | 49 | static int env_remote_load(void) |
Liu Gang | 85bcd73 | 2012-03-08 00:33:20 +0000 | [diff] [blame] | 50 | { |
| 51 | #ifndef ENV_IS_EMBEDDED |
| 52 | env_import((char *)env_ptr, 1); |
| 53 | #endif |
Simon Glass | 9977849 | 2017-08-03 12:22:17 -0600 | [diff] [blame] | 54 | |
| 55 | return 0; |
Liu Gang | 85bcd73 | 2012-03-08 00:33:20 +0000 | [diff] [blame] | 56 | } |
Simon Glass | c10a88e | 2017-08-03 12:21:58 -0600 | [diff] [blame] | 57 | |
| 58 | U_BOOT_ENV_LOCATION(remote) = { |
| 59 | .location = ENVL_REMOTE, |
Simon Glass | d8273ed | 2017-08-03 12:22:03 -0600 | [diff] [blame] | 60 | ENV_NAME("Remote") |
Simon Glass | 082af92 | 2017-08-03 12:22:01 -0600 | [diff] [blame] | 61 | .load = env_remote_load, |
| 62 | .save = env_save_ptr(env_remote_save), |
| 63 | .init = env_remote_init, |
Simon Glass | c10a88e | 2017-08-03 12:21:58 -0600 | [diff] [blame] | 64 | }; |