Docker: using DSM toolchain

This commit is contained in:
Fabio Belavenuto 2022-07-22 11:41:59 -03:00
parent 13ecf8108d
commit c7a569e4d6
3 changed files with 96 additions and 57 deletions

View File

@ -3,20 +3,17 @@ ARG PLATFORMS="@@@PLATFORMS@@@"
ARG TOOLKIT_VER="@@@TOOLKIT_VER@@@" ARG TOOLKIT_VER="@@@TOOLKIT_VER@@@"
# Copy downloaded toolkits # Copy downloaded toolkits
ADD cache /cache ADD cache/$TOOLKIT_VER /cache
# Extract toolkits # Extract toolkits
RUN for V in ${PLATFORMS}; do \ RUN for V in ${PLATFORMS}; do \
echo "${V}" | while IFS=':' read PLATFORM KVER; do \ echo "${V}" | while IFS=':' read PLATFORM KVER; do \
echo -e "${PLATFORM}\t${KVER}" >> /opt/platforms && \
echo "Extracting ds.${PLATFORM}-${TOOLKIT_VER}.dev.txz" && \ echo "Extracting ds.${PLATFORM}-${TOOLKIT_VER}.dev.txz" && \
mkdir "/opt/${PLATFORM}" && \ mkdir "/opt/${PLATFORM}" && \
tar -xaf "/cache/ds.${PLATFORM}-${TOOLKIT_VER}.dev.txz" -C "/opt/${PLATFORM}" --strip-components=10 \ 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}/build" && \ "usr/local/x86_64-pc-linux-gnu/x86_64-pc-linux-gnu/sys-root/usr/lib/modules/DSM-${TOOLKIT_VER}" && \
echo -e "${PLATFORM}\t${KVER}" >> /opt/platforms && \ echo "Extracting ${PLATFORM}-toolchain.txz" && \
if [ ! -d "/opt/linux-${KVER}" ]; then \ tar -xaf "/cache/${PLATFORM}-toolchain.txz" -C "/opt/${PLATFORM}" --strip-components=1; \
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; \
done; \ done; \
done done

View File

@ -6,50 +6,75 @@ function trap_cancel() {
sleep 2 || exit 1 sleep 2 || exit 1
} }
trap trap_cancel SIGINT SIGTERM trap trap_cancel SIGINT SIGTERM
cd `dirname $0` cd `dirname $0`
# Read platforms/kerver version ###############################################################################
echo "Reading platforms" function prepare() {
declare -A PLATFORMS declare -A URLS
while read PLATFORM KVER; do
PLATFORMS[${PLATFORM}]="${KVER}"
done <../PLATFORMS
# Download toolkits 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"
mkdir -p cache 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" TOOLKIT_VER="7.0"
for PLATFORM in ${!PLATFORMS[@]}; do TOOLCHAIN_VER="7.0-41890"
KVER="${PLATFORMS[${PLATFORM}]}" GCCLIB_VER="gcc750_glibc226"
echo -n "Checking cache/ds.${PLATFORM}-${TOOLKIT_VER}.dev.txz... " prepare
if [ ! -f "cache/ds.${PLATFORM}-${TOOLKIT_VER}.dev.txz" ]; then echo "Building ${TOOLKIT_VER}"
URL="https://global.download.synology.com/download/ToolChain/toolkit/${TOOLKIT_VER}/${PLATFORM}/ds.${PLATFORM}-${TOOLKIT_VER}.dev.txz" docker image rm fbelavenuto/syno-compiler:${TOOLKIT_VER} >/dev/null 2>&1
echo "Downloading ${URL}" docker buildx build . --load --tag fbelavenuto/syno-compiler:${TOOLKIT_VER}
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
# Generate Dockerfile # 7.1
echo "Generating Dockerfile" TOOLKIT_VER="7.1"
cp Dockerfile.template Dockerfile TOOLCHAIN_VER="7.1-42661"
VALUE="" GCCLIB_VER="gcc850_glibc226"
for PLATFORM in ${!PLATFORMS[@]}; do prepare
VALUE+="${PLATFORM}:${PLATFORMS[${PLATFORM}]} " echo "Building ${TOOLKIT_VER}"
done docker image rm fbelavenuto/syno-compiler:${TOOLKIT_VER} >/dev/null 2>&1
sed -i "s|@@@PLATFORMS@@@|${VALUE::-1}|g" Dockerfile docker buildx build . --load --tag fbelavenuto/syno-compiler:${TOOLKIT_VER} --tag fbelavenuto/syno-compiler:latest
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

View File

@ -2,6 +2,19 @@
set -e set -e
function export-vars {
# Validate
if [ -z "${1}" ]; then
echo "Use: export-vars <platform>"
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 { function compile-module {
# Validate # Validate
if [ -z "${1}" ]; then if [ -z "${1}" ]; then
@ -21,7 +34,9 @@ function compile-module {
fi fi
echo "Compiling module for ${PLATFORM}-${KVER}..." echo "Compiling module for ${PLATFORM}-${KVER}..."
cp -R /input /tmp 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 while read F; do
strip -g "${F}" strip -g "${F}"
echo "Copying `basename ${F}`" echo "Copying `basename ${F}`"
@ -36,11 +51,13 @@ function compile-lkm {
exit 1 exit 1
fi fi
cp -R /input /tmp 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" strip -g "/tmp/input/redpill.ko"
mv "/tmp/input/redpill.ko" "/output/redpill-dev.ko" mv "/tmp/input/redpill.ko" "/output/redpill-dev.ko"
make -C "/tmp/input" LINUX_SRC="/opt/${PLATFORM}" clean make -C "/tmp/input" clean
make -C "/tmp/input" LINUX_SRC="/opt/${PLATFORM}" prod-v7 make -C "/tmp/input" prod-v7
strip -g "/tmp/input/redpill.ko" strip -g "/tmp/input/redpill.ko"
mv "/tmp/input/redpill.ko" "/output/redpill-prod.ko" mv "/tmp/input/redpill.ko" "/output/redpill-prod.ko"
} }
@ -73,10 +90,10 @@ if [ $# -lt 1 ]; then
exit 1 exit 1
fi fi
case $1 in 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-module) compile-module $2 ;;
compile-lkm) compile-lkm $2 ;; compile-lkm) compile-lkm $2 ;;
# compile-drivers) compile-drivers ;; # compile-drivers) compile-drivers ;;
*) echo "Command not recognized: $1" ;; *) echo "Command not recognized: $1" ;;
esac esac