summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVadim Bendebury <vbendeb@chromium.org>2015-11-03 17:33:25 -0800
committerchrome-bot <chrome-bot@chromium.org>2015-11-04 07:08:40 -0800
commita25c7025e11a9abc0fea873de73148770105fcb3 (patch)
tree1d692657cb0541205c85147b2b4e8c203d7643c8
parente3554f39d752c39df2fb8d70b8a6dc0fdce441f6 (diff)
downloadchrome-ec-a25c7025e11a9abc0fea873de73148770105fcb3.tar.gz
mec1322: killing the white whale (removing temp files left behind)
This has been bothering me literally for years: once in a while there would be tons of files in /tmp directory named tmpXXXXXX where XXXXXXX is some random string. Finally, it became clear that the files are generated when 'make buildall -j' is called in the ec directory. Next step - it looks like one of the culprits is building for board named 'chell'. Indeed, this board uses its own version of cmd_obj_to_bin make function, which, among other things invokes the pack_ec script to pack the image. The script was creating temporary files and leaving them behind. This patch makes the name pattern of the temp files better recognizable, juts in case, and makes sure that the files are deleted once they are not needed. BRANCH=none BUG=none TEST=invoking 'make buildall -j' still succeeds but does not result in leaving temp files behind. Change-Id: I50c511773caa87d4e92980c4c9a36768b0c3101f Signed-off-by: Vadim Bendebury <vbendeb@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/310586 Reviewed-by: Aseda Aboagye <aaboagye@chromium.org>
-rwxr-xr-xchip/mec1322/util/pack_ec.py30
1 files changed, 17 insertions, 13 deletions
diff --git a/chip/mec1322/util/pack_ec.py b/chip/mec1322/util/pack_ec.py
index 236d364b2c..7fed5a8008 100755
--- a/chip/mec1322/util/pack_ec.py
+++ b/chip/mec1322/util/pack_ec.py
@@ -109,19 +109,23 @@ def BuildHeader(args, payload_len, rorofile):
return header
def SignByteArray(data, pem_file):
- hash_file = tempfile.mkstemp()[1]
- sign_file = tempfile.mkstemp()[1]
- with open(hash_file, 'wb') as f:
- hasher = hashlib.sha256()
- hasher.update(data)
- f.write(hasher.digest())
- subprocess.check_call(['openssl', 'rsautl', '-sign', '-inkey', pem_file,
- '-keyform', 'PEM', '-in', hash_file,
- '-out', sign_file])
- with open(sign_file, 'rb') as f:
- signed = list(f.read())
- signed.reverse()
- return bytearray(''.join(signed))
+ hash_file = tempfile.mkstemp(prefix='pack_ec.')[1]
+ sign_file = tempfile.mkstemp(prefix='pack_ec.')[1]
+ try:
+ with open(hash_file, 'wb') as f:
+ hasher = hashlib.sha256()
+ hasher.update(data)
+ f.write(hasher.digest())
+ subprocess.check_call(['openssl', 'rsautl', '-sign', '-inkey', pem_file,
+ '-keyform', 'PEM', '-in', hash_file,
+ '-out', sign_file])
+ with open(sign_file, 'rb') as f:
+ signed = list(f.read())
+ signed.reverse()
+ return bytearray(''.join(signed))
+ finally:
+ os.remove(hash_file)
+ os.remove(sign_file)
def BuildTag(args):
tag = bytearray([(args.header_loc >> 8) & 0xff,