diff mbox

[[meta-swupdate] PATCH 2/9] swupdate-common: change logic to add sha256

Message ID 20210826113412.327976-3-sbabic@denx.de
State Accepted
Headers show

Commit Message

Stefano Babic Aug. 26, 2021, 11:34 a.m. UTC
Instead of setting hash just for files going into SWU, scans
sw-description for any occurencies of sha256 attribute.

Signed-off-by: Stefano Babic <sbabic@denx.de>
---
 classes/swupdate-common.bbclass | 21 +++++++++++++--------
 1 file changed, 13 insertions(+), 8 deletions(-)
diff mbox

Patch

diff --git a/classes/swupdate-common.bbclass b/classes/swupdate-common.bbclass
index 0c08ca9..c95511f 100644
--- a/classes/swupdate-common.bbclass
+++ b/classes/swupdate-common.bbclass
@@ -74,12 +74,20 @@  def swupdate_encrypt_file(f, out, key, ivt):
     encargs += ["-K", key, "-iv", ivt, "-nosalt"]
     subprocess.run(encargs, check=True)
 
-def swupdate_write_sha256(s, filename, hash):
+def swupdate_write_sha256(s):
+    import re
     write_lines = []
-
     with open(os.path.join(s, "sw-description"), 'r') as f:
-        for line in f:
-            write_lines.append(line.replace("@%s" % (filename), hash))
+       for line in f:
+          shastr = r"sha256.+=.+@(.+\")"
+          #m = re.match(r"^(?P<before_placeholder>.+)sha256.+=.+(?P<filename>\w+)", line)
+          m = re.match(r"^(?P<before_placeholder>.+)sha256.+=.+(?P<quote>[\'\"])@(?P<filename>.*)(?P=quote)", line)
+          if m:
+              filename = m.group('filename')
+              hash = swupdate_get_sha256(s, filename)
+              write_lines.append(line.replace("@%s" % (filename), hash))
+          else:
+              write_lines.append(line)
 
     with open(os.path.join(s, "sw-description"), 'w+') as f:
         for line in write_lines:
@@ -192,10 +200,7 @@  def prepare_sw_description(d, s, list_for_cpio):
     swupdate_expand_bitbake_variables(d, s)
     swupdate_expand_auto_versions(d, s, list_for_cpio)
 
-    for file in list_for_cpio:
-        if file != 'sw-description' and swupdate_is_hash_needed(s, file):
-            hash = swupdate_get_sha256(s, file)
-            swupdate_write_sha256(s, file, hash)
+    swupdate_write_sha256(s)
 
     encrypt = d.getVar('SWUPDATE_ENCRYPT_SWDESC', True)
     if encrypt: