Skip to content

Commit

Permalink
优化过程
Browse files Browse the repository at this point in the history
  • Loading branch information
tossp committed Apr 10, 2022
1 parent 9c03c21 commit 4831cd2
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 159 deletions.
1 change: 1 addition & 0 deletions docker/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ build_redpill_load:
echo "#############################################"
@read -a KVERS <<< "$$(modinfo --field=vermagic redpill-lkm/redpill.ko)" && \
cp -f $(REDPILL_LKM_SRC)/redpill.ko $(REDPILL_LOAD_SRC)/ext/rp-lkm/redpill-linux-v$${KVERS[0]}.ko
./helper.sh "${TARGET_NAME}" "${TARGET_VERSION}-${TARGET_REVISION}"
pushd $(REDPILL_LOAD_SRC) && ./build-loader.sh '$(TARGET_NAME)' '$(TARGET_VERSION)-$(TARGET_REVISION)'

.PHONY: build_all
Expand Down
1 change: 0 additions & 1 deletion docker/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ 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
164 changes: 6 additions & 158 deletions docker/helper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,161 +2,13 @@

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
if [ ${TARGET_REVISION} -lt 42218 ];then
exit 0
fi

cd "${BASH_SOURCE%/*}/" || exit 1
########################################################################################################################

##### 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 "*******************************************"

########################################################## 读取环境参数完成
cat ./redpill-load/build-loader.sh | head -n `expr -1 + $(sed -n '/Printing config variables/=' ./redpill-load/build-loader.sh)` > ./redpill-load/_helper.sh
. ./redpill-load/_helper.sh "${TARGET_NAME}" "${TARGET_VERSION}-${TARGET_REVISION}"
rm ./_helper.sh

# Repacks tar-like file
#
Expand Down Expand Up @@ -211,7 +63,7 @@ make_extract(){
sum=`sha256sum ${BRP_PAT_FILE} | awk '{print $1}'`
old_sum="$(brp_json_get_field "${BRP_REL_CONFIG_JSON}" "os.sha256")"
sed -i "s/${old_sum}/${sum}/" "${BRP_REL_CONFIG_JSON}"

rm -rf /tmp/pat
pr_process_ok
}

Expand Down Expand Up @@ -279,11 +131,7 @@ if [ ! -d "${BRP_UPAT_DIR}" ]; then
pr_empty_nl
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

0 comments on commit 4831cd2

Please sign in to comment.