This commit is contained in:
砼砼 2021-08-09 21:09:48 +08:00
commit 5c144c44ff
No known key found for this signature in database
GPG Key ID: 3FDE30A50EA2CCEA
9 changed files with 372 additions and 0 deletions

17
.editorconfig Normal file
View File

@ -0,0 +1,17 @@
# Editor configuration, see https://editorconfig.org
root = true
[*]
end_of_line = lf
charset = utf-8
indent_style = space
indent_size = 2
insert_final_newline = true
trim_trailing_whitespace = true
[*.ts]
quote_type = single
[*.md]
max_line_length = off
trim_trailing_whitespace = false

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
*.txz
user_config.json

171
Makefile Normal file
View File

@ -0,0 +1,171 @@
AKEFLAGS += --warn-undefined-variables
SHELL := bash
.SHELLFLAGS := -e -o pipefail -c
.DEFAULT_GOAL := all
.DELETE_ON_ERROR:
.SUFFIXES:
####################################################
# Shared arguments for image build and container run
####################################################
export DOCKER_BASE_IMAGE := debian:8
#export DOCKER_BASE_IMAGE := ubuntu:16.04
export DOCKER_IMAGE_NAME := redpill-tool-chain
# The USERCONFIG_ variables MUST be configured with valid values - otherwise the redpill image will not boot!
export USERCONFIG_VID := <fill me>
export USERCONFIG_PID := <fill me>
export USERCONFIG_SN := <fill me>
export USERCONFIG_MAC1 := <fill me>
# Modify parameters to build either bromolow or apollolake with version 6.2.4-25556 or 7.0-41890
export TARGET_PLATFORM := bromolow
#export TARGET_PLATFORM := apollolake
export TARGET_VERSION := 6.2
#export TARGET_VERSION := 7.0
export BUILD_REDPILL_LOADER_VERSION := $(shell [ "$(TARGET_VERSION)" == "6.2" ] && echo "6.2.4-25556" || echo "7.0-41890")
####################################################
# Arguments for container run
####################################################
# mount-bind host folder with absolute path into redpill-load cache folder
# will not work with relativfe path! If single name is used, a docker volume will be created!
export REDPILL_LOAD_CACHE := $(PWD)/cache
# mount bind hots folder with absolute path into redpill load images folder
export REDPILL_LOAD_IMAGES := $(PWD)/images
####################################################
# build image downloads and build argument
####################################################
export DOWNLOAD_FOLDER := docker/downloads
export DSM6.2_BROMOLOW_TOOLCHAIN_DOWNLOAD_URL := https://sourceforge.net/projects/dsgpl/files/Tool%20Chain/DSM%206.2.4%20Tool%20Chains/Intel%20x86%20linux%203.10.105%20%28Bromolow%29/bromolow-gcc493_glibc220_linaro_x86_64-GPL.txz/download
export DSM6.2_BROMOLOW_TOOLCHAIN_FILENAME := bromolow-gcc493_glibc220_linaro_x86_64-GPL.txz
export DSM7.0_BROMOLOW_TOOLCHAIN_DOWNLOAD_URL := https://sourceforge.net/projects/dsgpl/files/Tool%20Chain/DSM%207.0.0%20Tool%20Chains/Intel%20x86%20linux%203.10.108%20%28Bromolow%29/bromolow-gcc750_glibc226_x86_64-GPL.txz/download
export DSM7.0_BROMOLOW_TOOLCHAIN_FILENAME := bromolow-gcc750_glibc226_x86_64-GPL.txz
export DSM6.2_APOLLOLAKE_TOOLCHAIN_DOWNLOAD_URL := https://sourceforge.net/projects/dsgpl/files/Tool%20Chain/DSM%206.2.4%20Tool%20Chains/Intel%20x86%20Linux%204.4.59%20%28Apollolake%29/apollolake-gcc493_glibc220_linaro_x86_64-GPL.txz/download
export DSM6.2_APOLLOLAKE_TOOLCHAIN_FILENAME := apollolake-gcc493_glibc220_linaro_x86_64-GPL.txz
export DSM7.0_APOLLOLAKE_TOOLCHAIN_DOWNLOAD_URL := https://sourceforge.net/projects/dsgpl/files/Tool%20Chain/DSM%207.0.0%20Tool%20Chains/Intel%20x86%20Linux%204.4.180%20%28Apollolake%29/apollolake-gcc750_glibc226_x86_64-GPL.txz/download
export DSM7.0_APOLLOLAKE_TOOLCHAIN_FILENAME := apollolake-gcc750_glibc226_x86_64-GPL.txz
export BROMOLOW_KERNEL_DOWNLOAD_URL := https://sourceforge.net/projects/dsgpl/files/Synology%20NAS%20GPL%20Source/25426branch/bromolow-source/linux-3.10.x.txz/download
export BROMOLOW_KERNEL_FILENAME := linux-3.10.x.txz
export APOLLOLAKE_KERNEL_DOWNLOAD_URL := https://sourceforge.net/projects/dsgpl/files/Synology%20NAS%20GPL%20Source/25426branch/apollolake-source/linux-4.4.x.txz/download
export APOLLOLAKE_KERNEL_FILENAME := linux-4.4.x.txz
export TOOLKIT_DEV_DOWNLOAD_URL := https://sourceforge.net/projects/dsgpl/files/toolkit/DSM$(TARGET_VERSION)/ds.$(TARGET_PLATFORM)-$(TARGET_VERSION).dev.txz/download
export TOOLKIT_DEV_FILENAME := ds.$(TARGET_PLATFORM)-$(TARGET_VERSION).dev.txz
export REDPILL_LKM_REPO := https://github.com/RedPill-TTG/redpill-lkm.git
export REDPILL_LKM_BRANCH := master
# detect based on TARGET_VERSION
export REDPILL_LOAD := https://github.com/$(shell [ "$(TARGET_VERSION)" == "6.2" ] && echo "RedPill-TTG" || echo "jumkey")/redpill-load.git
export REDPILL_LOAD_BRANCH := $(shell [ "$(TARGET_VERSION)" == "6.2" ] && echo "master" || echo "7.0-41890")
#export REDPILL_LOAD := https://github.com/RedPill-TTG/redpill-load.git
#export REDPILL_LOAD_BRANCH := master
#REDPILL_LOAD := https://github.com/jumkey/redpill-load.git
#REDPILL_LOAD_BRANCH := 7.0-41890
####################################################
# Do not touch anything below, unless you know what you are doing...
####################################################
.PHONY: all
all:
$(call printTargets)
.PHONY: build_image
build_image:
$(call downloadFromUrlIfNotExists,$(call getToolChainFilename),$(call getToolChainDownloadURL),$(TARGET_PLATFORM) toolchain)
$(call downloadFromUrlIfNotExists,$(call getKernelFilename),$(call getKernelDownloadURL),$(TARGET_PLATFORM) kernel)
$(call downloadFromUrlIfNotExists,$(TOOLKIT_DEV_FILENAME),$(TOOLKIT_DEV_DOWNLOAD_URL),$(TARGET_PLATFORM) $(TAGET_VERSION) Toolkit (includes kernel modules))
$(call buildImage,$(TARGET_PLATFORM),$(call getToolChainFilename),$(call getKernelFilename),$(TOOLKIT_DEV_FILENAME))
.PHONY: run_container
run_container:
$(call runContainer,$(TARGET_PLATFORM))
## Print makefile PHONY targets to the console
define printTargets
@echo "Possible Targets:"
@less Makefile |grep .PHONY[:] |cut -f2 -d ' ' |xargs -n1 echo " - " |grep -v " - all"
endef
## Download binaries
##
## @param 1 Path to downloaded file
## @param 2 Download URL
## @param 3 Message to display
define downloadFromUrlIfNotExists
@if [ ! -e $(DOWNLOAD_FOLDER)/$(1) ]; then \
echo "Downloading $(3)"; \
curl --progress-bar --location '$(2)' --output $(DOWNLOAD_FOLDER)/$(1); \
fi
endef
## Build docker image
##
## @param 1 Platform to build
## @param 3 Toolkit Filename to add to the image
## @param 2 Toolchain Filename to add to the image
define buildImage
@DOCKER_BUILDKIT=1 docker build --file docker/Dockerfile --force-rm --pull \
--build-arg DOCKER_BASE_IMAGE=$(DOCKER_BASE_IMAGE) \
--build-arg TOOLCHAIN_FILENAME="$(2)" \
--build-arg KERNEL_FILENAME="$(3)" \
--build-arg TOOLKIT_DEV_FILENAME="$(4)" \
--build-arg REDPILL_LKM_REPO="$(REDPILL_LKM_REPO)" \
--build-arg REDPILL_LKM_BRANCH="$(REDPILL_LKM_BRANCH)" \
--build-arg REDPILL_LOAD="$(REDPILL_LOAD)" \
--build-arg REDPILL_LOAD_BRANCH="$(REDPILL_LOAD_BRANCH)" \
--build-arg BUILD_REDPILL_LOADER_VERSION="$(BUILD_REDPILL_LOADER_VERSION)" \
--build-arg USERCONFIG_VID="$(USERCONFIG_VID)" \
--build-arg USERCONFIG_PID="$(USERCONFIG_PID)" \
--build-arg USERCONFIG_SN="$(USERCONFIG_SN)" \
--build-arg USERCONFIG_MAC1="$(USERCONFIG_MAC1)" \
--build-arg TARGET_PLATFORM="$(TARGET_PLATFORM)" \
--build-arg TARGET_VERSION="$(TARGET_VERSION)" \
-t $(DOCKER_IMAGE_NAME):$(TARGET_PLATFORM)-$(TARGET_VERSION) ./docker
endef
## Run docker container and mount cache volume, image bind-mount and if present a user_config.json file
define runContainer
@docker run -ti --rm --privileged -v /dev:/dev \
-v $(REDPILL_LOAD_CACHE):/opt/redpill-load/cache \
-v $(REDPILL_LOAD_IMAGES):/opt/redpill-load/images \
$(shell [ -e user_config.json ] && echo "-v $(PWD)/user_config.json:/opt/redpill-load/user_config.json") \
-e USERCONFIG_VID="$(USERCONFIG_VID)" \
-e USERCONFIG_PID="$(USERCONFIG_PID)" \
-e USERCONFIG_SN="$(USERCONFIG_SN)" \
-e USERCONFIG_MAC1="$(USERCONFIG_MAC1)" \
-e BUILD_REDPILL_LOADER_VERSION=$(BUILD_REDPILL_LOADER_VERSION) \
$(DOCKER_IMAGE_NAME):$(TARGET_PLATFORM)-$(TARGET_VERSION) bash
endef
define getToolChainFilename
${DSM$(TARGET_VERSION)_$(shell echo $(TARGET_PLATFORM) | tr '[:lower:]' '[:upper:]')_TOOLCHAIN_FILENAME}
endef
define getToolChainDownloadURL
${DSM$(TARGET_VERSION)_$(shell echo $(TARGET_PLATFORM) | tr '[:lower:]' '[:upper:]')_TOOLCHAIN_DOWNLOAD_URL}
endef
define getKernelFilename
${$(shell echo $(TARGET_PLATFORM) | tr '[:lower:]' '[:upper:]')_KERNEL_FILENAME}
endef
define getKernelDownloadURL
${$(shell echo $(TARGET_PLATFORM) | tr '[:lower:]' '[:upper:]')_KERNEL_DOWNLOAD_URL}
endef

40
README.md Normal file
View File

@ -0,0 +1,40 @@
# RedPill Tool Chain
THX @haydibe
# What is this?
The redpill tool chain docker image builder is updated to v0.4:
- proper DSM7 support for apollolake (thnx @jumkey)
- switched from kernel sources based build to toolkit dev based builds for DSM6.2.4 and DSM7.0 (thnx @jumkey)
- make targets for bromolow and apollolake merged: platform and version must be configure in the Makefile now
- image is ~720-780MB instead of ~1.200-1.500MB now
Note: since toolkit dev lacks the required sources for fs/proc, they are taken from the extracted DSM6.2.4 kernel sources.
The build requires the sources for this single folder, but does not use the kernel source to build the redpill.ko module.
If you see something is wrong in how the toolchain is build or have ideas how to make it better: please let me know.
For every other problem: please address it to the community - I don't know more than others do.
Note#2: before someone asks: I haven't managed a successfull installation/migration with the created bootloader so far. I am testing exclusivly on ESXi 6.7. The migration always stops at 56% and bails out with error 13.
# How to use it?
- (on host) configure the Makefile and configure TARGET_PLATFORM (default: bromolow) and TARGET_VERSION (default: 6.2 - will build 6.2.4)
- (on host) create your own user_config.json or edit the USERCONFIG_* variables in the Makefile
- (on host) build image: make build_image
- (on host) run container: make run_container
- (in container) build redpill.ko module and redpill bootloader image: make build_all
After running `make build_all` the created redpill bootloader image will be present in the ./image folder on the host.
Tested with hosts: Ubuntu 18.04 VM, Ubuntu 20.04 WSL2 and XPE (the make binary to build on Synology/XPE can be found here)
Dependencies: make and docker

57
docker/Dockerfile Normal file
View File

@ -0,0 +1,57 @@
ARG DOCKER_BASE_IMAGE=debian:8
# extract kernel and toolkit dev
FROM ${DOCKER_BASE_IMAGE} AS extract
ARG TOOLKIT_DEV_FILENAME
ADD downloads/${TOOLKIT_DEV_FILENAME} /
ARG KERNEL_FILENAME
ADD downloads/${KERNEL_FILENAME} /
# tool chain image
FROM ${DOCKER_BASE_IMAGE}
ARG DEBIAN_FRONTEND=noninteractive
RUN apt-get update && \
apt-get install --yes --no-install-recommends ca-certificates build-essential git libssl-dev curl cpio bspatch vim gettext bc bison flex dosfstools kmod && \
rm -rf /var/lib/apt/lists/* /tmp/* && \
curl --progress-bar --output /usr/bin/jq --location https://github.com/stedolan/jq/releases/download/jq-1.6/jq-linux64 && chmod +x /usr/bin/jq
ARG TOOLCHAIN_FILENAME
ADD downloads/${TOOLCHAIN_FILENAME} /opt/
ARG REDPILL_LKM_REPO=https://github.com/RedPill-TTG/redpill-lkm.git
ARG REDPILL_LKM_BRANCH=master
RUN git clone ${REDPILL_LKM_REPO} -b ${REDPILL_LKM_BRANCH} /opt/redpill-lkm
ARG REDPILL_LOAD=https://github.com/RedPill-TTG/redpill-load.git
ARG REDPILL_LOAD_BRANCH=master
RUN git clone ${REDPILL_LOAD} -b ${REDPILL_LOAD_BRANCH} /opt/redpill-load
ARG TARGET_VERSION
ARG TARGET_PLATFORM
COPY --from=extract /usr/local/x86_64-pc-linux-gnu/x86_64-pc-linux-gnu/sys-root/usr/lib/modules/DSM-${TARGET_VERSION}/build /opt/redpill-lkm/kernel-${TARGET_PLATFORM}-${TARGET_VERSION}
COPY --from=extract /linux*/fs/proc/ /opt/redpill-lkm/kernel-${TARGET_PLATFORM}-${TARGET_VERSION}/fs/proc/
WORKDIR "/opt"
COPY Makefile user_config.json.template /opt/
ARG BUILD_REDPILL_LOADER_VERSION
ARG USERCONFIG_VID=<fill me>
ARG USERCONFIG_PID=<fill me>
ARG USERCONFIG_SN=<fill me>
ARG USERCONFIG_MAC1=<fill me>
# LINUX_SRC=/usr/local/x86_64-pc-linux-gnu/x86_64-pc-linux-gnu/sys-root/usr/lib/modules/DSM-${TARGET_VERSION}/build \
ENV ARCH=x86_64 \
CROSS_COMPILE=/opt/x86_64-pc-linux-gnu/bin/x86_64-pc-linux-gnu- \
LINUX_SRC=/opt/redpill-lkm/kernel-${TARGET_PLATFORM}-${TARGET_VERSION} \
TARGET_PLATFORM=${TARGET_PLATFORM} \
BUILD_REDPILL_LOADER_VERSION=${BUILD_REDPILL_LOADER_VERSION} \
USERCONFIG_VID=${USERCONFIG_VID} \
USERCONFIG_PID=${USERCONFIG_PID} \
USERCONFIG_SN=${USERCONFIG_SN} \
USERCONFIG_MAC1=${USERCONFIG_MAC1}
CMD ["bash"]

63
docker/Makefile Normal file
View File

@ -0,0 +1,63 @@
AKEFLAGS += --warn-undefined-variables
SHELL := bash
.SHELLFLAGS := -e -o pipefail -c
.DEFAULT_GOAL := all
.DELETE_ON_ERROR:
.SUFFIXES:
export REDPILL_SRC := /opt/redpill-lkm
export REDPILL_LOADER_SRC := /opt/redpill-load
export TARGET_PLATFORM :=${TARGET_PLATFORM}
export LINUX_SRC := ${LINUX_SRC}
export USERCONFIG_VID := ${USERCONFIG_VID}
export USERCONFIG_PID := ${USERCONFIG_PID}
export USERCONFIG_SN := ${USERCONFIG_SN}
export USERCONFIG_MAC1 := ${USERCONFIG_MAC1}
export BUILD_REDPILL_LOADER_VERSION := ${BUILD_REDPILL_LOADER_VERSION}
.PHONY: all
all:
@echo "Possible Targets:"
@less Makefile |grep .PHONY[:] |cut -f2 -d ' ' |xargs -n1 echo " - " |grep -v " - all"
.PHONY: build_redpill_lkm
build_redpill_lkm:
@$(MAKE) -C $(REDPILL_SRC) LINUX_SRC=$(LINUX_SRC) && \
echo "#############################################" && \
modinfo $(REDPILL_SRC)/redpill.ko
.PHONY: build_redpill_load
build_redpill_load:
@mkdir -p $(REDPILL_LOADER_SRC)/ext/rp-lkm/
@if [ ! -e $(REDPILL_LOADER_SRC)/user_config.json ]; then envsubst < user_config.json.template > $(REDPILL_LOADER_SRC)/user_config.json; fi
@echo "#############################################" && \
echo "Using user_config.json:" && cat $(REDPILL_LOADER_SRC)/user_config.json && \
echo "#############################################"
@if [ "$(TARGET_PLATFORM)" == "bromolow" ]; then \
pushd $(REDPILL_LOADER_SRC) && \
if [ "$(BUILD_REDPILL_LOADER_VERSION)" == "7.0-41890" ];then \
cp -f $(REDPILL_SRC)/redpill.ko $(REDPILL_LOADER_SRC)/ext/rp-lkm/redpill-linux-v3.10.108.ko ; \
else \
cp -f $(REDPILL_SRC)/redpill.ko $(REDPILL_LOADER_SRC)/ext/rp-lkm/redpill-linux-v3.10.105.ko ; \
fi && \
./build-loader.sh 'DS3615xs' '$(BUILD_REDPILL_LOADER_VERSION)'; \
fi
@if [ "$(TARGET_PLATFORM)" == "apollolake" ]; then \
pushd $(REDPILL_LOADER_SRC) && \
if [ "$(BUILD_REDPILL_LOADER_VERSION)" == "7.0-41890" ];then \
cp -f $(REDPILL_SRC)/redpill.ko $(REDPILL_LOADER_SRC)/ext/rp-lkm/redpill-linux-v4.4.180+.ko; \
else \
cp -f $(REDPILL_SRC)/redpill.ko $(REDPILL_LOADER_SRC)/ext/rp-lkm/redpill-linux-v4.4.59+.ko; \
fi && \
./build-loader.sh 'DS918+' '$(BUILD_REDPILL_LOADER_VERSION)'; \
fi
.PHONY: build_all
build_all: build_redpill_lkm build_redpill_load
.PHONY: clean_redpill_lkm
clean_redpill_lkm:
@$(MAKE) -C $(REDPILL_SRC) clean

View File

@ -0,0 +1,2 @@
*.txz
user_config.json

View File

@ -0,0 +1,10 @@
{
"extra_cmdline": {
"vid": "${USERCONFIG_VID}",
"pid": "${USERCONFIG_PID}",
"sn": "${USERCONFIG_SN}",
"mac1": "${USERCONFIG_MAC1}"
},
"synoinfo": {},
"ramdisk_copy": {}
}

10
user_config.simple.json Normal file
View File

@ -0,0 +1,10 @@
{
"extra_cmdline": {
"vid": "0x1908",
"pid": "0x0226",
"sn": "1780PDN123456",
"mac1": "00505623F398"
},
"synoinfo": {},
"ramdisk_copy": {}
}