From 59c681004b0f34d81aac15d7fd294225c51401fd Mon Sep 17 00:00:00 2001 From: Maurizio Porrato Date: Sat, 7 Aug 2021 17:08:16 +0100 Subject: [PATCH] Initial commit --- .gitignore | 1 + Config.in | 1 + LICENSE | 24 +++++++++ README.md | 53 +++++++++++++++++++ board/commander-pi16/post-build.sh | 34 ++++++++++++ .../rootfs_overlay/bin/start.sh | 31 +++++++++++ configs/cpi16_raspberrypi4_64_defconfig | 41 ++++++++++++++ configs/cpi16_raspberrypi_defconfig | 36 +++++++++++++ external.desc | 2 + external.mk | 1 + package/x16emu/Config.in | 11 ++++ package/x16emu/x16emu.mk | 28 ++++++++++ 12 files changed, 263 insertions(+) create mode 100644 .gitignore create mode 100644 Config.in create mode 100644 LICENSE create mode 100644 README.md create mode 100755 board/commander-pi16/post-build.sh create mode 100755 board/commander-pi16/rootfs_overlay/bin/start.sh create mode 100644 configs/cpi16_raspberrypi4_64_defconfig create mode 100644 configs/cpi16_raspberrypi_defconfig create mode 100644 external.desc create mode 100644 external.mk create mode 100644 package/x16emu/Config.in create mode 100644 package/x16emu/x16emu.mk diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3fb2c29 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*[~%] diff --git a/Config.in b/Config.in new file mode 100644 index 0000000..c34dd60 --- /dev/null +++ b/Config.in @@ -0,0 +1 @@ +source "$BR2_EXTERNAL_COMMANDER_PI16_PATH/package/x16emu/Config.in" diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..efb9808 --- /dev/null +++ b/LICENSE @@ -0,0 +1,24 @@ +This is free and unencumbered software released into the public domain. + +Anyone is free to copy, modify, publish, use, compile, sell, or +distribute this software, either in source code form or as a compiled +binary, for any purpose, commercial or non-commercial, and by any +means. + +In jurisdictions that recognize copyright laws, the author or authors +of this software dedicate any and all copyright interest in the +software to the public domain. We make this dedication for the benefit +of the public at large and to the detriment of our heirs and +successors. We intend this dedication to be an overt act of +relinquishment in perpetuity of all present and future rights to this +software under copyright law. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR +OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +OTHER DEALINGS IN THE SOFTWARE. + +For more information, please refer to diff --git a/README.md b/README.md new file mode 100644 index 0000000..20cfaab --- /dev/null +++ b/README.md @@ -0,0 +1,53 @@ +# Commander Pi16 + +This is a collection of buildroot scripts and configuration files that allow +you to create your own [Commander X16](https://www.commanderx16.com/) +emulation box based on the Raspberry Pi. + +What you will get **is not a baremetal emulator**: it is not a full Linux +distribution either but it still runs on top of the Linux kernel. + +The boot time is about 25s on a Raspberry Pi 4 from the firmware splashscreen +to the CX16 ready prompt. + +This is by no means a finished product: there is still a lot of work to do +in order to strip down the image to the bare minimum and to improve +performance, boot time and user experience. + + +## Building the bootable image + +On the first line below, you might want to use the mirror at +`https://github.com/buildroot/buildroot` instead of the official git repo at +busybox.net . + +``` +git clone https://git.busybox.net/buildroot +git clone $this_repo_location/commander-pi16 +cd buildroot +git checkout 2021.02.3 # Check out the latest stable release +# In the next command you need to pick the defconfig for your rpi version +# from the table in the next section. +make BR2_EXTERNAL=../commander-pi16 cpi16_raspberrypi_defconfig +make menuconfig # Only if you want to customise your build +make +``` + +This will take a while, especially the first time. Once the build is completed +you will find a file called `sdcard.img` in `output/images`. Just flash it to +an sd card using your favourite method. + +Before booting the rpi you will have to drop a ROM image compatible with the +current emulator version in the root of the FAT32 partition. The file must be +named `rom.bin`. + + +## Supported boards + +| Board | defconfig file | +|--------------------------|----------------------------------------| +| Raspberry Pi B+ | cpi16_raspberrypi_defconfig | +| Raspberry Pi4 B+ | cpi16_raspberrypi4_64_defconfig | + +Note: the Raspberry Pi B+ port is very slow, to the point of being barely +usable. diff --git a/board/commander-pi16/post-build.sh b/board/commander-pi16/post-build.sh new file mode 100755 index 0000000..523c101 --- /dev/null +++ b/board/commander-pi16/post-build.sh @@ -0,0 +1,34 @@ +#!/bin/sh + +set -u +set -e + +# Run x16emu on boot +if [ -e ${TARGET_DIR}/etc/inittab ]; then + grep -qE '^tty7::' ${TARGET_DIR}/etc/inittab || \ + sed -i '/HDMI console/a\ +tty7::respawn:/bin/start.sh # run x16emu' ${TARGET_DIR}/etc/inittab +fi + +configtxt="${BINARIES_DIR}/rpi-firmware/config.txt" + +for arg in "$@"; +do + case "${arg}" in + --enable-audio) + # Enable analog audio + if ! grep -qE '^dtparam=audio=' "${configtxt}"; then + echo "Adding 'dtparam=audio=on' to config.txt." + echo "dtparam=audio=on" >> "${configtxt}" + fi + ;; + --overlay=*) + # Add overlays + ovlline="dtoverlay=${arg:10}" + if ! grep -qE '^${ovlline}' "${configtxt}"; then + echo "Adding '${ovlline}' to config.txt." + echo "${ovlline}" >> "${configtxt}" + fi + ;; + esac +done diff --git a/board/commander-pi16/rootfs_overlay/bin/start.sh b/board/commander-pi16/rootfs_overlay/bin/start.sh new file mode 100755 index 0000000..fee4f98 --- /dev/null +++ b/board/commander-pi16/rootfs_overlay/bin/start.sh @@ -0,0 +1,31 @@ +#!/bin/sh + +fatmnt=/mnt +x16emu=/bin/x16emu +x16emuargs="" +rootlabel=rootfs + +workdir="${fatmnt}/x16" +romimage="${fatmnt}/rom.bin" +nvramimage="${fatmnt}/nvram.bin" + + +if ! mountpoint -q "${fatmnt}" ; then + rootdev=$(realpath /dev/disk/by-label/${rootlabel}) + fatdev="${rootdev%2}1" + [ -d "${fatmnt}" ] || mkdir -p "${fatmnt}" + mount "${fatdev}" "${fatmnt}" || exit 1 +fi + +if [ -f "${romimage}" ] ; then + mkdir -p "${workdir}" + ( + cd "${workdir}" + "${x16emu}" -rom "${romimage}" -nvram "${nvramimage}" ${x16emuargs} + ) +else + echo "Can't find rom.bin in the root directory of the sdcard." + while true ; do + sleep 60 + done +fi diff --git a/configs/cpi16_raspberrypi4_64_defconfig b/configs/cpi16_raspberrypi4_64_defconfig new file mode 100644 index 0000000..08452dc --- /dev/null +++ b/configs/cpi16_raspberrypi4_64_defconfig @@ -0,0 +1,41 @@ +BR2_aarch64=y +BR2_cortex_a72=y +BR2_ARM_FPU_VFPV4=y +BR2_SHARED_STATIC_LIBS=y +BR2_TOOLCHAIN_BUILDROOT_WCHAR=y +BR2_TOOLCHAIN_BUILDROOT_CXX=y +BR2_GCC_ENABLE_LTO=y +BR2_GCC_ENABLE_GRAPHITE=y +BR2_ROOTFS_DEVICE_CREATION_DYNAMIC_EUDEV=y +BR2_SYSTEM_DHCP="eth0" +BR2_ROOTFS_OVERLAY="$(BR2_EXTERNAL_COMMANDER_PI16_PATH)/board/commander-pi16/rootfs_overlay" +BR2_ROOTFS_POST_BUILD_SCRIPT="board/raspberrypi4-64/post-build.sh $(BR2_EXTERNAL_COMMANDER_PI16_PATH)/board/commander-pi16/post-build.sh" +BR2_ROOTFS_POST_IMAGE_SCRIPT="board/raspberrypi4-64/post-image.sh" +BR2_ROOTFS_POST_SCRIPT_ARGS="--add-miniuart-bt-overlay --aarch64 --enable-audio --overlay=vc4-kms-v3d-pi4 --overlay=rpivid-v4l2" +BR2_LINUX_KERNEL=y +BR2_LINUX_KERNEL_CUSTOM_TARBALL=y +BR2_LINUX_KERNEL_CUSTOM_TARBALL_LOCATION="$(call github,raspberrypi,linux,967d45b29ca2902f031b867809d72e3b3d623e7a)/linux-967d45b29ca2902f031b867809d72e3b3d623e7a.tar.gz" +BR2_LINUX_KERNEL_DEFCONFIG="bcm2711" +BR2_LINUX_KERNEL_DTS_SUPPORT=y +BR2_LINUX_KERNEL_INTREE_DTS_NAME="broadcom/bcm2711-rpi-4-b" +BR2_LINUX_KERNEL_NEEDS_HOST_OPENSSL=y +BR2_PACKAGE_ALSA_UTILS=y +BR2_PACKAGE_ALSA_UTILS_AMIXER=y +BR2_PACKAGE_MESA3D=y +BR2_PACKAGE_MESA3D_GALLIUM_DRIVER_KMSRO=y +BR2_PACKAGE_MESA3D_GALLIUM_DRIVER_V3D=y +BR2_PACKAGE_MESA3D_GALLIUM_DRIVER_VC4=y +BR2_PACKAGE_MESA3D_OPENGL_ES=y +BR2_PACKAGE_SDL2_KMSDRM=y +BR2_PACKAGE_SDL2_OPENGLES=y +BR2_PACKAGE_RPI_FIRMWARE=y +BR2_PACKAGE_RPI_FIRMWARE_VARIANT_PI4=y +BR2_PACKAGE_GIFLIB=y +BR2_TARGET_ROOTFS_EXT2=y +BR2_TARGET_ROOTFS_EXT2_4=y +BR2_TARGET_ROOTFS_EXT2_SIZE="120M" +# BR2_TARGET_ROOTFS_TAR is not set +BR2_PACKAGE_HOST_DOSFSTOOLS=y +BR2_PACKAGE_HOST_GENIMAGE=y +BR2_PACKAGE_HOST_MTOOLS=y +BR2_PACKAGE_X16EMU=y diff --git a/configs/cpi16_raspberrypi_defconfig b/configs/cpi16_raspberrypi_defconfig new file mode 100644 index 0000000..456aa61 --- /dev/null +++ b/configs/cpi16_raspberrypi_defconfig @@ -0,0 +1,36 @@ +BR2_arm=y +BR2_arm1176jzf_s=y +BR2_SHARED_STATIC_LIBS=y +BR2_TOOLCHAIN_BUILDROOT_WCHAR=y +BR2_TOOLCHAIN_BUILDROOT_CXX=y +BR2_GCC_ENABLE_LTO=y +BR2_ROOTFS_DEVICE_CREATION_DYNAMIC_EUDEV=y +BR2_SYSTEM_DHCP="eth0" +BR2_ROOTFS_OVERLAY="$(BR2_EXTERNAL_COMMANDER_PI16_PATH)/board/commander-pi16/rootfs_overlay" +BR2_ROOTFS_POST_BUILD_SCRIPT="board/raspberrypi/post-build.sh $(BR2_EXTERNAL_COMMANDER_PI16_PATH)/board/commander-pi16/post-build.sh" +BR2_ROOTFS_POST_IMAGE_SCRIPT="board/raspberrypi/post-image.sh" +BR2_ROOTFS_POST_SCRIPT_ARGS="--enable-audio" +BR2_LINUX_KERNEL=y +BR2_LINUX_KERNEL_CUSTOM_TARBALL=y +BR2_LINUX_KERNEL_CUSTOM_TARBALL_LOCATION="$(call github,raspberrypi,linux,967d45b29ca2902f031b867809d72e3b3d623e7a)/linux-967d45b29ca2902f031b867809d72e3b3d623e7a.tar.gz" +BR2_LINUX_KERNEL_DEFCONFIG="bcmrpi" +BR2_LINUX_KERNEL_DTS_SUPPORT=y +BR2_LINUX_KERNEL_INTREE_DTS_NAME="bcm2708-rpi-b bcm2708-rpi-b-plus bcm2708-rpi-cm" +BR2_LINUX_KERNEL_NEEDS_HOST_OPENSSL=y +BR2_PACKAGE_ALSA_UTILS=y +BR2_PACKAGE_ALSA_UTILS_AMIXER=y +BR2_PACKAGE_ALSA_UTILS_APLAY=y +BR2_PACKAGE_ALSA_UTILS_SPEAKER_TEST=y +BR2_PACKAGE_MADPLAY=y +BR2_PACKAGE_SDL2_OPENGLES=y +BR2_PACKAGE_RPI_FIRMWARE=y +# BR2_PACKAGE_RPI_FIRMWARE_INSTALL_DTB_OVERLAYS is not set +BR2_PACKAGE_RPI_USERLAND=y +BR2_TARGET_ROOTFS_EXT2=y +BR2_TARGET_ROOTFS_EXT2_4=y +BR2_TARGET_ROOTFS_EXT2_SIZE="120M" +# BR2_TARGET_ROOTFS_TAR is not set +BR2_PACKAGE_HOST_DOSFSTOOLS=y +BR2_PACKAGE_HOST_GENIMAGE=y +BR2_PACKAGE_HOST_MTOOLS=y +BR2_PACKAGE_X16EMU=y diff --git a/external.desc b/external.desc new file mode 100644 index 0000000..f857e2c --- /dev/null +++ b/external.desc @@ -0,0 +1,2 @@ +name: COMMANDER_PI16 +desc: Turn your Raspberry Pi into a Commander X16 diff --git a/external.mk b/external.mk new file mode 100644 index 0000000..2276264 --- /dev/null +++ b/external.mk @@ -0,0 +1 @@ +include $(sort $(wildcard $(BR2_EXTERNAL_COMMANDER_PI16_PATH)/package/*/*.mk)) diff --git a/package/x16emu/Config.in b/package/x16emu/Config.in new file mode 100644 index 0000000..253d145 --- /dev/null +++ b/package/x16emu/Config.in @@ -0,0 +1,11 @@ +config BR2_PACKAGE_X16EMU + bool "x16emu" + depends on !BR2_STATIC_LIBS # sdl2 + select BR2_PACKAGE_SDL2 + help + Emulator for the Commander X16 computer system. + + https://github.com/commanderx16/ + +comment "x16emu requires dynamic libraries" + depends on BR2_STATIC_LIBS diff --git a/package/x16emu/x16emu.mk b/package/x16emu/x16emu.mk new file mode 100644 index 0000000..a4d7feb --- /dev/null +++ b/package/x16emu/x16emu.mk @@ -0,0 +1,28 @@ +################################################################################ +# +# x16emu +# +################################################################################ + +X16EMU_VERSION = master +X16EMU_SITE = $(call github,commanderx16,x16-emulator,$(X16EMU_VERSION)) +X16EMU_LICENSE = BSD-2-Clause +X16EMU_LICENSE_FILES = LICENSE + +X16EMU_DEPENDENCIES = sdl2 + +X16EMU_CFLAGS = -std=c99 -O3 -g0 +X16EMU_CFLAGS += -I$(@D)/src/extern/include -I$(@D)/src/extern/src +X16EMU_CFLAGS += `$(STAGING_DIR)/usr/bin/sdl2-config --cflags` + +define X16EMU_BUILD_CMDS + $(TARGET_MAKE_ENV) $(MAKE) \ + CC="$(TARGET_CC)" \ + CFLAGS="$(TARGET_CFLAGS) $(X16EMU_CFLAGS)" -C $(@D) +endef + +define X16EMU_INSTALL_TARGET_CMDS + $(TARGET_MAKE_ENV) cp "$(@D)/x16emu" "$(TARGET_DIR)/bin/" +endef + +$(eval $(generic-package))