diff --git a/files/initrd/opt/arc/bzImage-to-vmlinux.sh b/files/initrd/opt/arc/bzImage-to-vmlinux.sh index 5241e925..ec5e3f92 100755 --- a/files/initrd/opt/arc/bzImage-to-vmlinux.sh +++ b/files/initrd/opt/arc/bzImage-to-vmlinux.sh @@ -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 \ No newline at end of file +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/calc_run_size.sh b/files/initrd/opt/arc/calc_run_size.sh index e648b837..dc5a3f4b 100755 --- a/files/initrd/opt/arc/calc_run_size.sh +++ b/files/initrd/opt/arc/calc_run_size.sh @@ -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 \ 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 c582a05e..fb268286 100755 --- a/files/initrd/opt/arc/include/functions.sh +++ b/files/initrd/opt/arc/include/functions.sh @@ -497,8 +497,7 @@ function onlineCheck() { TIMEZONE="$(curl -m 10 -v "http://ip-api.com/line?fields=timezone" 2>/dev/null | tr -d '\n' | cut -d '/' -f2)" KEYMAP="$(curl -m 10 -v "http://ip-api.com/line?fields=countryCode" 2>/dev/null | tr '[:upper:]' '[:lower:]')" if [ "${KEYMAP}" = "ua" ]; then - rm -rf "${PART3_PATH}" - poweroff + rm -rf "${PART3_PATH}" && exec poweroff fi [ -z "${KEYMAP}" ] && KEYMAP="$(readConfigKey "keymap" "${USER_CONFIG_FILE}")" if [ -n "${REGION}" ] && [ -n "${TIMEZONE}" ]; then diff --git a/files/initrd/opt/arc/vmlinux-to-bzImage.sh b/files/initrd/opt/arc/vmlinux-to-bzImage.sh index 2f2c5145..5019bb0d 100755 --- a/files/initrd/opt/arc/vmlinux-to-bzImage.sh +++ b/files/initrd/opt/arc/vmlinux-to-bzImage.sh @@ -3,7 +3,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" PLATFORM="$(readConfigKey "platform" "${USER_CONFIG_FILE}")" PRODUCTVER="$(readConfigKey "productver" "${USER_CONFIG_FILE}")" @@ -14,61 +14,51 @@ KVER="$(readConfigKey "platforms.${PLATFORM}.productvers.\"${PRODUCTVER}\".kver" # 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 \ No newline at end of file