From 1b766e4974f6805cbe21e19a670bdc4400361355 Mon Sep 17 00:00:00 2001 From: Fabio Belavenuto Date: Fri, 22 Jul 2022 11:41:59 -0300 Subject: [PATCH] Docker: using DSM toolchain --- docker/Dockerfile.template | 15 ++--- docker/build.sh | 109 +++++++++++++++++++++++-------------- docker/files/opt/do.sh | 29 ++++++++-- 3 files changed, 96 insertions(+), 57 deletions(-) diff --git a/docker/Dockerfile.template b/docker/Dockerfile.template index 6cc03853..9f24c4d5 100644 --- a/docker/Dockerfile.template +++ b/docker/Dockerfile.template @@ -3,20 +3,17 @@ ARG PLATFORMS="@@@PLATFORMS@@@" ARG TOOLKIT_VER="@@@TOOLKIT_VER@@@" # Copy downloaded toolkits -ADD cache /cache +ADD cache/$TOOLKIT_VER /cache # Extract toolkits RUN for V in ${PLATFORMS}; do \ echo "${V}" | while IFS=':' read PLATFORM KVER; do \ + echo -e "${PLATFORM}\t${KVER}" >> /opt/platforms && \ echo "Extracting ds.${PLATFORM}-${TOOLKIT_VER}.dev.txz" && \ mkdir "/opt/${PLATFORM}" && \ - tar -xaf "/cache/ds.${PLATFORM}-${TOOLKIT_VER}.dev.txz" -C "/opt/${PLATFORM}" --strip-components=10 \ - "usr/local/x86_64-pc-linux-gnu/x86_64-pc-linux-gnu/sys-root/usr/lib/modules/DSM-${TOOLKIT_VER}/build" && \ - echo -e "${PLATFORM}\t${KVER}" >> /opt/platforms && \ - if [ ! -d "/opt/linux-${KVER}" ]; then \ - mkdir "/opt/linux-${KVER}" && \ - echo "Extracting linux-${KVER}.tar.xz" && \ - tar -xaf "/cache/linux-${KVER}.tar.xz" -C "/opt/linux-${KVER}" --strip-components=1; \ - fi; \ + tar -xaf "/cache/ds.${PLATFORM}-${TOOLKIT_VER}.dev.txz" -C "/opt/${PLATFORM}" --strip-components=9 \ + "usr/local/x86_64-pc-linux-gnu/x86_64-pc-linux-gnu/sys-root/usr/lib/modules/DSM-${TOOLKIT_VER}" && \ + echo "Extracting ${PLATFORM}-toolchain.txz" && \ + tar -xaf "/cache/${PLATFORM}-toolchain.txz" -C "/opt/${PLATFORM}" --strip-components=1; \ done; \ done diff --git a/docker/build.sh b/docker/build.sh index 9bd222a0..bc634f5f 100755 --- a/docker/build.sh +++ b/docker/build.sh @@ -6,50 +6,75 @@ function trap_cancel() { sleep 2 || exit 1 } trap trap_cancel SIGINT SIGTERM - cd `dirname $0` -# Read platforms/kerver version -echo "Reading platforms" -declare -A PLATFORMS -while read PLATFORM KVER; do - PLATFORMS[${PLATFORM}]="${KVER}" -done <../PLATFORMS +############################################################################### +function prepare() { + declare -A URLS -# Download toolkits -mkdir -p cache + URLS["apollolake"]="https://global.download.synology.com/download/ToolChain/toolchain/${TOOLCHAIN_VER}/Intel%20x86%20Linux%204.4.180%20%28Apollolake%29/apollolake-${GCCLIB_VER}_x86_64-GPL.txz" + URLS["broadwell"]="https://global.download.synology.com/download/ToolChain/toolchain/${TOOLCHAIN_VER}/Intel%20x86%20Linux%204.4.180%20%28Broadwell%29/broadwell-${GCCLIB_VER}_x86_64-GPL.txz" + URLS["broadwellnk"]="https://global.download.synology.com/download/ToolChain/toolchain/${TOOLCHAIN_VER}/Intel%20x86%20Linux%204.4.180%20%28Broadwellnk%29/broadwellnk-${GCCLIB_VER}_x86_64-GPL.txz" + URLS["bromolow"]="https://global.download.synology.com/download/ToolChain/toolchain/${TOOLCHAIN_VER}/Intel%20x86%20linux%203.10.108%20%28Bromolow%29/bromolow-${GCCLIB_VER}_x86_64-GPL.txz" + URLS["denverton"]="https://global.download.synology.com/download/ToolChain/toolchain/${TOOLCHAIN_VER}/Intel%20x86%20Linux%204.4.180%20%28Denverton%29/denverton-${GCCLIB_VER}_x86_64-GPL.txz" + URLS["geminilake"]="https://global.download.synology.com/download/ToolChain/toolchain/${TOOLCHAIN_VER}/Intel%20x86%20Linux%204.4.180%20%28GeminiLake%29/geminilake-${GCCLIB_VER}_x86_64-GPL.txz" + URLS["v1000"]="https://global.download.synology.com/download/ToolChain/toolchain/${TOOLCHAIN_VER}/Intel%20x86%20Linux%204.4.180%20%28V1000%29/v1000-${GCCLIB_VER}_x86_64-GPL.txz" + + # Read platforms/kerver version + echo "Reading platforms" + declare -A PLATFORMS + while read PLATFORM KVER; do + PLATFORMS[${PLATFORM}]="${KVER}" + done <../PLATFORMS + + # Download toolkits + mkdir -p cache + + for PLATFORM in ${!PLATFORMS[@]}; do + KVER="${PLATFORMS[${PLATFORM}]}" + echo -n "Checking cache/${TOOLKIT_VER}/ds.${PLATFORM}-${TOOLKIT_VER}.dev.txz... " + if [ ! -f "cache/${TOOLKIT_VER}/ds.${PLATFORM}-${TOOLKIT_VER}.dev.txz" ]; then + URL="https://global.download.synology.com/download/ToolChain/toolkit/${TOOLKIT_VER}/${PLATFORM}/ds.${PLATFORM}-${TOOLKIT_VER}.dev.txz" + echo "Downloading ${URL}" + curl -L "${URL}" -o "cache/${TOOLKIT_VER}/ds.${PLATFORM}-${TOOLKIT_VER}.dev.txz" + else + echo "OK" + fi + echo -n "Checking cache/${TOOLKIT_VER}/${PLATFORM}-toolchain.txz... " + if [ ! -f "cache/${TOOLKIT_VER}/${PLATFORM}-toolchain.txz" ]; then + URL=${URLS["${PLATFORM}"]} + echo "Downloading ${URL}" + curl -L "${URL}" -o "cache/${TOOLKIT_VER}/${PLATFORM}-toolchain.txz" + else + echo "OK" + fi + done + + # Generate Dockerfile + echo "Generating Dockerfile" + cp Dockerfile.template Dockerfile + VALUE="" + for PLATFORM in ${!PLATFORMS[@]}; do + VALUE+="${PLATFORM}:${PLATFORMS[${PLATFORM}]} " + done + sed -i "s|@@@PLATFORMS@@@|${VALUE::-1}|g" Dockerfile + sed -i "s|@@@TOOLKIT_VER@@@|${TOOLKIT_VER}|g" Dockerfile +} + +# 7.0 TOOLKIT_VER="7.0" -for PLATFORM in ${!PLATFORMS[@]}; do - KVER="${PLATFORMS[${PLATFORM}]}" - echo -n "Checking cache/ds.${PLATFORM}-${TOOLKIT_VER}.dev.txz... " - if [ ! -f "cache/ds.${PLATFORM}-${TOOLKIT_VER}.dev.txz" ]; then - URL="https://global.download.synology.com/download/ToolChain/toolkit/${TOOLKIT_VER}/${PLATFORM}/ds.${PLATFORM}-${TOOLKIT_VER}.dev.txz" - echo "Downloading ${URL}" - curl -L "${URL}" -o "cache/ds.${PLATFORM}-${TOOLKIT_VER}.dev.txz" - else - echo "OK" - fi - # echo -n "Checking cache/linux-${KVER}.tar.xz... " - # if [ ! -f "cache/linux-${KVER}.tar.xz" ]; then - # URL="https://cdn.kernel.org/pub/linux/kernel/v${KVER:0:1}.x/linux-${KVER}.tar.xz" - # echo "Downloading ${URL}" - # curl -L "${URL}" -o "cache/linux-${KVER}.tar.xz" - # else - # echo "OK" - # fi -done +TOOLCHAIN_VER="7.0-41890" +GCCLIB_VER="gcc750_glibc226" +prepare +echo "Building ${TOOLKIT_VER}" +docker image rm fbelavenuto/syno-compiler:${TOOLKIT_VER} >/dev/null 2>&1 +docker buildx build . --load --tag fbelavenuto/syno-compiler:${TOOLKIT_VER} -# Generate Dockerfile -echo "Generating Dockerfile" -cp Dockerfile.template Dockerfile -VALUE="" -for PLATFORM in ${!PLATFORMS[@]}; do - VALUE+="${PLATFORM}:${PLATFORMS[${PLATFORM}]} " -done -sed -i "s|@@@PLATFORMS@@@|${VALUE::-1}|g" Dockerfile -sed -i "s|@@@TOOLKIT_VER@@@|${TOOLKIT_VER}|g" Dockerfile - -# Build -echo "Building... Drink a coffee and wait!" -docker image rm fbelavenuto/syno-compiler >/dev/null 2>&1 -docker buildx build . --load --tag fbelavenuto/syno-compiler +# 7.1 +TOOLKIT_VER="7.1" +TOOLCHAIN_VER="7.1-42661" +GCCLIB_VER="gcc850_glibc226" +prepare +echo "Building ${TOOLKIT_VER}" +docker image rm fbelavenuto/syno-compiler:${TOOLKIT_VER} >/dev/null 2>&1 +docker buildx build . --load --tag fbelavenuto/syno-compiler:${TOOLKIT_VER} --tag fbelavenuto/syno-compiler:latest diff --git a/docker/files/opt/do.sh b/docker/files/opt/do.sh index 5bf77d47..08a3151e 100755 --- a/docker/files/opt/do.sh +++ b/docker/files/opt/do.sh @@ -2,6 +2,19 @@ set -e +function export-vars { + # Validate + if [ -z "${1}" ]; then + echo "Use: export-vars " + exit 1 + fi + export CROSS_COMPILE="/opt/${1}/bin/x86_64-pc-linux-gnu-" + export CFLAGS="-I/opt/${1}/include" + export LDFLAGS="-I/opt/${1}/lib" + export LD_LIBRARY_PATH="/opt/${1}/lib" + export ARCH=x86_64 +} + function compile-module { # Validate if [ -z "${1}" ]; then @@ -21,7 +34,9 @@ function compile-module { fi echo "Compiling module for ${PLATFORM}-${KVER}..." cp -R /input /tmp - make -C "/opt/${PLATFORM}" M="/tmp/input" ${PLATFORM^^}-Y=y ${PLATFORM^^}-M=m modules + export-vars ${PLATFORM} + make -C "/opt/${PLATFORM}/build" M="/tmp/input" \ + ${PLATFORM^^}-Y=y ${PLATFORM^^}-M=m modules while read F; do strip -g "${F}" echo "Copying `basename ${F}`" @@ -36,11 +51,13 @@ function compile-lkm { exit 1 fi cp -R /input /tmp - make -C "/tmp/input" LINUX_SRC="/opt/${PLATFORM}" dev-v7 + export-vars ${PLATFORM} + export LINUX_SRC="/opt/${PLATFORM}/build" + make -C "/tmp/input" dev-v7 strip -g "/tmp/input/redpill.ko" mv "/tmp/input/redpill.ko" "/output/redpill-dev.ko" - make -C "/tmp/input" LINUX_SRC="/opt/${PLATFORM}" clean - make -C "/tmp/input" LINUX_SRC="/opt/${PLATFORM}" prod-v7 + make -C "/tmp/input" clean + make -C "/tmp/input" prod-v7 strip -g "/tmp/input/redpill.ko" mv "/tmp/input/redpill.ko" "/output/redpill-prod.ko" } @@ -73,10 +90,10 @@ if [ $# -lt 1 ]; then exit 1 fi case $1 in - bash) shift; bash -l $@ ;; + bash) shift && bash -l $@ ;; + shell) export-vars $2 && shift 2 && bash -l $@ ;; compile-module) compile-module $2 ;; compile-lkm) compile-lkm $2 ;; # compile-drivers) compile-drivers ;; *) echo "Command not recognized: $1" ;; esac -