]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - board/amcc/acadia/cmd_acadia.c
Make sure that argv[] argument pointers are not modified.
[karo-tx-uboot.git] / board / amcc / acadia / cmd_acadia.c
1 /*
2  * (C) Copyright 2007
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
29 static u8 boot_267_nor[] = {
30         0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x8e, 0x00,
31         0x14, 0xc0, 0x36, 0xcc, 0x00, 0x0c, 0x00, 0x00,
32         0x00, 0x00, 0x00, 0x00
33 };
34
35 static u8 boot_267_nand[] = {
36         0xd0, 0x38, 0xc3, 0x50, 0x13, 0x88, 0x8e, 0x00,
37         0x14, 0xc0, 0x36, 0xcc, 0x00, 0x0c, 0x00, 0x00,
38         0x00, 0x00, 0x00, 0x00
39 };
40
41 static int do_bootstrap(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
42 {
43         u8 chip;
44         u8 *buf;
45         int cpu_freq;
46
47         if (argc < 3) {
48                 cmd_usage(cmdtp);
49                 return 1;
50         }
51
52         cpu_freq = simple_strtol(argv[1], NULL, 10);
53         if (cpu_freq != 267) {
54                 printf("Unsupported cpu-frequency - only 267 supported\n");
55                 return 1;
56         }
57
58         /* use 0x50 as I2C EEPROM address for now */
59         chip = 0x50;
60
61         if ((strcmp(argv[2], "nor") != 0) &&
62             (strcmp(argv[2], "nand") != 0)) {
63                 printf("Unsupported boot-device - only nor|nand support\n");
64                 return 1;
65         }
66
67         if (strcmp(argv[2], "nand") == 0) {
68                 switch (cpu_freq) {
69                 case 267:
70                         buf = boot_267_nand;
71                         break;
72                 default:
73                         break;
74                 }
75         } else {
76                 switch (cpu_freq) {
77                 case 267:
78                         buf = boot_267_nor;
79                         break;
80                 default:
81                         break;
82                 }
83         }
84
85         if (i2c_write(chip, 0, 1, buf, 16) != 0)
86                 printf("Error writing to EEPROM at address 0x%x\n", chip);
87         udelay(CONFIG_SYS_EEPROM_PAGE_WRITE_DELAY_MS * 1000);
88         if (i2c_write(chip, 0x10, 1, buf+16, 4) != 0)
89                 printf("Error2 writing to EEPROM at address 0x%x\n", chip);
90
91         printf("Done\n");
92         printf("Please power-cycle the board for the changes to take effect\n");
93
94         return 0;
95 }
96
97 U_BOOT_CMD(
98         bootstrap,      3,      0,      do_bootstrap,
99         "program the I2C bootstrap EEPROM",
100         "<cpu-freq> <nor|nand> - program the I2C bootstrap EEPROM"
101 );