# Installation

# Raspberry Pi Installation

## USB to Ethernet Adapter

<https://elinux.org/RPi_USB_Ethernet_adapters>  
- Not the Amazon one
- TP-Link UE300 parfait (<https://www.tp-link.com/en/home-networking/usb-ethernet-adapter/ue300/v4/>)

## Cases

For RPi 1 B : <https://www.thingiverse.com/thing:4384009>

## Operating System

- Install the official installer tool `Raspberry Pi Imager`  
  Depending on the OS, find the adapted software.  
  <https://www.raspberrypi.com/software/>

- For a USB boot, follow these steps :
  - Format a SD card as FAT 32 (can be a small 256Mb partition)
  - Copy the latest `bootcode.bin` on the partition  
    <https://github.com/raspberrypi/firmware/raw/master/boot/bootcode.bin>
    - If the RPi doesn't boot on the USB SSD disk after unplugging a USB keyboard, add a delay to the boot initialisation by creating a file named `timeout` on the same partition as *bootcode.bin*.  
      => Required with Kingston A400S and Startech SATA to USB.

- Run the installer tool and configure the future OS

  - Depending on RPI model, choose an adequate OS  
    | RPI Model | Specs | OS Recommended | PSU |
    | - | - | - | - |
    | RPi 1 B | 700 Mhz - 256 MB | RPi OS Lite (32 bit) | >= 2.5A |
    | RPi 3 B | 1.2 Ghz - 1 GB | RPi OS Lite (64 bit) | >= 2.5A |

    - To identify the model
      ```sh
      cat /sys/firmware/devicetree/base/model
      cat /proc/cpuinfo
      # Check RAM
      free -h
      ```

  - Set hostname (rpi-(dogname).local)
  - Enable SSH
    - Pub Key : Use the RaspPI one
  - Define user
      - name : rpi
      - pass : rpi
    - Set local settigns
      - timezone: America/Montreal
      - Keyboard : ca

- SSH to board
  - Configure GPU memory to minimum  
    `sudo raspi-config nonint do_memory_split 16`
- Update the board completely
  ```sh
  sudo apt update
  sudo apt full-upgrade -y
  reboot
  ```

- Optimization
```sh
# Increase swap file
sudo dphys-swapfile swapoff
CONF_SWAPSIZE=1024 # in file /etc/dphys-swapfile
sudo dphys-swapfile setup
sudo dphys-swapfile swapon

# Disable HDMI
/usr/bin/tvservice -o
# Doesn't work with latest version which uses `DRM VC4 V3D driver`
# Modify the line of the driver to disbale HDMI :
dtoverlay=vc4-kms-v3d,nohdmi
# ref : https://github.com/raspberrypi/firmware/blob/master/boot/overlays/README#L4571C13-L4571C13

# /boot/config.txt tweaks
# https://github.com/raspberrypi/firmware/blob/master/boot/overlays/README

## Disable splash screen
disable_splash=1

## Disable Bluetooth
# https://github.com/raspberrypi/firmware/blob/master/boot/overlays/README#L921
dtoverlay=disable-bt

## Disable WIFI if not used
# https://github.com/raspberrypi/firmware/blob/master/boot/overlays/README#L938
dtoverlay=disable-wifi

## Disable HDMI
dtparam=hdmi=off
## SD card working freq (default 50MHz)
dtparam=sd_overclock=100
## Disable SD card check
dtparam=sd_poll_once=on
## Disable audio
dtparam=audio=off

# then disable services
sudo systemctl disable hciuart.service
sudo systemctl disable bluealsa.service
sudo systemctl disable bluetooth.service

```

- Install ZRAM  
<https://github.com/novaspirit/rpi_zram>

<https://haydenjames.io/raspberry-pi-performance-add-zram-kernel-parameters/>

## Overclocking

### Display frequencies

```bash
sudo cat /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq # max
sudo cat /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_min_freq # min
sudo cat /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_cur_freq # current

# Get live metrics
watch -n1 vcgencmd measure_clock arm
watch -n1 vcgencmd measure_temp
```

<https://picockpit.com/raspberry-pi/overclock-raspberry-pi/>  
<https://www.tomshardware.com/how-to/overclock-any-raspberry-pi>  
<https://www.raspberrypi.org/documentation/configuration/config-txt/overclocking.md>

| Model	| config.txt settings |
| - | - |
| Raspberry Pi 1 Model A & B |	arm_freq=1000
| | core_freq=450 |
| | over_voltage=6 |
| | sdram_freq=450 |
| Raspberry Pi 3 & Compute Module 3	| arm_freq=1300 |
| source: picockpit (heatsink compatible)| core_freq=500 |
| | over_voltage=4 |
| | sdram_freq=450 |

- Optional values to review  
  force_turbo=1# Prevent regulation of speed down to 600Mhz when idling  
  boot_delay=1 # Avoid sdcard corruption when force_turbo is enabled

## Default configuration file

```bash
# Personal /boot/config.txt

# Presets RPI1 - Use at least a heatsink !!
# =======
# TYPE : ARM ; CORE ; RAM ; VOLT
# None :   700 ; 250 ; 400 ; 0
# Modest : 800 ; 250 ; 400 ; 0
# Medium : 900 ; 250 ; 450 ; 2
# High :   950 ; 250 ; 450 ; 6
# Tubro : 1000 ; 500 ; 600 ; 6

[pi1]
arm_freq=900 # CPU (default 700)
core_freq=250 # GPU (default 250) - Helps with L2 cache, better for RPI1
sdram_freq=450 # RAM (default 400)
over_voltage=2 # Overall voltage (default 0)

[pi3]
arm_freq=1200 # CPU (default 1200)
core_freq=400 # GPU (default 400) - Helps with L2 cache, better for RPI1
sdram_freq=450 # RAM (default 450)
over_voltage=0 # Overall voltage (default 0)

[all]
# Disable splash screen
disable_splash=1
# Disable serial
enable_uart=0
# Set GPU RAM to minimum (headless)
gpu_mem=16
# Give a small delay for the boot (better safe than sorry)
boot_delay=1
# Disable Bluetooth
dtoverlay=disable-bt
# Disable audio
dtparam=audio=off
# Disable HDMI
dtparam=hdmi=off
dtoverlay=vc4-kms-v3d,nohdmi
# Overclock SD Card controller in MHz - Enable this only if not booting on USB
# dtparam=sd_overclock=100 # default 50
# Disable SD Card polling once started
dtparam=sd_poll_once=on
## Disable WIFI if not used
# dtoverlay=disable-wifi

```

## More optimizations

<https://picockpit.com/raspberry-pi/raspberry-pi-zero-2-battery/>

## Resources

<https://feriman.com/raspberry-pi-optimization-hardware-and-software/>  
<https://di-marco.net/blog/it/2020-04-18-tips-disabling_bluetooth_on_raspberry_pi/>  
<https://pibenchmarks.com/latest/>