Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: include bootloader in release images #197

Merged
merged 2 commits into from
Apr 4, 2025
Merged

Conversation

Tejasgarg
Copy link
Contributor

@Tejasgarg Tejasgarg commented Mar 29, 2025

Fixes #189

As @bessman mentioned in the issue:
The current release process automatically builds and attaches firmware images to the release page. These firmware images include only the application firmware, not the bootloader. If someone were to flash these images with a PICkit, the existing bootloader would be erased and the PSLab would no longer be able to enter bootloader mode.

So, the bootloader image is added to the application image.

Did it in the following steps-

  1. Building the bootloader image:
  • Cloned the bootloader repository inside the container to access the files.
  • Made a build folder similar to the firmware application image
  • Used Cmake and make functions to make the .hex file from the .elf file.
  1. Importing the XC8 compiler:
  • Hexmate is used to combine the .hex files of the bootloader image and the application image into one file, which can be published and flashed to the PSLab board.
  • Now, Hexmate comes as a utility application as part of the XC8 compiler or the MPLABX IDE setup.
  • Downloaded the XC8 compiler and picked hexmate from it.
  • Before starting the download, cache the XC8 compiler similar to the XC16 compiler earlier in the build.
  • Entered the cache directory and started the download.
  • Now give permission to the .run file through chmod.

After the download, move to the installation.

  • Here set the install settings to unattended so it can automatically install inside the container.
  • Now, use the echo command to modify the system's PATH environment variable in GitHub's Actions workflow.
  1. Combining the hexfile:
  • The firmware.hex is present in the pslab-firmware/build directory, and the bootloader.hex is in the pslab-bootloader/build directory
  • So, move the firmware.hex into the pslab-bootloader/build folder and then shift the container into the same folder.
  • Give permission to combine.sh file in the pslab-bootloader directory and run it. It already has the definition to output combine.hex file
  1. Publishing the build files:
  • The final file, which is combined.hex is now present in the pslab-bootloader/build directory, so we pick it from there and publish it

Successful action run:
https://github.com/Tejasgarg/pslab-firmware/actions/runs/14147713427/job/39637063463

Summary by Sourcery

Modify the release build process to include the bootloader in the firmware image, ensuring a complete firmware package that can be flashed to the PSLab board without losing bootloader functionality.

New Features:

  • Add bootloader to the firmware release image, enabling complete firmware flashing

CI:

  • Update GitHub Actions workflow to build and combine bootloader and firmware hex files
  • Add steps to download and install XC8 compiler for hex file manipulation

Chores:

  • Modify release artifact publishing to include combined bootloader and firmware hex file

Copy link
Contributor

sourcery-ai bot commented Mar 29, 2025

Reviewer's Guide by Sourcery

This pull request modifies the build process to include the bootloader in the release images. It clones the bootloader repository, builds the bootloader, downloads and installs the XC8 compiler, combines the bootloader and firmware hex files, and updates the publish build files step to upload the combined hex file.

Sequence diagram for combining hex files

sequenceDiagram
    participant GitHub Actions
    participant pslab-bootloader

    GitHub Actions->>pslab-bootloader: mv pslab-firmware.hex
    GitHub Actions->>pslab-bootloader: chmod +x combine_hex.sh
    GitHub Actions->>pslab-bootloader: ./combine_hex.sh
    pslab-bootloader-->>GitHub Actions: combined.hex
Loading

File-Level Changes

Change Details Files
Added a job to build the bootloader.
  • Cloned the bootloader repository.
  • Initialized and updated git submodules.
  • Created a build directory.
  • Used CMake to generate makefiles.
  • Built the bootloader.
.github/workflows/main-builder.yml
Added steps to download and install the XC8 compiler.
  • Created a cache directory for the compiler.
  • Downloaded the XC8 compiler.
  • Made the installer executable.
  • Installed the compiler in unattended mode.
  • Added the compiler's binary directory to the system's PATH.
.github/workflows/main-builder.yml
Added a job to combine the bootloader and firmware hex files.
  • Moved the firmware hex file to the bootloader build directory.
  • Changed the current directory to the bootloader build directory.
  • Made the combine script executable.
  • Executed the combine script.
.github/workflows/main-builder.yml
Modified the publish build files step to upload the combined hex file.
  • Changed the path of the uploaded artifact to the combined hex file.
.github/workflows/main-builder.yml
Renamed the 'Cache XC-16 Compiler' step to 'Cache Compilers'.
  • Updated the name of the cache step to reflect that it now caches multiple compilers.
.github/workflows/main-builder.yml

Assessment against linked issues

Issue Objective Addressed Explanation
#189 Include the bootloader in the firmware release images.

Possibly linked issues


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

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @Tejasgarg - I've reviewed your changes - here's some feedback:

Overall Comments:

  • Consider using a Docker image with the necessary toolchain pre-installed to avoid installing the XC8 compiler in the workflow.
  • It would be cleaner to combine the hex files using a tool like srec_cat instead of a custom script.
Here's what I looked at during the review
  • 🟡 General issues: 2 issues found
  • 🟡 Security: 1 issue found
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@@ -64,9 +64,41 @@ jobs:
cd build_${{ matrix.target }}
cmake .. ${{ matrix.cmake_flags}}
make

- name: Build bootloader
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Pin bootloader repository version for reproducible builds

Consider cloning a specific commit, tag, or branch that is known to work rather than the default branch to ensure build reproducibility.

Suggested implementation:

          - name: Build bootloader
            run: |
              git clone https://github.com/fossasia/pslab-bootloader.git pslab-bootloader
              cd pslab-bootloader
              git checkout tags/v1.0.0
              git submodule update --init
              mkdir build
              cd build
              cmake ..
              make

Make sure that the tag "v1.0.0" exists in the bootloader repository, or replace it with the appropriate tag/commit hash that is known to work. Adjust the tag name to the desired version if necessary.


- name: Download XC8 Compiler
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚨 suggestion (security): Consider verifying the downloaded installer

A checksum verification or similar integrity check after downloading the installer could help ensure that the file is not corrupted or tampered with.

Suggested implementation:

          - name: Download XC8 Compiler
            if: steps.cache-compiler.outputs.cache-hit != 'true'
            run: |
              # Download XC8 Compiler installer
              wget https://example.com/path/to/xc8_installer.run -O xc8_installer.run
              # Verify installer checksum to ensure integrity
              expected_checksum="abc123def456ghi789jkl012mno345pq"  # Replace with the actual expected checksum value
              actual_checksum=$(sha256sum xc8_installer.run | awk '{print $1}')
              if [ "$actual_checksum" != "$expected_checksum" ]; then
                echo "Checksum verification failed! Expected: $expected_checksum, Got: $actual_checksum."
                exit 1
              fi

              # Continue with installation or further steps

Please update the download URL (https://example.com/path/to/xc8_installer.run) and expected_checksum with the actual values as required by your project.

Comment on lines 93 to 98
- name: Combining hex files
run: |
mv ${{ matrix.branch }}/build_${{ matrix.target }}/pslab-firmware.hex pslab-bootloader/build/pslab-firmware.hex
cd pslab-bootloader
chmod +x combine_hex.sh
./combine_hex.sh
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Improve error handling in hex file combination step

Adding error handling (for example, using 'set -e' to fail on errors) in the script block for moving files and executing combine_hex.sh would help catch issues earlier in the process.

Suggested change
- name: Combining hex files
run: |
mv ${{ matrix.branch }}/build_${{ matrix.target }}/pslab-firmware.hex pslab-bootloader/build/pslab-firmware.hex
cd pslab-bootloader
chmod +x combine_hex.sh
./combine_hex.sh
- name: Combining hex files
run: |
set -e
mv ${{ matrix.branch }}/build_${{ matrix.target }}/pslab-firmware.hex pslab-bootloader/build/pslab-firmware.hex
cd pslab-bootloader
chmod +x combine_hex.sh
./combine_hex.sh

Copy link
Collaborator

@bessman bessman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @Tejasgarg, thanks for the pull request!

Since we already build the bootloader in the bootloader repo, I would prefer to not duplicate the build script here. Instead, use the release image from the bootloader repo (https://github.com/fossasia/pslab-bootloader/releases/latest).

@bessman bessman merged commit 0285f6d into fossasia:main Apr 4, 2025
4 checks passed
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.

Include bootloader in firmware release images
2 participants