Skip to content

Instantly share code, notes, and snippets.

@joshschmelzle
Last active October 28, 2021 00:21
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save joshschmelzle/fe969b67ccc8104f20890c9fe552e046 to your computer and use it in GitHub Desktop.
Save joshschmelzle/fe969b67ccc8104f20890c9fe552e046 to your computer and use it in GitHub Desktop.
nanopi-m4v2-notes-and-cheatsheet.md

Important Specs

Source

SoC: Rockchip RK3399
CPU: big.LITTLE,Dual-Core Cortex-A72(up to 2.0GHz) + Quad-Core Cortex-A53(up to 1.5GHz)
RAM: Dual-Channel 4GB LPDDR4
Onboard Networking:
  Ethernet: Native Gigabit Ethernet
  Wi-Fi/BT: 802.11a/b/g/n/ac, Bluetooth 4.1, Wi-Fi and Bluetooth combo module, 2x2 MIMO,
  Antenna x2: IPX Connector (note these are different than connectors found on NGFF modules) 
USB 3.0 x4: USB 3.0 Type-A ports
USB Type-C x1: Supports USB2.0 OTG and Power input
Power Input: 5V/3A, via USB Type-C (USB PD Specification is not supported)
24Pin Extension ports:
  2 independent native USB 2.0 Host
  PCIe x2
  PWM x1, PowerKey
Debug Serial Port/UART0: one Debug UART, 4 Pin 2.54mm header, 3V level, 1500000bps

Power requirements are very similar to a RBPi 4. We can easily power this for many hours with the likes of an Anker power bank.

Addt. CPU info:

  • ARM Cortex-A72 is a microarchitecture implementing the ARMv8-A 64-bit
  • ARM Cortex-A53 is one of the first two microarchitectures implementing the ARMv8-A 64-bit
  • Rockchip RK3399 SoC integrates dual-core Cortex-A72 and quad-core Cortex-A53 with separate NEON coprocessor, and with ARM Mali-T864 GPU.

Install Tools

sudo apt install tree git wireshark lshw inxi ethtool manpages build-essential

NVMe M Key to E Key converter (TODO, GET WORKING, VALIDATE, TEST)

Required to use a M.2/NGFF board.

It is a goal to use a M.2/NGFF Wi-Fi Module, that is, the Intel AX200NGW, so that we can have 802.11ax pcap in a portable form factor.

Steps we'd take if iwlwifi module was built with the kernel

Download and install iwlwifi and Intel AX200NGW driver.

cd ~
wget https://git.kernel.org/pub/scm/linux/kernel/git/firmware/linux-firmware.git/tree/iwlwifi-cc-a0-48.ucode
sudo cp iwlwifi-cc-a0-48.ucode /lib/firmware
sudo modprobe iwlwifi
lsmod | grep iwl
ip addr
ip link
iw list

try cc-a0-46 if cc-a0-48 does not work.

https://wireless.wiki.kernel.org/en/users/drivers/iwlwifi#firmware

Move driver into /lib/firmware/.

armbian builds does not seem to include iwlwifi

So, it seems that the Armbian builds do not include iwlwifi.

I've run into errors that look like this: modprobe: FATAL: Module iwlwifi not found in directory /lib/modules/5.3.0-rc4-rockchip64, when I try sudo modprobe iwlwifi. The kernel version obviously changes depending on the build I'm testing.

# install dependencies for make
sudo apt install git build-essential

# running 5.3?
sudo apt install linux-headers-dev-rk3399

# running 4.4?
sudo apt install linux-headers-rk3399

# get missing kernel errors? try apt-cache search linux-headers
git clone https://git.kernel.org/pub/scm/linux/kernel/git/iwlwifi/backport-iwlwifi.git
cd backport-iwlwifi
# use `git branch -r` to list branches
git checkout -b release/core47 origin/release/core47
# use `git branch` to list active branch

# or you could only clone the specific branch you want
# git clone --single-branch --branch release/core47 https://git.kernel.org/pub/scm/linux/kernel/git/iwlwifi/backport-iwlwifi.git

sudo make defconfig-iwlwifi-public
sed -i 's/CPTCFG_IWLMVM_VENDOR_CMDS=y/# CPTCFG_IWLMVM_VENDOR_CMDS is not set/' .config
sudo make -j4
sudo make install

# validate
lsmod | grep iwlwifi
modinfo iwlwifi | grep iwlwifi

may not be neccessary:

update-initramfs -u

Typical Firmware Locations

Firmware is sourced from the following places (see udev's /lib/udev/hotplug.functions and /lib/udev/firmware.agent)

/lib/firmware/$(uname -r) - Firmware provided by a package, specific for a kernel.

/lib/firmware/ - Firmware provided by a package, valid for all kernels.

/usr/local/lib/firmware - Location for manually installed firmware.

/usr/lib/hotplug/firmware - Firmware provided by a package, valid for all kernels

List modules with lsmod.

Onboard Wi-Fi Module

TODO CLEAN UP, GET WORKING, AND VALIDATE

Onboard Wi-Fi should be a Broadcom BCM4356.

Error I've run into is Direct firmware load for brcm/brcmfmac4356-sdio.bin failed with error -2.

Looks like there were some tweaks mid 2019 done to fix these issues. I cam across this which led me to look for a newer version of the brcm firmware. So, need to use a different version of the brcmfmac4356-sdio firmware, than what's in firmware-brcmfmac. Problems? Check what version and when it was built.

Checked to see it working by running: iw wlan0 scan

How to reinsert the module (otherwise you have to reboot):

modprobe -r brcmfmac
modprobe brcmfmac

Useful troubleshooting commands

dmesg
dmesg --clear
modinfo brcmfmac

Or run a build that has it working.

# onboard broadcom brcmfmac BCM4356/2 - https://wiki.debian.org/brcmfmac

# what versions are in apt
sudo apt-cache madison firmware-brcm80211

# current version installed
sudo apt-cache policy firmware-brcm80211

# sudo apt-get install <package name>=<version>
sudo apt install firmware-brcm80211=20190717-2~bpo10+1

# what modules are loaded
lsmod | grep brcm


cd ~ 
wget <WHAT MODULE IS THE WORKING ONE>
sudo cp /lib/firmware/brcm/brcmfmac4356-sdio.bin /lib/firmware/brcm/brcmfmac4356-sdio.bin.backup
sudo cp ~/brcmfmac4356-sdio.bin /lib/firmware/brcm/brcmfmac4356-sdio.bin

# 
sudo modprobe -r brcmfmac
sudo modprobe brcmfmac

regulatory errors (you may see these if you're playing with nightly builds)

If you see these logs in dmesg:

platform regulatory.0: Direct firmware load for regulatory.db failed with error -2
cfg80211: failed to load regulatory.db

you need to put the appropraite files in /lib/firmware

the database for wireless adapters can be found in the wireless-regdb Debian package. Usually the kernel should load these. wireless-regdb is the Central Regulatory Domain Database. grab wireless regulatory database for CRDA:

git clone https://kernel.googlesource.com/pub/scm/linux/kernel/git/sforshee/wireless-regdb

move regulatory.db and regulatory.db.p7s into /lib/firmware/

this should fix the cfg80211: failed to load regulatory.db errors found in dmesg

configure your regulatory domain with:

iw reg set <EU|US|JP>

Armbian

Instead of using FriendlyCore, the NanoPi M4v2 can be run with the Rock Pi 4 build found here: https://www.armbian.com/rock-pi-4/

Goal is to run a Linux Kernel > 5.1 for the AX200NGW.

Currently, will need to run a nightly Armbian build or build our own.

Using M4v1 build on a M4v2

1. downloaded minimal M4 5.3.0 RC4 and burned it to SD card. https://dl.armbian.com/nanopim4/nightly/
2. downloaded pask's patch (`patch.tar.gz`) from https://drive.google.com/open?id=1LaJIywiZnZUkLDZ9HkWrRtc0PyfiYGOL
3. `dd` patch onto sdcard (note this is done after burning the image onto the uSD)
4. `sudo dd if=8M_after64ibs_uboot_working_rockpi4image_on_nanopim4v2.dd of=/dev/sdX seek=64`

Using Rockpi

https://dl.armbian.com/rockpi-4b/nightly/

Flash to SD card (can use Etcher to accomplish).

Modify /boot/armbianEnv.txt and add the following to the bottom:

fdtfile=rockchip/rk3399-nanopi-m4.dtb

You should see a flashing green LED if the boot is successful.

Optional

Install armbian-config:

sudo apt install armbian-config

Validating Specs (FriendlyCore or Armbian)

lshw:

sudo apt install lshw
sudo lshw

inxi (be aware inxi relies on some commands requiring dmidecode which may not exist on OS):

sudo apt install inxi
inxi

hwinfo:

sudo apt install hwinfo
hwinfo --short
hwinfo --cpu
hwinfo --memory
hwinfo --network

ethtool:

sudo apt install ethtool
ethtool eth0

memory:

top
free
vmstat -s
less /proc/meminfo
lshw -short -C memory
inxi

check current eth0 speed:

$ dmesg | grep eth0 | grep Up
[    8.701802] rk_gmac-dwmac fe300000.ethernet eth0: Link is Up - 100Mbps/Full - flow control rx/tx

PATH tweaks (if you dare - these should probably be in the root path and not in the normal user's $PATH - tread carefully)

Having problems running ifconfig, iwconfig, and the likes?

Check $ echo $PATH, if /sbin is missing, add it to your path:

export PATH=$PATH:/sbin

to make it persistent you can add to ~/.bashrc

Troubleshooting

Problems trying to boot from an SD card? Do have an eMMC module present? Try unplugging it.

serial debugging:

Use a USB-TTL serial dongle to see debug output: there is a 4 Pin 2.54mm header on the NanoPi M4v2. I haven't tried this yet. Be aware of voltage and pins used when doing this.

list debian packages using dpkg:

dpkg-query -l
dpkg-query -l | grep <string>

print the message buffer of the kernel with dmesg:

dmesg
dmesg | grep fail

list hw & usb devices:

lshw
lsusb

check the log:

tail /var/log/messages

dmesg buffer long? try clearing it:

sudo dmesg --clear

increase verbosity of modprobe:

modprobe -vvv <module>

check installed and remote version of a package:

apt-cache policy <package>

you an oldschool cat and using ifconfig? iproute2 /bin/ip is a newer more powerful version:

show network devices/config:

ifconfig

ip addr show
ip link show

enable/disable a network interface:

ifconfig eth0 up
ip link set eth0 up

ifconfig eth0 down
ip link set eth0 down

cool /bin/ip commands:

ip neigh
ip ro

also iwconfig has been replaced with iw:

sudo iw wlan0 scan | less
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment