From d420e08255da7a369e1063bc2354ef4c3191db78 Mon Sep 17 00:00:00 2001 From: Scott Duensing Date: Tue, 19 Dec 2023 20:54:18 -0600 Subject: [PATCH] Working Raspberry Pi support. --- cmake/aarch64-rpi3-linux-gnu.cmake | 48 ++++++++++++++++++++ cmake/apple-darwin-common.cmake | 19 ++------ cmake/armv6-rpi-linux-gnueabihf.cmake | 48 ++++++++++++++++++++ cmake/armv8-rpi3-linux-gnueabihf.cmake | 48 ++++++++++++++++++++ cmake/kangaroo-getconf.cmake | 35 +++++++++++++++ toolchains.sh | 62 ++++++++++++++++++++++++-- 6 files changed, 241 insertions(+), 19 deletions(-) create mode 100644 cmake/aarch64-rpi3-linux-gnu.cmake create mode 100644 cmake/armv6-rpi-linux-gnueabihf.cmake create mode 100644 cmake/armv8-rpi3-linux-gnueabihf.cmake create mode 100644 cmake/kangaroo-getconf.cmake diff --git a/cmake/aarch64-rpi3-linux-gnu.cmake b/cmake/aarch64-rpi3-linux-gnu.cmake new file mode 100644 index 0000000..1852d8f --- /dev/null +++ b/cmake/aarch64-rpi3-linux-gnu.cmake @@ -0,0 +1,48 @@ +# +# Kangaroo Punch Toolchains +# Copyright 2023-2024 Scott Duensing +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the “Software”), to +# deal in the Software without restriction, including without limitation the +# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +# sell copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# 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 OR COPYRIGHT HOLDERS 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. +# + + +include(${CMAKE_CURRENT_LIST_DIR}/kangaroo-getconf.cmake) + +kangaroo_getconf(SYSROOT) + +set(CMAKE_SYSTEM_NAME Linux) +set(CMAKE_SYSTEM_PROCESSOR aarch64) + +set(triple aarch64-rpi3-linux-gnu) + +set(CMAKE_C_COMPILER aarch64-rpi3-linux-gnu-gcc) +set(CMAKE_C_COMPILER_TARGET ${triple}) +set(CMAKE_CXX_COMPILER aarch64-rpi3-linux-gnu-c++) +set(CMAKE_CXX_COMPILER_TARGET ${triple}) + +#set(CMAKE_C_FLAGS "--sysroot ${SYSROOT}") +#set(CMAKE_CXX_FLAGS "--sysroot ${SYSROOT}") + +set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) +set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) +set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) +set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY) + +set(KANGAROO_OS pi) +set(KANGAROO_ARCH aarch64) diff --git a/cmake/apple-darwin-common.cmake b/cmake/apple-darwin-common.cmake index 9a11f72..841b4ee 100644 --- a/cmake/apple-darwin-common.cmake +++ b/cmake/apple-darwin-common.cmake @@ -22,22 +22,11 @@ # -macro(osxcross_getconf VAR) - if(NOT ${VAR}) - set(${VAR} "$ENV{${VAR}}") - if(${VAR}) - set(${VAR} "${${VAR}}" CACHE STRING "${VAR}") - message(STATUS "Found ${VAR}: ${${VAR}}") - else() - message(FATAL_ERROR "Cannot determine \"${VAR}\"") - endif() - endif() -endmacro() +include(${CMAKE_CURRENT_LIST_DIR}/kangaroo-getconf.cmake) - -osxcross_getconf(OSXCROSS_TARGET_DIR) -osxcross_getconf(OSXCROSS_TARGET) -osxcross_getconf(OSXCROSS_SDK) +kangaroo_getconf(OSXCROSS_TARGET_DIR) +kangaroo_getconf(OSXCROSS_TARGET) +kangaroo_getconf(OSXCROSS_SDK) set(OSXCROSS_LOCATION $ENV{OSXCROSS_LOCATION}) set(CMAKE_SYSTEM_NAME "Darwin") diff --git a/cmake/armv6-rpi-linux-gnueabihf.cmake b/cmake/armv6-rpi-linux-gnueabihf.cmake new file mode 100644 index 0000000..780810d --- /dev/null +++ b/cmake/armv6-rpi-linux-gnueabihf.cmake @@ -0,0 +1,48 @@ +# +# Kangaroo Punch Toolchains +# Copyright 2023-2024 Scott Duensing +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the “Software”), to +# deal in the Software without restriction, including without limitation the +# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +# sell copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# 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 OR COPYRIGHT HOLDERS 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. +# + + +include(${CMAKE_CURRENT_LIST_DIR}/kangaroo-getconf.cmake) + +kangaroo_getconf(SYSROOT) + +set(CMAKE_SYSTEM_NAME Linux) +set(CMAKE_SYSTEM_PROCESSOR armv6) + +set(triple armv6-rpi-linux-gnueabihf) + +set(CMAKE_C_COMPILER armv6-rpi-linux-gnueabihf-gcc) +set(CMAKE_C_COMPILER_TARGET ${triple}) +set(CMAKE_CXX_COMPILER armv6-rpi-linux-gnueabihf-c++) +set(CMAKE_CXX_COMPILER_TARGET ${triple}) + +#set(CMAKE_C_FLAGS "--sysroot ${SYSROOT}") +#set(CMAKE_CXX_FLAGS "--sysroot ${SYSROOT}") + +set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) +set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) +set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) +set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY) + +set(KANGAROO_OS pi) +set(KANGAROO_ARCH armv6) diff --git a/cmake/armv8-rpi3-linux-gnueabihf.cmake b/cmake/armv8-rpi3-linux-gnueabihf.cmake new file mode 100644 index 0000000..cd7d7eb --- /dev/null +++ b/cmake/armv8-rpi3-linux-gnueabihf.cmake @@ -0,0 +1,48 @@ +# +# Kangaroo Punch Toolchains +# Copyright 2023-2024 Scott Duensing +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the “Software”), to +# deal in the Software without restriction, including without limitation the +# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +# sell copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# 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 OR COPYRIGHT HOLDERS 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. +# + + +include(${CMAKE_CURRENT_LIST_DIR}/kangaroo-getconf.cmake) + +kangaroo_getconf(SYSROOT) + +set(CMAKE_SYSTEM_NAME Linux) +set(CMAKE_SYSTEM_PROCESSOR armv8) + +set(triple armv8-rpi3-linux-gnueabihf) + +set(CMAKE_C_COMPILER armv8-rpi3-linux-gnueabihf-gcc) +set(CMAKE_C_COMPILER_TARGET ${triple}) +set(CMAKE_CXX_COMPILER armv8-rpi3-linux-gnueabihf-c++) +set(CMAKE_CXX_COMPILER_TARGET ${triple}) + +#set(CMAKE_C_FLAGS "--sysroot ${SYSROOT}") +#set(CMAKE_CXX_FLAGS "--sysroot ${SYSROOT}") + +set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) +set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) +set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) +set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY) + +set(KANGAROO_OS pi) +set(KANGAROO_ARCH armv8) diff --git a/cmake/kangaroo-getconf.cmake b/cmake/kangaroo-getconf.cmake new file mode 100644 index 0000000..bcc970f --- /dev/null +++ b/cmake/kangaroo-getconf.cmake @@ -0,0 +1,35 @@ +# +# Kangaroo Punch Toolchains +# Copyright 2023-2024 Scott Duensing +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the “Software”), to +# deal in the Software without restriction, including without limitation the +# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +# sell copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# 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 OR COPYRIGHT HOLDERS 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. +# + + +macro(kangaroo_getconf VAR) + if(NOT ${VAR}) + set(${VAR} "$ENV{${VAR}}") + if(${VAR}) + set(${VAR} "${${VAR}}" CACHE STRING "${VAR}") + message(STATUS "Found ${VAR}: ${${VAR}}") + else() + message(FATAL_ERROR "Cannot determine \"${VAR}\"") + endif() + endif() +endmacro() diff --git a/toolchains.sh b/toolchains.sh index 89c8a69..49a7573 100755 --- a/toolchains.sh +++ b/toolchains.sh @@ -37,6 +37,8 @@ TC_G_SCRIPT=$(basename ${TC_G_SCRIPT_PATH}) TC_G_PIURL=https://github.com/tttapa/docker-arm-cross-toolchain/releases/latest/download/x-tools- +TC_G_PI64=https://downloads.raspberrypi.com/raspios_lite_arm64/images/raspios_lite_arm64-2023-12-11/2023-12-11-raspios-bookworm-arm64-lite.img.xz +TC_G_PI32=https://downloads.raspberrypi.com/raspios_lite_armhf/images/raspios_lite_armhf-2023-12-11/2023-12-11-raspios-bookworm-armhf-lite.img.xz function buildMacOSXToolchain() { @@ -113,6 +115,49 @@ NO_GCC } +function build_pi_sysroot() { + local BITS=$1 + local OS= + local IMAGE= + local START= + local SYSROOT=../x-tools/sysroot-pi${BITS} + + mkdir -p work + pushd work + if [[ ! -f sysroot-relativelinks.py ]]; then + wget https://raw.githubusercontent.com/riscv/riscv-poky/master/scripts/sysroot-relativelinks.py + fi + if [[ "${BITS}" == "64" ]]; then + OS=${TC_G_PI64} + else + OS=${TC_G_PI32} + fi + IMAGE=$(basename ${OS}) + if [[ ! -f $(basename ${OS} .xz) ]]; then + wget ${OS} + unxz ${IMAGE} + fi + IMAGE=$(basename ${IMAGE} .xz) + START=$(fdisk -l ${IMAGE} | grep Linux | awk '{ print $2 }') + START=$(( 512 * START )) + mkdir -p ${SYSROOT} + mkdir -p mnt + sudo mount -t ext4 -o loop,offset=${START} ${IMAGE} mnt + rsync -avz mnt/* ${SYSROOT} || true + #rsync -avz mnt/lib ${SYSROOT} + #rsync -avz mnt/usr/include ${SYSROOT}/usr + #rsync -avz mnt/usr/lib ${SYSROOT}/usr + sudo umount mnt + python3 ./sysroot-relativelinks.py ${SYSROOT} + if [[ "${BITS}" == "64" ]]; then + cp -f $(which qemu-aarch64-static) ${SYSROOT}/usr/bin/. + else + cp -f $(which qemu-arm-static) ${SYSROOT}/usr/bin/. + fi + popd +} + + function install_x86_64_linux() { # Required tools for Linux x86_64. These should always be installed. sudo apt-get install -y \ @@ -159,22 +204,22 @@ function install_x86_windows() { function install_aarch64_pi() { # Raspberry Pi, aarch64. - wget -O- ${TC_G_PIURL}aarch64-rpi3-linux-gnu.tar.xz | tar xJ - #***TODO*** sysroot +# wget -O- ${TC_G_PIURL}aarch64-rpi3-linux-gnu.tar.xz | tar xJ + build_pi_sysroot 64 } function install_armv6_pi() { # Raspberry Pi, armv6. wget -O- ${TC_G_PIURL}armv6-rpi-linux-gnueabihf.tar.xz | tar xJ - #***TODO*** sysroot + build_pi_sysroot 32 } function install_armv8_pi() { # Raspberry Pi, armv8. wget -O- ${TC_G_PIURL}armv8-rpi3-linux-gnueabihf.tar.xz | tar xJ - #***TODO*** sysroot + build_pi_sysroot 32 } @@ -268,12 +313,15 @@ function use_toolchain() { case "${ARCH}" in aarch64) TRIPLE="aarch64-rpi3-linux-gnu" + echo "export SYSROOT=${TC_G_SCRIPT_DIR}/x-tools/sysroot-pi64" ;; armv6) TRIPLE="armv6-rpi-linux-gnueabihf" + echo "export SYSROOT=${TC_G_SCRIPT_DIR}/x-tools/sysroot-pi64" ;; armv8) TRIPLE="armv8-rpi3-linux-gnueabihf" + echo "export SYSROOT=${TC_G_SCRIPT_DIR}/x-tools/sysroot-pi64" ;; esac CROSS_OS="linux" @@ -320,6 +368,7 @@ COLS=2 ROWS=11 row=0 declare -A PLATFORMS=() +# List of ARCHs List of PLATs PLATFORMS[0]="x86_64"; PLATFORMS[1]="linux" PLATFORMS[2]="x86"; PLATFORMS[3]="linux" PLATFORMS[4]="x86_64"; PLATFORMS[5]="windows" @@ -333,6 +382,11 @@ PLATFORMS[18]="aarch64"; PLATFORMS[19]="macos" PLATFORMS[20]="x86"; PLATFORMS[21]="dos" if [[ "${MODE}" == "install" ]]; then + # We need some more packages for Pi work. + if [[ "${PLAT}" == "pi" ]]; then + sudo apt-get -y install qemu-user-static + fi + # Install all toolchains. if [[ "${ARCH}" == "all" && "${PLAT}" == "all" ]]; then HELP=0