Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
tossp committed Apr 9, 2022
1 parent f9a0c87 commit beae19d
Show file tree
Hide file tree
Showing 7 changed files with 270 additions and 8 deletions.
8 changes: 3 additions & 5 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ jobs:
version: 7.0-41890
- platform: ds918p
version: 7.0.1-42218
- platform: DS3615xs
version: 7.1.0-42661
- platform: ds918p
version: 7.1.0-42661
- platform: ds3615xs
Expand All @@ -43,8 +41,8 @@ jobs:
version: 7.1.0-42661
- platform: ds1621p
version: 7.1.0-42661
- platform: dva3221
version: 7.1.0-42661
# - platform: dva3221
# version: 7.1.0-42661

steps:
- name: 检出项目文件
Expand Down Expand Up @@ -101,7 +99,7 @@ jobs:
- name: 添加 jumkey.dtb !!!Create your own device tree binary!!!
if: matrix.platform == 'ds920p' || matrix.platform == 'ds1621p' || matrix.platform == 'ds2422p'
run: |
./redpill_tool_chain.sh add https://github.com/tossp/redpill-tool-chain/raw/master/extensions/redpill-dtb.json
./redpill_tool_chain.sh add https://github.com/tossp/redpill-tool-chain/raw/test/extensions/redpill-dtb.json
echo '!!!Create your own device tree binary!!!'
echo 'see https://github.com/jumkey/redpill-load/blob/develop/redpill-dtb/README.md'
Expand Down
3 changes: 3 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,7 @@ COPY Makefile /opt/
COPY entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh

COPY helper.sh ./
RUN chmod +x ./helper.sh

ENTRYPOINT [ "/entrypoint.sh" ]
1 change: 1 addition & 0 deletions docker/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ if [ $# -eq 0 ];then
fi

echo "Lay back and enjoy the show: Magic is about to happen!"
./helper.sh "${TARGET_NAME}" "${TARGET_VERSION}-${TARGET_REVISION}"
make build_all
echo "The redpill bootloader is created, the container will be ended now."
exit 0
Expand Down
259 changes: 259 additions & 0 deletions docker/helper.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,259 @@
#!/usr/bin/env bash

set -u

##### BASIC RUNTIME VALIDATION #########################################################################################
# shellcheck disable=SC2128
if [ -z "${BASH_SOURCE}" ] ; then
echo "You need to execute this script using bash v4+ without using pipes"
exit 1
fi

cd "${BASH_SOURCE%/*}/" || exit 1
########################################################################################################################
echo "${BASH_SOURCE%/*}/"
echo "$PWD"
##### CONFIGURATION YOU CAN OVERRIDE USING ENVIRONMENT #################################################################
BRP_JUN_MOD=${BRP_JUN_MOD:-0} # whether you want to use jun's mod
BRP_DEBUG=${BRP_DEBUG:-0} # whether you want to see debug messages
BRP_CACHE_DIR=${BRP_CACHE_DIR:-"$PWD/redpill-load/cache"} # cache directory where stuff is downloaded & unpacked
BRP_USER_CFG=${BRP_USER_CFG:-"$PWD/redpill-load/user_config.json"}
BRP_BUILD_DIR=${BRP_BUILD_DIR:-''} # makes sure attempts are unique; do not override this unless you're using repack
BRP_KEEP_BUILD=${BRP_KEEP_BUILD:-''} # will be set to 1 for repack method or 0 for direct
BRP_LINUX_PATCH_METHOD=${BRP_LINUX_PATCH_METHOD:-"direct"} # how to generate kernel image (direct bsp patch vs repack)
BRP_LINUX_SRC=${BRP_LINUX_SRC:-''} # used for repack method
BRP_BOOT_IMAGE=${BRP_BOOT_IMAGE:-"$PWD/redpill-load/ext/boot-image-template.img.gz"} # gz-ed "template" image to base final image on
# you can also set RPT_EXTS_DIR as it's used by ext-manager
RPT_BUNDLED_EXTS_CFG=${RPT_BUNDLED_EXTS_CFG:-"$PWD/redpill-load/bundled-exts.json"} # file with list of bundled extensions

# The options below are meant for debugging only. Setting them will create an image which is not normally usable
BRP_DEV_DISABLE_RP=${BRP_DEV_DISABLE_RP:-0} # when set to 1 the rp.ko will be renamed to rp-dis.ko
BRP_DEV_DISABLE_SB=${BRP_DEV_DISABLE_SB:-0} # when set to 1 the synobios.ko will be renamed to synobios-dis.ko
BRP_DEV_DISABLE_EXTS=${BRP_DEV_DISABLE_EXTS:-0} # when set 1 all extensions will be disabled (and not included in image)
########################################################################################################################

##### INCLUDES #########################################################################################################
. redpill-load/include/log.sh # logging helpers
. redpill-load/include/text.sh # text manipulation
. redpill-load/include/runtime.sh # need to include this early so we can used date and such
. redpill-load/include/json.sh # json parsing routines
. redpill-load/include/config-manipulators.sh
. redpill-load/include/file.sh # file-related operations (copying/moving/unpacking etc)
. redpill-load/include/patch.sh # helpers for patching files using patch(1) and bspatch(1)
. redpill-load/include/boot-image.sh # helper functions for dealing with the boot image
. redpill-load/include/ext-bridge.sh # helper to interact with extensions manager
########################################################################################################################

##### CONFIGURATION VALIDATION##########################################################################################

### Command line params handling
if [ $# -lt 2 ] || [ $# -gt 3 ]; then
echo "Usage: $0 platform version <output-file>"
exit 1
fi
BRP_HW_PLATFORM="$1"
BRP_SW_VERSION="$2"
BRP_OUTPUT_FILE="${3:-"$PWD/redpill-load/images/redpill-${BRP_HW_PLATFORM}_${BRP_SW_VERSION}_b$(date '+%s').img"}"

BRP_REL_CONFIG_BASE="$PWD/redpill-load/config/${BRP_HW_PLATFORM}/${BRP_SW_VERSION}"
BRP_REL_CONFIG_JSON="${BRP_REL_CONFIG_BASE}/config.json"

### Some config validation
if [ "${BRP_LINUX_PATCH_METHOD}" == "direct" ]; then
BRP_BUILD_DIR=${BRP_BUILD_DIR:-"$PWD/redpill-load/build/$(date '+%s')"}
BRP_KEEP_BUILD=${BRP_KEEP_BUILD:='0'}
elif [ "${BRP_LINUX_PATCH_METHOD}" == "repack" ]; then
if [ -z ${BRP_BUILD_DIR} ]; then
pr_crit "You've chosen \"%s\" method for patching - you must specify BRP_BUILD_DIR" "${BRP_LINUX_PATCH_METHOD}"
fi
BRP_KEEP_BUILD=${BRP_KEEP_BUILD:='1'}

if [ -z ${BRP_LINUX_SRC} ]; then
pr_crit "You've chosen \"repack\" method for patching - you must specify BRP_LINUX_SRC" "${BRP_LINUX_PATCH_METHOD}"
fi

if [ ! -f "${BRP_LINUX_SRC}/Kbuild" ]; then
pr_crit "BRP_LINUX_SRC=%s doesn't look like are valid Linux source tree (Kbuild not present)" "${BRP_LINUX_SRC}"
fi

if [ ! -f "${BRP_LINUX_SRC}/.config" ]; then
pr_crit "Kernel configuration file (%s/.config) doesn't exist - create one (or copy existing one)" "${BRP_LINUX_SRC}"
fi
else
pr_crit "BRP_LINUX_PATCH_METHOD=%s is not are valid value: {direct|repack}" "${BRP_LINUX_PATCH_METHOD}"
fi

if [ ! -f "${BRP_USER_CFG}" ]; then
pr_crit "User config (BRP_USER_CFG) \"%s\" doesn't exist" "${BRP_USER_CFG}"
fi
brp_json_validate "${BRP_USER_CFG}"

if [ ! -f "${BRP_REL_CONFIG_JSON}" ]; then
pr_crit "There doesn't seem to be a config for %s platform running %s (checked %s)" \
"${BRP_HW_PLATFORM}" "${BRP_SW_VERSION}" "${BRP_REL_CONFIG_JSON}"
fi
brp_json_validate "${BRP_REL_CONFIG_JSON}"

### Here we define some common/well-known paths used later, as well as the map for resolving path variables in configs
readonly BRP_REL_OS_ID=$(brp_json_get_field "${BRP_REL_CONFIG_JSON}" "os.id")
readonly BRP_UPAT_DIR="${BRP_BUILD_DIR}/pat-${BRP_REL_OS_ID}-unpacked" # unpacked pat directory
readonly BRP_EXT_DIR="$PWD/ext" # a directory with external tools/files/modules
readonly BRP_COMMON_CFG_BASE="$PWD/config/_common" # a directory with common configs & patches sable for many platforms
readonly BRP_USER_DIR="$PWD/custom"
# vars map for copying files from release configs. If you're changing this please add to docs!
typeset -r -A BRP_RELEASE_PATHS=(
[@@@_DEF_@@@]="${BRP_REL_CONFIG_BASE}"
[@@@PAT@@@]="${BRP_UPAT_DIR}"
[@@@COMMON@@@]="${BRP_COMMON_CFG_BASE}"
[@@@EXT@@@]="${BRP_EXT_DIR}"
)
# vars map for copying files from user config. If you're changing this please add to docs!
typeset -r -A BRP_USER_PATHS=(
[@@@_DEF_@@@]="${BRP_USER_DIR}"
)

### Load metadata about extensions
typeset -a RPT_BUNDLED_EXTS_IDS # ordered IDs of bundled extensions
typeset -A RPT_BUNDLED_EXTS # k=>v extensions to their index urls
RPT_BUILD_EXTS='' # by default it's empty == all
RPT_USER_EXTS=''
if [[ "${BRP_DEV_DISABLE_EXTS}" -ne 1 ]]; then
RPT_USER_EXTS=$(rpt_load_user_extensions "${BRP_USER_CFG}") || exit 1
rpt_load_bundled_extensions "${RPT_BUNDLED_EXTS_CFG}" RPT_BUNDLED_EXTS_IDS RPT_BUNDLED_EXTS
if [[ ! -z "${RPT_USER_EXTS}" ]]; then # if user defined some extensions we need to whitelist bundled + user picked
for ext_id in ${RPT_BUNDLED_EXTS_IDS[@]+"${RPT_BUNDLED_EXTS_IDS[@]}"}; do
if [[ ! -z "${RPT_BUILD_EXTS}" ]]; then
RPT_BUILD_EXTS+=','
fi
RPT_BUILD_EXTS+="${ext_id}"
done
RPT_BUILD_EXTS+=",${RPT_USER_EXTS}"
fi
fi

pr_dbg "******** Printing config variables ********"
pr_dbg "Cache dir: %s" "$BRP_CACHE_DIR"
pr_dbg "Build dir: %s" "$BRP_BUILD_DIR"
pr_dbg "Ext dir: %s" "$BRP_EXT_DIR"
pr_dbg "User custom dir: %s" "$BRP_USER_DIR"
pr_dbg "User config: %s" "$BRP_USER_CFG"
pr_dbg "Keep build dir? %s" "$BRP_KEEP_BUILD"
pr_dbg "Linux patch method: %s" "$BRP_LINUX_PATCH_METHOD"
pr_dbg "Linux repack src: %s" "$BRP_LINUX_SRC"
pr_dbg "Hardware platform: %s" "$BRP_HW_PLATFORM"
pr_dbg "Software version: %s" "$BRP_SW_VERSION"
pr_dbg "Image template: %s" "$BRP_BOOT_IMAGE"
pr_dbg "Image destination: %s" "$BRP_OUTPUT_FILE"
pr_dbg "Common cfg base: %s" "$BRP_COMMON_CFG_BASE"
pr_dbg "Release cfg base: %s" "$BRP_REL_CONFIG_BASE"
pr_dbg "Release cfg JSON: %s" "$BRP_REL_CONFIG_JSON"
pr_dbg "Release id: %s" "$BRP_REL_OS_ID"
if [[ "${BRP_DEV_DISABLE_EXTS}" -ne 1 ]]; then
pr_dbg "User extensions [empty means all]: %s" "$RPT_USER_EXTS"
pr_dbg "Selected extensions [empty means all]: %s" "$RPT_BUILD_EXTS"
else
pr_warn "User extensions: <disabled>"
pr_warn "Selected extensions: <all disabled>"
fi
pr_dbg "*******************************************"

########################################################## 读取环境参数完成

# BRP_DEBUG=1 ./helper.sh "DS918+" "7.1.0-42661"

readonly EXTRACT_PAT_FILE="${BRP_CACHE_DIR}/extract.tar.gz"
make_extract(){
archive="$1"
if [ ! -f "${EXTRACT_PAT_FILE}" ]; then
readonly EXTRACT_PAT_URL='https://global.download.synology.com/download/DSM/release/7.0.1/42218/DSM_DS3622xs%2B_42218.pat'
pr_info "PAT file %s not found - downloading from %s" "${EXTRACT_PAT_FILE}" "${EXTRACT_PAT_URL}"
"${CURL_PATH}" --output "${EXTRACT_PAT_FILE}" "${EXTRACT_PAT_URL}"
else
pr_dbg "Found existing PAT at %s - skipping download" "${EXTRACT_PAT_FILE}"
fi
mkdir synoesp
tar -C./synoesp/ -xf "${EXTRACT_PAT_FILE}" rd.gz
cd synoesp
xz -dc < rd.gz >rd 2>/dev/null && echo "extract rd.gz" || echo error
cpio -idm <rd 2>&1 && echo "extract rd" || echo error
mkdir extract && cd extract
cp ../usr/lib/libcurl.so.4 ../usr/lib/libmbedcrypto.so.5 ../usr/lib/libmbedtls.so.13 ../usr/lib/libmbedx509.so.1 ../usr/lib/libmsgpackc.so.2 ../usr/lib/libsodium.so ../usr/lib/libsynocodesign-ng-virtual-junior-wins.so.7 /usr/local/lib
cp ../usr/syno/bin/scemd /usr/local/bin/syno_extract_system_patch
cd ../..
mkdir pat
LD_LIBRARY_PATH=/usr/local/lib /usr/local/bin/syno_extract_system_patch "${BRP_PAT_FILE}" pat || pr_info "extract latest pat"
cd pat
pr_process "Repacked PAT %s" ${BRP_PAT_FILE}
pr_empty_nl
"${TAR_PATH}" -czf archive.tar.gz ./
mv ${BRP_PAT_FILE} ${BRP_PAT_FILE}.org
mv archive.tar.gz ${BRP_PAT_FILE}
cd ../
rm -rf pat synoesp
sum=`sha256sum ${BRP_PAT_FILE} | awk '{print $1}'`
pr_info "The new checksum - %s" "${sum}"

old_sum="$(brp_json_get_field "${BRP_REL_CONFIG_JSON}" "os.sha256")"
sed -i "s/${old_sum}/${sum}/" "${BRP_REL_CONFIG_JSON}"
pr_process_ok
}

check_pat() {
archive="$1"
archiveheader="$(od -bc ${archive} | head -1 | awk '{print $3}')"
return_value=0
case ${archiveheader} in
105)
pr_dbg "${archive}, is a Tar file"
;;
255)
pr_info "File ${archive}, Decryption required"
return_value=1
;;
213)
pr_dbg "File ${archive}, is a compressed tar"
;;
*)
pr_process_err

pr_err "Could not determine if file ${archive} is encrypted or not, maybe corrupted"
ls -ltr ${archive}
pr_crit "${archiveheader}"
return_value=99
;;
esac
return $return_value
}

##########################################################
readonly BRP_PAT_FILE="${BRP_CACHE_DIR}/${BRP_REL_OS_ID}.pat"
if [ ! -d "${BRP_UPAT_DIR}" ]; then
pr_dbg "Unpacked PAT %s not found - preparing" "${BRP_UPAT_DIR}"

brp_mkdir "${BRP_UPAT_DIR}"

if [ ! -f "${BRP_PAT_FILE}" ]; then
readonly BRP_PAT_URL=$(brp_json_get_field "${BRP_REL_CONFIG_JSON}" "os.pat_url")
pr_info "PAT file %s not found - downloading from %s" "${BRP_PAT_FILE}" "${BRP_PAT_URL}"
"${CURL_PATH}" --output "${BRP_PAT_FILE}" "${BRP_PAT_URL}"
else
pr_dbg "Found existing PAT at %s - skipping download" "${BRP_PAT_FILE}"
fi

brp_verify_file_sha256 "${BRP_PAT_FILE}" "$(brp_json_get_field "${BRP_REL_CONFIG_JSON}" "os.sha256")"

check_pat "${BRP_PAT_FILE}"
exec_status=$?
pr_info "Test encryption pat results %s" "${exec_status}"
if [ "$exec_status" -eq 1 ]; then
make_extract "${BRP_PAT_FILE}"
fi
brp_unpack_tar "${BRP_PAT_FILE}" "${BRP_UPAT_DIR}"
else
pr_info "Found unpacked PAT at \"%s\" - skipping unpacking" "${BRP_UPAT_DIR}"
fi


if [ "${BRP_KEEP_BUILD}" -eq 0 ]; then
"${RM_PATH}" -rf "${BRP_BUILD_DIR}"
fi
2 changes: 1 addition & 1 deletion extensions/redpill-dtb.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"id": "redpill-dtb",
"url": "https://github.com/tossp/redpill-tool-chain/raw/master/extensions/redpill-dtb.json",
"url": "https://github.com/tossp/redpill-tool-chain/raw/test/extensions/redpill-dtb.json",
"info": {
"name": "Device tree binary",
"description": "Create your own device tree binary",
Expand Down
4 changes: 2 additions & 2 deletions global_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@
"platform_name": "DS918+",
"platform_version": "apollolake-7.1.0-42661",
"user_config_json": "ds918p_user_config.json",
"docker_base_image": "debian:8-slim",
"docker_base_image": "debian:10-slim",
"compile_with": "toolkit_dev",
"redpill_lkm_make_target": "test-v7",
"downloads": {
Expand Down Expand Up @@ -320,7 +320,7 @@
"id": "ds3622xsp-7.1.0-42661",
"platform_name": "DS3622xs+",
"platform_version": "broadwellnk-7.1.0-42661",
"user_config_json": "ds3622xsp_user_config-test.json",
"user_config_json": "ds3622xsp_user_config.json",
"docker_base_image": "debian:10-slim",
"redpill_lkm_make_target": "dev-v7",
"compile_with": "toolkit_dev",
Expand Down
1 change: 1 addition & 0 deletions redpill_tool_chain.sh
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ function runContainer(){
$( [ -e "${USER_CONFIG_JSON}" ] && echo "--volume $(realpath ${USER_CONFIG_JSON}):/opt/redpill-load/user_config.json") \
--volume ${REDPILL_LOAD_CACHE}:/opt/redpill-load/cache \
--volume ${REDPILL_LOAD_IMAGES}:/opt/redpill-load/images \
# --volume $(realpath docker/helper.sh):/opt/helper.sh \
--env REDPILL_LKM_MAKE_TARGET=${REDPILL_LKM_MAKE_TARGET} \
--env TARGET_PLATFORM="${TARGET_PLATFORM}" \
--env TARGET_NAME="${TARGET_NAME}" \
Expand Down

0 comments on commit beae19d

Please sign in to comment.