OpenWrt Forum Archive

Topic: Dlink DSL-2500 support in brcm63xx

The content of this topic has been archived on 8 Apr 2018. There are no obvious gaps in this topic, but there may still be some posts missing at the end.

Hello.
I have some old DSL-2500 devices BRU_C revision, BCM6332, 8Mb ram, 2Mb spi flash NXW25P16, 96332CG_F4W board id. I have idea use it as a network gpio box with openwrt. And have some problems.
I temporally solder 32Mb ram for testing and build current trunk BARRIER BREAKER (Bleeding Edge, r40569), ramdisk image, netboot it and get message:

Auto run second count down: 110
0x80010000/3837052 0x803b8c7c/246856 Entry at 0x80014d10
Closing network.
Starting program at 0x80014d10
[    0.000000] Linux version 3.10.36 (archie@build41) (gcc version 4.8.3 (OpenWrt/Linaro GCC 4.8-2014.01 r40569) ) #6 Sat Apr 26 21:23:14 EEST 2014
[    0.000000] Detected Broadcom 0x6338 CPU revision a2
[    0.000000] CPU frequency is 240 MHz
[    0.000000] 32MB of RAM installed
[    0.000000] registering 8 GPIOs
[    0.000000] board_bcm963xx: Boot address 0xbfc00000
[    0.000000] board_bcm963xx: CFE version: unknown
[    0.000000] board_bcm963xx: unknown bcm963xx board: 96332CG_F4W
[    0.000000] bootconsole [early0] enabled
[    0.000000] CPU revision is: 00029010 (Broadcom BCM6338)
[    0.000000] Kernel panic - not syncing: unable to detect bcm963xx board
reset

Then i add to board_bcm963xx.c

+static struct board_info __initdata board_96332cg_f4w = {
+    .name                = "96332CG_F4W",
+    .expected_cpu_id        = 0x6338,
+
+    .has_uart0            = 1,
+    .has_enet0            = 1,
+    .enet0 = {
+        .has_phy        = 1,
+        .phy_id            = 0,
+        .force_speed_100    = 1,
+        .force_duplex_full    = 1,
+    },
+
+    .leds = {
+        {
+            .name        = "96332CG_F4W:green:wan",
+            .gpio        = 4,
+            .active_low    = 1,
+        },
+        {
+            .name        = "96332CG_F4W:green:ppp",
+            .gpio        = 3,
+            .active_low    = 1,
+        },
+        {
+            .name        = "96332CG_F4W:green:power",
+            .gpio        = 0,
+            .active_low    = 1,
+            .default_trigger = "default-on",
+        },
+        {
+            .name        = "96332CG_F4W:green:stop",
+            .gpio        = 6,
+            .active_low    = 1,
+        },
+    },
+};

 static struct board_info __initdata board_96338gw = {
     .name                = "96338GW",
     .expected_cpu_id        = 0x6338,
@@ -4793,6 +4909,8 @@
     &board_FAST2704V2,
 #endif
 #ifdef CONFIG_BCM63XX_CPU_6338
+    &board_96332cg_f4w,
     &board_96338gw,
     &board_96338w,
     &board_96338w2_e7t,

rebuild and netboot ok, here is log http://pastebin.com/6aiSzj1g , but have some problems:
1. board_prom_init doesn't detect CFE version, board_bcm963xx: CFE version: unknown
i made some research and add before CFE version detect in board_bcm963xx.c:

cfe = boot_addr + BCM963XX_CFE_VERSION_OFFSET;
    printk(KERN_INFO PFX "%x %x %x %x %x %x %x %x - %x %x %x %x %x %x %x %x\n", cfe[0], cfe[1], cfe[2], cfe[3], cfe[4], cfe[5], cfe[6], cfe[7], cfe[8], cfe[9], cfe[10], cfe[11], cfe[12], cfe[13], cfe[14], cfe[15]);

output: board_bcm963xx: 63 65 76 00 76 00 0c 00 0c 00 00 00 00 00 00 00
but must be:   00000570: 63 66 65 2d 76 01 00 25 0c 01 00 00 00 00 00 00 
so it reads every first byte of 16 bit word and i have no idea why.

2. spi flash is not detected, more in log

[    2.432000] physmap platform flash device: 00400000 at 1fc00000
[    2.444000] physmap-flash physmap-flash.0: map_probe failed
[    2.456000] bcm63xx-spi bcm63xx-spi: at 0xfffe0c00 (irq 9, FIFOs size 63)

3. ethernet not working. Netboot ok, but after boot i assign manually adress/mask and no response.

I have some skills in C programming, so if someone help me with right direction i can myself test it.
Sorry for language, english is not my native.

(Last edited by mgmzog on 27 Apr 2014, 22:23)

Ok, some prgress with serial flash:
added this to dev-flash.c
case BCM6338_CPU_ID:
+    return BCM63XX_FLASH_TYPE_SERIAL;

and get:
[    2.436000] m25p80 spi0.0: found w25x16, expected m25p80
[    2.440000] m25p80 spi0.0: w25x16 (2048 Kbytes)
[    2.444000] m25p80 spi0.0: unable to do transfers larger than FIFO size (261 > 63)
[    2.456000] Searching for RedBoot partition table in spi0.0 at offset 0x1f0000
[    2.464000] m25p80 spi0.0: unable to do transfers larger than FIFO size (65541 > 63)
[    2.472000] m25p80: probe of spi0.0 failed with error -5
[    2.476000] bcm63xx-spi bcm63xx-spi: at 0xfffe0c00 (irq 9, FIFOs size 63)

full log here:
http://pastebin.com/n50by38f

Update:
Added in int __init bcm63xx_flash_register(int num_caldata, struct bcm63xx_caldata *caldata)
case BCM63XX_FLASH_TYPE_SERIAL:
        if (BCMCPU_IS_6338())
            bcm63xx_flash_data.max_transfer_len = SPI_6348_MSG_DATA_SIZE;

now spi flash work, but squashfs cannot mount from it and i created dd images of mtdblock0,1,2 and data in dumps is wron
g.

(Last edited by mgmzog on 27 Apr 2014, 13:06)

Ok, have some progress.
I switch to current stable branch 12.09
Add the same changes. Now spi flash detected and works ok. But jffs2 not mount because of small flash. Now try get smaller image and 2 problems still have:
1. board_prom_init doesn't detect CFE version, board_bcm963xx: CFE version: unknown
2. ethernet not working. Netboot ok, but after boot i assign manually adress/mask and no response.
log here: http://pastebin.com/4Y8xUNRx

Hi, are you aware your board may be affected by an SPI bug?. I did send a patch to the mailing list:

http://patchwork.openwrt.org/patch/4817/

Looks like SPI cannot make data transfers > 58 otherwise it returns random data. Not sure if this is true for your board since it seems it boots ok
I recommend you to use this code for the max transfer length

case BCM63XX_FLASH_TYPE_SERIAL:
        if (BCMCPU_IS_6338())
            bcm63xx_flash_data.max_transfer_len = 56;

I tested 58 without any problem. but 56 might be a safer value.

Also you need a fixup for SPI writes as done with SPI reads, probably after booting your board it cannot initialize the default enviromnent writing it to the spi flash drive. For the reads, this is currently the patch
https://dev.openwrt.org/browser/trunk/t … eads.patch

But for writes it isn't still implemented, but it is something very similar:

--- a/drivers/mtd/devices/m25p80.c
+++ b/drivers/mtd/devices/m25p80.c
@@ -419,10 +419,9 @@
  * FLASH_PAGESIZE chunks.  The address range may be any size provided
  * it is within the physical boundaries.
  */
-static int m25p80_write(struct mtd_info *mtd, loff_t to, size_t len,
+static int __m25p80_write(struct m25p *flash, loff_t to, size_t len,
     size_t *retlen, const u_char *buf)
 {
-    struct m25p *flash = mtd_to_m25p(mtd);
     u32 page_offset, page_size;
     struct spi_transfer t[2];
     struct spi_message m;
@@ -501,6 +500,30 @@
     return 0;
 }
 
+static int m25p80_write(struct mtd_info *mtd, loff_t to, size_t len,
+    size_t *retlen, const u_char *buf)
+{
+    struct m25p *flash = mtd_to_m25p(mtd);
+    size_t off;
+    size_t write_len = flash->max_transfer_len;
+    size_t part_len;
+    int ret = 0;
+
+    if (!write_len)
+        return __m25p80_write(flash, to, len, retlen, buf);
+
+    *retlen = 0;
+
+    for (off = 0; off < len && !ret; off += write_len) {
+        ret = __m25p80_write(flash, to + off, min(len - off, write_len),
+                    &part_len, buf + off);
+            *retlen += part_len;
+    }
+
+    return ret;
+}
+
+
 static int sst_write(struct mtd_info *mtd, loff_t to, size_t len,
         size_t *retlen, const u_char *buf)
 {

So try to make the changes shown in this patch to the kernel. Also the bcm63xx SPI driver might be partially broken in AA, you should try trunk first.
Let me know if you are having problems with the transfer length, and if this patch solves your problems.

You made a nice job hacking your board.

Regards

Hi.
Thanks for point to right direction. I switch to current openwrt trunk. And see 'max_transfer' bug. When by default set bcm63xx_flash_data.max_transfer_len = SPI_6348_MSG_DATA_SIZE; mtd don't detect rootfs on flash and read bad data from flash:

[    2.684000] bcm63xxpart: CFE boot tag CRC invalid (expected ffffffff, actual bc2b198b)
[    2.692000] bcm63xxpart: Partition 0 is CFE offset 0 and length 10000
[    2.700000] bcm63xxpart: Partition 1 is nvram offset 1f0000 and length 10000
[    2.708000] bcm63xxpart: Partition 2 is linux offset 10000 and length 1e0000
[    2.716000] bcm63xxpart: Spare partition is offset 10000 and length 1e0000
[    2.724000] 3 bcm63xxpart partitions found on MTD device spi0.0

then i set bcm63xx_flash_data.max_transfer_len = SPI_6348_MSG_DATA_SIZE-7; (i.e. 56) all work ok.

Then i do work with write. Before patch m25p80.c i try and get after start:

[   30.704000] m25p80 spi0.0: unable to do transfers larger than FIFO size (72 > 63)
[   30.712000] jffs2: Write of 68 bytes at 0x0005000c failed. returned 0, retlen -4
[   30.720000] m25p80 spi0.0: unable to do transfers larger than FIFO size (72 > 63)
[   30.728000] jffs2: Write of 68 bytes at 0x00050050 failed. returned 0, retlen -4

then i add you patch to m25p80.c and write to spi work ok now.
Now system boot ok and i have issues with network only.

But bad news for me is that i try this build on the same modem but with factory memory amount 8Mb, and it is very bad, freeze, not make jffs2 at start. So next i try to recompile gpl sources from dlink maby will be better with performance.

boot log http://pastebin.com/Bw2pt6Jx
summary patch:

--- a/drivers/mtd/devices/m25p80.c
+++ b/drivers/mtd/devices/m25p80.c
@@ -419,10 +419,9 @@
  * FLASH_PAGESIZE chunks.  The address range may be any size provided
  * it is within the physical boundaries.
  */
-static int m25p80_write(struct mtd_info *mtd, loff_t to, size_t len,
+static int __m25p80_write(struct m25p *flash, loff_t to, size_t len,
     size_t *retlen, const u_char *buf)
 {
-    struct m25p *flash = mtd_to_m25p(mtd);
     u32 page_offset, page_size;
     struct spi_transfer t[2];
     struct spi_message m;
@@ -501,6 +500,30 @@
     return 0;
 }
 
+static int m25p80_write(struct mtd_info *mtd, loff_t to, size_t len,
+    size_t *retlen, const u_char *buf)
+{
+    struct m25p *flash = mtd_to_m25p(mtd);
+    size_t off;
+    size_t write_len = flash->max_transfer_len;
+    size_t part_len;
+    int ret = 0;
+
+    if (!write_len)
+        return __m25p80_write(flash, to, len, retlen, buf);
+
+    *retlen = 0;
+
+    for (off = 0; off < len && !ret; off += write_len) {
+        ret = __m25p80_write(flash, to + off, min(len - off, write_len),
+                    &part_len, buf + off);
+            *retlen += part_len;
+    }
+
+    return ret;
+
+}
+
 static int sst_write(struct mtd_info *mtd, loff_t to, size_t len,
         size_t *retlen, const u_char *buf)
 {
--- a/arch/mips/bcm63xx/boards/board_bcm963xx.c
+++ b/arch/mips/bcm63xx/boards/board_bcm963xx.c
@@ -796,6 +796,120 @@
  * known 6338 boards
  */
 #ifdef CONFIG_BCM63XX_CPU_6338
+static struct board_info __initdata board_96332cg_f4w = {
+    .name                = "96332CG_F4W",
+    .expected_cpu_id        = 0x6338,
+
+    .has_uart0            = 1,
+    .has_enet0            = 1,
+    .enet0 = {
+        .has_phy        = 1,
+        .phy_id            = 0,
+        .force_speed_100    = 1,
+        .force_duplex_full    = 1,
+    },
+
+    .leds = {
+        {
+            .name        = "96332CG_F4W:green:g0",
+            .gpio        = 0,
+            .active_low    = 1,
+        },
+        {
+            .name        = "96332CG_F4W:green:g1",
+            .gpio        = 1,
+            .active_low    = 1,
+        },
+        {
+            .name        = "96332CG_F4W:green:g2",
+            .gpio        = 2,
+            .active_low    = 1,
+        },
+        {
+            .name        = "96332CG_F4W:green:g3",
+            .gpio        = 3,
+            .active_low    = 1,
+        },
+{
+            .name        = "96332CG_F4W:green:g4",
+            .gpio        = 4,
+            .active_low    = 1,
+        },
+        {
+            .name        = "96332CG_F4W:green:g5",
+            .gpio        = 5,
+            .active_low    = 1,
+        },
+        {
+            .name        = "96332CG_F4W:green:g6",
+            .gpio        = 6,
+            .active_low    = 1,
+        },
+        {
+            .name        = "96332CG_F4W:green:g7",
+            .gpio        = 7,
+            .active_low    = 1,
+        },
+    },
+};
+
+static struct board_info __initdata board_96332cg = {
+    .name                = "96332CG",
+    .expected_cpu_id        = 0x6338,
+
+    .has_uart0            = 1,
+    .has_enet0            = 1,
+    .enet0 = {
+        .has_phy        = 1,
+        .phy_id            = 0,
+        .force_speed_100    = 1,
+        .force_duplex_full    = 1,
+    },
+
+    .leds = {
+        {
+            .name        = "96332CG:green:g0",
+            .gpio        = 0,
+            .active_low    = 1,
+        },
+        {
+            .name        = "96332CG:green:g1",
+            .gpio        = 1,
+            .active_low    = 1,
+        },
+        {
+            .name        = "96332CG:green:g2",
+            .gpio        = 2,
+            .active_low    = 1,
+        },
+        {
+            .name        = "96332CG:green:g3",
+            .gpio        = 3,
+            .active_low    = 1,
+        },
+{
+            .name        = "96332CG:green:g4",
+            .gpio        = 4,
+            .active_low    = 1,
+        },
+        {
+            .name        = "96332CG:green:g5",
+            .gpio        = 5,
+            .active_low    = 1,
+        },
+        {
+            .name        = "96332CG:green:g6",
+            .gpio        = 6,
+            .active_low    = 1,
+        },
+        {
+            .name        = "96332CG:green:g7",
+            .gpio        = 7,
+            .active_low    = 1,
+        },
+    },
+};
+
 static struct board_info __initdata board_96338gw = {
     .name                = "96338GW",
     .expected_cpu_id        = 0x6338,
@@ -4793,6 +4907,8 @@
     &board_FAST2704V2,
 #endif
 #ifdef CONFIG_BCM63XX_CPU_6338
+    &board_96332cg_f4w,
+    &board_96332cg,
     &board_96338gw,
     &board_96338w,
     &board_96338w2_e7t,
--- a/arch/mips/bcm63xx/boards/dev-flash.c
+++ b/arch/mips/bcm63xx/boards/dev-flash.c
@@ -101,6 +101,7 @@
         else
             return BCM63XX_FLASH_TYPE_NAND;
     case BCM6338_CPU_ID:
+        return BCM63XX_FLASH_TYPE_SERIAL;
     case BCM6345_CPU_ID:
     case BCM6348_CPU_ID:
         /* no way to auto detect so assume parallel */
@@ -226,7 +227,10 @@
 
         if (BCMCPU_IS_6358() || BCMCPU_IS_6368())
             bcm63xx_flash_data.max_transfer_len = SPI_6358_MSG_DATA_SIZE;
-
+        
+        if (BCMCPU_IS_6338())
+            bcm63xx_flash_data.max_transfer_len = SPI_6348_MSG_DATA_SIZE - 7;
+        
         return spi_register_board_info(bcm63xx_spi_flash_info,
                     ARRAY_SIZE(bcm63xx_spi_flash_info));
     case BCM63XX_FLASH_TYPE_NAND:

(Last edited by mgmzog on 1 May 2014, 19:25)

Good to know the SPI flash is working OK, this will be is useful for other boards.

I'm not sure you did define correctly the eth0. It's an internal phy for sure, and these phys are commonly defined as this

    .enet0 = {
        .has_phy        = 1,
        .use_internal_phy    = 1,
    },

Your enet0 structure maybe OK, but I think the phy_id should be 1 not 0.

About having 8 MB RAM for Openwrt, this makes almost imposible to run it, unless you make a bare system without almost nothing installed.

(Last edited by danitool on 1 May 2014, 20:18)

Thanks, add change
    .enet0 = {
        .has_phy        = 1,
        .phy_id            = 1,
        .force_speed_100    = 1,
        .force_duplex_full    = 1,
    },
but anyway network not work. and netifd not set lan adress. if i manually add 192.168.1.100/24 it add, but lost ping.

default network config is

config interface 'loopback'
        option ifname 'lo'
        option proto 'static'
        option ipaddr '127.0.0.1'
        option netmask '255.0.0.0'

config interface 'lan'
        option ifname 'eth0'
        option type 'bridge'
        option proto 'static'
        option ipaddr '192.168.1.1'
        option netmask '255.255.255.0'
        option ip6assign '60'

config interface 'wan6'
        option ifname '@wan'
        option proto 'dhcpv6'

config globals 'globals'
        option ula_prefix 'fd52:4194:1b45::/48'

i change to

config interface 'loopback'
        option ifname 'lo'
        option proto 'static'
        option ipaddr '127.0.0.1'
        option netmask '255.0.0.0'

config interface 'lan'
        option ifname 'eth0'
        option proto 'static'
        option ipaddr '192.168.1.1'
        option netmask '255.255.255.0'
        option ip6assign '60'

config interface 'wan6'
        option ifname '@wan'
        option proto 'dhcpv6'

config globals 'globals'
        option ula_prefix 'fd52:4194:1b45::/48'

and then change to

config interface 'loopback'
        option ifname 'lo'
        option proto 'static'
        option ipaddr '127.0.0.1'
        option netmask '255.0.0.0'

config interface 'lan'
        option ifname 'eth0'
        option proto 'static'
        option ipaddr '192.168.1.100'
        option netmask '255.255.255.0'

anyway not work and netifd not set adress

eth0      Link encap:Ethernet  HWaddr 00:24:01:5B:E0:84  
          UP BROADCAST MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)
          Interrupt:16 

Did you try with?

    .enet0 = {
        .has_phy        = 1,
        .use_internal_phy    = 1,
    },

Sorry, my mistake. Changed to internal phy and lan works ok.
More questions:
- why when detects CFE version reads only first byte of 16 bit word ? Maybe bug in old CFE?
- in 12.09 max_transfer_len set to SPI_6348_MSG_DATA_SIZE and spi read works ok, detect mtd partitions, mount it.

boot log with worked spi and lan: http://pastebin.com/aZ2g2pde

(Last edited by mgmzog on 2 May 2014, 13:54)

No idea why it doesn't detect your CFE version, BTW it isn't important, OpenWrt doesn't use it for anything, just to inform at boot time.

About why 12.09 is able to work with max-transfer-length=SPI_6348_MSG_DATA_SIZE, I didn't compare the SPI driver with trunk. I can only say this driver is far from being perfect and seems nobody cares to improve it to work with will all SoCs and with any SPI device. The lack of documentation (Broadcom Corp. doesn't supply any specifications) for the SPI registers doesn't help either.

I work with broadcom sources for dlink 2500 and it was terrible.
So i decide switch back to openwrt current trunk. And found i think why openwrt freeze on devices with 8mb ram.
By default /tmp mount with tmpfs with no option size, and it use half ram size. And on my system with 8Mb use 2.5Mb. I found ticket in older release of opewrt for my problem https://dev.openwrt.org/ticket/286
But now init system in openwrt changed to procd and i can't found where i can add option to mount /tmp with less size.
Maybe someone can help me with it?

root@(none):/# free
             total         used         free       shared      buffers
Mem:          5076         4604          472            0          200
-/+ buffers:               4404          672
Swap:            0            0            0
root@(none):/# mount
rootfs on / type rootfs (rw)
/dev/root on / type squashfs (ro,relatime)
proc on /proc type proc (rw,noatime)
sysfs on /sys type sysfs (rw,noatime)
tmpfs on /tmp type tmpfs (rw,nosuid,nodev,noatime)
tmpfs on /dev type tmpfs (rw,noatime,size=512k,mode=755)
devpts on /dev/pts type devpts (rw,noatime,mode=600)
root@(none):/# df -h
Filesystem                Size      Used Available Use% Mounted on
rootfs                  768.0K    768.0K         0 100% /
/dev/root               768.0K    768.0K         0 100% /
tmpfs                     2.5M      4.0K      2.5M   0% /tmp
tmpfs                   512.0K         0    512.0K   0% /dev

(Last edited by mgmzog on 10 May 2014, 18:31)

Hi, all.
I aslo have DSL-2520 devices D revision, and i want to use it like internet radio or UTMS router. And after ther discussion I'm not sure that I can do this. Сan tell what I should do?

clerikowl wrote:

Hi, all.
I aslo have DSL-2520 devices D revision, and i want to use it like internet radio or UTMS router. And after ther discussion I'm not sure that I can do this. Сan tell what I should do?

This device don't have usb host, so it can't be used as internet radio or UTMS router.
And very low ram and flash, slow cpu. No support from stock openwrt.

Thank you, pity(
and nothing useful or interesting on this device?

(Last edited by clerikowl on 15 Mar 2015, 19:55)

clerikowl wrote:

Thank you, pity(
and nothing useful or interesting on this device?

Can be used as gpio lan box, but needed more ram for openwrt.
On stock fw here is Russian article: http://robocraft.ru/blog/electronics/538.html

The discussion might have continued from here.