-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathversion.c
More file actions
95 lines (77 loc) · 1.75 KB
/
Copy pathversion.c
File metadata and controls
95 lines (77 loc) · 1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#include <mios/version.h>
#include <mios/eventlog.h>
#include <stdio.h>
#include <stdint.h>
#include <string.h>
const char _appname[] __attribute__((section("appname"))) = APPNAME;
uint8_t _miosversion[21] __attribute__((section("miosversion")));
uint8_t _appversion[21] __attribute__((section("appversion")));
const char *
mios_get_app_name(void)
{
return _appname;
}
const uint8_t *
mios_get_app_version(void)
{
return _appversion;
}
const uint8_t *
mios_get_mios_version(void)
{
return _miosversion;
}
static void
stprintversion(stream_t *s, const uint8_t *ver)
{
uint8_t or = 0;
for(size_t i = 0; i < 21; i++) {
or |= ver[i];
}
if(or == 0) {
stprintf(s, "no-version-info\n");
return;
}
sthexstr(s, ver, 20);
stprintf(s, "%s\n", ver[20] ? "-dirty" : "");
}
void
log_sysinfo(void)
{
evlog(LOG_NOTICE, "System booted");
if(APPNAME[0]) {
evlog(LOG_NOTICE, "%s version: %.*s%s", APPNAME,
-20, _appversion, _appversion[20] ? "-dirty" : "");
}
evlog(LOG_NOTICE, "Mios version: %.*s%s",
-20, _miosversion, _miosversion[20] ? "-dirty" : "");
evlog(LOG_NOTICE, "Build: %.*s", -20, mios_build_id());
}
void
mios_print_version(stream_t *s)
{
if(APPNAME[0]) {
stprintf(s, "%s version:", APPNAME);
stprintversion(s, _appversion);
}
stprintf(s, "Mios version:");
stprintversion(s, _miosversion);
#ifdef MIOS_BUILD_TIMESTAMP
stprintf(s, "Build time: %s\n", MIOS_BUILD_TIMESTAMP);
#endif
stprintf(s, "BuildID: ");
sthexstr(s, mios_build_id(), 20);
stprintf(s, "\n");
}
typedef struct {
uint32_t namesz;
uint32_t descsz;
uint32_t type;
uint8_t data[];
} ElfNoteSection_t;
extern ElfNoteSection_t _build_id;
const unsigned char *
mios_build_id(void)
{
return &_build_id.data[_build_id.namesz];
}