]> git.ipfire.org Git - people/ms/u-boot.git/blame - board/pn62/cmd_pn62.c
cmd_usage(): simplify return code handling
[people/ms/u-boot.git] / board / pn62 / cmd_pn62.c
CommitLineData
c609719b
WD
1/*
2 * (C) Copyright 2002
3 * Wolfgang Grandegger, DENX Software Engineering, wg@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#include <common.h>
25#include <malloc.h>
26#include <net.h>
27#include <asm/io.h>
28#include <pci.h>
8bde7f77 29#include <command.h>
c609719b
WD
30#include "pn62.h"
31
3fe00109 32#if defined(CONFIG_CMD_BSP)
c609719b
WD
33
34extern int do_bootm (cmd_tbl_t *, int, int, char *[]);
35
36/*
37 * Command led: controls the various LEDs 0..11 on the PN62 card.
38 */
47e26b1b 39int do_led(cmd_tbl_t * cmdtp, int flag, int argc, char *const argv[])
c609719b 40{
47e26b1b 41 unsigned int number, function;
c609719b 42
47e26b1b
WD
43 if (argc != 3)
44 return cmd_usage(cmdtp);
45
46 number = simple_strtoul(argv[1], NULL, 10);
47 if (number > PN62_LED_MAX)
48 return 1;
49
50 function = simple_strtoul(argv[2], NULL, 16);
51 set_led(number, function);
52 return 0;
c609719b 53}
0d498393
WD
54U_BOOT_CMD(
55 led , 3, 1, do_led,
2fb2604d 56 "set LED 0..11 on the PN62 board",
a89c33db
WD
57 "i fun"
58 " - set 'i'th LED to function 'fun'"
8bde7f77 59);
c609719b
WD
60
61/*
62 * Command loadpci: loads a image over PCI.
63 */
64#define CMD_MOVE_WINDOW 0x1
65#define CMD_BOOT_IMAGE 0x2
66
54841ab5 67int do_loadpci (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
c609719b
WD
68{
69 char *s;
70 ulong addr = 0, count = 0;
71 u32 off;
72 int cmd, rcode = 0;
73
74 /* pre-set load_addr */
75 if ((s = getenv("loadaddr")) != NULL) {
76 addr = simple_strtoul(s, NULL, 16);
77 }
78
79 switch (argc) {
80 case 1:
81 break;
82 case 2:
83 addr = simple_strtoul(argv[1], NULL, 16);
84 break;
85 default:
47e26b1b 86 return cmd_usage(cmdtp);
c609719b
WD
87 }
88
89 printf ("## Ready for image download ...\n");
90
91 show_startup_phase(12);
92
93 while (1) {
94 /* Alive indicator */
95 i2155x_write_scrapad(BOOT_PROTO, BOOT_PROTO_READY);
96
97 /* Toggle status LEDs */
98 cmd = (count / 200) % 4; /* downscale */
99 set_led(4, cmd == 0 ? LED_1 : LED_0);
100 set_led(5, cmd == 1 ? LED_1 : LED_0);
101 set_led(6, cmd == 2 ? LED_1 : LED_0);
102 set_led(7, cmd == 3 ? LED_1 : LED_0);
103 udelay(1000);
104 count++;
105
106 cmd = i2155x_read_scrapad(BOOT_CMD);
107
108 if (cmd == BOOT_CMD_MOVE) {
109 off = i2155x_read_scrapad(BOOT_DATA);
110 off += addr;
111 i2155x_set_bar_base(3, off);
112 printf ("## BAR3 Addr moved = 0x%08x\n", off);
113 i2155x_write_scrapad(BOOT_CMD, ~cmd);
114 show_startup_phase(13);
115 }
116 else if (cmd == BOOT_CMD_BOOT) {
117 set_led(4, LED_1);
118 set_led(5, LED_1);
119 set_led(6, LED_1);
120 set_led(7, LED_1);
121
122 i2155x_write_scrapad(BOOT_CMD, ~cmd);
123 show_startup_phase(14);
124 break;
125 }
126
127 /* Abort if ctrl-c was pressed */
128 if (ctrlc()) {
129 printf("\nAbort\n");
130 return 0;
131 }
132
133 }
134
135 /* Repoint to the default shared memory */
136 i2155x_set_bar_base(3, PN62_SMEM_DEFAULT);
137
138 load_addr = addr;
139 printf ("## Start Addr = 0x%08lx\n", addr);
140
141 show_startup_phase(15);
142
143 /* Loading ok, check if we should attempt an auto-start */
144 if (((s = getenv("autostart")) != NULL) && (strcmp(s,"yes") == 0)) {
145 char *local_args[2];
146 local_args[0] = argv[0];
147 local_args[1] = NULL;
148
149 printf ("Automatic boot of image at addr 0x%08lX ...\n",
150 load_addr);
151 rcode = do_bootm (cmdtp, 0, 1, local_args);
152 }
153
c609719b
WD
154 return rcode;
155}
156
0d498393
WD
157U_BOOT_CMD(
158 loadpci, 2, 1, do_loadpci,
2fb2604d 159 "load binary file over PCI",
8bde7f77 160 "[addr]\n"
a89c33db 161 " - load binary file over PCI to address 'addr'"
8bde7f77
WD
162);
163
c609719b 164#endif