xref: /OK3568_Linux_fs/u-boot/env/remote.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun  * (C) Copyright 2011-2012 Freescale Semiconductor, Inc.
3*4882a593Smuzhiyun  *
4*4882a593Smuzhiyun  * SPDX-License-Identifier:	GPL-2.0+
5*4882a593Smuzhiyun  */
6*4882a593Smuzhiyun 
7*4882a593Smuzhiyun /* #define DEBUG */
8*4882a593Smuzhiyun 
9*4882a593Smuzhiyun #include <common.h>
10*4882a593Smuzhiyun #include <command.h>
11*4882a593Smuzhiyun #include <environment.h>
12*4882a593Smuzhiyun #include <linux/stddef.h>
13*4882a593Smuzhiyun 
14*4882a593Smuzhiyun #ifdef ENV_IS_EMBEDDED
15*4882a593Smuzhiyun env_t *env_ptr = &environment;
16*4882a593Smuzhiyun #else /* ! ENV_IS_EMBEDDED */
17*4882a593Smuzhiyun env_t *env_ptr = (env_t *)CONFIG_ENV_ADDR;
18*4882a593Smuzhiyun #endif /* ENV_IS_EMBEDDED */
19*4882a593Smuzhiyun 
20*4882a593Smuzhiyun DECLARE_GLOBAL_DATA_PTR;
21*4882a593Smuzhiyun 
22*4882a593Smuzhiyun #if !defined(CONFIG_ENV_OFFSET)
23*4882a593Smuzhiyun #define CONFIG_ENV_OFFSET 0
24*4882a593Smuzhiyun #endif
25*4882a593Smuzhiyun 
env_remote_init(void)26*4882a593Smuzhiyun static int env_remote_init(void)
27*4882a593Smuzhiyun {
28*4882a593Smuzhiyun 	if (crc32(0, env_ptr->data, ENV_SIZE) == env_ptr->crc) {
29*4882a593Smuzhiyun 		gd->env_addr = (ulong)&(env_ptr->data);
30*4882a593Smuzhiyun 		gd->env_valid = ENV_VALID;
31*4882a593Smuzhiyun 		return 0;
32*4882a593Smuzhiyun 	}
33*4882a593Smuzhiyun 
34*4882a593Smuzhiyun 	return -ENOENT;
35*4882a593Smuzhiyun }
36*4882a593Smuzhiyun 
37*4882a593Smuzhiyun #ifdef CONFIG_CMD_SAVEENV
env_remote_save(void)38*4882a593Smuzhiyun static int env_remote_save(void)
39*4882a593Smuzhiyun {
40*4882a593Smuzhiyun #ifdef CONFIG_SRIO_PCIE_BOOT_SLAVE
41*4882a593Smuzhiyun 	printf("Can not support the 'saveenv' when boot from SRIO or PCIE!\n");
42*4882a593Smuzhiyun 	return 1;
43*4882a593Smuzhiyun #else
44*4882a593Smuzhiyun 	return 0;
45*4882a593Smuzhiyun #endif
46*4882a593Smuzhiyun }
47*4882a593Smuzhiyun #endif /* CONFIG_CMD_SAVEENV */
48*4882a593Smuzhiyun 
env_remote_load(void)49*4882a593Smuzhiyun static int env_remote_load(void)
50*4882a593Smuzhiyun {
51*4882a593Smuzhiyun #ifndef ENV_IS_EMBEDDED
52*4882a593Smuzhiyun 	env_import((char *)env_ptr, 1);
53*4882a593Smuzhiyun #endif
54*4882a593Smuzhiyun 
55*4882a593Smuzhiyun 	return 0;
56*4882a593Smuzhiyun }
57*4882a593Smuzhiyun 
58*4882a593Smuzhiyun U_BOOT_ENV_LOCATION(remote) = {
59*4882a593Smuzhiyun 	.location	= ENVL_REMOTE,
60*4882a593Smuzhiyun 	ENV_NAME("Remote")
61*4882a593Smuzhiyun 	.load		= env_remote_load,
62*4882a593Smuzhiyun 	.save		= env_save_ptr(env_remote_save),
63*4882a593Smuzhiyun 	.init		= env_remote_init,
64*4882a593Smuzhiyun };
65