Raspberry Pi Serial Ports

The Gentoo Stage3 at the time of this writing is missing a couple of things to make the serial ports behave as they do in Raspbian Jessie. There is no Udev rule to create the serial0 and serial1 symlinks that point to the serial ports. In Raspbian, the serial0 symlink always points to the serial port assigned to GPIO14:15 while serial1 always points to the other serial port. Raspbian has a custom Udev rule that is responsible for this, but missing in the arm64 Gentoo Stage 3.

The other issue at hand is the console serial port assignment in /etc/inittab. By default, /etc/inittab assigns ttyAMA0 as the console serial port. For non-wireless/Bluetooth Pi units, it works perfectly fine as ttyAMA0 is the console serial port. However, on wireless/Bluetooth equipped units such as the Pi 3 and the Pi Zero W, ttyAMA0 defaults to the Bluetooth module. This cannot work as the console takes over ttyAMA0, creating a conflict.

UART Setup
In order to set up Gentoo such that it follows the Raspbian configuration, we need to do a few things -


 * Unassign ttyAMA0 as the console UART in /etc/inittab
 * Assign ttyS0 as the console UART in /etc/inittab (optional)
 * Create the dialout group
 * Create udev rules file which handles the serial symlinks and assigns the serial ports to the dialout group
 * Edit the config.txt and cmdline.txt files for your desired operation

Changing Console Assignment
Open up /etc/inittab -

Find the line below and comment it out by appending a # at the beginning of the line -

Save the file and exit.

Create The Dialout Group
Create the dialout group with a GID of 20 -

Create Udev Rules
In Raspbian Jessie, there is a custom Udev rule in /etc/udev/rules.d called 99-com.rules. This rule is responsible for ensuring that the serial0 symlink always points to the GPIO14:15 UART. I've made a slight modification to it to assign the serial hardware to the dialout group.

Create the file 99-com.rules -

Copy this text and paste it into the file.

Save and exit the file.

Modify The Boot Files
Mount the boot partition -

Open up config.txt -

Add the following at the end of the file -

Save and exit the file.

Open up cmdline.txt -

Add console=ttyS0,115200 to the kernel command line in the file. An example kernel command line is shown below -

Save and exit the file, then reboot the Pi -

===Checking Your Configuration