Merge tag 'rpi-next-2020.01' of https://github.com/mbgg/u-boot
[platform/kernel/u-boot.git] / env / remote.c
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * (C) Copyright 2011-2012 Freescale Semiconductor, Inc.
4  */
5
6 /* #define DEBUG */
7
8 #include <common.h>
9 #include <command.h>
10 #include <env_internal.h>
11 #include <linux/stddef.h>
12
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 static int env_remote_init(void)
22 {
23         if (crc32(0, env_ptr->data, ENV_SIZE) == env_ptr->crc) {
24                 gd->env_addr = (ulong)&(env_ptr->data);
25                 gd->env_valid = ENV_VALID;
26                 return 0;
27         }
28
29         return -ENOENT;
30 }
31
32 #ifdef CONFIG_CMD_SAVEENV
33 static int env_remote_save(void)
34 {
35 #ifdef CONFIG_SRIO_PCIE_BOOT_SLAVE
36         printf("Can not support the 'saveenv' when boot from SRIO or PCIE!\n");
37         return 1;
38 #else
39         return 0;
40 #endif
41 }
42 #endif /* CONFIG_CMD_SAVEENV */
43
44 static int env_remote_load(void)
45 {
46 #ifndef ENV_IS_EMBEDDED
47         return env_import((char *)env_ptr, 1);
48 #endif
49
50         return 0;
51 }
52
53 U_BOOT_ENV_LOCATION(remote) = {
54         .location       = ENVL_REMOTE,
55         ENV_NAME("Remote")
56         .load           = env_remote_load,
57         .save           = env_save_ptr(env_remote_save),
58         .init           = env_remote_init,
59 };