1 /*
2  * Copyright (c) 2013 Google, Inc.
3  *
4  * Use of this source code is governed by a MIT-style
5  * license that can be found in the LICENSE file or at
6  * https://opensource.org/licenses/MIT
7  */
8 #include <lib/version.h>
9 
10 #include <lk/debug.h>
11 #include <stdio.h>
12 #include <lk/init.h>
13 #include <lk/console_cmd.h>
14 
15 /* generated for us */
16 #include <buildid.h>
17 
18 /* ARCH, PLATFORM, TARGET, PROJECT should be defined by the build system */
19 
20 /* BUILDID is optional, and may be defined anywhere */
21 #ifndef BUILDID
22 #define BUILDID ""
23 #endif
24 
25 const lk_version_t lk_version = {
26     .struct_version = VERSION_STRUCT_VERSION,
27     .arch = ARCH,
28     .platform = PLATFORM,
29     .target = TARGET,
30     .project = PROJECT,
31     .buildid = BUILDID
32 };
33 
print_version(void)34 void print_version(void) {
35     printf("version:\n");
36     printf("\tarch:     %s\n", lk_version.arch);
37     printf("\tplatform: %s\n", lk_version.platform);
38     printf("\ttarget:   %s\n", lk_version.target);
39     printf("\tproject:  %s\n", lk_version.project);
40     printf("\tbuildid:  %s\n", lk_version.buildid);
41 }
42 
cmd_version(int argc,const console_cmd_args * argv)43 static int cmd_version(int argc, const console_cmd_args *argv) {
44     print_version();
45     return 0;
46 }
47 
48 STATIC_COMMAND_START
49 STATIC_COMMAND("version", "print version", &cmd_version)
50 STATIC_COMMAND_END(version);
51 
52 #if LK_DEBUGLEVEL > 0
53 // print the version string if any level of debug is set
54 LK_INIT_HOOK(version, (void *)&print_version, LK_INIT_LEVEL_HEAP - 1);
55 #endif
56