HAB Example

HAB Example#

This example shows how to create a simple bootable image (i.MX-RT).

After the image is created, the DCD part, application segment are added. The basic info of the whole segment is displayed. The image is saved to a file.

The application segment is a “plain load” image without a boot device header, IVT, boot data, etc.

#!/usr/bin/env python
# -*- coding: UTF-8 -*-
#
# Copyright 2019-2023 NXP
#
# SPDX-License-Identifier: BSD-3-Clause

%run ../init_notebook.ipynb

import os

from spsdk.image.images import BootImgRT
from spsdk.image.segments import SegDCD

DATA_DIR = os.path.join("..", "_data")

# Create Boot Image instance
img = BootImgRT(address=0x20000000, version=0x40)

# Add DCD segment
with open(f"{DATA_DIR}/dcd.txt", "r") as f_txt:
    img.dcd = SegDCD.parse_txt(f_txt.read())

# Add application segment
with open(f"{DATA_DIR}/plain_load_ivt_flashloader.bin", "rb") as f_bin:
    img.add_image(data=f_bin.read())

# Print image info
print(str(img))

# Save into file
with open(f"{DATA_DIR}/flashloader.imx", "wb") as f:
    f.write(img.export())
env: JUPYTER_SPSDK=1
Created `%!` as an alias for `%execute`.
############################################################
# FCB (Flash Configuration Block)
############################################################

PaddingFCB: 1024 bytes############################################################
# IVT (Image Vector Table)
############################################################

 Format version   : 0x40
 IVT start address: 0x20001000
 BDT start address: 0x20001020
 DCD start address: 0x20001040
 APP entry point  : 0x20014b91
 CSF start address: none

############################################################
# BDI (Boot Data Info)
############################################################

 Start      : 0x20000000
 App Length : 87.9 kiB (90039 Bytes)
 Plugin     : NO

############################################################
# DCD (Device Config Data)
############################################################

------------------------------------------------------------
Command "Write Data"   [Tag=204, length=36]
Write Data Command (Ops: WRITE_VALUE, Bytes: 4)
- Address: 0x30340004, Value: 0x4F400005
- Address: 0x30340004, Value: 0x4F400005
- Address: 0x30340004, Value: 0x4F400005
- Address: 0x30340004, Value: 0x4F400005
------------------------------------------------------------

------------------------------------------------------------
Command "Write Data"   [Tag=204, length=12]
Write Data Command (Ops: CLEAR_BITMASK, Bytes: 4)
- Address: 0x307900C4, Value: 0x00000001
------------------------------------------------------------

------------------------------------------------------------
Command "Write Data"   [Tag=204, length=12]
Write Data Command (Ops: SET_BITMASK, Bytes: 4)
- Address: 0x307900C4, Value: 0x00000001
------------------------------------------------------------

------------------------------------------------------------
Command "Check Data"   [Tag=207, length=12]
Check Data Command (Ops: ALL_CLEAR, Bytes: 4)
- Address: 0x307900C4, Mask: 0x00000001
------------------------------------------------------------

------------------------------------------------------------
Command "Check Data"   [Tag=207, length=16]
Check Data Command (Ops: ALL_CLEAR, Bytes: 4)
- Address: 0x307900C4, Mask: 0x00000001, Count: 5
------------------------------------------------------------

------------------------------------------------------------
Command "Check Data"   [Tag=207, length=12]
Check Data Command (Ops: ANY_CLEAR, Bytes: 4)
- Address: 0x307900C4, Mask: 0x00000001
------------------------------------------------------------

------------------------------------------------------------
Command "Check Data"   [Tag=207, length=16]
Check Data Command (Ops: ANY_CLEAR, Bytes: 4)
- Address: 0x307900C4, Mask: 0x00000001, Count: 5
------------------------------------------------------------

------------------------------------------------------------
Command "Check Data"   [Tag=207, length=12]
Check Data Command (Ops: ALL_SET, Bytes: 4)
- Address: 0x307900C4, Mask: 0x00000001
------------------------------------------------------------

------------------------------------------------------------
Command "Check Data"   [Tag=207, length=16]
Check Data Command (Ops: ALL_SET, Bytes: 4)
- Address: 0x307900C4, Mask: 0x00000001, Count: 5
------------------------------------------------------------

------------------------------------------------------------
Command "Check Data"   [Tag=207, length=12]
Check Data Command (Ops: ANY_SET, Bytes: 4)
- Address: 0x307900C4, Mask: 0x00000001
------------------------------------------------------------

------------------------------------------------------------
Command "Check Data"   [Tag=207, length=16]
Check Data Command (Ops: ANY_SET, Bytes: 4)
- Address: 0x307900C4, Mask: 0x00000001, Count: 5
------------------------------------------------------------

------------------------------------------------------------
Command "No Operation (NOP)"   [Tag=192, length=4]
------------------------------------------------------------