2 #include <linux/types.h>
3 #include <linux/version.h>
4 #include <linux/init.h>
5 #include <linux/platform_device.h>
8 #include <asm/mach-types.h>
9 #include <asm/mach/arch.h>
10 #include <asm/mach/time.h>
11 #include <asm/clkdev.h>
13 #include <mach/clkdev.h>
14 #include <mach/hardware.h>
15 #include <mach/memory.h>
16 #include <mach/io_map.h>
19 #include <plat/mpcore.h>
20 #include <plat/plat-bcm5301x.h>
22 #ifdef CONFIG_MTD_PARTITIONS
23 #include <linux/mtd/mtd.h>
24 #include <linux/mtd/nand.h>
25 #include <linux/mtd/partitions.h>
26 #include <linux/romfs_fs.h>
27 #include <linux/cramfs_fs.h>
28 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,36)
29 #include <linux/squashfs_fs.h>
31 /* #include <magic.h> */
39 #include <bcmendian.h>
48 #include <ctf/hndctf.h>
50 #include <hndsflash.h>
51 #ifdef CONFIG_MTD_NFLASH
55 extern char __initdata saved_root_name
[];
57 /* Global SB handle */
58 si_t
*bcm947xx_sih
= NULL
;
59 spinlock_t bcm947xx_sih_lock
= SPIN_LOCK_UNLOCKED
;
60 EXPORT_SYMBOL(bcm947xx_sih
);
61 EXPORT_SYMBOL(bcm947xx_sih_lock
);
64 #define sih bcm947xx_sih
65 #define sih_lock bcm947xx_sih_lock
67 #define WATCHDOG_MIN 3000 /* milliseconds */
68 extern int panic_timeout
;
69 extern int panic_on_oops
;
70 static int watchdog
= 0;
75 ctf_attach_t ctf_attach_fn
= NULL
;
76 EXPORT_SYMBOL(ctf_attach_fn
);
80 struct dummy_super_block
{
84 /* This is the main reference clock 25MHz from external crystal */
85 static struct clk clk_ref
= {
87 .rate
= 25 * 1000000, /* run-time override */
93 static struct clk_lookup board_clk_lookups
[] = {
102 void __init
board_map_io(void)
104 early_printk("board_map_io\n");
105 /* Install clock sources into the lookup table */
106 clkdev_add_table(board_clk_lookups
,
107 ARRAY_SIZE(board_clk_lookups
));
109 /* Map SoC specific I/O */
110 soc_map_io( &clk_ref
);
114 void __init
board_init_irq(void)
116 early_printk("board_init_irq\n");
119 /* serial_setup(sih); */
122 void board_init_timer(void)
124 early_printk("board_init_timer\n");
128 static int __init
rootfs_mtdblock(void)
133 #ifdef CONFIG_FAILSAFE_UPGRADE
134 char *img_boot
= nvram_get(BOOTPARTITION
);
137 bootdev
= soc_boot_dev((void *)sih
);
138 knldev
= soc_knl_dev((void *)sih
);
141 if (bootdev
== SOC_BOOTDEV_NANDFLASH
&&
142 knldev
== SOC_KNLDEV_NANDFLASH
) {
143 #ifdef CONFIG_FAILSAFE_UPGRADE
144 if (img_boot
&& simple_strtol(img_boot
, NULL
, 10))
153 /* SFLASH/PFLASH only */
154 if (bootdev
!= SOC_BOOTDEV_NANDFLASH
&&
155 knldev
!= SOC_KNLDEV_NANDFLASH
) {
156 #ifdef CONFIG_FAILSAFE_UPGRADE
157 if (img_boot
&& simple_strtol(img_boot
, NULL
, 10))
169 #ifdef CONFIG_FAILSAFE_UPGRADE
170 if (img_boot
&& simple_strtol(img_boot
, NULL
, 10))
173 /* Boot from norflash and kernel in nandflash */
177 static void __init
brcm_setup(void)
179 /* Get global SB handle */
180 sih
= si_kattach(SI_OSH
);
182 if (strncmp(boot_command_line
, "root=/dev/mtdblock", strlen("root=/dev/mtdblock")) == 0)
183 sprintf(saved_root_name
, "/dev/mtdblock%d", rootfs_mtdblock());
185 /* Set watchdog interval in ms */
186 watchdog
= simple_strtoul(nvram_safe_get("watchdog"), NULL
, 0);
188 /* Ensure at least WATCHDOG_MIN */
189 if ((watchdog
> 0) && (watchdog
< WATCHDOG_MIN
))
190 watchdog
= WATCHDOG_MIN
;
192 /* Set panic timeout in seconds */
193 panic_timeout
= watchdog
/ 1000;
194 panic_on_oops
= watchdog
/ 1000;
197 void soc_watchdog(void)
200 si_watchdog_ms(sih
, watchdog
);
203 #define CFE_UPDATE 1 // added by Chen-I for mac/regulation update
206 void bcm947xx_watchdog_disable(void)
209 si_watchdog_ms(sih
, 0);
213 void __init
board_init(void)
215 early_printk("board_init\n");
218 * Add common platform devices that do not have board dependent HW
226 static void __init
board_fixup(
227 struct machine_desc
*desc
,
233 u32 mem_size
, lo_size
;
234 early_printk("board_fixup\n" );
236 /* Fuxup reference clock rate */
237 if (desc
->nr
== MACH_TYPE_BRCM_NS_QT
)
238 clk_ref
.rate
= 17594; /* Emulator ref clock rate */
243 early_printk("board_fixup: mem=%uMiB\n", mem_size
>> 20);
245 lo_size
= min(mem_size
, DRAM_MEMORY_REGION_SIZE
);
247 mi
->bank
[0].start
= PHYS_OFFSET
;
248 mi
->bank
[0].size
= lo_size
;
251 if (lo_size
== mem_size
)
254 mi
->bank
[1].start
= PHYS_OFFSET2
;
255 mi
->bank
[1].size
= mem_size
- lo_size
;
259 #ifdef CONFIG_ZONE_DMA
261 * Adjust the zones if there are restrictions for DMA access.
263 void __init
bcm47xx_adjust_zones(unsigned long *size
, unsigned long *hole
)
265 unsigned long dma_size
= SZ_128M
>> PAGE_SHIFT
;
267 if (size
[0] <= dma_size
)
270 size
[ZONE_NORMAL
] = size
[0] - dma_size
;
271 size
[ZONE_DMA
] = dma_size
;
272 hole
[ZONE_NORMAL
] = hole
[0];
275 #endif /* CONFIG_ZONE_DMA */
277 static struct sys_timer board_timer
= {
278 .init
= board_init_timer
,
281 #if (( (IO_BASE_VA >>18) & 0xfffc) != 0x3c40)
285 MACHINE_START(BRCM_NS
, "Northstar Prototype")
286 .phys_io
= /* UART I/O mapping */
288 .io_pg_offst
= /* for early debug */
289 (IO_BASE_VA
>>18) & 0xfffc,
290 .fixup
= board_fixup
, /* Opt. early setup_arch() */
291 .map_io
= board_map_io
, /* Opt. from setup_arch() */
292 .init_irq
= board_init_irq
, /* main.c after setup_arch() */
293 .timer
= &board_timer
, /* main.c after IRQs */
294 .init_machine
= board_init
, /* Late archinitcall */
295 .boot_params
= CONFIG_BOARD_PARAMS_PHYS
,
298 #ifdef CONFIG_MACH_BRCM_NS_QT
299 MACHINE_START(BRCM_NS_QT
, "Northstar Emulation Model")
300 .phys_io
= /* UART I/O mapping */
302 .io_pg_offst
= /* for early debug */
303 (IO_BASE_VA
>>18) & 0xfffc,
304 .fixup
= board_fixup
, /* Opt. early setup_arch() */
305 .map_io
= board_map_io
, /* Opt. from setup_arch() */
306 .init_irq
= board_init_irq
, /* main.c after setup_arch() */
307 .timer
= &board_timer
, /* main.c after IRQs */
308 .init_machine
= board_init
, /* Late archinitcall */
309 .boot_params
= CONFIG_BOARD_PARAMS_PHYS
,
313 void arch_reset(char mode
, const char *cmd
)
315 #ifdef CONFIG_OUTER_CACHE_SYNC
316 outer_cache
.sync
= NULL
;
321 #ifdef CONFIG_MTD_PARTITIONS
323 static spinlock_t
*mtd_lock
= NULL
;
325 spinlock_t
*partitions_lock_init(void)
328 mtd_lock
= (spinlock_t
*)kzalloc(sizeof(spinlock_t
), GFP_KERNEL
);
332 spin_lock_init( mtd_lock
);
336 EXPORT_SYMBOL(partitions_lock_init
);
338 static struct nand_hw_control
*nand_hwcontrol
= NULL
;
339 struct nand_hw_control
*nand_hwcontrol_lock_init(void)
341 if (!nand_hwcontrol
) {
342 nand_hwcontrol
= (struct nand_hw_control
*)kzalloc(sizeof(struct nand_hw_control
), GFP_KERNEL
);
346 spin_lock_init(&nand_hwcontrol
->lock
);
347 init_waitqueue_head(&nand_hwcontrol
->wq
);
349 return nand_hwcontrol
;
351 EXPORT_SYMBOL(nand_hwcontrol_lock_init
);
353 /* Find out prom size */
354 static uint32
boot_partition_size(uint32 flash_phys
) {
355 uint32 bootsz
, *bisz
;
357 /* Default is 256K boot partition */
360 /* Do we have a self-describing binary image? */
361 bisz
= (uint32
*)(flash_phys
+ BISZ_OFFSET
);
362 if (bisz
[BISZ_MAGIC_IDX
] == BISZ_MAGIC
) {
363 int isz
= bisz
[BISZ_DATAEND_IDX
] - bisz
[BISZ_TXTST_IDX
];
365 if (isz
> (1024 * 1024))
366 bootsz
= 2048 * 1024;
367 else if (isz
> (512 * 1024))
368 bootsz
= 1024 * 1024;
369 else if (isz
> (256 * 1024))
371 else if (isz
<= (128 * 1024))
377 #if defined(BCMCONFMTD)
387 #if defined(CONFIG_FAILSAFE_UPGRADE)
388 #define FAILSAFE_PARTS 2
390 #define FAILSAFE_PARTS 0
392 #if defined(CONFIG_CRASHLOG)
393 #define CRASHLOG_PARTS 1
395 #define CRASHLOG_PARTS 0
397 /* boot;nvram;kernel;rootfs;empty */
398 #define FLASH_PARTS_NUM (5+MTD_PARTS+PLC_PARTS+FAILSAFE_PARTS+CRASHLOG_PARTS)
400 static struct mtd_partition bcm947xx_flash_parts
[FLASH_PARTS_NUM
] = {{0}};
402 static uint
lookup_flash_rootfs_offset(struct mtd_info
*mtd
, int *trx_off
, size_t size
,
405 struct romfs_super_block
*romfsb
;
406 struct cramfs_super
*cramfsb
;
407 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,36)
408 struct squashfs_super_block
*squashfsb
;
410 struct dummy_super_block
*squashfsb
;
412 struct trx_header
*trx
;
413 unsigned char buf
[512];
417 romfsb
= (struct romfs_super_block
*) buf
;
418 cramfsb
= (struct cramfs_super
*) buf
;
419 squashfsb
= (void *) buf
;
420 trx
= (struct trx_header
*) buf
;
422 /* Look at every 64 KB boundary */
423 for (off
= *trx_off
; off
< size
; off
+= (64 * 1024)) {
424 memset(buf
, 0xe5, sizeof(buf
));
427 * Read block 0 to test for romfs and cramfs superblock
429 if (mtd
->read(mtd
, off
, sizeof(buf
), &len
, buf
) ||
433 /* Try looking at TRX header for rootfs offset */
434 if (le32_to_cpu(trx
->magic
) == TRX_MAGIC
) {
436 *trx_size
= le32_to_cpu(trx
->len
);
437 if (trx
->offsets
[1] == 0)
440 * Read to test for romfs and cramfs superblock
442 off
+= le32_to_cpu(trx
->offsets
[1]);
443 memset(buf
, 0xe5, sizeof(buf
));
444 if (mtd
->read(mtd
, off
, sizeof(buf
), &len
, buf
) || len
!= sizeof(buf
))
448 /* romfs is at block zero too */
449 if (romfsb
->word0
== ROMSB_WORD0
&&
450 romfsb
->word1
== ROMSB_WORD1
) {
452 "%s: romfs filesystem found at block %d\n",
453 mtd
->name
, off
/ mtd
->erasesize
);
458 if (cramfsb
->magic
== CRAMFS_MAGIC
) {
460 "%s: cramfs filesystem found at block %d\n",
461 mtd
->name
, off
/ mtd
->erasesize
);
465 if (squashfsb
->s_magic
== SQUASHFS_MAGIC
) {
467 "%s: squash filesystem found at block %d\n",
468 mtd
->name
, off
/ mtd
->erasesize
);
476 struct mtd_partition
*
477 init_mtd_partitions(hndsflash_t
*sfl_info
, struct mtd_info
*mtd
, size_t size
)
485 uint vmlz_off
, knl_size
;
489 #ifdef CONFIG_CRASHLOG
490 char create_crash_partition
= 0;
492 #ifdef CONFIG_FAILSAFE_UPGRADE
493 char *img_boot
= nvram_get(BOOTPARTITION
);
494 char *imag_1st_offset
= nvram_get(IMAGE_FIRST_OFFSET
);
495 char *imag_2nd_offset
= nvram_get(IMAGE_SECOND_OFFSET
);
496 unsigned int image_first_offset
= 0;
497 unsigned int image_second_offset
= 0;
498 char dual_image_on
= 0;
500 /* The image_1st_size and image_2nd_size are necessary if the Flash does not have any
503 dual_image_on
= (img_boot
!= NULL
&& imag_1st_offset
!= NULL
&& imag_2nd_offset
!= NULL
);
506 image_first_offset
= simple_strtol(imag_1st_offset
, NULL
, 10);
507 image_second_offset
= simple_strtol(imag_2nd_offset
, NULL
, 10);
508 printk("The first offset=%x, 2nd offset=%x\n", image_first_offset
,
509 image_second_offset
);
512 #endif /* CONFIG_FAILSAFE_UPGRADE */
514 /* limit size for R6300V2/R6250 */
515 if (nvram_match("boardnum", "679") && nvram_match("boardtype", "0x0646")
516 && nvram_match("boardrev", "0x1110")) {
521 if (nvram_match("boardnum", "32") && nvram_match("boardtype", "0x0665")
522 && nvram_match("boardrev", "0x1301")) {
527 bootdev
= soc_boot_dev((void *)sih
);
528 knldev
= soc_knl_dev((void *)sih
);
530 if (bootdev
== SOC_BOOTDEV_NANDFLASH
) {
531 /* Do not init MTD partitions on NOR flash when NAND boot */
535 if (knldev
!= SOC_KNLDEV_NANDFLASH
) {
537 rfs_off
= lookup_flash_rootfs_offset(mtd
, &vmlz_off
, size
, &trx_size
);
540 bcm947xx_flash_parts
[nparts
].name
= "boot";
541 bcm947xx_flash_parts
[nparts
].size
= vmlz_off
;
542 bcm947xx_flash_parts
[nparts
].offset
= top
;
543 bcm947xx_flash_parts
[nparts
].mask_flags
= MTD_WRITEABLE
; /* forces on read only */
546 /* Setup kernel MTD partition */
547 bcm947xx_flash_parts
[nparts
].name
= "linux";
548 #ifdef CONFIG_FAILSAFE_UPGRADE
549 if (trx_size
> (image_second_offset
-image_first_offset
)) {
550 printk("sflash size is too small to afford two images.\n");
552 image_first_offset
= 0;
553 image_second_offset
= 0;
556 bcm947xx_flash_parts
[nparts
].size
= image_second_offset
-image_first_offset
;
558 bcm947xx_flash_parts
[nparts
].size
= mtd
->size
- vmlz_off
;
560 /* Reserve for NVRAM */
561 bcm947xx_flash_parts
[nparts
].size
-= ROUNDUP(nvram_space
, mtd
->erasesize
);
563 /* Reserve for PLC */
564 bcm947xx_flash_parts
[nparts
].size
-= ROUNDUP(0x1000, mtd
->erasesize
);
567 bcm947xx_flash_parts
[nparts
].size
-= (mtd
->erasesize
*4);
572 bcm947xx_flash_parts
[nparts
].size
= mtd
->size
- vmlz_off
;
575 /* Reserve for PLC */
576 bcm947xx_flash_parts
[nparts
].size
-= ROUNDUP(0x1000, mtd
->erasesize
);
578 /* Reserve for NVRAM */
579 bcm947xx_flash_parts
[nparts
].size
-= ROUNDUP(nvram_space
, mtd
->erasesize
);
582 bcm947xx_flash_parts
[nparts
].size
-= (mtd
->erasesize
*4);
584 #endif /* CONFIG_FAILSAFE_UPGRADE */
586 /* Reserve for board_data */
587 if (nvram_match("boardnum", "32") && nvram_match("boardtype", "0x0665")
588 && nvram_match("boardrev", "0x1301") && nvram_match("model", "R1D")) {
589 bcm947xx_flash_parts
[nparts
].size
-= ROUNDUP(0x10000, mtd
->erasesize
);
593 #ifdef CONFIG_CRASHLOG
594 if ((bcm947xx_flash_parts
[nparts
].size
- trx_size
) >=
595 ROUNDUP(0x4000, mtd
->erasesize
)) {
596 bcm947xx_flash_parts
[nparts
].size
-= ROUNDUP(0x4000, mtd
->erasesize
);
597 create_crash_partition
= 1;
599 create_crash_partition
= 0;
603 bcm947xx_flash_parts
[nparts
].offset
= vmlz_off
;
604 knl_size
= bcm947xx_flash_parts
[nparts
].size
;
605 offset
= bcm947xx_flash_parts
[nparts
].offset
+ knl_size
;
608 /* Setup rootfs MTD partition */
609 bcm947xx_flash_parts
[nparts
].name
= "rootfs";
610 bcm947xx_flash_parts
[nparts
].size
= knl_size
- (rfs_off
- vmlz_off
);
611 bcm947xx_flash_parts
[nparts
].offset
= rfs_off
;
612 bcm947xx_flash_parts
[nparts
].mask_flags
= MTD_WRITEABLE
; /* forces on read only */
613 offset
= bcm947xx_flash_parts
[nparts
].offset
+ bcm947xx_flash_parts
[nparts
].size
;
616 #if defined(CONFIG_CRASHLOG) && defined(BCMDBG)
617 if (create_crash_partition
) {
618 /* Setup crash MTD partition */
619 bcm947xx_flash_parts
[nparts
].name
= "crash";
620 bcm947xx_flash_parts
[nparts
].size
= ROUNDUP(0x4000, mtd
->erasesize
);
621 bcm947xx_flash_parts
[nparts
].offset
= offset
;
622 bcm947xx_flash_parts
[nparts
].mask_flags
= 0;
626 #ifdef CONFIG_FAILSAFE_UPGRADE
628 offset
= image_second_offset
;
629 rfs_off
= lookup_flash_rootfs_offset(mtd
, &offset
, size
, &trx_size
);
630 /* When the second image doesn't exist,
631 * set the rootfs use the same offset with the kernel
637 /* Setup kernel2 MTD partition */
638 bcm947xx_flash_parts
[nparts
].name
= "linux2";
639 bcm947xx_flash_parts
[nparts
].size
= mtd
->size
- image_second_offset
;
640 /* Reserve for NVRAM */
641 bcm947xx_flash_parts
[nparts
].size
-= ROUNDUP(nvram_space
, mtd
->erasesize
);
644 bcm947xx_flash_parts
[nparts
].size
-= (mtd
->erasesize
*4);
647 /* Reserve for PLC */
648 bcm947xx_flash_parts
[nparts
].size
-= ROUNDUP(0x1000, mtd
->erasesize
);
650 bcm947xx_flash_parts
[nparts
].offset
= image_second_offset
;
651 knl_size
= bcm947xx_flash_parts
[nparts
].size
;
652 offset
= bcm947xx_flash_parts
[nparts
].offset
+ knl_size
;
655 /* Setup rootfs MTD partition */
656 bcm947xx_flash_parts
[nparts
].name
= "rootfs2";
657 bcm947xx_flash_parts
[nparts
].size
=
658 knl_size
- (rfs_off
- image_second_offset
);
659 bcm947xx_flash_parts
[nparts
].offset
= rfs_off
;
660 /* forces on read only */
661 bcm947xx_flash_parts
[nparts
].mask_flags
= MTD_WRITEABLE
;
664 #endif /* CONFIG_FAILSAFE_UPGRADE */
667 bootsz
= boot_partition_size(sfl_info
->base
);
668 printk("Boot partition size = %d(0x%x)\n", bootsz
, bootsz
);
672 bcm947xx_flash_parts
[nparts
].name
= "boot";
673 bcm947xx_flash_parts
[nparts
].size
= bootsz
;
674 bcm947xx_flash_parts
[nparts
].offset
= top
;
675 //bcm947xx_flash_parts[nparts].mask_flags = MTD_WRITEABLE; /* forces on read only */
676 offset
= bcm947xx_flash_parts
[nparts
].size
;
681 /* Setup CONF MTD partition */
682 bcm947xx_flash_parts
[nparts
].name
= "confmtd";
683 bcm947xx_flash_parts
[nparts
].size
= mtd
->erasesize
* 4;
684 bcm947xx_flash_parts
[nparts
].offset
= offset
;
685 offset
= bcm947xx_flash_parts
[nparts
].offset
+ bcm947xx_flash_parts
[nparts
].size
;
687 #endif /* BCMCONFMTD */
690 /* Setup plc MTD partition */
691 bcm947xx_flash_parts
[nparts
].name
= "plc";
692 bcm947xx_flash_parts
[nparts
].size
= ROUNDUP(0x1000, mtd
->erasesize
);
693 bcm947xx_flash_parts
[nparts
].offset
=
694 size
- (ROUNDUP(nvram_space
, mtd
->erasesize
) + ROUNDUP(0x1000, mtd
->erasesize
));
698 /* Setup board_data partition */
699 if (nvram_match("boardnum", "32") && nvram_match("boardtype", "0x0665")
700 && nvram_match("boardrev", "0x1301") && nvram_match("model", "R1D")) {
701 bcm947xx_flash_parts
[nparts
].name
= "board_data";
702 bcm947xx_flash_parts
[nparts
].size
= ROUNDUP(0x10000, mtd
->erasesize
);
703 bcm947xx_flash_parts
[nparts
].offset
= 0xFE0000;
707 /* Setup nvram MTD partition */
708 bcm947xx_flash_parts
[nparts
].name
= "nvram";
709 bcm947xx_flash_parts
[nparts
].size
= ROUNDUP(nvram_space
, mtd
->erasesize
);
712 if (nvram_match("boardnum", "32") && nvram_match("boardtype", "0x0665")
713 && nvram_match("boardrev", "0x1301") && nvram_match("model", "R1D")) {
714 bcm947xx_flash_parts
[nparts
].offset
= 0xFF0000;
717 bcm947xx_flash_parts
[nparts
].offset
= (size
- 0x10000) - bcm947xx_flash_parts
[nparts
].size
;
719 bcm947xx_flash_parts
[nparts
].offset
= size
- bcm947xx_flash_parts
[nparts
].size
;
724 return bcm947xx_flash_parts
;
727 EXPORT_SYMBOL(init_mtd_partitions
);
729 #endif /* CONFIG_MTD_PARTITIONS */
732 #ifdef CONFIG_MTD_NFLASH
734 #define NFLASH_PARTS_NUM 7
735 static struct mtd_partition bcm947xx_nflash_parts
[NFLASH_PARTS_NUM
] = {{0}};
738 lookup_nflash_rootfs_offset(hndnand_t
*nfl
, struct mtd_info
*mtd
, int offset
, size_t size
)
740 struct romfs_super_block
*romfsb
;
741 struct cramfs_super
*cramfsb
;
742 struct dummy_super_block
*squashfsb
;
743 struct trx_header
*trx
;
745 uint blocksize
, pagesize
, mask
, blk_offset
, off
, shift
= 0;
748 pagesize
= nfl
->pagesize
;
749 buf
= (unsigned char *)kmalloc(pagesize
, GFP_KERNEL
);
751 printk("lookup_nflash_rootfs_offset: kmalloc fail\n");
755 romfsb
= (struct romfs_super_block
*) buf
;
756 cramfsb
= (struct cramfs_super
*) buf
;
757 squashfsb
= (void *) buf
;
758 trx
= (struct trx_header
*) buf
;
760 /* Look at every block boundary till 16MB; higher space is reserved for application data. */
761 blocksize
= mtd
->erasesize
;
762 printk("lookup_nflash_rootfs_offset: offset = 0x%x\n", offset
);
763 for (off
= offset
; off
< offset
+ size
; off
+= blocksize
) {
764 mask
= blocksize
- 1;
765 blk_offset
= off
& ~mask
;
766 if (hndnand_checkbadb(nfl
, blk_offset
) != 0)
768 memset(buf
, 0xe5, pagesize
);
769 if ((ret
= hndnand_read(nfl
, off
, pagesize
, buf
)) != pagesize
) {
771 "%s: nflash_read return %d\n", mtd
->name
, ret
);
775 /* Try looking at TRX header for rootfs offset */
776 if (le32_to_cpu(trx
->magic
) == TRX_MAGIC
) {
778 off
= offset
+ (le32_to_cpu(trx
->offsets
[1]) & ~mask
) - blocksize
;
779 shift
= (le32_to_cpu(trx
->offsets
[1]) & mask
);
780 romfsb
= (struct romfs_super_block
*)((unsigned char *)romfsb
+ shift
);
781 cramfsb
= (struct cramfs_super
*)((unsigned char *)cramfsb
+ shift
);
782 squashfsb
= (struct squashfs_super_block
*)
783 ((unsigned char *)squashfsb
+ shift
);
787 /* romfs is at block zero too */
788 if (romfsb
->word0
== ROMSB_WORD0
&&
789 romfsb
->word1
== ROMSB_WORD1
) {
791 "%s: romfs filesystem found at block %d\n",
792 mtd
->name
, off
/ blocksize
);
797 if (cramfsb
->magic
== CRAMFS_MAGIC
) {
799 "%s: cramfs filesystem found at block %d\n",
800 mtd
->name
, off
/ blocksize
);
804 if (squashfsb
->s_magic
== SQUASHFS_MAGIC
) {
806 "%s: squash filesystem with lzma found at block %d\n",
807 mtd
->name
, off
/ blocksize
);
819 struct mtd_partition
*
820 init_nflash_mtd_partitions(hndnand_t
*nfl
, struct mtd_info
*mtd
, size_t size
)
830 uint32 bootossz
= nfl_boot_os_size(nfl
);
831 uint boardnum
= bcm_strtoul(nvram_safe_get("boardnum"), NULL
, 0);
833 if (((boardnum
== 1) || (nvram_get("boardnum") == NULL
)) && nvram_match("boardtype", "0xF646") && nvram_match("boardrev", "0x1100")) {
834 bootossz
= 0x4000000;
837 else if (((boardnum
== 1) || (nvram_get("boardnum") == NULL
)) && nvram_match("boardtype","0xD646") && nvram_match("boardrev","0x1100")) {
838 bootossz
= 0x4000000;
841 #ifdef CONFIG_FAILSAFE_UPGRADE
842 char *img_boot
= nvram_get(BOOTPARTITION
);
843 char *imag_1st_offset
= nvram_get(IMAGE_FIRST_OFFSET
);
844 char *imag_2nd_offset
= nvram_get(IMAGE_SECOND_OFFSET
);
845 unsigned int image_first_offset
= 0;
846 unsigned int image_second_offset
= 0;
847 char dual_image_on
= 0;
849 /* The image_1st_size and image_2nd_size are necessary if the Flash does not have any
852 dual_image_on
= (img_boot
!= NULL
&& imag_1st_offset
!= NULL
&& imag_2nd_offset
!= NULL
);
855 image_first_offset
= simple_strtol(imag_1st_offset
, NULL
, 10);
856 image_second_offset
= simple_strtol(imag_2nd_offset
, NULL
, 10);
857 printk("The first offset=%x, 2nd offset=%x\n", image_first_offset
,
858 image_second_offset
);
861 #endif /* CONFIG_FAILSAFE_UPGRADE */
863 bootdev
= soc_boot_dev((void *)sih
);
864 knldev
= soc_knl_dev((void *)sih
);
866 if (bootdev
== SOC_BOOTDEV_NANDFLASH
) {
867 bootsz
= boot_partition_size(nfl
->base
);
868 if (bootsz
> mtd
->erasesize
) {
869 /* Prepare double space in case of bad blocks */
870 bootsz
= (bootsz
<< 1);
872 /* CFE occupies at least one block */
873 bootsz
= mtd
->erasesize
;
875 printk("Boot partition size = %d(0x%x)\n", bootsz
, bootsz
);
878 bcm947xx_nflash_parts
[nparts
].name
= "boot";
879 bcm947xx_nflash_parts
[nparts
].size
= bootsz
;
880 bcm947xx_nflash_parts
[nparts
].offset
= top
;
881 //bcm947xx_nflash_parts[nparts].mask_flags = MTD_WRITEABLE; /* forces on read only */
882 offset
= bcm947xx_nflash_parts
[nparts
].size
;
885 /* Setup NVRAM MTD partition */
886 bcm947xx_nflash_parts
[nparts
].name
= "nvram";
888 bcm947xx_nflash_parts
[nparts
].size
= nvsz
;
890 bcm947xx_nflash_parts
[nparts
].size
= nfl_boot_size(nfl
) - offset
;
891 bcm947xx_nflash_parts
[nparts
].offset
= offset
;
893 offset
= nfl_boot_size(nfl
);
897 if (knldev
== SOC_KNLDEV_NANDFLASH
) {
898 /* Setup kernel MTD partition */
899 bcm947xx_nflash_parts
[nparts
].name
= "linux";
900 #ifdef CONFIG_FAILSAFE_UPGRADE
902 bcm947xx_nflash_parts
[nparts
].size
=
903 image_second_offset
- image_first_offset
;
907 bcm947xx_nflash_parts
[nparts
].size
= nparts
?
908 (bootossz
- nfl_boot_size(nfl
)) :
909 nfl_boot_os_size(nfl
);
911 /* fix linux offset for the R6300V2/R6250 units */
912 if (nvram_match("boardnum","679") && nvram_match("boardtype", "0x0646") && nvram_match("boardrev", "0x1110")) {
914 bcm947xx_nflash_parts
[nparts
].size
-= 0x180000;
917 if (nvram_match("boardnum", "32") && nvram_match("boardtype", "0x0665") && nvram_match("boardrev", "0x1301")) {
918 bcm947xx_nflash_parts
[nparts
].size
+= 0x200000;
921 bcm947xx_nflash_parts
[nparts
].offset
= offset
;
923 shift
= lookup_nflash_rootfs_offset(nfl
, mtd
, offset
,
924 bcm947xx_nflash_parts
[nparts
].size
);
926 #ifdef CONFIG_FAILSAFE_UPGRADE
928 offset
= image_second_offset
;
934 /* Setup rootfs MTD partition */
935 bcm947xx_nflash_parts
[nparts
].name
= "rootfs";
936 #ifdef CONFIG_FAILSAFE_UPGRADE
938 bcm947xx_nflash_parts
[nparts
].size
= image_second_offset
- shift
;
941 bcm947xx_nflash_parts
[nparts
].size
= bootossz
- shift
;
942 bcm947xx_nflash_parts
[nparts
].offset
= shift
;
943 bcm947xx_nflash_parts
[nparts
].mask_flags
= MTD_WRITEABLE
;
944 offset
= nfl_boot_os_size(nfl
);
948 #ifdef CONFIG_DUAL_TRX /* ASUS Setup 2nd kernel MTD partition */
949 bcm947xx_nflash_parts
[nparts
].name
= "linux2";
950 bcm947xx_nflash_parts
[nparts
].size
= NFL_BOOT_OS_SIZE
;
951 bcm947xx_nflash_parts
[nparts
].offset
= NFL_BOOT_OS_SIZE
;
953 /* Setup rootfs MTD partition */
954 bcm947xx_nflash_parts
[nparts
].name
= "rootfs2";
955 bcm947xx_nflash_parts
[nparts
].size
= NFL_BOOT_OS_SIZE
- shift
;
956 bcm947xx_nflash_parts
[nparts
].offset
= NFL_BOOT_OS_SIZE
+ shift
;
957 bcm947xx_nflash_parts
[nparts
].mask_flags
= MTD_WRITEABLE
;
959 #endif /* End of ASUS 2nd FW partition*/
961 /* again, to fix R6300V2 and R7000 */
962 if (nvram_match("boardnum", "32") && nvram_match("boardtype", "0x0665") && nvram_match("boardrev", "0x1301")) {
964 bcm947xx_nflash_parts
[nparts
].name
= "board_data";
965 bcm947xx_nflash_parts
[nparts
].size
= 0x40000;
966 bcm947xx_nflash_parts
[nparts
].offset
= 0x2200000;
970 if ( nvram_match("boardnum","679") && nvram_match("boardtype", "0x0646")
971 && (nvram_match("boardrev", "0x1110")) ) {
972 bcm947xx_nflash_parts
[nparts
].name
= "board_data";
973 bcm947xx_nflash_parts
[nparts
].size
= 0x20000;
974 bcm947xx_nflash_parts
[nparts
].offset
= 0x200000;
977 #ifdef CONFIG_FAILSAFE_UPGRADE
978 /* Setup 2nd kernel MTD partition */
980 bcm947xx_nflash_parts
[nparts
].name
= "linux2";
981 bcm947xx_nflash_parts
[nparts
].size
= bootossz
- image_second_offset
;
982 bcm947xx_nflash_parts
[nparts
].offset
= image_second_offset
;
983 shift
= lookup_nflash_rootfs_offset(nfl
, mtd
, image_second_offset
,
984 bcm947xx_nflash_parts
[nparts
].size
);
986 /* Setup rootfs MTD partition */
987 bcm947xx_nflash_parts
[nparts
].name
= "rootfs2";
988 bcm947xx_nflash_parts
[nparts
].size
= bootossz
- shift
;
989 bcm947xx_nflash_parts
[nparts
].offset
= shift
;
990 bcm947xx_nflash_parts
[nparts
].mask_flags
= MTD_WRITEABLE
;
993 #endif /* CONFIG_FAILSAFE_UPGRADE */
997 #ifdef PLAT_NAND_JFFS2
998 /* Setup the remainder of NAND Flash as FFS partition */
999 if( size
> offset
) {
1000 bcm947xx_nflash_parts
[nparts
].name
= "ffs";
1001 bcm947xx_nflash_parts
[nparts
].size
= size
- offset
;
1002 bcm947xx_nflash_parts
[nparts
].offset
= offset
;
1003 bcm947xx_nflash_parts
[nparts
].mask_flags
= 0;
1004 bcm947xx_nflash_parts
[nparts
].ecclayout
= mtd
->ecclayout
;
1009 return bcm947xx_nflash_parts
;
1012 /* LR: Calling this function directly violates Linux API conventions */
1013 EXPORT_SYMBOL(init_nflash_mtd_partitions
);
1014 #endif /* CONFIG_MTD_NFLASH */
1016 #ifdef CONFIG_CRASHLOG
1017 extern char *get_logbuf(void);
1018 extern char *get_logsize(void);
1020 void nvram_store_crash(void)
1022 struct mtd_info
*mtd
= NULL
;
1025 unsigned char buf
[16];
1029 printk("Trying to store crash\n");
1031 mtd
= get_mtd_device_nm("crash");
1035 buf_len
= get_logsize();
1036 buffer
= get_logbuf();
1037 if (buf_len
> mtd
->size
)
1038 buf_len
= mtd
->size
;
1040 memset(buf
,0,sizeof(buf
));
1041 mtd
->read(mtd
, 0, sizeof(buf
), &len
, buf
);
1042 for (len
=0;len
<sizeof(buf
);len
++)
1043 if (buf
[len
]!=0xff) {
1044 printk("Could not save crash, partition not clean\n");
1047 if (len
== sizeof(buf
)) {
1048 mtd
->write(mtd
, 0, buf_len
, &len
, buffer
);
1050 printk("Crash Saved\n");
1053 printk("Could not find NVRAM partition\n");
1056 #endif /* CONFIG_CRASHLOG */