Bering-uClibc 7.x - User Guide - Advanced Topics - Setting Up a Raspberry PI

From bering-uClibc
Jump to: navigation, search

Raspberry PIs installation of tarballs images

The simplest way of doing that is to use:

There are other ways too, but you have to know your way around... for instance, with the SD card mounted on the external PC, you could enable the console on /dev/ttyAMA0 by including a special configdb.lrp file in the tarball alongside the other *.lrp files. This special file will be automatically loaded by LEAF even if it is not specified in leaf.cfg. This file is normally created when you do save on LEAF but you can make one manually...

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:

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: 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 editting 2 files:

# Example how to put a getty on a serial line (for a terminal)
ttyAMA0::respawn:/sbin/getty -L ttyAMA0 115200 vt100


... add at the end of the file:

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 not connect +3.3V.

PI2 ttl USB.jpg 20210413 165052.png

and an RS232C to TTL 3.3 volts converter: pins 14,15, +3.3V and ground

Rs232 ttl rpi2 APU2C2.jpg

If you are using a USB converter, before rebooting your PI, run on your external PC:

picocom -b115200 /dev/ttyUSB0

After rebooting your PI, if you have both HDMI and serial displays still enabled, you should now see on both the console boot messages and logging prompts.

You might be wondering what the push-button and the blue led are doing on the PI2 header ... they are leftovers for other OSs that are not as safe as LEAF regarding the SD card corruption on power failure, have a look here ...
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) all have a single NIC, which will default to eth0, on LEAF. To ease and force a similar kind of access for your PI, from your local network, you should first temporarily remove the shorwall entry from the LRP=" list " in leaf.cfg file:

On your external PC, with the SD card in the /mnt directory, 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... 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 run the command: ip addr.

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 design, 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.