GithubHelp home page GithubHelp logo

jonnydyer / add-version-info Goto Github PK

View Code? Open in Web Editor NEW

This project forked from thomask77/add-version-info

0.0 1.0 0.0 13 KB

Add CRC checksum and version information to ELF and binary files

Python 100.00%

add-version-info's Introduction

Add CRC checksum and version information to ELF and binary files

Embedded programmers often face the task to insert a checksum into binaries after linking. A bootloader can then verify the checksum before allowing a firmware update or running the program.

add_version_info is a small python script that can insert version control information and checksums into ELF or binary firmware images.

Usage

The tool will search for two 16 byte markers in the firmware image and fill in a structure with the current git or subversion id, a checksum, and build time information. The checksum is forged, so that running a CRC32 check over the entire image will yield the requested checksum.

Example

version.h

#include <stdint.h>

#define VCS_INFO_START "VCSINFO2_START->"
#define VCS_INFO_END   "<---VCSINFO2_END"

struct version_info {
    char        vcs_info_start[16];

    // set by add-version-info.py
    //
    uint32_t    image_crc;
    uint32_t    image_start;
    uint32_t    image_size;

    char        vcs_id[32];
    char        build_user[16];
    char        build_host[16];
    char        build_date[16];
    char        build_time[16];

    // set at compile-time
    //
    char        product_name[32];
    int         major;
    int         minor;
    int         patch;

    char        vcs_info_end[16];
};

extern volatile const struct version_info  version_info;

void print_version_info(const struct version_info *v);

version.c

#include "version.h"

volatile const struct version_info version_info = {
    .vcs_info_start = VCS_INFO_START,
    .product_name   = "add_version_info example",
    .major          = 1,
    .minor          = 2,
    .patch          = 3,
    .vcs_info_end   = VCS_INFO_END
};

void print_version_info(const struct version_info *v)
{
    printf(
        "%s v%d.%d.%d %s\n\r"
        "Compiled %s %s by %s on %s\n\r"
        "Image Start: 0x%x Size: %d\n\r"
        "Image CRC: 0x%x\n",
        v->product_name,
        v->major, v->minor, v->patch,
        v->vcs_id,
        v->build_date, v->build_time,
        v->build_user, v->build_host,
        v->image_start, v->image_size,
        v->image_crc
    );

}

void main(void)
{
    print_version_info(&version_info);
}

Makefile rule

# Link: create ELF output file from object files
#
$(TARGET).elf: $(OBJECTS)
	@echo
	@echo Linking: $@
	$(CC) $(OBJECTS) $(LDFLAGS) --output $(basename $@).tmp

	@echo
	@echo Post-processing: $@
	add-version-info.py -v $(basename $@).tmp $@

add-version-info's People

Contributors

jonnydyer avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.