Files
OpenCellular/common/version.c
Anton Staaf 8513e23df1 USB: Remove special case for iVersion string descriptor
Previously the version string was special cased in the USB stack
because the build system prevented the inclusion of ec_version.h in
any file other than common/version.c.  This lead to common/version.c
being the only place that the USB version string could be computed
and thus the special case of filling in the version string descriptor
at run time.  This made the USB stack more complex, and lead to the
common/version.c file including usb.h, which is actually STM32
specific.

Now, the portion of ec_version.h that is deterministic is only
updated when something in the tree actually changes (by way of a
conditional in the makefile), and ec_version.h no longer has to
depend on all object files (other than the special version.o).
This allows anyone to include ec_version.h as needed.  In particular,
each board that wants to define a USB version string can directly
include ec_version.h and do so.

Signed-off-by: Anton Staaf <robotboy@chromium.org>

BRANCH=None
BUG=None
TEST=make buildall -j
     touch files and verify rebuilds happen correctly

Change-Id: Ic84d0b9da90f82ebb4630fb550ec841071e25a49
Reviewed-on: https://chromium-review.googlesource.com/227211
Tested-by: Anton Staaf <robotboy@chromium.org>
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
Commit-Queue: Anton Staaf <robotboy@chromium.org>
2014-11-04 21:34:39 +00:00

54 lines
1.1 KiB
C

/* 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_date.h"
#include "ec_version.h"
#include "version.h"
const struct version_struct version_data
__attribute__((section(".rodata.ver"))) = {
CROS_EC_VERSION_COOKIE1,
CROS_EC_VERSION32,
CROS_EC_VERSION_COOKIE2
};
const char build_info[] __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 (version_data.version[i] == '.') {
numperiods++;
if (numperiods == 2)
break;
}
}
i++;
for (; i < 32; i++) {
if (version_data.version[i] == '-')
break;
ret *= 10;
ret += version_data.version[i] - '0';
}
return (i == 32 ? 0 : ret);
}