aboutsummaryrefslogtreecommitdiff
path: root/board
diff options
context:
space:
mode:
authorSébastien Dailly <sebastien@chimrod.com>2021-11-14 20:42:34 +0100
committerSébastien Dailly <sebastien@chimrod.com>2021-11-15 08:29:49 +0100
commit8f86f098b6ea868f8d98b4d26df8382dc4047c81 (patch)
tree1ef66b6243eb504b23d3739a47b923cc7d90f5c7 /board
Inital commit
Diffstat (limited to 'board')
-rw-r--r--board/common.sh8
-rw-r--r--board/genimage-raspberrypi0w.cfg31
-rw-r--r--board/genimage-raspberrypi3.cfg33
-rwxr-xr-xboard/post-build.sh114
-rwxr-xr-xboard/post-image.sh106
5 files changed, 292 insertions, 0 deletions
diff --git a/board/common.sh b/board/common.sh
new file mode 100644
index 0000000..ecda59d
--- /dev/null
+++ b/board/common.sh
@@ -0,0 +1,8 @@
+create_missing_dir() {
+ test -d "${TARGET_DIR}/$1" || mkdir "${TARGET_DIR}/$1"
+}
+
+remove_text() {
+ echo sed --in-place "s/$2//" $1
+ sed --in-place "s/$2//" $1
+}
diff --git a/board/genimage-raspberrypi0w.cfg b/board/genimage-raspberrypi0w.cfg
new file mode 100644
index 0000000..f76256e
--- /dev/null
+++ b/board/genimage-raspberrypi0w.cfg
@@ -0,0 +1,31 @@
+image boot.vfat {
+ vfat {
+ files = {
+ "bcm2708-rpi-zero-w.dtb",
+ "rpi-firmware/bootcode.bin",
+ "rpi-firmware/cmdline.txt",
+ "rpi-firmware/config.txt",
+ "rpi-firmware/fixup.dat",
+ "rpi-firmware/start.elf",
+ "rpi-firmware/overlays",
+ "zImage"
+ }
+ }
+ size = 32M
+}
+
+image sdcard.img {
+ hdimage {
+ }
+
+ partition boot {
+ partition-type = 0xC
+ bootable = "true"
+ image = "boot.vfat"
+ }
+
+ partition rootfs {
+ partition-type = 0x83
+ image = "rootfs.ext4"
+ }
+}
diff --git a/board/genimage-raspberrypi3.cfg b/board/genimage-raspberrypi3.cfg
new file mode 100644
index 0000000..0a54724
--- /dev/null
+++ b/board/genimage-raspberrypi3.cfg
@@ -0,0 +1,33 @@
+image boot.vfat {
+ vfat {
+ files = {
+ "bcm2710-rpi-3-b.dtb",
+ "bcm2710-rpi-3-b-plus.dtb",
+ "bcm2710-rpi-cm3.dtb",
+ "rpi-firmware/bootcode.bin",
+ "rpi-firmware/cmdline.txt",
+ "rpi-firmware/config.txt",
+ "rpi-firmware/fixup.dat",
+ "rpi-firmware/start.elf",
+ "rpi-firmware/overlays",
+ "zImage"
+ }
+ }
+ size = 32M
+}
+
+image sdcard.img {
+ hdimage {
+ }
+
+ partition boot {
+ partition-type = 0xC
+ bootable = "true"
+ image = "boot.vfat"
+ }
+
+ partition rootfs {
+ partition-type = 0x83
+ image = "rootfs.ext4"
+ }
+}
diff --git a/board/post-build.sh b/board/post-build.sh
new file mode 100755
index 0000000..6b1c86c
--- /dev/null
+++ b/board/post-build.sh
@@ -0,0 +1,114 @@
+#!/bin/sh
+
+set -u
+set -e
+
+. "${BR2_EXTERNAL_PIAUDIO_PATH}/board/common.sh"
+
+# Add a console on tty1
+if [ -e ${TARGET_DIR}/etc/inittab ]; then
+ grep -qE '^tty1::' ${TARGET_DIR}/etc/inittab || \
+ sed -i '/GENERIC_SERIAL/a\
+tty1::respawn:/sbin/getty -L tty1 0 vt100 # HDMI console' ${TARGET_DIR}/etc/inittab
+fi
+
+# Put the whole system in readonly
+sed -ie '/^\/dev\/root/ s/rw 0 1/ro 0 0/' "${TARGET_DIR}/etc/fstab"
+
+###########################
+# #
+# Network configuration #
+# #
+###########################
+
+# Add default wpa_supplicant.conf if it exists
+if [ -f "$BR2_EXTERNAL_PIAUDIO_PATH/wpa_supplicant.conf" ]; then
+ create_missing_dir "/etc/wpa_supplicant/"
+ cat "$BR2_EXTERNAL_PIAUDIO_PATH/wpa_supplicant.conf" > "${TARGET_DIR}/etc/wpa_supplicant/wpa_supplicant-wlan0.conf"
+
+
+ cat << __EOF__ > "${TARGET_DIR}/etc/systemd/network/wireless.network"
+[Match]
+Name=wlan0
+
+[Network]
+DHCP=yes
+__EOF__
+
+ # Create the link to interface wlan0 directly in the system configuration
+ ln -sf /usr/lib/systemd/system/wpa_supplicant@.service "${TARGET_DIR}/usr/lib/systemd/system/multi-user.target.wants/wpa_supplicant@wlan0.service"
+
+fi
+
+##############################
+# #
+# Pulseaudio configuration #
+# #
+##############################
+
+# Create the directory where pulseaudio store its files and put it in tempfs
+create_missing_dir "/var/lib/pulse"
+if ! grep -qE '/var/lib/pulse' "${TARGET_DIR}/etc/fstab"; then
+ cat << __EOF__ >> "${TARGET_DIR}/etc/fstab"
+tmpfs /var/lib/pulse tmpfs rw 0 0
+__EOF__
+fi
+
+if ! grep -qE '^load-module module-native-protocol-tcp' "${TARGET_DIR}/etc/pulse/system.pa"; then
+ cat << __EOF__ >> "${TARGET_DIR}/etc/pulse/system.pa"
+load-module module-bluetooth-policy
+load-module module-bluetooth-discover
+load-module module-native-protocol-tcp auth-ip-acl=127.0.0.1;192.168.0.0/24;2a01:e35:8ac8:0e00::/64 auth-anonymous=1
+__EOF__
+fi
+
+#############################
+# #
+# Bluetooth configuration #
+# #
+#############################
+
+create_missing_dir "/etc/bluetooth/"
+cat << __EOF__ > "${TARGET_DIR}/etc/bluetooth/main.conf"
+[General]
+
+Class = 200428
+DiscoverableTimeout = 0
+PairableTimeout = 0
+
+[Policy]
+AutoEnable=true
+__EOF__
+
+
+cat << __EOF__ > "${TARGET_DIR}/etc/systemd/system/bt-agent.service"
+[Unit]
+Description=Bluetooth Agent
+After=bluetooth.service
+Requires=bluetooth.service
+
+[Service]
+Type=simple
+ExecStartPre=bt-adapter --set Discoverable 1
+ExecStart=bt-agent -c NoInputNoOutput
+RestartSec=5
+Restart=always
+KillSignal=SIGUSR1
+
+[Install]
+WantedBy=bluetooth.target
+__EOF__
+
+# The same for the bluetooth, as bluetoothd keep a track for each paired device
+create_missing_dir "/var/lib/bluetooth/"
+if ! grep -qE '/var/lib/bluetooth' "${TARGET_DIR}/etc/fstab"; then
+ cat << __EOF__ >> "${TARGET_DIR}/etc/fstab"
+tmpfs /var/lib/bluetooth tmpfs rw 0 0
+__EOF__
+fi
+
+
+mkdir -p "${TARGET_DIR}"/etc/systemd/system/getty.target.wants
+# Add a console on ttyAMA0 and enable auto login
+ln -sf /usr/lib/systemd/system/serial-getty@.service "${TARGET_DIR}"/etc/systemd/system/getty.target.wants/serial-getty@ttyGS0.service
+sed '/^ExecStart=/ s/-o .-p -- ..u./--skip-login --noclear --noissue --login-options "-f root"/' -i "${TARGET_DIR}"/usr/lib/systemd/system/serial-getty@.service
diff --git a/board/post-image.sh b/board/post-image.sh
new file mode 100755
index 0000000..c7cc700
--- /dev/null
+++ b/board/post-image.sh
@@ -0,0 +1,106 @@
+#!/bin/bash
+
+set -e
+
+. "${BR2_EXTERNAL_PIAUDIO_PATH}/board/common.sh"
+
+BOARD_DIR="$(dirname $0)"
+GENIMAGE_CFG="${BOARD_DIR}/genimage-${BOARDNAME}.cfg"
+GENIMAGE_TMP="${BUILD_DIR}/genimage.tmp"
+
+for arg in "$@"
+do
+ case "${arg}" in
+ --add-miniuart-bt-overlay)
+ if ! grep -qE '^dtoverlay=' "${BINARIES_DIR}/rpi-firmware/config.txt"; then
+ echo "Adding 'dtoverlay=miniuart-bt' to config.txt (fixes ttyAMA0 serial console)."
+ cat << __EOF__ >> "${BINARIES_DIR}/rpi-firmware/config.txt"
+
+# fixes rpi (3B, 3B+, 3A+, 4B and Zero W) ttyAMA0 serial console
+dtoverlay=miniuart-bt
+__EOF__
+ fi
+ ;;
+ --aarch64)
+ # Run a 64bits kernel (armv8)
+ sed -e '/^kernel=/s,=.*,=Image,' -i "${BINARIES_DIR}/rpi-firmware/config.txt"
+ if ! grep -qE '^arm_64bit=1' "${BINARIES_DIR}/rpi-firmware/config.txt"; then
+ cat << __EOF__ >> "${BINARIES_DIR}/rpi-firmware/config.txt"
+
+# enable 64bits support
+arm_64bit=1
+__EOF__
+ fi
+ ;;
+ --gpu_mem_256=*|--gpu_mem_512=*|--gpu_mem_1024=*)
+ # Set GPU memory
+ gpu_mem="${arg:2}"
+ sed -e "/^${gpu_mem%=*}=/s,=.*,=${gpu_mem##*=}," -i "${BINARIES_DIR}/rpi-firmware/config.txt"
+ ;;
+
+ --configure-piaudio)
+ # Configure piaudio
+
+ # Set the bootloader delay to 0 seconds
+ if ! grep -qE '^boot_delay=0' "${BINARIES_DIR}/rpi-firmware/config.txt"; then
+ cat << __EOF__ >> "${BINARIES_DIR}/rpi-firmware/config.txt"
+boot_delay=0
+__EOF__
+ fi
+
+ # Set turbo mode for boot
+ if ! grep -qE '^initial_turbo' "${BINARIES_DIR}/rpi-firmware/config.txt"; then
+ cat << __EOF__ >> "${BINARIES_DIR}/rpi-firmware/config.txt"
+initial_turbo=10
+__EOF__
+ fi
+
+ # Inform the kernel about the filesystem and ro state
+ if ! grep -qE 'fastboot noswap ro' "${BINARIES_DIR}/rpi-firmware/cmdline.txt"; then
+ sed '/^root=/ s/$/ fastboot noswap ro/' -i "${BINARIES_DIR}/rpi-firmware/cmdline.txt"
+ fi
+
+ # Remove the serial console over the UART port and let it available for
+ # bluetooth
+ remove_text "${BINARIES_DIR}/rpi-firmware/cmdline.txt" "console=ttyAMA0,115200 "
+
+ if ! grep -qE '^dtoverlay=dwc2' "${BINARIES_DIR}/rpi-firmware/config.txt"; then
+
+
+ cat << __EOF__ >> "${BINARIES_DIR}/rpi-firmware/config.txt"
+dtoverlay=dwc2
+
+# https://github.com/raspberrypi/firmware/tree/master/boot/overlays
+dtparam=krnbt=on
+dtparam=i2c=on
+dtparam=audio=on
+dtoverlay=allo-boss-dac-pcm512x-audio
+__EOF__
+ fi
+
+ if ! grep -qE 'modules-load=dwc2,g_serial' "${BINARIES_DIR}/rpi-firmware/cmdline.txt"; then
+ sed '/^root=/ s/$/ modules-load=dwc2,g_serial/' -i "${BINARIES_DIR}/rpi-firmware/cmdline.txt"
+ fi
+ ;;
+ esac
+
+done
+
+# Pass an empty rootpath. genimage makes a full copy of the given rootpath to
+# ${GENIMAGE_TMP}/root so passing TARGET_DIR would be a waste of time and disk
+# space. We don't rely on genimage to build the rootfs image, just to insert a
+# pre-built one in the disk image.
+
+trap 'rm -rf "${ROOTPATH_TMP}"' EXIT
+ROOTPATH_TMP="$(mktemp -d)"
+
+rm -rf "${GENIMAGE_TMP}"
+
+genimage \
+ --rootpath "${ROOTPATH_TMP}" \
+ --tmppath "${GENIMAGE_TMP}" \
+ --inputpath "${BINARIES_DIR}" \
+ --outputpath "${BINARIES_DIR}" \
+ --config "${GENIMAGE_CFG}"
+
+exit $?