# mcbootflash
![build](https://github.com/bessman/mcbootflash/actions/workflows/main.yml/badge.svg)
[![Documentation](https://img.shields.io/badge/doc-latest-blue.svg)](https://bessman.github.io/mcbootflash/)
[![PyPI](https://img.shields.io/pypi/v/mcbootflash.svg)](https://pypi.org/project/mcbootflash/)
[![License](https://img.shields.io/pypi/l/mcbootflash)](https://mit-license.org/)
## What
Mcbootflash is a Python tool for flashing firmware to 16-bit Microchip MCUs and DSCs
from the PIC24 and dsPIC33 families of devices, which are running a
[bootloader](https://www.microchip.com/en-us/software-library/16-bit-bootloader)
generated by the MPLAB Code Configurator tool.
Mcbootflash is intended to be a drop-in replacement for Microchip's official tool, the
Unified Bootloader Host Application (UBHA).
## Why
Mcbootflash is:
### Scriptable
As a command-line application, mcbootflash is easily scriptable.
### Extensible
In addition to its command-line interface, mcbootflash can be used as a library by
applications wanting to implement firmware flashing as part of a larger suite of
features.
### Free and Open Source
Mcbootflash is distributed under the MIT license.
## Installation
`pip install mcbootflash`
## Usage
Mcbootflash can be used as both a command-line application and a library.
### Command-line
```shellsession
$ mcbootflash --help
usage: mcbootflash [-h] -p PORT -b BAUDRATE [-t TIMEOUT] [-v] [-q] [--version] hexfile
Flash firmware over serial connection to a device running Microchip's 16-bit bootloader.
positional arguments:
hexfile an Intel HEX file containing application firmware
optional arguments:
-h, --help show this help message and exit
-p PORT, --port PORT serial port connected to the device you want to flash
-b BAUDRATE, --baudrate BAUDRATE
symbol rate of device's serial bus
-t TIMEOUT, --timeout TIMEOUT
try to read data from the bus for this many seconds before giving up
-v, --verbose print debug messages
-q, --quiet suppress output
--version show program's version number and exit
```
#### Example
```shellsession
$ mcbootflash --port /dev/ttyUSB0 --baudrate 460800 firmware.hex
Connecting to bootloader...
Connected
Existing application detected, erasing...
Application erased
Flashing firmware.hex
100% 88.7 KiB |########################################| Elapsed Time: 0:00:05
Self verify OK
```
### Library
When using mcbootflash as a library, typical workflow looks something like this:
``` py
import mcbootflash as bf
import serial
# Connect to a device in bootloader mode.
connection = serial.Serial(port=<PORT>, baudrate=<BAUDRATE>, timeout=<TIMEOUT>)
# Query its attributes.
bootattrs = bf.get_boot_attrs(connection)
# Load the firmware image and split it into chunks.
total_bytes, chunks = bf.chunked(hexfile=<HEXFILE_PATH_STRING>, bootattrs)
# Erase the device's program memory area.
bf.erase_flash(connection, bootattrs.memory_range, bootattrs.erase_size)
# Write the firmware chunks to the bootloader in a loop.
for chunk in chunks:
bf.write_flash(connection, chunk)
# Optionally, check that the write is OK by checksumming.
if bootattrs.has_checksum:
bf.checksum(connection, chunk)
# At this point, you may want to give an indication of the flashing progress,
# like updating a progress bar.
# Verify that the new application is detected.
bf.self_verify(connection)
```
See also the [API Reference](https://bessman.github.io/mcbootflash/api/).
Raw data
{
"_id": null,
"home_page": null,
"name": "mcbootflash",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.8",
"maintainer_email": null,
"keywords": "firmware,flashing,bootloader,serial,uart,microchip,pic24,dspic33,16-bit",
"author": null,
"author_email": "Alexander Bessman <alexander.bessman@gmail.com>",
"download_url": "https://files.pythonhosted.org/packages/84/be/f4c44936efcfe4411b4148ad872b4db649c8229f888d40428378b7e4fa18/mcbootflash-8.0.1.tar.gz",
"platform": null,
"description": "# mcbootflash\n\n![build](https://github.com/bessman/mcbootflash/actions/workflows/main.yml/badge.svg)\n[![Documentation](https://img.shields.io/badge/doc-latest-blue.svg)](https://bessman.github.io/mcbootflash/)\n[![PyPI](https://img.shields.io/pypi/v/mcbootflash.svg)](https://pypi.org/project/mcbootflash/)\n[![License](https://img.shields.io/pypi/l/mcbootflash)](https://mit-license.org/)\n\n## What\n\nMcbootflash is a Python tool for flashing firmware to 16-bit Microchip MCUs and DSCs\nfrom the PIC24 and dsPIC33 families of devices, which are running a\n[bootloader](https://www.microchip.com/en-us/software-library/16-bit-bootloader)\ngenerated by the MPLAB Code Configurator tool.\n\nMcbootflash is intended to be a drop-in replacement for Microchip's official tool, the\nUnified Bootloader Host Application (UBHA).\n\n## Why\n\nMcbootflash is:\n\n### Scriptable\n\nAs a command-line application, mcbootflash is easily scriptable.\n\n### Extensible\n\nIn addition to its command-line interface, mcbootflash can be used as a library by\napplications wanting to implement firmware flashing as part of a larger suite of\nfeatures.\n\n### Free and Open Source\n\nMcbootflash is distributed under the MIT license.\n\n## Installation\n\n`pip install mcbootflash`\n\n## Usage\n\nMcbootflash can be used as both a command-line application and a library.\n\n### Command-line\n\n```shellsession\n$ mcbootflash --help\nusage: mcbootflash [-h] -p PORT -b BAUDRATE [-t TIMEOUT] [-v] [-q] [--version] hexfile\n\nFlash firmware over serial connection to a device running Microchip's 16-bit bootloader.\n\npositional arguments:\n hexfile an Intel HEX file containing application firmware\n\noptional arguments:\n -h, --help show this help message and exit\n -p PORT, --port PORT serial port connected to the device you want to flash\n -b BAUDRATE, --baudrate BAUDRATE\n symbol rate of device's serial bus\n -t TIMEOUT, --timeout TIMEOUT\n try to read data from the bus for this many seconds before giving up\n -v, --verbose print debug messages\n -q, --quiet suppress output\n --version show program's version number and exit\n```\n\n#### Example\n\n```shellsession\n$ mcbootflash --port /dev/ttyUSB0 --baudrate 460800 firmware.hex\nConnecting to bootloader...\nConnected\nExisting application detected, erasing...\nApplication erased\nFlashing firmware.hex\n100% 88.7 KiB |########################################| Elapsed Time: 0:00:05\nSelf verify OK\n```\n\n### Library\n\nWhen using mcbootflash as a library, typical workflow looks something like this:\n\n``` py\nimport mcbootflash as bf\nimport serial\n\n\n# Connect to a device in bootloader mode.\nconnection = serial.Serial(port=<PORT>, baudrate=<BAUDRATE>, timeout=<TIMEOUT>)\n# Query its attributes.\nbootattrs = bf.get_boot_attrs(connection)\n# Load the firmware image and split it into chunks.\ntotal_bytes, chunks = bf.chunked(hexfile=<HEXFILE_PATH_STRING>, bootattrs)\n# Erase the device's program memory area.\nbf.erase_flash(connection, bootattrs.memory_range, bootattrs.erase_size)\n\n# Write the firmware chunks to the bootloader in a loop.\nfor chunk in chunks:\n bf.write_flash(connection, chunk)\n\n # Optionally, check that the write is OK by checksumming.\n if bootattrs.has_checksum:\n bf.checksum(connection, chunk)\n\n # At this point, you may want to give an indication of the flashing progress,\n # like updating a progress bar.\n\n# Verify that the new application is detected.\nbf.self_verify(connection)\n```\n\nSee also the [API Reference](https://bessman.github.io/mcbootflash/api/).",
"bugtrack_url": null,
"license": null,
"summary": "Flash firmware to devices running Microchip's 16-bit bootloader.",
"version": "8.0.1",
"project_urls": {
"Home": "https://bessman.github.io/mcbootflash/"
},
"split_keywords": [
"firmware",
"flashing",
"bootloader",
"serial",
"uart",
"microchip",
"pic24",
"dspic33",
"16-bit"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "c0cdc00b2b884aece25128d0d39c6d18698d129170ca3f499d9cd53a797ed4ac",
"md5": "0e9bde2f7adad159aabd31b2b27d26e6",
"sha256": "b6e95f374918e6cf887c954523bea16c804eacaaea6ab1cc7544208dbfb9318b"
},
"downloads": -1,
"filename": "mcbootflash-8.0.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "0e9bde2f7adad159aabd31b2b27d26e6",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8",
"size": 14515,
"upload_time": "2024-02-08T11:53:13",
"upload_time_iso_8601": "2024-02-08T11:53:13.068970Z",
"url": "https://files.pythonhosted.org/packages/c0/cd/c00b2b884aece25128d0d39c6d18698d129170ca3f499d9cd53a797ed4ac/mcbootflash-8.0.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "84bef4c44936efcfe4411b4148ad872b4db649c8229f888d40428378b7e4fa18",
"md5": "2d931fdc9d426d7926fe21f83ff5efb1",
"sha256": "58723294a2c252aa931b05dc0d734fbc7a256ee1e56d000b497320dc8427f86b"
},
"downloads": -1,
"filename": "mcbootflash-8.0.1.tar.gz",
"has_sig": false,
"md5_digest": "2d931fdc9d426d7926fe21f83ff5efb1",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8",
"size": 24906,
"upload_time": "2024-02-08T11:53:24",
"upload_time_iso_8601": "2024-02-08T11:53:24.445879Z",
"url": "https://files.pythonhosted.org/packages/84/be/f4c44936efcfe4411b4148ad872b4db649c8229f888d40428378b7e4fa18/mcbootflash-8.0.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-02-08 11:53:24",
"github": false,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"lcname": "mcbootflash"
}