Skip to content

Latest commit

 

History

History
645 lines (507 loc) · 17.4 KB

INSTALL_RPI3B_PLUS.md

File metadata and controls

645 lines (507 loc) · 17.4 KB

Notes on fresh RPI 3B+ installation

Download OS image from https://www.raspberrypi.com/software/

Backup card, unmount, unpack disk image, write to SD card:

sudo dd if=2023-05-03-raspios-bullseye-armhf-lite.img of=/dev/mmcblk0 bs=4M status=progress

Open Gparted, resize root partition to fill space.

Mount memory card partitions.

Enable SSH on first boot:

cd /run/media/darek/bootfs
touch ssh

Setup static IP address on Ethernet (connected directly to laptop):

sudo nano /run/media/darek/rootfs/etc/dhcpcd.conf

Add lines:

interface eth0
static ip_address = 192.168.1.3

That is initial bootfs/cmdline.txt

console=serial0,115200 console=tty1 root=PARTUUID=4c4e106f-02 rootfstype=ext4 fsck.repair=yes rootwait quiet init=/usr/lib/raspberrypi-sys-mods/firstboot

Append static IP setting at the end of boot line:

ip=192.168.1.3::192.168.1.1:255.255.255.0:rpi:eth0:off

Setup password of pi user by copying shadow entry from another Linux:

sudo su
cat /etc/shadow | grep YOUR_USER >> /run/media/darek/rootfs/etc/shadow

Edit /run/media/darek/rootfs/etc/shadow replacing YOUR_USER with pi and all content after password hash with content from original pi user line, then delete original pi user line.

Umount and run RPI, connect Ethernet cable, wait until starts.

Connect to SSH

ssh pi@192.168.1.3

Type yes:

Are you sure you want to continue connecting (yes/no/[fingerprint])? yes

When connected update password

sudo su
passwd pi

On laptop do:

$ ssh-keygen -t rsa -b 4096
Enter file in which to save the key (/home/darek/.ssh/id_rsa): /home/darek/.ssh/rpi3_rsa

$ scp /home/darek/.ssh/rpi3_rsa.pub pi@192.168.1.3:
$ ssh pi@192.168.1.3

pi@raspberrypi:~ $ mkdir .ssh
pi@raspberrypi:~ $ cat rpi3_rsa.pub >> .ssh/authorized_keys
pi@raspberrypi:~ $ rm rpi3_rsa.pub

Re-login SSH, should be able to access without password this time.

Execute sudo raspi-config enable SPI, in my case also I2C for real-time hwclock and 1-wire for thermomether. Do not reboot yet.

Updated with raspi-config

$ cat /boot/config.txt
# For more options and information see
# http://rpf.io/configtxt
# Some settings may impact device functionality. See link above for details

# uncomment if you get no picture on HDMI for a default "safe" mode
#hdmi_safe=1

# uncomment the following to adjust overscan. Use positive numbers if console
# goes off screen, and negative if there is too much border
#overscan_left=16
#overscan_right=16
#overscan_top=16
#overscan_bottom=16

# uncomment to force a console size. By default it will be display's size minus
# overscan.
#framebuffer_width=1280
#framebuffer_height=720

# uncomment if hdmi display is not detected and composite is being output
#hdmi_force_hotplug=1

# uncomment to force a specific HDMI mode (this will force VGA)
#hdmi_group=1
#hdmi_mode=1

# uncomment to force a HDMI mode rather than DVI. This can make audio work in
# DMT (computer monitor) modes
#hdmi_drive=2

# uncomment to increase signal to HDMI, if you have interference, blanking, or
# no display
#config_hdmi_boost=4

# uncomment for composite PAL
#sdtv_mode=2

#uncomment to overclock the arm. 700 MHz is the default.
#arm_freq=800

# Uncomment some or all of these to enable the optional hardware interfaces
dtparam=i2c_arm=on
#dtparam=i2s=on
dtparam=spi=on

# Uncomment this to enable infrared communication.
#dtoverlay=gpio-ir,gpio_pin=17
#dtoverlay=gpio-ir-tx,gpio_pin=18

# Additional overlays and parameters are documented /boot/overlays/README

# Enable audio (loads snd_bcm2835)
dtparam=audio=on

# Automatically load overlays for detected cameras
camera_auto_detect=1

# Automatically load overlays for detected DSI displays
display_auto_detect=1

# Enable DRM VC4 V3D driver
dtoverlay=vc4-kms-v3d
max_framebuffers=2

# Disable compensation for displays with overscan
disable_overscan=1

[cm4]
# Enable host mode on the 2711 built-in XHCI USB controller.
# This line should be removed if the legacy DWC2 controller is required
# (e.g. for USB device mode) or if USB support is not required.
otg_mode=1

[all]

[pi4]
# Run as fast as firmware / board allows
arm_boost=1

[all]
dtoverlay=w1-gpio

Configure timezone:

sudo dpkg-reconfigure tzdata

Install dependencies:

wget http://www.airspayce.com/mikem/bcm2835/bcm2835-1.73.tar.gz
tar xvpf bcm2835-1.73.tar.gz
cd bcm2835-1.73/
./configure
make
sudo make install
sudo apt install libx11-dev libxfixes-dev

Clean-up network settings

  • Use sudo raspi-config to manage network with NetworkManager and not dhcpcd
  • Remove IP settings from /boot/cmdline.txt
  • Use sudo nmtui to:
    • remove redundant eth0 entries
    • remove Local connection (redundant)
    • leave only one eth0 - never use this interface for default route, remove default gw, connect automatically on startup
    • see rpi_nmtui_eth0_config.png
    • Add new connection - wifi (if needed).
  • Make sure correct services are loaded:
sudo systemctl enable NetworkManager
sudo systemctl disable dhcpcd
sudo systemctl stop dhcpcd
sudo reboot

Raspberry desktop environment in standalone mode

Setup some libs and desktop environment

sudo apt install mate-desktop-environment-extras libx11-dev libxfixes-dev libxext-dev xinit xserver-xorg-video-dummy

Setup xorg.conf as described in README.md

Setup sudo as described in sudoers.example

echo '[[ -z $DISPLAY && $XDG_VTNR -eq 1 ]] && exec startx' > ~/.profile

Setup getty@tty1 service as in README.md And .xinitrc with EINK_ENABLE=0 (will run manually).

Skip setting magic cookie at the moment.

Reboot.

Choose anybody while asked:

sudo dpkg-reconfigure xserver-xorg-legacy
sudo reboot

Add to the /boot/config.txt

framebuffer_width=1200
framebuffer_height=825
hdmi_force_hotplug=1
hdmi_group=2
hdmi_mode=82

Reboot

mv .xinitrc .xsession
sudo systemctl enable getty@tty1

Reboot

darek@M6600 ~ $ ssh -X pi@192.168.1.3
Please note that SSH may not work until a valid user has been set up.

See http://rptl.io/newuser for details.
Warning: untrusted X11 forwarding setup failed: xauth key data not generated
Linux raspberrypi 6.1.21-v7+ #1642 SMP Mon Apr  3 17:20:52 BST 2023 armv7l

The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
Last login: Thu Sep  7 21:34:13 2023 from 192.168.1.1

pi@raspberrypi:~$ echo $DISPLAY

pi@raspberrypi:~$ xauth list $DISPLAY
raspberrypi/unix:0  MIT-MAGIC-COOKIE-1  d2b6f9e21ed52bf9526226ab39497e18
raspberrypi:0  MIT-MAGIC-COOKIE-1  d2b6f9e21ed52bf9526226ab39497e18
pi@raspberrypi:~$ xinit: giving up
xinit: unable to connect to X server: Connection refused
xinit: server error
Couldn't get a file descriptor referring to the console.

[1]+  Exit 1                  startx
pi@raspberrypi:~$ xauth add raspberrypi/unix:0  MIT-MAGIC-COOKIE-1  d2b6f9e21ed52bf9526226ab39497e18
pi@raspberrypi:~$

Update X11 23.09.2023

Added spidev.bufsiz=65536 to boot/cmdline.txt

Added to boot/config.txt

# uncomment this if your display has a black border of unused pixels visible
# and your display can output without overscan
disable_overscan=1

# uncomment the following to adjust overscan. Use positive numbers if console
# goes off screen, and negative if there is too much border
overscan_left=0
overscan_right=0
overscan_top=0
overscan_bottom=0

# uncomment to force a console size. By default it will be display's size minus
# overscan.
framebuffer_width=1200
framebuffer_height=825
framebuffer_depth=32
framebuffer_ignore_alpha=1

Commented out all hdmi related config.txt

Config for I2C hwclock enabled (optional) and SPI (required)

# Uncomment some or all of these to enable the optional hardware interfaces
dtparam=i2c_arm=on
dtparam=i2c1=on
#dtparam=i2s=on
dtparam=spi=on

/etc/X11/Xwrapper.config

needs_root_rights=yes
allowed_users=anybody

~/.profile

# if running bash
if [ -n "$BASH_VERSION" ]; then
    # include .bashrc if it exists
    if [ -f "$HOME/.bashrc" ]; then
    . "$HOME/.bashrc"
    fi
fi

# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/bin" ] ; then
    PATH="$HOME/bin:$PATH"
fi

# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/.local/bin" ] ; then
    PATH="$HOME/.local/bin:$PATH"
fi

[[ -z $DISPLAY && $XDG_VTNR -eq 1 ]] && exec startx

~/.xsession

EINK_ENABLE=0
LOGF="/home/pi/eink.log"
#EINK_EXEC="/opt/eink/eink_rpi_standalone"
EINK_ARGS="4 20 200 3 550 1200 825 0 0 0 50 1 1930 17850000"

EINK_EXEC="/home/pi/projects/eink2_x11_1200x825_24bpp/eink_rpi_standalone"

# That's only for my touchscreen which is wider and lower than Eink screen
# xinput set-prop "pointer:UsbHID SingWon-CTP-V1.18A" "Coordinate Transformation Matrix" \
#   1.109057 0 0 0 1 0 0 0 1
#EINK_ARGS="4 20 200 3 550 1200 750 0 0 0 50 1 1930 17850000"

if [ $EINK_ENABLE -eq 1 ] ; then
        echo "=== $(date) EINK is enabled ===" >>$LOGF
        exec mate-session &
        sleep 15

        echo "=== $(date) Starting EINK ===" >>$LOGF
        sudo $EINK_EXEC $EINK_ARGS >>$LOGF 2>&1
        RET=$?
        echo "=== $(date) EINK exited with status $RET ===" >>$LOGF
        exit $RET
else
        echo "=== $(date) EINK is DISABLED ===" >>$LOGF
        exec mate-session
fi

Added to ~/.bashrc

if [[ -z $DISPLAY ]] ; then
  pidof -q Xorg && DISPLAY=":0"
fi

After above setting mate-session is started and can run ex DISPLAY=":0" pluma.

Issue was:

pi@raspberrypi:~/projects/eink2_x11_1200x825_24bpp $ DISPLAY=":0" sudo ./eink_rpi_standalone 4 20 200 3 550 1200 825 0 0 0 500 1 0 0
...
No protocol specified
XOpenDisplay fail: No such file or directory

That was due to it requires root to have access to X server started by pi user.

Found out that there is missing /root/.Xauthority...

Following solved issue

SSH with -X option

darek@M6600 ~ $ ssh -X pi@192.168.1.3

Run second Xorg now as root

pi@raspberrypi:~ $ sudo startx

Move it to background with CTRL^Z and then

pi@raspberrypi:~ $ xauth list $DISPLAY
raspberrypi/unix:0  MIT-MAGIC-COOKIE-1  d2b6f9e21ed52bf9526226ab39497e18
pi@raspberrypi:~ $ sudo xauth add raspberrypi/unix:0  MIT-MAGIC-COOKIE-1  d2b6f9e21ed52bf9526226ab39497e18
pi@raspberrypi:~ $ fg

Terminate with CTRL^C and verify both user and root has authority set:

pi@raspberrypi:~ $ xauth list $DISPLAY
raspberrypi/unix:0  MIT-MAGIC-COOKIE-1  d2b6f9e21ed52bf9526226ab39497e18
pi@raspberrypi:~ $ sudo xauth list $DISPLAY
raspberrypi/unix:0  MIT-MAGIC-COOKIE-1  d2b6f9e21ed52bf9526226ab39497e18

And run Eink standalone, should work now

pi@raspberrypi:~ $ cd projects/eink2_x11_1200x825_24bpp/
pi@raspberrypi:~/projects/eink2_x11_1200x825_24bpp $ DISPLAY=":0" sudo ./eink_rpi_standalone 4 20 200 3 550 1200 825 0 0 0 500 1 0 0

Reboot Raspberry and verify again: Had some issue with Eink controller, needed to press Reset on HAT and re-run:

darek@M6600 ~ $ ssh pi@192.168.1.3
Please note that SSH may not work until a valid user has been set up.

See http://rptl.io/newuser for details.
Linux raspberrypi 6.1.21-v7+ #1642 SMP Mon Apr  3 17:20:52 BST 2023 armv7l

The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
Last login: Sat Sep 23 14:43:19 2023
pi@raspberrypi:~ $ cd projects/eink2_x11_1200x825_24bpp/
pi@raspberrypi:~/projects/eink2_x11_1200x825_24bpp $ DISPLAY=":0" sudo ./eink_rpi_standalone 4 20 200 3 550 1200 825 0 0 0 500 1 0 0
bpp_mode: 4 bit per eink pixel
bar_height: 20 px
n_full_refresh every: 200 frames
set_size: 3
set_max_dist: 550
screen_width: 1200 px
screen_height: 825 px
screen_x0: 0 px
screen_y0: 0 px
invert colors: 0
X11 refresh interval: 500 ms
show mouse cursor: 1
vcom: 0 mV
SPI speed: 0 Hz
                _spi_init#0543: Using SPI clock divider /32
              IT8951_Init#0757: ****** IT8951 ******
               _epd_reset#0292: Perform reset...
               _epd_reset#0294: Reset ok. Send SYS_RUN command...
               _epd_reset#0299: Reset OK
           Device_getInfo#0323: Command sent
^C
pi@raspberrypi:~/projects/eink2_x11_1200x825_24bpp $ DISPLAY=":0" sudo ./eink_rpi_standalone 4 20 200 3 550 1200 825 0 0 0 500 1 0 0
bpp_mode: 4 bit per eink pixel
bar_height: 20 px
n_full_refresh every: 200 frames
set_size: 3
set_max_dist: 550
screen_width: 1200 px
screen_height: 825 px
screen_x0: 0 px
screen_y0: 0 px
invert colors: 0
X11 refresh interval: 500 ms
show mouse cursor: 1
vcom: 0 mV
SPI speed: 0 Hz
                _spi_init#0543: Using SPI clock divider /32
              IT8951_Init#0757: ****** IT8951 ******
               _epd_reset#0292: Perform reset...
               _epd_reset#0294: Reset ok. Send SYS_RUN command...
               _epd_reset#0299: Reset OK
           Device_getInfo#0323: Command sent
Panel(W,H) = (0,0)
Image Buffer Address = 0
FW Version =
LUT Version =
           Device_getInfo#0349: Incorrect device info
              IT8951_Init#0763: Fail to get device info
                     main#0018: Eink init error
pi@raspberrypi:~/projects/eink2_x11_1200x825_24bpp $ DISPLAY=":0" sudo ./eink_rpi_standalone 4 20 200 3 550 1200 825 0 0 0 500 1 0 0
bpp_mode: 4 bit per eink pixel
bar_height: 20 px
n_full_refresh every: 200 frames
set_size: 3
set_max_dist: 550
screen_width: 1200 px
screen_height: 825 px
screen_x0: 0 px
screen_y0: 0 px
invert colors: 0
X11 refresh interval: 500 ms
show mouse cursor: 1
vcom: 0 mV
SPI speed: 0 Hz
                _spi_init#0543: Using SPI clock divider /32
              IT8951_Init#0757: ****** IT8951 ******
               _epd_reset#0292: Perform reset...
               _epd_reset#0294: Reset ok. Send SYS_RUN command...
               _epd_reset#0299: Reset OK
           Device_getInfo#0323: Command sent
Panel(W,H) = (1200,825)
Image Buffer Address = 11A1E0
FW Version = SWv_0.2.1T
LUT Version = M841T
Get VCOM...
VCOM = -2600 mV
         XScreenshot_init#0194: self->bar_height = 20
         XScreenshot_init#0195: self->bar_count = 42
         XScreenshot_init#0196: self->last_bar_height = 5
           ClientLoop_run#0056: Waiting for SIGINT|SIGUSR1 or refresh with interval 500 millis
           ClientLoop_run#0057: *** PID is: 1501

Also needed to install keyboard/mouse drivers:

pi@raspberrypi:~ $  sudo apt install xserver-xorg-input-evdev xserver-xorg-input-mouse xserver-xorg-input-libinput xinput

Added config file /etc/X11/xorg.conf.d/40-libinput.conf

Section "InputClass"
        Identifier "libinput keyboard catchall"
        MatchIsKeyboard "on"
        MatchDevicePath "/dev/input/event*"
        Driver          "libinput"
EndSection

Restart X by terminating Xorg process:

pi@raspberrypi:~/projects/eink2_x11_1200x825_24bpp $ ps aux  | grep X
pi        1065  0.0  0.0   3756   716 tty1     S+   14:44   0:00 xinit /etc/X11/xinit/xinitrc -- /etc/X11/xinit/xserverrc :0 vt1 -keeptty -auth /tmp/serverauth.cRowkTbfOc
root      1066  2.1  7.5 289564 71668 tty1     Sl   14:44   0:10 /usr/lib/xorg/Xorg -nolisten tcp :0 vt1 -keeptty -auth /tmp/serverauth.cRowkTbfOc
pi        1877  0.0  0.0   7452   588 pts/0    S+   14:52   0:00 grep --color=auto X
pi@raspberrypi:~/projects/eink2_x11_1200x825_24bpp $ sudo kill -s SIGTERM 1066

And re-run eink_rpi_standalone once started. Works.

Update X11 input (working)

sudo apt purge xserver-xorg-input-libinput
sudo systemctl mask systemd-logind.service
sudo pam-auth-update # confirm with default settings

Reboot

On one SSH session startx, on another start eink standalone. Input devices should work now.

Auto-start standalone setup

Prepare

See also: touch_panel.md

Commented out in ~/.bashrc

#if [[ -z $DISPLAY ]] ; then
#  pidof -q Xorg && DISPLAY=":0"
#fi

Commented out in ~/.profile

#if [ -z "${DISPLAY}" ] && [ "${XDG_VTNR}" -eq 1 ]; then
#  exec startx
#fi

Install lightdm

sudo apt install lightdm lightdm-gtk-greeter

Hint. Was stucked on dpkg used by other process

$ ps aux | grep dpkg
root      1419  1.5  1.5  22292 14964 tty8     S+   16:37   0:01 /usr/bin/perl -w /usr/sbin/dpkg-reconfigure -p critical keyboard-configuration
root      1432  0.1  0.3   3984  3480 tty8     S+   16:37   0:00 /bin/sh /var/lib/dpkg/info/keyboard-configuration.config reconfigure 1.205+rpt1
pi        1610  0.0  0.0   7448   516 pts/0    S+   16:38   0:00 grep --color=auto dpkg

And then:

$ sudo kill -9 1419 1432; sudo dpkg-reconfigure keyboard-configuration

And set keyboard layout settings.

Finally run raspi-config and apply:

System options > Boot / Auto Login > B3 Desktop

Reboot.

Verify is running:

pi@raspberrypi:~ $ ps aux | grep lightdm
root       594  0.5  0.6  38360  6016 ?        Ssl  16:50   0:00 /usr/sbin/lightdm
root       603  3.6  4.6 289000 44340 ?        Sl   16:50   0:00 /usr/lib/xorg/Xorg :0 -seat seat0 -auth /var/run/lightdm/root/:0 -nolisten tcp vt7 -novtswitch