blob: 30046fee3ab6d8c051a58f4730dff33c22274b38 [file] [log] [blame]
Stefan Roese8e1a3fe2008-03-11 16:51:17 +01001/*
2 * (C) Copyright 2008
3 * Stefan Roese, DENX Software Engineering, sr@denx.de.
4 *
5 * See file CREDITS for list of people who contributed to this
6 * project.
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
21 * MA 02111-1307 USA
22 *
23 */
24
25#include <common.h>
26#include <command.h>
27#include <i2c.h>
28#include <asm/io.h>
29
30/*
Stefan Roese71665eb2008-03-03 17:27:02 +010031 * NOR and NAND boot options change bytes 5, 6, 8, 9, 11. The
Stefan Roese8e1a3fe2008-03-11 16:51:17 +010032 * values are independent of the rest of the clock settings.
33 */
34
35#define NAND_COMPATIBLE 0x01
36#define NOR_COMPATIBLE 0x02
37
38#define I2C_EEPROM_ADDR 0x52
39
40static char *config_labels[] = {
41 "CPU: 600 PLB: 200 OPB: 100 EBC: 100",
42 "CPU: 800 PLB: 200 OPB: 100 EBC: 100",
Stefan Roesef4d14c52008-10-13 15:15:31 +020043 "CPU:1000 PLB: 200 OPB: 100 EBC: 100",
44 "CPU:1066 PLB: 266 OPB: 88 EBC: 88",
Stefan Roese8e1a3fe2008-03-11 16:51:17 +010045 NULL
46};
47
48static u8 boot_configs[][17] = {
49 {
Stefan Roese71665eb2008-03-03 17:27:02 +010050 (NAND_COMPATIBLE | NOR_COMPATIBLE),
Stefan Roese8e1a3fe2008-03-11 16:51:17 +010051 0x86, 0x80, 0xce, 0x1f, 0x79, 0x80, 0x00, 0xa0, 0x40, 0x08,
Stefan Roese71665eb2008-03-03 17:27:02 +010052 0x23, 0x50, 0x0d, 0x05, 0x00, 0x00
Stefan Roese8e1a3fe2008-03-11 16:51:17 +010053 },
54 {
Stefan Roese71665eb2008-03-03 17:27:02 +010055 (NAND_COMPATIBLE | NOR_COMPATIBLE),
Stefan Roese8e1a3fe2008-03-11 16:51:17 +010056 0x86, 0x80, 0xba, 0x14, 0x99, 0x80, 0x00, 0xa0, 0x40, 0x08,
Stefan Roese71665eb2008-03-03 17:27:02 +010057 0x23, 0x50, 0x0d, 0x05, 0x00, 0x00
Stefan Roese8e1a3fe2008-03-11 16:51:17 +010058 },
59 {
Stefan Roesef4d14c52008-10-13 15:15:31 +020060 (NAND_COMPATIBLE | NOR_COMPATIBLE),
61 0x86, 0x82, 0x96, 0x19, 0xb9, 0x80, 0x00, 0xa0, 0x40, 0x08,
62 0x23, 0x50, 0x0d, 0x05, 0x00, 0x00
63 },
64 {
65 (NAND_COMPATIBLE | NOR_COMPATIBLE),
66 0x86, 0x80, 0xb3, 0x01, 0x9d, 0x80, 0x00, 0xa0, 0x40, 0x08,
67 0x23, 0x50, 0x0d, 0x05, 0x00, 0x00
68 },
69 {
Stefan Roese8e1a3fe2008-03-11 16:51:17 +010070 0,
71 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
72 }
73};
74
75/*
Stefan Roese71665eb2008-03-03 17:27:02 +010076 * Bytes 5,6,8,9,11 change for NAND boot
Stefan Roese8e1a3fe2008-03-11 16:51:17 +010077 */
Stefan Roese499e7832008-04-08 10:33:29 +020078#if 0
79/*
80 * Values for 512 page size NAND chips, not used anymore, just
81 * keep them here for reference
82 */
Stefan Roese8e1a3fe2008-03-11 16:51:17 +010083static u8 nand_boot[] = {
Stefan Roese71665eb2008-03-03 17:27:02 +010084 0x90, 0x01, 0xa0, 0x68, 0x58
Stefan Roese8e1a3fe2008-03-11 16:51:17 +010085};
Stefan Roese499e7832008-04-08 10:33:29 +020086#else
87/*
88 * Values for 2k page size NAND chips
89 */
90static u8 nand_boot[] = {
91 0x90, 0x01, 0xa0, 0xe8, 0x58
92};
93#endif
Stefan Roese8e1a3fe2008-03-11 16:51:17 +010094
95static int do_bootstrap(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
96{
97 u8 *buf, b_nand;
98 int x, y, nbytes, selcfg;
99 extern char console_buffer[];
100
101 if (argc < 2) {
Peter Tyser62c3ae72009-01-27 18:03:10 -0600102 cmd_usage(cmdtp);
Stefan Roese8e1a3fe2008-03-11 16:51:17 +0100103 return 1;
104 }
105
106 if ((strcmp(argv[1], "nor") != 0) &&
107 (strcmp(argv[1], "nand") != 0)) {
108 printf("Unsupported boot-device - only nor|nand support\n");
109 return 1;
110 }
111
112 /* set the nand flag based on provided input */
113 if ((strcmp(argv[1], "nand") == 0))
114 b_nand = 1;
115 else
116 b_nand = 0;
117
118 printf("Available configurations: \n\n");
119
120 if (b_nand) {
121 for(x = 0, y = 0; boot_configs[x][0] != 0; x++) {
122 /* filter on nand compatible */
123 if (boot_configs[x][0] & NAND_COMPATIBLE) {
124 printf(" %d - %s\n", (y+1), config_labels[x]);
125 y++;
126 }
127 }
128 } else {
129 for(x = 0, y = 0; boot_configs[x][0] != 0; x++) {
130 /* filter on nor compatible */
131 if (boot_configs[x][0] & NOR_COMPATIBLE) {
132 printf(" %d - %s\n", (y+1), config_labels[x]);
133 y++;
134 }
135 }
136 }
137
138 do {
139 nbytes = readline(" Selection [1-x / quit]: ");
140
141 if (nbytes) {
142 if (strcmp(console_buffer, "quit") == 0)
143 return 0;
144 selcfg = simple_strtol(console_buffer, NULL, 10);
145 if ((selcfg < 1) || (selcfg > y))
146 nbytes = 0;
147 }
148 } while (nbytes == 0);
149
150
151 y = (selcfg - 1);
152
153 for (x = 0; boot_configs[x][0] != 0; x++) {
154 if (b_nand) {
155 if (boot_configs[x][0] & NAND_COMPATIBLE) {
156 if (y > 0)
157 y--;
158 else if (y < 1)
159 break;
160 }
161 } else {
162 if (boot_configs[x][0] & NOR_COMPATIBLE) {
163 if (y > 0)
164 y--;
165 else if (y < 1)
166 break;
167 }
168 }
169 }
170
171 buf = &boot_configs[x][1];
172
173 if (b_nand) {
Stefan Roese71665eb2008-03-03 17:27:02 +0100174 buf[5] = nand_boot[0];
175 buf[6] = nand_boot[1];
176 buf[8] = nand_boot[2];
177 buf[9] = nand_boot[3];
178 buf[11] = nand_boot[4];
Stefan Roese8e1a3fe2008-03-11 16:51:17 +0100179 }
180
181 if (i2c_write(I2C_EEPROM_ADDR, 0, 1, buf, 16) != 0)
182 printf("Error writing to EEPROM at address 0x%x\n", I2C_EEPROM_ADDR);
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200183 udelay(CONFIG_SYS_EEPROM_PAGE_WRITE_DELAY_MS * 1000);
Stefan Roese8e1a3fe2008-03-11 16:51:17 +0100184
185 printf("Done\n");
186 printf("Please power-cycle the board for the changes to take effect\n");
187
188 return 0;
189}
190
191U_BOOT_CMD(
192 bootstrap, 2, 0, do_bootstrap,
Peter Tyser2fb26042009-01-27 18:03:12 -0600193 "program the I2C bootstrap EEPROM",
Stefan Roese8e1a3fe2008-03-11 16:51:17 +0100194 "<nand|nor> - strap to boot from NAND or NOR flash\n"
195 );