New docker image syno-toolkit

This commit is contained in:
Fabio Belavenuto 2022-11-28 10:44:00 -03:00
parent 048345a3c5
commit cb37d9adc9
9 changed files with 171 additions and 10 deletions

4
.gitignore vendored
View File

@ -5,7 +5,7 @@ arpl*.vmdk
*.zip *.zip
.buildroot .buildroot
test*.sh test*.sh
docker/Dockerfile docker/syno-compiler/Dockerfile
docker/cache cache
*.bak *.bak
*.o *.o

View File

@ -1,5 +1,8 @@
#!/usr/bin/env bash #!/usr/bin/env bash
CACHE_DIR="cache"
PLATFORM_FILE="../../PLATFORMS"
############################################################################### ###############################################################################
function trap_cancel() { function trap_cancel() {
echo "Press Control+C once more terminate the process (or wait 2s for it to restart)" echo "Press Control+C once more terminate the process (or wait 2s for it to restart)"
@ -26,26 +29,26 @@ function prepare() {
declare -A PLATFORMS declare -A PLATFORMS
while read PLATFORM KVER; do while read PLATFORM KVER; do
PLATFORMS[${PLATFORM}]="${KVER}" PLATFORMS[${PLATFORM}]="${KVER}"
done <../PLATFORMS done < ${PLATFORM_FILE}
# Download toolkits # Download toolkits
mkdir -p cache mkdir -p ${CACHE_DIR}
for PLATFORM in ${!PLATFORMS[@]}; do for PLATFORM in ${!PLATFORMS[@]}; do
KVER="${PLATFORMS[${PLATFORM}]}" KVER="${PLATFORMS[${PLATFORM}]}"
echo -n "Checking cache/${TOOLKIT_VER}/ds.${PLATFORM}-${TOOLKIT_VER}.dev.txz... " echo -n "Checking ${CACHE_DIR}/ds.${PLATFORM}-${TOOLKIT_VER}.dev.txz... "
if [ ! -f "cache/${TOOLKIT_VER}/ds.${PLATFORM}-${TOOLKIT_VER}.dev.txz" ]; then 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" URL="https://global.download.synology.com/download/ToolChain/toolkit/${TOOLKIT_VER}/${PLATFORM}/ds.${PLATFORM}-${TOOLKIT_VER}.dev.txz"
echo "Downloading ${URL}" 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 else
echo "OK" echo "OK"
fi fi
echo -n "Checking cache/${TOOLKIT_VER}/${PLATFORM}-toolchain.txz... " echo -n "Checking ${CACHE_DIR}/${PLATFORM}-toolchain.txz... "
if [ ! -f "cache/${TOOLKIT_VER}/${PLATFORM}-toolchain.txz" ]; then if [ ! -f "${CACHE_DIR}/${PLATFORM}-toolchain.txz" ]; then
URL=${URLS["${PLATFORM}"]} URL=${URLS["${PLATFORM}"]}
echo "Downloading ${URL}" echo "Downloading ${URL}"
curl -L "${URL}" -o "cache/${TOOLKIT_VER}/${PLATFORM}-toolchain.txz" curl -L "${URL}" -o "${CACHE_DIR}/${PLATFORM}-toolchain.txz"
else else
echo "OK" echo "OK"
fi fi

View File

@ -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
docker/syno-toolkit/build.sh Executable file
View File

@ -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

View File

@ -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}"

View File

@ -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