FritzBox 7312 (Lantiq AR9) Asterisk VoIP

Hi there,
I was unhappy with the stock AVM firmware on my FritzBox7312 which I am using as an AP and VoIP to analog Phone bridge. So i compiled OpenWRT with a new target created by @juppin.
If I compile OpenWRT without kmod-ltq-vmmc (needed by asterisk chan-lantiq) the system works fine and i can use it as an AP but i can't use the FXS hardware.
If I try to use kmod-ltq-vmmc (and chan-lantiq) the system gets stuck in a boot loop.

[Bootlog with ltq-vmmc enabled]

ROM VER: 1.1.3
CFG 01
[-]

(AVM) EVA Revision: 1.1820 Version: 2820

(C) Copyright 2005 AVM Date: Jul 16 2013 Time: 15:30:34 (0) 3 0x90000909-0x9000BD1F

[FLASH:] MACRONIX Uniform-Flash 16MB 64 Bytes WriteBuffer
[FLASH:](Eraseregion [0] 128 sectors a 128kB) 
[SYSTEM:] AR9 on 393MHz/393MHz/196MHz

Atheros 8030 detected

Eva_AVM >.................................[    0.000000] Linux version 4.14.44 (jan@Rechner) (gcc version 7.3.0 (OpenWrt GCC 7.3.0 r7063-53822d5eb3)) #0 Wed May 30 21:56:51 2018

[    0.000000] SoC: AR9 rev 1.2

[    0.000000] bootconsole [early0] enabled

[    0.000000] CPU0 revision is: 0001954c (MIPS 34Kc)

[    0.000000] MIPS: machine is FritzBox 7312 (1&1 WLAN-MODEM)

[    0.000000] Determined physical RAM map:

[    0.000000]  memory: 04000000 @ 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 16kB, 4-way, VIPT, no aliases, linesize 32 bytes

[    0.000000] Zone ranges:

[    0.000000]   Normal   [mem 0x0000000000000000-0x0000000003ffffff]

[    0.000000] Movable zone start for each node

[    0.000000] Early memory node ranges

[    0.000000]   node   0: [mem 0x0000000000000000-0x0000000003ffffff]

[    0.000000] Initmem setup node 0 [mem 0x0000000000000000-0x0000000003ffffff]

[    0.000000] random: get_random_bytes called from start_kernel+0x8c/0x474 with crng_init=0

[    0.000000] Built 1 zonelists, mobility grouping on.  Total pages: 16256

[    0.000000] Kernel command line: console=ttyLTQ0,115200

[    0.000000] PID hash table entries: 256 (order: -2, 1024 bytes)

[    0.000000] Dentry cache hash table entries: 8192 (order: 3, 32768 bytes)

[    0.000000] Inode-cache hash table entries: 4096 (order: 2, 16384 bytes)

[    0.000000] Writing ErrCtl register=0006c99d

[    0.000000] Readback ErrCtl register=0006c99d

[    0.000000] Memory: 58136K/65536K available (4119K kernel code, 184K rwdata, 1004K rodata, 1204K init, 219K bss, 7400K reserved, 0K cma-reserved)

[    0.000000] SLUB: HWalign=32, Order=0-3, MinObjects=0, CPUs=1, Nodes=1

[    0.000000] NR_IRQS: 256

[    0.000000] CPU Clock: 393MHz

[    0.000000] clocksource: MIPS: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 9721189849 ns

[    0.000014] sched_clock: 32 bits at 196MHz, resolution 5ns, wraps every 10922685437ns

[    0.007964] Calibrating delay loop... 260.86 BogoMIPS (lpj=521728)

[    0.045990] pid_max: default: 32768 minimum: 301

[    0.050994] Mount-cache hash table entries: 1024 (order: 0, 4096 bytes)

[    0.057497] Mountpoint-cache hash table entries: 1024 (order: 0, 4096 bytes)

[    0.070841] clocksource: jiffies: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 7645041785100000 ns

[    0.080497] futex hash table entries: 256 (order: -1, 3072 bytes)

[    0.086742] pinctrl core: initialized pinctrl subsystem

[    0.093169] NET: Registered protocol family 16

[    0.103186] pinctrl-xway 1e100b10.pinmux: Init done

[    0.108977] dma-xway 1e104100.dma: Init done - hw rev: 6, ports: 5, channels: 20

[    0.125919] PCI host bridge /fpi@10000000/pci@e105400 ranges:

[    0.131588]  MEM 0x0000000018000000..0x0000000019ffffff

[    0.136832]   IO 0x000000001ae00000..0x000000001affffff

[    0.171491] usbcore: registered new interface driver usbfs

[    0.177009] usbcore: registered new interface driver hub

[    0.182390] usbcore: registered new device driver usb

[    0.187708] PCI host bridge to bus 0000:00

[    0.191720] pci_bus 0000:00: root bus resource [mem 0x18000000-0x19ffffff]

[    0.198624] pci_bus 0000:00: root bus resource [io  0x1ae00000-0x1affffff]

[    0.205566] pci_bus 0000:00: root bus resource [??? 0x00000000 flags 0x0]

[    0.212423] pci_bus 0000:00: No busn resource found for root bus, will use [bus 00-ff]

[    0.221078] pci 0000:00:0e.0: BAR 0: assigned [mem 0x18000000-0x1800ffff]

[    0.228690] clocksource: Switched to clocksource MIPS

[    0.235116] NET: Registered protocol family 2

[    0.240546] TCP established hash table entries: 1024 (order: 0, 4096 bytes)

[    0.247463] TCP bind hash table entries: 1024 (order: 0, 4096 bytes)

[    0.253835] TCP: Hash tables configured (established 1024 bind 1024)

[    0.260506] UDP hash table entries: 256 (order: 0, 4096 bytes)

[    0.266286] UDP-Lite hash table entries: 256 (order: 0, 4096 bytes)

[    0.272931] NET: Registered protocol family 1

[    0.284644] gptu: totally 6 16-bit timers/counters

[    0.289511] gptu: misc_register on minor 63

[    0.293603] gptu: succeeded to request irq 126

[    0.298086] gptu: succeeded to request irq 127

[    0.302600] gptu: succeeded to request irq 128

[    0.307114] gptu: succeeded to request irq 129

[    0.311627] gptu: succeeded to request irq 130

[    0.316141] gptu: succeeded to request irq 131

[    0.321683] Crashlog allocated RAM at address 0x3f00000

[    0.329118] workingset: timestamp_bits=30 max_order=14 bucket_order=0

[    0.342895] squashfs: version 4.0 (2009/01/31) Phillip Lougher

[    0.348642] jffs2: version 2.2 (NAND) (SUMMARY) (LZMA) (RTIME) (CMODE_PRIORITY) (c) 2001-2006 Red Hat, Inc.

[    0.374401] io scheduler noop registered

[    0.378229] io scheduler deadline registered (default)

[    0.385142] 1e100c00.serial: ttyLTQ0 at MMIO 0x1e100c00 (irq = 112, base_baud = 0) is a lantiq,asc

[    0.394072] console [ttyLTQ0] enabled
[    0.394072] console [ttyLTQ0] enabled

[    0.401317] bootconsole [early0] disabled
[    0.401317] bootconsole [early0] disabled

[    0.409936] cacheinfo: Failed to find cpu0 device node
[    0.413651] cacheinfo: Unable to detect cache hierarchy for CPU 0
[    0.420112] lantiq nor flash device: 01000000 at 10000000
[    0.425237] ltq_nor: Found 1 x16 devices at 0x0 in 16-bit bank. Manufacturer ID 0x0000c2 Chip ID 0x00227e
[    0.434516] Amd/Fujitsu Extended Query Table at 0x0040
[    0.439607]   Amd/Fujitsu Extended Query version 1.3.
[    0.444588] number of CFI chips: 1
[    0.448004] 4 fixed-partitions partitions found on MTD device ltq_nor
[    0.454344] Creating 4 MTD partitions on "ltq_nor":
[    0.459172] 0x000000000000-0x000000020000 : "urlader"
[    0.465516] 0x000000020000-0x000000f80000 : "firmware"
[    0.511641] 2 eva-fw partitions found on MTD device firmware
[    0.515862] 0x000000020000-0x0000001c574b : "kernel"
[    0.521975] 0x0000001d0100-0x000000f80000 : "rootfs"
[    0.526863] mtd: device 3 (rootfs) set to be root filesystem
[    0.531402] 1 squashfs-split partitions found on MTD device rootfs
[    0.537428] 0x000000840000-0x000000f80000 : "rootfs_data"
[    0.543938] 0x000000f80000-0x000000fc0000 : "tffs (1)"
[    0.549189] 0x000000fc0000-0x000001000000 : "tffs (2)"
[    0.556460] libphy: Fixed MDIO Bus: probed
[    0.559995] libphy: ltq_mii: probed
[    0.644935] Atheros 8030 ethernet 1e180000.etop-ffffffff:00: attached PHY driver [Atheros 8030 ethernet] (mii_bus:phy_addr=1e180000.etop-ffffffff:00, irq=POLL)
[    0.659443] wdt 1f8803f0.watchdog: Init done
[    0.665631] NET: Registered protocol family 10
[    0.676462] Segment Routing with IPv6
[    0.678896] NET: Registered protocol family 17
[    0.683187] 8021q: 802.1Q VLAN Support v1.8
[    0.693478] OF: fdt: not creating '/sys/firmware/fdt': CRC check[    0.709768] VFS: Mounted root (squashfs filesystem) readonly on device 31:3.
[    0.717531] Freeing unused kernel memory: 1204K
[    0.720583] This architecture does not have kernel memory protection.
[    1.132705] random: fast init done
[    2.158582] init: Console is alive
[    2.161001] init: - watchdog -
[    4.244989] kmodloader: loading kernel modules from /etc/modules-boot.d/*
[    4.478221] kmodloader: done loading kernel modules from /etc/modules-boot.d/*
[    4.487971] init: - preinit -
[    5.651687] IPv6: ADDRCONF(NETDEV_UP): eth0: link is not ready
[    5.677408] random: procd: uninitialized urandom read (4 bytes read)
Press the [f] key and hit [enter] to enter failsafe mode
Press the [1], [2], [3] or [4] key and hit [enter] to select the debug level
[    9.354186] jffs2: notice: (382) jffs2_build_xattr_subsystem: complete building xattr subsystem, 15 of xdatum (1 unchecked, 13 orphan) and 64 of xref (7 dead, 48 orphan) found.
[    9.371756] mount_root: overlay filesystem has not been fully initialized yet
[    9.457852] mount_root: switching to jffs2 overlay
[    9.504109] overlayfs: upper fs does not support tmpfile.
- config restore -
[    9.892349] urandom-seed: Seed file not found (/etc/urandom.seed)
[   10.068787] procd: - early -
[   10.070419] procd: - watchdog -
[   10.743559] procd: - watchdog -
[   10.745914] procd: - ubus -
[   11.083495] random: ubusd: uninitialized urandom read (4 bytes read)
[   11.090274] random: ubusd: uninitialized urandom read (4 bytes read)
[   11.095918] random: ubusd: uninitialized urandom read (4 bytes read)
[   11.103597] procd: - init -
Please press Enter to activate this console.
[   11.742124] kmodloader: loading kernel modules from /etc/modules.d/*
[   11.752266] IFXOS, Version 1.5.19 (c) Copyright 2009, Lantiq Deutschland GmbH
[   11.766675] Lantiq TAPI device driver, version 3.13.0.2, (c) 2001-2010 Lantiq Deutschland GmbH
[   11.779228] NET: Registered protocol family 8
[   11.782195] NET: Registered protocol family 20
[   11.794865] PPP generic driver version 2.4.2
[   11.807182] ip6_tables: (C) 2000-2006 Netfilter Core Team
[   11.829898] IFX MEI Version 5.00.00
[   11.842576] Infineon CPE API Driver version: DSL CPE API V3.24.4.4
[   11.856074] Loading modules backported from Linux version wt-2017-11-01-0-gfe248fc2c180
[   11.862662] Backport generated by backports.git v4.14-rc2-1-31-g86cf0e5d
[   11.881160] Lantiq MIPS24KEc MPS driver, version 2.2.2.5, (c) 2006-2010 Lantiq Deutschland GmbH
[   11.888460] request_timer(3, 0x000001AE, 1)...
[   11.888487] successful!

ROM VER: 1.1.3
CFG 01

ROM VER: 1.1.3
CFG 01
[-]

The System starts up until the driver is loaded and crashes...
How do i fix this?

I had a quick look at FRITZ7312.dts in the PR and it seems that nosmp is missing from bootargs. The voice firmware uses the second CPU core, so SMP has to be disabled.
Try compiling with bootargs = "console=ttyLTQ0,115200 nosmp"
You probably need to add VPE parameters to the command line as well. Have a look at VGV7510KW22.dtsi. I don't know how to find out the correct vpe1_load_addr for your device though.

Have a look at the wiki, there's a more detailed explanation: https://openwrt.org/docs/guide-user/services/voip/asterisk/chan-lantiq#add_support_for_new_devices

Since the FB7312 also has 64MB of RAM, bootargs = "console=ttyLTQ0,115200 mem=62M vpe1_load_addr=0x83e00000 vpe1_mem=2M maxvpes=1 maxtcs=1 nosmp" should be worth a try.

Same behaviour with those bootargs as before...
Does chan-lantiq even work on Xway AR9 devices?
I haven't fount anything about AR9 and this driver most of the time it's used with "DANUBE" or "VR9" chips.
Maybe the solution to this problem is the vmmc section in the dtsi file. But i have no clue how to add that.

I´m pretty sure (90%) that in the time of my pr it was working for me.
In AVM gpl source code there was noting about gpio´s for a relay or something else... All stuff that i found in gpl source is documented on the pr on github.

Probably there is a error with a newer kernel version...
Try to use a older 4.14 kernel.
In file "include/kernel-version.mk" change "LINUX_VERSION-4.14" eg. to ".30" and do a make download V=s.
You should see a complain about kernel archive hash mismatch.
Copy the hash and set this hash for your specific kernel version also in "include/kernel-version.mk".

Don´t know if i used 4.9 kernel version for my successful voip gw tests...
At the time of the creation of my PR the lantiq target was on 4.9 but got switched to 4.14 and i removed all stuff (dts and etop patch) from my PR. So will be hard to test 4.9 without adopting the dts and etop patch.

It doesn't seem to be a kernel issue. I tried a two different Kernel versions with the same results.
But i think i know why it is not working. The ltq-vmmc module has different compile options for the different Lantiq CPU families. By selecting Lantig xway as the build target the module is compiled for the Danube, Twinpass and Vinax CPU's but not for AR9 or VR9. I modified the config so that i could compile it with the correct CPU definition.
On boot the vmmc driver loads a firmware.bin into the second CPU core. This firmware is missing for the AR9 CPUs and the DANUBE firmware is not compatible. So I tried the VR9 firmware and it booted!
There are a lot of Errors and Warnings in the kernel log but i think this is a step in the right direction.

Now the big question is: Where do i get the correct Firmware from? Where did the firmware for the other CPUs come form?

This is normally created / downloaded with the make files...
If i take a look into package/kernel/lantiq/ltq-vmmc/Makefile, there is.

ifeq ($(CONFIG_VOICE_CPE_VMMC_WITH_DEVICE_VR9),y)
  CONFIGURE_ARGS += --with-device=VR9
  FW_TARGET:=voice_ar9_firmware.bin
  ...

In make menuconfig i see the symbol for AR9 is in an unknown state:
Symbol: VOICE_CPE_VMMC_WITH_DEVICE_AR9 [=VOICE_CPE_VMMC_WITH_DEVICE_AR9] Type : unknown

And the part for AR9 in the above mentioned Makefile is almost empty with an comment:

ifeq ($(CONFIG_VOICE_CPE_VMMC_WITH_DEVICE_AR9),y)
  CONFIGURE_ARGS += --with-device=AR9
  # TODO: add fw/coef
endif

But i do not have an clue about this stuff... Probably there is a firmware build for AR9 with the VR9 target???

I had the same boot loop symptoms with kmod-ltq-vmmc on the AR9 Klapstuhl describes. Could I help myself if I poke at the official 7312 image to extract the voice firmware for the AR9? or is this discouraged?
On lantiq-xdsl-firmware-info I read Lantiq started in 2015 to provide xdsl fw binaries with a license permitting redistribution, though this does not seem to apply to AR9.

@Klapstuhl: with 7z e to the downloadable image and a second extract for kernel.image, one can find both the dsl modem firmware in an updated and working version (ar9-B-dsl.bin, 5.1.A instead of 4.1.7) and most likely the correct firmware (voip_R12.1.0.1.0-enc.bin) for ltq-vmmc.

I'll try your suggestion to mimic the VR9 commit with the proper firmware for AR9, though I'm unsure about the ETSI .bin files.

Hi there i am not a xway (aka danube or ar9) expert but i thing it differ from vr9.
I think it does not need the nosmp because it is always no-SMP.
So you can take a look inside the Easybox-803 (aka Acor 803) Box called: ARV752DPW22.dts
I know that the telefon was working last year and i thing the DTS file was not changed.
There is no nosmp code but for vmmc the following lines are required:

&vmmc {
	status = "okay";
	gpios = <&gpiomm 1 GPIO_ACTIVE_HIGH>;
};

I have no idea which are the correct gpios line.
In other DTS files i have see it without the gpios line

Don't bother, AVM uses Dialog SC14xxx chips for DECT and FXS in all products which has no documentation and no Linux driver available. Use Arcadyan boards if you need FXS.