blob: c56434c3b9fe12c8494a54319f14ee7f828175e3 [file] [log] [blame]
rjw1f884582022-01-06 17:20:42 +08001/*
2 * Copyright (c) 2013 Google, Inc.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining
5 * a copy of this software and associated documentation files
6 * (the "Software"), to deal in the Software without restriction,
7 * including without limitation the rights to use, copy, modify, merge,
8 * publish, distribute, sublicense, and/or sell copies of the Software,
9 * and to permit persons to whom the Software is furnished to do so,
10 * subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be
13 * included in all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
19 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
20 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
21 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 */
23#include <lib/version.h>
24
25#include <debug.h>
26#include <stdio.h>
27#include <lk/init.h>
28
29/* generated for us */
30#include <buildid.h>
31
32/* ARCH, PLATFORM, TARGET, PROJECT should be defined by the build system */
33
34/* BUILDID is optional, and may be defined anywhere */
35#ifndef BUILDID
36#define BUILDID ""
37#endif
38
39const lk_version_t version = {
40 .struct_version = VERSION_STRUCT_VERSION,
41 .arch = ARCH,
42 .platform = PLATFORM,
43 .target = TARGET,
44 .project = PROJECT,
45 .buildid = BUILDID
46};
47
48void print_version(void)
49{
50 printf("version:\n");
51 printf("\tarch: %s\n", version.arch);
52 printf("\tplatform: %s\n", version.platform);
53 printf("\ttarget: %s\n", version.target);
54 printf("\tproject: %s\n", version.project);
55 printf("\tbuildid: %s\n", version.buildid);
56}
57
58#if WITH_LIB_CONSOLE
59
60#include <debug.h>
61#include <lib/console.h>
62
63static int cmd_version(int argc, const cmd_args *argv)
64{
65 print_version();
66 return 0;
67}
68
69STATIC_COMMAND_START
70STATIC_COMMAND("version", "print version", &cmd_version)
71STATIC_COMMAND_END(version);
72
73#endif // WITH_LIB_CONSOLE
74
75#if LK_DEBUGLEVEL > 0
76// print the version string if any level of debug is set
77LK_INIT_HOOK(version, (void *)&print_version, LK_INIT_LEVEL_HEAP - 1);
78#endif
79