diff options
author | Simon Glass <sjg@chromium.org> | 2018-09-14 04:57:31 -0600 |
---|---|---|
committer | Simon Glass <sjg@chromium.org> | 2018-09-29 11:49:35 -0600 |
commit | e0e5df9310d3a0e1fc0eda86ff43fd3e782e61f1 (patch) | |
tree | 7550a5bb58f99bcf8e0f3ac2fdd2db8a5bce4bbf /tools/binman/state.py | |
parent | 9c888cca5e87e28e9addcffae9810fee481428a8 (diff) |
binman: Support hashing entries
Sometimesi it us useful to be able to verify the content of entries with
a hash. Add an easy way to do this in binman. The hash information can be
retrieved from the device tree at run time.
Signed-off-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'tools/binman/state.py')
-rw-r--r-- | tools/binman/state.py | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/tools/binman/state.py b/tools/binman/state.py index 2f8c0863a8f..d945e4bf657 100644 --- a/tools/binman/state.py +++ b/tools/binman/state.py @@ -5,6 +5,7 @@ # Holds and modifies the state information held by binman # +import hashlib import re from sets import Set @@ -226,3 +227,27 @@ def SetInt(node, prop, value): """ for n in GetUpdateNodes(node): n.SetInt(prop, value) + +def CheckAddHashProp(node): + hash_node = node.FindNode('hash') + if hash_node: + algo = hash_node.props.get('algo') + if not algo: + return "Missing 'algo' property for hash node" + if algo.value == 'sha256': + size = 32 + else: + return "Unknown hash algorithm '%s'" % algo + for n in GetUpdateNodes(hash_node): + n.AddEmptyProp('value', size) + +def CheckSetHashValue(node, get_data_func): + hash_node = node.FindNode('hash') + if hash_node: + algo = hash_node.props.get('algo').value + if algo == 'sha256': + m = hashlib.sha256() + m.update(get_data_func()) + data = m.digest() + for n in GetUpdateNodes(hash_node): + n.SetData('value', data) |