1 /* *********************************************************************
2 * Broadcom Common Firmware Environment (CFE)
5 * bcm63xx board specific routines and commands.
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();
80 console_readline ("", ans
, sizeof (ans
));
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?");
102 // erase some sectors
103 static int ui_cmd_erase(ui_cmdline_t
*cmd
,int argc
,char *argv
[])
109 int i
, blk_start
, blk_end
;
111 flag
= cmd_getarg(cmd
,0);
115 printf("Erase [n]vram or [a]ll flash except bootrom; usage: e [n/a]\n");
122 printf("Erase boot loader?");
125 printf("\nNow think carefully. Do you really,\n"
126 "really want to erase the boot loader?");
129 flash_sector_erase_int(0);
132 printf("Erase nvram?");
138 printf("Erase all flash (except bootrom)?");
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();
152 for (i
= blk_start
; i
< blk_end
; i
++)
155 flash_sector_erase_int(i
);
158 printf( "\nResetting board...\n" );
159 kerSysMipsSoftReset();
162 printf("Erase [n]vram or [a]ll flash except bootrom; usage: e [n/a]\n");
174 static int ui_cmd_flash_image(ui_cmdline_t
*cmd
,int argc
,char *argv
[])
176 char hostImageName
[BOOT_FILENAME_LEN
+ BOOT_IP_LEN
];
182 imageName
= cmd_getarg(cmd
, 0);
186 if (strchr(imageName
, ':'))
187 strcpy(hostImageName
, imageName
);
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
);
207 la
.la_filesys
= "tftp";
208 la
.la_filename
= hostImageName
;
210 la
.la_address
= (intptr_t) ptr
;
212 la
.la_maxsize
= FLASH_STAGING_BUFFER_SIZE
;
213 la
.la_flags
= LOADFLG_SPECADDR
;
215 res
= cfe_load_program("raw", &la
);
218 ui_showerror(res
, "Loading failed.");
221 printf("Finished loading %d bytes\n", res
);
223 // check and flash image
224 res
= flashImage(ptr
);
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". */
238 printf( "Resetting board...\n" );
239 kerSysMipsSoftReset();
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
];
255 imageName
= cmd_getarg(cmd
, 0);
257 return ui_showusage(cmd
);
259 if (strchr(imageName
, ':'))
260 strcpy(hostImageName
, imageName
);
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
);
273 la
.la_filesys
= "tftp";
274 la
.la_filename
= hostImageName
;
276 la
.la_address
= (intptr_t) ptr
;
278 la
.la_maxsize
= FLASH_STAGING_BUFFER_SIZE
;
279 la
.la_flags
= LOADFLG_SPECADDR
;
281 res
= cfe_load_program("raw", &la
);
284 ui_showerror(res
, "Loading failed.");
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
);
296 printf( "Resetting board...\n" );
297 kerSysMipsSoftReset();
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
];
312 imageName
= cmd_getarg(cmd
, 0);
314 return ui_showusage(cmd
);
316 if (strchr(imageName
, ':'))
317 strcpy(hostImageName
, imageName
);
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
);
330 la
.la_filesys
= "tftp";
331 la
.la_filename
= hostImageName
;
333 la
.la_address
= (intptr_t) ptr
;
335 la
.la_maxsize
= FLASH_STAGING_BUFFER_SIZE
;
336 la
.la_flags
= LOADFLG_SPECADDR
;
338 res
= cfe_load_program("raw", &la
);
341 ui_showerror(res
, "Loading failed.");
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
);
350 printf("Finished flashing image.\n");
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". */
364 printf( "Resetting board...\n" );
365 kerSysMipsSoftReset();
371 static int autoRun(char *imageName
)
373 char runCmd
[BOOT_FILENAME_LEN
+ BOOT_IP_LEN
+ 20], ipImageName
[BOOT_FILENAME_LEN
+ BOOT_IP_LEN
];
377 if (bootInfo
.runFrom
== 'f' && !imageName
)
379 strcpy(runCmd
, "boot -elf -z -rawfs flash1:");
380 ret
= ui_docommand(runCmd
);
382 else // loading from host
386 if (strchr(imageName
, ':'))
387 strcpy(ipImageName
, imageName
);
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
);
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
[])
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
,
452 "Flashes a compressed image after the bootloader.",
453 "eg. flashimage [hostip:]compressed_image_file_name",
464 ui_cmd_set_board_param
,
466 "Change board parameters",
473 "Erase persistent storage data",
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'",
485 ui_cmd_change_bootline
,
487 "Change booline parameters",
492 ui_cmd_print_system_info
,
494 "Print boot line and board parameter info",
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'",
508 "Erase [n]vram or [a]ll flash except bootrom",
513 ui_cmd_write_whole_image
,
515 "Write the whole image start from beginning of the flash",
516 "eg. w [hostip:]whole_image_file_name",
523 static int runDelay(int delayCount
)
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
537 printf("\b%d", delayCount
);
538 cfe_sleep(CFE_HZ
/2); // about 1 second
539 if (console_status())
541 if (--delayCount
== 0)
547 printf("\b%d\n", delayCount
);
553 void bcm63xx_run(void)
555 ui_init_bcm6345_cmds();
558 if (runDelay(bootInfo
.bootDelay
))
559 autoRun(NULL
); // never returns