diff options
Diffstat (limited to 'meta/packages/uboot/u-boot-mkimage-openmoko-native/env_nand_oob.patch')
-rw-r--r-- | meta/packages/uboot/u-boot-mkimage-openmoko-native/env_nand_oob.patch | 198 |
1 files changed, 198 insertions, 0 deletions
diff --git a/meta/packages/uboot/u-boot-mkimage-openmoko-native/env_nand_oob.patch b/meta/packages/uboot/u-boot-mkimage-openmoko-native/env_nand_oob.patch new file mode 100644 index 0000000000..5a2dd61461 --- /dev/null +++ b/meta/packages/uboot/u-boot-mkimage-openmoko-native/env_nand_oob.patch | |||
@@ -0,0 +1,198 @@ | |||
1 | This patch adds support for CFG_ENV_OFFSET_PATCHED and | ||
2 | CFG_ENV_OFFSET_OOB. | ||
3 | |||
4 | Both try to solve the problem of fixing the environment location in NAND flash | ||
5 | at compile time, which doesn't work well if the NAND flash has a bad block at | ||
6 | exactly that location. | ||
7 | |||
8 | CFG_ENV_OFFSET_PATCHED puts the environment in a global variable. You can then | ||
9 | use the linker script to put that variable to a fixed location in the u-boot | ||
10 | image. Then you can use bianry patching during the production flash process. | ||
11 | |||
12 | The idea of CFG_ENV_OFFSET_OOB is to store the environment offset in the NAND | ||
13 | OOB data of block 0. We can do this in case the vendor makes a guarantee that | ||
14 | block 0 never is a factory-default bad block. | ||
15 | |||
16 | Signed-off-by: Harald Welte <laforge@openmoko.org> | ||
17 | |||
18 | Index: u-boot/common/env_nand.c | ||
19 | =================================================================== | ||
20 | --- u-boot.orig/common/env_nand.c | ||
21 | +++ u-boot/common/env_nand.c | ||
22 | @@ -271,6 +271,33 @@ | ||
23 | ulong total; | ||
24 | int ret; | ||
25 | |||
26 | +#if defined(CFG_ENV_OFFSET_OOB) | ||
27 | + struct mtd_info *mtd = &nand_info[0]; | ||
28 | + struct nand_chip *this = mtd->priv; | ||
29 | + int buf_len; | ||
30 | + uint8_t *buf; | ||
31 | + | ||
32 | + buf_len = (1 << this->bbt_erase_shift); | ||
33 | + buf_len += (buf_len >> this->page_shift) * mtd->oobsize; | ||
34 | + buf = malloc(buf_len); | ||
35 | + if (!buf) | ||
36 | + return; | ||
37 | + | ||
38 | + nand_read_raw(mtd, buf, 0, mtd->oobblock, mtd->oobsize); | ||
39 | + if (buf[mtd->oobblock + 8 + 0] == 'E' && | ||
40 | + buf[mtd->oobblock + 8 + 1] == 'N' && | ||
41 | + buf[mtd->oobblock + 8 + 2] == 'V' && | ||
42 | + buf[mtd->oobblock + 8 + 3] == '0') { | ||
43 | + CFG_ENV_OFFSET = *((unsigned long *) &buf[mtd->oobblock + 8 + 4]); | ||
44 | + /* fall through to the normal environment reading code below */ | ||
45 | + free(buf); | ||
46 | + puts("Found Environment offset in OOB..\n"); | ||
47 | + } else { | ||
48 | + free(buf); | ||
49 | + return use_default(); | ||
50 | + } | ||
51 | +#endif | ||
52 | + | ||
53 | total = CFG_ENV_SIZE; | ||
54 | ret = nand_read(&nand_info[0], CFG_ENV_OFFSET, &total, (u_char*)env_ptr); | ||
55 | if (ret || total != CFG_ENV_SIZE) | ||
56 | Index: u-boot/common/environment.c | ||
57 | =================================================================== | ||
58 | --- u-boot.orig/common/environment.c | ||
59 | +++ u-boot/common/environment.c | ||
60 | @@ -29,6 +29,12 @@ | ||
61 | #undef __ASSEMBLY__ | ||
62 | #include <environment.h> | ||
63 | |||
64 | +#if defined(CFG_ENV_OFFSET_PATCHED) | ||
65 | +unsigned long env_offset = CFG_ENV_OFFSET_PATCHED; | ||
66 | +#elif defined(CFG_ENV_OFFSET_OOB) | ||
67 | +unsigned long env_offset = CFG_ENV_OFFSET_OOB; | ||
68 | +#endif | ||
69 | + | ||
70 | /* | ||
71 | * Handle HOSTS that have prepended | ||
72 | * crap on symbol names, not TARGETS. | ||
73 | Index: u-boot/include/environment.h | ||
74 | =================================================================== | ||
75 | --- u-boot.orig/include/environment.h | ||
76 | +++ u-boot/include/environment.h | ||
77 | @@ -70,6 +70,10 @@ | ||
78 | #endif /* CFG_ENV_IS_IN_FLASH */ | ||
79 | |||
80 | #if defined(CFG_ENV_IS_IN_NAND) | ||
81 | +#if defined(CFG_ENV_OFFSET_PATCHED) || defined(CFG_ENV_OFFSET_OOB) | ||
82 | +extern unsigned long env_offset; | ||
83 | +#define CFG_ENV_OFFSET env_offset | ||
84 | +#else | ||
85 | # ifndef CFG_ENV_OFFSET | ||
86 | # error "Need to define CFG_ENV_OFFSET when using CFG_ENV_IS_IN_NAND" | ||
87 | # endif | ||
88 | @@ -82,6 +86,7 @@ | ||
89 | # ifdef CFG_ENV_IS_EMBEDDED | ||
90 | # define ENV_IS_EMBEDDED 1 | ||
91 | # endif | ||
92 | +#endif /* CFG_ENV_NAND_PATCHED */ | ||
93 | #endif /* CFG_ENV_IS_IN_NAND */ | ||
94 | |||
95 | |||
96 | Index: u-boot/common/Makefile | ||
97 | =================================================================== | ||
98 | --- u-boot.orig/common/Makefile | ||
99 | +++ u-boot/common/Makefile | ||
100 | @@ -31,7 +31,7 @@ | ||
101 | cmd_bdinfo.o cmd_bedbug.o cmd_bmp.o cmd_boot.o cmd_bootm.o \ | ||
102 | cmd_cache.o cmd_console.o \ | ||
103 | cmd_date.o cmd_dcr.o cmd_diag.o cmd_display.o cmd_doc.o cmd_dtt.o \ | ||
104 | - cmd_eeprom.o cmd_elf.o cmd_ext2.o \ | ||
105 | + cmd_dynenv.o cmd_eeprom.o cmd_elf.o cmd_ext2.o \ | ||
106 | cmd_fat.o cmd_fdc.o cmd_fdt.o cmd_fdos.o cmd_flash.o cmd_fpga.o \ | ||
107 | cmd_i2c.o cmd_ide.o cmd_immap.o cmd_itest.o cmd_jffs2.o \ | ||
108 | cmd_load.o cmd_log.o \ | ||
109 | Index: u-boot/common/cmd_dynenv.c | ||
110 | =================================================================== | ||
111 | --- /dev/null | ||
112 | +++ u-boot/common/cmd_dynenv.c | ||
113 | @@ -0,0 +1,85 @@ | ||
114 | +/* | ||
115 | + * (C) Copyright 2006-2007 OpenMoko, Inc. | ||
116 | + * Author: Harald Welte <laforge@openmoko.org> | ||
117 | + * | ||
118 | + * This program is free software; you can redistribute it and/or | ||
119 | + * modify it under the terms of the GNU General Public License as | ||
120 | + * published by the Free Software Foundation; either version 2 of | ||
121 | + * the License, or (at your option) any later version. | ||
122 | + * | ||
123 | + * This program is distributed in the hope that it will be useful, | ||
124 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
125 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
126 | + * GNU General Public License for more details. | ||
127 | + * | ||
128 | + * You should have received a copy of the GNU General Public License | ||
129 | + * along with this program; if not, write to the Free Software | ||
130 | + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, | ||
131 | + * MA 02111-1307 USA | ||
132 | + */ | ||
133 | + | ||
134 | +#include <common.h> | ||
135 | +#include <command.h> | ||
136 | +#include <malloc.h> | ||
137 | +#include <environment.h> | ||
138 | +#include <nand.h> | ||
139 | +#include <asm/errno.h> | ||
140 | + | ||
141 | +#if defined(CFG_ENV_OFFSET_OOB) | ||
142 | + | ||
143 | +int do_dynenv(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) | ||
144 | +{ | ||
145 | + struct mtd_info *mtd = &nand_info[0]; | ||
146 | + int ret, size = 8; | ||
147 | + uint8_t *buf; | ||
148 | + | ||
149 | + char *cmd = argv[1]; | ||
150 | + | ||
151 | + buf = malloc(mtd->oobsize); | ||
152 | + if (!buf) | ||
153 | + return -ENOMEM; | ||
154 | + | ||
155 | + if (!strcmp(cmd, "get")) { | ||
156 | + ret = mtd->read_oob(mtd, 8, size, (size_t *) &size, (u_char *) buf); | ||
157 | + | ||
158 | + if (buf[0] == 'E' && buf[1] == 'N' && | ||
159 | + buf[2] == 'V' && buf[3] == '0') | ||
160 | + printf("0x%08x\n", *((u_int32_t *) &buf[4])); | ||
161 | + else | ||
162 | + printf("No dynamic environment marker in OOB block 0\n"); | ||
163 | + | ||
164 | + } else if (!strcmp(cmd, "set")) { | ||
165 | + unsigned long addr; | ||
166 | + if (argc < 3) | ||
167 | + goto usage; | ||
168 | + | ||
169 | + buf[0] = 'E'; | ||
170 | + buf[1] = 'N'; | ||
171 | + buf[2] = 'V'; | ||
172 | + buf[3] = '0'; | ||
173 | + addr = simple_strtoul(argv[2], NULL, 16); | ||
174 | + memcpy(buf+4, &addr, 4); | ||
175 | + | ||
176 | + printf("%02x %02x %02x %02x - %02x %02x %02x %02x\n", | ||
177 | + buf[0], buf[1], buf[2], buf[3], | ||
178 | + buf[4], buf[5], buf[6], buf[7]); | ||
179 | + | ||
180 | + ret = mtd->write_oob(mtd, 8, size, (size_t *) &size, (u_char *) buf); | ||
181 | + } else | ||
182 | + goto usage; | ||
183 | + | ||
184 | + free(buf); | ||
185 | + return ret; | ||
186 | + | ||
187 | +usage: | ||
188 | + free(buf); | ||
189 | + printf("Usage:\n%s\n", cmdtp->usage); | ||
190 | + return 1; | ||
191 | +} | ||
192 | + | ||
193 | +U_BOOT_CMD(dynenv, 3, 1, do_dynenv, | ||
194 | + "dynenv - dynamically placed (NAND) environment\n", | ||
195 | + "dynenv set off - set enviromnent offset\n" | ||
196 | + "dynenv get - get environment offset\n"); | ||
197 | + | ||
198 | +#endif /* CFG_ENV_OFFSET_OOB */ | ||