RaspberryPi-Joystick icon indicating copy to clipboard operation
RaspberryPi-Joystick copied to clipboard

Create IMG for easy distribution

Open gdsports opened this issue 3 years ago • 3 comments

The goal is to reduce the steps for the end user by creating an IMG file with all the changes specified in various README files. Perhaps one IMG for XAC BT and one for NSGamepad BT.

  • Create the ideal system with changes to usb_f_hid.ko, /etc/modules , /boot/config.txt, /etc/rc.local, etc.
  • Expire the pi password so it must be changed.
  • Remove SSH keys so they are regenerated?
  • Remove your SSID/PSK from /etc/wpa_supplicant.conf!
  • Shutdown and poweroff.
  • Mount the SD card on a Linux system as a data drive.
  • Shrink the ext4 partition using GParted.
  • Save the card image to an IMG file and zip it.

The end user instructions reduce to the following.

  • Download Raspberry Pi USB gadget BT zip file.
  • Unzip to extract IMG file created above.
  • Burn IMG to micro SD card.
  • An optional step is to customize WiFi SSID/PSK. Create wpa_supplicant.conf on the FAT32 partition with the desired SSID and PSK.
  • Plug SD Card into PiZW, Pi3A+, Pi4B, or Pi400.
  • Continue with instructions on BT pairing, etc.

It may be possible to run a shell script to create the ideal system instead of doing the steps by hand specified in the README files.

One interesting raspi-config option is the Overlay File System. This effectively makes the rootfs read-only so power off without shutdown will not corrupt the rootfs. Configuration files can be stored in the boot partition which is FAT32 so configuration options can be changed on Windows or Mac.

The following is an attempt at single script to create an ideal system but is currently incomplete.

#!/usr/bin/env bash
sudo apt update
sudo apt install -y python3-pip python3-gpiozero python3-evdev git

cd
git clone https://github.com/milador/RaspberryPi-Joystick
cd RaspberryPi-Joystick/NSGamepad

# Update system files to load the USB gadget drivers, if needed.
grep --quiet "^dtoverlay=dwc2$" /boot/config.txt
if [ $? -eq 1 ]
then
    echo "dtoverlay=dwc2" | sudo tee -a /boot/config.txt
fi
grep --quiet "^dwc2$" /etc/modules
if [ $? -eq 1 ]
then
    echo "dwc2" | sudo tee -a /etc/modules
fi
grep --quiet "^libcomposite$" /etc/modules
if [ $? -eq 1 ]
then
    echo "libcomposite" | sudo tee -a /etc/modules
fi

# Install USB NS gadget on boot
chmod +x ns_gamepad_usb
sudo cp ns_gamepad_usb /usr/bin/
# Insert line in /etc/rc.local, if needed
grep --quiet "^/usr/bin/ns_gamepad_usb$" /etc/rc.local
if [ $? -eq 1 ]
then
    sudo sed -i '/^exit 0/i \
/usr/bin/ns_gamepad_usb' /etc/rc.local
fi

# TBD Update usb_f_hid.ko files. This required for XAC but not NS.

# TBD Install service?

# TBD Expire pi account password?

# TBD Remove SSH keys?

# Remove my SSID/PSK
sudo rm /etc/wpa_supplicant/wpa_supplicant.conf

#sudo raspi-config overlay-file-system turn on???
echo "Powering off so an IMG can be created from this microSD card."
sleep 1
sudo poweroff

gdsports avatar Mar 05 '21 00:03 gdsports

This will be great! I am going to work on mapping options. in next few days so users can map mouse keys and keyboard keys using GUI. So is it possible to have users change key mappings through boot partition via Overlay File System as well? I am wondering if the mapping software should be on RPI or host (Windows or Mac)?

milador avatar Mar 06 '21 01:03 milador

The boot partition /boot is FAT32 so the overlay fs (read-only) does not apply. The overlay fs only applies to the Linux ext4 partition. This is the one that tends to get corrupted after repeated power off without shutdown. Keeping configuration files on the boot partition (/boot) should work because it will be writable. I think programs running on the RPi should be able to write to files in /boot so the mapping software could run on RPi.

gdsports avatar Mar 06 '21 08:03 gdsports

One problem occurred to me. Using overlayfs read-only means BT pairing will not be remembered across reboots/power cycles. I have no idea if the BT applet can save its config on /boot.

gdsports avatar Mar 06 '21 09:03 gdsports