This commit is contained in:
Ing 2023-06-23 16:33:41 +08:00
parent ad528f0de2
commit e873c671ed
6 changed files with 41 additions and 45 deletions

View File

@ -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

View File

@ -1,4 +1,4 @@
#!/bin/sh
#!/usr/bin/env bash
#
# Calculate the amount of space needed to run the kernel, including room for
# the .bss and .brk sections.

View File

@ -5,8 +5,8 @@ set -e
. /opt/arpl/include/functions.sh
# Detect if has new local plugins to install/reinstall
for F in `ls ${CACHE_PATH}/*.addon 2>/dev/null`; do
ADDON=`basename "${F}" | sed 's|.addon||'`
for F in $(ls ${CACHE_PATH}/*.addon 2>/dev/null); do
ADDON=$(basename "${F}" | sed 's|.addon||')
rm -rf "${ADDONS_PATH}/${ADDON}"
mkdir -p "${ADDONS_PATH}/${ADDON}"
echo "Installing ${F} to ${ADDONS_PATH}/${ADDON}"

View File

@ -5,15 +5,13 @@
# be able to execute in the initramfs/preboot environment (so no bashism etc)
# All comments will be stripped, functions here should NOT start with brp_ as they're not part of the builder
if [ -z ${SED_PATH+x} ]; then
echo "Your SED_PATH variable is not set/is empty!"
exit 1
fi
##$1 from, $2 to, $3 file to path
_replace_in_file()
{
_replace_in_file() {
if grep -q "$1" "$3"; then
$SED_PATH -i "$3" -e "s#$1#$2#"
fi
@ -22,12 +20,11 @@ _replace_in_file()
# Replace/remove/add values in .conf K=V file
#
# Args: $1 name, $2 new_val, $3 path
_set_conf_kv()
{
_set_conf_kv() {
# Delete
if [ -z "$2" ]; then
$SED_PATH -i "$3" -e "s/^$1=.*$//"
return 0;
return 0
fi
# Replace
@ -37,5 +34,5 @@ _set_conf_kv()
fi
# Add if doesn't exist
echo "$1=\"$2\"" >> $3
echo "$1=\"$2\"" >>$3
}

View File

@ -4,8 +4,7 @@
# possible (which turns out to be via init/main.c => load_default_modules => load_default_elevator_module
# When the kernel is booted with "elevator=elevator" it will attempt to load a module "elevator-iosched"... and the rest
# should be obvious from the code below. DO NOT print anything here (kernel doesn't attach STDOUT)
for arg in "$@"
do
for arg in "$@"; do
if [ "$arg" = "elevator-iosched" ]; then
insmod /usr/lib/modules/rp.ko
rm /usr/lib/modules/rp.ko

View File

@ -1,44 +1,44 @@
#!/bin/sh
#!/usr/bin/env bash
# Based on code and ideas from @jumkey
. /opt/arpl/include/functions.sh
MODEL="`readConfigKey "model" "${USER_CONFIG_FILE}"`"
BUILD="`readConfigKey "build" "${USER_CONFIG_FILE}"`"
KVER="`readModelKey "${MODEL}" "builds.${BUILD}.kver"`"
MODEL="$(readConfigKey "model" "${USER_CONFIG_FILE}")"
BUILD="$(readConfigKey "build" "${USER_CONFIG_FILE}")"
KVER="$(readModelKey "${MODEL}" "builds.${BUILD}.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=$(expr ${dec_size} + ${fsize});
done;
fsize=$(stat -c "%s" ${F})
dec_size=$(expr ${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;
}
read 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 ch0 ch1 ch2 ch3;
for ch in ${ch3} ${ch2} ${ch1} ${ch0}; do
printf '%s%03o' '\' $((0x${ch}));
done;
}
read ch0 ch1 ch2 ch3
for ch in ${ch3} ${ch2} ${ch1} ${ch0}; do
printf '%s%03o' '\' $((0x${ch}))
done
}
)
}
SCRIPT_DIR=`dirname $0`
SCRIPT_DIR=$(dirname $0)
VMLINUX_MOD=${1}
ZIMAGE_MOD=${2}
KVER_MAJOR=${KVER:0:1}
@ -58,23 +58,23 @@ if [ $KVER_MAJOR -eq 4 ] || [ $KVER_MAJOR -eq 3 ]; then
# unknown 114460
#) 114570
#crc32 4
gzip -dc "${SCRIPT_DIR}/bzImage-template-v4.gz" > "${ZIMAGE_MOD}"
gzip -dc "${SCRIPT_DIR}/bzImage-template-v4.gz" >"${ZIMAGE_MOD}"
dd if="${VMLINUX_MOD}" of="${ZIMAGE_MOD}" bs=16494 seek=1 conv=notrunc >"${LOG_FILE}" 2>&1 || dieLog
file_size_le "${VMLINUX_MOD}" | dd of="${ZIMAGE_MOD}" bs=15745134 seek=1 conv=notrunc >"${LOG_FILE}" 2>&1 || dieLog
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"`
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 $(($((16#`crc32 "${ZIMAGE_MOD}" | awk '{print$1}'`)) ^ 0xFFFFFFFF)) | dd of="${ZIMAGE_MOD}" conv=notrunc oflag=append >"${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
gzip -dc "${SCRIPT_DIR}/bzImage-template-v5.gz" > "${ZIMAGE_MOD}"
gzip -dc "${SCRIPT_DIR}/bzImage-template-v5.gz" >"${ZIMAGE_MOD}"
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
size_le $(($((16#`crc32 "${ZIMAGE_MOD}" | awk '{print$1}'`)) ^ 0xFFFFFFFF)) | dd of="${ZIMAGE_MOD}" conv=notrunc oflag=append >"${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