halmartin / meraki-builder

Scripts and tools to assemble firmware images for various Meraki MS switches and MX routers
GNU General Public License v3.0
76 stars 16 forks source link

PD690xx PoE daemon #1

Closed halmartin closed 11 months ago

halmartin commented 4 years ago

The init script S03gpio currently auto-configures the PD690xx for PoE. This allows for "plug-and-play" PoE functionality on the switch (at least on the MS220-8P; I don't have other Meraki PoE enabled hardware to test).

However, more advanced functionality which is present in the original Meraki firmware is not possible, this includes:

And probably more things I don't know about since I don't have much experience with PoE.

Resources:

halmartin commented 4 years ago

Here is a super basic program to manage PoE. Tested on an MS220-8P.

I welcome PRs by people who aren't terrible at C code. This is some A+ copy pasta.

halmartin commented 4 years ago

Okay, there are more features now:

Updated the README and now it prints some pretty usage message if you don't specify any arguments (or -h) 🥳

halmartin commented 4 years ago

More new features!

Summary of all PoE port statuses:

$ pd690xx -l
Port    Status          Type    Priority        Power
1       Disabled        at      Critical        0.0
2       Enabled         af      Critical        1.8
3       Enabled         at      Critical        0.0
4       Disabled        at      Critical        0.0
5       Forced          at      Critical        15.4
6       Enabled         at      Critical        0.0
7       Disabled        at      Critical        0.0
8       Enabled         at      Critical        0.0
9       Enabled         at      Critical        0.0
10      Enabled         at      Critical        0.0
11      Enabled         at      Critical        0.0
12      Enabled         at      Critical        0.0

There is no way (that I can see) to query for how many ports exist, so an MS220-8P will display 12 ports (despite having only 8 PoE capable ports) because that's what the PD69012 supports, and apparently the PD69008 has the same port registers ¯_(ツ)_/¯

You can also "force" a port on, though I don't know what that means in practice (maybe don't test this with equipment you care about).

Now you can also query the pd690xx for the PoE voltage within the switch:

$ pd690xx -s
56.2 V
halmartin commented 4 years ago

The only items I consider still to-do are:

ben-oxley commented 4 years ago

I've got a MS220-48LP if I can do anything to help confirm your second bullet point above. I've taken a binary dump from the device now which I can share if it helps?

halmartin commented 4 years ago

@ben-oxley thank you for the offer! The Meraki firmware is common to all the MS22/42/220/320 series. Current builds of postmerkOS are also common to all models.

I have decompiled libpoecore from the Meraki firmware and used some information from that in my design of pd690xx

What I am still missing is the I2C addresses of the PoE controllers that manage ports 13-48 (each controller manages 12 ports; there is one controller in the MS220-8P, two in the -24, and four in the -48 models). I would greatly appreciate some assistance from someone with 24 or 48 port MS220/MS320 switch, however you'll need to flash postmerkOS first.

Once you have postmerkOS flashed and booting, you can enable I2C tracing in the kernel and use poe_cli from the Meraki firmware to query ports 23, 35, and 47 (for example). The I2C trace output will provide the I2C address of the remaining controllers and then I can add support for these and pd690xx will be usable on larger switch models too.

ben-oxley commented 4 years ago

We're up and running on postmerkOS (sort of). Seems to have some issues on boot.

Bootlog below:

LinuxLoader built Nov 12 2020 18:01:50
init_pll ok
init_spi ok
init_memctl ok
wait_memctl ok
Training DRAM ok
init_irq ok
init_dram_uncached ok
init_icache ok
init_dcache ok
enable_caches ok
init_pi ok
init_board ok
Low level initialization complete, exiting boot mode
[    0.000000] Linux version 3.18.123-meraki-elemental (hmartin@alp) (gcc version 5.4.0 (GCC) ) #10 Sat Jul 18 17:06:37 UTC 2020
[    0.000000] CPU0 revision is: 01019654 (MIPS 24KEc)
[    0.000000] Determined physical RAM map:
[    0.000000]  memory: 00477000 @ 00100000 (usable)
[    0.000000]  memory: 00049000 @ 00577000 (usable after init)
[    0.000000] User-defined physical RAM map:
[    0.000000]  memory: 07ff0000 @ 00000000 (usable)
[    0.000000] Initmem setup node 0 [mem 0x00000000-0x07feffff]
[    0.000000] Reserving 0MB of memory at 0MB for crashkernel
[    0.000000] Kernel command line: console=ttyS0,115200 mtdparts=m25p80:0x40000(redboot),0x2c0000(kernel),0x800000(squashfs),0x500000(overlay) root=/dev/mtdblock3 ubi.mtd=gen_nand.0 mem=134152192
[    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=8000a004
[    0.000000] Readback ErrCtl register=8000a004
[    0.000000] Cache parity protection enabled
[    0.000000] SLUB: HWalign=32, Order=0-3, MinObjects=0, CPUs=1, Nodes=1
[    0.000000] NR_IRQS:66
[    0.000000] sched_clock: 32 bits at 1kHz, resolution 1000000ns, wraps every 2147483648000000ns
[    0.002000] VCore-III slave device ID 7460 found
[    0.002000] Calibrating delay loop... 275.45 BogoMIPS (lpj=137728)
[    0.011000] pid_max: default: 32768 minimum: 301
[    0.011000] Mount-cache hash table entries: 1024 (order: 0, 4096 bytes)
[    0.011000] Mountpoint-cache hash table entries: 1024 (order: 0, 4096 bytes)
[    0.013000] ftrace: allocating 11994 entries in 24 pages
[    0.041000] Performance counters: mips/24K PMU enabled, 2 32-bit counters available to each CPU, irq -1 (share with timer interrupt)
[    0.048000] devtmpfs: initialized
[    0.055000] NET: Registered protocol family 16
[    0.094000] Switched to clocksource MIPS
[    0.124000] NET: Registered protocol family 2
[    0.127000] TCP established hash table entries: 1024 (order: 0, 4096 bytes)
[    0.128000] TCP bind hash table entries: 1024 (order: 0, 4096 bytes)
[    0.128000] TCP: Hash tables configured (established 1024 bind 1024)
[    0.128000] TCP: reno registered
[    0.128000] UDP hash table entries: 256 (order: 0, 4096 bytes)
[    0.128000] UDP-Lite hash table entries: 256 (order: 0, 4096 bytes)
[    0.129000] NET: Registered protocol family 1
[    0.133000] VCORE-III Watchdog Timer enabled (30 seconds).  Prev boot was not caused by WDT reset.
[    0.158000] futex hash table entries: 256 (order: -1, 3072 bytes)
[    0.196000] squashfs: version 4.0 (2009/01/31) Phillip Lougher
[    0.196000] jffs2: version 2.2. (NAND) © 2001-2006 Red Hat, Inc.
[    0.199000] msgmni has been set to 241
[    0.21=000] io scheduler noop registered
[    0.219000] io scheduler deadline registered (default)
[    0.221000] Serial: 8250/16550 driver, 1 ports, IRQ sharing disabled
[    0.223000] console [ttyS0] disabled
[    0.224000] serial8250.0: ttyS0 at MMIO 0x70100000 (irq = 14, base_baud = 13020833) is a 16550A
[    0.609000] console [ttyS0] enabled
[    0.619000] nand: device found, Manufacturer ID: 0x2c, Chip ID: 0xf1
[    0.625000] nand: Micron MT29F1G08ABADAWP
[    0.630000] nand: 128MiB, SLC, page size: 2048, OOB size: 64
[    0.641000] Scanning device for bad blocks
[    0.758000] m25p80 spi0.1: found mx25l12805d, expected m25p80
[    0.764000] m25p80 spi0.1: mx25l12805d (16384 Kbytes)
[    0.769000] 4 cmdlinepart partitions found on MTD device m25p80
[    0.775000] Creating 4 MTD partitions on "m25p80":
[    0.780000] 0x000000000000-0x000000040000 : "redboot"
[    0.802000] 0x000000040000-0x000000300000 : "kernel"
[    0.812000] 0x000000300000-0x000000b00000 : "squashfs"
[    0.827000] 0x000000b00000-0x000001000000 : "overlay"
[    0.841000] tun: Universal TUN/TAP device driver, 1.6
[    0.846000] tun: (C) 1999-2004 Max Krasnyansky <maxk@qualcomm.com>
[    0.856000] i2c /dev entries driver
[    0.863000] TCP: cubic registered
[    0.867000] Initializing XFRM netlink socket
[    0.874000] NET: Registered protocol family 10
[    0.883000] NET: Registered protocol family 17
[    0.888000] NET: Registered protocol family 15
[    0.893000] 8021q: 802.1Q VLAN Support v1.8
[    0.903000] i2c-gpio i2c-gpio.1: using pins 15 (SDA) and 14 (SCL)
[    0.910000] at24 1-0051: 1024 byte 24c08 EEPROM, writable, 8 bytes/write
[    0.925000] meraki-config meraki-config: Meraki config device loaded
[    1.016000] i2c-gpio-scl i2c-gpio-scl.2: using pins 53 (SDA) and 52 (SCL)
[    1.024000] i2c i2c-2: Added multiplexed i2c bus 3
[    1.031000] i2c i2c-2: Added multiplexed i2c bus 4
[    1.037000] i2c i2c-2: Added multiplexed i2c bus 5
[    1.045000] i2c i2c-2: Added multiplexed i2c bus 6
[    1.062000] tmp401 8-004c: Detected TI TMP411 chip
[    1.082000] i2c-gpio i2c-gpio.8: using pins 47 (SDA) and 46 (SCL)
[    1.090000] at24 3-0050: 256 byte 24c02 EEPROM, read-only, 0 bytes/write
[    1.097000] at24 4-0050: 256 byte 24c02 EEPROM, read-only, 0 bytes/write
[    1.104000] at24 5-0050: 256 byte 24c02 EEPROM, read-only, 0 bytes/write
[    1.112000] at24 6-0050: 256 byte 24c02 EEPROM, read-only, 0 bytes/write
[    1.129000] UBI: attaching mtd0 to ubi0
[    1.933000] UBI: scanning is finished
[    1.975000] UBI: attached mtd0 (name "gen_nand.0", size 128 MiB) to ubi0
[    1.982000] UBI: PEB size: 131072 bytes (128 KiB), LEB size: 129024 bytes
[    1.989000] UBI: min./max. I/O unit sizes: 2048/2048, sub-page size 512
[    1.995000] UBI: VID header offset: 512 (aligned 512), data offset: 2048
[    2.002000] UBI: good PEBs: 1024, bad PEBs: 0, corrupted PEBs: 0
[    2.008000] UBI: user volume: 12, internal volumes: 1, max. volumes count: 128
[    2.016000] UBI: max/mean erase counter: 11/1, WL threshold: 4096, image sequence number: 1363641321
[    2.025000] UBI: available PEBs: 462, total reserved PEBs: 562, PEBs reserved for bad PEB handling: 20
[    2.034000] UBI: background thread "ubi_bgt0d" started, PID 285
[    2.158000] devtmpfs: mounted
[    2.202000] VFS: Mounted root (squashfs filesystem) readonly on device 31:3.
[    2.241000] devtmpfs: mounted
[    2.250000] Freeing unused kernel memory: 292K
[    6.244000] devpts: called with bogus options
Starting syslogd: OK
Starting klogd: OK
Running sysctl: OK
/overlay is already mounted
[    8.701000] random: nonblocking pool is initialized
board-config is /dev/mtd5
insmod: ERROR: could not load module /lib/modules//vtss_core.ko: No such file or directory
Loaded 'proclikefs.ko'
[   31.300000] click: starting router thread pid 458 (87a97e00)
Loaded 'merakiclick.ko'
[   66.332000] elts_meraki: module license 'unspecified' taints kernel.
[   66.339000] Disabling lock debugging due to kernel taint
Loaded 'elts_meraki.ko'
insmod: ERROR: could not load module /lib/modules//vc_click.ko: No such file or directory
[   69.410000] unsatisfied requirement 'vc_click'
[   69.416000] click-config/switch/io-real/vitesse.click:26: unknown element class 'ToVitesse'
[   69.425000] click-config/switch/io-real/vitesse.click:31: unknown element class 'FromVitesse'
[   69.435000] click-config/switch/io-real/vitesse.click:59: unknown element class 'VitesseController'
[   69.854000] click-config/switch.template:74: While configuring 'switch_intf_table :: SwitchIntfTable':
[   69.863000]   SWITCH_HARDWARE: element type mismatch, expected SwitchHardwareIntf
[   69.874000] click-config/switch.template:1045: While configuring 'switch_port_table :: SwitchPortTable':
[   69.884000]   SWITCH_HARDWARE_INTERFACE: element type mismatch, expected SwitchHardwareIntf
[   69.907000] click-config/switch.template:58: While configuring 'l3_update_hardware :: UpdateHardwareTable':
[   69.918000]   SWITCH_HARDWARE_INTERFACE: element type mismatch, expected SwitchHardwareIntf
[   69.936000] click-config/switch.template:383: While configuring 'switch_rpc_server :: SwitchRPCServer':
[   69.945000]   HW_INTF: element type mismatch, expected SwitchHardwareIntf
[   69.955000] click-config/switch.template:566: While configuring 'CheckStackMaster@187 :: CheckStackMaster':
[   69.966000]   HW_INTF: element type mismatch, expected SwitchHardwareIntf
[   69.974000] click-config/switch.template:602: While configuring 'CheckStackMaster@235 :: CheckStackMaster':
[   69.984000]   HW_INTF: element type mismatch, expected SwitchHardwareIntf
[   69.993000] click-config/switch.template:633: While configuring 'switch_mrt :: MulticastRoutingTable':
[   70.002000]   SWITCH_HARDWARE_INTERFACE: element type mismatch, expected SwitchHardwareIntf
[   70.013000] click-config/switch.template:655: While configuring 'ospf_hello_inspector :: OspfHelloInspector':
[   70.024000]   SWITCH_HARDWARE_INTERFACE: element type mismatch, expected SwitchHardwareIntf
[   70.056000] click-config/switch.template:875: While configuring 'msstp_encap_inst :: MSSTPEncap':
[   70.065000]   HW_INTF: element type mismatch, expected SwitchHardwareIntf
[   70.077000] click-config/switch.template:930: While configuring 'IntraStackResolver@527 :: IntraStackResolver':
[   70.087000]   HW_INTF: element type mismatch, expected SwitchHardwareIntf
[   70.099000] click-config/switch.template:1072: While configuring 'igmp_table :: IGMPSnoopTable':
[   70.108000]   SWITCH_HARDWARE_INTERFACE: element type mismatch, expected SwitchHardwareIntf
[   70.118000] click-config/switch.template:1093: While configuring 'mld_table :: MLDSnoopTable':
[   70.126000]   SWITCH_HARDWARE_INTERFACE: element type mismatch, expected SwitchHardwareIntf
[   70.137000] click-config/switch.template:1125: While configuring 'msstp_decap :: MSSTPDecap':
[   70.146000]   HW_INTF: element type mismatch, expected SwitchHardwareIntf
[   70.159000] click-config/switch.template:1187: While configuring 'CheckStackMaster@664 :: CheckStackMaster':
[   70.169000]   HW_INTF: element type mismatch, expected SwitchHardwareIntf
[   70.176000] click-config/switch.template:1189: While configuring 'CheckStackMaster@669 :: CheckStackMaster':
[   70.186000]   HW_INTF: element type mismatch, expected SwitchHardwareIntf
[   70.194000] click-config/switch.template:1199: While configuring 'CheckStackMaster@680 :: CheckStackMaster':
[   70.204000]   HW_INTF: element type mismatch, expected SwitchHardwareIntf
[   70.212000] click-config/switch.template:1212: While configuring 'CheckStackMaster@693 :: CheckStackMaster':
[   70.222000]   HW_INTF: element type mismatch, expected SwitchHardwareIntf
[   70.231000] click-config/switch.template:1238: While configuring 'CheckStackMaster@726 :: CheckStackMaster':
[   70.241000]   HW_INTF: element type mismatch, expected SwitchHardwareIntf
[   70.253000] click-config/switch.template:1307: While configuring 'stp_check_master :: CheckStackMaster':
[   70.263000]   HW_INTF: element type mismatch, expected SwitchHardwareIntf
[   70.270000] click-config/switch.template:1320: While configuring 'lacp_check_master :: CheckStackMaster':
[   70.280000]   HW_INTF: element type mismatch, expected SwitchHardwareIntf
[   70.289000] click-config/switch.template:1409: While configuring 'udld :: UDLD':
[   70.297000]   HW_INTF: element type mismatch, expected SwitchHardwareIntf
[   70.306000] click-config/switch.template:1459: While configuring 'CheckStackMaster@861 :: CheckStackMaster':
[   70.316000]   HW_INTF: element type mismatch, expected SwitchHardwareIntf
[   70.405000] Router could not be initialized!
Default port count: 10
net.ipv4.ip_local_reserved_ports = 50000-50127
vc_click isn't loaded; aborting!
/etc/init.d/S11leds: line 8: can't create /click/sw0_ctrl/power_led_orange: nonexistent directory
/etc/init.d/S11leds: line 9: can't create /click/sw0_ctrl/power_led_green: nonexistent directory
Generating dropbear ECDSA host key
Generating 521 bit ecdsa key, this may take a while...
Public key portion is:
ecdsa-sha2-nistp521 AAAAE2VjZHNhLXNoYTItbmlzdHA1MjEAAAAIbmlzdHA1MjEAAACFBACyoNXi8VllFxatkvlFWh6fUgwjfwU9XYpO9ieo+mt892lxCq0pe1bQu8CAa7le/ArQ6j6pncVl8iZ0p3kRzFFgiQFlLOdZBYc202LGorSDtuybFnDpsEnrRBv2QLafafMgXjADZCl7xavDvpcBjCwAwWNYnZyR4Stbvwdpoa3euvDogw== root@m881544301590
Fingerprint: sha1!! 0a:c1:43:72:66:67:ea:ef:6c:b3:41:be:f7:1a:2b:80:d6:d2:56:53
Saving random seed: SKIP (read-only file system detected)
Starting network: OK
Starting chrony: Could not open configuration file /etc/chrony.conf : No such file or directory
FAIL
Starting dropbear sshd: OK
Starting lighttpd: OK

/ # 
halmartin commented 4 years ago

@ben-oxley It looks like the board detection in S08kmods doesn't quite work for the MS220-48LP. Could you please provide the output of the following?

cat /proc/cpuinfo
cat /proc/mtd

I'd also really appreciate the strings output of the board-config mtd part:

BCFG=$(cat /proc/mtd | grep board-config | awk '{print $1}' | grep -oE '[0-9]')
dd if=/dev/mtdblock${BCFG} | strings

With these details I should be able to fix the logic in S08kmods. Thanks!

ben-oxley commented 4 years ago

No problem, I'll get this to you asap, probably tomorrow now though!

halmartin commented 4 years ago

Please exclude the last line of board-config as it contains your unit serial number!

ben-oxley commented 4 years ago

/ # cat /proc/cpuinfo system type : Vitesse VCore-III VSC7434 Dual machine : Unknown processor : 0 cpu model : MIPS 24KEc V5.4 BogoMIPS : 275.45 wait instruction : yes microsecond timers : yes tlb_entries : 16 extra interrupt vector : yes hardware watchpoint : yes, count: 4, address/irw mask: [0x0ffc, 0x0ffc, 0x0ffb, 0x0ffb] isa : mips1 mips2 mips32r1 mips32r2 ASEs implemented : mips16 dsp shadow register sets : 1 kscratch registers : 0 package : 0 core : 0 VCED exceptions : not available VCEI exceptions : not available

/ # cat /proc/mtd dev: size erasesize name mtd0: 08000000 00020000 "gen_nand.0" mtd1: 00040000 00010000 "redboot" mtd2: 002c0000 00010000 "kernel" mtd3: 00800000 00010000 "squashfs" mtd4: 00500000 00010000 "overlay" �td5: 0001f800 0001f800 "board-config" mtd6: 00086000 0001f800 "bootroot" mtd7: 0140e800 0001f800 "part1" mtd8: 0140e800 0001f800 "part2" mtd9: 0081f000 0001f800 "storage" mtd10: 0020bdb0 0001f800 "SMBStaX-24" mtd11: 00292240 0001f800 "SMBStaX-48" mtd12: 00230af0 0001f800 "SMBStaX-MS220-8" mtd13: 0022be00 0001f800 "SMBStaX-MS220-24" mtd14: 0029bc88 0001f800 "SMBStaX-MS220-48" mtd15: 0029e7c0 0001f800 "SMBStaX-MS320-24" mtd16: 0029ca88 0001f800 "SMBStaX-MS320-48" / # BCFG=$(cat /proc/mtd | grep board-config | awk '{print $1}' | grep -oE '[0-9 ]') / # echo ${BCFG} 5 / # dd if=/dev/mtdblock${BCFG} | strings 5311 meraki_elemental 000000000 Q2XXXXXXXXXV 252+0 records in 252+0 records out

ben-oxley commented 4 years ago

Failed to initialize PoE server. a=030 a=031 a=033 a=035

Is this the magic you're looking for?

halmartin commented 4 years ago

Thanks to @ben-oxley for help in debugging the MS220-48P and testing, pd690xx has been updated to work with larger switch models such as the MS220-48.

mterron commented 4 years ago

Hi @halmartin there's a whole poe driver infrastructure in the Meraki dump at linux-3.18/drivers/poe/. It's probably worth it to take a look as it is the official Meraki PoE controller infrastructure.

halmartin commented 4 years ago

@mterron Oh man, I should really grep for strings before I write user-space daemons.

Nice to see I wasn't the only person confounded by the poorly written temperature formula in the datasheet.

For some reason, Meraki does not enable POE_PD690XX in the defconfig they supply in their GPL archive. The string pd690 also doesn't appear in the kernel used by their firmware I extracted from my MS220-8P.

I'm not sure why they would go to the effort of writing this driver and then not use it.

mterron commented 4 years ago

Can't comment on that, sorry. It is nicely integrated with thermal monitoring and other goodies so it doesn't look like a POC.

$ grep -ri meraki switch-11-22-ms220/linux-3.18 points to lot's of useful information though.

halmartin commented 2 years ago

There was a serious bug in pd690xx that affects the MS220-24P and MS220-48LP/FP: #27

Users should update their switch firmware to 20221115 to resolve the issue.

halmartin commented 11 months ago

Closing as the pd690xx utility is usable and contains no major bugs.