summaryrefslogtreecommitdiff
path: root/packages/u-boot/u-boot-mkimage-openmoko-native/default-env.patch
blob: b9ae4f29fe22c367c79389c0f464f7fd3343f8fb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
common/env_common.c (default_env): new function that resets the environment to
  the default value
common/env_common.c (env_relocate): use default_env instead of own copy
common/env_nand.c (env_relocate_spec): use default_env instead of own copy
include/environment.h: added default_env prototype

- Werner Almesberger <werner@openmoko.org>

Index: u-boot/common/env_common.c
===================================================================
--- u-boot.orig/common/env_common.c
+++ u-boot/common/env_common.c
@@ -202,6 +202,25 @@ uchar *env_get_addr (int index)
 	}
 }
 
+void default_env(void)
+{
+	if (sizeof(default_environment) > ENV_SIZE)
+	{
+		puts ("*** Error - default environment is too large\n\n");
+		return;
+	}
+
+	memset (env_ptr, 0, sizeof(env_t));
+	memcpy (env_ptr->data,
+		default_environment,
+		sizeof(default_environment));
+#ifdef CFG_REDUNDAND_ENVIRONMENT
+	env_ptr->flags = 0xFF;
+#endif
+	env_crc_update ();
+	gd->env_valid = 1;
+}
+
 void env_relocate (void)
 {
 	DEBUGF ("%s[%d] offset = 0x%lx\n", __FUNCTION__,__LINE__,
@@ -245,23 +264,8 @@ void env_relocate (void)
 		gd->env_valid = 0;
 #endif
 
-	if (gd->env_valid == 0) {
-		if (sizeof(default_environment) > ENV_SIZE)
-		{
-			puts ("*** Error - default environment is too large\n\n");
-			return;
-		}
-
-		memset (env_ptr, 0, sizeof(env_t));
-		memcpy (env_ptr->data,
-			default_environment,
-			sizeof(default_environment));
-#ifdef CFG_REDUNDAND_ENVIRONMENT
-		env_ptr->flags = 0xFF;
-#endif
-		env_crc_update ();
-		gd->env_valid = 1;
-	}
+	if (gd->env_valid == 0)
+		default_env();
 	else {
 		env_relocate_spec ();
 	}
Index: u-boot/common/env_nand.c
===================================================================
--- u-boot.orig/common/env_nand.c
+++ u-boot/common/env_nand.c
@@ -313,19 +313,7 @@ void env_relocate_spec (void)
 static void use_default()
 {
 	puts ("*** Warning - bad CRC or NAND, using default environment\n\n");
-
-	if (default_environment_size > CFG_ENV_SIZE){
-		puts ("*** Error - default environment is too large\n\n");
-		return;
-	}
-
-	memset (env_ptr, 0, sizeof(env_t));
-	memcpy (env_ptr->data,
-			default_environment,
-			default_environment_size);
-	env_ptr->crc = crc32(0, env_ptr->data, ENV_SIZE);
-	gd->env_valid = 1;
-
+	default_env();
 }
 #endif
 
Index: u-boot/include/environment.h
===================================================================
--- u-boot.orig/include/environment.h
+++ u-boot/include/environment.h
@@ -107,4 +107,7 @@ typedef	struct environment_s {
 	unsigned char	data[ENV_SIZE]; /* Environment data		*/
 } env_t;
 
+
+void default_env(void);
+
 #endif	/* _ENVIRONMENT_H_ */