2 * Broadcom Common Firmware Environment (CFE)
3 * Board device initialization, File: bcm947xx_devs.c
5 * Copyright (C) 2011, Broadcom Corporation
8 * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Broadcom Corporation;
9 * the contents of this file may not be disclosed to third parties, copied
10 * or duplicated in any form, in whole or in part, without the prior
11 * written permission of Broadcom Corporation.
13 * $Id: bcm947xx_devs.c 324903 2012-03-30 19:57:48Z $
17 #include "lib_types.h"
18 #include "lib_printf.h"
19 #include "lib_physio.h"
21 #include "cfe_error.h"
23 #include "cfe_device.h"
24 #include "cfe_timer.h"
25 #include "ui_command.h"
26 #include "bsp_config.h"
27 #include "dev_newflash.h"
31 #include "../../../../../dev/ns16550.h"
33 #include "net_ether.h"
54 #include <cfe_devfuncs.h>
55 #include <cfe_ioctl.h>
57 #define MAX_WAIT_TIME 20 /* seconds to wait for boot image */
58 #define MIN_WAIT_TIME 3 /* seconds to wait for boot image */
60 #define RESET_DEBOUNCE_TIME (500*1000) /* 500 ms */
62 /* Defined as sih by bsp_config.h for convenience */
63 si_t
*bcm947xx_sih
= NULL
;
65 /* Configured devices */
66 #if (CFG_FLASH || CFG_SFLASH || CFG_NFLASH) && CFG_XIP
67 #error "XIP and Flash cannot be defined at the same time"
70 extern cfe_driver_t ns16550_uart
;
72 extern cfe_driver_t newflashdrv
;
75 extern cfe_driver_t sflashdrv
;
78 extern cfe_driver_t nflashdrv
;
81 extern cfe_driver_t bcmet
;
84 extern cfe_driver_t bcmwl
;
87 extern cfe_driver_t bcm5700drv
;
91 static int restore_defaults
= 0;
92 extern char *flashdrv_nvram
;
95 board_console_add(void *regs
, uint irq
, uint baud_base
, uint reg_shift
)
99 /* The CFE NS16550 driver expects a physical address */
100 base
= PHYSADDR((physaddr_t
) regs
);
101 cfe_add_device(&ns16550_uart
, base
, baud_base
, ®_shift
);
104 #if CFG_FLASH || CFG_SFLASH || CFG_NFLASH
107 reset_release_wait(void)
112 if ((gpio
= nvram_resetgpio_init ((void *)sih
)) < 0)
115 /* Reset button is active low */
116 gpiomask
= (uint32
)1 << gpio
;
118 if (si_gpioin(sih
) & gpiomask
) {
119 OSL_DELAY(RESET_DEBOUNCE_TIME
);
121 if (si_gpioin(sih
) & gpiomask
)
126 #endif /* !CFG_SIM */
127 #endif /* CFG_FLASH || CFG_SFLASH || CFG_NFLASH */
130 * board_console_init()
132 * Add the console device and set it to be the primary
142 board_console_init(void)
145 uint32 mipsclock
= 0, siclock
= 0, pciclock
= 0;
151 #if !CFG_MINIMAL_SIZE
152 cfe_set_console(CFE_BUFFER_CONSOLE
);
155 /* Initialize SB access */
156 sih
= si_kattach(SI_OSH
);
160 /* Check whether NVRAM reset needs be done */
161 if (nvram_reset((void *)sih
) > 0)
162 restore_defaults
= 1;
165 /* Initialize NVRAM access accordingly. In case of invalid NVRAM, load defaults */
166 //if (asus_nvram_init((void *)sih) > 0)
167 // restore_defaults = 1;
168 restore_defaults
= 0;
171 restore_defaults
= 0;
173 /* Figure out current MIPS clock speed */
174 if ((cfe_cpu_speed
= si_cpu_clock(sih
)) == 0)
175 cfe_cpu_speed
= 133000000;
178 if (!restore_defaults
) {
181 /* MIPS clock speed override */
182 if ((nvstr
= nvram_get("clkfreq"))) {
183 mipsclock
= bcm_strtoul(nvstr
, &end
, 0) * 1000000;
186 siclock
= bcm_strtoul(nvstr
, &end
, 0) * 1000000;
189 pciclock
= bcm_strtoul(nvstr
, &end
, 0) * 1000000;
195 /* Set current MIPS clock speed */
196 si_mips_setclock(sih
, mipsclock
, siclock
, pciclock
);
200 /* Figure out current MIPS clock speed */
201 if ((cfe_cpu_speed
= si_cpu_clock(sih
)) == 0)
202 cfe_cpu_speed
= 133000000;
204 /* Next sections all want to talk to chipcommon */
205 origidx
= si_coreidx(sih
);
206 cc
= si_setcoreidx(sih
, SI_CC_IDX
);
208 nvstr
= nvram_get("boardpwrctl");
210 if ((CHIPID(sih
->chip
) == BCM4716_CHIP_ID
) ||
211 (CHIPID(sih
->chip
) == BCM4748_CHIP_ID
) ||
212 (CHIPID(sih
->chip
) == BCM47162_CHIP_ID
)) {
215 /* Adjust regulator settings */
216 W_REG(osh
, &cc
->regcontrol_addr
, 2);
217 /* Readback to ensure completion of the write */
218 (void)R_REG(osh
, &cc
->regcontrol_addr
);
219 reg
= R_REG(osh
, &cc
->regcontrol_data
);
220 /* Make the regulator frequency to 1.2MHz
227 /* Take 2.5v regulator output down one notch,
228 * officially to 2.45, but in reality to be
229 * closer to 2.5 than the default.
233 /* Bits corresponding to mask 0x00078000
234 * controls 1.3v source
236 * ========================
237 * 0xf0000000 1.2 V (default)
255 uint32 pwrctl
= bcm_strtoul(nvstr
, NULL
, 0);
258 reg
|= (pwrctl
& 0xf0c78000);
260 W_REG(osh
, &cc
->regcontrol_data
, reg
);
262 /* Turn off unused PLLs */
263 W_REG(osh
, &cc
->pllcontrol_addr
, 6);
264 (void)R_REG(osh
, &cc
->pllcontrol_addr
);
265 new = reg
= R_REG(osh
, &cc
->pllcontrol_data
);
266 if (sih
->chippkg
== BCM4716_PKG_ID
)
267 new |= 0x68; /* Channels 3, 5 & 6 off in 4716 */
268 if ((sih
->chipst
& 0x00000c00) == 0x00000400)
269 new |= 0x10; /* Channel 4 if MII mode */
271 /* apply new value */
272 W_REG(osh
, &cc
->pllcontrol_data
, new);
273 (void)R_REG(osh
, &cc
->pllcontrol_data
);
274 W_REG(osh
, &cc
->pmucontrol
,
275 PCTL_PLL_PLLCTL_UPD
| PCTL_NOILP_ON_WAIT
|
276 PCTL_HT_REQ_EN
| PCTL_ALP_REQ_EN
| PCTL_LPO_SEL
);
280 if ((CHIPID(sih
->chip
) == BCM5356_CHIP_ID
) ||
281 (CHIPID(sih
->chip
) == BCM5357_CHIP_ID
) ||
282 (CHIPID(sih
->chip
) == BCM53572_CHIP_ID
) ||
283 (CHIPID(sih
->chip
) == BCM4749_CHIP_ID
)) {
286 /* Change regulator if requested */
288 uint32 pwrctl
= bcm_strtoul(nvstr
, NULL
, 0);
290 W_REG(osh
, &cc
->regcontrol_addr
, 1);
291 /* Readback to ensure completion of the write */
292 (void)R_REG(osh
, &cc
->regcontrol_addr
);
293 reg
= R_REG(osh
, &cc
->regcontrol_data
);
295 reg
|= (pwrctl
& 0x00018f00);
297 W_REG(osh
, &cc
->regcontrol_data
, reg
);
301 /* On AI chips, change sflash divisor if requested. */
302 if (sih
->socitype
== SOCI_AI
) {
304 uint32 fltype
, clkdiv
, bpclock
, sflmaxclk
, sfldiv
;
306 fltype
= sih
->cccaps
& CC_CAP_FLASH_MASK
;
307 if ((fltype
!= SFLASH_ST
) && (fltype
!= SFLASH_AT
))
310 /* sdram_init is really a field in the nvram header */
311 nvstr
= nvram_get("sdram_init");
312 sflmaxclk
= bcm_strtoul(nvstr
, &end
, 0);
313 if ((sflmaxclk
= 0xffff) || (sflmaxclk
== 0x0419))
320 bpclock
= si_clock(sih
);
321 sflmaxclk
*= 10000000;
322 for (sfldiv
= 2; sfldiv
< 16; sfldiv
+= 2) {
323 if ((bpclock
/ sfldiv
) < sflmaxclk
)
329 clkdiv
= R_REG(osh
, &cc
->clkdiv
);
330 if (((clkdiv
& CLKD_SFLASH
) >> CLKD_SFLASH_SHIFT
) != sfldiv
) {
331 clkdiv
= (clkdiv
& ~CLKD_SFLASH
) | (sfldiv
<< CLKD_SFLASH_SHIFT
);
332 W_REG(osh
, &cc
->clkdiv
, clkdiv
);
337 si_setcoreidx(sih
, origidx
);
338 #endif /* !CFG_SIM */
340 /* Initialize clocks and interrupts */
341 si_mips_init(sih
, 0);
343 /* Initialize UARTs */
344 si_serial_init(sih
, board_console_add
);
346 if (cfe_finddev("uart0"))
347 cfe_set_console("uart0");
351 #if (CFG_FLASH || CFG_SFLASH)
353 flash_memory_size_config(newflash_probe_t
*fprobe
)
355 chipcregs_t
*cc
= NULL
;
356 uint size
, reg_sz
, val
;
358 if ((cc
= (chipcregs_t
*)si_setcoreidx(sih
, SI_CC_IDX
)))
361 size
= fprobe
->flash_size
; /* flash total size */
363 if (size
<= 4*1024*1024)
364 reg_sz
= FLSTRCF4706_1ST_MADDR_SEG_4MB
;
365 else if (size
> 4*1024*1024 && size
<= 8*1024*1024)
366 reg_sz
= FLSTRCF4706_1ST_MADDR_SEG_8MB
;
367 else if (size
> 8*1024*1024 && size
<= 16*1024*1024)
368 reg_sz
= FLSTRCF4706_1ST_MADDR_SEG_16MB
;
369 else if (size
> 16*1024*1024 && size
<= 32*1024*1024)
370 reg_sz
= FLSTRCF4706_1ST_MADDR_SEG_32MB
;
371 else if (size
> 32*1024*1024 && size
<= 64*1024*1024)
372 reg_sz
= FLSTRCF4706_1ST_MADDR_SEG_64MB
;
373 else if (size
> 64*1024*1024 && size
<= 128*1024*1024)
374 reg_sz
= FLSTRCF4706_1ST_MADDR_SEG_128MB
;
376 reg_sz
= FLSTRCF4706_1ST_MADDR_SEG_256MB
;
378 val
= R_REG(NULL
, &cc
->eci
.flashconf
.flashstrconfig
);
379 val
&= ~FLSTRCF4706_1ST_MADDR_SEG_MASK
;
382 W_REG(NULL
, &cc
->eci
.flashconf
.flashstrconfig
, val
);
384 #endif /* (CFG_FLASH || CFG_SFLASH) */
386 #if (CFG_FLASH || CFG_SFLASH || CFG_NFLASH)
387 #if (CFG_NFLASH || defined(FAILSAFE_UPGRADE) || defined(DUAL_IMAGE))
389 get_flash_size(char *device_name
)
392 flash_info_t flashinfo
;
395 fd
= cfe_open(device_name
);
397 (cfe_ioctl(fd
, IOCTL_FLASH_GETINFO
,
398 (unsigned char *) &flashinfo
,
399 sizeof(flash_info_t
), &res
, 0) == 0)) {
400 return flashinfo
.flash_size
;
405 #endif /* CFG_NFLASH */
407 #if defined(FAILSAFE_UPGRADE) || defined(DUAL_IMAGE)
409 int calculate_max_image_size(char *device_name
,int reserved_space_begin
,int reserved_space_end
,int *need_commit
)
418 if (!nvram_get(IMAGE_BOOT
))
420 if (!nvram_get(BOOTPARTITION
))
424 nvram_setting
= nvram_get(IMAGE_SIZE
);
427 image_size
= atoi(nvram_setting
)*1024;
429 } else if (device_name
[0] == 'n') {
430 /* use 8 meg for nand flash */
431 image_size
= (NFL_BOOT_OS_SIZE
- reserved_space_begin
)/2;
432 image_size
= image_size
- image_size
%(64*1024);
437 flash_size
= get_flash_size(device_name
);
438 if (flash_size
> 0) {
440 flash_size
- (reserved_space_begin
+ reserved_space_end
);
442 /* Calculate the 2nd offset with divide the
443 * availabe space by 2
444 * Make sure it is aligned to 64Kb to set
445 * the rootfs search algorithm
447 image_size
= available_size
/2;
448 image_size
= image_size
- image_size
%(128*1024);
451 /* 1st image start from bootsz end */
452 sprintf(buf
, "%d", reserved_space_begin
);
453 if (!nvram_match(IMAGE_FIRST_OFFSET
, buf
)) {
454 printf("The 1st image start addr changed, set to %s[%x] (was %s)\n",
455 buf
,reserved_space_begin
,nvram_get(IMAGE_FIRST_OFFSET
));
456 nvram_set(IMAGE_FIRST_OFFSET
, buf
);
459 sprintf(buf
, "%d", reserved_space_begin
+ image_size
);
460 if (!nvram_match(IMAGE_SECOND_OFFSET
, buf
)) {
461 printf("The 2nd image start addr changed, set to %s[%x] (was %s)\n",
462 buf
,reserved_space_begin
+ image_size
, nvram_get(IMAGE_SECOND_OFFSET
));
463 nvram_set(IMAGE_SECOND_OFFSET
, buf
);
469 #endif /* FAILSAFE_UPGRADE|| DUAL_IMAGE */
473 flash_nflash_init(void)
475 newflash_probe_t fprobe
;
476 chipcregs_t
*cc
= NULL
;
478 struct nflash
*nfl_info
;
482 int max_image_size
= 0;
483 #if defined(DUAL_IMAGE) || defined(FAILSAFE_UPGRADE)
487 memset(&fprobe
, 0, sizeof(fprobe
));
489 if (CHIPID(sih
->chip
) == BCM4706_CHIP_ID
|| sih
->ccrev
== 38) {
491 fprobe
.flash_phys
= (CHIPID(sih
->chip
) == BCM4706_CHIP_ID
) ? 0 : SI_FLASH1
;
492 cc
= (chipcregs_t
*)si_setcoreidx(sih
, SI_CC_IDX
);
493 fprobe
.flash_cmdset
= (int)cc
;
495 printf("Can't find nandflash! ccrev = %d, chipst= %d \n", sih
->ccrev
, sih
->chipst
);
499 nfl_info
= nflash_init(sih
, cc
);
503 /* check bootflags */
504 if ((val
= nvram_get("bootflags")))
505 bootflags
= atoi(val
);
508 /* kernel in nand flash */
509 if ((bootflags
& FLASH_KERNEL_NFLASH
) == FLASH_KERNEL_NFLASH
) {
510 #if defined(FAILSAFE_UPGRADE) || defined(DUAL_IMAGE)
511 max_image_size
= calculate_max_image_size("nflash0",0,0,&need_commit
);
513 /* Because CFE can only boot from the beginning of a partition */
514 fprobe
.flash_parts
[j
].fp_size
= sizeof(struct trx_header
);
515 fprobe
.flash_parts
[j
++].fp_name
= "trx";
516 fprobe
.flash_parts
[j
].fp_size
= max_image_size
?
517 max_image_size
- sizeof(struct trx_header
) : 0;
518 fprobe
.flash_parts
[j
++].fp_name
= "os";
519 #if defined(FAILSAFE_UPGRADE) || defined(DUAL_IMAGE)
520 if (max_image_size
) {
521 fprobe
.flash_parts
[j
].fp_size
= sizeof(struct trx_header
);
522 fprobe
.flash_parts
[j
++].fp_name
= "trx2";
523 fprobe
.flash_parts
[j
].fp_size
= max_image_size
;
524 fprobe
.flash_parts
[j
++].fp_name
= "os2";
527 fprobe
.flash_nparts
= j
;
529 cfe_add_device(drv
, 0, 0, &fprobe
);
531 /* Because CFE can only boot from the beginning of a partition */
533 fprobe
.flash_parts
[j
].fp_size
= max_image_size
?
534 max_image_size
: NFL_BOOT_OS_SIZE
;
535 fprobe
.flash_parts
[j
++].fp_name
= "trx";
536 #if defined(FAILSAFE_UPGRADE) || defined(DUAL_IMAGE)
537 if (max_image_size
) {
538 fprobe
.flash_parts
[j
].fp_size
= NFL_BOOT_OS_SIZE
- max_image_size
;
539 fprobe
.flash_parts
[j
++].fp_name
= "trx2";
544 fprobe
.flash_parts
[j
].fp_size
= 0;
545 fprobe
.flash_parts
[j
++].fp_name
= "brcmnand";
546 fprobe
.flash_nparts
= j
;
548 cfe_add_device(drv
, 0, 0, &fprobe
);
550 #if defined(FAILSAFE_UPGRADE) || defined(DUAL_IMAGE)
551 if (need_commit
) nvram_commit();
554 #endif /* CFG_NFLASH */
560 newflash_probe_t fprobe
;
561 chipcregs_t
*cc
= NULL
;
562 uint32 fltype
, bootsz
, *bisz
;
565 int max_image_size
= 0;
566 #if defined(DUAL_IMAGE) || defined(FAILSAFE_UPGRADE)
572 memset(&fprobe
, 0, sizeof(fprobe
));
574 if ((cc
= (chipcregs_t
*)si_setcoreidx(sih
, SI_CC_IDX
))) {
576 if ((sih
->ccrev
== 38) && ((sih
->chipst
& (1 << 4)) != 0)) {
578 fprobe
.flash_phys
= SI_FLASH1
;
582 fltype
= R_REG(NULL
, &cc
->capabilities
) & CC_CAP_FLASH_MASK
;
583 fprobe
.flash_phys
= SI_FLASH2
;
592 fprobe
.flash_flags
= FLASH_FLG_BUS16
| FLASH_FLG_DEV16
;
593 if (!(R_REG(NULL
, &cc
->flash_config
) & CC_CFG_DS
))
594 fprobe
.flash_flags
= FLASH_FLG_BUS8
| FLASH_FLG_DEV16
;
602 /* Overload cmdset field */
603 fprobe
.flash_cmdset
= (int)cc
;
609 fprobe
.flash_cmdset
= (int)cc
;
613 /* No flash or unsupported flash */
617 /* Default is 256K boot partition */
620 /* Do we have a self-describing binary image? */
621 bisz
= (uint32
*)PHYS_TO_K1(fprobe
.flash_phys
+ BISZ_OFFSET
);
622 if (bisz
[BISZ_MAGIC_IDX
] == BISZ_MAGIC
) {
623 int isz
= bisz
[BISZ_DATAEND_IDX
] - bisz
[BISZ_TXTST_IDX
];
625 if (isz
> (1024 * 1024))
626 bootsz
= 2048 * 1024;
627 else if (isz
> (512 * 1024))
628 bootsz
= 1024 * 1024;
629 else if (isz
> (256 * 1024))
631 else if (isz
<= (128 * 1024))
634 printf("Boot partition size = %d(0x%x)\n", bootsz
, bootsz
);
637 if (fltype
== NFLASH
) {
638 struct nflash
*nfl_info
;
641 nfl_info
= nflash_init(sih
, cc
);
643 if (bootsz
> nfl_info
->blocksize
) {
644 /* Prepare double space in case of bad blocks */
645 bootsz
= (bootsz
<< 1);
647 /* CFE occupies at least one block */
648 bootsz
= nfl_info
->blocksize
;
652 /* Because sometimes we want to program the entire device */
653 fprobe
.flash_nparts
= 0;
654 cfe_add_device(drv
, 0, 0, &fprobe
);
656 #if defined(FAILSAFE_UPGRADE) || defined(DUAL_IMAGE)
657 max_image_size
= calculate_max_image_size("nflash0",NFL_BOOT_SIZE
,0,&need_commit
);
659 /* Because sometimes we want to program the entire device */
660 /* Because CFE can only boot from the beginning of a partition */
662 fprobe
.flash_parts
[j
].fp_size
= bootsz
;
663 fprobe
.flash_parts
[j
++].fp_name
= "boot";
664 fprobe
.flash_parts
[j
].fp_size
= (NFL_BOOT_SIZE
- bootsz
);
665 fprobe
.flash_parts
[j
++].fp_name
= "nvram";
667 fprobe
.flash_parts
[j
].fp_size
= sizeof(struct trx_header
);
668 fprobe
.flash_parts
[j
++].fp_name
= "trx";
669 fprobe
.flash_parts
[j
].fp_size
= max_image_size
?
670 max_image_size
- sizeof(struct trx_header
) : 0;
671 fprobe
.flash_parts
[j
++].fp_name
= "os";
672 #if defined(FAILSAFE_UPGRADE) || defined(DUAL_IMAGE)
673 if (max_image_size
) {
674 fprobe
.flash_parts
[j
].fp_size
= sizeof(struct trx_header
);
675 fprobe
.flash_parts
[j
++].fp_name
= "trx2";
676 fprobe
.flash_parts
[j
].fp_size
= max_image_size
;
677 fprobe
.flash_parts
[j
++].fp_name
= "os2";
681 fprobe
.flash_nparts
= j
;
682 cfe_add_device(drv
, 0, 0, &fprobe
);
684 /* Because CFE can only flash an entire partition */
686 fprobe
.flash_parts
[j
].fp_size
= bootsz
;
687 fprobe
.flash_parts
[j
++].fp_name
= "boot";
688 fprobe
.flash_parts
[j
].fp_size
= (NFL_BOOT_SIZE
- bootsz
);
689 fprobe
.flash_parts
[j
++].fp_name
= "nvram";
690 fprobe
.flash_parts
[j
].fp_size
= max_image_size
;
691 fprobe
.flash_parts
[j
++].fp_name
= "trx";
692 #if defined(FAILSAFE_UPGRADE) || defined(DUAL_IMAGE)
693 if (max_image_size
) {
694 fprobe
.flash_parts
[j
].fp_size
= NFL_BOOT_OS_SIZE
- NFL_BOOT_SIZE
- max_image_size
;
695 fprobe
.flash_parts
[j
++].fp_name
= "trx2";
698 flash_size
= get_flash_size("nflash0") - NFL_BOOT_OS_SIZE
;
699 if (flash_size
> 0) {
700 fprobe
.flash_parts
[j
].fp_size
= flash_size
;
701 fprobe
.flash_parts
[j
++].fp_name
= "brcmnand";
704 fprobe
.flash_nparts
= j
;
705 cfe_add_device(drv
, 0, 0, &fprobe
);
707 /* Change nvram device name for NAND boot */
708 flashdrv_nvram
= "nflash0.nvram";
710 #endif /* CFG_NFLASH */
712 /* Because sometimes we want to program the entire device */
713 fprobe
.flash_nparts
= 0;
714 cfe_add_device(drv
, 0, 0, &fprobe
);
716 #if defined(FAILSAFE_UPGRADE) || defined(DUAL_IMAGE)
717 /* check bootflags */
718 if ((val
= nvram_get("bootflags")))
719 bootflags
= atoi(val
);
721 /* If the kernel is not in nand flash, split up the sflash */
722 if ((bootflags
& FLASH_KERNEL_NFLASH
) != FLASH_KERNEL_NFLASH
)
723 max_image_size
= calculate_max_image_size("flash0",bootsz
,NVRAM_SPACE
,
727 /* Because CFE can only boot from the beginning of a partition */
729 fprobe
.flash_parts
[j
].fp_size
= bootsz
;
730 fprobe
.flash_parts
[j
++].fp_name
= "boot";
731 fprobe
.flash_parts
[j
].fp_size
= sizeof(struct trx_header
);
732 fprobe
.flash_parts
[j
++].fp_name
= "trx";
733 fprobe
.flash_parts
[j
].fp_size
= max_image_size
?
734 max_image_size
- sizeof(struct trx_header
) : 0;
735 fprobe
.flash_parts
[j
++].fp_name
= "os";
736 #if defined(FAILSAFE_UPGRADE) || defined(DUAL_IMAGE)
737 if (max_image_size
) {
738 fprobe
.flash_parts
[j
].fp_size
= sizeof(struct trx_header
);
739 fprobe
.flash_parts
[j
++].fp_name
= "trx2";
740 fprobe
.flash_parts
[j
].fp_size
= 0;
741 fprobe
.flash_parts
[j
++].fp_name
= "os2";
744 fprobe
.flash_parts
[j
].fp_size
= NVRAM_SPACE
;
745 fprobe
.flash_parts
[j
++].fp_name
= "nvram";
746 fprobe
.flash_nparts
= j
;
747 cfe_add_device(drv
, 0, 0, &fprobe
);
749 /* Because CFE can only flash an entire partition */
751 fprobe
.flash_parts
[j
].fp_size
= bootsz
;
752 fprobe
.flash_parts
[j
++].fp_name
= "boot";
753 fprobe
.flash_parts
[j
].fp_size
= max_image_size
;
754 fprobe
.flash_parts
[j
++].fp_name
= "trx";
755 #if defined(FAILSAFE_UPGRADE) || defined(DUAL_IMAGE)
756 if (max_image_size
) {
757 fprobe
.flash_parts
[j
].fp_size
= 0;
758 fprobe
.flash_parts
[j
++].fp_name
= "trx2";
761 fprobe
.flash_parts
[j
].fp_size
= NVRAM_SPACE
;
762 fprobe
.flash_parts
[j
++].fp_name
= "nvram";
763 fprobe
.flash_nparts
= j
;
764 cfe_add_device(drv
, 0, 0, &fprobe
);
767 #if (CFG_FLASH || CFG_SFLASH)
768 if (CHIPID(sih
->chip
) == BCM4706_CHIP_ID
)
769 flash_memory_size_config(&fprobe
);
770 #endif /* (CFG_FLASH || CFG_SFLASH) */
773 /* If boot from sflash and nand flash present */
774 if ((fltype
!= NFLASH
) && ((CHIPID(sih
->chip
) == BCM4706_CHIP_ID
) || sih
->ccrev
== 38) &&
775 (sih
->cccaps
& CC_CAP_NFLASH
)) {
778 #endif /* CFG_NFLASH */
780 #if defined(FAILSAFE_UPGRADE) || defined(DUAL_IMAGE)
781 if (need_commit
) nvram_commit();
784 #endif /* CFG_FLASH || CFG_SFLASH || CFG_NFLASH */
787 * board_device_init()
789 * Initialize and add other devices. Add everything you need
790 * for bootstrap here, like disk drives, flash memory, UARTs,
791 * network controllers, etc.
800 board_device_init(void)
804 #if CFG_ET || CFG_WL || CFG_BCM57XX
808 /* Set by board_console_init() */
812 #if CFG_FLASH || CFG_SFLASH || CFG_NFLASH
816 for (unit
= 0; unit
< SI_MAXCORES
; unit
++) {
818 if ((regs
= si_setcore(sih
, ENET_CORE_ID
, unit
)))
819 cfe_add_device(&bcmet
, BCM47XX_ENET_ID
, unit
, regs
);
822 if ((regs
= si_setcore(sih
, GMAC_CORE_ID
, unit
)))
823 cfe_add_device(&bcmet
, BCM47XX_GMAC_ID
, unit
, regs
);
827 if ((regs
= si_setcore(sih
, D11_CORE_ID
, unit
)))
828 cfe_add_device(&bcmwl
, BCM4306_D11G_ID
, unit
, regs
);
831 if ((regs
= si_setcore(sih
, GIGETH_CORE_ID
, unit
)))
832 cfe_add_device(&bcm5700drv
, BCM47XX_GIGETH_ID
, unit
, regs
);
838 * board_device_reset()
840 * Reset devices. This call is done when the firmware is restarted,
841 * as might happen when an operating system exits, just before the
842 * "reset" command is applied to the installed devices. You can
843 * do whatever board-specific things are here to keep the system
844 * stable, like stopping DMA sources, interrupts, etc.
853 board_device_reset(void)
860 * Do any final initialization, such as adding commands to the
863 * If you don't want a user interface, put the startup code here.
864 * This routine is called just before CFE starts its user interface.
873 board_final_init(void)
875 char *addr
, *mask
, *wait_time
;
876 char buf
[512], *cur
= buf
;
878 char *boot_cfg
= NULL
;
879 char *go_cmd
= "go;";
883 #if CFG_WL && CFG_WLU && CFG_SIM
887 ui_init_bcm947xxcmds();
889 /* Force commit of embedded NVRAM */
890 //commit = restore_defaults;
893 /* Set the SDRAM NCDL value into NVRAM if not already done */
894 if ((getintvar(NULL
, "sdram_ncdl") == 0) &&
895 ((ncdl
= si_memc_get_ncdl(sih
)) != 0)) {
896 sprintf(buf
, "0x%x", ncdl
);
897 nvram_set("sdram_ncdl", buf
);
901 /* Set the bootloader version string if not already done */
902 sprintf(buf
, "CFE %s", EPI_VERSION_STR
);
903 if (strcmp(nvram_safe_get("pmon_ver"), buf
) != 0) {
904 nvram_set("pmon_ver", buf
);
908 #if CFG_FLASH || CFG_SFLASH || CFG_NFLASH
912 printf("Committing NVRAM...");
915 if (restore_defaults
) {
916 printf("Waiting for reset button release...");
917 reset_release_wait();
924 /* Reboot after restoring defaults */
925 if (restore_defaults
)
927 #endif /* !CFG_SIM */
930 printf("Flash not configured, not commiting NVRAM...\n");
931 #endif /* CFG_FLASH || CFG_SFLASH || CFG_NFLASH */
934 * Read the wait_time NVRAM variable and set the tftp max retries.
935 * Assumption: tftp_rrq_timeout & tftp_recv_timeout are set to 1sec.
937 if ((wait_time
= nvram_get("wait_time")) != NULL
) {
938 tftp_max_retries
= atoi(wait_time
);
939 if (tftp_max_retries
> MAX_WAIT_TIME
)
940 tftp_max_retries
= MAX_WAIT_TIME
;
941 else if (tftp_max_retries
< MIN_WAIT_TIME
)
942 tftp_max_retries
= MIN_WAIT_TIME
;
945 /* Configure network */
946 if (cfe_finddev("eth0")) {
947 if ((addr
= nvram_get("lan_ipaddr")) &&
948 (mask
= nvram_get("lan_netmask")))
949 sprintf(buf
, "ifconfig eth0 -addr=%s -mask=%s",
952 sprintf(buf
, "ifconfig eth0 -auto");
956 #if CFG_WL && CFG_WLU && CFG_SIM
957 if ((ssid
= nvram_get("wl0_ssid"))) {
958 sprintf(buf
, "wl join %s", ssid
);
964 /* Try to run boot_config command if configured.
965 * make sure to leave space for "go" command.
967 if ((boot_cfg
= nvram_get("boot_config"))) {
968 if (strlen(boot_cfg
) < (sizeof(buf
) - sizeof(go_cmd
)))
969 cur
+= sprintf(cur
, "%s;", boot_cfg
);
971 printf("boot_config too long, skipping to autoboot\n");
975 cur
+= sprintf(cur
, go_cmd
);
976 #endif /* !CFG_SIM */
980 env_setenv("STARTUP", buf
, ENV_FLG_NORMAL
);