Skip to content
This repository has been archived by the owner on May 8, 2024. It is now read-only.

Commit

Permalink
Merge pull request #355 from fbelavenuto/docker-toolkit
Browse files Browse the repository at this point in the history
New docker image syno-toolkit
  • Loading branch information
fbelavenuto authored Nov 28, 2022
2 parents efb54e1 + f6dbd4b commit c00c94f
Show file tree
Hide file tree
Showing 9 changed files with 171 additions and 10 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ arpl*.vmdk
*.zip
.buildroot
test*.sh
docker/Dockerfile
docker/cache
docker/syno-compiler/Dockerfile
cache
*.bak
*.o
File renamed without changes.
19 changes: 11 additions & 8 deletions docker/build.sh → docker/syno-compiler/build.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#!/usr/bin/env bash

CACHE_DIR="cache"
PLATFORM_FILE="../../PLATFORMS"

###############################################################################
function trap_cancel() {
echo "Press Control+C once more terminate the process (or wait 2s for it to restart)"
Expand All @@ -26,26 +29,26 @@ function prepare() {
declare -A PLATFORMS
while read PLATFORM KVER; do
PLATFORMS[${PLATFORM}]="${KVER}"
done <../PLATFORMS
done < ${PLATFORM_FILE}

# Download toolkits
mkdir -p cache
mkdir -p ${CACHE_DIR}

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
echo -n "Checking ${CACHE_DIR}/ds.${PLATFORM}-${TOOLKIT_VER}.dev.txz... "
if [ ! -f "${CACHE_DIR}/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"
curl -L "${URL}" -o "${CACHE_DIR}/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
echo -n "Checking ${CACHE_DIR}/${PLATFORM}-toolchain.txz... "
if [ ! -f "${CACHE_DIR}/${PLATFORM}-toolchain.txz" ]; then
URL=${URLS["${PLATFORM}"]}
echo "Downloading ${URL}"
curl -L "${URL}" -o "cache/${TOOLKIT_VER}/${PLATFORM}-toolchain.txz"
curl -L "${URL}" -o "${CACHE_DIR}/${PLATFORM}-toolchain.txz"
else
echo "OK"
fi
Expand Down
File renamed without changes.
15 changes: 15 additions & 0 deletions docker/syno-toolkit/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
FROM scratch
ARG PLATFORM
ARG TOOLKIT_VER
ARG CACHE_DIR

ENV PLATFORM=${PLATFORM} TOOLKIT_VER=${TOOLKIT_VER}
ADD ${CACHE_DIR}/base_env-${TOOLKIT_VER}.txz /
ADD ${CACHE_DIR}/ds.${PLATFORM}-${TOOLKIT_VER}.env.txz /
ADD ${CACHE_DIR}/ds.${PLATFORM}-${TOOLKIT_VER}.dev.txz /
ADD rootfs /

WORKDIR /input
VOLUME /input /output

ENTRYPOINT ["/usr/bin/do.sh"]
61 changes: 61 additions & 0 deletions docker/syno-toolkit/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#!/usr/bin/env bash

set -e

CACHE_DIR="cache"
PLATFORM_FILE="../../PLATFORMS"
TOOLKIT_VER=7.1

###############################################################################
function trap_cancel() {
echo "Press Control+C once more terminate the process (or wait 2s for it to restart)"
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 < ${PLATFORM_FILE}

# Download toolkits
mkdir -p ${CACHE_DIR}

# Check base environment
echo -n "Checking ${CACHE_DIR}/base_env-${TOOLKIT_VER}.txz... "
if [ ! -f "${CACHE_DIR}/base_env-${TOOLKIT_VER}.txz" ]; then
URL="https://global.download.synology.com/download/ToolChain/toolkit/${TOOLKIT_VER}/${PLATFORM}/base_env-${TOOLKIT_VER}.txz"
echo "Downloading ${URL}"
curl -L "${URL}" -o "${CACHE_DIR}/base_env-${TOOLKIT_VER}.txz"
else
echo "OK"
fi

# Check all platforms
for PLATFORM in ${!PLATFORMS[@]}; do
echo -n "Checking ${CACHE_DIR}/ds.${PLATFORM}-${TOOLKIT_VER}.dev.txz... "
if [ ! -f "${CACHE_DIR}/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_DIR}/ds.${PLATFORM}-${TOOLKIT_VER}.dev.txz"
else
echo "OK"
fi
echo -n "Checking ${CACHE_DIR}/ds.${PLATFORM}-${TOOLKIT_VER}.env.txz... "
if [ ! -f "${CACHE_DIR}/ds.${PLATFORM}-${TOOLKIT_VER}.env.txz" ]; then
URL="https://global.download.synology.com/download/ToolChain/toolkit/${TOOLKIT_VER}/${PLATFORM}/ds.${PLATFORM}-${TOOLKIT_VER}.env.txz"
echo "Downloading ${URL}"
curl -L "${URL}" -o "${CACHE_DIR}/ds.${PLATFORM}-${TOOLKIT_VER}.env.txz"
else
echo "OK"
fi
done

# Generate docker images
for PLATFORM in ${!PLATFORMS[@]}; do
docker buildx build . --build-arg PLATFORM=${PLATFORM} --build-arg TOOLKIT_VER=${TOOLKIT_VER} --build-arg CACHE_DIR="${CACHE_DIR}" \
--tag fbelavenuto/syno-toolkit:${PLATFORM}-${TOOLKIT_VER} --load
done
10 changes: 10 additions & 0 deletions docker/syno-toolkit/rootfs/etc/profile.d/login.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[[ "$-" != *i* ]] && return
export LS_OPTIONS='--color=auto'
export SHELL='linux'
eval "`dircolors`"
alias ls='ls -F -h --color=always -v --author --time-style=long-iso'
alias ll='ls -l'
alias l='ls -l -a'
alias h='history 25'
alias j='jobs -l'
export PATH="/opt/${PLATFORM}/bin:${PATH}"
72 changes: 72 additions & 0 deletions docker/syno-toolkit/rootfs/usr/bin/do.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#!/usr/bin/env bash

set -e

###############################################################################
function compile-module {
echo -e "Compiling module for \033[7m${PLATFORM}\033[0m..."
cp -R /input /tmp
make -C ${KSRC} M=/tmp/input ${PLATFORM^^}-Y=y ${PLATFORM^^}-M=m modules
while read F; do
strip -g "${F}"
echo "Copying `basename ${F}`"
cp "${F}" "/output"
chown 1000.1000 "/output/`basename ${F}`"
done < <(find /tmp/input -name \*.ko)
}

###############################################################################
function compile-lkm {
cp -R /input /tmp
make -C "/tmp/input" dev-v7
strip -g "/tmp/input/redpill.ko"
mv "/tmp/input/redpill.ko" "/output/redpill-dev.ko"
chown 1000.1000 /output/redpill-dev.ko
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"
chown 1000.1000 /output/redpill-prod.ko
}

###############################################################################
# function compile-drivers {
# while read platform kver; do
# SRC_PATH="/opt/${platform}"
# echo "Compiling for ${platform}-${kver}"
# cd /opt/linux-${kver}/drivers
# while read dir; do
# if [ -f "${dir}/Makefile" ]; then
# echo "Driver `basename ${dir}`"
# grep "CONFIG_.*/.*" "${dir}/Makefile" | sed 's/.*\(CONFIG_[^)]*\).*/\1=n/g' > /tmp/env
# grep "CONFIG_.*\.o.*" "${dir}/Makefile" | sed 's/.*\(CONFIG_[^)]*\).*/\1=m/g' >> /tmp/env
# make -C "${SRC_PATH}" M=$(readlink -f "${dir}") clean
# cat /tmp/env | xargs -d '\n' make -C "${SRC_PATH}" M=$(readlink -f "${dir}") modules $@
# fi
# done < <(find -type d)
# DST_PATH="/output/compiled-mods/${platform}-${kver}"
# mkdir -p "${DST_PATH}"
# while read f; do
# strip -g "${f}"
# mv "${f}" "${DST_PATH}"
# done < <(find -name \*.ko)
# done </opt/platforms
# }

###############################################################################
###############################################################################

if [ $# -lt 1 ]; then
echo "Use: <command> (<params>)"
echo "Commands: shell | compile-module | compile-lkm"
exit 1
fi
export KSRC="/usr/local/x86_64-pc-linux-gnu/x86_64-pc-linux-gnu/sys-root/usr/lib/modules/DSM-${TOOLKIT_VER}/build"
export LINUX_SRC="/usr/local/x86_64-pc-linux-gnu/x86_64-pc-linux-gnu/sys-root/usr/lib/modules/DSM-${TOOLKIT_VER}/build"
case $1 in
shell) shift && bash -l $@ ;;
compile-module) compile-module ;;
compile-lkm) compile-lkm ;;
# compile-drivers) compile-drivers ;;
*) echo "Command not recognized: $1" ;;
esac

0 comments on commit c00c94f

Please sign in to comment.