===============
Bootable Image
===============

Bootable image is primarily intended for booting from the external memories, for other use cases refer to the :ref:`Executable Images`.
Bootable image encapsulates the executable application images and adds additional data processed by the bootROM that are needed for boot, like for example configuration of the flash memories.
The bootable image might consists of:

- Keyblob or IPED table for data decryption
- Keystore
- FlexSPI Configuration Block (FCB)
- External Memory Configuration Data (XMCD)
- Device Configuration Data (DCD) -  The DCD contains configuration data to configure any peripherals.
- Application Image - It might contain plain application image, HAB, AHAB image or MBI.

For details on AHAB container layout used in i.MX 9x imx-boot images, see :doc:`ahab` section
"AHAB Container Structure for imx-boot".

On-the-fly Encryption
=====================

The ``keyblob`` segment accepts a raw binary table or a path to an OTFAD, IEE or IPED
YAML/JSON configuration for the same device family. With a configuration, bootable-image
export builds the table and encrypts the assembled application segments (MBI, HAB or AHAB)
in the configured address ranges. This also works when application segments refer to
configuration files: signing and image assembly happen before on-the-fly encryption.
Do not supply already encrypted application data with an encryption configuration.
To assemble previously encrypted data without encrypting it again, use a binary keyblob.

Use a configuration generated by the corresponding ``nxpimage otfad``, ``nxpimage iee``
or ``nxpimage iped`` tool. The engine is identified by its existing configuration keys;
no additional engine selector is needed. For example::

    family: mimxrt1176
    memory_type: flexspi_nor
    keyblob: otfad.yaml
    fcb: fcb.bin
    hab_container: application.bin
    output: encrypted_bootable.bin

``otfad_table_address`` (OTFAD) or ``keyblob_address`` (IEE/IPED) is the absolute address
of the keyblob segment, not of the application. Application addresses are calculated from
that address and the bootable layout. ``init_offset`` only trims the exported image; it
does not change encryption addresses, even when the keyblob itself is excluded.
Paths inside the encryption configuration are resolved relative to that configuration.

Bytes outside encryption regions remain unchanged. Encryption regions must not overlap
boot headers such as the keyblob, FCB or XMCD. Overlapping encryption regions are rejected.
Encryption padding or interleaved IPED GCM authentication tags can extend an application
segment, but must not relocate trailing data within it or overlap the next segment.
Invalid layouts are reported as errors rather than silently moving application data.
OTFAD region ends must use 1 KB boundaries (or the preceding byte for an inclusive
end address). IEE AES-XTS application data must start on a 4 KB data-unit boundary.
The same encryption is applied to all output formats.

Application input comes from bootable-image segments, not from the encryption configuration's
optional ``data_blobs``. If ``post_export`` is enabled, the referenced encryption tool also
exports its standalone artifacts, including any separately configured ``data_blobs``.
Those artifacts do not replace application segments in the bootable image.
Header-only configurations remain supported without application encryption.
Exporting a configuration from an encrypted image stores the generated binary table
and ciphertext application segments together; rebuilding that configuration does not
encrypt them a second time.
See :doc:`flash` for encryption configuration details.

Generating Templates
====================

The bootable image configuration template can be generated using the nxpimage tool's ``get-template`` command:

``nxpimage bootable-image get-template -f <family> -m <memory_type> -o bootable_template.yaml``

Generating Multiple Templates
==============================

The ``get-templates`` command (note the plural) allows you to generate multiple template configurations at once:

``nxpimage bootable-image get-templates -f <family> -o <output_directory>``

When used without the ``--template`` option, this command generates:
- Standard templates for all memory types (legacy behavior)
- All extra templates in sub-folders, with board-specific variants

You can generate a specific template structure using the ``--template`` option:

``nxpimage bootable-image get-templates -f <family> -o <output_directory> --template imx_boot_flash_all``

Available template names include: ``imx_boot_flash_all`` and others depending on the family.

For board-specific configurations, use the ``--board`` option:

``nxpimage bootable-image get-templates -f <family> -o <output_directory> --board imx95-19x19-lpddr5-evk``

Use the ``list-boards`` command to see available boards for your family:

``nxpimage bootable-image list-boards -f <family>``


.. toctree::
    :caption: Sub images
    :maxdepth: 1

    fcb
    xmcd
