GUI: Fix Tomato RAF theme for all builds. Compilation typo.
[tomato.git] / release / src-rt-6.x.4708 / cfe / cfe / arch / mips / board / bcm963xx / src / bcm63xx_cmd.c
blobe3d7bdcd7d487620a25d7c5babd1919b0a5e3942
1 /* *********************************************************************
2 * Broadcom Common Firmware Environment (CFE)
3 *
4 *
5 * bcm63xx board specific routines and commands.
6 *
7 * by: seanl
9 * April 1, 2002
11 *********************************************************************
13 * Copyright 2000,2001,2002,2003
14 * Broadcom Corporation. All rights reserved.
16 * This software is furnished under license and may be used and
17 * copied only in accordance with the following terms and
18 * conditions. Subject to these conditions, you may download,
19 * copy, install, use, modify and distribute modified or unmodified
20 * copies of this software in source and/or binary form. No title
21 * or ownership is transferred hereby.
23 * 1) Any source code used, modified or distributed must reproduce
24 * and retain this copyright notice and list of conditions
25 * as they appear in the source file.
27 * 2) No right is granted to use any trade name, trademark, or
28 * logo of Broadcom Corporation. The "Broadcom Corporation"
29 * name may not be used to endorse or promote products derived
30 * from this software without the prior written permission of
31 * Broadcom Corporation.
33 * 3) THIS SOFTWARE IS PROVIDED "AS-IS" AND ANY EXPRESS OR
34 * IMPLIED WARRANTIES, INCLUDING BUT NOT LIMITED TO, ANY IMPLIED
35 * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
36 * PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT
37 * SHALL BROADCOM BE LIABLE FOR ANY DAMAGES WHATSOEVER, AND IN
38 * PARTICULAR, BROADCOM SHALL NOT BE LIABLE FOR DIRECT, INDIRECT,
39 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
40 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
41 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
42 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
43 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
44 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE), EVEN IF ADVISED OF
45 * THE POSSIBILITY OF SUCH DAMAGE.
46 ********************************************************************* */
49 #include "bcm63xx_util.h"
51 #define ENTRY_POINT 0x80010470
52 #define CODE_ADDRESS 0x80010000
53 #define FLASH_STAGING_BUFFER (1024*1024) /* 1MB line */
54 #define FLASH_STAGING_BUFFER_SIZE (4 * 1024 *1024 + TAG_LEN) // 4 MB for now
56 extern PFILE_TAG kerSysImageTagGet(void);
57 extern NVRAM_DATA nvramData;
59 static int ui_cmd_set_board_param(ui_cmdline_t *cmd,int argc,char *argv[])
61 return(setBoardParam());
66 static int ui_cmd_reset(ui_cmdline_t *cmd,int argc,char *argv[])
68 kerSysMipsSoftReset();
70 return 0;
74 // return 0 if 'y'
75 int yesno(void)
77 char ans[5];
79 printf(" (y/n):");
80 console_readline ("", ans, sizeof (ans));
81 if (ans[0] != 'y')
82 return -1;
84 return 0;
88 // erase Persistent sector
89 static int ui_cmd_erase_psi(ui_cmdline_t *cmd,int argc,char *argv[])
91 printf("Erase persisten storage data?");
92 if (yesno())
93 return -1;
95 kerSysErasePsi();
97 return 0;
102 // erase some sectors
103 static int ui_cmd_erase(ui_cmdline_t *cmd,int argc,char *argv[])
106 //FILE_TAG cfeTag;
107 PFILE_TAG pTag;
108 char *flag;
109 int i, blk_start, blk_end;
111 flag = cmd_getarg(cmd,0);
113 if (!flag)
115 printf("Erase [n]vram or [a]ll flash except bootrom; usage: e [n/a]\n");
116 return 0;
119 switch (*flag)
121 case 'b':
122 printf("Erase boot loader?");
123 if (yesno())
124 return 0;
125 printf("\nNow think carefully. Do you really,\n"
126 "really want to erase the boot loader?");
127 if (yesno())
128 return 0;
129 flash_sector_erase_int(0);
130 break;
131 case 'n':
132 printf("Erase nvram?");
133 if (yesno())
134 return 0;
135 kerSysEraseNvRam();
136 break;
137 case 'a':
138 printf("Erase all flash (except bootrom)?");
139 if (yesno())
140 return 0;
142 if ((pTag = kerSysImageTagGet()) != NULL)
143 blk_start = flash_get_blk( atoi(pTag->rootfsAddress) );
144 else // just erase all after cfe
146 blk_start = FLASH45_BLKS_BOOT_ROM;
147 printf("No image tag found. Erase the blocks start at [%d]\n", blk_start);
149 blk_end = flash_get_numsectors();
150 if( blk_start > 0 )
152 for (i = blk_start; i < blk_end; i++)
154 printf(".");
155 flash_sector_erase_int(i);
158 printf( "\nResetting board...\n" );
159 kerSysMipsSoftReset();
160 break;
161 default:
162 printf("Erase [n]vram or [a]ll flash except bootrom; usage: e [n/a]\n");
163 return 0;
166 flash_reset();
168 return 0;
173 // flash the image
174 static int ui_cmd_flash_image(ui_cmdline_t *cmd,int argc,char *argv[])
176 char hostImageName[BOOT_FILENAME_LEN + BOOT_IP_LEN];
177 char *imageName;
178 uint8_t *ptr;
179 cfe_loadargs_t la;
180 int res;
182 imageName = cmd_getarg(cmd, 0);
184 if (imageName)
186 if (strchr(imageName, ':'))
187 strcpy(hostImageName, imageName);
188 else
190 strcpy(hostImageName, bootInfo.hostIp);
191 strcat(hostImageName, ":");
192 strcat(hostImageName, imageName);
195 else // use default flash file name
197 strcpy(hostImageName, bootInfo.hostIp);
198 strcat(hostImageName, ":");
199 strcat(hostImageName, bootInfo.flashFileName);
202 printf("Loading %s ...\n", hostImageName);
204 ptr = (uint8_t *) PHYS_TO_K0(FLASH_STAGING_BUFFER);
206 // tftp only
207 la.la_filesys = "tftp";
208 la.la_filename = hostImageName;
209 la.la_device = NULL;
210 la.la_address = (intptr_t) ptr;
211 la.la_options = 0;
212 la.la_maxsize = FLASH_STAGING_BUFFER_SIZE;
213 la.la_flags = LOADFLG_SPECADDR;
215 res = cfe_load_program("raw", &la);
216 if (res < 0)
218 ui_showerror(res, "Loading failed.");
219 return res;
221 printf("Finished loading %d bytes\n", res);
223 // check and flash image
224 res = flashImage(ptr);
226 if( res == 0 )
228 char *p;
230 for( p = nvramData.szBootline; p[2] != '\0'; p++ )
231 if( p[0] == 'r' && p[1] == '=' && p[2] == 'h' )
233 /* Change boot source to "boot from flash". */
234 p[2] = 'f';
235 writeNvramData();
236 break;
238 printf( "Resetting board...\n" );
239 kerSysMipsSoftReset();
242 return( res );
246 // write the whole image
247 static int ui_cmd_write_whole_image(ui_cmdline_t *cmd,int argc,char *argv[])
249 char hostImageName[BOOT_FILENAME_LEN + BOOT_IP_LEN];
250 char *imageName;
251 uint8_t *ptr;
252 cfe_loadargs_t la;
253 int res;
255 imageName = cmd_getarg(cmd, 0);
256 if (!imageName)
257 return ui_showusage(cmd);
259 if (strchr(imageName, ':'))
260 strcpy(hostImageName, imageName);
261 else
263 strcpy(hostImageName, bootInfo.hostIp);
264 strcat(hostImageName, ":");
265 strcat(hostImageName, imageName);
268 printf("Loading %s ...\n", hostImageName);
270 ptr = (uint8_t *) PHYS_TO_K0(FLASH_STAGING_BUFFER);
272 // tftp only
273 la.la_filesys = "tftp";
274 la.la_filename = hostImageName;
275 la.la_device = NULL;
276 la.la_address = (intptr_t) ptr;
277 la.la_options = 0;
278 la.la_maxsize = FLASH_STAGING_BUFFER_SIZE;
279 la.la_flags = LOADFLG_SPECADDR;
281 res = cfe_load_program("raw", &la);
282 if (res < 0)
284 ui_showerror(res, "Loading failed.");
285 return res;
287 printf("Finished loading %d bytes\n", res);
289 // check and flash image
290 res = writeWholeImage(ptr, res);
292 printf("Finished flashing image. return = %d\n", res);
294 if (res == 0)
296 printf( "Resetting board...\n" );
297 kerSysMipsSoftReset();
300 return( res );
303 // Used to flash an RTEMS image. Only works on BCM96345 with top boot flash part.
304 static int ui_cmd_flash_router_image(ui_cmdline_t *cmd,int argc,char *argv[])
306 char hostImageName[BOOT_FILENAME_LEN + BOOT_IP_LEN];
307 char *imageName;
308 uint8_t *ptr;
309 cfe_loadargs_t la;
310 int res;
312 imageName = cmd_getarg(cmd, 0);
313 if (!imageName)
314 return ui_showusage(cmd);
316 if (strchr(imageName, ':'))
317 strcpy(hostImageName, imageName);
318 else
320 strcpy(hostImageName, bootInfo.hostIp);
321 strcat(hostImageName, ":");
322 strcat(hostImageName, imageName);
325 printf("Loading %s ...\n", hostImageName);
327 ptr = (uint8_t *) PHYS_TO_K0(FLASH_STAGING_BUFFER);
329 // tftp only
330 la.la_filesys = "tftp";
331 la.la_filename = hostImageName;
332 la.la_device = NULL;
333 la.la_address = (intptr_t) ptr;
334 la.la_options = 0;
335 la.la_maxsize = FLASH_STAGING_BUFFER_SIZE;
336 la.la_flags = LOADFLG_SPECADDR;
338 res = cfe_load_program("raw", &la);
339 if (res < 0)
341 ui_showerror(res, "Loading failed.");
342 return res;
344 printf("Finished loading %d bytes\n", res);
346 // check and flash image
347 if ((res = kerSysBcmImageSet(FLASH45_IMAGE_START_ADDR, ptr, res, 1)) != 0)
348 printf("Failed to flash image. Error: %d\n", res);
349 else
350 printf("Finished flashing image.\n");
352 if (res == 0)
354 char *p;
356 for( p = nvramData.szBootline; p[2] != '\0'; p++ )
357 if( p[0] == 'r' && p[1] == '=' && p[2] == 'h' )
359 /* Change boot source to "boot from flash". */
360 p[2] = 'f';
361 writeNvramData();
362 break;
364 printf( "Resetting board...\n" );
365 kerSysMipsSoftReset();
368 return( res );
371 static int autoRun(char *imageName)
373 char runCmd[BOOT_FILENAME_LEN + BOOT_IP_LEN + 20], ipImageName[BOOT_FILENAME_LEN + BOOT_IP_LEN];
374 int ret;
377 if (bootInfo.runFrom == 'f' && !imageName)
379 strcpy(runCmd, "boot -elf -z -rawfs flash1:");
380 ret = ui_docommand(runCmd);
382 else // loading from host
384 if (imageName)
386 if (strchr(imageName, ':'))
387 strcpy(ipImageName, imageName);
388 else
390 strcpy(ipImageName, bootInfo.hostIp);
391 strcat(ipImageName, ":");
392 strcat(ipImageName, imageName);
395 else // use default host file name
397 strcpy(ipImageName, bootInfo.hostIp);
398 strcat(ipImageName, ":");
399 strcat(ipImageName, bootInfo.hostFileName);
402 // try uncompressed image first
403 strcpy(runCmd, "boot -elf ");
404 strcat(runCmd, ipImageName);
406 ret = ui_docommand(runCmd);
408 if( ret == CFE_ERR_NOTELF )
410 // next try as a compressed image
411 printf("Retry loading it as a compressed image.\n");
412 strcpy(runCmd, "boot -elf -z ");
413 strcat(runCmd, ipImageName);
414 ret = ui_docommand(runCmd);
418 return ret;
422 // run program from compressed image in flash or from tftped program from host
423 static int ui_cmd_run_program(ui_cmdline_t *cmd,int argc,char *argv[])
425 char *imageName;
427 imageName = cmd_getarg(cmd, 0);
429 return autoRun(imageName);
433 static int ui_cmd_print_system_info(ui_cmdline_t *cmd,int argc,char *argv[])
435 return printSysInfo();
439 static int ui_cmd_change_bootline(ui_cmdline_t *cmd,int argc,char *argv[])
441 return changeBootLine();
445 static int ui_init_bcm6345_cmds(void)
448 // Used to flash an RTEMS image.
449 cmd_addcmd("flashimage",
450 ui_cmd_flash_router_image,
451 NULL,
452 "Flashes a compressed image after the bootloader.",
453 "eg. flashimage [hostip:]compressed_image_file_name",
454 "");
456 cmd_addcmd("reset",
457 ui_cmd_reset,
458 NULL,
459 "Reset the board",
461 "");
463 cmd_addcmd("b",
464 ui_cmd_set_board_param,
465 NULL,
466 "Change board parameters",
468 "");
470 cmd_addcmd("i",
471 ui_cmd_erase_psi,
472 NULL,
473 "Erase persistent storage data",
475 "");
477 cmd_addcmd("f",
478 ui_cmd_flash_image,
479 NULL,
480 "Write image to the flash ",
481 "eg. f [[hostip:]filename]<cr> -- if no filename, tftped from host with file name in 'Default host flash file name'",
482 "");
484 cmd_addcmd("c",
485 ui_cmd_change_bootline,
486 NULL,
487 "Change booline parameters",
489 "");
491 cmd_addcmd("p",
492 ui_cmd_print_system_info,
493 NULL,
494 "Print boot line and board parameter info",
496 "");
498 cmd_addcmd("r",
499 ui_cmd_run_program,
500 NULL,
501 "Run program from flash image or from host depend on [f/h] flag",
502 "eg. r [[hostip:]filenaem]<cr> if no filename, use the file name in 'Default host run file name'",
503 "");
505 cmd_addcmd("e",
506 ui_cmd_erase,
507 NULL,
508 "Erase [n]vram or [a]ll flash except bootrom",
509 "e [n/a]",
510 "");
512 cmd_addcmd("w",
513 ui_cmd_write_whole_image,
514 NULL,
515 "Write the whole image start from beginning of the flash",
516 "eg. w [hostip:]whole_image_file_name",
517 "");
519 return 0;
523 static int runDelay(int delayCount)
525 int goAuot = 0;
527 if (delayCount == 0)
528 return goAuot;
530 printf("*** Press any key to stop auto run (%d seconds) ***\n", delayCount);
531 printf("Auto run second count down: %d", delayCount);
533 cfe_sleep(CFE_HZ/8); // about 1/4 second
535 while (1)
537 printf("\b%d", delayCount);
538 cfe_sleep(CFE_HZ/2); // about 1 second
539 if (console_status())
540 break;;
541 if (--delayCount == 0)
543 goAuot = 1;
544 break;
547 printf("\b%d\n", delayCount);
549 return goAuot;
553 void bcm63xx_run(void)
555 ui_init_bcm6345_cmds();
556 printSysInfo();
557 enet_init();
558 if (runDelay(bootInfo.bootDelay))
559 autoRun(NULL); // never returns