diff --git a/generate_boot_bins.sh b/generate_boot_bins.sh old mode 100644 new mode 100755 index ca2c1ca..8c4be2c --- a/generate_boot_bins.sh +++ b/generate_boot_bins.sh @@ -6,7 +6,7 @@ BOOTIMG_EXTRA_SPACE="512" MKFSVFAT_EXTRAOPTS="-S 512" show_help() { - echo "Usage: generate_boot_bins.sh [command] [options]" + echo "Usage: generate_boot_bins.sh [global options] [command] [options]" echo "" echo "Commands:" echo " efi Generate EFI image" @@ -14,6 +14,9 @@ show_help() { echo " fatimg Generate FAT image" echo " help Show this help message" echo "" + echo "Global options:" + echo " --sector-size BYTES Set logical sector size passed to mkfs.vfat (default: 512)" + echo "" echo "efi command options:" echo " --ramdisk PATH Path to the ramdisk file" echo " --systemd-boot PATH Path to the systemd boot" @@ -82,7 +85,7 @@ generate_efi_image() { case $1 in --ramdisk) RAMDISK="$2"; shift ;; --systemd-boot) SYSTEMD_BOOT="$2"; shift ;; - --stub) STUB="$2"; shift ;; + --stub) STUB="$2"; shift ;; --linux) LINUX_IMAGE="$2"; shift ;; --devicetree) DTB="$2"; shift ;; --cmdline) KERNEL_VENDOR_CMDLINE="$2"; shift ;; @@ -201,6 +204,19 @@ generate_fat_image() { generate_bin "${INPUT_DIR}" "${OUTPUT_PATH}" } +# ------------------------------------------------------------ +# Minimal addition: parse global --sector-size before command +# ------------------------------------------------------------ +if [[ "$1" == "--sector-size" ]]; then + if [[ -n "$2" ]]; then + MKFSVFAT_EXTRAOPTS="-S $2" + shift 2 + else + echo "Error: --sector-size requires a value (e.g., 512)" + exit 1 + fi +fi + # Main script logic if [[ "$1" == "efi" ]]; then shift @@ -211,7 +227,7 @@ elif [[ "$1" == "dtb" ]]; then elif [[ "$1" == "bin" ]]; then shift generate_fat_image "$@" -elif [[ "$1" == "--help" ]]; then +elif [[ "$1" == "--help" || "$1" == "help" ]]; then show_help else echo "Unknown command: $1" diff --git a/make_fitimage.sh b/make_fitimage.sh old mode 100644 new mode 100755 index e6ec115..4bbf33f --- a/make_fitimage.sh +++ b/make_fitimage.sh @@ -4,19 +4,22 @@ # make_fitimage.sh - FIT image packaging script for Qualcomm Linux development # # Usage: -# ./make_fitimage.sh --dtb --its [--kob ] [--output ] +# ./make_fitimage.sh --metadata --its \ +# [--kobj ] [--output ] \ +# [--sector-size ] # # Options: -# --metadata Path to metadata DTS file (mandatory) -# --its Path to FIT image ITS file (mandatory) -# --kobj Path to kernel build artifacts directory (default: ../kobj) -# --output Output directory for generated FIT image (default: ../images) -# --help Show this help message and exit +# --metadata Path to metadata DTS file (default: ../artifacts/qcom-dtb-metadata/qcom-metadata.dts) +# --its Path to FIT image ITS file (default: ../artifacts/qcom-dtb-metadata/qcom-fitimage.its) +# --kobj Path to kernel build artifacts directory (default: ../kobj) +# --output Output directory for generated FIT image (default: ../images) +# --sector-size Logical sector size passed to mkfs.vfat via helper script (default: 512) +# --help Show this help message and exit # # Description: # This script generates a FIT image using Qualcomm metadata and ITS files. # It compiles the metadata DTS to DTB, creates the FIT image using mkimage, -# and packages the final image using generate_boot_bins.sh +# and packages the final image using generate_boot_bins.sh. ############################################################################### set -e @@ -27,6 +30,9 @@ OUTPUT_DIR="../images" METADATA_DTS_PATH="../artifacts/qcom-dtb-metadata/qcom-metadata.dts" FIT_IMAGE_ITS_PATH="../artifacts/qcom-dtb-metadata/qcom-fitimage.its" +# Default sector size (passed to generate_boot_bins.sh as global option) +SECTOR_SIZE="512" + # Help message function show_help() { cat < Path to metadata DTS file (default: $METADATA_DTS_PATH) - --its Path to FIT image ITS file (default: $FIT_IMAGE_ITS_PATH) - --kobj Path to kernel build artifacts directory (default: $KERNEL_BUILD_ARTIFACTS) - --output Output directory for generated FIT image (default: $OUTPUT_DIR) - --help Show this help message and exit + --metadata Path to metadata DTS file (default: $METADATA_DTS_PATH) + --its Path to FIT image ITS file (default: $FIT_IMAGE_ITS_PATH) + --kobj Path to kernel build artifacts directory (default: $KERNEL_BUILD_ARTIFACTS) + --output Output directory for generated FIT image (default: $OUTPUT_DIR) + --sector-size Logical sector size for FAT image packaging (default: $SECTOR_SIZE) + --help Show this help message and exit Description: This script generates a FIT image using Qualcomm metadata and ITS files. @@ -54,11 +61,21 @@ while [[ $# -gt 0 ]]; do --metadata) METADATA_DTS_PATH="$2"; shift 2 ;; --its) FIT_IMAGE_ITS_PATH="$2"; shift 2 ;; --output) OUTPUT_DIR="$2"; shift 2 ;; + --sector-size) SECTOR_SIZE="$2"; shift 2 ;; --help) show_help; exit 0 ;; *) echo "Unknown option: $1"; exit 1 ;; esac done +# ---------------- Install prerequisites (root, Debian/Ubuntu only) ------------ +if command -v apt-get >/dev/null 2>&1; then + echo "Ensuring prerequisites are installed: device-tree-compiler, u-boot-tools" + export DEBIAN_FRONTEND=noninteractive + apt-get update -y + apt-get install -y device-tree-compiler u-boot-tools +fi +# ----------------------------------------------------------------------------- + # Resolve paths KERNEL_BUILD_ARTIFACTS="$(realpath "$KERNEL_BUILD_ARTIFACTS")" OUTPUT_DIR="$(realpath "$OUTPUT_DIR")" @@ -68,7 +85,7 @@ FIT_IMAGE_ITS_PATH="$(realpath "$FIT_IMAGE_ITS_PATH")" # Function to create FIT image function create_fit_image() { # Cleaning previous FIT image artifacts - rm -f "${OUTPUT_DIR}/fit_dtb.bin" + rm -f "${OUTPUT_DIR}/dtb.bin" rm -rf "${OUTPUT_DIR}/fit_dir" rm -f "${KERNEL_BUILD_ARTIFACTS}/qcom-fitimage.its" rm -f "${KERNEL_BUILD_ARTIFACTS}/qcom-metadata.dtb" @@ -79,16 +96,20 @@ function create_fit_image() { # Copying ITS file to kernel build artifacts path cp "$FIT_IMAGE_ITS_PATH" "$KERNEL_BUILD_ARTIFACTS/qcom-fitimage.its" - #Compiling metadata DTS to DTB + # Compiling metadata DTS to DTB dtc -I dts -O dtb -o "${KERNEL_BUILD_ARTIFACTS}/qcom-metadata.dtb" "${METADATA_DTS_PATH}" echo "Generating FIT image..." mkimage -f "${KERNEL_BUILD_ARTIFACTS}/qcom-fitimage.its" "${OUTPUT_DIR}/fit_dir/qclinux_fit.img" -E -B 8 - echo "Packing final image into fit_dtb.bin..." - generate_boot_bins.sh bin --input "${OUTPUT_DIR}/fit_dir" --output "${OUTPUT_DIR}/fit_dtb.bin" + echo "Packing final image into dtb.bin..." + SELF_DIR="$(dirname "$(realpath "$0")")" + + # Pass sector size to helper (global option). If SECTOR_SIZE is empty, default to 512 earlier. + "${SELF_DIR}/generate_boot_bins.sh" --sector-size "${SECTOR_SIZE}" bin \ + --input "${OUTPUT_DIR}/fit_dir" --output "${OUTPUT_DIR}/dtb.bin" } echo "Starting FIT image creation..." create_fit_image -echo "FIT image created at ${OUTPUT_DIR}/fit_dtb.bin" +echo "FIT image created at ${OUTPUT_DIR}/dtb.bin"