armbian-next: tune logging: unmounting, u-boot prep/source/install; traps; extensions
This commit is contained in:
parent
ff4b5069ce
commit
1636a2afea
@ -243,7 +243,7 @@ initialize_extension_manager() {
|
||||
|
||||
cleanup_extension_manager() {
|
||||
if [[ -f "${fragment_manager_cleanup_file}" ]]; then
|
||||
display_alert "Cleaning up" "extension manager" "info"
|
||||
display_alert "Cleaning up" "extension manager" "debug"
|
||||
# shellcheck disable=SC1090 # dynamic source, thanks, shellcheck
|
||||
source "${fragment_manager_cleanup_file}" # this will unset all the functions.
|
||||
rm -f "${fragment_manager_cleanup_file}" # also remove the file.
|
||||
|
||||
@ -34,12 +34,13 @@ umount_chroot() {
|
||||
done
|
||||
}
|
||||
|
||||
# demented recursive version, for final umount.
|
||||
# demented recursive version, for final umount. call: umount_chroot_recursive /some/dir "DESCRIPTION"
|
||||
function umount_chroot_recursive() {
|
||||
if [[ ! -d "${1}" ]]; then # only even try if target is a directory
|
||||
return 0
|
||||
fi
|
||||
local target
|
||||
|
||||
local target description="${2:-"UNKNOWN"}"
|
||||
target="$(realpath "$1")/" # normalize, make sure to have slash as last element
|
||||
|
||||
if [[ ! -d "${target}" ]]; then # only even try if target is a directory
|
||||
@ -47,7 +48,7 @@ function umount_chroot_recursive() {
|
||||
elif [[ "${target}" == "/" ]]; then # make sure we're not trying to umount root itself.
|
||||
return 0
|
||||
fi
|
||||
display_alert "Unmounting recursively" "${target}" ""
|
||||
display_alert "Unmounting recursively" "${description} - be patient" ""
|
||||
sync # sync. coalesce I/O. wait for writes to flush to disk. it might take a second.
|
||||
# First, try to umount some well-known dirs, in a certain order. for speed.
|
||||
local -a well_known_list=("dev/pts" "dev" "proc" "sys" "boot/efi" "boot/firmware" "boot" "tmp" ".")
|
||||
@ -68,6 +69,9 @@ function umount_chroot_recursive() {
|
||||
tries=$((tries + 1))
|
||||
done
|
||||
|
||||
display_alert "Unmounted OK after ${tries} attempt(s)" "$target" "info"
|
||||
# if more than one try..
|
||||
if [[ $tries -gt 1 ]]; then
|
||||
display_alert "Unmounted OK after ${tries} attempt(s)" "${description}" "info"
|
||||
fi
|
||||
return 0
|
||||
}
|
||||
|
||||
@ -52,31 +52,31 @@ function check_loop_device_internal() {
|
||||
}
|
||||
|
||||
# write_uboot_to_loop_image <loopdev>
|
||||
# @TODO: isnt this supposed to be u-boot related? why in loop.sh?
|
||||
write_uboot_to_loop_image() {
|
||||
function write_uboot_to_loop_image() {
|
||||
|
||||
local loop=$1 revision
|
||||
display_alert "Preparing u-boot bootloader" "$loop" "info"
|
||||
TEMP_DIR=$(mktemp -d) # set-e is in effect. no need to exit on errors explicitly
|
||||
chmod 700 ${TEMP_DIR}
|
||||
revision=${REVISION}
|
||||
declare loop=$1
|
||||
display_alert "Preparing u-boot bootloader" "LOOP=${loop} - ${CHOSEN_UBOOT}" "info"
|
||||
|
||||
declare TEMP_DIR revision="${REVISION}"
|
||||
TEMP_DIR="$(mktemp -d)" # Subject to TMPDIR, so common trap applies
|
||||
chmod 700 "${TEMP_DIR}"
|
||||
if [[ -n $UBOOT_REPO_VERSION ]]; then
|
||||
revision=${UBOOT_REPO_VERSION}
|
||||
run_host_command_logged dpkg -x "${DEB_STORAGE}/linux-u-boot-${BOARD}-${BRANCH}_${revision}_${ARCH}.deb" ${TEMP_DIR}/
|
||||
run_host_command_logged dpkg -x "${DEB_STORAGE}/linux-u-boot-${BOARD}-${BRANCH}_${revision}_${ARCH}.deb" "${TEMP_DIR}"/
|
||||
else
|
||||
run_host_command_logged dpkg -x "${DEB_STORAGE}/${CHOSEN_UBOOT}_${revision}_${ARCH}.deb" ${TEMP_DIR}/
|
||||
run_host_command_logged dpkg -x "${DEB_STORAGE}/${CHOSEN_UBOOT}_${revision}_${ARCH}.deb" "${TEMP_DIR}"/
|
||||
fi
|
||||
|
||||
if [[ ! -f "${TEMP_DIR}/usr/lib/u-boot/platform_install.sh" ]]; then
|
||||
exit_with_error "Missing ${TEMP_DIR}/usr/lib/u-boot/platform_install.sh"
|
||||
fi
|
||||
|
||||
display_alert "Sourcing u-boot install functions" "$loop" "info"
|
||||
source ${TEMP_DIR}/usr/lib/u-boot/platform_install.sh
|
||||
display_alert "Sourcing u-boot install functions" "${CHOSEN_UBOOT}" "info"
|
||||
source "${TEMP_DIR}"/usr/lib/u-boot/platform_install.sh
|
||||
set -e # make sure, we just included something that might disable it
|
||||
|
||||
display_alert "Writing u-boot bootloader" "$loop" "info"
|
||||
write_uboot_platform "${TEMP_DIR}${DIR}" "$loop" # @TODO: rpardini: what is ${DIR} ?
|
||||
write_uboot_platform "${TEMP_DIR}${DIR}" "$loop" # important: DIR is set in platform_install.sh sourced above.
|
||||
|
||||
export UBOOT_CHROOT_DIR="${TEMP_DIR}${DIR}"
|
||||
|
||||
@ -88,7 +88,8 @@ write_uboot_to_loop_image() {
|
||||
Consider that `write_uboot_platform()` is also called board-side, when updating uboot, eg: nand-sata-install.
|
||||
POST_WRITE_UBOOT_PLATFORM
|
||||
|
||||
#rm -rf ${TEMP_DIR}
|
||||
# cleanup
|
||||
rm -rf "${TEMP_DIR}"
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
@ -74,14 +74,16 @@ create_image_from_sdcard_rootfs() {
|
||||
Called before unmounting both `/root` and `/boot`.
|
||||
PRE_UMOUNT_FINAL_IMAGE
|
||||
|
||||
# Check the partition table after the uboot code has been written
|
||||
display_alert "Partition table after write_uboot" "$LOOP" "debug"
|
||||
run_host_command_logged sfdisk -l "${LOOP}" # @TODO: use asset..
|
||||
if [[ "${SHOW_DEBUG}" == "yes" ]]; then
|
||||
# Check the partition table after the uboot code has been written
|
||||
display_alert "Partition table after write_uboot" "$LOOP" "debug"
|
||||
run_host_command_logged sfdisk -l "${LOOP}" # @TODO: use asset..
|
||||
fi
|
||||
|
||||
run_host_command_logged sync
|
||||
|
||||
umount_chroot_recursive "${MOUNT}"
|
||||
[[ $CRYPTROOT_ENABLE == yes ]] && cryptsetup luksClose $ROOT_MAPPER
|
||||
umount_chroot_recursive "${MOUNT}" "MOUNT"
|
||||
[[ $CRYPTROOT_ENABLE == yes ]] && cryptsetup luksClose "$ROOT_MAPPER"
|
||||
|
||||
call_extension_method "post_umount_final_image" "config_post_umount_final_image" <<- 'POST_UMOUNT_FINAL_IMAGE'
|
||||
*allow config to hack into the image after the unmount*
|
||||
|
||||
@ -90,7 +90,7 @@ function build_rootfs_and_image() {
|
||||
fi
|
||||
|
||||
# Completely and recursively unmount the directory. This will remove the tmpfs mount too
|
||||
umount_chroot_recursive "${SDCARD}"
|
||||
umount_chroot_recursive "${SDCARD}" "SDCARD"
|
||||
|
||||
# Remove the dir
|
||||
[[ -d "${SDCARD}" ]] && rm -rf --one-file-system "${SDCARD}"
|
||||
@ -111,10 +111,10 @@ function trap_handler_cleanup_rootfs_and_image() {
|
||||
|
||||
cd "${SRC}" || echo "Failed to cwd to ${SRC}" # Move pwd away, so unmounts work
|
||||
# those will loop until they're unmounted.
|
||||
umount_chroot_recursive "${SDCARD}" || true
|
||||
umount_chroot_recursive "${MOUNT}" || true
|
||||
umount_chroot_recursive "${SDCARD}" "SDCARD" || true
|
||||
umount_chroot_recursive "${MOUNT}" "MOUNT" || true
|
||||
|
||||
# unmount tmpfs mounted on SDCARD if it exists.
|
||||
# unmount tmpfs mounted on SDCARD if it exists. #@TODO: move to new tmpfs-utils scheme
|
||||
mountpoint -q "${SDCARD}" && umount "${SDCARD}"
|
||||
|
||||
mountpoint -q "${SRC}"/cache/toolchain && umount -l "${SRC}"/cache/toolchain >&2 # @TODO: why does Igor uses lazy umounts? nfs?
|
||||
|
||||
Loading…
Reference in New Issue
Block a user