Nand flash driver for bcm47xx wnr3500lv2

If you can live with the Wifi limitations (depends what you want to do with your device), then fixing the Nand (maybe usb) drivers makes sense. Maybe even not for you, but other users might “repurpose” their Broadcom device. Suggestions in my previous reply.

I guess bcm caters to "law enforcement" and leaves backdoors in there. Afterall when you're in law everyone's a suspect.

So I may still dig mine out and see which one I have and if it's doable. Maybe it could be useful as a NAS.

Concerning wifi driver I hope(d) that it would be supported by b43 driver.

Are you sure about that? Because they seem to use the bcrm sdk which is not included in openwrt/lede kernel and which seems to be free software, and which I tried to port to openwrt kernel (unsuccessfully for now). Also the nand driver itself is very clearly free as it is provided by the file "linux-3.10/drivers/mtd/bcm947xx/nand/brcmnand_47xx.c" from the dd-wrt kernel, and there is a free software copyright notice.

My problem for now is that no pci bus seems to be detected in the first place, so the driver which is pci based can't run.

Also note that tomato also runs well on wnr3500lv2 with kernel 2.6.x (usb,nand, wifi) I'm not sure if they also have an agreement.

For those who whish to build a custom .bin image flashable from dd-wrt:

I see arch/mips/pci/pci-bcm47xx.c so it seems that you need to check your pci config in your kernel .config.

Does the bcm sdk contain proprietary code/blobs?

Ok I will see that.

I don't think there is proprietary blob in the sdk, it is available in the folder brcm in the root folder kernel tree.

In my kernel tree pci-bcm47xx.c seems to be compiled since I have a pci-bcm47xx.o. But I still don't have any pci bus when calling pci_find_bus(0, 0) (it returns NULL).

Pierre, I have noticed lately that you're working on this. I had the best of intentions to do some looking around at Netgear's "stock" firmware some months back and instead got busy with other things. Now I won't be able to do anything until after Christmas. But since you've already taken a stab at DD-WRT (and it doesn't surprise me that it was a no-go), why not take a look at the Netgear source codes yourself? They are GPLed since Netgear ported someone else's Linux code base as a starting point. I think the worst thing that might happen is you'll find that the NAND driver was included as an ABI. But you might also find a chunk of source code that you can easily adapt. https://www.downloads.netgear.com/files/GPL/WNR3500Lv2-V1.2.0.44_40.0.84_src.tar.gz.zip

P.S.: If you get a build that seems to work, I will make time to do some testing for you.

@drfranco

Thanks but most honestly I don't know what to do with this code....
I don't see any nand driver in it.

Isn’t the router using the same SoC as the Linksys E4200v1? Should be using the same NAND driver right?

I think that NAND driver is in bcm47186\src\linux\linux-2.6\drivers\mtd\47xxnand

Off course using fresh 2.6.22 kernel

Yes the file brcmand_47xx.c in the folder bcm47186\src\linux\linux-2.6\drivers\mtd\47xxnand seems to be more or less the same as the one in dd-wrt.

The thing is it won't work any better than the other if I don't have a PCI bus detected....

@pparent76 Hmm. Surprising. That must mean that the Netgear code is inheriting a flash ROM access environment from the CFE. Sorry I wasted your time.

@pparent76 Pierre, I looked over my scribbles from earlier this year and there's one thread in an OpenWRT forum about some patch work that was being done by a couple of the developers. I bring it to your attention here because it hasn't been mentioned so far in recent posts here. Best I can tell, Tathagatha Das had a patch that made the WNR3500Lv2 work, but it looks like it might have broken other devices so it may not have been accepted.

Here's the thread on the topic and here's a specific post detailing some patch work to the bus controller code.

Great thanks a lot for the info!

I will look at this patch and see if it can be applied to openwrt 15.05 or lede 17.01!

I tried to carry the dd-wrt driver src/linux/universal/linux-4.4/drivers/mtd/bcm947xx which works on dd-wrt revision 33555

I put the firmware bcm947xx in

linux-04.14.54/drivers/mtd/bcm947xx

I also modify the Kconfig of drivers / mtd to bind the driver.

I can see my driver to select it in the kernel .config

make kernel_menuconfig

#
# Broadcom Flash Devices Support
#
CONFIG_MTD_BCMSFLASH=y
CONFIG_MTD_BRCMNAND=y
CONFIG_MTD_NFLASH=y
# CONFIG_OF is not set
CONFIG_ARCH_MIGHT_HAVE_PC_PARPORT=y
# CONFIG_PARPORT is not set
CONFIG_BLK_DEV=y
# CONFIG_BLK_DEV_NULL_BLK is not set
# CONFIG_BLK_DEV_PCIESSD_MTIP32XX is not set
# CONFIG_BLK_DEV_DAC960 is not set
# CONFIG_BLK_DEV_UMEM is not set
# CONFIG_BLK_DEV_COW_COMMON is not set
CONFIG_BLK_DEV_LOOP=y
CONFIG_BLK_DEV_LOOP_MIN_COUNT=8
# CONFIG_BLK_DEV_CRYPTOLOOP is not set
# CONFIG_BLK_DEV_DRBD is not set
# CONFIG_BLK_DEV_NBD is not set
# CONFIG_BLK_DEV_SX8 is not set
CONFIG_BLK_DEV_RAM=y
CONFIG_BLK_DEV_RAM_COUNT=16
CONFIG_BLK_DEV_RAM_SIZE=4096
# CONFIG_CDROM_PKTCDVD is not set
# CONFIG_ATA_OVER_ETH is not set
# CONFIG_BLK_DEV_RBD is not set
# CONFIG_BLK_DEV_RSXX is not set
# CONFIG_BLK_DEV_NVME is not set
# CONFIG_NVME_FC is not set

The compilation goes very well. I can boot but I still feel that the wrong driver is loaded.

Build Date: Fri May  6 11:54:17 CST 2011
Init Arena
Init Devs.
Boot partition size = 262144(0x40000)
NFLASH Boot partition size = 524288(0x80000)
et0: Broadcom BCM47XX 10/100/1000 Mbps Ethernet Controller 5.60.136
CPU type 0x19749: 480MHz
Tot mem: 131072 KBytes

Device eth0:  hwaddr 50-6A-03-A8-39-9A, ipaddr 192.168.1.1, mask 255.255.255.0
        gateway not set, nameserver not set
Checking crc...done.
Loader:raw Filesys:raw Dev:flash0.os File: Options:(null)
Loading: ........ 4722700 bytes read
Entry at 0x80001000
Closing network.
Starting program at 0x80001000
[    0.000000] Linux version 4.14.54 (root@2ISSV038) (gcc version 7.3.0 (OpenWrt GCC 7.3.0 r7188-b0b5c64c22)) #0 Mon Jul 30 16:25:17 2018
[    0.000000] CPU0 revision is: 00019749 (MIPS 74Kc)
[    0.000000] bcm47xx: Using bcma bus
[    0.000000] bcma: bus0: Found chip with id 0x5357, rev 0x02 and package 0x0A
[    0.000000] Determined physical RAM map:
[    0.000000]  memory: 07fff000 @ 00000000 (usable)
[    0.000000] Initrd not found or empty - disabling initrd
[    0.000000] Primary instruction cache 32kB, VIPT, 4-way, linesize 32 bytes.
[    0.000000] Primary data cache 32kB, 4-way, VIPT, cache aliases, linesize 32 bytes
[    0.000000] This processor doesn't support highmem. -131068k highmem ignored
[    0.000000] Zone ranges:
[    0.000000]   Normal   [mem 0x0000000000000000-0x0000000007ffefff]
[    0.000000]   HighMem  empty
[    0.000000] Movable zone start for each node
[    0.000000] Early memory node ranges
[    0.000000]   node   0: [mem 0x0000000000000000-0x0000000007ffefff]
[    0.000000] Initmem setup node 0 [mem 0x0000000000000000-0x0000000007ffefff]
[    0.000000] random: get_random_bytes called from start_kernel+0x90/0x478 with crng_init=0
[    0.000000] Built 1 zonelists, mobility grouping on.  Total pages: 32511
[    0.000000] Kernel command line: noinitrd console=ttyS0,115200
[    0.000000] PID hash table entries: 512 (order: -1, 2048 bytes)
[    0.000000] Dentry cache hash table entries: 16384 (order: 4, 65536 bytes)
[    0.000000] Inode-cache hash table entries: 8192 (order: 3, 32768 bytes)
[    0.000000] Writing ErrCtl register=00000000
[    0.000000] Readback ErrCtl register=00000000
[    0.000000] Memory: 124872K/131068K available (3509K kernel code, 144K rwdata, 792K rodata, 216K init, 301K bss, 6196K reserved, 0K cma-reserved, 0K highmem)
[    0.000000] SLUB: HWalign=32, Order=0-3, MinObjects=0, CPUs=1, Nodes=1
[    0.000000] NR_IRQS: 128
[    0.000000] bcma: bus0: Core 0 found: ChipCommon (manuf 0x4BF, id 0x800, rev 0x26, class 0x0)
[    0.000000] bcma: bus0: Core 1 found: IEEE 802.11 (manuf 0x4BF, id 0x812, rev 0x1C, class 0x0)
[    0.000000] bcma: bus0: Core 2 found: GBit MAC (manuf 0x4BF, id 0x82D, rev 0x03, class 0x0)
[    0.000000] bcma: bus0: Core 3 found: MIPS 74K (manuf 0x4A7, id 0x82C, rev 0x04, class 0x0)
[    0.000000] bcma: bus0: Core 4 found: USB 2.0 Host (manuf 0x4BF, id 0x819, rev 0x05, class 0x0)
[    0.000000] bcma: bus0: Core 5 found: DDR1/DDR2 Memory Controller (manuf 0x4BF, id 0x82E, rev 0x02, class 0x0)
[    0.000000] bcma: bus0: Core 6 found: I2S (manuf 0x4BF, id 0x834, rev 0x02, class 0x0)
[    0.000000] bcma: bus0: Core 7 found: Internal Memory (manuf 0x4BF, id 0x80E, rev 0x0B, class 0x0)
[    0.000000] bcma: bus0: Unsupported ST serial flash (id: 0x0, id2: 0x0)
[    0.000000] bcma: bus0: Early bus registered
[    0.000000] MIPS: machine is Unknown Board
[    0.000000] bcm47xx: Setting up vectored interrupts
[    0.000000] clocksource: MIPS: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 7963585194 ns
[    0.000016] sched_clock: 32 bits at 240MHz, resolution 4ns, wraps every 8947848189ns
[    0.000105] Calibrating delay loop... 239.61 BogoMIPS (lpj=1198080)
[    0.070024] pid_max: default: 32768 minimum: 301
[    0.070409] Mount-cache hash table entries: 1024 (order: 0, 4096 bytes)
[    0.070448] Mountpoint-cache hash table entries: 1024 (order: 0, 4096 bytes)
[    0.074200] clocksource: jiffies: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 19112604462750000 ns
[    0.074252] futex hash table entries: 256 (order: -1, 3072 bytes)
[    0.075200] NET: Registered protocol family 16
[    0.111509] clocksource: Switched to clocksource MIPS
[    0.113705] NET: Registered protocol family 2
[    0.115080] TCP established hash table entries: 1024 (order: 0, 4096 bytes)
[    0.115141] TCP bind hash table entries: 1024 (order: 0, 4096 bytes)
[    0.115187] TCP: Hash tables configured (established 1024 bind 1024)
[    0.115455] UDP hash table entries: 256 (order: 0, 4096 bytes)
[    0.115528] UDP-Lite hash table entries: 256 (order: 0, 4096 bytes)
[    0.116009] NET: Registered protocol family 1
[    0.131897] can not parse nvram name sb/1/boardnum(null) with value 3500L got -22
[    0.147863]  2(S)*
[    0.147869]  3
[    0.147887]  4
[    0.147900]  5
[    0.147912]  6
[    0.147925]  D
[    0.147937]  I
[    0.147949]
[    0.147975]  2(S)
[    0.147981]  3*
[    0.147994]  4
[    0.148006]  5
[    0.148018]  6
[    0.148030]  D
[    0.148043]  I
[    0.148054]
[    0.148080]  2(S)
[    0.148086]  3
[    0.148099]  4*
[    0.148111]  5
[    0.148123]  6
[    0.148135]  D
[    0.148147]  I
[    0.148159]
[    0.148184]  2(S)
[    0.148190]  3
[    0.148202]  4
[    0.148214]  5
[    0.148226]  6
[    0.148238]  D
[    0.148251]  I*
[    0.148262]
[    0.148288]  2(S)
[    0.148294]  3
[    0.148307]  4
[    0.148319]  5*
[    0.148331]  6
[    0.148343]  D
[    0.148355]  I
[    0.148367]
[    0.148394]  2(S)
[    0.148399]  3
[    0.148412]  4
[    0.148424]  5
[    0.148436]  6
[    0.148448]  D*
[    0.148460]  I
[    0.148472]
[    0.148497]  2(S)*
[    0.148503]  3
[    0.148515]  4
[    0.148527]  5
[    0.148540]  6
[    0.148552]  D
[    0.148564]  I
[    0.148575]
[    0.148600]  2(S)
[    0.148606]  3
[    0.148619]  4
[    0.148631]  5
[    0.148643]  6
[    0.148655]  D
[    0.148667]  I*
[    0.148678]
[    0.150453] bcma: bus0: Bus registered
[    0.151730] Crashlog allocated RAM at address 0x3f00000
[    0.157756] workingset: timestamp_bits=30 max_order=15 bucket_order=0
[    0.166978] squashfs: version 4.0 (2009/01/31) Phillip Lougher
[    0.167015] jffs2: version 2.2 (NAND) (SUMMARY) (LZMA) (RTIME) (CMODE_PRIORITY) (c) 2001-2006 Red Hat, Inc.
[    0.185660] io scheduler noop registered
[    0.185697] io scheduler deadline registered (default)
[    0.186011] Serial: 8250/16550 driver, 2 ports, IRQ sharing enabled
[    0.187025] console [ttyS0] disabled
[    0.207321] serial8250.0: ttyS0 at MMIO 0xb8000300 (irq = 2, base_baud = 1250000) is a U6_16550A
[    0.760766] console [ttyS0] enabled
[    0.804475] brd: module loaded
[    0.817610] loop: module loaded
[    0.831847] libphy: Fixed MDIO Bus: probed
[    0.836266] bgmac_bcma bcma0:2: Found PHY addr: 30 (NOREGS)
[    0.844772] libphy: bcma_mdio mii bus: probed
[    0.849232] bgmac_bcma bcma0:2: Support for Roboswitch not implemented
[    1.029465] b53_common: found switch: BCM53115, rev 8
[    1.035954] bgmac_bcma: Broadcom 47xx GBit MAC driver loaded
[    1.042307] bcm47xx-wdt bcm47xx-wdt.0: BCM47xx Watchdog Timer enabled (30 seconds)
[    1.052257] NET: Registered protocol family 10
[    1.063964] Segment Routing with IPv6
[    1.067881] NET: Registered protocol family 17
[    1.072626] 8021q: 802.1Q VLAN Support v1.8
[    1.081050] VFS: Cannot open root device "(null)" or unknown-block(0,0): error -6
[    1.088760] Please append a correct "root=" boot option; here are the available partitions:
[    1.097309] 0100            4096 ram0
[    1.097319]  (driver?)
[    1.103589] 0101            4096 ram1
[    1.103598]  (driver?)
[    1.109811] 0102            4096 ram2
[    1.109816]  (driver?)
[    1.116073] 0103            4096 ram3
[    1.116081]  (driver?)
[    1.122340] 0104            4096 ram4
[    1.122349]  (driver?)
[    1.128563] 0105            4096 ram5
[    1.128569]  (driver?)
[    1.134827] 0106            4096 ram6
[    1.134835]  (driver?)
[    1.141050] 0107            4096 ram7
[    1.141056]  (driver?)
[    1.147314] 0108            4096 ram8
[    1.147322]  (driver?)
[    1.153589] 0109            4096 ram9
[    1.153597]  (driver?)
[    1.159812] 010a            4096 ram10
[    1.159817]  (driver?)
[    1.166163] 010b            4096 ram11
[    1.166172]  (driver?)
[    1.172526] 010c            4096 ram12
[    1.172534]  (driver?)
[    1.178838] 010d            4096 ram13
[    1.178843]  (driver?)
[    1.185189] 010e            4096 ram14
[    1.185198]  (driver?)
[    1.191551] 010f            4096 ram15
[    1.191559]  (driver?)
[    1.197868] Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(0,0)
[    1.208508] Rebooting in 1 seconds..

You would you likely want to use this driver submission:

https://www.mail-archive.com/openwrt-devel@lists.openwrt.org/msg12655.html

though the file drivers/mtd/nand/bcm47xx_nand.c should be dropped in favor of using drivers/mtd/nand/brcmnand/brcmnand.c since the latter is a much more feature complete version of the same driver.

This is a good idea to use 4.14 kernel, which was not availliable on openwrt/lede at the time I worked on it.

First Check if a pci bus is detected at line
pci_find_bus(0, 0)
By adding kernel debug logs.

@ffainelli

Not so easy to apply this patch to newer kernel though, or is it?