diff --git a/files/initrd/opt/arc/arc.sh b/files/initrd/opt/arc/arc.sh index 8c4aa63..45fd2bc 100755 --- a/files/initrd/opt/arc/arc.sh +++ b/files/initrd/opt/arc/arc.sh @@ -551,13 +551,6 @@ function make() { fi clear livepatch - if [ ${FAIL} -eq 1 ]; then - echo "Patching DSM Image failed! Please stay patient for Update." - sleep 5 - return 1 - else - echo "DSM Image patched - Ready!" - fi sleep 3 if [ -f "${ORI_ZIMAGE_FILE}" ] && [ -f "${ORI_RDGZ_FILE}" ] && [ -f "${MOD_ZIMAGE_FILE}" ] && [ -f "${MOD_RDGZ_FILE}" ]; then # Build is done diff --git a/files/initrd/opt/arc/boot.sh b/files/initrd/opt/arc/boot.sh index 4d8cdb3..6d99f63 100755 --- a/files/initrd/opt/arc/boot.sh +++ b/files/initrd/opt/arc/boot.sh @@ -33,10 +33,6 @@ if [ "${ZIMAGE_HASH_CUR}" != "${ZIMAGE_HASH}" ] || [ "${RAMDISK_HASH_CUR}" != "$ echo -e "\033[1;34mDSM zImage/Ramdisk changed!\033[0m" echo livepatch - if [ ${FAIL} -eq 1 ]; then - echo -e "\033[1;34mPatching DSM Files failed! Please stay patient for Update.\033[0m" 0 0 - exit 1 - fi echo fi diff --git a/files/initrd/opt/arc/bzImage-to-vmlinux.sh b/files/initrd/opt/arc/bzImage-to-vmlinux.sh index b2096a6..5241e92 100755 --- a/files/initrd/opt/arc/bzImage-to-vmlinux.sh +++ b/files/initrd/opt/arc/bzImage-to-vmlinux.sh @@ -1,16 +1,16 @@ -#!/bin/bash +#!/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 )) +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 \ No newline at end of file diff --git a/files/initrd/opt/arc/include/functions.sh b/files/initrd/opt/arc/include/functions.sh index ec1ad23..f6b3322 100755 --- a/files/initrd/opt/arc/include/functions.sh +++ b/files/initrd/opt/arc/include/functions.sh @@ -319,6 +319,7 @@ function livepatch() { else ZIMAGE_HASH_CUR="$(sha256sum "${ORI_ZIMAGE_FILE}" | awk '{print $1}')" writeConfigKey "zimage-hash" "${ZIMAGE_HASH_CUR}" "${USER_CONFIG_FILE}" + FAIL=0 fi # Patch Ramdisk if ! ${ARC_PATH}/ramdisk-patch.sh; then @@ -326,6 +327,7 @@ function livepatch() { else RAMDISK_HASH_CUR="$(sha256sum "${ORI_RDGZ_FILE}" | awk '{print $1}')" writeConfigKey "ramdisk-hash" "${RAMDISK_HASH_CUR}" "${USER_CONFIG_FILE}" + FAIL=0 fi # Looking for Update if [ ${FAIL} -eq 1 ]; then @@ -372,6 +374,13 @@ function livepatch() { FAIL=0 fi fi + if [ ${FAIL} -eq 1 ]; then + echo -e "\033[1;34mPatching DSM Files failed! Please stay patient for Update.\033[0m" 0 0 + sleep 5 + exit 1 + else + echo "DSM Image patched - Ready!" + fi } ############################################################################### diff --git a/files/initrd/opt/arc/vmlinux-to-bzImage.sh b/files/initrd/opt/arc/vmlinux-to-bzImage.sh index 408d424..d4a27b1 100755 --- a/files/initrd/opt/arc/vmlinux-to-bzImage.sh +++ b/files/initrd/opt/arc/vmlinux-to-bzImage.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/usr/bin/env bash # Based on code and ideas from @jumkey [ -z "${ARC_PATH}" ] || [ ! -d "${ARC_PATH}/include" ] && ARC_PATH="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)" @@ -12,39 +12,39 @@ KVER="$(readModelKey "${MODEL}" "productvers.[${PRODUCTVER}].kver")" # 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 () { +file_size_le() { printf $( - dec_size=0; + dec_size=0 for F in "${@}"; do - fsize=$(stat -c "%s" ${F}); - dec_size=$((${dec_size}+${fsize})); - done; + fsize=$(stat -c "%s" ${F}) + dec_size=$((${dec_size} + ${fsize})) + 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; - } + read -r ch0 ch1 ch2 ch3 + for ch in ${ch3} ${ch2} ${ch1} ${ch0}; do + printf '%s%03o' '\' $((0x${ch})) + done + } ) } -size_le () { +size_le() { printf $( 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; - } + read -r ch0 ch1 ch2 ch3 + for ch in ${ch3} ${ch2} ${ch1} ${ch0}; do + printf '%s%03o' '\' $((0x${ch})) + done + } ) } SCRIPT_DIR=$(dirname $0) VMLINUX_MOD=${1} ZIMAGE_MOD=${2} KVER_MAJOR=${KVER:0:1} -if [ ${KVER_MAJOR} -eq 4 ]; then +if [ ${KVER_MAJOR} -eq 4 ] || [ ${KVER_MAJOR} -eq 3 ]; then # Kernel version 4.x or 3.x (bromolow) #zImage_head 16494 #payload( @@ -67,7 +67,7 @@ if [ ${KVER_MAJOR} -eq 4 ]; then file_size_le "${VMLINUX_MOD}" | dd of="${ZIMAGE_MOD}" bs=15745244 seek=1 conv=notrunc >"${LOG_FILE}" 2>&1 || dieLog RUN_SIZE=$(objdump -h ${VMLINUX_MOD} | sh "${SCRIPT_DIR}/calc_run_size.sh") - size_le ${RUN_SIZE} | dd of="${ZIMAGE_MOD}" bs=15745210 seek=1 conv=notrunc >"${LOG_FILE}" 2>&1 || dieLog + size_le ${RUN_SIZE} | dd of=${ZIMAGE_MOD} bs=15745210 seek=1 conv=notrunc >"${LOG_FILE}" 2>&1 || dieLog size_le $(($((16#$(crc32 "${ZIMAGE_MOD}" | awk '{print$1}'))) ^ 0xFFFFFFFF)) | dd of="${ZIMAGE_MOD}" conv=notrunc oflag=append >"${LOG_FILE}" 2>&1 || dieLog else # Kernel version 5.x @@ -76,7 +76,7 @@ else dd if="${VMLINUX_MOD}" of="${ZIMAGE_MOD}" bs=14561 seek=1 conv=notrunc >"${LOG_FILE}" 2>&1 || dieLog file_size_le "${VMLINUX_MOD}" | dd of="${ZIMAGE_MOD}" bs=34463421 seek=1 conv=notrunc >"${LOG_FILE}" 2>&1 || dieLog file_size_le "${VMLINUX_MOD}" | dd of="${ZIMAGE_MOD}" bs=34479132 seek=1 conv=notrunc >"${LOG_FILE}" 2>&1 || dieLog -# RUN_SIZE=`objdump -h ${VMLINUX_MOD} | sh "${SCRIPT_DIR}/calc_run_size.sh"` -# size_le ${RUN_SIZE} | dd of=${ZIMAGE_MOD} bs=34626904 seek=1 conv=notrunc >"${LOG_FILE}" 2>&1 || dieLog + # RUN_SIZE=`objdump -h ${VMLINUX_MOD} | sh "${SCRIPT_DIR}/calc_run_size.sh"` + # size_le ${RUN_SIZE} | dd of=${ZIMAGE_MOD} bs=34626904 seek=1 conv=notrunc >"${LOG_FILE}" 2>&1 || dieLog size_le $(($((16#$(crc32 "${ZIMAGE_MOD}" | awk '{print$1}'))) ^ 0xFFFFFFFF)) | dd of="${ZIMAGE_MOD}" conv=notrunc oflag=append >"${LOG_FILE}" 2>&1 || dieLog -fi +fi \ No newline at end of file