The Ubiquiti mPower series of smart outlets has been discontinued. As a replacement I purchased a Pro Switch from Digital Loggers.

The Pro Switch contains a Qualcomm Atheros 9331 MIPS 24K big Endian 32-bit processor with 61264 kB of memory.

Cross compilation

I installed glibc-devel.i686, lld, but the following did not link:

$ clang -target mips-unknown-linux-gnu -fuse-ld=lld -v main.c
...
ld.lld: error: cannot open crtbegin.o: No such file or directory
ld.lld: error: unable to find library -lgcc
ld.lld: error: unable to find library -lgcc_s
ld.lld: error: unable to find library -lgcc
ld.lld: error: unable to find library -lgcc_s
ld.lld: error: cannot open crtend.o: No such file or directory
clang-9: error: linker command failed with exit code 1 (use -v to see invocation

It looks like I may want to download a Linaro toolchain and add --sysroot or --gcc-toolchain.

Unfortunately, the Atheros is just listed as a firmware. However, there are a few QEMU MIPS configs.

$ dnf install gcc-mips64-linux-gnu
$ mips64-linux-gnu-gcc -I /usr/include/ -g -static main.c
/usr/bin/mips64-linux-gnu-ld: cannot find crt1.o: No such file or directory
/usr/bin/mips64-linux-gnu-ld: cannot find crti.o: No such file or directory
/usr/bin/mips64-linux-gnu-ld: cannot find -lc
collect2: error: ld returned 1 exit status

Although, the errors when running clang:

ld.lld: error: unable to find library -lgcc_s
ld.lld: error: unable to find library -lgcc_s
clang-9: error: linker command failed with exit code 1 (use -v to see invocation)

Adding -static produces the following:

ld.lld: error: unable to find library -lgcc_eh
ld.lld: error: unable to find library -lc
clang-9: error: linker command failed with exit code 1 (use -v to see invocation)

https://toolchains.bootlin.com/

./relocate-sdk.sh
bin/mips-linux-gcc --sysroot=mips-buildroot-linux-gnu/sysroot ~/main.c
# ./a.out 
FATAL: kernel too old
Aborted

The device is running Linux 3.18.71.

Lua applications

Digitial Loggers have implemented a number of programs in Lua version 5.1.5:

root@LPC994:~# ls /usr/bin/*.lua
/usr/bin/auth_server.lua                       /usr/bin/relay_adapter.lua
/usr/bin/autoping_server.lua                   /usr/bin/relay_modbus.lua
/usr/bin/default_route_manager.lua             /usr/bin/relay_mqtt.lua
/usr/bin/generic_state_server.lua              /usr/bin/relay_reset.lua
/usr/bin/i2c_state_mirror.lua                  /usr/bin/relay_snmp.lua
/usr/bin/meter_server.lua                      /usr/bin/relay_state_server.lua
/usr/bin/misc_config_server.lua                /usr/bin/relay_upnp.lua
/usr/bin/network_config_server.lua             /usr/bin/relay_web_ui.lua
/usr/bin/notification_server.lua               /usr/bin/renderer.lua
/usr/bin/platform_sysupgrade_notify_relay.lua  /usr/bin/scripting_server.lua

Based on the byte code header they are using version 5.1, which should be able to be decompiled using luadec, unfortunately building and running the tool I ran into an error, bad header in precompiled chunk. This may be related to the shebang or license in each file.

The relay module is controlled using a “ubus serial line-oriented interface”.

Hardware

SSH

Run ssh-copy-id and then move the authorized_keys file to /etc/dropbear/.

See also