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