2023-10-06 23:28:40 -05:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
#patch the target rootfs to add any needed drivers
|
|
|
|
|
2024-04-29 02:53:01 -05:00
|
|
|
. ./common.sh
|
2023-12-22 21:15:24 -06:00
|
|
|
. ./image_utils.sh
|
2023-10-20 07:04:19 -05:00
|
|
|
|
|
|
|
print_help() {
|
|
|
|
echo "Usage: ./patch_rootfs.sh shim_path reco_path rootfs_dir"
|
|
|
|
}
|
|
|
|
|
2024-04-29 02:53:01 -05:00
|
|
|
assert_root
|
2024-04-29 12:27:08 -05:00
|
|
|
assert_deps "git gunzip depmod"
|
2024-04-29 02:53:01 -05:00
|
|
|
assert_args "$3"
|
2023-10-20 07:04:19 -05:00
|
|
|
|
2023-10-20 05:38:45 -05:00
|
|
|
copy_modules() {
|
2024-01-25 15:19:25 -06:00
|
|
|
local shim_rootfs=$(realpath -m $1)
|
|
|
|
local reco_rootfs=$(realpath -m $2)
|
|
|
|
local target_rootfs=$(realpath -m $3)
|
2023-10-06 23:28:40 -05:00
|
|
|
|
2023-10-21 04:06:52 -05:00
|
|
|
rm -rf "${target_rootfs}/lib/modules"
|
|
|
|
cp -r "${shim_rootfs}/lib/modules" "${target_rootfs}/lib/modules"
|
|
|
|
|
|
|
|
mkdir -p "${target_rootfs}/lib/firmware"
|
2023-10-20 07:04:19 -05:00
|
|
|
cp -r --remove-destination "${shim_rootfs}/lib/firmware/"* "${target_rootfs}/lib/firmware/"
|
2023-10-20 07:39:43 -05:00
|
|
|
cp -r --remove-destination "${reco_rootfs}/lib/firmware/"* "${target_rootfs}/lib/firmware/"
|
2023-10-21 01:59:53 -05:00
|
|
|
|
|
|
|
mkdir -p "${target_rootfs}/lib/modprobe.d/"
|
|
|
|
mkdir -p "${target_rootfs}/etc/modprobe.d/"
|
2023-10-20 05:38:45 -05:00
|
|
|
cp -r "${reco_rootfs}/lib/modprobe.d/"* "${target_rootfs}/lib/modprobe.d/"
|
|
|
|
cp -r "${reco_rootfs}/etc/modprobe.d/"* "${target_rootfs}/etc/modprobe.d/"
|
2024-04-29 02:53:01 -05:00
|
|
|
|
|
|
|
#decompress kernel modules if necessary - debian won't recognize these otherwise
|
2024-04-29 04:02:30 -05:00
|
|
|
local compressed_files="$(find "${target_rootfs}/lib/modules" -name '*.gz')"
|
|
|
|
if [ "$compressed_files" ]; then
|
2024-04-29 12:27:08 -05:00
|
|
|
echo "$compressed_files" | xargs gunzip
|
|
|
|
for kernel_dir in "$target_rootfs/lib/modules/"*; do
|
|
|
|
local version="$(basename "$kernel_dir")"
|
|
|
|
depmod -b "$target_rootfs" "$version"
|
|
|
|
done
|
2024-04-29 04:02:30 -05:00
|
|
|
fi
|
2023-10-06 23:28:40 -05:00
|
|
|
}
|
|
|
|
|
2023-10-20 07:04:19 -05:00
|
|
|
copy_firmware() {
|
|
|
|
local firmware_path="/tmp/chromium-firmware"
|
2024-01-25 15:19:25 -06:00
|
|
|
local target_rootfs=$(realpath -m $1)
|
2023-10-20 07:04:19 -05:00
|
|
|
|
|
|
|
if [ ! -e "$firmware_path" ]; then
|
|
|
|
download_firmware $firmware_path
|
|
|
|
fi
|
|
|
|
|
2023-10-20 21:30:02 -05:00
|
|
|
cp -r --remove-destination "${firmware_path}/"* "${target_rootfs}/lib/firmware/"
|
2023-10-20 07:04:19 -05:00
|
|
|
}
|
|
|
|
|
2023-10-20 05:38:45 -05:00
|
|
|
download_firmware() {
|
|
|
|
local firmware_url="https://chromium.googlesource.com/chromiumos/third_party/linux-firmware"
|
2024-01-25 15:19:25 -06:00
|
|
|
local firmware_path=$(realpath -m $1)
|
2023-10-20 05:38:45 -05:00
|
|
|
|
|
|
|
git clone --branch master --depth=1 "${firmware_url}" $firmware_path
|
2023-10-20 07:04:19 -05:00
|
|
|
}
|
|
|
|
|
2024-01-25 15:19:25 -06:00
|
|
|
shim_path=$(realpath -m $1)
|
|
|
|
reco_path=$(realpath -m $2)
|
|
|
|
target_rootfs=$(realpath -m $3)
|
2023-10-20 07:04:19 -05:00
|
|
|
shim_rootfs="/tmp/shim_rootfs"
|
|
|
|
reco_rootfs="/tmp/reco_rootfs"
|
|
|
|
|
|
|
|
echo "mounting shim"
|
|
|
|
shim_loop=$(create_loop "${shim_path}")
|
2024-05-13 13:03:17 -05:00
|
|
|
safe_mount "${shim_loop}p3" $shim_rootfs ro
|
2023-10-20 07:04:19 -05:00
|
|
|
|
|
|
|
echo "mounting recovery image"
|
|
|
|
reco_loop=$(create_loop "${reco_path}")
|
2024-05-13 13:03:17 -05:00
|
|
|
safe_mount "${reco_loop}p3" $reco_rootfs ro
|
2023-10-20 07:04:19 -05:00
|
|
|
|
|
|
|
echo "copying modules to rootfs"
|
|
|
|
copy_modules $shim_rootfs $reco_rootfs $target_rootfs
|
|
|
|
|
|
|
|
echo "downloading misc firmware"
|
|
|
|
copy_firmware $target_rootfs
|
|
|
|
|
|
|
|
echo "unmounting and cleaning up"
|
|
|
|
umount $shim_rootfs
|
|
|
|
umount $reco_rootfs
|
|
|
|
losetup -d $shim_loop
|
|
|
|
losetup -d $reco_loop
|
|
|
|
|
|
|
|
echo "done"
|