P4D

Hardware

Hummingboard i2eX

  • Humingboard i2eX
  • CPU: i.MX6 Dual 1GHz
  • GPU: GC2000 OpenGL ES1.1,2.0
  • RAM: 64bit 1Gb
  • NIC: 10/100/1000Mbps
  • 1x HDMI 1080p mit CEC
  • 1x Coax SPDIF
  • 2x USB2.0
  • 1x microSD
  • 1x mini PCI-E
  • 1x mSata
  • 1x Standard micro USB 5V DC
  • + sonstige Schnittstellen (SPI, … )

Aktuell

  • µSD: SanDisk 32GB SD-Karte
  • SSD: 512GB mSATA Cruical M550
  • WiFi: USB RTL8192EU
  • OneWire: DS18B20

Software

  • Arch Linux ARM

SD-Karte vorbereiten

# dd if=/dev/zero of=/dev/sdX bs=1M count=4
# fdisk /dev/sdX

Welcome to fdisk (util-linux 2.36.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Device does not contain a recognized partition table.
Created a new DOS disklabel with disk identifier 0xca7b0c11.

Command (m for help): p
Disk /dev/sde: 29,72 GiB, 31914983424 bytes, 62333952 sectors
Disk model: STORAGE DEVICE  
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0xca7b0c11

Command (m for help): n
Partition type
   p   primary (0 primary, 0 extended, 4 free)
   e   extended (container for logical partitions)
Select (default p): 

Using default response p.
Partition number (1-4, default 1): 
First sector (2048-62333951, default 2048): 
Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-62333951, default 62333951): 

Created a new partition 1 of type 'Linux' and of size 29,7 GiB.

Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.

# mkfs.ext4 -L P4D /dev/sdX1
# mkdir /mnt/p4d
# mount /dev/sdX1 /mnt/p4d
# cd /tmp
# wget http://archlinuxarm.org/os/ArchLinuxARM-armv7-latest.tar.gz
# wget http://archlinuxarm.org/armv7h/alarm/uboot-cubox-i-2017.01-1-armv7h.pkg.tar.xz
# tar -xpf ArchLinuxARM-armv7-latest.tar.gz -C /mnt/p4d && sync
# tar -xpf uboot-cubox-i-2017.01-1-armv7h.pkg.tar.xz -C /mnt/p4d/ boot/{boot.scr,SPL,u-boot.img} && sync
# dd if=/mnt/p4d/boot/SPL of=/dev/sdX bs=1K seek=1
# dd if=/mnt/p4d/boot/u-boot.img of=/dev/sdX bs=1K seek=69
# sync
# umount /mnt/p4d

System von der SD-Karte booten und als Benutzer alarm per ssh einloggen

  • Benutzer: alarm Passwort: alarm
  • Benutzer: root Passwort: root

zum Benutzer root wechseln

$ su

neue Passwörter für root und den Benutzer alarm setzen

# passwd
# passwd alarm

System aktualisieren

# pacman-key --init
# pacman-key --populate archlinuxarm
# pacman -Syu

Script zum Durchführen eines Chroot installieren

# pacman -S arch-install-scripts wget

Das aktualisierte System neustart

# reboot

wieder per ssh einloggen, mit den neu gesetzen Passwörtern

Arch Linux ARM auf die mSATA/SSD installieren

SSD vorbereiten

# fdisk /dev/sda

Welcome to fdisk (util-linux 2.36.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.


Command (m for help): o
Created a new DOS disklabel with disk identifier 0x9ad9c45c.

Command (m for help): n
Partition type
   p   primary (0 primary, 0 extended, 4 free)
   e   extended (container for logical partitions)
Select (default p): 

Using default response p.
Partition number (1-4, default 1): 
First sector (2048-1000215215, default 2048): 
Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-1000215215, default 1000215215): 

Created a new partition 1 of type 'Linux' and of size 476.9 GiB.

Command (m for help): w

The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.

Dateisystem ext4 anlegen

# mkfs.ext4 -L MSATA /dev/sda1

mke2fs 1.46.2 (28-Feb-2021)
Discarding device blocks: done                            
Creating filesystem with 125026646 4k blocks and 31260672 inodes
Filesystem UUID: 17288d69-bf81-4e28-9750-346c1c9fae4a
Superblock backups stored on blocks: 
	32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 
	4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968, 
	102400000
Allocating group tables: done                            
Writing inode tables: done                            
Creating journal (262144 blocks): done
Writing superblocks and filesystem accounting information: done     

ArchLinmuxARM-Image herunterladen

# cd /tmp
# wget http://archlinuxarm.org/os/ArchLinuxARM-armv7-latest.tar.gz

Partition auf der SSD unter /mnt einhängen

# mount /dev/sda1 /mnt

ArchLinuxARM-Image auf die mSATA kopieren

# tar -xpf ArchLinuxARM-armv7-latest.tar.gz -C /mnt/ && sync

Chroot in das Neu-Installierte System durchführen

# arch-chroot /mnt/

neue Passwörter für root und den Benutzer alarm setzen

# passwd
# passwd alarm

System aktualisieren

# pacman-key --init
# pacman-key --populate archlinuxarm
# pacman -Syu

die richtige Zeitzone setzen

# ln -sf /usr/share/zoneinfo/Europe/Berlin /etc/localtime

deutsches Tastaturlayout auf der Konsole einstellen

# echo KEYMAP=de-latin1 > /etc/vconsole.conf

die zu erzeugende Lokalisierungen (Systemsprache und Formatierung) festlegen

# nano /etc/locale.gen

/etc/locale.gen

de_DE.UTF-8 UTF-8
de_DE ISO-8859-1 
de_DE@euro ISO-8859-15

die Lokalisierung erzeugen

# locale-gen

Lokalisierung auf de_DE.UTF8 setzen

# echo LANG=de_DE.UTF8 > /etc/locale.conf

Hostname setzen

# echo p4d > /etc/hostname

Aktuelleres U-Boot installieren

mit der verfügbaren Version, kann das System nicht von der mSATA booten

# pacman -S arch-install-scripts base-devel bc git htop pacman-contrib python swig wget

von base-devel alles installieren

# su alarm
$ mkdir ~/workspace && cd ~/workspace
$ git clone https://github.com/archlinuxarm/PKGBUILDs.git
$ cd PKGBUILDs
$ git checkout -b i2ex
$ cd alarm/uboot-cubox-i
$ sed -i 's/pkgver=2017.01/pkgver=2021.01/' PKGBUILD
$ makepkg --skipchecksums
$ exit
# pacman -U uboot-cubox-i-2021.01-1-armv7h.pkg.tar.xz

U-Boot auf die SD-Karte spielen

# dd if=/boot/SPL of=/dev/mmcblk1 bs=1K seek=1
# dd if=/boot/u-boot.img of=/dev/mmcblk1 bs=1K seek=69

chroot wieder verlassen

# exit

System zwingen von der mSATA zu booten
dafür muss die Datei boot.scr im Verzeichnis /boot umbenannt werden
hiermit sucht das neuere U-Boot auch auf der mSATA nach der Datei boot.scr und startet von dieser

# mv /boot/boot.scr /boot/boot.org
# reboot

wieder per ssh einloggen, mit den neu gesetzen Passwörtern

Kontrollieren, ob von der mSATA gebootet wurde

# df -h

Ausgabe

Filesystem      Size  Used Avail Use% Mounted on
dev             459M     0  459M   0% /dev
run             495M  828K  494M   1% /run
/dev/sda1       469G  2.2G  443G   1% /          <= sda = SSD
tmpfs           495M     0  495M   0% /dev/shm
tmpfs           495M     0  495M   0% /tmp

p4d installieren

# pacman -S jansson libwebsockets mariadb
# su alarm
$ mkdir -p /home/alarm/workspace/linux-p4d && cd /home/alarm/workspace/linux-p4d
$ nano PKGBUILD

/home/alarm/workspace/linux-p4d/PKGBUILD

# Maintainer: milaw.biz
pkgname="linux-p4d"
pkgver=0.7.6
pkgrel=1
pkgdesc="fetching data from the S 3200 and store it in a MySQL database"
arch=('any')
url="https://github.com/horchi/linux-p4d"
license=('GPL')
depends=(
 'curl'
 'jansson'
 'libwebsockets'
 'libxml2'
 'mariadb'
 'openssl')
makedepends=(
 'git'
 'sed')
provides=('linux-p4d')
source=("linux-p4d::git+https://github.com/horchi/linux-p4d.git#tag=$pkgver")
md5sums=("SKIP")

prepare() {
 cd $srcdir/$pkgname
 sed -i 's/WEBOWNER      = www-data/WEBOWNER      = http/g' Make.config
 sed -i 's/DEBUG = 1/DEBUG = 0/g' Make.config
 sed -i 's/# LIBS += $(shell pkg-config --libs libwebsockets)/LIBS += $(shell pkg-config --libs libwebsockets)/g' Make.config
 sed -i 's/LIBS += $(shell pkg-config --libs-only-L libwebsockets)/#LIBS += $(shell pkg-config --libs-only-L libwebsockets)/g' Make.config
 sed -i 's/LIBS += -l:libwebsockets.a/#LIBS += -l:libwebsockets.a/g' Make.config
}

build() {
 cd $srcdir/$pkgname
 make
}

package() {
 cd $srcdir/$pkgname
 make DESTDIR="$pkgdir" install
}

linux-p4d bauen und installieren

$ makepkg
$ exit
# pacman -U linux-p4d-0.7.6-1-any.pkg.tar.xz

MariaDB einrichten

# mariadb-install-db --user=mysql --basedir=/usr --datadir=/var/lib/mysql
# systemctl start mariadb
# mysql -u root -Dmysql -p

Enter password:
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 3
Server version: 10.5.9-MariaDB Arch Linux

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [mysql]> CREATE DATABASE p4 charset utf8;
Query OK, 1 row affected (0.001 sec)

MariaDB [mysql]> CREATE USER 'p4'@'localhost' IDENTIFIED BY 'p4';
Query OK, 0 rows affected (0.008 sec)

MariaDB [mysql]> GRANT ALL PRIVILEGES ON p4.* TO 'p4'@'localhost' IDENTIFIED BY 'p4';
Query OK, 0 rows affected (0.006 sec)

MariaDB [mysql]> flush privileges;
Query OK, 0 rows affected (0.003 sec)

MariaDB [mysql]> exit
Bye

SQL-Dumps wiederherstellen (Optional)

Dumps aus der SQL-Datenbank (mittels dem Befehl p4d-backup erzeugt) liegen hier im Verzeichnis p4-dumps

# su alarm
$ find /home/alarm/p4-dumps -name "*.sql.gz" -type f -exec zcat {} \; | mysql -u p4 -pp4 -Dp4

P4D starten

# systemctl start p4d

MariaDB und P4D beim Systemstart mitstarten

# systemctl enable mariadb
# systemctl enable p4d

OneWire

DS18B20 am GPIO1 angeschlossen

$ mkdir -p workspace/w1-gpio-cl && cd workspace/w1-gpio-cl
$ nano PKGBUILD

/home/alarm/workspace/w1-gpio-cl/PKGBUILD

# Maintainer: milaw.biz
_pkgbase=w1-gpio-cl
pkgname=${_pkgbase}-dkms
pkgver=1.2.1
pkgrel=1
_commit=32e1bc8
pkgdesc="Command line configured gpio w1 bus master driver"
arch=('armv6' 'armv7h')
url=https://github.com/pstolarz/w1-gpio-cl
license=('GPL')
depends=('dkms')
makedepends=(
 'bc'
 'bison'
 'flex'
 'openssl'
 'git'
 'make')
source=("w1-gpio-cl::git+https://github.com/pstolarz/w1-gpio-cl.git#commit=$_commit")
md5sums=('SKIP')

package() {
  # Install dkms.conf
  install -dm755 "${pkgdir}/usr/src/${_pkgbase}-${pkgver}"
  cat > "${pkgdir}/usr/src/${_pkgbase}-${pkgver}/dkms.conf" << EOF
PACKAGE_NAME="${_pkgbase}"
PACKAGE_VERSION="${pkgver}"
MAKE[0]="make"
CLEAN="make clean"
BUILT_MODULE_NAME[0]="${_pkgbase}"
DEST_MODULE_LOCATION[0]="/kernel/drivers/w1"
AUTOINSTALL="yes"
EOF
  # Copy sources (including Makefile)
  cp -r ${_pkgbase}/* "${pkgdir}"/usr/src/${_pkgbase}-${pkgver}/
}

$ makepkg
$ su
# pacman -U w1-gpio-cl-dkms-1.2.1-1-armv7h.pkg.tar.xz

Modul laden

# modprobe w1-gpio-cl m1="gdt:1"

Temperatur auslesen

# cat /sys/bus/w1/devices/28-{ID}/temperature

Ausgabe

19375

bedeutet 19,375°C

Modul automatisch laden

# nano /etc/modules-load.d/w1-gpio-cl.conf

/etc/modules-load.d/w1-gpio-cl.conf

w1-gpio-cl

# nano /etc/modprobe.d/w1-gpio-cl.conf

/etc/modprobe.d/w1-gpio-cl.conf

options w1-gpio-cl m1="gdt:1"

Netzwerk

  • LAN - Schnittstelle eth0
  • WLAN - Schnittstelle wlan0

benötigte Software installieren

# pacman -S ifplugd wpa_supplicant

WLAN einrichten

# nano /etc/wpa_supplicant/wpa_supplicant-wlan0.conf

/etc/wpa_supplicant/wpa_supplicant-wlan0.conf

ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=wheel
update_config=1
network={
        ssid="SSID"
        psk="KEY"
        scan_ssid=1
        proto=RSN
        key_mgmt=WPA-PSK
        group=CCMP TKIP
        pairwise=CCMP TKIP
        priority=5
}

Metric für eth0 und wlan0 festlegen

# nano /etc/systemd/network/eth0.network

/etc/systemd/network/eth0.network

[Match]
Name=eth0

[Network]
DHCP=yes
DNSSEC=no

[DHCP]
RouteMetric=10

# nano /etc/systemd/network/wlan0.network

/etc/systemd/network/wlan0.network

[Match]
Name=wlan0

[Network]
DHCP=yes

[DHCP]
RouteMetric=20

Dienste beim Systemstart mitstarten

# systemctl enable ifplugd@eth0.service
# systemctl enable wpa_supplicant@wlan0.service