summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVadim Bendebury <vbendeb@chromium.org>2017-09-05 18:09:40 -0700
committerchrome-bot <chrome-bot@chromium.org>2017-09-13 21:47:07 -0700
commit857ab8ffa23cdceb019323d96ec076df71809486 (patch)
treebe115848534fac5434b08e3257a68095fed23fa6
parent3c2adda3267c9d1ba9d04f6a10fec09de45e1a4f (diff)
downloadchrome-ec-857ab8ffa23cdceb019323d96ec076df71809486.tar.gz
cr50: generate self signed images with proper header values
The self signed images generated when running 'make BOARD=cr50' use constant default values for the epoch, major and minor image header fields. For the purposes of continuous testing we need the generated images have sensible values in those header fields. Since adding a full blown C++ based parser to the signer image is too much trouble, let's just have a very basic Python based parser, which pays attention only to the required fields from the current manifest. BRANCH=cr50 BUG=none TEST=built the new image and checked its version: $ make BOARD=cr50 ... $ ./extra/usb_updater/usb_updater -b build/cr50/ec.bin read 524288(0x80000) bytes from build/cr50/ec.bin RO_A:0.0.23 RW_A:0.0.23[00000000:00000000:00000000] RO_B:-1.-1.-1 ... Change-Id: I822475ed0a3c481b08e9268f9c13663b0b132d4a Signed-off-by: Vadim Bendebury <vbendeb@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/651132 Reviewed-by: Marius Schilder <mschilder@chromium.org> Reviewed-by: Mary Ruthven <mruthven@chromium.org>
-rw-r--r--util/signer/build.mk11
-rw-r--r--util/signer/codesigner.cc6
-rwxr-xr-xutil/signer/pmjp.py53
3 files changed, 67 insertions, 3 deletions
diff --git a/util/signer/build.mk b/util/signer/build.mk
index 07db0ea7ea..88fea91bce 100644
--- a/util/signer/build.mk
+++ b/util/signer/build.mk
@@ -10,7 +10,14 @@ signer_INC := $(addprefix common/, aes.h ecdh.h gnubby.h \
signer_SRC := codesigner.cc publickey.cc image.cc gnubby.cc aes.cc ecdh.cc
SIGNER_DEPS := $(addprefix $(signer_ROOT)/, $(signer_SRC) $(signer_INC))
-HOST_CXXFLAGS += -I/usr/include/libxml2
-$(out)/util/signer: $(SIGNER_DEPS)
+HOST_CXXFLAGS += -I/usr/include/libxml2 -I $(out)
+$(out)/util/signer: $(SIGNER_DEPS) $(out)/pmjp.h
$(call quiet,cxx_to_host,HOSTCXX)
+# When building self signed Cr50 images we still want the epoch/major/minor
+# fields come from the dev manifest. Since a full blown JSON parser for C is
+# not readily available, this rule generates a small .h file with only the
+# fields of interest retrieved from the dev JSON file.
+$(out)/pmjp.h: util/signer/pmjp.py util/signer/ec_RW-manifest-dev.json
+ @echo " PMJP $@"
+ $(Q)./util/signer/pmjp.py ./util/signer/ec_RW-manifest-dev.json > $@
diff --git a/util/signer/codesigner.cc b/util/signer/codesigner.cc
index f489851ee0..89b23eccd2 100644
--- a/util/signer/codesigner.cc
+++ b/util/signer/codesigner.cc
@@ -17,6 +17,8 @@
#include <common/signed_header.h>
#ifdef HAVE_JSON
#include <rapidjson/document.h>
+#else
+#include <pmjp.h>
#endif
#include <map>
@@ -433,7 +435,9 @@ int main(int argc, char* argv[]) {
if (jsonFilename.empty()) {
// Defaults, in case no JSON
values.insert(make_pair("keyid", key.n0inv()));
- values.insert(make_pair("epoch", 0x1337));
+ values.insert(make_pair("epoch", MANIFEST_EPOCH));
+ values.insert(make_pair("major", MANIFEST_MAJOR));
+ values.insert(make_pair("minor", MANIFEST_MINOR));
}
// Hardcoded expectation. Can be overwritten in JSON w/ new explicit value.
diff --git a/util/signer/pmjp.py b/util/signer/pmjp.py
new file mode 100755
index 0000000000..92e3db035c
--- /dev/null
+++ b/util/signer/pmjp.py
@@ -0,0 +1,53 @@
+#!/usr/bin/python
+# Copyright 2017 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.
+
+"""Poor man's JSON parser.
+
+This module reads the input JSON file, retrieves from it some name/value pairs
+and generates a .h file to allow a C code use the definitions.
+
+The JSON file name is required to be passed in in the command line, the nodes
+this script pays attention to are included in required_keys tuple below.
+"""
+
+import json
+import sys
+
+required_keys = ('epoch', 'major', 'minor')
+
+
+def main(json_file_name):
+ # get rid of the comments
+ json_text = []
+ h_file_text = ['''
+/*
+ * Copyright %d 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.
+ */
+
+/* This file was autogenerated, do not edit. */
+''',]
+
+ json_file = open(json_file_name, 'r')
+ for line in json_file.read().splitlines():
+ json_text.append(line.split('//')[0])
+
+ j = json.loads('\n'.join(json_text))
+
+ for key in required_keys:
+ if key in j.keys():
+ value = j[key]
+ else:
+ value = '0'
+
+ h_file_text.append('#define MANIFEST_%s %s' % (key.upper(), value))
+
+ h_file_text.append('')
+ return '\n'.join(h_file_text)
+
+
+if __name__ == '__main__':
+ print main(sys.argv[1])