@@ -4,14 +4,14 @@
|
||||
# Overlay Init Section
|
||||
[[ -z "${ARC_PATH}" || ! -d "${ARC_PATH}/include" ]] && ARC_PATH="$(cd "$(dirname "${BASH_SOURCE[0]}")" 2>/dev/null && pwd)"
|
||||
|
||||
. ${ARC_PATH}/include/functions.sh
|
||||
. ${ARC_PATH}/include/addons.sh
|
||||
. ${ARC_PATH}/include/modules.sh
|
||||
. ${ARC_PATH}/include/update.sh
|
||||
. ${ARC_PATH}/include/storage.sh
|
||||
. ${ARC_PATH}/include/network.sh
|
||||
. ${ARC_PATH}/include/compat.sh
|
||||
. ${ARC_PATH}/arc-functions.sh
|
||||
. "${ARC_PATH}/include/functions.sh"
|
||||
. "${ARC_PATH}/include/addons.sh"
|
||||
. "${ARC_PATH}/include/modules.sh"
|
||||
. "${ARC_PATH}/include/update.sh"
|
||||
. "${ARC_PATH}/include/storage.sh"
|
||||
. "${ARC_PATH}/include/network.sh"
|
||||
. "${ARC_PATH}/include/compat.sh"
|
||||
. "${ARC_PATH}/arc-functions.sh"
|
||||
|
||||
# Get Keymap and Timezone Config
|
||||
onlineCheck
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
set -e
|
||||
[[ -z "${ARC_PATH}" || ! -d "${ARC_PATH}/include" ]] && ARC_PATH="$(cd "$(dirname "${BASH_SOURCE[0]}")" 2>/dev/null && pwd)"
|
||||
|
||||
. ${ARC_PATH}/include/functions.sh
|
||||
. "${ARC_PATH}/include/functions.sh"
|
||||
|
||||
# Clear logs for dbgutils addons
|
||||
rm -rf "${PART1_PATH}/logs" >/dev/null 2>&1 || true
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
read_u8() {
|
||||
dd if=$1 bs=1 skip=$(($2)) count=1 2>/dev/null | od -An -tu1 | grep -Eo '[0-9]+'
|
||||
dd if="${1}" bs=1 skip="$((${2}))" count=1 2>/dev/null | od -An -tu1 | grep -Eo '[0-9]+'
|
||||
}
|
||||
read_u32() {
|
||||
dd if=$1 bs=1 skip=$(($2)) count=4 2>/dev/null | od -An -tu4 | grep -Eo '[0-9]+'
|
||||
dd if="${1}" bs=1 skip="$((${2}))" count=4 2>/dev/null | od -An -tu4 | grep -Eo '[0-9]+'
|
||||
}
|
||||
|
||||
set -x
|
||||
setup_size=$(read_u8 $1 0x1f1)
|
||||
payload_offset=$(read_u32 $1 0x248)
|
||||
payload_length=$(read_u32 $1 0x24c)
|
||||
inner_pos=$((($setup_size + 1) * 512))
|
||||
setup_size=$(read_u8 "${1}" 0x1f1)
|
||||
payload_offset=$(read_u32 "${1}" 0x248)
|
||||
payload_length=$(read_u32 "${1}" 0x24c)
|
||||
inner_pos=$(((setup_size + 1) * 512))
|
||||
|
||||
tail -c+$(($inner_pos + 1)) $1 | tail -c+$(($payload_offset + 1)) | head -c $(($payload_length)) | head -c $(($payload_length - 4)) | unlzma >$2
|
||||
tail -c+$(($inner_pos + 1)) "${1}" | tail -c+$(($payload_offset + 1)) | head -c "${payload_length}" | head -c $(($payload_length - 4)) | unlzma >"${2}"
|
||||
@@ -7,28 +7,22 @@
|
||||
# objdump -h a.out | sh calc_run_size.sh
|
||||
|
||||
NUM='\([0-9a-fA-F]*[ \t]*\)'
|
||||
OUT=$(sed -n 's/^[ \t0-9]*.b[sr][sk][ \t]*'"${NUM}${NUM}${NUM}${NUM}"'.*/\1\4/p')
|
||||
if [ -z "$OUT" ]; then
|
||||
OUT=$(sed -n 's/^[ \t0-9]*.b[sr][sk][ \t]*'"${NUM}${NUM}${NUM}${NUM}"'.*/0x\1 0x\4/p')
|
||||
|
||||
if [ -z "${OUT}" ]; then
|
||||
echo "Never found .bss or .brk file offset" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
OUT=$(echo ${OUT# })
|
||||
sizeA=$(printf "%d" 0x${OUT%% *})
|
||||
OUT=${OUT#* }
|
||||
offsetA=$(printf "%d" 0x${OUT%% *})
|
||||
OUT=${OUT#* }
|
||||
sizeB=$(printf "%d" 0x${OUT%% *})
|
||||
OUT=${OUT#* }
|
||||
offsetB=$(printf "%d" 0x${OUT%% *})
|
||||
read -r sizeA offsetA sizeB offsetB <<<$(echo ${OUT} | awk '{printf "%d %d %d %d", strtonum($1), strtonum($2), strtonum($3), strtonum($4)}')
|
||||
|
||||
run_size=$((${offsetA} + ${sizeA} + ${sizeB}))
|
||||
runSize=$((offsetA + sizeA + sizeB))
|
||||
|
||||
# BFD linker shows the same file offset in ELF.
|
||||
if [ "${offsetA}" -ne "${offsetB}" ]; then
|
||||
# Gold linker shows them as consecutive.
|
||||
endB=$((${offsetB} + ${sizeB}))
|
||||
if [ "$endB" != "$run_size" ]; then
|
||||
endSize=$((offsetB + sizeB))
|
||||
if [ "${endSize}" -ne "${runSize}" ]; then
|
||||
printf "sizeA: 0x%x\n" ${sizeA} >&2
|
||||
printf "offsetA: 0x%x\n" ${offsetA} >&2
|
||||
printf "sizeB: 0x%x\n" ${sizeB} >&2
|
||||
@@ -38,5 +32,5 @@ if [ "${offsetA}" -ne "${offsetB}" ]; then
|
||||
fi
|
||||
fi
|
||||
|
||||
printf "%d\n" ${run_size}
|
||||
printf "%d\n" ${runSize}
|
||||
exit 0
|
||||
@@ -10,38 +10,34 @@
|
||||
#
|
||||
# ----------------------------------------------------------------------
|
||||
|
||||
check_vmlinux()
|
||||
{
|
||||
# Use readelf to check if it's a valid ELF
|
||||
# TODO: find a better to way to check that it's really vmlinux
|
||||
# and not just an elf
|
||||
readelf -h $1 > /dev/null 2>&1 || return 1
|
||||
check_vmlinux() {
|
||||
# Use readelf to check if it's a valid ELF
|
||||
# TODO: find a better to way to check that it's really vmlinux
|
||||
# and not just an elf
|
||||
readelf -h $1 >/dev/null 2>&1 || return 1
|
||||
|
||||
cat $1
|
||||
exit 0
|
||||
cat $1
|
||||
exit 0
|
||||
}
|
||||
|
||||
try_decompress()
|
||||
{
|
||||
# The obscure use of the "tr" filter is to work around older versions of
|
||||
# "grep" that report the byte offset of the line instead of the pattern.
|
||||
try_decompress() {
|
||||
# The obscure use of the "tr" filter is to work around older versions of
|
||||
# "grep" that report the byte offset of the line instead of the pattern.
|
||||
|
||||
# Try to find the header ($1) and decompress from here
|
||||
for pos in `tr "$1\n$2" "\n$2=" < "$img" | grep -abo "^$2"`
|
||||
do
|
||||
pos=${pos%%:*}
|
||||
tail -c+$pos "$img" | $3 > $tmp 2> /dev/null
|
||||
check_vmlinux $tmp
|
||||
done
|
||||
# Try to find the header ($1) and decompress from here
|
||||
for pos in $(tr "$1\n$2" "\n$2=" <"$img" | grep -abo "^$2"); do
|
||||
pos=${pos%%:*}
|
||||
tail -c+$pos "$img" | $3 >$tmp 2>/dev/null
|
||||
check_vmlinux $tmp
|
||||
done
|
||||
}
|
||||
|
||||
# Check invocation:
|
||||
me=${0##*/}
|
||||
img=$1
|
||||
if [ $# -ne 1 -o ! -s "$img" ]
|
||||
then
|
||||
echo "Usage: $me <kernel-image>" >&2
|
||||
exit 2
|
||||
if [ $# -ne 1 ] || [ ! -s "$img" ]; then
|
||||
echo "Usage: $me <kernel-image>" >&2
|
||||
exit 2
|
||||
fi
|
||||
|
||||
# Prepare temp files:
|
||||
@@ -61,4 +57,4 @@ try_decompress '(\265/\375' xxx unzstd
|
||||
check_vmlinux $img
|
||||
|
||||
# Bail out:
|
||||
echo "$me: Cannot find vmlinux." >&2
|
||||
echo "$me: Cannot find vmlinux." >&2
|
||||
@@ -1,8 +1,8 @@
|
||||
[[ -z "${ARC_PATH}" || ! -d "${ARC_PATH}/include" ]] && ARC_PATH="$(cd "$(dirname "${BASH_SOURCE[0]}")/../" 2>/dev/null && pwd)"
|
||||
|
||||
. ${ARC_PATH}/include/consts.sh
|
||||
. ${ARC_PATH}/include/configFile.sh
|
||||
. ${ARC_PATH}/include/addons.sh
|
||||
. "${ARC_PATH}/include/consts.sh"
|
||||
. "${ARC_PATH}/include/configFile.sh"
|
||||
. "${ARC_PATH}/include/addons.sh"
|
||||
|
||||
###############################################################################
|
||||
# Check loader disk
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
set -e
|
||||
[[ -z "${ARC_PATH}" || ! -d "${ARC_PATH}/include" ]] && ARC_PATH="$(cd "$(dirname "${BASH_SOURCE[0]}")" 2>/dev/null && pwd)"
|
||||
|
||||
. ${ARC_PATH}/include/functions.sh
|
||||
. "${ARC_PATH}/include/functions.sh"
|
||||
|
||||
# Get Loader Disk Bus
|
||||
[ -z "${LOADER_DISK}" ] && die "Loader Disk not found!"
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
|
||||
[[ -z "${ARC_PATH}" || ! -d "${ARC_PATH}/include" ]] && ARC_PATH="$(cd "$(dirname "${BASH_SOURCE[0]}")" 2>/dev/null && pwd)"
|
||||
|
||||
. ${ARC_PATH}/include/functions.sh
|
||||
. ${ARC_PATH}/include/addons.sh
|
||||
. ${ARC_PATH}/include/modules.sh
|
||||
. "${ARC_PATH}/include/functions.sh"
|
||||
. "${ARC_PATH}/include/addons.sh"
|
||||
. "${ARC_PATH}/include/modules.sh"
|
||||
|
||||
set -o pipefail # Get exit code from process piped
|
||||
|
||||
|
||||
@@ -3,72 +3,62 @@
|
||||
|
||||
[[ -z "${ARC_PATH}" || ! -d "${ARC_PATH}/include" ]] && ARC_PATH="$(cd "$(dirname "${BASH_SOURCE[0]}")" 2>/dev/null && pwd)"
|
||||
|
||||
. ${ARC_PATH}/include/functions.sh
|
||||
. "${ARC_PATH}/include/functions.sh"
|
||||
|
||||
PLATFORM="$(readConfigKey "platform" "${USER_CONFIG_FILE}")"
|
||||
PRODUCTVER="$(readConfigKey "productver" "${USER_CONFIG_FILE}")"
|
||||
KVER="$(readConfigKey "platforms.${PLATFORM}.productvers.\"${PRODUCTVER}\".kver" "${P_FILE}")"
|
||||
KVER="$(readConfigKey "platforms.${PLATFORM}.productvers.\"${PRODUCTVER}\".kver" "${ARC_PATH}/platforms.yml")"
|
||||
|
||||
# Adapted from: scripts/Makefile.lib
|
||||
# Usage: size_append FILE [FILE2] [FILEn]...
|
||||
# Output: LE HEX with size of file in bytes (to STDOUT)
|
||||
file_size_le() {
|
||||
printf $(
|
||||
dec_size=0
|
||||
for F in "${@}"; do
|
||||
fsize=$(stat -c "%s" ${F})
|
||||
dec_size=$((${dec_size} + ${fsize}))
|
||||
done
|
||||
printf "%08x\n" ${dec_size} |
|
||||
sed 's/\(..\)/\1 /g' | {
|
||||
read ch0 ch1 ch2 ch3
|
||||
for ch in ${ch3} ${ch2} ${ch1} ${ch0}; do
|
||||
printf '%s%03o' '\' $((0x${ch}))
|
||||
done
|
||||
local dec_size=0
|
||||
for F in "$@"; do dec_size=$((dec_size + $(stat -c "%s" "${F}"))); done
|
||||
printf "%08x\n" "${dec_size}" | sed 's/\(..\)/\1 /g' | {
|
||||
read -r ch0 ch1 ch2 ch3
|
||||
for ch in "${ch3}" "${ch2}" "${ch1}" "${ch0}"; do printf '%s%03o' '\' "$((0x${ch}))"; done
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
size_le() {
|
||||
printf $(
|
||||
printf "%08x\n" "${@}" |
|
||||
sed 's/\(..\)/\1 /g' | {
|
||||
read ch0 ch1 ch2 ch3
|
||||
for ch in ${ch3} ${ch2} ${ch1} ${ch0}; do
|
||||
printf '%s%03o' '\' $((0x${ch}))
|
||||
done
|
||||
printf "%08x\n" "${@}" | sed 's/\(..\)/\1 /g' | {
|
||||
read -r ch0 ch1 ch2 ch3
|
||||
for ch in "${ch3}" "${ch2}" "${ch1}" "${ch0}"; do printf '%s%03o' '\' "$((0x${ch}))"; done
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
VMLINUX_MOD=${1}
|
||||
ZIMAGE_MOD=${2}
|
||||
KVER_MAJOR=${KVER:0:1}
|
||||
if [ ${KVER_MAJOR} -eq 4 ]; then
|
||||
if [ "$(echo "${KVER:-4}" | cut -d'.' -f1)" -lt 5 ]; then
|
||||
# Kernel version 4.x or 3.x (bromolow)
|
||||
#zImage_head 16494
|
||||
#payload(
|
||||
# vmlinux.bin x
|
||||
# padding 0xf00000-x
|
||||
# vmlinux.bin size 4
|
||||
#) 0xf00004
|
||||
#zImage_tail(
|
||||
# unknown 72
|
||||
# run_size 4
|
||||
# unknown 30
|
||||
# vmlinux.bin size 4
|
||||
# unknown 114460
|
||||
#) 114570
|
||||
#crc32 4
|
||||
# zImage_head 16494
|
||||
# payload(
|
||||
# vmlinux.bin x
|
||||
# padding 0xf00000-x
|
||||
# vmlinux.bin size 4
|
||||
# ) 0xf00004
|
||||
# zImage_tail(
|
||||
# unknown 72
|
||||
# run_size 4
|
||||
# unknown 30
|
||||
# vmlinux.bin size 4
|
||||
# unknown 114460
|
||||
# ) 114570
|
||||
# crc32 4
|
||||
gzip -dc "${ARC_PATH}/bzImage-template-v4.gz" >"${ZIMAGE_MOD}" || exit 1
|
||||
|
||||
dd if="${VMLINUX_MOD}" of="${ZIMAGE_MOD}" bs=16494 seek=1 conv=notrunc || exit 1
|
||||
file_size_le "${VMLINUX_MOD}" | dd of="${ZIMAGE_MOD}" bs=15745134 seek=1 conv=notrunc || exit 1
|
||||
file_size_le "${VMLINUX_MOD}" | dd of="${ZIMAGE_MOD}" bs=15745244 seek=1 conv=notrunc || exit 1
|
||||
|
||||
RUN_SIZE=$(objdump -h ${VMLINUX_MOD} | sh "${ARC_PATH}/calc_run_size.sh")
|
||||
size_le ${RUN_SIZE} | dd of=${ZIMAGE_MOD} bs=15745210 seek=1 conv=notrunc|| exit 1
|
||||
size_le $(($((16#$(crc32 "${ZIMAGE_MOD}" | awk '{print $1}'))) ^ 0xFFFFFFFF)) | dd of="${ZIMAGE_MOD}" conv=notrunc oflag=append || exit 1
|
||||
RUN_SIZE=$(objdump -h "${VMLINUX_MOD}" | sh "${ARC_PATH}/calc_run_size.sh")
|
||||
size_le "${RUN_SIZE}" | dd of="${ZIMAGE_MOD}" bs=15745210 seek=1 conv=notrunc || exit 1
|
||||
size_le "$((16#$(crc32 "${ZIMAGE_MOD}" | awk '{print $1}') ^ 0xFFFFFFFF))" | dd of="${ZIMAGE_MOD}" conv=notrunc oflag=append || exit 1
|
||||
else
|
||||
# Kernel version 5.x
|
||||
gzip -dc "${ARC_PATH}/bzImage-template-v5.gz" >"${ZIMAGE_MOD}" || exit 1
|
||||
@@ -76,7 +66,7 @@ else
|
||||
dd if="${VMLINUX_MOD}" of="${ZIMAGE_MOD}" bs=14561 seek=1 conv=notrunc || exit 1
|
||||
file_size_le "${VMLINUX_MOD}" | dd of="${ZIMAGE_MOD}" bs=34463421 seek=1 conv=notrunc || exit 1
|
||||
file_size_le "${VMLINUX_MOD}" | dd of="${ZIMAGE_MOD}" bs=34479132 seek=1 conv=notrunc || exit 1
|
||||
# RUN_SIZE=$(objdump -h ${VMLINUX_MOD} | sh "${ARC_PATH}/calc_run_size.sh")
|
||||
# size_le ${RUN_SIZE} | dd of=${ZIMAGE_MOD} bs=34626904 seek=1 conv=notrunc || exit 1
|
||||
size_le $(($((16#$(crc32 "${ZIMAGE_MOD}" | awk '{print $1}'))) ^ 0xFFFFFFFF)) | dd of="${ZIMAGE_MOD}" conv=notrunc oflag=append || exit 1
|
||||
# RUN_SIZE=$(objdump -h "${VMLINUX_MOD}" | sh "${ARC_PATH}/calc_run_size.sh")
|
||||
# size_le "${RUN_SIZE}" | dd of="${ZIMAGE_MOD}" bs=34626904 seek=1 conv=notrunc || exit 1
|
||||
size_le "$((16#$(crc32 "${ZIMAGE_MOD}" | awk '{print $1}') ^ 0xFFFFFFFF))" | dd of="${ZIMAGE_MOD}" conv=notrunc oflag=append || exit 1
|
||||
fi
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
[[ -z "${ARC_PATH}" || ! -d "${ARC_PATH}/include" ]] && ARC_PATH="$(cd "$(dirname "${BASH_SOURCE[0]}")" 2>/dev/null && pwd)"
|
||||
|
||||
. ${ARC_PATH}/include/functions.sh
|
||||
. "${ARC_PATH}/include/functions.sh"
|
||||
|
||||
set -o pipefail # Get exit code from process piped
|
||||
|
||||
@@ -23,11 +23,11 @@ if [ "${KERNEL}" = "custom" ]; then
|
||||
gzip -dc "${CUSTOM_PATH}/bzImage-${PLATFORM}-${KVERP}.gz" >"${MOD_ZIMAGE_FILE}"
|
||||
else
|
||||
# Extract vmlinux
|
||||
${ARC_PATH}/bzImage-to-vmlinux.sh "${ORI_ZIMAGE_FILE}" "${TMP_PATH}/vmlinux" >"${LOG_FILE}" 2>&1 || dieLog
|
||||
"${ARC_PATH}/bzImage-to-vmlinux.sh" "${ORI_ZIMAGE_FILE}" "${TMP_PATH}/vmlinux" >"${LOG_FILE}" 2>&1 || dieLog
|
||||
# Patch boot params and ramdisk check
|
||||
${ARC_PATH}/kpatch "${TMP_PATH}/vmlinux" "${TMP_PATH}/vmlinux-mod" >"${LOG_FILE}" 2>&1 || dieLog
|
||||
"${ARC_PATH}/kpatch" "${TMP_PATH}/vmlinux" "${TMP_PATH}/vmlinux-mod" >"${LOG_FILE}" 2>&1 || dieLog
|
||||
# rebuild zImage
|
||||
${ARC_PATH}/vmlinux-to-bzImage.sh "${TMP_PATH}/vmlinux-mod" "${MOD_ZIMAGE_FILE}" >"${LOG_FILE}" 2>&1 || dieLog
|
||||
"${ARC_PATH}/vmlinux-to-bzImage.sh" "${TMP_PATH}/vmlinux-mod" "${MOD_ZIMAGE_FILE}" >"${LOG_FILE}" 2>&1 || dieLog
|
||||
fi
|
||||
|
||||
sync
|
||||
Reference in New Issue
Block a user