Verified Commit f3830f3c authored by Rahix's avatar Rahix
Browse files

feat: Include version in binaries



This commit adds a script to embed the git-version of the firmware into
the bootloader, epicardium, and pycardium.  All three binaries will
display their version on startup.

Signed-off-by: Rahix's avatarRahix <rahix@rahix.de>
parent 6aa9d9b7
#include "bootloader.h"
/* Autogenerated */
#include "splash-screen.h"
#include "card10-version.h"
#include "gfx.h"
#include "display.h"
......@@ -46,8 +47,12 @@ void bootloader_display_init(void)
*/
void bootloader_display_header(void)
{
txt_puts(&display_textb, "Bootloader\n");
txt_puts(&display_textb, __DATE__ "\n");
gfx_clear(&display_screen);
Color white = gfx_color(&display_screen, WHITE);
bootloader_display_line(0, "Bootloader", white);
bootloader_display_line(1, __DATE__, white);
bootloader_display_line(2, CARD10_VERSION, white);
}
/*
......
......@@ -123,12 +123,12 @@ void bootloader_stop(void)
void bootloader_dirty(void)
{
bootloader_display_line(3, "Writing.", 0xf000);
bootloader_display_line(4, "Writing.", 0xf000);
}
void bootloader_clean(void)
{
bootloader_display_line(3, "Ready. ", 0xffff);
bootloader_display_line(4, "Ready. ", 0xffff);
}
/******************************************************************************/
......
#include "bootloader.h"
#include "card10-version.h"
#include "card10.h"
#include "led.h"
......@@ -197,7 +198,7 @@ static void pmic_button(bool falling)
/******************************************************************************/
int main(void)
{
printf("\n\nBootloader\n");
printf("\n\nBootloader " CARD10_VERSION "\n");
card10_init();
/*
......@@ -210,8 +211,8 @@ int main(void)
// If the button is pressed, we go into MSC mode.
if (PB_Get(3)) {
bootloader_display_header();
bootloader_display_line(2, "USB activated.", 0xffff);
bootloader_display_line(3, "Ready.", 0xffff);
bootloader_display_line(3, "USB activated.", 0xffff);
bootloader_display_line(4, "Ready.", 0xffff);
run_usbmsc();
// If we return, don't try to boot. Maybe rather trigger a software reset.
......@@ -229,7 +230,7 @@ int main(void)
printf("card10.bin CRC is invalid!\n");
bootloader_display_header();
bootloader_display_line(
2, "Integrity check failed", 0xffff
3, "Integrity check failed", 0xffff
);
bootloader_display_line(4, "Trying to boot", 0xffff);
......@@ -239,7 +240,7 @@ int main(void)
printf("Trying to update firmware from external flash\n");
bootloader_display_header();
bootloader_display_line(
3, "Updating ...", 0xffff
4, "Updating ...", 0xffff
);
erase_partition();
flash_partition();
......@@ -253,7 +254,7 @@ int main(void)
} else {
bootloader_display_header();
bootloader_display_line(
2, "Failed to mount filesystem", 0xffff
3, "Failed to mount filesystem", 0xffff
);
printf("Failed to mount the external flash\n");
......
......@@ -21,6 +21,7 @@ executable(
'bootloader-usb.c',
'crc16-ccitt.c',
splash_screen,
version_hdr,
dependencies: [
libcard10,
max32665_startup_boot,
......
......@@ -21,6 +21,7 @@
#include "Heart.h"
#include "gfx.h"
#include "display.h"
#include "card10-version.h"
#include "FreeRTOS.h"
#include "task.h"
......@@ -47,6 +48,7 @@ void vApiDispatcher(void *pvParameters)
int main(void)
{
LOG_INFO("startup", "Epicardium startup ...");
LOG_INFO("startup", "Version " CARD10_VERSION);
card10_init();
card10_diag();
......
......@@ -78,6 +78,7 @@ elf = executable(
module_sources,
l0der_sources,
ble_sources,
version_hdr,
dependencies: [libcard10, max32665_startup_core0, maxusb, libff13, ble],
link_with: [api_dispatcher_lib, freertos],
link_whole: [max32665_startup_core0_lib, board_card10_lib, newlib_heap_lib],
......
......@@ -37,6 +37,15 @@ add_global_link_arguments(
# python3 = import('python').find_installation('python3')
python3 = 'python3'
# Version Header
version_hdr = custom_target(
'card10-version.h',
output: 'card10-version.h',
build_by_default: true,
build_always_stale: true,
command: [files('tools/version-header.sh'), '@OUTPUT@'],
)
subdir('lib/')
subdir('bootloader/')
......
#include "mphalport.h"
#include "card10-version.h"
#include "max32665.h"
......@@ -13,8 +14,17 @@
extern void *__StackTop, *__StackLimit;
extern void *__HeapBase, *__HeapLimit;
static const char header[] =
"--------------------------------\r\n"
" Pycardium\r\n"
" Version: " CARD10_VERSION
"\r\n"
"--------------------------------\r\n";
int main(void)
{
epic_uart_write_str(header, sizeof(header));
pycardium_hal_init();
mp_stack_set_top(&__StackTop);
......
......@@ -78,6 +78,7 @@ elf = executable(
frozen_source,
modsrc,
mp_headers,
version_hdr,
include_directories: micropython_includes,
dependencies: [max32665_startup_core1, periphdriver, api_caller],
link_with: upy,
......
#!/usr/bin/env bash
#
# Generate a version header which defines
#
# CARD10_VERSION
# CARD10_GITHASH
FW_REPO="$(dirname "$0")/.."
HEADERFILE="$1"
VERSION="$(git -C "$FW_REPO" describe --always --dirty)"
GITHASH="$(git -C "$FW_REPO" rev-parse HEAD)"
TMPHEADER="$(mktemp)"
cat >"$TMPHEADER" <<EOF
/* Autogenerated. DO NOT EDIT */
#ifndef _CARD10_VERSION
#define _CARD10_VERSION
#define CARD10_VERSION "$VERSION"
#define CARD10_GITHASH "$GITHASH"
#endif /* _CARD10_VERSION */
EOF
if ! cmp -s "$TMPHEADER" "$HEADERFILE"; then
cp "$TMPHEADER" "$HEADERFILE"
fi
rm "$TMPHEADER"
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment