Skip to content

Conversation

kienvo
Copy link
Member

@kienvo kienvo commented Apr 15, 2025

This will resolve #37, and #38

Summary by Sourcery

Port MCUboot bootloader to the project, enabling firmware update capabilities with signed image support

New Features:

  • Implement MCUboot bootloader integration for firmware updates
  • Add support for signed firmware images
  • Create bootloader entry point and flash map backend

Enhancements:

  • Modify Makefile to support MCUboot build process
  • Update linker scripts to accommodate bootloader and application images
  • Refactor debug and logging mechanisms

Build:

  • Add external MCUboot and Tinycrypt library sources
  • Configure build system to compile bootloader and application components

Deployment:

  • Add new programming targets for bootloader and signed application images
  • Implement combined firmware image generation

Tests:

  • Add initial configuration for MCUboot logging and debug support

Copy link
Contributor

sourcery-ai bot commented Apr 15, 2025

Reviewer's Guide by Sourcery

This pull request ports MCUboot to the project. It includes the addition of MCUboot and Tinycrypt source files, updates to the Makefile for build configuration, implementation of flash area operations, creation of a boot entry point, and addition of linker scripts. The changes enable secure boot functionality using MCUboot.

No diagrams generated as the changes look simple and do not need a visual representation.

File-Level Changes

Change Details Files
Introduces MCUboot, Tinycrypt, and related source files to the project.
  • Added source files for MCUboot.
  • Added source files for Tinycrypt.
  • Updated the Makefile to include the new source files and include directories.
  • Added linker scripts for application and bootloader.
  • Added flash map backend implementation.
  • Added mcuboot configuration header.
  • Added debug and os malloc headers.
Makefile
src/mcuboot.c
bootloader.ld
inc/mcuboot_config/mcuboot_config.h
app.ld
src/boot-entry.c
inc/flash_map_backend/flash_map_backend.h
inc/sysflash/sysflash.h
inc/mcuboot_config/mcuboot_logging.h
inc/common/debug.h
inc/os/os_malloc.h
external/mcuboot
external/tinycrypt
Configures build options and linker settings for MCUboot integration.
  • Enabled debugging and USB-C version build options.
  • Added an option to specify the OpenOCD path.
  • Modified CFLAGS and LDFLAGS to include necessary flags for MCUboot and Tinycrypt.
  • Added targets for building signed binaries, mcuboot binaries, and combined binaries.
  • Updated the programming target to flash the combined binary.
  • Added a debug target to run OpenOCD with a debug configuration.
  • Added isp-bootld target to flash mcuboot elf.
Makefile
Implements flash area operations for MCUboot using the CH58x flash ROM.
  • Defines flash areas for bootloader, primary image, and secondary image.
  • Implements flash_area_* functions for reading, writing, erasing, and opening flash areas.
  • Implements flash_area_get_sectors to retrieve sector information.
  • Implements flash_area_id_from_multi_image_slot and flash_area_id_from_image_slot to get flash area IDs.
  • Implements flash_area_to_sectors to get flash area information.
src/mcuboot.c
Creates a boot entry point to start the MCUboot process.
  • Initializes the debug console.
  • Calls boot_go to determine the image to boot.
  • Starts the application by jumping to the image's reset handler.
  • Imports the application binary as a section.
  • Defines a function to start the application at a given address.
src/boot-entry.c
Updates the main application to include bootutil.
  • Includes the bootutil header file.
src/main.c
Replaces the debug header with a common debug header.
  • Replaces the debug header with a common debug header.
src/debug.h
Adds linker scripts for the bootloader and application.
  • Defines memory regions for FLASH and RAM.
  • Defines sections for code, data, and BSS.
  • Sets the entry point for the bootloader and application.
  • Defines the stack location.
bootloader.ld
app.ld

Assessment against linked issues

Issue Objective Addressed Explanation
#37 Implement firmware flashing over BLE.

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!
  • Generate a plan of action for an issue: Comment @sourcery-ai plan on
    an issue to generate a plan of action for it.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@kienvo kienvo force-pushed the mcuboot branch 3 times, most recently from dc091c4 to f0c2f3e Compare April 17, 2025 04:22
tested with AuTerm - slow
cannot work with `mcumgr` or `smpmgr` due to small MTU
@kienvo
Copy link
Member Author

kienvo commented Jun 4, 2025

I have completed porting MCUboot for CH582. In this PR, I wired the existing USB ACM to MCUboot's boot_serial and use AuTerm to transfer the firmware binary.

At the moment, it works with AuTerm with MTU set at 247, but getting slow. It takes about an hour to complete the uploading. I tried changing the MTU in the code, but it didn't have any effect. Since the MTU value is fixed somewhere in the code, trying smpmgr or mcumgr-client gave an error requiring a higher MTU.

From my observation, AuTerm just waited about 2 seconds after receiving an ACK from smp server (MCUboot), then sent a new packet. This slows down progress. I don't know what is missing here to trigger AuTerm to send new packets after receiving ACKs immediately.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Flash firmware over BLE
1 participant