summaryrefslogtreecommitdiff
path: root/common/version.c
blob: ff8207bf2c4184b1611b6365205b4f16c05a131b (plain)
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
/* Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

/* Embed firmware version number in the binary */

#include <stdint.h>
#include "common.h"
#include "ec_version.h"
#include "version.h"

const struct image_data __keep current_image_data
	__attribute__((section(".rodata.ver"))) = {
	.cookie1 = CROS_EC_IMAGE_DATA_COOKIE1,
	.version = CROS_EC_VERSION32,
#ifndef TEST_BUILD
	.size = (const uintptr_t)&__image_size,
#endif
	.cookie2 = CROS_EC_IMAGE_DATA_COOKIE2,
};

const char build_info[] __keep __attribute__((section(".rodata.buildinfo"))) =
	CROS_EC_VERSION " " DATE " " BUILDER;

uint32_t ver_get_numcommits(void)
{
	int i;
	int numperiods = 0;
	uint32_t ret = 0;

	/*
	 * Version string is formatted like:
	 * name_major.branch.numcommits-hash[dirty]
	 * we want to return the numcommits as an int.
	 */
	for (i = 0; i < 32; i++) {
		if (current_image_data.version[i] == '.') {
			numperiods++;
			if (numperiods == 2)
				break;
		}
	}

	i++;
	for (; i < 32; i++) {
		if (current_image_data.version[i] == '-')
			break;
		ret *= 10;
		ret += current_image_data.version[i] - '0';
	}

	return (i == 32 ? 0 : ret);
}