This is an old revision of the document!


Enable UART Serial Communication

Edit /boot/config.txt and append:

enable_uart=1

to the end of the file and reboot.

Disable Wifi Power Management

When receiving large amounts of output over SSH the Raspberry Pi might render the console inoperable and the connection will time out in a few seconds.

The following command adds some module options to the wifi kernel module to disable power management which is apparently responsible for the former issue.

echo "options 8192cu rtw_power_mgnt=0 rtw_enusbss=0" | sudo tee --append /etc/modprobe.d/8192cu.conf

Enable SSH on (First) Boot

Create a blank file named ssh with no extension at the root of the boot partition of the SD card in order to make Raspbian start the SSH daemon on boot. One use for this trick is combining the Raspberry Pi with an ethernet hat such that the Raspberry can be setup without needing to attach a monitor and keyboard.

Check if Hardware Decoders are Enabled

vcgencmd codec_enabled MPG2
vcgencmd codec_enabled WVC1

Note that the Raspberry Pi 4 does not have hardware decoders such that the commands will most likely state disabled.

Change Audio Output

Issuing:

amixer controls

will yield the controls available on the Raspberry Pi:

# amixer controls
numid=3,iface=MIXER,name='PCM Playback Route'
numid=2,iface=MIXER,name='PCM Playback Switch'
numid=1,iface=MIXER,name='PCM Playback Volume'

The Raspberry Pi 2,3 and 4 can commute between sending sound through the $3.5mm$ audio jack:

amixer cset numid=3 1

or the HDMI output:

amixer cset numid=3 2

respectively, or:

amixer cset numid=3

to set the sound selection to autodetect where the jack will be used only if the HDMI cable is not connected.

Fixing Various Network Issues

Any of the following symptoms are to be detected?

  • SSH connections drop,
  • issuing commands with large output over SSH makes the SSH session hang,
  • connection issues toward package repositories on Raspbian

They may all boil down to a non-uniform MTU setting across the network.

Logging-in via SSH over USB

The Raspberry Pi when connected to a PC can configure itself as an USB gadget and start a network over USB. A RNDIS network adapter is needed in most cases and can be downloaded from here:

In order to log into the Raspberry Pi over SSH via the USB port, edit config.txt and add:

dtoverlay=dwc2

Next, edit cmdline.txt and add the following to the kernel parameters between rootwait and quiet:

modules-load=dwc2,g_ether

Finally, add a blank file named ssh with no contents to the root of the boot partition.

The Raspberry can now be connected to a PC via its USB port (not the USB port marked PWR). The PC that the Raspberry Pi connects to will act as a router and should forward packets to the Raspberry Pi.

When the RNDIS interface is brought up, if Apple bonjour is installed and running on the machine that the Raspberry Pi is connected to, then the Raspberry Pi is supposed to register the DNS address raspberry.local via mDNS with Windows. Even if Apple bonjour is installed, the name might not be assigned even though the Rasbperry Pi might be configured properly as per the above. Also, it seems that in some cases when the RNDIS interface is brought up, the Raspberry Pi does not send any packets as all making an ARP table query via arp -a entirely futile.

The first attempt would be to try connecting via the assigned DNS address: ssh pi@raspberry.local and enter raspberry at the password prompt. if that fails, a packet sniffer such as WireShark or TcpDump may reveal the initial Raspberry Pi's ARP requests for Google's DNS servers (8.8.8.8). Sometimes just restarting the bonjour service and disabling and re-enabling the RNDIS interface may get the Raspberry Pi to register its name.

Connecting to a Bridge Automatically

In order to connect the Raspberry Pi to a bridge as it is connected to a server, an udev rule can be written that will match all RNDIS adapters and connect them to a bridge.

The only changes required on the Raspberry Pi is to edit /etc/network/interfaces.d/usb0 and add the lines:

auto usb0
iface usb0 inet dhcp

and save the file. This will make sure that when the Raspberry Pi boots, an IP address will be requested over the usb0 interface and will work provided that the computer that the Raspberry Pi is connected to is running a DHCP server on the other end.

Enabling Monitor Mode via Nexmon Drivers

Some Raspberry Pi devices such as the Raspberry Pi Zero W can operate in monitor mode in order to sniff wireless traffic. Up to this date, there is no official way to get monitor mode working for the Raspberry SoC except for using alternative Nexmon drivers that replace the brcmfmac kernel module with a patched module enabling monitor mode. Unfortunately, the Nexmon drivers lag behind and last successful builds are known to work with Raspbian Jessie at best.

Here is a short guide on how to build the nexmon drivers for Raspberry Pi W and substitute the kernel module in order to enable monitor mode.

Install required packages to compile the drivers:

apt-get install subversion raspberrypi-kernel-headers git libgmp3-dev gawk qpdf bison flex make autoconf automake build-essential libtool libisl10

Change directory to a compile space:

cd /usr/src

and check out the source (official):

git clone https://github.com/MaximusBaton/nexmon.git

or from Wizardry and Steamworks:

svn co http://svn.grimore.org/nexmon

Set variables:

export NEXMON_ROOT=/usr/src/nexmon

and load the provided environment:

source setup_env.sh

Now compile the nexmon package from the top-level:

make

Now build the kernel module and firmware:

cd patches/bcm43430a1/7_45_41_46/nexmon/

where:

  • bcm43430a1 is for the Raspberry Pi Zero W
make

Now generate a backup of the original firmware file and install the patched firmware:

make backup-firmware
make install-firmware

Compile nexutil since it might come in handy:

cd utilities/nexutil
make install

Now to make the Raspberry load the modified kernel module after reboot it, the existing module is simply substituted for the module that was compiled at the previous step:

PATH_OF_DEFAULT_DRIVER_AT_REBOOT=$(modinfo brcmfmac | grep -m 1 -oP "^filename:(\s*?)(.*)$" | sed -e 's/^filename:\(\s*\)\(.*\)$/\2/g')
mv "$PATH_OF_DEFAULT_DRIVER_AT_REBOOT" "$PATH_OF_DEFAULT_DRIVER_AT_REBOOT.orig"
cp patches/bcm43430a1/7_45_41_46/nexmon/brcmfmac_4.14.y-nexmon/brcmfmac.ko $PATH_OF_DEFAULT_DRIVER_AT_REBOOT

Finally, generate module dependencies:

depmod -a

In order to set up the Wifi monitoring interface on boot, create the file /etc/network/interfaces.d/mon0 with the following contents:

auto mon0
iface mon0 inet manual
  pre-up iw wlan0 interface add mon0 type monitor
  wireless-mode monitor

and restart the Raspberry Pi.

Running a One-Off Script on First Machine Boot

To execute a script unconditionally edit /boot/cmdline.txt and set init to mount virtual filesystems and then execute a script. For example, the /boot/cmdline.txt file would contain:

init=/bin/bash -- -c "mount -t proc proc /proc; mount -t sysfs sys /sys; mount /boot; source /boot/firstboot.sh"

that will end up executing /boot/firstboot.sh.

The contents of /boot/firstboot.sh should make sure to remove the init parameter from the kernel command line such that the first boot script does not run again, then perform the necessary operations and finally restart the system:

# Boot
mount -t tmpfs tmp /run
mkdir -p /run/systemd
mount / -o remount,rw
# Ensure the script does not run again.
sed -i 's| init=.*||' /boot/cmdline.txt
 
# Run
 
# Insert custom commands.
/usr/lib/raspi-config/init_resize.sh
/usr/bin/ssh-keygen -A
 
# Reboot
sync
umount /boot
mount / -o remount,ro
sync
echo 1 > /proc/sys/kernel/sysrq
echo b > /proc/sysrq-trigger
sleep 5

fuss/raspberry_pi.1588974942.txt.gz · Last modified: 2020/05/08 21:55 by office

Access website using Tor Access website using i2p Wizardry and Steamworks PGP Key


For the contact, copyright, license, warranty and privacy terms for the usage of this website please see the contact, license, privacy, copyright.