Commit 13a5695b7c454d5a2a5a885002cfe0e18536dad9
1 parent
c3c7f861ae
Exists in
master
and in
54 other branches
Patch by Jian Zhang, 20 May 2004:
add support for environment in NAND flash
Showing 7 changed files with 193 additions and 5 deletions Side-by-side Diff
CHANGELOG
... | ... | @@ -2,6 +2,9 @@ |
2 | 2 | Changes since U-Boot 1.1.1: |
3 | 3 | ====================================================================== |
4 | 4 | |
5 | +* Patch by Jian Zhang, 20 May 2004: | |
6 | + add support for environment in NAND flash | |
7 | + | |
5 | 8 | * Patch by Yuli Barcohen, 20 May 2004: |
6 | 9 | Add support for Interphase iSPAN boards. |
7 | 10 |
README
... | ... | @@ -1827,6 +1827,16 @@ |
1827 | 1827 | environment area within the total memory of your DataFlash placed |
1828 | 1828 | at the specified address. |
1829 | 1829 | |
1830 | +- CFG_ENV_IS_IN_NAND: | |
1831 | + | |
1832 | + Define this if you have a NAND device which you want to use | |
1833 | + for the environment. | |
1834 | + | |
1835 | + - CFG_ENV_OFFSET: | |
1836 | + - CFG_ENV_SIZE: | |
1837 | + | |
1838 | + These two #defines specify the offset and size of the environment | |
1839 | + area within the first NAND device. | |
1830 | 1840 | |
1831 | 1841 | - CFG_SPI_INIT_OFFSET |
1832 | 1842 |
common/Makefile
... | ... | @@ -42,7 +42,7 @@ |
42 | 42 | cmd_reginfo.o cmd_reiser.o cmd_scsi.o cmd_spi.o cmd_usb.o cmd_vfd.o \ |
43 | 43 | command.o console.o devices.o dlmalloc.o docecc.o \ |
44 | 44 | environment.o env_common.o \ |
45 | - env_dataflash.o env_flash.o env_eeprom.o env_nvram.o env_nowhere.o exports.o \ | |
45 | + env_nand.o env_dataflash.o env_flash.o env_eeprom.o env_nvram.o env_nowhere.o exports.o \ | |
46 | 46 | flash.o fpga.o \ |
47 | 47 | hush.o kgdb.o lists.o lynxkdi.o memsize.o miiphybb.o miiphyutil.o \ |
48 | 48 | s_record.o soft_i2c.o soft_spi.o spartan2.o \ |
common/cmd_nand.c
... | ... | @@ -70,10 +70,10 @@ |
70 | 70 | * Function Prototypes |
71 | 71 | */ |
72 | 72 | static void nand_print(struct nand_chip *nand); |
73 | -static int nand_rw (struct nand_chip* nand, int cmd, | |
73 | +int nand_rw (struct nand_chip* nand, int cmd, | |
74 | 74 | size_t start, size_t len, |
75 | 75 | size_t * retlen, u_char * buf); |
76 | -static int nand_erase(struct nand_chip* nand, size_t ofs, size_t len, int clean); | |
76 | +int nand_erase(struct nand_chip* nand, size_t ofs, size_t len, int clean); | |
77 | 77 | static int nand_read_ecc(struct nand_chip *nand, size_t start, size_t len, |
78 | 78 | size_t * retlen, u_char *buf, u_char *ecc_code); |
79 | 79 | static int nand_write_ecc (struct nand_chip* nand, size_t to, size_t len, |
... | ... | @@ -429,7 +429,7 @@ |
429 | 429 | * 3: NANDRW_READ | NANDRW_JFFS2 read, data all 0xff for bad blocks |
430 | 430 | * 7: NANDRW_READ | NANDRW_JFFS2 | NANDRW_JFFS2_SKIP read, skip bad blocks |
431 | 431 | */ |
432 | -static int nand_rw (struct nand_chip* nand, int cmd, | |
432 | +int nand_rw (struct nand_chip* nand, int cmd, | |
433 | 433 | size_t start, size_t len, |
434 | 434 | size_t * retlen, u_char * buf) |
435 | 435 | { |
... | ... | @@ -1304,7 +1304,7 @@ |
1304 | 1304 | |
1305 | 1305 | } |
1306 | 1306 | |
1307 | -static int nand_erase(struct nand_chip* nand, size_t ofs, size_t len, int clean) | |
1307 | +int nand_erase(struct nand_chip* nand, size_t ofs, size_t len, int clean) | |
1308 | 1308 | { |
1309 | 1309 | /* This is defined as a structure so it will work on any system |
1310 | 1310 | * using native endian jffs2 (the default). |
common/cmd_nvedit.c
... | ... | @@ -53,6 +53,7 @@ |
53 | 53 | !defined(CFG_ENV_IS_IN_EEPROM) && \ |
54 | 54 | !defined(CFG_ENV_IS_IN_FLASH) && \ |
55 | 55 | !defined(CFG_ENV_IS_IN_DATAFLASH) && \ |
56 | + !defined(CFG_ENV_IS_IN_NAND) && \ | |
56 | 57 | !defined(CFG_ENV_IS_NOWHERE) |
57 | 58 | # error Define one of CFG_ENV_IS_IN_{NVRAM|EEPROM|FLASH|DATAFLASH|NOWHERE} |
58 | 59 | #endif |
common/env_common.c
common/env_nand.c
1 | +/* | |
2 | + * (C) Copyright 2004 | |
3 | + * Jian Zhang, Texas Instruments, jzhang@ti.com. | |
4 | + | |
5 | + * (C) Copyright 2000-2004 | |
6 | + * Wolfgang Denk, DENX Software Engineering, wd@denx.de. | |
7 | + * | |
8 | + * (C) Copyright 2001 Sysgo Real-Time Solutions, GmbH <www.elinos.com> | |
9 | + * Andreas Heppel <aheppel@sysgo.de> | |
10 | + | |
11 | + * See file CREDITS for list of people who contributed to this | |
12 | + * project. | |
13 | + * | |
14 | + * This program is free software; you can redistribute it and/or | |
15 | + * modify it under the terms of the GNU General Public License as | |
16 | + * published by the Free Software Foundation; either version 2 of | |
17 | + * the License, or (at your option) any later version. | |
18 | + * | |
19 | + * This program is distributed in the hope that it will be useful, | |
20 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
21 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
22 | + * GNU General Public License for more details. | |
23 | + * | |
24 | + * You should have received a copy of the GNU General Public License | |
25 | + * along with this program; if not, write to the Free Software | |
26 | + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, | |
27 | + * MA 02111-1307 USA | |
28 | + */ | |
29 | + | |
30 | +/* #define DEBUG */ | |
31 | + | |
32 | +#include <common.h> | |
33 | + | |
34 | +#if defined(CFG_ENV_IS_IN_NAND) /* Environment is in Nand Flash */ | |
35 | + | |
36 | +#include <command.h> | |
37 | +#include <environment.h> | |
38 | +#include <linux/stddef.h> | |
39 | +#include <malloc.h> | |
40 | +#include <linux/mtd/nand.h> | |
41 | + | |
42 | +#if ((CONFIG_COMMANDS&(CFG_CMD_ENV|CFG_CMD_NAND)) == (CFG_CMD_ENV|CFG_CMD_NAND)) | |
43 | +#define CMD_SAVEENV | |
44 | +#endif | |
45 | + | |
46 | +#if defined(CFG_ENV_SIZE_REDUND) | |
47 | +#error CFG_ENV_SIZE_REDUND not supported yet | |
48 | +#endif | |
49 | + | |
50 | +#if defined(CFG_ENV_ADDR_REDUND) | |
51 | +#error CFG_ENV_ADDR_REDUND and CFG_ENV_IS_IN_NAND not supported yet | |
52 | +#endif | |
53 | + | |
54 | + | |
55 | +#ifdef CONFIG_INFERNO | |
56 | +#error CONFIG_INFERNO not supported yet | |
57 | +#endif | |
58 | + | |
59 | +/* references to names in cmd_nand.c */ | |
60 | +#define NANDRW_READ 0x01 | |
61 | +#define NANDRW_WRITE 0x00 | |
62 | +#define NANDRW_JFFS2 0x02 | |
63 | +extern struct nand_chip nand_dev_desc[]; | |
64 | +int nand_rw (struct nand_chip* nand, int cmd, | |
65 | + size_t start, size_t len, | |
66 | + size_t * retlen, u_char * buf); | |
67 | +int nand_erase(struct nand_chip* nand, size_t ofs, | |
68 | + size_t len, int clean); | |
69 | + | |
70 | +/* references to names in env_common.c */ | |
71 | +extern uchar default_environment[]; | |
72 | +extern int default_environment_size; | |
73 | + | |
74 | +char * env_name_spec = "NAND"; | |
75 | + | |
76 | + | |
77 | +#ifdef ENV_IS_EMBEDDED | |
78 | +extern uchar environment[]; | |
79 | +env_t *env_ptr = (env_t *)(&environment[0]); | |
80 | +#else /* ! ENV_IS_EMBEDDED */ | |
81 | +env_t *env_ptr = 0; //(env_t *)CFG_ENV_ADDR; | |
82 | +#endif /* ENV_IS_EMBEDDED */ | |
83 | + | |
84 | + | |
85 | +/* local functions */ | |
86 | +static void use_default(void); | |
87 | + | |
88 | + | |
89 | +uchar env_get_char_spec (int index) | |
90 | +{ | |
91 | + DECLARE_GLOBAL_DATA_PTR; | |
92 | + | |
93 | + return ( *((uchar *)(gd->env_addr + index)) ); | |
94 | +} | |
95 | + | |
96 | + | |
97 | +/* this is called before nand_init() | |
98 | + * so we can't read Nand to validate env data. | |
99 | + * Mark it OK for now. env_relocate() in env_common.c | |
100 | + * will call our relocate function which will does | |
101 | + * the real validation. | |
102 | + */ | |
103 | +int env_init(void) | |
104 | +{ | |
105 | + DECLARE_GLOBAL_DATA_PTR; | |
106 | + | |
107 | + gd->env_addr = (ulong)&default_environment[0]; | |
108 | + gd->env_valid = 1; | |
109 | + | |
110 | + return (0); | |
111 | +} | |
112 | + | |
113 | +#ifdef CMD_SAVEENV | |
114 | +int saveenv(void) | |
115 | +{ | |
116 | + int total, ret = 0; | |
117 | + puts ("Erasing Nand..."); | |
118 | + if (nand_erase(nand_dev_desc + 0, CFG_ENV_OFFSET, CFG_ENV_SIZE, 0)) | |
119 | + return 1; | |
120 | + | |
121 | + puts ("Writing to Nand... "); | |
122 | + ret = nand_rw(nand_dev_desc + 0, | |
123 | + NANDRW_WRITE | NANDRW_JFFS2, CFG_ENV_OFFSET, CFG_ENV_SIZE, | |
124 | + &total, (u_char*)env_ptr); | |
125 | + if (ret || total != CFG_ENV_SIZE) | |
126 | + return 1; | |
127 | + | |
128 | + puts ("done\n"); | |
129 | + return ret; | |
130 | +} | |
131 | +#endif /* CMD_SAVEENV */ | |
132 | + | |
133 | + | |
134 | +void env_relocate_spec (void) | |
135 | +{ | |
136 | +#if !defined(ENV_IS_EMBEDDED) | |
137 | + int ret, total; | |
138 | + | |
139 | + ret = nand_rw(nand_dev_desc + 0, | |
140 | + NANDRW_READ | NANDRW_JFFS2, CFG_ENV_OFFSET, CFG_ENV_SIZE, | |
141 | + &total, (u_char*)env_ptr); | |
142 | + if (ret || total != CFG_ENV_SIZE) | |
143 | + return use_default(); | |
144 | + | |
145 | + if (crc32(0, env_ptr->data, ENV_SIZE) != env_ptr->crc) | |
146 | + return use_default(); | |
147 | +#endif /* ! ENV_IS_EMBEDDED */ | |
148 | + | |
149 | +} | |
150 | + | |
151 | +static void use_default() | |
152 | +{ | |
153 | + DECLARE_GLOBAL_DATA_PTR; | |
154 | + | |
155 | + puts ("*** Warning - bad CRC or NAND, using default environment\n\n"); | |
156 | + | |
157 | + if (default_environment_size > CFG_ENV_SIZE){ | |
158 | + puts ("*** Error - default environment is too large\n\n"); | |
159 | + return; | |
160 | + } | |
161 | + | |
162 | + memset (env_ptr, 0, sizeof(env_t)); | |
163 | + memcpy (env_ptr->data, | |
164 | + default_environment, | |
165 | + default_environment_size); | |
166 | + env_ptr->crc = crc32(0, env_ptr->data, ENV_SIZE); | |
167 | + gd->env_valid = 1; | |
168 | + | |
169 | +} | |
170 | + | |
171 | +#endif /* CFG_ENV_IS_IN_NAND */ |