Skip to content

Firmware Versioning#185

Draft
dhairs wants to merge 2 commits into
mainfrom
fw-versioning
Draft

Firmware Versioning#185
dhairs wants to merge 2 commits into
mainfrom
fw-versioning

Conversation

@dhairs
Copy link
Copy Markdown
Contributor

@dhairs dhairs commented Mar 6, 2026

TODO:

  • initialize CAN packet to reports version over the bus.
  • shared linker script for projects so no need to change for each project
  • add CAN packet to CSV for reporting version
  • add SemVer to every project

dhairs added 2 commits March 6, 2026 01:58
todo: automatically initialize version as CAN packet that can be reported to telemetry
@vercel
Copy link
Copy Markdown

vercel Bot commented Mar 6, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
lhre-2026 Ready Ready Preview, Comment Mar 6, 2026 8:01am

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces a comprehensive firmware versioning system, enabling the embedding of semantic version information directly into the firmware binaries. This standardization facilitates better tracking of releases, simplifies debugging processes, and ensures consistent version identification across various deployments. The changes establish a foundational mechanism for managing firmware versions programmatically within the build system.

Highlights

  • Semantic Versioning Integration: Implemented a structured approach to embed semantic versioning (major, minor, patch) directly into firmware binaries.
  • Dedicated Version Information Section: Introduced a new .ver_info section in the linker script to store firmware version data, ensuring it's easily retrievable from the compiled binary.
  • New Versioning Module: Added a drivers/versioning module containing fw_version.c and fw_version.h to define the structure and constant for storing application version details.
  • Automated Version Definition in Build System: Enhanced the firmware_project_g4 Bazel rule to accept a version string, which is then parsed and passed as preprocessor defines (APP_VERS_MAJOR, APP_VERS_MINOR, APP_VERS_PATCH) to the firmware compilation.
Changelog
  • VCU/firmware/BUILD.bazel
    • Added a version attribute to the firmware_project_g4 rule.
  • VCU/firmware/STM32G474XX_FLASH.ld
    • Defined a new .ver_info section in the flash memory to store version information.
  • drivers/versioning/BUILD.bazel
    • Created a new Bazel filegroup to manage firmware versioning source files.
  • drivers/versioning/fw_version.c
    • Implemented the AppVersion_t structure and g_app_version constant to store semantic version and build date.
  • drivers/versioning/fw_version.h
    • Added a header file for firmware versioning definitions.
  • tools/outputs/build_outputs.bzl
    • Added a version parameter to the firmware_project_g4 function with a default value.
    • Parsed the version string into APP_VERS_MAJOR, APP_VERS_MINOR, and APP_VERS_PATCH preprocessor defines.
    • Included the new drivers/versioning module in the firmware build dependencies.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a firmware versioning mechanism by embedding a version structure into a dedicated flash section and updating the build system to populate it. This is a solid foundation for version tracking. My review includes suggestions to improve the robustness of the build script's version parsing and to refactor the C code to make the version information accessible to other firmware modules, which will be crucial for features like reporting the version over a CAN bus.

Comment on lines +3 to +9
typedef struct {
char magic[4];
uint8_t major;
uint8_t minor;
uint16_t patch;
char build_date[12];
} AppVersion_t;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

high

The AppVersion_t struct is defined locally in this C file. To make the version information accessible to other parts of the firmware (e.g., for reporting over CAN or USB), this structure definition should be moved to the public header file fw_version.h. This makes the versioning data structure available across the project, which is essential for using this information elsewhere.

@@ -0,0 +1,4 @@
#ifndef FW_VERSION_H
#define FW_VERSION_H

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

high

This header file is currently empty. It should contain the definition for AppVersion_t and an extern declaration for the global g_app_version variable. This will allow other modules to include this header and access the firmware version information.

Suggested change
#include <stdint.h>
typedef struct {
char magic[4];
uint8_t major;
uint8_t minor;
uint16_t patch;
char build_date[12];
} AppVersion_t;
extern const AppVersion_t g_app_version;

Comment on lines +156 to +158
final_defines.append("APP_VERS_MAJOR=" + version.split(".")[0])
final_defines.append("APP_VERS_MINOR=" + version.split(".")[1])
final_defines.append("APP_VERS_PATCH=" + version.split(".")[2])
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

high

The current implementation for parsing the version string is not robust. It assumes the version string will always be in the format "major.minor.patch". If a user provides a version string with fewer than two dots (e.g., "1.0"), this code will raise an IndexError and cause the build to fail. It's better to validate the version string format to provide a clear error message and prevent build failures.

    version_parts = version.split(".")
    if len(version_parts) != 3:
        fail("Version string must be in the format 'major.minor.patch', but got '{}'".format(version))

    final_defines.append("APP_VERS_MAJOR=" + version_parts[0])
    final_defines.append("APP_VERS_MINOR=" + version_parts[1])
    final_defines.append("APP_VERS_PATCH=" + version_parts[2])

@@ -0,0 +1,17 @@
#include <stdint.h>
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

It is a common best practice for a source file to include its own header file. This ensures that the header is self-contained and that its declarations are consistent with the definitions in the source file. This also simplifies dependency management, as including fw_version.h will transitively include <stdint.h> (based on my other suggestion).

Suggested change
#include <stdint.h>
#include "fw_version.h"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant