diff --git a/board/raspberrypi4/cleanups.sh b/board/raspberrypi4/cleanups.sh new file mode 120000 index 0000000000..d9a8ba25c5 --- /dev/null +++ b/board/raspberrypi4/cleanups.sh @@ -0,0 +1 @@ +../raspberrypi/cleanups.sh \ No newline at end of file diff --git a/board/raspberrypi4/cmdline.txt b/board/raspberrypi4/cmdline.txt new file mode 100644 index 0000000000..16d676103d --- /dev/null +++ b/board/raspberrypi4/cmdline.txt @@ -0,0 +1 @@ +dwc_otg.fiq_fix_enable=1 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 rootwait ro rootflags=noload panic=10 quiet loglevel=1 ipv6.disable=1 diff --git a/board/raspberrypi4/config.txt b/board/raspberrypi4/config.txt new file mode 100644 index 0000000000..b7f96a2ef7 --- /dev/null +++ b/board/raspberrypi4/config.txt @@ -0,0 +1,7 @@ +gpu_mem=128 + +dtparam=i2c_arm=on +dtparam=i2s=on +dtparam=spi=on +dtparam=audio=on + diff --git a/board/raspberrypi4/cpinitramfs.sh b/board/raspberrypi4/cpinitramfs.sh new file mode 120000 index 0000000000..be9760b343 --- /dev/null +++ b/board/raspberrypi4/cpinitramfs.sh @@ -0,0 +1 @@ +../raspberrypi/cpinitramfs.sh \ No newline at end of file diff --git a/board/raspberrypi4/initrd.gz b/board/raspberrypi4/initrd.gz new file mode 100644 index 0000000000..22060e53c9 Binary files /dev/null and b/board/raspberrypi4/initrd.gz differ diff --git a/board/raspberrypi4/mkimage.sh b/board/raspberrypi4/mkimage.sh new file mode 120000 index 0000000000..437f24e6f6 --- /dev/null +++ b/board/raspberrypi4/mkimage.sh @@ -0,0 +1 @@ +../raspberrypi/mkimage.sh \ No newline at end of file diff --git a/board/raspberrypi4/overlay/etc/board b/board/raspberrypi4/overlay/etc/board new file mode 100644 index 0000000000..976df614ed --- /dev/null +++ b/board/raspberrypi4/overlay/etc/board @@ -0,0 +1 @@ +raspberrypi4 diff --git a/board/raspberrypi4/overlay/etc/init.d/S05cpufreq b/board/raspberrypi4/overlay/etc/init.d/S05cpufreq new file mode 100755 index 0000000000..ed1d28f889 --- /dev/null +++ b/board/raspberrypi4/overlay/etc/init.d/S05cpufreq @@ -0,0 +1,37 @@ +#!/bin/bash + +GOV="ondemand" +CPUFREQDIR="/sys/devices/system/cpu/cpu0/cpufreq" +GOVDIR="/sys/devices/system/cpu/cpufreq/${GOV}" + + +test -n "${OS_VERSION}" || source /etc/init.d/base + +configure() { + echo ${GOV} > ${CPUFREQDIR}/scaling_governor + if [[ ${GOV} == "ondemand" ]]; then + echo 50 > ${GOVDIR}/up_threshold + echo 100000 > ${GOVDIR}/sampling_rate + echo 50 > ${GOVDIR}/sampling_down_factor + echo 1 > ${GOVDIR}/io_is_busy + fi +} + +case "$1" in + start) + msg_begin "Configuring CPU frequency" + configure + test $? == 0 && msg_done || msg_fail + ;; + + stop) + true + ;; + + *) + echo $"Usage: $0 {start}" + exit 1 +esac + +exit $? + diff --git a/board/raspberrypi4/overlay/etc/init.d/S11throttlewatch b/board/raspberrypi4/overlay/etc/init.d/S11throttlewatch new file mode 100755 index 0000000000..4f6a422152 --- /dev/null +++ b/board/raspberrypi4/overlay/etc/init.d/S11throttlewatch @@ -0,0 +1,65 @@ +#!/bin/bash + +CHECK_INTERVAL=30 + + +test -n "${OS_VERSION}" || source /etc/init.d/base + +get_throttled_now() { + t=$(vcgencmd get_throttled | cut -d '=' -f 2) + test $((t & 1)) -ne 0 && echo -n "under-voltage " + test $((t & 2)) -ne 0 && echo -n "arm-frequency-capped " + test $((t & 4)) -ne 0 && echo -n "throttled " +} + +get_throttled_since_boot() { + t=$(vcgencmd get_throttled | cut -d '=' -f 2) + test $((t & 65536)) -ne 0 && echo -n "under-voltage " + test $((t & 131072)) -ne 0 && echo -n "arm-frequency-capped " + test $((t & 262144)) -ne 0 && echo -n "throttled " +} + +watch_now() { + while true; do + t=$(get_throttled_now) + if [[ -n "${t}" ]]; then + logger -t throttlewatch -s "currently: ${t}" + fi + + sleep ${CHECK_INTERVAL} + done +} + +watch_since_boot() { + while true; do + t=$(get_throttled_since_boot) + if [[ -n "${t}" ]]; then + logger -t throttlewatch -s "since boot: ${t}" + break + fi + + sleep ${CHECK_INTERVAL} + done +} + +case "$1" in + start) + msg_begin "Starting throttle watcher" + watch_now & + watch_since_boot & + test $? == 0 && msg_done || msg_fail + ;; + + stop) + msg_begin "Stopping throttle watcher" + ps | grep throttlewatch | grep -v $$ | grep -v grep | tr -s ' ' | sed -e 's/^\s//' | cut -d ' ' -f 1 | xargs -r kill + test $? == 0 && msg_done || msg_fail + ;; + + *) + echo $"Usage: $0 {start|stop}" + exit 1 +esac + +exit $? + diff --git a/board/raspberrypi4/overlay/etc/init.d/S13btuart b/board/raspberrypi4/overlay/etc/init.d/S13btuart new file mode 100755 index 0000000000..0ad4deda81 --- /dev/null +++ b/board/raspberrypi4/overlay/etc/init.d/S13btuart @@ -0,0 +1,46 @@ +#!/bin/bash + +SYS_CONF="/etc/bluetooth.conf" +BOOT_CONF="/boot/bluetooth.conf" +CONF="/data/etc/bluetooth.conf" + + +test -f ${CONF} || test -f ${BOOT_CONF} || test -f ${SYS_CONF} || exit 0 + +test -d "/proc/device-tree/soc/gpio@7e200000/uart0_pins" || exit 0 # no rpi bluetooth detected + +test -n "${OS_VERSION}" || source /etc/init.d/base + +function start() { + if [[ "$(cat /proc/device-tree/aliases/uart0)" = "$(cat /proc/device-tree/aliases/serial1)" ]] ; then + if [[ "$(wc -c /proc/device-tree/soc/gpio@7e200000/uart0_pins/brcm\,pins | cut -f 1 -d ' ')" = " 16" ]] ; then + /usr/bin/hciattach -t5 /dev/serial1 bcm43xx 3000000 flow - &>/dev/null + else + /usr/bin/hciattach -t5 /dev/serial1 bcm43xx 921600 noflow - &>/dev/null + fi + else + /usr/bin/hciattach -t5 /dev/serial1 bcm43xx 460800 noflow - &>/dev/null + fi +} + +case "$1" in + start) + msg_begin "Attaching UART bluetooth modem" + # for some reason, sometimes the hciattach command needs to be run twice + (start || start) &>/dev/null & + msg_background + ;; + + stop) + msg_begin "Detaching UART bluetooth modem" + killall hciattach &>/dev/null + test $? == 0 && msg_done || msg_fail + ;; + + *) + echo $"Usage: $0 {start}" + exit 1 +esac + +exit $? + diff --git a/board/raspberrypi4/overlay/etc/init.d/boardsn b/board/raspberrypi4/overlay/etc/init.d/boardsn new file mode 100755 index 0000000000..16881c26f7 --- /dev/null +++ b/board/raspberrypi4/overlay/etc/init.d/boardsn @@ -0,0 +1,5 @@ +#!/bin/bash + +sn=$(cat /proc/cpuinfo | grep Serial | tr -d ' ' | cut -d ':' -f 2) +echo ${sn: -8} + diff --git a/board/raspberrypi4/overlay/etc/ld.so.preload b/board/raspberrypi4/overlay/etc/ld.so.preload new file mode 100644 index 0000000000..863162b676 --- /dev/null +++ b/board/raspberrypi4/overlay/etc/ld.so.preload @@ -0,0 +1 @@ +/usr/lib/libarmmem.so diff --git a/board/raspberrypi4/overlay/etc/modprobe.d/blacklist-rtl8192cu.conf b/board/raspberrypi4/overlay/etc/modprobe.d/blacklist-rtl8192cu.conf new file mode 100644 index 0000000000..dc07e99662 --- /dev/null +++ b/board/raspberrypi4/overlay/etc/modprobe.d/blacklist-rtl8192cu.conf @@ -0,0 +1 @@ +blacklist rtl8192cu diff --git a/board/raspberrypi4/overlay/etc/modules b/board/raspberrypi4/overlay/etc/modules new file mode 100644 index 0000000000..d5499e6362 --- /dev/null +++ b/board/raspberrypi4/overlay/etc/modules @@ -0,0 +1,3 @@ +i2c-bcm2708 +i2c-dev + diff --git a/board/raspberrypi4/overlay/etc/udev/rules.d/99-com.rules b/board/raspberrypi4/overlay/etc/udev/rules.d/99-com.rules new file mode 100644 index 0000000000..a964057230 --- /dev/null +++ b/board/raspberrypi4/overlay/etc/udev/rules.d/99-com.rules @@ -0,0 +1,32 @@ +SUBSYSTEM=="input", GROUP="input", MODE="0660" +SUBSYSTEM=="i2c-dev", GROUP="i2c", MODE="0660" +SUBSYSTEM=="spidev", GROUP="spi", MODE="0660" +SUBSYSTEM=="bcm2835-gpiomem", GROUP="gpio", MODE="0660" + +SUBSYSTEM=="gpio*", PROGRAM="/bin/sh -c '\ + chown -R root:gpio /sys/class/gpio && chmod -R 770 /sys/class/gpio;\ + chown -R root:gpio /sys/devices/virtual/gpio && chmod -R 770 /sys/devices/virtual/gpio;\ + chown -R root:gpio /sys$devpath && chmod -R 770 /sys$devpath\ +'" + +KERNEL=="ttyAMA[01]", PROGRAM="/bin/sh -c '\ + ALIASES=/proc/device-tree/aliases; \ + if cmp -s $ALIASES/uart0 $ALIASES/serial0; then \ + echo 0;\ + elif cmp -s $ALIASES/uart0 $ALIASES/serial1; then \ + echo 1; \ + else \ + exit 1; \ + fi\ +'", SYMLINK+="serial%c" + +KERNEL=="ttyS0", PROGRAM="/bin/sh -c '\ + ALIASES=/proc/device-tree/aliases; \ + if cmp -s $ALIASES/uart1 $ALIASES/serial0; then \ + echo 0; \ + elif cmp -s $ALIASES/uart1 $ALIASES/serial1; then \ + echo 1; \ + else \ + exit 1; \ + fi \ +'", SYMLINK+="serial%c" diff --git a/board/raspberrypi4/overlay/lib/firmware/BCM43430A1.hcd b/board/raspberrypi4/overlay/lib/firmware/BCM43430A1.hcd new file mode 100644 index 0000000000..162275ac0b Binary files /dev/null and b/board/raspberrypi4/overlay/lib/firmware/BCM43430A1.hcd differ diff --git a/board/raspberrypi4/overlay/usr/bin/hciattach b/board/raspberrypi4/overlay/usr/bin/hciattach new file mode 100755 index 0000000000..468a3342a6 Binary files /dev/null and b/board/raspberrypi4/overlay/usr/bin/hciattach differ diff --git a/board/raspberrypi4/overlay/usr/libexec/fw-prepare-boot b/board/raspberrypi4/overlay/usr/libexec/fw-prepare-boot new file mode 100755 index 0000000000..e372abdb87 --- /dev/null +++ b/board/raspberrypi4/overlay/usr/libexec/fw-prepare-boot @@ -0,0 +1,5 @@ +#!/bin/bash + +echo >> /boot/config.txt +echo "initramfs initrd.gz" >> /boot/config.txt + diff --git a/board/raspberrypi4/overlay/usr/libexec/fw-restore-boot-cfg b/board/raspberrypi4/overlay/usr/libexec/fw-restore-boot-cfg new file mode 100755 index 0000000000..a4cf5afe76 --- /dev/null +++ b/board/raspberrypi4/overlay/usr/libexec/fw-restore-boot-cfg @@ -0,0 +1,10 @@ +#!/bin/bash + +if [ -z "$1" ]; then + echo "Usage: $0 " 1>&2 + exit -1 +fi + +old_boot=$1 +cp ${old_boot}/config.txt /boot + diff --git a/board/raspberrypi4/postscript.sh b/board/raspberrypi4/postscript.sh new file mode 100755 index 0000000000..51e630b1d8 --- /dev/null +++ b/board/raspberrypi4/postscript.sh @@ -0,0 +1,14 @@ +#!/bin/sh + +set -e + +RPI_FW_DIR=${TARGET}/../images/rpi-firmware + +cp ${BOARD_DIR}/config.txt ${BOOT_DIR} +cp ${BOARD_DIR}/cmdline.txt ${BOOT_DIR} +cp ${BOARD_DIR}/initrd.gz ${BOOT_DIR} +cp ${IMG_DIR}/zImage ${BOOT_DIR}/kernel.img +cp ${IMG_DIR}/bcm2711-rpi-4-b.dtb ${BOOT_DIR} +cp ${RPI_FW_DIR}/bootcode.bin ${BOOT_DIR} +cp ${RPI_FW_DIR}/start4.elf ${BOOT_DIR} +cp ${RPI_FW_DIR}/fixup4.dat ${BOOT_DIR} diff --git a/configs/raspberrypi4_defconfig b/configs/raspberrypi4_defconfig new file mode 100644 index 0000000000..493cd0f637 --- /dev/null +++ b/configs/raspberrypi4_defconfig @@ -0,0 +1,80 @@ +BR2_arm=y +BR2_cortex_a7=y +BR2_ARM_FPU_NEON_VFPV4=y +BR2_CCACHE=y +BR2_CCACHE_DIR="$(TOPDIR)/.buildroot-ccache-raspberrypi4" +BR2_OPTIMIZE_2=y +BR2_TOOLCHAIN_EXTERNAL=y +BR2_TARGET_OPTIMIZATION="-pipe" +BR2_ROOTFS_DEVICE_CREATION_DYNAMIC_EUDEV=y +BR2_TARGET_TZ_INFO=y +BR2_ROOTFS_OVERLAY="board/common/overlay board/raspberrypi4/overlay" +BR2_ROOTFS_POST_BUILD_SCRIPT="board/common/postscript.sh" +BR2_LINUX_KERNEL=y +BR2_LINUX_KERNEL_CUSTOM_TARBALL=y +BR2_LINUX_KERNEL_CUSTOM_TARBALL_LOCATION="https://github.com/raspberrypi/linux/archive/6e787b87ace9f945f17a9022288e2758ed281cf7.tar.gz" +BR2_LINUX_KERNEL_DEFCONFIG="bcm2711" +BR2_LINUX_KERNEL_DTS_SUPPORT=y +BR2_LINUX_KERNEL_INTREE_DTS_NAME="bcm2711-rpi-4-b" +BR2_PACKAGE_BUSYBOX_CONFIG="board/common/busybox.config" +BR2_PACKAGE_BUSYBOX_SHOW_OTHERS=y +BR2_PACKAGE_ALSA_UTILS=y +BR2_PACKAGE_ALSA_UTILS_APLAY=y +BR2_PACKAGE_GZIP=y +BR2_PACKAGE_JQ=y +BR2_PACKAGE_E2FSPROGS=y +BR2_PACKAGE_NTFS_3G=y +BR2_PACKAGE_B43_FIRMWARE=y +BR2_PACKAGE_LINUX_FIRMWARE=y +BR2_PACKAGE_LINUX_FIRMWARE_ATHEROS_7010=y +BR2_PACKAGE_LINUX_FIRMWARE_ATHEROS_9170=y +BR2_PACKAGE_LINUX_FIRMWARE_ATHEROS_9271=y +BR2_PACKAGE_LINUX_FIRMWARE_BRCM_BCM43XX=y +BR2_PACKAGE_LINUX_FIRMWARE_BRCM_BCM43XXX=y +BR2_PACKAGE_LINUX_FIRMWARE_MWIFIEX_USB8797=y +BR2_PACKAGE_LINUX_FIRMWARE_MWIFIEX_USB8897=y +BR2_PACKAGE_LINUX_FIRMWARE_MEDIATEK_MT7601U=y +BR2_PACKAGE_LINUX_FIRMWARE_RALINK_RT61=y +BR2_PACKAGE_LINUX_FIRMWARE_RALINK_RT73=y +BR2_PACKAGE_LINUX_FIRMWARE_RALINK_RT2XX=y +BR2_PACKAGE_LINUX_FIRMWARE_RTL_81XX=y +BR2_PACKAGE_LINUX_FIRMWARE_RTL_87XX=y +BR2_PACKAGE_LINUX_FIRMWARE_RTL_88XX=y +BR2_PACKAGE_RPI_FIRMWARE=y +BR2_PACKAGE_RPI_FIRMWARE_X=y +BR2_PACKAGE_RPI_ARMMEM=y +BR2_PACKAGE_RPI_USERLAND=y +BR2_PACKAGE_USB_MODESWITCH_DATA=y +BR2_PACKAGE_CA_CERTIFICATES=y +BR2_PACKAGE_LIBSSH2=y +BR2_PACKAGE_LIBFUSE=y +BR2_PACKAGE_LIBCURL=y +BR2_PACKAGE_CURL=y +BR2_PACKAGE_LIBCAP=y +BR2_PACKAGE_PCRE=y +BR2_PACKAGE_PCRE_UCP=y +BR2_PACKAGE_AUTOSSH=y +BR2_PACKAGE_CRDA=y +BR2_PACKAGE_DHCP=y +BR2_PACKAGE_DHCP_CLIENT=y +# BR2_PACKAGE_IFUPDOWN_SCRIPTS is not set +BR2_PACKAGE_IPTABLES=y +BR2_PACKAGE_IW=y +BR2_PACKAGE_NETCAT=y +BR2_PACKAGE_NET_TOOLS=y +BR2_PACKAGE_NTP=y +BR2_PACKAGE_NTP_NTPDATE=y +BR2_PACKAGE_OPENSSH=y +BR2_PACKAGE_PPPD=y +BR2_PACKAGE_WIRELESS_TOOLS=y +BR2_PACKAGE_WPA_SUPPLICANT=y +BR2_PACKAGE_WPA_SUPPLICANT_AUTOSCAN=y +BR2_PACKAGE_WPA_SUPPLICANT_EAP=y +BR2_PACKAGE_WPA_SUPPLICANT_WPS=y +BR2_PACKAGE_WPA_SUPPLICANT_CLI=y +BR2_PACKAGE_BASH=y +BR2_PACKAGE_LOGROTATE=y +BR2_PACKAGE_TAR=y +BR2_PACKAGE_UTIL_LINUX_BINARIES=y +BR2_PACKAGE_UTIL_LINUX_PARTX=y +BR2_PACKAGE_NANO=y diff --git a/package/rpi-firmware/rpi-firmware.mk b/package/rpi-firmware/rpi-firmware.mk index 1cb7f1db69..2c79b82121 100644 --- a/package/rpi-firmware/rpi-firmware.mk +++ b/package/rpi-firmware/rpi-firmware.mk @@ -42,9 +42,17 @@ endef endif # INSTALL_VCDBG define RPI_FIRMWARE_INSTALL_IMAGES_CMDS + cp $(@D)/boot/fixup4cd.dat $(@D)/boot/fixup4_cd.dat + cp $(@D)/boot/fixup4x.dat $(@D)/boot/fixup4_x.dat + cp $(@D)/boot/fixup4db.dat $(@D)/boot/fixup4_db.dat + cp $(@D)/boot/start4cd.elf $(@D)/boot/start4_cd.elf + cp $(@D)/boot/start4x.elf $(@D)/boot/start4_x.elf + cp $(@D)/boot/start4db.elf $(@D)/boot/start4_db.elf $(INSTALL) -D -m 0644 $(@D)/boot/bootcode.bin $(BINARIES_DIR)/rpi-firmware/bootcode.bin $(INSTALL) -D -m 0644 $(@D)/boot/start$(BR2_PACKAGE_RPI_FIRMWARE_BOOT).elf $(BINARIES_DIR)/rpi-firmware/start.elf $(INSTALL) -D -m 0644 $(@D)/boot/fixup$(BR2_PACKAGE_RPI_FIRMWARE_BOOT).dat $(BINARIES_DIR)/rpi-firmware/fixup.dat + $(INSTALL) -D -m 0644 $(@D)/boot/start4$(BR2_PACKAGE_RPI_FIRMWARE_BOOT).elf $(BINARIES_DIR)/rpi-firmware/start4.elf + $(INSTALL) -D -m 0644 $(@D)/boot/fixup4$(BR2_PACKAGE_RPI_FIRMWARE_BOOT).dat $(BINARIES_DIR)/rpi-firmware/fixup4.dat $(INSTALL) -D -m 0644 package/rpi-firmware/config.txt $(BINARIES_DIR)/rpi-firmware/config.txt $(INSTALL) -D -m 0644 package/rpi-firmware/cmdline.txt $(BINARIES_DIR)/rpi-firmware/cmdline.txt $(RPI_FIRMWARE_INSTALL_DTB)