Initial commit

This commit is contained in:
Dale Whinham
2017-01-02 22:41:48 +00:00
commit a649e047d2
24 changed files with 1774 additions and 0 deletions

2
Config.in Normal file
View File

@@ -0,0 +1,2 @@
source "$BR2_EXTERNAL_MT32_PI_PATH/package/libmt32emu/Config.in"
source "$BR2_EXTERNAL_MT32_PI_PATH/package/mt32d/Config.in"

52
README.md Normal file
View File

@@ -0,0 +1,52 @@
# mt32-pi
A [Buildroot](https://buildroot.org) external tree which which turns your
Raspberry Pi 2 into a dedicated
[Roland MT-32](https://en.wikipedia.org/wiki/Roland_MT-32) emulator based on
[MUNT/libmt32em](https://github.com/munt/munt).
The aim is to have the Raspberry Pi boot into a working state in about 5
seconds.
## How to use it
* Check out this repo.
* Copy `MT32_CONTROL.ROM` and `MT32_PCM.ROM` to the `mt32-roms` folder
(you need to source these copyrighted ROMs yourself).
* Download and extract Buildroot 2016.11 or later.
* Build the system (this will take a long time):
cd /path/to/buildroot
make BR2_EXTERNAL=/path/to/this/repo raspberrypi2_defconfig
make
* After a successful build, an SD card image is located in
`output/images/sdcard.img`.
* Copy the image onto an SD card with `dd` (use the correct argument for
the device representing your SD card reader):
sudo dd if=output/images/sdcard.img of=/dev/sdc bs=1M
sync
* Place the SD card into the Raspberry Pi 2, attach a USB MIDI cable,
and enjoy!
## TODO
* There is some kind of delay in the handling of MIDI messages when many
messages arrive at once (more complex songs). Need to figure out what this
is being caused by (slow Pi USB MIDI? Would a GPIO MIDI interface be
better? Threading problem with `mt32d`?).
* Hardcoded to use (poor) internal sound and first USB MIDI device. Need to
script hotplugging things properly and select appropriate devices.
* Maybe try to use `PREEMPT_RT` kernel patch to see if it helps to get the
latency of `mt32d` down as low as possible with various audio devices.
N.B.: USB audio devices can achieve lower latency and superior sound
quality to the internal audio.
* Provide configurations for external LCD screens such as 3.2" touchscreens
and various character displays in order to allow the virtual MT-32 to
output messages and be controlled.
* Reduce initial build time and image size by disabling unnecessary kernel
modules.
* In relation to above, reduce startup time. There's a 2 second `sleep` while
we wait for the MIDI interfaces to come up before invoking `aconnect`; this
needs to go away. A 'release' build could also remove network/SSH as this
increases startup time.

View File

@@ -0,0 +1,32 @@
image boot.vfat {
vfat {
files = {
"bcm2708-rpi-b.dtb",
"bcm2708-rpi-b-plus.dtb",
"bcm2708-rpi-cm.dtb",
"rpi-firmware/bootcode.bin",
"rpi-firmware/cmdline.txt",
"rpi-firmware/config.txt",
"rpi-firmware/fixup.dat",
"rpi-firmware/start.elf",
"kernel-marked/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"
}
}

View File

@@ -0,0 +1,30 @@
image boot.vfat {
vfat {
files = {
"bcm2708-rpi-b-plus.dtb",
"rpi-firmware/bootcode.bin",
"rpi-firmware/cmdline.txt",
"rpi-firmware/config.txt",
"rpi-firmware/fixup.dat",
"rpi-firmware/start.elf",
"kernel-marked/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"
}
}

View File

@@ -0,0 +1,30 @@
image boot.vfat {
vfat {
files = {
"bcm2709-rpi-2-b.dtb",
"rpi-firmware/bootcode.bin",
"rpi-firmware/cmdline.txt",
"rpi-firmware/config.txt",
"rpi-firmware/fixup.dat",
"rpi-firmware/start.elf",
"kernel-marked/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"
}
}

View File

@@ -0,0 +1,31 @@
image boot.vfat {
vfat {
files = {
"bcm2710-rpi-3-b.dtb",
"rpi-firmware/bootcode.bin",
"rpi-firmware/cmdline.txt",
"rpi-firmware/config.txt",
"rpi-firmware/fixup.dat",
"rpi-firmware/start.elf",
"rpi-firmware/overlays",
"kernel-marked/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"
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,32 @@
#!/bin/sh
set -u
set -e
# 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
# Override Raspberry Pi config.txt
echo -n "Copying Raspberry Pi boot config..."
cp ${BR2_EXTERNAL_MT32_PI_PATH}/rpi-bootconfig.txt ${BINARIES_DIR}/rpi-firmware/config.txt
echo " OK!"
# Copy MT-32 ROMs into place
echo -n "Copying MT-32 ROMs..."
if [ ! -f ${BR2_EXTERNAL_MT32_PI_PATH}/mt32-roms/MT32_CONTROL.ROM ]; then
echo "\nMT32_CONTROL.ROM is missing. Please place it into the mt32-roms directory."
exit 1
fi
if [ ! -f ${BR2_EXTERNAL_MT32_PI_PATH}/mt32-roms/MT32_PCM.ROM ]; then
echo "\nMT32_PCM.ROM is missing. Please place it into the mt32-roms directory."
exit 1
fi
mkdir -p ${TARGET_DIR}/usr/share/mt32-rom-data
cp ${BR2_EXTERNAL_MT32_PI_PATH}/mt32-roms/*.ROM ${TARGET_DIR}/usr/share/mt32-rom-data/
echo " OK!"

View File

@@ -0,0 +1,35 @@
#!/bin/sh
BOARD_DIR="$(dirname $0)"
BOARD_NAME="$(basename ${BOARD_DIR})"
GENIMAGE_CFG="${BOARD_DIR}/genimage-${BOARD_NAME}.cfg"
GENIMAGE_TMP="${BUILD_DIR}/genimage.tmp"
case "${2}" in
--add-pi3-miniuart-bt-overlay)
if ! grep -qE '^dtoverlay=' "${BINARIES_DIR}/rpi-firmware/config.txt"; then
echo "Adding 'dtoverlay=pi3-miniuart-bt' to config.txt (fixes ttyAMA0 serial console)."
cat << __EOF__ >> "${BINARIES_DIR}/rpi-firmware/config.txt"
# fixes rpi3 ttyAMA0 serial console
dtoverlay=pi3-miniuart-bt
__EOF__
fi
;;
esac
# Mark the kernel as DT-enabled
mkdir -p "${BINARIES_DIR}/kernel-marked"
${HOST_DIR}/usr/bin/mkknlimg "${BINARIES_DIR}/zImage" \
"${BINARIES_DIR}/kernel-marked/zImage"
rm -rf "${GENIMAGE_TMP}"
genimage \
--rootpath "${TARGET_DIR}" \
--tmppath "${GENIMAGE_TMP}" \
--inputpath "${BINARIES_DIR}" \
--outputpath "${BINARIES_DIR}" \
--config "${GENIMAGE_CFG}"
exit $?

View File

@@ -0,0 +1,91 @@
Raspberry Pi
Intro
=====
These instructions apply to all models of the Raspberry Pi:
- the original models A and B,
- the "enhanced" models A+ and B+,
- the model B2 (aka Raspberry Pi 2)
- the model B3 (aka Raspberry Pi 3).
How to build it
===============
Configure Buildroot
-------------------
There are two RaspberryPi defconfig files in Buildroot, one for each
major variant, which you should base your work on:
For models A, B, A+ or B+:
$ make raspberrypi_defconfig
For model 2 B:
$ make raspberrypi2_defconfig
For model 3 B:
$ make raspberrypi3_defconfig
Build the rootfs
----------------
Note: you will need to have access to the network, since Buildroot will
download the packages' sources.
You may now build your rootfs with:
$ make
(This may take a while, consider getting yourself a coffee ;-) )
Result of the build
-------------------
After building, you should obtain this tree:
output/images/
+-- bcm2708-rpi-b.dtb [1]
+-- bcm2708-rpi-b-plus.dtb [1]
+-- bcm2709-rpi-2-b.dtb [1]
+-- bcm2710-rpi-3-b.dtb [1]
+-- boot.vfat
+-- kernel-marked/zImage [2]
+-- rootfs.ext4
+-- rpi-firmware/
| +-- bootcode.bin
| +-- cmdline.txt
| +-- config.txt
| +-- fixup.dat
| +-- start.elf
| `-- overlays/ [3]
+-- sdcard.img
`-- zImage
[1] Not all of them will be present, depending on the RaspberryPi
model you are using.
[2] This is the mkknlimg DT-marked kernel.
[3] Only for the Raspberry Pi 3 Model (overlay pi3-miniuart-bt is needed
to enable the RPi3 serial console otherwise occupied by the bluetooth
chip). Alternative would be to disable the serial console in cmdline.txt
and /etc/inittab.
How to write the SD card
========================
Once the build process is finished you will have an image called "sdcard.img"
in the output/images/ directory.
Copy the bootable "sdcard.img" onto an SD card with "dd":
$ sudo dd if=output/images/sdcard.img of=/dev/sdX
Insert the SDcard into your Raspberry Pi, and power it up. Your new system
should come up now and start two consoles: one on the serial port on
the P1 header, one on the HDMI output where you can login using a USB
keyboard.

View File

@@ -0,0 +1 @@
pi 8000 wheel -1 =pi /home/pi /bin/sh - Default user

View File

@@ -0,0 +1,46 @@
BR2_arm=y
BR2_cortex_a7=y
BR2_ARM_FPU_NEON_VFPV4=y
BR2_CCACHE=y
BR2_OPTIMIZE_3=y
BR2_TOOLCHAIN_BUILDROOT_GLIBC=y
BR2_PACKAGE_HOST_LINUX_HEADERS_CUSTOM_4_4=y
BR2_EXTRA_GCC_CONFIG_OPTIONS="--with-float=hard"
BR2_TOOLCHAIN_BUILDROOT_CXX=y
BR2_TARGET_OPTIMIZATION="-pipe -mfpu=vfpv4"
BR2_TARGET_GENERIC_HOSTNAME="mt32-pi"
BR2_TARGET_GENERIC_ISSUE="Welcome to MT-32 Pi!"
BR2_GENERATE_LOCALE="en_US"
BR2_ROOTFS_USERS_TABLES="${BR2_EXTERNAL_MT32_PI_PATH}/board/raspberrypi2/users.txt"
BR2_ROOTFS_OVERLAY="${BR2_EXTERNAL_MT32_PI_PATH}/fsoverlay"
BR2_ROOTFS_POST_BUILD_SCRIPT="${BR2_EXTERNAL_MT32_PI_PATH}/board/raspberrypi2/post-build.sh"
BR2_ROOTFS_POST_IMAGE_SCRIPT="${BR2_EXTERNAL_MT32_PI_PATH}/board/raspberrypi2/post-image.sh"
BR2_LINUX_KERNEL=y
BR2_LINUX_KERNEL_CUSTOM_GIT=y
BR2_LINUX_KERNEL_CUSTOM_REPO_URL="https://github.com/raspberrypi/linux.git"
BR2_LINUX_KERNEL_CUSTOM_REPO_VERSION="raspberrypi-kernel_1.20161020-1"
BR2_LINUX_KERNEL_PATCH="${BR2_EXTERNAL_MT32_PI_PATH}/board/raspberrypi2/patches/"
BR2_LINUX_KERNEL_USE_CUSTOM_CONFIG=y
BR2_LINUX_KERNEL_CUSTOM_CONFIG_FILE="${BR2_EXTERNAL_MT32_PI_PATH}/board/raspberrypi2/kernel.config"
BR2_LINUX_KERNEL_DTS_SUPPORT=y
BR2_LINUX_KERNEL_INTREE_DTS_NAME="bcm2709-rpi-2-b"
BR2_PACKAGE_ALSA_UTILS=y
BR2_PACKAGE_ALSA_UTILS_ALSACONF=y
BR2_PACKAGE_ALSA_UTILS_ACONNECT=y
BR2_PACKAGE_ALSA_UTILS_AMIDI=y
BR2_PACKAGE_ALSA_UTILS_AMIXER=y
BR2_PACKAGE_ALSA_UTILS_APLAY=y
BR2_PACKAGE_ALSA_UTILS_APLAYMIDI=y
BR2_PACKAGE_ALSA_UTILS_ASEQDUMP=y
BR2_PACKAGE_ALSA_UTILS_SPEAKER_TEST=y
BR2_PACKAGE_RPI_FIRMWARE=y
# BR2_PACKAGE_RPI_FIRMWARE_INSTALL_DTB_OVERLAYS is not set
BR2_PACKAGE_OPENSSH=y
BR2_TARGET_ROOTFS_EXT2=y
BR2_TARGET_ROOTFS_EXT2_4=y
# BR2_TARGET_ROOTFS_TAR is not set
BR2_PACKAGE_HOST_DOSFSTOOLS=y
BR2_PACKAGE_HOST_GENIMAGE=y
BR2_PACKAGE_HOST_MTOOLS=y
BR2_PACKAGE_LIBMT32EMU=y
BR2_PACKAGE_MT32D=y

2
external.desc Normal file
View File

@@ -0,0 +1,2 @@
name: MT32_PI
desc: An embedded, standalone Roland MT-32 emulator for the Raspberry Pi 2 based on MUNT.

1
external.mk Normal file
View File

@@ -0,0 +1 @@
include $(sort $(wildcard $(BR2_EXTERNAL_MT32_PI_PATH)/package/*/*.mk))

View File

@@ -0,0 +1,6 @@
#!/bin/sh
for cpu in /sys/devices/system/cpu/cpu[0-9]*
do
echo -n performance | tee $cpu/cpufreq/scaling_governor >/dev/null
done

View File

@@ -0,0 +1,5 @@
#!/bin/sh
modprobe snd-seq
modprobe snd-usb-audio index=1
modprobe snd-bcm2835

View File

@@ -0,0 +1,3 @@
#!/bin/sh
amixer cset numid=3 1

10
fsoverlay/etc/init.d/S17mt32d Executable file
View File

@@ -0,0 +1,10 @@
#!/bin/sh
# External USB soundcard is happy with lower buffer of 5 or so,
# but internal Pi sound device doesn't cope too well
mt32d -i 10 &
# This needs replacing with some kind of hotplug event handler to
# attach MIDI devices to MUNT
sleep 2
aconnect 20:0 128:0

1
mt32-roms/README.md Normal file
View File

@@ -0,0 +1 @@
Please place your MT32_CONTROL.ROM and MT32_PCM.ROM files here.

View File

@@ -0,0 +1,6 @@
config BR2_PACKAGE_LIBMT32EMU
bool "libmt32emu"
help
C/C++ library to emulate (approximately) the Roland MT-32, CM-32L and LAPC-I synthesiser modules.
http://github.com/munt/munt

View File

@@ -0,0 +1,13 @@
################################################################################
#
# libmt32emu
#
################################################################################
LIBMT32EMU_VERSION = 2.0.1
LIBMT32EMU_SOURCE = libmt32emu_2_0_1.tar.gz
LIBMT32EMU_SITE = https://github.com/munt/munt/archive
LIBMT32EMU_INSTALL_STAGING = YES
LIBMT32EMU_CONF_OPTS = -DCMAKE_VERBOSE_MAKEFILE=TRUE -DCMAKE_BUILD_TYPE=Release -Dmunt_WITH_MT32EMU_QT=FALSE -Dmunt_WITH_MT32EMU_SMF2WAV=FALSE
$(eval $(cmake-package))

7
package/mt32d/Config.in Normal file
View File

@@ -0,0 +1,7 @@
config BR2_PACKAGE_MT32D
bool "mt32d"
depends on BR2_PACKAGE_LIBMT32EMU
help
Daemon to emulate a Roland MT-32 synthesizer module.
http://github.com/munt/munt

25
package/mt32d/mt32d.mk Normal file
View File

@@ -0,0 +1,25 @@
################################################################################
#
# mt32d
#
################################################################################
MT32D_VERSION = 2.0.1
MT32D_SOURCE = libmt32emu_2_0_1.tar.gz
MT32D_SITE = https://github.com/munt/munt/archive
MT32D_INSTALL_STAGING = YES
MT32D_DEPENDENCIES = libmt32emu
define MT32D_BUILD_CMDS
$(MAKE) $(TARGET_CONFIGURE_OPTS) CXXFLAGS+="-DANALOG_MODE=2" -C $(@D)/mt32emu_alsadrv mt32d
endef
define MT32D_INSTALL_STAGING_CMDS
$(INSTALL) -D -m 0755 $(@D)/mt32emu_alsadrv/mt32d $(TARGET_DIR)/usr/bin/mt32d
endef
define MT32D_INSTALL_TARGET_CMDS
$(INSTALL) -D -m 0755 $(@D)/mt32emu_alsadrv/mt32d $(TARGET_DIR)/usr/bin/mt32d
endef
$(eval $(generic-package))

16
rpi-bootconfig.txt Normal file
View File

@@ -0,0 +1,16 @@
kernel=zImage
disable_overscan=1
disable_splash=1
boot_delay=0
dtparam=audio=on
dtparam=spi=on
arm_freq=900
arm_freq_min=300
gpu_mem=64
sdram_freq=500
core_freq=500
over_voltage=2
temp_limit=80
initial_turbo=30