Skip to content
Open
22 changes: 19 additions & 3 deletions generate_boot_bins.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,17 @@ 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"
echo " dtb Generate DTB image"
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"
Expand Down Expand Up @@ -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 ;;
Expand Down Expand Up @@ -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
Expand All @@ -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"
Expand Down
55 changes: 38 additions & 17 deletions make_fitimage.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,22 @@
# make_fitimage.sh - FIT image packaging script for Qualcomm Linux development
#
# Usage:
# ./make_fitimage.sh --dtb <metadata_dts> --its <fitimage_its> [--kob <kernel_build_artifacts>] [--output <output_dir>]
# ./make_fitimage.sh --metadata <metadata_dts> --its <fitimage_its> \
# [--kobj <kernel_build_artifacts>] [--output <output_dir>] \
# [--sector-size <bytes>]
#
# 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
Expand All @@ -27,18 +30,22 @@ 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 <<EOF
Usage:
./make_fitimage.sh [OPTIONS]

Options:
--metadata <path> Path to metadata DTS file (default: $METADATA_DTS_PATH)
--its <path> Path to FIT image ITS file (default: $FIT_IMAGE_ITS_PATH)
--kobj <path> Path to kernel build artifacts directory (default: $KERNEL_BUILD_ARTIFACTS)
--output <path> Output directory for generated FIT image (default: $OUTPUT_DIR)
--help Show this help message and exit
--metadata <path> Path to metadata DTS file (default: $METADATA_DTS_PATH)
--its <path> Path to FIT image ITS file (default: $FIT_IMAGE_ITS_PATH)
--kobj <path> Path to kernel build artifacts directory (default: $KERNEL_BUILD_ARTIFACTS)
--output <path> Output directory for generated FIT image (default: $OUTPUT_DIR)
--sector-size <bytes> 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.
Expand All @@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Dockerfile already installs u-boot-tools; you could also include device-tree-compiler there.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both device-tree-compiler AND u-boot-tools are mandatory for the tool to execute, so until BOTH are included in Dockerfile definition, it's a must to have the tool install those as pre-req.

At the same time, there is no harm in having those there, taking in consideration support for local developer workflows independent of docker usage?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At the same time, there is no harm in having those there, taking in consideration support for local developer workflows independent of docker usage?

Absolutely, I agree with your point

fi
# -----------------------------------------------------------------------------

# Resolve paths
KERNEL_BUILD_ARTIFACTS="$(realpath "$KERNEL_BUILD_ARTIFACTS")"
OUTPUT_DIR="$(realpath "$OUTPUT_DIR")"
Expand All @@ -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"
Expand All @@ -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 \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It won’t work if someone is running from the Docker image.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why so?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes us rely on the source file to run, which kind of undermines the whole point of using Docker—to avoid depending on local compilation.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Komal, we need to get these changes merged for tooling to be usable, can you elaborate why would this particular block break if invoked from docker? Did you test using docker?

--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"
Loading