add version info
1.0.0
임베디드 프로그래머는 종종 연결 후 체크섬을 바이너리에 삽입하는 작업에 직면합니다. 그런 다음 부트 로더는 펌웨어 업데이트를 허용하거나 프로그램을 실행하기 전에 체크섬을 확인할 수 있습니다.
add_version_info 버전 제어 정보와 체크섬을 ELF 또는 이진 펌웨어 이미지에 삽입 할 수있는 작은 파이썬 스크립트입니다.
이 도구는 펌웨어 이미지에서 2 개의 16 바이트 마커를 검색하고 현재 GIT 또는 Subversion ID, 체크섬 및 구축 시간 정보로 구조를 작성합니다. 체크섬이 위조되어 전체 이미지를 통해 CRC32 점검을 실행하면 요청 된 체크섬이 생성됩니다.
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 ( int verbose );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 %s %sn"
" Compiled %s %s by %s on %sn"
v -> product_name ,
v -> major , v -> minor , v -> patch ,
v -> vcs_id ,
v -> build_date , v -> build_time ,
v -> build_date , v -> build_time ,
v -> build_user , v -> build_host
);
}
void main ( void )
{
print_version_info ( & version_info );
}Makefile 규칙 # 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 $@