Merge pull request #53 from fbelavenuto/dev

Various commits
This commit is contained in:
Fabio Belavenuto 2022-07-22 16:58:46 -03:00 committed by GitHub
commit 6d80b03f0f
21 changed files with 131 additions and 74 deletions

View File

@ -10,7 +10,7 @@ I tried to make the system as user-friendly as possible, to make life easier. Th
To use this project, download the latest image available and burn it to a USB stick or SATA disk-on-module. Set the PC to boot from the burned media and follow the informations on the screen. When booting, the user can call the "menu.sh" command from the computer itself, access via SSH or use the virtual terminal (ttyd) by typing the address provided on the screen (http://(ip):7681). The loader will automatically increase the size of the last partition and use this space as cache if it is larger than 2GiB. To use this project, download the latest image available and burn it to a USB stick or SATA disk-on-module. Set the PC to boot from the burned media and follow the informations on the screen. When booting, the user can call the "menu.sh" command from the computer itself, access via SSH or use the virtual terminal (ttyd) by typing the address provided on the screen (http://(ip):7681). The loader will automatically increase the size of the last partition and use this space as cache if it is larger than 2GiB.
## It is highly recommended to use an SSD for the loader in the case of the option via DoM or a fast USB flash drive ### It is highly recommended to use an SSD for the loader in the case of the option via DoM or a fast USB flash drive
The menu system is dynamic and I hope it is intuitive enough that the user can use it without any problems. Its allows you to choose a model, the existing buildnumber for the chosen model, type or randomly create a serial number, add/remove addons, add/remove/view "cmdline" and "synoinfo" entries, choose the LKM version, create the loader, boot, manually edit the configuration file, choose a keymap, update and exit. The menu system is dynamic and I hope it is intuitive enough that the user can use it without any problems. Its allows you to choose a model, the existing buildnumber for the chosen model, type or randomly create a serial number, add/remove addons, add/remove/view "cmdline" and "synoinfo" entries, choose the LKM version, create the loader, boot, manually edit the configuration file, choose a keymap, update and exit.

View File

@ -12,15 +12,6 @@ tasks:
cmds: cmds:
- ./build.sh - ./build.sh
compile-lkms:
cmds:
- ./compile-lkm.sh
compile-addons:
dir: addons
cmds:
- ./compile-addons.sh {{.CLI_ARGS}}
compile-kpatch: compile-kpatch:
dir: kpatch dir: kpatch
cmds: cmds:

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

View File

@ -76,7 +76,8 @@ EFI_BUG="`readModelKey "${MODEL}" "builds.${BUILD}.efi-bug"`"
LOADER_DISK="`blkid | grep 'LABEL="ARPL3"' | cut -d3 -f1`" LOADER_DISK="`blkid | grep 'LABEL="ARPL3"' | cut -d3 -f1`"
BUS=`udevadm info --query property --name ${LOADER_DISK} | grep ID_BUS | cut -d= -f2` BUS=`udevadm info --query property --name ${LOADER_DISK} | grep ID_BUS | cut -d= -f2`
if [ "${BUS}" = "ata" ]; then if [ "${BUS}" = "ata" ]; then
SIZE=$((`df -BM | awk '/\/mnt\/p3/{print$2}' | tr 'M' ' '`+300)) LOADER_DEVICE_NAME=`echo ${LOADER_DISK} | sed 's|/dev/||'`
SIZE=$((`cat /sys/block/${LOADER_DEVICE_NAME}/size`/2048+10))
# Read SATADoM type # Read SATADoM type
DOM="`readModelKey "${MODEL}" "dom"`" DOM="`readModelKey "${MODEL}" "dom"`"
fi fi

View File

@ -34,7 +34,6 @@ mount ${LOADER_DISK}1 ${BOOTLOADER_PATH} || die "Can't mount ${BOOTLOADER_PATH}"
mount ${LOADER_DISK}2 ${SLPART_PATH} || die "Can't mount ${SLPART_PATH}" mount ${LOADER_DISK}2 ${SLPART_PATH} || die "Can't mount ${SLPART_PATH}"
mount ${LOADER_DISK}3 ${CACHE_PATH} || die "Can't mount ${CACHE_PATH}" mount ${LOADER_DISK}3 ${CACHE_PATH} || die "Can't mount ${CACHE_PATH}"
mkdir -p "${ADDONS_PATH}"
# Move/link SSH machine keys to/from cache volume # Move/link SSH machine keys to/from cache volume
[ ! -d "${CACHE_PATH}/ssh" ] && cp -R "/etc/ssh" "${CACHE_PATH}/ssh" [ ! -d "${CACHE_PATH}/ssh" ] && cp -R "/etc/ssh" "${CACHE_PATH}/ssh"
rm -rf "/etc/ssh" rm -rf "/etc/ssh"
@ -156,3 +155,7 @@ echo
echo -e "User config is on \033[1;32m${USER_CONFIG_FILE}\033[0m" echo -e "User config is on \033[1;32m${USER_CONFIG_FILE}\033[0m"
echo -e "Default SSH Root password is \033[1;31mRedp1lL-1s-4weSomE\033[0m" echo -e "Default SSH Root password is \033[1;31mRedp1lL-1s-4weSomE\033[0m"
echo echo
mkdir -p "${ADDONS_PATH}"
mkdir -p "${LKM_PATH}"
mkdir -p "${MODULES_PATH}"

View File

@ -173,6 +173,7 @@ function addonMenu() {
d "Delete addon(s)" \ d "Delete addon(s)" \
s "Show user addons" \ s "Show user addons" \
m "Show all available addons" \ m "Show all available addons" \
o "Download a external addon" \
e "Exit" \ e "Exit" \
2>${TMP_PATH}/resp 2>${TMP_PATH}/resp
[ $? -ne 0 ] && return [ $? -ne 0 ] && return
@ -243,6 +244,30 @@ function addonMenu() {
dialog --backtitle "`backtitle`" --title "Available addons" \ dialog --backtitle "`backtitle`" --title "Available addons" \
--colors --msgbox "${MSG}" 0 0 --colors --msgbox "${MSG}" 0 0
;; ;;
o)
TEXT="please enter the complete URL to download.\n"
dialog --backtitle "`backtitle`" --aspect 18 --colors --inputbox "${TEXT}" 0 0 \
2>${TMP_PATH}/resp
[ $? -ne 0 ] && continue
URL="`<"${TMP_PATH}/resp"`"
[ -z "${URL}" ] && continue
clear
echo "Downloading ${URL}"
curl --insecure -L "${URL}" -o "${TMP_PATH}/addon.tgz" --progress-bar
if [ $? -ne 0 ]; then
dialog --backtitle "`backtitle`" --title "Error downloading" --aspect 18 \
--msgbox "Check internet, URL or cache disk space" 0 0
return 1
fi
ADDON="`untarAddon "${TMP_PATH}/addon.tgz"`"
if [ -n "${ADDON}" ]; then
dialog --backtitle "`backtitle`" --title "Success" --aspect 18 \
--msgbox "Addon '${ADDON}' added to loader" 0 0
else
dialog --backtitle "`backtitle`" --title "Invalid addon" --aspect 18 \
--msgbox "File format not recognized!" 0 0
fi
;;
e) return ;; e) return ;;
esac esac
done done
@ -778,12 +803,11 @@ function updateMenu() {
unzip /tmp/addons.zip -d /tmp/addons >/dev/null 2>&1 unzip /tmp/addons.zip -d /tmp/addons >/dev/null 2>&1
dialog --backtitle "`backtitle`" --title "Update addons" --aspect 18 \ dialog --backtitle "`backtitle`" --title "Update addons" --aspect 18 \
--infobox "Installing new addons" 0 0 --infobox "Installing new addons" 0 0
DEST_PATH="/mnt/p3/addons"
for PKG in `ls /tmp/addons/*.addon`; do for PKG in `ls /tmp/addons/*.addon`; do
ADDON=`basename ${PKG} | sed 's|.addon||'` ADDON=`basename ${PKG} | sed 's|.addon||'`
rm -rf "${DEST_PATH}/${ADDON}" rm -rf "${ADDONS_PATH}/${ADDON}"
mkdir -p "${DEST_PATH}/${ADDON}" mkdir -p "${ADDONS_PATH}/${ADDON}"
tar xaf "${PKG}" -C "${DEST_PATH}/${ADDON}" >/dev/null 2>&1 tar xaf "${PKG}" -C "${ADDONS_PATH}/${ADDON}" >/dev/null 2>&1
done done
DIRTY=1 DIRTY=1
dialog --backtitle "`backtitle`" --title "Update addons" --aspect 18 \ dialog --backtitle "`backtitle`" --title "Update addons" --aspect 18 \

View File

@ -115,7 +115,6 @@ ADDONS['eudev']=""
echo -n "." echo -n "."
mkdir -p "${RAMDISK_PATH}/addons" mkdir -p "${RAMDISK_PATH}/addons"
echo "#!/bin/sh" > "${RAMDISK_PATH}/addons/addons.sh" echo "#!/bin/sh" > "${RAMDISK_PATH}/addons/addons.sh"
echo 'export INSMOD="/sbin/insmod"' >> "${RAMDISK_PATH}/addons/addons.sh"
echo 'echo "addons.sh called with params ${@}"' >> "${RAMDISK_PATH}/addons/addons.sh" echo 'echo "addons.sh called with params ${@}"' >> "${RAMDISK_PATH}/addons/addons.sh"
for ADDON in ${!ADDONS[@]}; do for ADDON in ${!ADDONS[@]}; do
PARAMS=${ADDONS[${ADDON}]} PARAMS=${ADDONS[${ADDON}]}