2023-10-02 01:47:30 -04:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
#build the bootloader image
|
|
|
|
|
2024-04-24 17:54:52 -04:00
|
|
|
. ./common.sh
|
2023-12-21 01:09:41 -05:00
|
|
|
. ./image_utils.sh
|
2023-12-21 01:05:17 -05:00
|
|
|
. ./shim_utils.sh
|
2023-10-02 15:17:59 -04:00
|
|
|
|
2023-10-02 01:47:30 -04:00
|
|
|
print_help() {
|
2023-10-04 02:56:57 -04:00
|
|
|
echo "Usage: ./build.sh output_path shim_path rootfs_dir"
|
2024-04-26 16:11:20 -04:00
|
|
|
echo "Valid named arguments (specify with 'key=value'):"
|
|
|
|
echo " quiet - Don't use progress indicators which may clog up log files."
|
|
|
|
echo " arch - Set this to 'arm64' to specify that the shim is for an ARM chromebook."
|
2023-10-02 01:47:30 -04:00
|
|
|
}
|
|
|
|
|
2024-04-24 17:54:52 -04:00
|
|
|
assert_root
|
2024-06-14 02:07:20 -04:00
|
|
|
assert_deps "cpio binwalk pcregrep realpath cgpt mkfs.ext4 mkfs.ext2 fdisk lz4"
|
2024-04-24 17:54:52 -04:00
|
|
|
assert_args "$3"
|
2024-01-30 16:13:03 -05:00
|
|
|
parse_args "$@"
|
2023-10-02 15:06:06 -04:00
|
|
|
|
2024-01-25 16:19:25 -05:00
|
|
|
output_path=$(realpath -m "${1}")
|
|
|
|
shim_path=$(realpath -m "${2}")
|
|
|
|
rootfs_dir=$(realpath -m "${3}")
|
2023-10-02 01:47:30 -04:00
|
|
|
|
2024-04-26 16:11:20 -04:00
|
|
|
echo "reading the shim image"
|
2023-10-02 01:47:30 -04:00
|
|
|
initramfs_dir=/tmp/shim_initramfs
|
2024-04-26 16:11:20 -04:00
|
|
|
kernel_img=/tmp/kernel.img
|
|
|
|
rm -rf $initramfs_dir $kernel_img
|
|
|
|
extract_initramfs_full $shim_path $initramfs_dir $kernel_img "${args['arch']}"
|
2023-10-02 01:47:30 -04:00
|
|
|
|
2023-10-02 02:08:31 -04:00
|
|
|
echo "patching initramfs"
|
2023-10-02 15:17:59 -04:00
|
|
|
patch_initramfs $initramfs_dir
|
2023-10-02 02:08:31 -04:00
|
|
|
|
2023-10-02 18:57:49 -04:00
|
|
|
echo "creating disk image"
|
2023-10-06 13:29:10 -04:00
|
|
|
rootfs_size=$(du -sm $rootfs_dir | cut -f 1)
|
2024-04-26 16:11:20 -04:00
|
|
|
rootfs_part_size=$(($rootfs_size * 12 / 10 + 5))
|
2023-10-06 13:29:10 -04:00
|
|
|
#create a 20mb bootloader partition
|
2023-10-20 16:51:56 -04:00
|
|
|
#rootfs partition is 20% larger than its contents
|
2023-10-06 13:29:10 -04:00
|
|
|
create_image $output_path 20 $rootfs_part_size
|
2023-10-02 18:57:49 -04:00
|
|
|
|
|
|
|
echo "creating loop device for the image"
|
|
|
|
image_loop=$(create_loop ${output_path})
|
|
|
|
|
|
|
|
echo "creating partitions on the disk image"
|
2024-04-26 16:11:20 -04:00
|
|
|
create_partitions $image_loop $kernel_img
|
2023-10-02 18:57:49 -04:00
|
|
|
|
|
|
|
echo "copying data into the image"
|
2024-01-30 16:13:03 -05:00
|
|
|
populate_partitions $image_loop $initramfs_dir $rootfs_dir "${args['quiet']}"
|
2024-04-26 16:11:20 -04:00
|
|
|
rm -rf $initramfs_dir $kernel_img
|
2023-10-02 18:57:49 -04:00
|
|
|
|
2023-10-02 01:47:30 -04:00
|
|
|
echo "cleaning up loop devices"
|
2023-10-20 16:51:56 -04:00
|
|
|
losetup -d $image_loop
|
|
|
|
echo "done"
|