From 494269135b658d7bc061afdff8e213c8b256f31a Mon Sep 17 00:00:00 2001 From: Alex Somesan Date: Wed, 21 Sep 2022 13:18:49 +0200 Subject: [PATCH] * Overall refactoring * Update base image to Armbian buster * Enable support for MCP2515 CAN controller * Install SignalK, canboat, etc. --- .gitignore | 7 +- build-home-wifi.json | 47 -------- build.json | 71 ------------ build.pkr.hcl | 181 ++++++++++++++++++++++++++++++ provision/Hotspot.nmconnection | 24 ---- provision/build-from-src.sh | 20 ++-- provision/can0.ifconfig | 5 + provision/configure-hotspot.sh | 5 - provision/dt-overlays.sed | 2 +- provision/prepare-build.sh | 12 -- provision/reload-rtlmod.service | 11 ++ provision/signalk-service.service | 14 +++ provision/sun50i-h5-mcp2515.dts | 57 ++++++++++ 13 files changed, 282 insertions(+), 174 deletions(-) delete mode 100644 build-home-wifi.json delete mode 100644 build.json create mode 100644 build.pkr.hcl delete mode 100644 provision/Hotspot.nmconnection create mode 100644 provision/can0.ifconfig delete mode 100644 provision/configure-hotspot.sh delete mode 100644 provision/prepare-build.sh create mode 100644 provision/reload-rtlmod.service create mode 100644 provision/signalk-service.service create mode 100644 provision/sun50i-h5-mcp2515.dts diff --git a/.gitignore b/.gitignore index 370ae51..4fe7d6f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,3 @@ -Armbian*.img -armbian_first_run.txt -armbian_first_run.txt.template -armbianEnv.txt -armbianEnv.txt.template +*.img* +tmp output-arm-image/ \ No newline at end of file diff --git a/build-home-wifi.json b/build-home-wifi.json deleted file mode 100644 index a566049..0000000 --- a/build-home-wifi.json +++ /dev/null @@ -1,47 +0,0 @@ -{ - "variables": {}, - "builders": [ - { - "type": "arm-image", - "iso_url": "file://Armbian_5.91_Orangepizeroplus2-h5_Debian_buster_next_4.19.59.img", - "iso_checksum_type": "sha256", - "iso_checksum": "0b8ba0c74b98bc4f84fc861c57fb43fda3d64593350ee22884a387e5a5742738", - "target_image_size": 4294967296, - "image_mounts": [ - "/" - ] - } - ], - "provisioners": [ - { - "type": "file", - "source": "provision/blacklist-rtlsdr.conf", - "destination": "/etc/modprobe.d/blacklist-rtlsdr.conf", - "direction": "upload" - }, - { - "destination": "./armbian_first_run.txt.template", - "source": "/boot/armbian_first_run.txt.template", - "type": "file", - "direction": "download" - }, - { - "type": "shell-local", - "command": "sed -f provision/wifi-fr.sed armbian_first_run.txt" - }, - { - "source": "./armbian_first_run.txt", - "destination": "/boot/armbian_first_run.txt", - "type": "file", - "generated": true, - "direction": "upload" - }, - { - "type": "shell", - "scripts": [ - "provision/prepare-build.sh", - "provision/build-from-src.sh" - ] - } - ] -} diff --git a/build.json b/build.json deleted file mode 100644 index 89b391c..0000000 --- a/build.json +++ /dev/null @@ -1,71 +0,0 @@ -{ - "variables": {}, - "builders": [ - { - "type": "arm-image", - "iso_url": "file://Armbian_5.91_Orangepizeroplus2-h5_Debian_buster_next_4.19.59.img", - "iso_checksum_type": "sha256", - "iso_checksum": "0b8ba0c74b98bc4f84fc861c57fb43fda3d64593350ee22884a387e5a5742738", - "target_image_size": 15472787456, - "image_mounts": [ - "/" - ] - } - ], - "provisioners": [ - { - "destination": "./armbianEnv.txt.template", - "source": "/boot/armbianEnv.txt", - "type": "file", - "direction": "download" - }, - { - "type": "shell-local", - "command": "sed -f provision/dt-overlays.sed armbianEnv.txt" - }, - { - "source": "./armbianEnv.txt", - "destination": "/boot/armbianEnv.txt", - "type": "file", - "generated": true, - "direction": "upload" - }, - { - "type": "file", - "source": "provision/blacklist-rtlsdr.conf", - "destination": "/etc/modprobe.d/blacklist-rtlsdr.conf", - "direction": "upload" - }, - { - "type": "file", - "source": "provision/Hotspot.nmconnection", - "destination": "/etc/NetworkManager/system-connections/Hotspot.nmconnection", - "direction": "upload" - }, - { - "type": "file", - "source": "provision/kplex.conf", - "destination": "/etc/kplex.conf", - "direction": "upload" - }, - { - "type": "file", - "source": "provision/kplex.service", - "destination": "/etc/systemd/system/kplex.service", - "direction": "upload" - }, - { - "type": "file", - "source": "provision/rtl-ais.service", - "destination": "/etc/systemd/system/rtl-ais.service", - "direction": "upload" - }, - { - "type": "shell", - "scripts": [ - "provision/prepare-build.sh", - "provision/build-from-src.sh" - ] - } - ] -} diff --git a/build.pkr.hcl b/build.pkr.hcl new file mode 100644 index 0000000..71cdc64 --- /dev/null +++ b/build.pkr.hcl @@ -0,0 +1,181 @@ +variable "login_user" { + type = string + default = "alex" +} + +variable "login_pass" { + type = string + default = "daedalus" +} + +variable "local_ssh_public_key" { + type = string + default = "/home/alex/.ssh/id_rsa.pub" +} + +variable "root_pass" { + type = string + default = "daedalus" +} + +variable "output_img_size" { + type = number + default = 4 * 1024 * 1024 * 1024 +} + +variable "hotspot_dev" { + type = string + default = "wlan0" +} + +variable "hotspot_ssid" { + type = string + default = "Fenix" +} + +variable "hotspot_pass" { + type = string + default = "Macanache" +} + +locals { + image_home_dir = "/home/${var.login_user}" +} + +source "arm-image" "armbian" { + image_mounts = ["/"] + iso_checksum = "sha256:f43e88596e736f44d72ed7ad98de447405bf908739d5981fdb36293fd3e295ec" + iso_url = "https://armbian.hosthatch.com/archive/orangepizeroplus2-h5/archive/Armbian_21.08.1_Orangepizeroplus2-h5_buster_current_5.10.60.img.xz" + iso_target_path = "./Armbian.img" + qemu_binary = "qemu-aarch64-static" + target_image_size = var.output_img_size +} + +build { + sources = ["source.arm-image.armbian"] + + provisioner "shell" { + inline = [ + "rm -f /etc/systemd/system/getty@.service.d/override.conf", + "rm -f /etc/systemd/system/serial-getty@.service.d/override.conf", + "rm -r /root/.not_logged_in_yet", + "echo 'deb http://deb.debian.org/debian buster-backports main' > /etc/apt/sources.list.d/backports.list", + "curl -sL https://deb.nodesource.com/setup_16.x | bash -", + "apt-get --allow-releaseinfo-change update", + "apt-get upgrade -y", + "apt-get install -y build-essential cmake rustc-mozilla cargo-mozilla python3 python3-dev python3-pip python3-venv libffi-dev git libusb-1.0-0-dev pkg-config dnsmasq-base avahi-daemon tmux can-utils nodejs libnss-mdns avahi-utils libavahi-compat-libdnssd-dev xsltproc libxml2-utils", + "apt install -y -t buster-backports cockpit", + "npm install -g npm@latest", + "npm install -g signalk-server", + "/usr/sbin/useradd -m -r signalk", + "/usr/sbin/useradd -p '${var.login_pass}' -s /usr/bin/zsh -m ${var.login_user}", + "echo '${var.login_user} ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers", + "(echo '${var.root_pass}'; echo '${var.root_pass}';) | passwd root", + "mkdir -p /root/.ssh", + "/usr/sbin/usermod -s /usr/bin/zsh root" + ] + } + + provisioner "file" { + source = pathexpand(var.local_ssh_public_key) + destination = "/root/.ssh/authorized_keys" + } + + provisioner "file" { + direction = "download" + source = "/boot/armbianEnv.txt" + destination = "tmp/armbianEnv.txt.orig" + } + + provisioner "shell-local" { + command = "sed -f provision/dt-overlays.sed < tmp/armbianEnv.txt.orig > tmp/armbianEnv.txt" + } + + provisioner "file" { + direction = "upload" + generated = true + source = "tmp/armbianEnv.txt" + destination = "/boot/armbianEnv.txt" + } + + provisioner "file" { + direction = "upload" + source = "provision/blacklist-rtlsdr.conf" + destination = "/etc/modprobe.d/blacklist-rtlsdr.conf" + } + + provisioner "file" { + direction = "upload" + source = "provision/sun50i-h5-mcp2515.dts" + destination = "/root/sun50i-h5-mcp2515.dts" + } + + provisioner "file" { + direction = "upload" + source = "provision/kplex.conf" + destination = "/etc/kplex.conf" + } + + provisioner "file" { + direction = "upload" + source = "provision/can0.ifconfig" + destination = "/etc/network/interfaces.d/can0" + } + + provisioner "file" { + direction = "upload" + source = "provision/kplex.service" + destination = "/etc/systemd/system/kplex.service" + } + + provisioner "file" { + direction = "upload" + source = "provision/rtl-ais.service" + destination = "/etc/systemd/system/rtl-ais.service" + } + + provisioner "file" { + direction = "upload" + source = "provision/signalk-service.service" + destination = "/etc/systemd/system/signalk-service.service" + } + + provisioner "file" { + direction = "upload" + source = "provision/reload-rtlmod.service" + destination = "/etc/systemd/system/reload-rtlmod.service" + } + + provisioner "shell" { + inline = [ + "pip3 install -U pip", + "pip3 install -U setuptools", + "pip3 install -U wheel", + "pip3 install -U esptool", + ] + } + + provisioner "shell" { + inline = [ + "sudo armbian-add-overlay /root/sun50i-h5-mcp2515.dts", + # "systemctl enable rtl-ais.service", + # "systemctl enable kplex.service", + "systemctl enable signalk-service.service", + "systemctl enable reload-rtlmod.service", + "systemctl set-default multi-user.target", + ] + } + + provisioner "shell" { + inline = [ + # "nmcli con add type wifi ifname ${var.hotspot_dev} con-name Hostspot autoconnect yes ssid '${var.hotspot_ssid}' 802-11-wireless.mode ap ipv4.method shared wifi-sec.key-mgmt wpa-psk wifi-sec.psk '${var.hotspot_pass}'", + "", + ] + } + + provisioner "shell" { + scripts = [ + "provision/build-from-src.sh", + ] + } +} diff --git a/provision/Hotspot.nmconnection b/provision/Hotspot.nmconnection deleted file mode 100644 index eadb8f7..0000000 --- a/provision/Hotspot.nmconnection +++ /dev/null @@ -1,24 +0,0 @@ -[connection] -id=Hotspot -uuid=fac25b16-f5f1-4497-9b1d-0b73b68b6977 -type=wifi -interface-name=wlan0 -permissions= - -[wifi] -mac-address-blacklist= -mode=ap -ssid=Fenix - -[wifi-security] -key-mgmt=wpa-psk -psk=Macanache - -[ipv4] -dns-search= -method=shared - -[ipv6] -addr-gen-mode=stable-privacy -dns-search= -method=auto diff --git a/provision/build-from-src.sh b/provision/build-from-src.sh index 8782815..716508c 100644 --- a/provision/build-from-src.sh +++ b/provision/build-from-src.sh @@ -3,23 +3,25 @@ mkdir -p /tmp/build cd /tmp/build -wget -O kplex.zip https://github.com/stripydog/kplex/archive/master.zip -unzip kplex.zip -cd kplex-master +git clone --depth 1 https://github.com/stripydog/kplex.git +cd kplex make && make install cd .. -wget -O rtl-sdr.zip https://github.com/osmocom/rtl-sdr/archive/master.zip -unzip rtl-sdr.zip -cd rtl-sdr-master +git clone --depth 1 https://gitea.osmocom.org/sdr/rtl-sdr.git +cd rtl-sdr mkdir _build && cd _build cmake ../ -Wno-dev -DDETACH_KERNEL_DRIVER=ON -DINSTALL_UDEV_RULES=ON make install ldconfig cd .. -wget -O rtl-ais.zip https://github.com/dgiardini/rtl-ais/archive/master.zip -unzip rtl-ais.zip -cd rtl-ais-master +git clone --depth 1 https://github.com/dgiardini/rtl-ais.git +cd rtl-ais make && cp rtl_ais /usr/local/bin/ cd .. + +git clone --depth 1 https://github.com/canboat/canboat.git +# cd canboat +# make install +# cd .. diff --git a/provision/can0.ifconfig b/provision/can0.ifconfig new file mode 100644 index 0000000..3fa2c9a --- /dev/null +++ b/provision/can0.ifconfig @@ -0,0 +1,5 @@ +auto can0 +iface can0 inet manual + pre-up /sbin/ip link set can0 type can bitrate 250000 triple-sampling on restart-ms 100 + up /sbin/ifconfig can0 up + down /sbin/ifconfig can0 down \ No newline at end of file diff --git a/provision/configure-hotspot.sh b/provision/configure-hotspot.sh deleted file mode 100644 index 7f22b49..0000000 --- a/provision/configure-hotspot.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/sh - -systemctl start NetworkManager.service -nmcli con add type wifi ifname wlan0 con-name Hostspot autoconnect yes ssid "Fenix" 802-11-wireless.mode ap ipv4.method shared wifi-sec.key-mgmt wpa-psk wifi-sec.psk "Macanache" -nmcli con up Hostspot diff --git a/provision/dt-overlays.sed b/provision/dt-overlays.sed index ed72201..285ffa2 100644 --- a/provision/dt-overlays.sed +++ b/provision/dt-overlays.sed @@ -1 +1 @@ -s/^overlays=.*$/overlays=uart1 uart2 uart3 usbhost0 usbhost1 usbhost2 usbhost3/ \ No newline at end of file +s/^overlays=.*$/overlays=uart1 uart2 usbhost0 usbhost1 usbhost2 usbhost3/ \ No newline at end of file diff --git a/provision/prepare-build.sh b/provision/prepare-build.sh deleted file mode 100644 index 5f380fc..0000000 --- a/provision/prepare-build.sh +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/sh - -apt-get --allow-releaseinfo-change update -apt-get upgrade -y -apt-get install -y build-essential cmake python-pip git libusb-1.0-0-dev pkg-config dnsmasq-base avahi-daemon tmux -pip install setuptools -pip install esptool - -systemctl set-default multi-user.target -systemctl enable avahi-daemon.service -systemctl enable rtl-ais.service -systemctl enable kplex.service diff --git a/provision/reload-rtlmod.service b/provision/reload-rtlmod.service new file mode 100644 index 0000000..f7dd232 --- /dev/null +++ b/provision/reload-rtlmod.service @@ -0,0 +1,11 @@ +[Unit] +Description=Reload wifi modules +After=networking.service +Requires=networking.service + +[Service] +Type=oneshot +ExecStart=/usr/bin/sh -c "modprobe -r r8712u && modprobe r8712u" + +[Install] +WantedBy=multi-user.target \ No newline at end of file diff --git a/provision/signalk-service.service b/provision/signalk-service.service new file mode 100644 index 0000000..561d1c8 --- /dev/null +++ b/provision/signalk-service.service @@ -0,0 +1,14 @@ +[Unit] +Description=SignalK +After=network.target + +[Service] +Type=simple +Restart=always +RestartSec=10 +User=signalk +WorkingDirectory=/home/signalk +ExecStart=/usr/bin/signalk-server + +[Install] +WantedBy=multi-user.target diff --git a/provision/sun50i-h5-mcp2515.dts b/provision/sun50i-h5-mcp2515.dts new file mode 100644 index 0000000..817ae4e --- /dev/null +++ b/provision/sun50i-h5-mcp2515.dts @@ -0,0 +1,57 @@ +/dts-v1/; +/plugin/; + +/ { + compatible = "allwinner,sun50i-h5"; + + fragment@0 { + target-path = "/aliases"; + __overlay__ { + spi1 = "/soc/spi@1c69000"; + }; + }; + + fragment@1 { + target-path = "/clocks"; + __overlay__ { + #address-cells = <1>; + #size-cells = <1>; + can0_osc_fixed: can0_osc_fixed { + compatible = "fixed-clock"; + #clock-cells = <0>; + clock-frequency = <8000000>; + }; + }; + }; + + fragment@2 { + target = <&pio>; + __overlay__ { + can0_pin_irq: can0_pin_irq { + pins = "PA2"; + function = "irq"; + bias-pull-up; + }; + }; + }; + + fragment@3 { + target = <&spi1>; + __overlay__ { + #address-cells = <1>; + #size-cells = <0>; + status = "okay"; + can0:mcp2515@0 { + reg = <0>; + compatible = "microchip,mcp2515"; + pinctrl-names = "default"; + pinctrl-0 = <&can0_pin_irq>; + spi-max-frequency = <10000000>; + interrupt-parent = <&pio>; + interrupts = <0 2 8>; + clocks = <&can0_osc_fixed>; + status = "okay"; + }; + }; + }; +};