From f9b33836981ee798905f4036b89550890e7fcd67 Mon Sep 17 00:00:00 2001 From: ading2210 Date: Mon, 13 May 2024 11:03:17 -0700 Subject: [PATCH] don't modify shim and reco images at all --- build_complete.sh | 4 ++++ image_utils.sh | 20 ++++++++++++++------ patch_rootfs.sh | 6 ++---- 3 files changed, 20 insertions(+), 10 deletions(-) diff --git a/build_complete.sh b/build_complete.sh index d10c525..0cd67d6 100755 --- a/build_complete.sh +++ b/build_complete.sh @@ -1,6 +1,7 @@ #!/bin/bash . ./common.sh +. ./image_utils.sh print_help() { echo "Usage: ./build_complete.sh board_name" @@ -138,6 +139,9 @@ rm -rf $final_image retry_cmd ./build.sh $final_image $shim_bin $rootfs_dir "quiet=$quiet" echo "build complete! the final disk image is located at $final_image" +echo "cleaning up" +clean_loops + if [ "$compress_img" ]; then image_zip="$data_dir/shimboot_$board.zip" echo "compressing disk image into a zip file" diff --git a/image_utils.sh b/image_utils.sh index d449efb..779b3e2 100755 --- a/image_utils.sh +++ b/image_utils.sh @@ -12,11 +12,6 @@ create_loop() { echo $loop_device } -#original shim rootfses have a non standard ext2 filesystem -make_mountable() { - printf '\000' | dd of=$1 seek=$((0x464 + 3)) conv=notrunc count=1 bs=1 status=none -} - #set required flags on the kernel partition make_bootable() { cgpt add -i 2 -S 1 -T 5 -P 10 -l kernel $1 @@ -79,7 +74,7 @@ safe_mount() { rm -rf $dest mkdir -p $dest if [ "$opts" ]; then - mount $source $dest -o $dest + mount $source $dest -o $opts else mount $source $dest fi @@ -151,4 +146,17 @@ patch_initramfs() { cp -r bootloader/* "${initramfs_path}/" find ${initramfs_path}/bin -name "*" -exec chmod +x {} \; +} + +#clean up unused loop devices +clean_loops() { + local loop_devices="$(losetup -a | awk -F':' {'print $1'})" + for loop_device in $loop_devices; do + local mountpoints="$(cat /proc/mounts | grep "$loop_device")" + if [ ! "$mountpoints" ]; then + losetup -d $loop_device + else + echo "warning: not removing $loop_device because it is still mounted" + fi + done } \ No newline at end of file diff --git a/patch_rootfs.sh b/patch_rootfs.sh index ae679ca..7e941d9 100755 --- a/patch_rootfs.sh +++ b/patch_rootfs.sh @@ -67,13 +67,11 @@ reco_rootfs="/tmp/reco_rootfs" echo "mounting shim" shim_loop=$(create_loop "${shim_path}") -make_mountable "${shim_loop}p3" -safe_mount "${shim_loop}p3" $shim_rootfs +safe_mount "${shim_loop}p3" $shim_rootfs ro echo "mounting recovery image" reco_loop=$(create_loop "${reco_path}") -make_mountable "${reco_loop}p3" -safe_mount "${reco_loop}p3" $reco_rootfs +safe_mount "${reco_loop}p3" $reco_rootfs ro echo "copying modules to rootfs" copy_modules $shim_rootfs $reco_rootfs $target_rootfs