Files
OpenCellular/common/version.c
Nicolas Boichat ca0e826859 common/rollback: Add support for rollback protection
Implement actual rollback protection. First, we add a new field
in the version structure, which is an incrementing integer
(we'll start by shipping images with version 0, and gradually
increase the number as required). This allows us to release
new versions of the EC without necessarily bumping the rollback
protection.

For the rollback protection block itself, it contains 2 sub-blocks
of equal size (normally, 2k), that are individually erasable.
The rollback code looks at both, and takes the most restrictive one
to determine the desired rollback minimum version. The blocks
are also allowed to be erased (full of 1's), in which case the
rollback minimum version is assumed to be 0.

We also add an FMAP entry, in case we later decide to allow the
signer to increment the rollback version.

Also note that, like any version_data struct change, this change
breaks compatibility between old and new RO/RW.

Follow-up code will take care of auto-updating the rollback block
as required, and properly manage block protection.

BRANCH=none
BUG=b:35586219
TEST=Flash hammer
     rollbackinfo => 1 version 0 block, 1 empty block, RW verifies
           correctly.
     rollbackupdate 0; rollbackinfo => No change
     rollbackupdate 1; reboot => RO refuses to jump to RW
     rollbackupdate 2, 3, 4; rollbackinfo => Writes alternate
           between the 2 blocks.
     rollbackupdate 2 => Refuses to downgrade version

Change-Id: Ia969afb481a93deb912b9153bdd95ace01ad8fa7
Reviewed-on: https://chromium-review.googlesource.com/452815
Commit-Ready: Nicolas Boichat <drinkcat@chromium.org>
Tested-by: Nicolas Boichat <drinkcat@chromium.org>
Reviewed-by: Randall Spangler <rspangler@chromium.org>
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
2017-04-06 03:29:38 -07:00

60 lines
1.4 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 "compile_time_macros.h"
#include "ec_version.h"
#include "version.h"
BUILD_ASSERT(CONFIG_ROLLBACK_VERSION >= 0);
BUILD_ASSERT(CONFIG_ROLLBACK_VERSION <= INT32_MAX);
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
.rollback_version = CONFIG_ROLLBACK_VERSION,
.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);
}