Blhost (MBoot)#
Blhost is a tool that facilitates communication with the bootloader. It allows users to perform various operations such as programming firmware or configuring the bootloader settings. Blhost is typically used in development and debugging processes to interact with the bootloader on a target device.
The blhost provides several communication interfaces for interacting with NXP microcontrollers. The available communication interfaces are:
UART (Universal Asynchronous Receiver-Transmitter): This is the most common communication interface used with the blhost utility. It allows you to communicate with the target microcontroller over a serial connection, such as a USB-to-UART adapter or the on-board UART interface of the microcontroller.
USB HID (Human Interface Device): The blhost utility can also communicate with the target microcontroller over a USB HID interface. This is useful when the microcontroller has a built-in USB HID interface, which can be used for communication without the need for a separate UART interface.
SPI (Serial Peripheral Interface): Some NXP microcontrollers support communication with the blhost utility over an SPI interface. This can be useful in scenarios where UART or USB are not available or convenient.
I2C (Inter-Integrated Circuit): Similar to SPI, the blhost utility can also communicate with the target microcontroller over an I2C interface.
CAN: Widely used communication protocol in the automotive and industrial sectors, and it is also supported by many NXP microcontrollers.
Buspal: Utility provided by NXP that allows you to communicate with and control various bus interfaces on NXP microcontrollers.
For more information about the available configuration options for the communication interface, you can refer to the help message provided by the blhost utility. To access the help message, run the command
blhost --help
.
The specific communication interfaces supported by the blhost utility may vary depending on the NXP microcontroller you are using.
It’s important to consult the documentation for your target microcontroller to determine which communication interfaces are available and how to configure them for use with the blhost utility.
The supported communication interfaces can be also listed with command spsdk utils family-info
1. Prerequisites#
SPSDK is needed with examples extension.
pip install spsdk[examples]
(Please refer to the installation documentation.)Connect your preferred board via USB interface. In this example we will be using
lpc55s69
2. Blhost API#
The blhost Python API provides a convenient way to integrate the functionality of the blhost utility into your Python-based applications. It abstracts the low-level details of the communication protocols and allows you to interact with the target microcontroller using a simple and intuitive Python interface.
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
#
# Copyright 2019-2023 NXP
#
# SPDX-License-Identifier: BSD-3-Clause
from spsdk.exceptions import SPSDKError
from spsdk.mboot.interfaces.usb import MbootUSBInterface
from spsdk.mboot.mcuboot import McuBoot
interfaces = MbootUSBInterface.scan()
if not interfaces:
raise SPSDKError("No USB interfaces found")
interface = interfaces[0]
with McuBoot(interface) as mb:
property_list = mb.get_property_list()
for prop in property_list:
print(prop)
Current Version = K3.0.0
Available Peripherals = UART, I2C-Slave, SPI-Slave, USB-HID
Flash Start Address = 0x00000000
Flash Size = 631.5 kiB
Flash Sector Size = 32.0 kiB
Available Commands = ['FlashEraseAll', 'FlashEraseRegion', 'ReadMemory', 'WriteMemory', 'GetProperty', 'ReceiveSBFile', 'Execute', 'Reset', 'SetProperty', 'ConfigureMemory', 'KeyProvisioning']
CRC Check Status = AppCrcCheckInvalid
Verify Writes = ON
Max Packet Size = 56 B
Reserved Regions =
Region 0: 0x14000000 - 0x14005FFF; Total Size: 24.0 kiB
Region 1: 0x04000000 - 0x04007FFF; Total Size: 32.0 kiB
Region 2: 0x30000000 - 0x30005FFF; Total Size: 24.0 kiB
Region 3: 0x20000000 - 0x20005FFF; Total Size: 24.0 kiB
RAM Start Address = 0x20000000
RAM Size = 256.0 kiB
System Device Identification = 0x501000C5
Security State = UNSECURE
Unique Device Identification = 0C 10 23 41 7B 56 3A 50 BC 86 60 C7 BD 9E 22 67
Target Version = T1.1.4
Flash Page Size = 512 B
Irq Notifier Pin = IRQ Port[0], Pin[0] is disabled
PFR Keystore Update Opt = KEY_PROVISIONING
3. Blhost CLI#
The blhost Python CLI provides a user-friendly and cross-platform interface for interacting with NXP microcontrollers. It abstracts the low-level details of the communication protocols and presents a consistent command-line experience, making it easy for developers to integrate the blhost functionality into their workflows.
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
#
# Copyright 2024 NXP
#
# SPDX-License-Identifier: BSD-3-Clause
VID_PID = "0x1fc9:0x0021"
print("Current bootloader version:")
%! blhost -u $VID_PID get-property 1
print("List of memories:")
%! blhost -u $VID_PID list-memory
Current bootloader version:
blhost -u 0x1fc9:0x0021 get-property 1
Response status = 0 (0x0) Success.
Response word 1 = 1258487808 (0x4b030000)
Current Version = K3.0.0
List of memories:
blhost -u 0x1fc9:0x0021 list-memory
Internal Flash:
Region 0: 0x00000000 - 0x0009DDFF; Total Size: 631.5 kiB Sector size: 32.0 kiB
Region 1: 0x0009DE00 - 0x0009FFFF; Total Size: 8.5 kiB Sector size: 32.0 kiB
Internal RAM:
Region 0: 0x20000000 - 0x2003FFFF; Total Size: 256.0 kiB
Region 1: 0x30000000 - 0x3003FFFF; Total Size: 256.0 kiB
External Memories:
SPI-MEM:
Not Configured