diff options
author | Vincent Palatin <vpalatin@chromium.org> | 2012-02-29 00:39:41 +0000 |
---|---|---|
committer | Vincent Palatin <vpalatin@chromium.org> | 2012-03-02 16:46:26 +0000 |
commit | a94e3277b332536a01d8e109f5ae277dcfe82337 (patch) | |
tree | 123b8db7b44a2b09fa80629b0cf92a9f3ebceff4 | |
parent | 1db93690d9b3fed1690f6645408384451c42519b (diff) | |
download | chrome-ec-a94e3277b332536a01d8e109f5ae277dcfe82337.tar.gz |
update versioning information stored in the EC
Add build information (date/time/builder) which can be displayed at the
EC console.
Generate a version from the board name and the branch tag.
Signed-off-by: Vincent Palatin <vpalatin@chromium.org>
BUG=chromium-os:27013
TEST=on BDS, run version command on the console.
inspect the built binary.
Change-Id: Idb1f68898ba6b811d02919f17ab4536ed9f8934a
-rw-r--r-- | Makefile | 2 | ||||
-rw-r--r-- | Makefile.rules | 5 | ||||
-rw-r--r-- | common/build.mk | 2 | ||||
-rw-r--r-- | common/main.c | 4 | ||||
-rw-r--r-- | common/system.c | 37 | ||||
-rw-r--r-- | common/version.c | 20 | ||||
-rw-r--r-- | core/cortex-m/ec.lds.S | 4 | ||||
-rw-r--r-- | core/cortex-m/init.S | 11 | ||||
-rw-r--r-- | include/system.h | 5 | ||||
-rw-r--r-- | include/version.h | 23 | ||||
-rwxr-xr-x | util/getversion.sh | 33 |
11 files changed, 106 insertions, 40 deletions
@@ -45,6 +45,6 @@ all-y+=$(call objs_from_dir,private,$(private-y)) all-y+=$(call objs_from_dir,common,$(common-y)) all-y+=$(call objs_from_dir,test,$($(PROJECT)-y)) dirs=core/$(CORE) chip/$(CHIP) board/$(BOARD) private common test util -includes=include core/$(CORE)/include $(dirs) +includes=include core/$(CORE)/include $(dirs) $(out) include Makefile.rules diff --git a/Makefile.rules b/Makefile.rules index b92e9a6efc..647a7b27c3 100644 --- a/Makefile.rules +++ b/Makefile.rules @@ -35,6 +35,7 @@ cmd_c_to_build = $(BUILDCC) $(BUILD_CFLAGS) $(BUILD_LDFLAGS) \ cmd_c_to_host = $(HOSTCC) $(HOST_CFLAGS) -MMD -MF $@.d $< -o $@ cmd_qemu = ./util/run_qemu_test --image=build/$(BOARD)/$*/$*.bin test/$*.py \ $(silent) +cmd_version = ./util/getversion.sh > $@ .PHONY: all tests utils @@ -85,6 +86,10 @@ $(out)/%.o:%.c $(out)/%.o:%.S $(call quiet,c_to_o,AS ) +$(out)/common/version.o: $(out)/ec_version.h +$(out)/ec_version.h: $(filter-out $(out)/common/version.o,$(objs)) + $(call quiet,version,VERSION) + $(build-utils): $(out)/%:%.c $(call quiet,c_to_build,BUILDCC) diff --git a/common/build.mk b/common/build.mk index 00386b15b3..82a49bf079 100644 --- a/common/build.mk +++ b/common/build.mk @@ -7,7 +7,7 @@ common-y=main.o util.o console.o vboot.o uart_buffering.o usb_charge_commands.o common-y+=memory_commands.o shared_mem.o system.o usb_charge.o -common-y+=gpio_commands.o +common-y+=gpio_commands.o version.o common-$(CONFIG_LPC)+=port80.o common-$(CONFIG_TASK_HOSTCMD)+=host_command.o common-$(CONFIG_TASK_I8042CMD)+=i8042.o keyboard.o diff --git a/common/main.c b/common/main.c index 628227d627..887312f6e5 100644 --- a/common/main.c +++ b/common/main.c @@ -96,9 +96,9 @@ int main(void) /* Print the reset cause */ uart_printf("\n\n--- Chrome EC initialized! ---\n"); - uart_printf("(image: %s, version: %s, last reset: %s)\n", + uart_printf("build: %s\n", system_get_build_info()); + uart_printf("(image: %s, last reset: %s)\n", system_get_image_copy_string(), - system_get_version(SYSTEM_IMAGE_UNKNOWN), system_get_reset_cause_string()); /* Launch task scheduling (never returns) */ diff --git a/common/system.c b/common/system.c index ff242b9796..5bbc78f599 100644 --- a/common/system.c +++ b/common/system.c @@ -11,18 +11,6 @@ #include "util.h" #include "version.h" -struct version_struct { - uint32_t cookie1; - char version[32]; - uint32_t cookie2; -} __attribute__ ((packed)); - -static const struct version_struct version_data = { - 0xce112233, - CROS_EC_VERSION_STRING, - 0xce445566 -}; - static enum system_reset_cause_t reset_cause = SYSTEM_RESET_UNKNOWN; enum system_reset_cause_t system_get_reset_cause(void) @@ -116,7 +104,6 @@ int system_run_image_copy(enum system_image_copy_t copy) const char *system_get_version(enum system_image_copy_t copy) { int imoffset; - const uint32_t *p, *pend; const struct version_struct *v; /* Handle version of current image */ @@ -139,23 +126,20 @@ const char *system_get_version(enum system_image_copy_t copy) return ""; } - /* Search for version cookies in target image */ - /* TODO: (crosbug.com/p/7469) could be smarter about where to - * search if we stuffed the version data into a predefined - * area of the image - for example, immediately following the - * reset vectors. */ - pend = (uint32_t *)(imoffset + CONFIG_FW_IMAGE_SIZE - - sizeof(version_data)); - for (p = (uint32_t *)imoffset; p <= pend; p++) { - v = (const struct version_struct *)p; - if (v->cookie1 == version_data.cookie1 && - v->cookie2 == version_data.cookie2) - return v->version; - } + /* The version string is always located after the reset vectors */ + v = (const struct version_struct *)((uint8_t *)&version_data + + imoffset); + if (v->cookie1 == version_data.cookie1 && + v->cookie2 == version_data.cookie2) + return v->version; return ""; } +const char *system_get_build_info(void) +{ + return build_info; +} static int command_sysinfo(int argc, char **argv) { @@ -221,6 +205,7 @@ static int command_version(int argc, char **argv) system_get_version(SYSTEM_IMAGE_RW_A)); uart_printf("RW-B version: %s\n", system_get_version(SYSTEM_IMAGE_RW_B)); + uart_printf("Current build: %s\n", system_get_build_info()); return EC_SUCCESS; } DECLARE_CONSOLE_COMMAND(version, command_version); diff --git a/common/version.c b/common/version.c new file mode 100644 index 0000000000..36567095ff --- /dev/null +++ b/common/version.c @@ -0,0 +1,20 @@ +/* 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 "ec_version.h" +#include "version.h" + +const struct version_struct version_data + __attribute__((section(".rodata.ver"))) = { + CROS_EC_VERSION_COOKIE1, + CROS_EC_VERSION, + CROS_EC_VERSION_COOKIE2 +}; + +const char build_info[] __attribute__((section(".rodata.buildinfo"))) = + CROS_EC_BUILD_INFO; diff --git a/core/cortex-m/ec.lds.S b/core/cortex-m/ec.lds.S index 94027c7b61..04c95f85e4 100644 --- a/core/cortex-m/ec.lds.S +++ b/core/cortex-m/ec.lds.S @@ -18,6 +18,10 @@ MEMORY SECTIONS { .text : { + OUTDIR/core/CORE/init.o (.text.vecttable) + . = ALIGN(4); + *(.rodata.ver) + . = ALIGN(4); OUTDIR/core/CORE/init.o (.text) *(.text*) #ifdef COMPILE_FOR_RAM diff --git a/core/cortex-m/init.S b/core/cortex-m/init.S index 576247d925..f8fa196dee 100644 --- a/core/cortex-m/init.S +++ b/core/cortex-m/init.S @@ -7,10 +7,7 @@ #include "config.h" -.text - -.syntax unified -.code 16 +.section .text.vecttable .macro vector name .long \name\()_handler @@ -298,11 +295,15 @@ vector_irq 252 @ IRQ 252 handler vector_irq 253 @ IRQ 253 handler vector_irq 254 @ IRQ 254 handler +.text +.syntax unified +.code 16 + .global reset .thumb_func reset: /* set the vector table on our current code */ - adr r1, vectors + ldr r1, =vectors ldr r2, =0xE000ED08 /* VTABLE register in SCB*/ str r1, [r2] /* Clear BSS */ diff --git a/include/system.h b/include/system.h index 23607cfcaa..0259f357c9 100644 --- a/include/system.h +++ b/include/system.h @@ -76,6 +76,11 @@ int system_run_image_copy(enum system_image_copy_t copy); * currently-running image. */ const char *system_get_version(enum system_image_copy_t copy); +/* Returns information about the build including the version + * the build date and user/machine. + */ +const char *system_get_build_info(void); + /* Resets the system. If is_cold!=0, performs a cold reset (which * resets on-chip peripherals); else performs a warm reset (which does * not reset on-chip peripherals). If successful, does not return. diff --git a/include/version.h b/include/version.h index 0031339c34..0ded5513e1 100644 --- a/include/version.h +++ b/include/version.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2011 The Chromium OS Authors. All rights reserved. +/* 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. */ @@ -8,9 +8,22 @@ #ifndef __CROS_EC_VERSION_H #define __CROS_EC_VERSION_H -#define CROS_EC_VERSION_MAJOR 0 -#define CROS_EC_VERSION_MINOR 1 -#define CROS_EC_VERSION_SUBMINOR 2 -#define CROS_EC_VERSION_STRING "Link.0.1.2" +#define STRINGIFY0(name) #name +#define STRINGIFY(name) STRINGIFY0(name) + +#define CROS_EC_VERSION_COOKIE1 0xce112233 +#define CROS_EC_VERSION_COOKIE2 0xce445566 + +#define CROS_EC_VERSION STRINGIFY(BOARD) "_" VERSION +#define CROS_EC_BUILD_INFO CROS_EC_VERSION " " DATE " " BUILDER + +struct version_struct { + uint32_t cookie1; + char version[32]; + uint32_t cookie2; +} __attribute__ ((packed)); + +extern const struct version_struct version_data; +extern const char build_info[]; #endif /* __CROS_EC_VERSION_H */ diff --git a/util/getversion.sh b/util/getversion.sh new file mode 100755 index 0000000000..93900fcaf6 --- /dev/null +++ b/util/getversion.sh @@ -0,0 +1,33 @@ +#!/bin/bash +# +# 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. +# +# Generate version information for the EC binary + +if ghash=`git rev-parse --short --verify HEAD 2>/dev/null`; then + if gdesc=`git describe --dirty --match='v*' 2>/dev/null`; then + IFS="-" fields=($gdesc) + tag="${fields[0]}" + IFS="." vernum=($tag) + numcommits=$((${vernum[2]}+${fields[1]:-0})) + ver_major="${vernum[0]}" + ver_branch="${vernum[1]}" + else + numcommits=`git rev-list HEAD | wc -l` + ver_major="v0" + ver_branch="0" + fi + # avoid putting the -dirty attribute if only the timestamp + # changed + git status > /dev/null 2>&1 + + dirty=`sh -c "[ $(git diff-index --name-only HEAD) ] && echo '-dirty'"` + ver="${ver_major}.${ver_branch}.${numcommits}-${ghash}${dirty}" +else + ver="no_version" +fi +echo "#define VERSION \"${ver}\"" +echo "#define DATE \"`date '+%F %T'`\"" +echo "#define BUILDER \"${USER}@`hostname`\"" |