Bering-uClibc 7.x - User Guide - Advanced Topics - Setting Up a Raspberry PI
Contents
Raspberry PIs installation of tarballs images
We will use:
- a HDMI Television or a computer monitor with an HDMI input
- a USB keyboard
- for the PI Zero we will need a mini to standard HDMI adapter and a USB OTG micro B to A cable.
partition and format your SD card
We assume the PI will use an SD card for LEAF. As we said before the PI becomes very reliable when running LEAF so there is no appreciable gain to use a so called "more reliable" USB key.
On an external PC running Linux, insert your SD card, and run:
dmesg or sudo fdisk -l
to see which device your SD card is assigned to (let's assume we get /dev/sdb)...
Start the fdisk utility to partition your SD card.
sudo fdisk /dev/sdb
The safest approach is to delete any existing partition. To delete a partition type "d", to create a new partition type "n", choose "p" for a new primary partition, "1" for the partition number, accept the default values for First and Last Sector. To change the partition system id to W95 FAT32, choose "t" and "b".
You may have a look before writing the changes to your SD with the command "p". It should show something like this:
Device Boot Start End Blocks Id System /dev/sdb1 2048 524287 261120 b W95 FAT32
Save your changes with the command "w".
Format the SD card:
sudo mkfs.vfat -r 1024 /dev/sdb1
Mount the SD card:
sudo mount /dev/sdb1 /mnt cd /mnt
Extract your tarball: extract the contents of your PI(n) downloaded file with a command like the following
sudo tar -xvzf ~/Download/Bering-uClibc/7.0.1/Bering-uClibc_7.0.1_raspberry-rpi3.tar.gz
Note: that this assumes the downloaded file is located in your $HOME/Download
directory.
sudo umount /dev/mnt
Insert the SD card in your PI.
prepare your Raspberry PI
Connect your PI to your HDMI monitor and USB keyboard, and power it up ...
You will get a display on your HDMI screen just like on a VGA display and the keyboard will act like the Linux tty1 standard input device.
From here on you can configure everything on the PI. Let's look at some interesting and desirable setups...
Enabling the PI Linux serial console
As usual, there is a small catch 22 waiting for us... just have a look at the Raspberry Pis documentation on the UARTS here and you will find out that all PIs are not born equal... The important thing is that for LEAF the PI's /dev/ttyAMA0 should be the first PL011 (UART0).
... extracted from the PI's documentation:
By default, only UART0 is enabled. The following table summarises the assignment of the first two UARTs:
Model | first PL011 (UART0) | mini UART |
---|---|---|
Raspberry Pi Zero | primary | secondary |
Raspberry Pi Zero W | secondary (Bluetooth) | primary |
Raspberry Pi 1 | primary | secondary |
Raspberry Pi 2 | primary | secondary |
Raspberry Pi 3 | secondary (Bluetooth) | primary |
Raspberry Pi 4 | secondary (Bluetooth) | primary |
This means that for the PIs Zero W, 3 and 4, you will have to add dtoverlay=disable-bt
at the end of the file config.txt
to reassign UART0 as the primary UART .
mount /dev/mmcblk0p1 /mnt
cd /mnt
edit config.txt
... and add at the end dtoverlay=disable-bt
Doing so insures that the serial interface conveniently becomes /dev/ttyAMA0 for all PIs in LEAF.
now for the Linux console
The Linux console is simply enabled by touching 2 files:
/etc/inittab add: ... # Example how to put a getty on a serial line (for a terminal) # ttyAMA0::respawn:/sbin/getty -L ttyAMA0 115200 vt100 ...
and
/etc/securetty ... add at the end of the file: ttyAMA0
The serial interface is available on the PI's GPIO pins 14(TX) and 15(RX). You can use any suitable converter to connect to it as long as it uses 3.3 volts DC.
Here are examples of a USB to TTL 3.3 volts converter: pins 14, 15 and ground...do not connect +5V.
and an RS232C to TTL 3.3 volts converter: pins 14,15, +5V and ground
To display your console on your external PC screen using a USB converter run:
picocom -b115200 /dev/ttyUSB0
and reboot your PI.
reboot
You should now have both the TV display and the picocom terminal giving you the boot messages and a logging prompt.
web browser method
You could have a look here at how LEAF now allows a secure web browser access on eth1 on platforms that have more than one NIC. The PIs (1,2,3,and 4), on the other hand, all have a single NIC, which will default to eth0, on LEAF. To facilitate and enjoy the same kind of access for your PI, when it will be connected on your local network, you should first temporarily remove the shorwall
entry from the LRP=" list " in leaf.cfg
file:
while still in the /mnt directory, from the previous steps, edit the leaf.cfg
file with
sudo nano leaf.cfg
find the line
LRP="license root nano dhcpcd keyboard shorwall dnsmasq dropbear lighttpd webconf patch"
and remove the shorwall
entry ... save and exit nano, run sync and un-mount the SD card.
accessing your PI
Now insert the SD card in your PI, connect it to your local network, and power it up. Count to 100 :-)..., your local network DHCP server should assign an IP address to your PI. You can then access the PI from a web browser running on your external PC at http://dhcp.assigned.addr with admin:admin. To find out the IP address, use fing on Android or look in /var/lib/misc/dnsmasq.leases
if you're already running a LEAF firewall local net.
You can always add other NICs with a suitable HAT add-on or a dongle, to your PI and use it more like the intended LEAF box router, but remember to restore the shorwall
entry. The PI's might not be the best routers firewalls, but in these cases and for other networking purposes they become a very robust platform once loaded with LEAF since the code is then executed in rams only and no potentially destructive writes to SD card will ever happen while running.
As of this writing, a naked PI Zero can only be access with the serial console, using GPIO 14 and 15 and a ttl-usb converter, since there is no NIC... The console have to be enabled by adding the file configdb.lrp to the media files.
The PI zero W is an interesting one, as it can be accessed thru WIFI... There is an example of it's use here which does not use the serial console.