d1-riscv-arch-image-builder
d1-riscv-arch-image-builder copied to clipboard
Script to only install kernel and boot binaries on SDcard
Here is a script that allow to only install kernel and boot, to upgrade/downgrade an existing system and don't have to format the whole fs.
commit 85b9eeb7bc0121849fc7be4e5e6d9d19b36f115f
Author: Popolon <[email protected]>
Date: Mon Dec 26 20:36:33 2022 +0100
add upgrading kernel script
diff --git a/3_upgrade_disk_kernel.sh b/3_upgrade_disk_kernel.sh
new file mode 100755
index 0000000..1c2e06a
--- /dev/null
+++ b/3_upgrade_disk_kernel.sh
@@ -0,0 +1,107 @@
+#!/usr/bin/sh
+
+set -e
+# set -x
+
+. ./consts.sh
+
+check_root_fs() {
+ if [ ! -f "${ROOT_FS}" ] ; then
+ wget "${ROOT_FS_DL}"
+ fi
+}
+
+check_sd_card_is_block_device() {
+ _DEVICE=${1}
+
+ if [ -z "${_DEVICE}" ] || [ ! -b "${_DEVICE}" ] ; then
+ echo "Error: '${_DEVICE}' is empty or not a block device"
+ exit 1
+ fi
+}
+
+check_required_file() {
+ if [ ! -f "${1}" ] ; then
+ echo "Missing file: ${1}, did you compile everyhing first?"
+ exit 1
+ fi
+}
+
+probe_partition_separator() {
+ _DEVICE=${1}
+
+ [ -b "${_DEVICE}p1" ] && echo 'p' || echo ''
+}
+
+DEVICE=${1}
+
+if [ "${USE_CHROOT}" != 0 ] ; then
+ # check_deps for arch-chroot on non RISC-V host
+ for DEP in ${INSTALL_DEPS} ; do
+ check_deps ${DEP}
+ done
+fi
+check_sd_card_is_block_device "${DEVICE}"
+check_root_fs
+for FILE in 8723ds.ko u-boot-sunxi-with-spl.bin Image.gz Image; do
+ check_required_file "${OUT_DIR}/${FILE}"
+done
+
+# get kernel version
+cd build/linux-build
+KERNEL_RELEASE=$(make ARCH="${ARCH}" -s kernelversion)
+cd ../../
+
+# install kernel and modules
+echo "replacing current kernel on ${DEVICE}, by ${KERNEL_RELEASE} on it!"
+printf "Continue? (y/N): "
+read -r confirm && [ "${confirm}" = "y" ] || [ "${confirm}" = "Y" ] || exit 1
+
+# flash boot things
+${SUDO} dd if="${OUT_DIR}/u-boot-sunxi-with-spl.bin" of="${DEVICE}" bs=1024 seek=128
+
+# mount it
+mkdir -p "${MNT}"
+${SUDO} mount "${DEVICE}${PART_IDENTITYFIER}2" "${MNT}"
+${SUDO} mkdir -p "${MNT}/boot"
+${SUDO} mount "${DEVICE}${PART_IDENTITYFIER}1" "${MNT}/boot"
+
+# install kernel and modules
+${SUDO} cp "${OUT_DIR}/Image.gz" "${OUT_DIR}/Image" "${MNT}/boot/"
+cd build/linux-build
+echo "make in `pwd`"
+${SUDO} make ARCH="${ARCH}" INSTALL_MOD_PATH="../../${MNT}" KERNELRELEASE="${KERNEL_RELEASE}" modules_install
+cd ../..
+${SUDO} install -D -p -m 644 "${OUT_DIR}/8723ds.ko" "${MNT}/lib/modules/${KERNEL_RELEASE}/kernel/drivers/net/wireless/8723ds.ko"
+
+${SUDO} rm "${MNT}/lib/modules/${KERNEL_RELEASE}/build"
+${SUDO} rm "${MNT}/lib/modules/${KERNEL_RELEASE}/source"
+
+${SUDO} depmod -a -b "${MNT}" "${KERNEL_RELEASE}"
+echo '8723ds' >> 8723ds.conf
+${SUDO} cp 8723ds.conf "${MNT}/etc/modules-load.d/"
+rm 8723ds.conf
+
+# install U-Boot
+if [ "${BOOT_METHOD}" = 'script' ] ; then
+ ${SUDO} cp "${OUT_DIR}/boot.scr" "${MNT}/boot/"
+elif [ "${BOOT_METHOD}" = 'extlinux' ] ; then
+ ${SUDO} mkdir -p "${MNT}/boot/extlinux"
+ cat << EOF > extlinux.conf
+label default
+ linux ../Image
+ append earlycon=sbi console=ttyS0,115200n8 root=/dev/mmcblk0p2 rootwait cma=96M
+EOF
+ ${SUDO} cp extlinux.conf "${MNT}/boot/extlinux/extlinux.conf"
+ rm extlinux.conf
+fi
+
+# umount card
+${SUDO} umount -R "${MNT}"
+
+# done
+ echo ''
+ echo 'Done!'
+fi
+
+exit 0
Thanks! This patch looks broken though:
- why is there a
fiin the 3rd last line? ${INSTALL_DEPS}is not defined