summaryrefslogtreecommitdiffstats
path: root/meta/packages/uboot/u-boot-mkimage-openmoko-native/dynenv-harden.patch
diff options
context:
space:
mode:
Diffstat (limited to 'meta/packages/uboot/u-boot-mkimage-openmoko-native/dynenv-harden.patch')
-rw-r--r--meta/packages/uboot/u-boot-mkimage-openmoko-native/dynenv-harden.patch139
1 files changed, 0 insertions, 139 deletions
diff --git a/meta/packages/uboot/u-boot-mkimage-openmoko-native/dynenv-harden.patch b/meta/packages/uboot/u-boot-mkimage-openmoko-native/dynenv-harden.patch
deleted file mode 100644
index cf12352553..0000000000
--- a/meta/packages/uboot/u-boot-mkimage-openmoko-native/dynenv-harden.patch
+++ /dev/null
@@ -1,139 +0,0 @@
1common/cmd_nand.c: globalized arg_off_size
2include/util.h: new header to convenience functions, such as arg_off_size
3common/cmd_dynenv.c (do_dynenv): use arg_off_size to sanity-check offset and to
4 allow use of partition name
5common/cmd_dynenv.c (do_dynenv): indicate in no uncertain terms when an update
6 would not work due to Flash bits already cleared
7common/cmd_dynenv.c (do_dynenv): update CFG_ENV_OFFSET after successful "dynenv
8 set", so that we can write the new environment without having to reboot
9
10- Werner Almesberger <werner@openmoko.org>
11
12Index: u-boot/common/cmd_nand.c
13===================================================================
14--- u-boot.orig/common/cmd_nand.c
15+++ u-boot/common/cmd_nand.c
16@@ -100,7 +100,7 @@ static inline int str2long(char *p, ulon
17 return (*p != '\0' && *endptr == '\0') ? 1 : 0;
18 }
19
20-static int
21+int
22 arg_off_size(int argc, char *argv[], nand_info_t *nand, ulong *off, ulong *size)
23 {
24 int idx = nand_curr_device;
25Index: u-boot/include/util.h
26===================================================================
27--- /dev/null
28+++ u-boot/include/util.h
29@@ -0,0 +1,33 @@
30+/*
31+ * util.h - Convenience functions
32+ *
33+ * (C) Copyright 2006-2007 OpenMoko, Inc.
34+ * Author: Werner Almesberger <werner@openmoko.org>
35+ *
36+ * This program is free software; you can redistribute it and/or
37+ * modify it under the terms of the GNU General Public License as
38+ * published by the Free Software Foundation; either version 2 of
39+ * the License, or (at your option) any later version.
40+ *
41+ * This program is distributed in the hope that it will be useful,
42+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
43+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
44+ * GNU General Public License for more details.
45+ *
46+ * You should have received a copy of the GNU General Public License
47+ * along with this program; if not, write to the Free Software
48+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
49+ * MA 02111-1307 USA
50+ */
51+
52+#ifndef UTIL_H
53+#define UTIL_H
54+
55+#include "nand.h"
56+
57+
58+/* common/cmd_nand.c */
59+int arg_off_size(int argc, char *argv[], nand_info_t *nand, ulong *off,
60+ ulong *size);
61+
62+#endif /* UTIL_H */
63Index: u-boot/common/cmd_dynenv.c
64===================================================================
65--- u-boot.orig/common/cmd_dynenv.c
66+++ u-boot/common/cmd_dynenv.c
67@@ -23,6 +23,7 @@
68 #include <malloc.h>
69 #include <environment.h>
70 #include <nand.h>
71+#include <util.h>
72 #include <asm/errno.h>
73
74 #if defined(CFG_ENV_OFFSET_OOB)
75@@ -39,8 +40,8 @@ int do_dynenv(cmd_tbl_t *cmdtp, int flag
76 if (!buf)
77 return -ENOMEM;
78
79+ ret = mtd->read_oob(mtd, 8, size, (size_t *) &size, (u_char *) buf);
80 if (!strcmp(cmd, "get")) {
81- ret = mtd->read_oob(mtd, 8, size, (size_t *) &size, (u_char *) buf);
82
83 if (buf[0] == 'E' && buf[1] == 'N' &&
84 buf[2] == 'V' && buf[3] == '0')
85@@ -49,7 +50,8 @@ int do_dynenv(cmd_tbl_t *cmdtp, int flag
86 printf("No dynamic environment marker in OOB block 0\n");
87
88 } else if (!strcmp(cmd, "set")) {
89- unsigned long addr;
90+ unsigned long addr, dummy;
91+
92 if (argc < 3)
93 goto usage;
94
95@@ -57,7 +59,23 @@ int do_dynenv(cmd_tbl_t *cmdtp, int flag
96 buf[1] = 'N';
97 buf[2] = 'V';
98 buf[3] = '0';
99- addr = simple_strtoul(argv[2], NULL, 16);
100+
101+ if (arg_off_size(argc-2, argv+2, mtd, &addr, &dummy) < 0) {
102+ printf("Offset or partition name expected\n");
103+ goto fail;
104+ }
105+ if (!ret) {
106+ uint8_t tmp[4];
107+ int i;
108+
109+ memcpy(&tmp, &addr, 4);
110+ for (i = 0; i != 4; i++)
111+ if (tmp[i] & ~buf[i+4]) {
112+ printf("ERROR: erase OOB block to "
113+ "write this value\n");
114+ goto fail;
115+ }
116+ }
117 memcpy(buf+4, &addr, 4);
118
119 printf("%02x %02x %02x %02x - %02x %02x %02x %02x\n",
120@@ -65,6 +83,8 @@ int do_dynenv(cmd_tbl_t *cmdtp, int flag
121 buf[4], buf[5], buf[6], buf[7]);
122
123 ret = mtd->write_oob(mtd, 8, size, (size_t *) &size, (u_char *) buf);
124+ if (!ret)
125+ CFG_ENV_OFFSET = addr;
126 } else
127 goto usage;
128
129@@ -72,8 +92,9 @@ int do_dynenv(cmd_tbl_t *cmdtp, int flag
130 return ret;
131
132 usage:
133- free(buf);
134 printf("Usage:\n%s\n", cmdtp->usage);
135+fail:
136+ free(buf);
137 return 1;
138 }
139