diff options
author | Sébastien Dailly <sebastien@chimrod.com> | 2021-11-14 20:42:34 +0100 |
---|---|---|
committer | Sébastien Dailly <sebastien@chimrod.com> | 2021-11-15 08:29:49 +0100 |
commit | 8f86f098b6ea868f8d98b4d26df8382dc4047c81 (patch) | |
tree | 1ef66b6243eb504b23d3739a47b923cc7d90f5c7 |
Inital commit
-rw-r--r-- | .gitignore | 3 | ||||
-rw-r--r-- | Config.in | 0 | ||||
-rw-r--r-- | board/common.sh | 8 | ||||
-rw-r--r-- | board/genimage-raspberrypi0w.cfg | 31 | ||||
-rw-r--r-- | board/genimage-raspberrypi3.cfg | 33 | ||||
-rwxr-xr-x | board/post-build.sh | 114 | ||||
-rwxr-xr-x | board/post-image.sh | 106 | ||||
-rwxr-xr-x | build.sh | 42 | ||||
-rw-r--r-- | configs/config | 118 | ||||
-rw-r--r-- | external.desc | 2 | ||||
-rw-r--r-- | external.mk | 1 | ||||
-rw-r--r-- | readme.rst | 82 |
12 files changed, 540 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ac3e8f2 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +wpa_supplicant.conf +output +configs/*_defconfig diff --git a/Config.in b/Config.in new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/Config.in 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 $? diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..7b61baa --- /dev/null +++ b/build.sh @@ -0,0 +1,42 @@ +#!/bin/sh +usage() { + echo "usage: BUILDROOT_DIR=${BUILDROOT_DIR} $0 {boardname} all" + echo + echo "with boardname in" + echo " - raspberrypi0w" + echo " - raspberrypi3" +} + +test -z ${BUILDROOT_DIR} && BUILDROOT_DIR=../buildroot + +if [ ! -d ${BUILDROOT_DIR} ]; then + usage + echo + echo "Error: the path to buildroot \"${BUILDROOT_DIR}\" does not exists" + exit 1 +fi + +export BOARDNAME=$1 + +case "$BOARDNAME" in + raspberrypi0w) + ;; + raspberrypi3) + ;; + *) + usage + echo + echo "Error: unknown card \"$1\"" + exit 1 + ;; +esac + +# Merge custom buildroot configurations +CONFIG_="BR2" KCONFIG_CONFIG="configs/${BOARDNAME}_defconfig" "$BUILDROOT_DIR/support/kconfig/merge_config.sh" -m -r "${BUILDROOT_DIR}/configs/${BOARDNAME}_defconfig" configs/config +sed "1i ### DO NOT EDIT, this file was automatically generated\n" -i "configs/${BOARDNAME}_defconfig" + +## Create full buildroot configuration +BR2_EXTERNAL="$(pwd)" make O="$(pwd)/output/$BOARDNAME" -C "$BUILDROOT_DIR" "${BOARDNAME}_defconfig" + +# Build +BR2_EXTERNAL="$(pwd)" make O="$(pwd)/output/${BOARDNAME}" -C ${BUILDROOT_DIR} "$2" diff --git a/configs/config b/configs/config new file mode 100644 index 0000000..6ff77e9 --- /dev/null +++ b/configs/config @@ -0,0 +1,118 @@ +BR2_HAVE_DOT_CONFIG=y +BR2_EXTERNAL_PIAUDIO_PATH="/home/sebastien/pi0/pi_audio" +BR2_NEEDS_HOST_UTF8_LOCALE=y +#BR2_DEFCONFIG="/home/sebastien/pi0/pi_audio/configs/raspberrypi3_defconfig" +#BR2_SSP_NONE=y +#BR2_RELRO_NONE=y +BR2_FORTIFY_SOURCE_NONE=y +BR2_TOOLCHAIN_USES_GLIBC=y +BR2_TOOLCHAIN_BUILDROOT_GLIBC=y +BR2_TOOLCHAIN_BUILDROOT_LIBC="glibc" +BR2_PACKAGE_GLIBC=y +BR2_USE_WCHAR=y +BR2_ENABLE_LOCALE=y +BR2_TARGET_GENERIC_HOSTNAME="piaudio" +BR2_TARGET_GENERIC_ISSUE="" +BR2_INIT_SYSTEMD=y +BR2_ROOTFS_MERGED_USR=y + +BR2_TARGET_ENABLE_ROOT_LOGIN=y +BR2_TARGET_GENERIC_ROOT_PASSWD="root" + +BR2_TARGET_GENERIC_REMOUNT_ROOTFS_RW=y +BR2_SYSTEM_DHCP="" +BR2_GENERATE_LOCALE="" +BR2_TARGET_TZ_INFO=y +BR2_TARGET_TZ_ZONELIST="default" +BR2_TARGET_LOCALTIME="Etc/UTC" +BR2_ROOTFS_POST_BUILD_SCRIPT="$(BR2_EXTERNAL_PIAUDIO_PATH)/board/post-build.sh" +BR2_ROOTFS_POST_IMAGE_SCRIPT="$(BR2_EXTERNAL_PIAUDIO_PATH)/board/post-image.sh" +BR2_ROOTFS_POST_SCRIPT_ARGS="--configure-piaudio" +BR2_PACKAGE_BUSYBOX_SHOW_OTHERS=y +BR2_PACKAGE_PROVIDES_SKELETON="skeleton-init-systemd" +BR2_PACKAGE_SKELETON_INIT_SYSTEMD=y +BR2_PACKAGE_ALSA_UTILS=y +BR2_PACKAGE_BLUEZ_ALSA_HCITOP=y +BR2_PACKAGE_BLUEZ_ALSA_RFCOMM=y +BR2_PACKAGE_PULSEAUDIO_ENABLE_ATOMIC=y +BR2_PACKAGE_PULSEAUDIO=y +BR2_PACKAGE_PULSEAUDIO_DAEMON=y +BR2_PACKAGE_SOX=y + +BR2_PACKAGE_LIBTOOL=y +BR2_PACKAGE_RPI_BT_FIRMWARE=y +BR2_PACKAGE_RPI_WIFI_FIRMWARE=y + +BR2_PACKAGE_DBUS=y +BR2_PACKAGE_DBUS_GLIB=y +BR2_PACKAGE_PROVIDES_UDEV="systemd" + +BR2_PACKAGE_ALSA_LIB=y +BR2_PACKAGE_ALSA_LIB_DEVDIR="/dev/snd" +BR2_PACKAGE_ALSA_LIB_PCM_PLUGINS="all" +BR2_PACKAGE_ALSA_LIB_CTL_PLUGINS="all" +BR2_PACKAGE_ALSA_LIB_ALOAD=y +BR2_PACKAGE_ALSA_LIB_MIXER=y +BR2_PACKAGE_ALSA_LIB_PCM=y +BR2_PACKAGE_ALSA_LIB_RAWMIDI=y +BR2_PACKAGE_ALSA_LIB_HWDEP=y +BR2_PACKAGE_ALSA_LIB_SEQ=y +BR2_PACKAGE_ALSA_LIB_UCM=y +BR2_PACKAGE_ALSA_LIB_ALISP=y +BR2_PACKAGE_ALSA_LIB_OLD_SYMBOLS=y + +BR2_PACKAGE_LIBSNDFILE=y + +BR2_PACKAGE_SBC=y +BR2_PACKAGE_SPEEX=y +BR2_PACKAGE_SPEEX_ARM5E=y + +BR2_PACKAGE_EXPAT=y + +BR2_PACKAGE_LIBOGG=y + +BR2_PACKAGE_LIBNL=y + +BR2_PACKAGE_BLUEZ_TOOLS=y +BR2_PACKAGE_BLUEZ5_UTILS=y +BR2_PACKAGE_BLUEZ5_UTILS_TOOLS=y +BR2_PACKAGE_BLUEZ5_UTILS_OBEX=y +BR2_PACKAGE_BLUEZ5_UTILS_CLIENT=y +BR2_PACKAGE_BLUEZ5_UTILS_DEPRECATED=y +BR2_PACKAGE_BLUEZ5_UTILS_PLUGINS_AUDIO=y +BR2_PACKAGE_BLUEZ5_UTILS_PLUGINS_NETWORK=y +BR2_PACKAGE_DHCPCD=y +BR2_PACKAGE_IFUPDOWN=y +BR2_PACKAGE_IPROUTE2=y +BR2_PACKAGE_IPTABLES=y + +BR2_PACKAGE_WPA_SUPPLICANT=y +BR2_PACKAGE_WPA_SUPPLICANT_NL80211=y +BR2_PACKAGE_WPA_SUPPLICANT_WPA3=y +BR2_PACKAGE_WPA_SUPPLICANT_CLI=y +BR2_PACKAGE_WPA_SUPPLICANT_CTRL_IFACE=y + +BR2_PACKAGE_KMOD=y +BR2_PACKAGE_KMOD_TOOLS=y +BR2_PACKAGE_SYSTEMD=y +BR2_PACKAGE_SYSTEMD_PSTORE=y +BR2_PACKAGE_SYSTEMD_HOSTNAMED=y +BR2_PACKAGE_SYSTEMD_HWDB=y +BR2_PACKAGE_SYSTEMD_MYHOSTNAME=y +BR2_PACKAGE_SYSTEMD_NETWORKD=y +BR2_PACKAGE_SYSTEMD_RESOLVED=y +BR2_PACKAGE_SYSTEMD_TIMEDATED=y +BR2_PACKAGE_SYSTEMD_TIMESYNCD=y +BR2_PACKAGE_SYSTEMD_TMPFILES=y +BR2_PACKAGE_SYSTEMD_VCONSOLE=y + +BR2_PACKAGE_UTIL_LINUX=y +BR2_PACKAGE_UTIL_LINUX_LIBS=y +BR2_PACKAGE_UTIL_LINUX_LIBBLKID=y +BR2_PACKAGE_UTIL_LINUX_LIBMOUNT=y +BR2_PACKAGE_UTIL_LINUX_LIBSMARTCOLS=y +BR2_PACKAGE_UTIL_LINUX_LIBUUID=y +BR2_PACKAGE_UTIL_LINUX_AGETTY=y +BR2_PACKAGE_UTIL_LINUX_FSCK=y +BR2_PACKAGE_UTIL_LINUX_MOUNT=y +BR2_PACKAGE_UTIL_LINUX_RFKILL=y diff --git a/external.desc b/external.desc new file mode 100644 index 0000000..308ab7d --- /dev/null +++ b/external.desc @@ -0,0 +1,2 @@ +name: PIAUDIO +desc: Sound server diff --git a/external.mk b/external.mk new file mode 100644 index 0000000..a1ebada --- /dev/null +++ b/external.mk @@ -0,0 +1 @@ +include $(sort $(wildcard $(BR2_EXTERNAL_PIAUDIO_PATH)/package/*/*.mk)) diff --git a/readme.rst b/readme.rst new file mode 100644 index 0000000..c1bf677 --- /dev/null +++ b/readme.rst @@ -0,0 +1,82 @@ +.. -*- mode: rst -*- +.. -*- coding: utf-8 -*- + +================================== +PIAudio : système pour raspberrypi +================================== + +Ce dépôt contient la configuration buildroot permettant de construire un +serveur de son avec un raspberrypi 0 ou raspberrypi 3. + +Le système ainsi créé est un système minimaliste avec un serveur pulseaudio +ouvert sur le réseau local, et un point d’accès audio bluetooth. + +Installation +============ + +Pré-requis +---------- + +Il est nécessaire d’installer `buildroot`_ et créer décompresser l’archive dans +un répertoire parent au dépôt. + +.. _buildroot: https://buildroot.org/ + +Copie du dépôt +-------------- + +.. code-block:: bash + + git clone https://git.chimrod.com/piaudio.git/ + +Configuration +------------- + +Tout est déjà configuré (ou presque…). Si l’on veut connecter la carte en wifi, +il faut créer un fichier `wpa_supplicant.conf` dans le dépôt avec le nom du +point d’accès et le mot de passe : + +:: + + ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev + update_config=1 + country=FR + + network={ + ssid="" + psk="" + } + +Construction +============ + +Lancer la commande suivante pour lancer l’image : + + +.. code-block:: bash + + # Construire l’image + ./build.sh raspberrypi0w all + + # Copier sur une clef USB : + sudo dd if=output/raspberrypi0w/images/sdcard.img of=/dev/XXX bs=4k + +L’image du système est d’environ 150Mo, n’importe quel carte SD devrait +fonctionner :) + +`raspberrypi0w` peut etre remplacé par `raspberrypi3` dans les commandes +ci-dessus pour cibler cette carte. + +Connexion +========= + +Le système est « briqué » dans le sens où il n’est pas possible de se connecter +à distance. Par contre, avec un raspberrypi0, il est possible d’ouvrir une +connexion locale en branchant le cable USB sur la prise USB du raspberry pi +(pas la prise d’alimentation), et en le connectant tel quel sur l’ordinateur. + +On peut ensuite s’y connecter avec la commande suivante : + +.. code-block:: bash + + screen /dev/ttyACM0 |