2023-10-02 00:47:30 -05:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
#build the bootloader image
|
|
|
|
|
2024-04-24 16:54:52 -05:00
|
|
|
. ./common.sh
|
2023-12-21 00:09:41 -06:00
|
|
|
. ./image_utils.sh
|
2023-12-21 00:05:17 -06:00
|
|
|
. ./shim_utils.sh
|
2023-10-02 14:17:59 -05:00
|
|
|
|
2023-10-02 00:47:30 -05:00
|
|
|
print_help() {
|
2023-10-04 01:56:57 -05:00
|
|
|
echo "Usage: ./build.sh output_path shim_path rootfs_dir"
|
2023-10-02 00:47:30 -05:00
|
|
|
}
|
|
|
|
|
2024-04-24 16:54:52 -05:00
|
|
|
assert_root
|
2024-01-25 15:12:20 -06:00
|
|
|
assert_deps "cpio binwalk pcregrep realpath cgpt mkfs.ext4 mkfs.ext2 fdisk rsync"
|
2024-04-24 16:54:52 -05:00
|
|
|
assert_args "$3"
|
2024-01-30 15:13:03 -06:00
|
|
|
parse_args "$@"
|
2023-10-02 14:06:06 -05:00
|
|
|
|
2024-01-25 15:19:25 -06:00
|
|
|
output_path=$(realpath -m "${1}")
|
|
|
|
shim_path=$(realpath -m "${2}")
|
|
|
|
rootfs_dir=$(realpath -m "${3}")
|
2023-10-02 00:47:30 -05:00
|
|
|
|
|
|
|
echo "created loop device for shim"
|
2023-10-02 14:06:06 -05:00
|
|
|
shim_loop=$(create_loop "${shim_path}")
|
2023-10-02 00:47:30 -05:00
|
|
|
kernel_loop="${shim_loop}p2" #KERN-A should always be p2
|
|
|
|
|
|
|
|
echo "copying shim kernel to new file in /tmp"
|
|
|
|
kernel_dir=/tmp/shim_kernel
|
|
|
|
mkdir $kernel_dir -p
|
|
|
|
dd if=$kernel_loop of=$kernel_dir/kernel.bin bs=1M status=none
|
|
|
|
|
|
|
|
echo "extracting data from kernel"
|
|
|
|
initramfs_dir=/tmp/shim_initramfs
|
|
|
|
rm -rf $initramfs_dir
|
2023-12-21 00:05:17 -06:00
|
|
|
extract_initramfs $kernel_dir/kernel.bin $kernel_dir $initramfs_dir
|
2023-12-22 21:15:24 -06:00
|
|
|
losetup -d $shim_loop
|
2023-10-02 00:47:30 -05:00
|
|
|
|
2023-10-02 01:08:31 -05:00
|
|
|
echo "patching initramfs"
|
2023-10-02 14:17:59 -05:00
|
|
|
patch_initramfs $initramfs_dir
|
2023-10-02 01:08:31 -05:00
|
|
|
|
2023-10-02 17:57:49 -05:00
|
|
|
echo "creating disk image"
|
2023-10-06 12:29:10 -05:00
|
|
|
rootfs_size=$(du -sm $rootfs_dir | cut -f 1)
|
2023-12-25 21:33:28 -06:00
|
|
|
rootfs_part_size=$(($rootfs_size * 12 / 10))
|
2023-10-06 12:29:10 -05:00
|
|
|
#create a 20mb bootloader partition
|
2023-10-20 15:51:56 -05:00
|
|
|
#rootfs partition is 20% larger than its contents
|
2023-10-06 12:29:10 -05:00
|
|
|
create_image $output_path 20 $rootfs_part_size
|
2023-10-02 17:57:49 -05:00
|
|
|
|
|
|
|
echo "creating loop device for the image"
|
|
|
|
image_loop=$(create_loop ${output_path})
|
|
|
|
|
|
|
|
echo "creating partitions on the disk image"
|
|
|
|
create_partitions $image_loop "${kernel_dir}/kernel.bin"
|
|
|
|
|
|
|
|
echo "copying data into the image"
|
2024-01-30 15:13:03 -06:00
|
|
|
populate_partitions $image_loop $initramfs_dir $rootfs_dir "${args['quiet']}"
|
2023-10-02 17:57:49 -05:00
|
|
|
|
2023-10-02 00:47:30 -05:00
|
|
|
echo "cleaning up loop devices"
|
2023-10-20 15:51:56 -05:00
|
|
|
losetup -d $image_loop
|
|
|
|
echo "done"
|