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

From bering-uClibc
Revision as of 01:12, 28 April 2021 by Jeanrocco (Talk | contribs) (Created page with "===Raspberry PIs installation of tarballs images=== ====partition and format your SD card==== We assume the PI will use an SD card for LEAF. As we said before the PI becomes...")

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Raspberry PIs installation of tarballs images

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 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 it 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.

Leave the SD card mounted for the next steps ...

prepare your Raspberry PI

There are 2 methods of accessing your PI, the serial console or the web browser. The serial console requires additionnal hardware while the web browser doesn't. But once installed the serial console can stay on all the time, and is a great tool for debugging.

serial console

The serial console will require that you connect a USB to TTL 3.3 volts converter to the GPIO pins 14(TX) and 15(RX) and ground of the PI. PI2 ttl USB.jpg

As usual, there is another small surprise 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 for our console is that on LEAF /dev/ttyAMA0 is the first PL011 (UART0).

Taken 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 .

One, last, more thing, the actual LEAF PI's distributions are not correctly assigning ttyAMA0 for the console, but we can easily correct that, for now, by copying this workaround file configdb.lrp to the SD card in /mnt so: ...

sudo cp ~/Downloads/configdb.lrp /mnt/

If you want to know, the file configdb.lrp simply adds ttyAMA0 to /etc/inittab and to /etc/securetty. When present on the boot media LEAF will read this configdb.lrp file last on boot, and will apply it's contents superseding the previous ones. This is a neat way of correcting some LEAF's parameters on the fly as the file does not have to be signed. This minimalist configdb.lrp file will be overwritten when you will do your first lrcfg s) save command, or a save configuration in webconf. This will be corrected in future distributions.

You can now proceed to accessing your PI .

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.

Of course, if you have the serial console installed, use a telecom program to connect to it:

picocom -b115200 /dev/ttyUSB0

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.