Controlling LEDs through a 74x164 shift register

Have you managed to improve something?

I've added in the power LED to 01_leds and that works nicely, but I'm having trouble in detecting a hotplug event for the eth0/1 ports.

Nothing changes in /sys/class/net/eth[0,1] when I plug/unplug a cable from eth0 (eth1 is the PoE port I'm using), so I can't tell if any interfaces are up/down from a script. All the usual tools (ifconfig/ip a) all report the interface as UP all the time.

Interestingly enough, now that I've got eth0 connected I've noticed that GPIO62 controls both eth0 and eth1. GPIO61 does nothing. When I set GPIO62 low then high, both eth0 and eth1 go down then come up again with the LEDs on. Both ports' LEDs work as expected after GPIO62 has been toggled.

I still can't find an event to check for though. Today I've been busy with other things, but I'll try some more ideas out tomorrow.

My current plan (for tomorrow) is to get a script in hotplug.d/iface to log any events that it catches and write them to a file. Then I'll try bringing each interface down/up and see if it's recorded. Then I can check the $board_name for 'netgear,wac510' to make sure it doesn't trigger for every device.

Am I heading down the correct path?

Tim

If you want to set power led on by default, that should be done in DTS instead of 01_leds.
Since you stated that GPIO61 does nothing I have removed it from DTS and set green power LED to be on by default.
But, we should better investigate why does not diag.sh kick in and control power led since aliases are set correctly.

As far as eth link detection go,that could be done by just reading /sys/class/net/eth0/operstate for eth0 and /sys/class/net/eth1/operstate for eth1.

LED aliases from DTS are not getting set:
root@OpenWrt:/# ls -l /proc/device-tree/aliases/
-r--r--r-- 1 root root 24 Mar 8 13:11 ethernet0
-r--r--r-- 1 root root 24 Mar 8 13:11 ethernet1
-r--r--r-- 1 root root 17 Mar 8 13:11 i2c0
-r--r--r-- 1 root root 8 Mar 8 13:11 name
-r--r--r-- 1 root root 17 Mar 8 13:11 spi0
root@OpenWrt:/#

I've also been trying the eth ports again. Eth1 (PoE) works as expected - /proc/net/eth1/operstate works and kernel reports plug-in/out to console. However eth0 does not get reported to the kernel when the link goes up/down and /proc/net/eth0/operstate is always 'up', regardless of link state. Eth0 appears to pass data OK - I can ping across it with no problems.

Do we need to worry about that? I can make my hotplug script detect eth1 instead, but if someone powers this device up using a DC jack and only uses eth0, the eth LEDs will not work.

Edit - actually on bootup, the eth0 is getting picked up:
[ 3.332545] IPv6: ADDRCONF(NETDEV_UP): eth0: link is not ready
[ 3.332701] IPv6: ADDRCONF(NETDEV_CHANGE): eth0: link becomes ready

Tim

Ok, so we gotta figure out why arent aliases being set.
Hm,I think that that switch would need some configuration in DTS like other IPQ4018/19 devices instead of just using defaults.
Can you check if all MAC addresses including those of radios match printed ones?

Interesting about the MAC addresses.. From OpenWrt:
br-lan Link encap:Ethernet HWaddr A0:40:A0:7B:B7:6F
eth0 Link encap:Ethernet HWaddr A0:40:A0:7B:B7:6F
eth1 Link encap:Ethernet HWaddr A0:40:A0:7B:B7:7F
wlan0 Link encap:Ethernet HWaddr 00:03:7F:12:34:56
wlan1 Link encap:Ethernet HWaddr 12:34:56:78:90:12

From Netgear's Web GUI (I can't get eth1, I assume 'ethernet' is just eth0):
Ethernet MAC Address
A0-40-A0-7B-B7-6F
Wireless MAC Address for 2.4 GHz
A0-40-A0-7B-B7-60
Wireless MAC Address for 5 GHz
A0-40-A0-7B-B7-70

WiFi radio MACs are out then. From my WNDAP360's, the MAC addresses were stored in the ART partition at certain off-sets. Could that be the case here as well?

Tim

We dont even need to read them from flash,we can just patch them when loading calibration with offset from eth0.
Really easy when you know stock ones.
Just done that,so MAC should now match.
Netgear uses a really weird -15 offset for 2.4GHz radio and +1 for 5Ghz.
Usually they are just +2 and +3

Easy for you! :slight_smile:

How did you find their offsets? Just search the ddimg of the ART partition?

Just re-compiling..

Tim

You simply look at eth0 MAC and offset it by the difference in last segment value.
You dont have to read it from flash at all,just a little bit of math.

I will look into aliases today

Except that the MAC addresses are not the stock ones still, after compiling your latest commits:
wlan0 Link encap:Ethernet HWaddr 00:03:7F:12:5D:5D
wlan1 Link encap:Ethernet HWaddr 00:34:56:78:F7:F7

I'll see if I can delve into it too..

Tim

Hm,that is weird.
Can you give me output of cat /sys/class/net/eth0/address ?

The eth[0,1] MACs are fine, it's just the WLAN ones:
root@OpenWrt:/# cat /sys/class/net/eth0/address
a0:40:a0:7b:b7:6f
root@OpenWrt:/# cat /sys/class/net/eth1/address
a0:40:a0:7b:b7:7f
root@OpenWrt:/# cat /sys/class/net/wlan0/address
00:03:7f:12:5d:5d
root@OpenWrt:/# cat /sys/class/net/wlan1/address
00:34:56:78:f7:f7

FWIW, I can't find any MAC addresses apart from eth[0,1] in the ART binary..

Tim

Hm, its weird that MAC address is not patched because eth0 is correct.
I use that same script in other architectures without an issue.

I think Netgear intended the wifi MAC offsets to be 2 and 3 like you said. I found these by grepping through the stock init scripts:
MANUFAC_MTD_CHAR=/dev/mtdblock7
MAC_OFFSET_4_WLAN0=2
MAC_OFFSET_4_WLAN1=3
MAC_OFFSET_4_ETH=0
MAC_OFFSET_4_ETH1=1
WIFI0_MAC=${BDDATARD} ${MANUFAC_MTD_CHAR} ${MAC_OFFSET_4_WLAN0}
WIFI1_MAC=${BDDATARD} ${MANUFAC_MTD_CHAR} ${MAC_OFFSET_4_WLAN1}

BDDATARD is a Netgear binary which appears to read an mtd partition..

/dev/mtd7 has eth0 MAC address in it and 2.4Ghz wifi address in it. It's here:
https://github.com/7604timo/netgear-wac510/blob/master/mtd7.dd

I'm still digging....

Tim

That makes sense

I can confirm the lan/wan LEDs both work after my hotplug addition.

I'm having trouble with the wifi MAC addresses though. I see that the hotplug script writes the MAC address to the pre-cal file, but that doesn't seem to be used for the interface. I can't set the MAC address manually in the firmware hotplug script because wlan[0,1] don't exist when it's run.

Would it be OK to add to the iface script an ifconfig line to set the MAC address when the wlan[0,1] interfaces come up, or would it be better if it happened sooner?

Also, from my testing yesterday, I noticed that the macaddr_add function in the 11-ath10k-caldata script doesn't work under the shell 'sh or ash', only bash. I managed to fix it at work, but the MAC address still isn't picked up after I fixed it. I can get my changes later and show you them..

Tim

Hm,nice catch.
Looks like it is ipq806x specific cause the same function is used in other architectures using ath10k driver

I added in an entry for the wac510 in your hotplug.d/ieee80211/10_fix_wifi_mac file and it seems to work, but I need to check it for sure by flashing OpenWrt onto this device permanently.

I tried the sysupgrade method and I've soft-bricked it. I can get into uboot, but it can't find anything to boot and just gets stuck in a reboot loop.

I know I need to tftpboot the kernel/rootfs into RAM and then copy it into flash, but I've no idea which memory locations to use.

Here's the output from sysupgrade and uboot:
root@OpenWrt:/tmp# sysupgrade -v openwrt-ipq806x-netgear_wac510-squashfs-nand-sy
supgrade.bin
Cannot save config while running from ramdisk.
Commencing upgrade. All shell sessions will be closed now.
Watchdog handover: fd=3
watchdog -
killall: telnetd: no process killed
Sending TERM to remaining processes ... dnsmasq netifd ubusd hostapd hostapd [ 795.393185] device wlan0 left promiscuous mode
[ 795.393542] br-lan: port 2(wlan0) entered disabled state
[ 795.413247] device wlan1 left promiscuous mode
[ 795.413574] br-lan: port 3(wlan1) entered disabled state
[ 795.444506] ath10k_ahb a000000.wifi: peer-unmap-event: unknown peer id 1
logd [ 795.469027] ath10k_ahb a800000.wifi: peer-unmap-event: unknown peer id 1
odhcpd ntpd
Sending KILL to remaining processes ...
Performing system upgrade...
[ 800.672550] ubi0: attaching mtd9
[ 805.712145] ubi0: scanning is finished
[ 805.778826] ubi0: attached mtd9 (name "rootfs", size 56 MiB)
[ 805.778865] ubi0: PEB size: 131072 bytes (128 KiB), LEB size: 126976 bytes
[ 805.783607] ubi0: min./max. I/O unit sizes: 2048/2048, sub-page size 2048
[ 805.790246] ubi0: VID header offset: 2048 (aligned 2048), data offset: 4096
[ 805.797123] ubi0: good PEBs: 448, bad PEBs: 0, corrupted PEBs: 0
[ 805.803888] ubi0: user volume: 2, internal volumes: 1, max. volumes count: 128
[ 805.810126] ubi0: max/mean erase counter: 1/0, WL threshold: 4096, image sequence number: 1011195579
[ 805.817179] ubi0: available PEBs: 194, total reserved PEBs: 254, PEBs reserved for bad PEB handling: 20
[ 805.826487] ubi0: background thread "ubi_bgt0d" started, PID 2373
UBI device number 0, total 448 LEBs (56885248 bytes, 54.2 MiB), available 194 LEBs (24633344 bytes, 23.5 MiB), LEB size 126976 bytes)
Volume ID 0, size 22 LEBs (2793472 bytes, 2.7 MiB), LEB size 126976 bytes (124.0 KiB), dynamic, name "kernel", alignment 1
Volume ID 2, size 20 LEBs (2539520 bytes, 2.4 MiB), LEB size 126976 bytes (124.0 KiB), dynamic, name "rootfs", alignment 1
Set volume size to 22982656
Volume ID 3, size 181 LEBs (22982656 bytes, 21.9 MiB), LEB size 126976 bytes (124.0 KiB), dynamic, name "rootfs_data", alignment 1
[ 813.133834] spi_qup 78b5000.spi: unexpected irq 00000000 00000000 00000d40
[ 824.210016] spi_qup 78b5000.spi: unexpected irq 00000000 00000000 00000d40
[ 824.257219] spi_qup 78b5000.spi: unexpected irq 00000000 00000000 00000d40
sysupgrade successful
umount: can't unmount /dev: Resource busy
umount: can't unmount /tmp: Resource busy
umount: can't unmount /: Invalid argument
[
Format: Log Type - Time(microsec) - Message - Optional Info
Log Type: B - Since Boot(Power On Reset), D - Delta, S - Statistic
S - QC_IMAGE_VERSION_STRING=BOOT.BF.3.1.1-00096
S - IMAGE_VARIANT_STRING=DAABANAZA
S - OEM_IMAGE_VERSION_STRING=CRM
S - Boot Config, 0x00000021
S - Core 0 Frequency, 0 MHz
B - 261 - PBL, Start
B - 1339 - bootable_media_detect_entry, Start
B - 1679 - bootable_media_detect_success, Start
B - 1693 - elf_loader_entry, Start
B - 5076 - auth_hash_seg_entry, Start
B - 7223 - auth_hash_seg_exit, Start
B - 573341 - elf_segs_hash_verify_entry, Start
B - 688998 - PBL, End
B - 689023 - SBL1, Start
B - 777397 - pm_device_init, Start
D - 6 - pm_device_init, Delta
B - 778910 - boot_flash_init, Start
D - 63410 - boot_flash_init, Delta
B - 846511 - boot_config_data_table_init, Start
D - 3846 - boot_config_data_table_init, Delta - (419 Bytes)
B - 853736 - clock_init, Start
D - 7562 - clock_init, Delta
B - 865819 - CDT version:2,Platform ID:8,Major ID:1,Minor ID:1,Subtype:0
B - 869307 - sbl1_ddr_set_params, Start
B - 874293 - cpr_init, Start
D - 2 - cpr_init, Delta
B - 878785 - Pre_DDR_clock_init, Start
D - 4 - Pre_DDR_clock_init, Delta
D - 13146 - sbl1_ddr_set_params, Delta
B - 892485 - pm_driver_init, Start
D - 2 - pm_driver_init, Delta
B - 962832 - sbl1_wait_for_ddr_training, Start
D - 29 - sbl1_wait_for_ddr_training, Delta
B - 978657 - Image Load, Start
D - 134954 - QSEE Image Loaded, Delta - (262104 Bytes)
B - 1114105 - Image Load, Start
D - 1443 - SEC Image Loaded, Delta - (2048 Bytes)
B - 1124469 - Image Load, Start
D - 213684 - APPSBL Image Loaded, Delta - (436880 Bytes)
B - 1338576 - QSEE Execution, Start
D - 58 - QSEE Execution, Delta
B - 1344753 - SBL1, End
D - 657840 - SBL1, Delta
S - Flash Throughput, 2004 KB/s (701451 Bytes, 349937 us)
S - DDR Frequency, 537 MHz
U-Boot 2012.07-V1.2.0.0 [local,local] (Oct 26 2016 - 02:39:01)
smem ram ptable found: ver: 1 len: 3
DRAM: 256 MiB
machid : 0x8010100
NAND: spi_nand: spi_nand_flash_probe SF NAND ID 0:ef:aa:21
SF: Detected W25N01GV with page size 2 KiB, total 128 MiB
SF: Detected W25Q16 with page size 4 KiB, total 2 MiB
ipq_spi: page_size: 0x100, sector_size: 0x1000, size: 0x200000
130 MiB
MMC:
In: serial
Out: serial
Err: serial
Product ID: WAC510
machid: 8010100
flash_type: 0
Net: MAC0 addr:a0:40:a0:7b:b7:6f
PHY ID1: 0x4d
PHY ID2: 0xd0b2
ipq40xx_ess_sw_init done
eth0
Hit any key to stop autoboot: 0
Saving Environment to NAND...
Erasing Nand...
Erasing at 0xef000 -- 100% complete.
Writing to Nand... done
Boot count=1
Creating 1 MTD partitions on "nand1":
0x000000000000-0x000003800000 : "mtd=0"
UBI: attaching mtd2 to ubi0
UBI: physical eraseblock size: 131072 bytes (128 KiB)
UBI: logical eraseblock size: 126976 bytes
UBI: smallest flash I/O unit: 2048
UBI: VID header offset: 2048 (aligned 2048)
UBI: data offset: 4096
UBI: attached mtd2 to ubi0
UBI: MTD device name: "mtd=0"
UBI: MTD device size: 56 MiB
UBI: number of good PEBs: 448
UBI: number of bad PEBs: 0
UBI: max. allowed volumes: 128
UBI: wear-leveling threshold: 4096
UBI: number of internal volumes: 1
UBI: number of user volumes: 4
UBI: available PEBs: 16
UBI: total number of reserved PEBs: 432
UBI: number of PEBs reserved for bad PEB handling: 4
UBI: max/mean erase counter: 2/0
Read 0 bytes from volume kernel to 84000000
No size specified -> Using max size (2793472)
Config not availabale

bootipq failed!!
resetting ...

Tim

It looks like they use different FIT config partition than default in OpenWRT.
Thats why after not finding it,it just resets.

You can usually find out memory location for TFTP-ing by looking at u-boot environment variables,manufacturers usually write one with the location

My uboot environment variables are:
(IPQ40xx) # printenv
baudrate=115200
boot_cnt=2
bootcmd=bootipq
bootdelay=2
bootparm=init=/bin/sh
bootparms=init=/bin/sh
delenv=sf probe && sf erase 0x000e0000 +0x10000
ethact=eth0
fdt_high=0x87000000
flash_type=0
fw_upgrade=0
install_cal_to_end_of_nor=sf probe && sf read 0x84000000 0x170000 0x10000 && sf erase 0x1f0000 +0x10000 && sf write 0x84000000 0x1f00
ipaddr=192.168.1.11
machid=8010100
primary=0
proceed_upgrade=0
product_id=WAC510
secondary=3800000
show_cal_at_end_of_nor=sf probe && sf read 0x84000000 0x1f0000 0x10000 && md.b 0x84001000 0x40
stderr=serial
stdin=serial
stdout=serial
Environment size: 630/65532 bytes

But last time I tried tftp'ing to 0x3800000 (the 'secondary' partition, or so I thought), I ended up with a hard brick with no uboot or anything.

I can still tftpboot my initramfs image, so am I right in thinking I need to tftpboot the openwrt-ipq806x-netgear_wac510-fit-uImage.itb file into the 'kernel' partition?

Tim